:root {
  --paper: #f3ecda;
  --paper-deep: #e8dfc8;
  --card: #fbf6ea;
  --ink: #22201a;
  --ink-soft: #5d5749;
  --felt: #1c352c;
  --felt-deep: #142720;
  --ivory: #f6efdd;
  --gold: #c9a227;
  --gold-deep: #a3821a;
  --line: rgba(90, 78, 56, 0.22);
  --shadow: 0 18px 40px rgba(40, 34, 22, 0.16);
  --shadow-soft: 0 6px 18px rgba(40, 34, 22, 0.1);
  --radius: 18px;
  --cell-gap: 0px;
  --font-display: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --font-ui: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  min-height: 100vh;
  background:
    radial-gradient(1200px 700px at 50% -10%, #fbf6ea 0%, rgba(251, 246, 234, 0) 60%),
    repeating-linear-gradient(0deg, rgba(120, 104, 74, 0.035) 0 2px, transparent 2px 6px),
    var(--paper);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

.app {
  width: min(960px, 100%);
  margin: 0 auto;
  padding: 28px 20px 48px;
}

/* ---------- top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  flex-wrap: wrap;
  margin-bottom: 22px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.brand-mark {
  display: inline-flex;
  width: 46px;
  height: 46px;
  flex: none;
  filter: drop-shadow(0 4px 10px rgba(28, 53, 44, 0.24));
}

.brand-mark svg {
  width: 100%;
  height: 100%;
}

.brand-text h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 30px;
  font-weight: 600;
  letter-spacing: 0.01em;
  line-height: 1.1;
}

.tagline {
  margin: 2px 0 0;
  color: var(--ink-soft);
  font-size: 13.5px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  color: var(--felt);
  cursor: pointer;
  box-shadow: var(--shadow-soft);
  transition: transform 120ms ease, background 120ms ease, border-color 120ms ease;
}

.icon-btn svg {
  width: 22px;
  height: 22px;
}

.icon-btn:hover {
  background: #fffdf5;
  border-color: rgba(90, 78, 56, 0.38);
}

.icon-btn:active {
  transform: translateY(1px);
}

.icon-btn .icon-off {
  display: none;
}

.icon-btn[aria-pressed="false"] .icon-on {
  display: none;
}

.icon-btn[aria-pressed="false"] .icon-off {
  display: block;
}

.primary-btn,
.ghost-btn {
  font-family: var(--font-ui);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.01em;
  border-radius: 12px;
  padding: 11px 20px;
  cursor: pointer;
  transition: transform 120ms ease, background 120ms ease, border-color 120ms ease, color 120ms ease;
}

.primary-btn {
  border: 1px solid var(--felt-deep);
  background: linear-gradient(180deg, #24483b, var(--felt));
  color: var(--ivory);
  box-shadow: 0 8px 18px rgba(20, 39, 32, 0.26);
}

.primary-btn:hover {
  background: linear-gradient(180deg, #2a5444, #234336);
}

.primary-btn:active {
  transform: translateY(1px);
}

.ghost-btn {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--felt);
}

.ghost-btn:hover:not(:disabled) {
  background: #fffdf5;
  border-color: rgba(90, 78, 56, 0.4);
}

.ghost-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* ---------- hud ---------- */

.hud {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 18px;
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow-soft);
  min-width: 0;
}

.stat-label {
  font-size: 11.5px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.stat-value {
  font-family: var(--font-display);
  font-size: 21px;
  font-weight: 600;
  color: var(--felt);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- advertisement ---------- */

.ad-slot {
  margin: 0 auto 18px;
  width: 100%;
  max-width: 760px;
  padding: 10px 12px 12px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(251, 246, 234, 0.7);
  text-align: center;
}

.ad-kicker {
  display: block;
  margin-bottom: 6px;
  font-size: 10.5px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.ad-top-inner {
  min-height: 90px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ad-top-inner ins {
  width: 100%;
}

/* ---------- table and board ---------- */

.table {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 18px;
}

.table-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.deal-kicker {
  margin: 0 0 2px;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.deal-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 600;
  color: var(--felt);
}

.turn-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--paper);
  font-size: 13px;
  font-weight: 600;
  color: var(--felt);
  white-space: nowrap;
}

.turn-chip::before {
  content: "";
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #26231d;
  box-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.35);
}

.turn-chip.is-white::before {
  background: var(--ivory);
  border: 1px solid rgba(34, 32, 26, 0.45);
}

.turn-chip.is-over::before {
  background: var(--gold);
}

.board-wrap {
  position: relative;
  display: flex;
  justify-content: center;
}

.board {
  --cell: calc(100% / 15);
  position: relative;
  width: min(100%, 560px);
  aspect-ratio: 1 / 1;
  display: grid;
  grid-template-columns: repeat(15, 1fr);
  grid-template-rows: repeat(15, 1fr);
  gap: var(--cell-gap);
  padding: 0;
  background: var(--felt);
  border-radius: 12px;
  border: 1px solid var(--felt-deep);
  box-shadow:
    inset 0 0 0 1px rgba(246, 239, 221, 0.06),
    inset 0 10px 30px rgba(0, 0, 0, 0.28),
    0 12px 26px rgba(30, 26, 18, 0.22);
  background-image:
    repeating-linear-gradient(
      to right,
      transparent 0 calc(50% - 0.5px),
      rgba(246, 239, 221, 0.28) calc(50% - 0.5px) calc(50% + 0.5px),
      transparent calc(50% + 0.5px) 100%
    ),
    repeating-linear-gradient(
      to bottom,
      transparent 0 calc(50% - 0.5px),
      rgba(246, 239, 221, 0.28) calc(50% - 0.5px) calc(50% + 0.5px),
      transparent calc(50% + 0.5px) 100%
    );
  background-size: calc(100% / 15) 100%, 100% calc(100% / 15);
  background-position: 0 0, 0 0;
  touch-action: manipulation;
}

.point {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  margin: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  border-radius: 50%;
  -webkit-tap-highlight-color: transparent;
}

.point::before {
  content: "";
  position: absolute;
  width: 78%;
  height: 78%;
  border-radius: 50%;
  opacity: 0;
  transform: scale(0.9);
  transition: opacity 110ms ease, transform 110ms ease;
}

.point:hover::before,
.point:focus-visible::before {
  opacity: 1;
  transform: scale(1);
  background: rgba(246, 239, 221, 0.22);
}

.point:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: -2px;
}

.point .stone {
  position: relative;
  display: block;
  width: 82%;
  height: 82%;
  border-radius: 50%;
  pointer-events: none;
  animation: stone-in 140ms ease-out;
}

.stone.black {
  background:
    radial-gradient(circle at 34% 28%, #6a655b 0%, #2c2924 42%, #131210 78%, #0b0a09 100%);
  box-shadow:
    0 2px 4px rgba(0, 0, 0, 0.55),
    inset 0 -2px 4px rgba(0, 0, 0, 0.55),
    inset 0 1px 2px rgba(255, 255, 255, 0.18);
}

.stone.white {
  background:
    radial-gradient(circle at 34% 28%, #ffffff 0%, #f4ecd8 40%, #ded2b4 78%, #c3b693 100%);
  box-shadow:
    0 2px 4px rgba(0, 0, 0, 0.4),
    inset 0 -2px 4px rgba(120, 105, 75, 0.4),
    inset 0 1px 2px rgba(255, 255, 255, 0.8);
}

.stone.last::after {
  content: "";
  position: absolute;
  inset: 50% auto auto 50%;
  width: 22%;
  height: 22%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 6px rgba(201, 162, 39, 0.7);
}

.stone.win {
  animation: win-pulse 1.1s ease-in-out infinite alternate;
  box-shadow:
    0 0 0 2px var(--gold),
    0 0 12px rgba(201, 162, 39, 0.85);
}

@keyframes stone-in {
  from {
    opacity: 0;
    transform: scale(0.55);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes win-pulse {
  from {
    box-shadow: 0 0 0 2px rgba(201, 162, 39, 0.7), 0 0 8px rgba(201, 162, 39, 0.5);
  }
  to {
    box-shadow: 0 0 0 3px var(--gold), 0 0 18px rgba(201, 162, 39, 0.95);
  }
}

.board-status {
  margin: 14px 2px 0;
  min-height: 22px;
  font-size: 14px;
  color: var(--ink-soft);
}

/* ---------- overlay ---------- */

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  border-radius: 12px;
  background: rgba(20, 39, 32, 0.66);
  backdrop-filter: blur(3px);
  z-index: 5;
}

.overlay-card {
  width: min(340px, 100%);
  padding: 22px 22px 18px;
  border-radius: 16px;
  background: var(--card);
  border: 1px solid rgba(246, 239, 221, 0.4);
  box-shadow: 0 24px 50px rgba(0, 0, 0, 0.35);
  text-align: center;
}

.overlay-kicker {
  margin: 0 0 4px;
  font-size: 11.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.overlay-card h2 {
  margin: 0 0 8px;
  font-family: var(--font-display);
  font-size: 26px;
  color: var(--felt);
}

.overlay-body {
  margin: 0 0 18px;
  color: var(--ink-soft);
  font-size: 14.5px;
}

.overlay-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

/* ---------- action bar ---------- */

.actionbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.selection-note {
  margin: 0;
  color: var(--ink-soft);
  font-size: 14px;
}

.actions {
  display: flex;
  gap: 10px;
}

.hint {
  margin: 0 0 22px;
  color: var(--ink-soft);
  font-size: 13px;
}

.hint strong {
  color: var(--ink);
  font-weight: 600;
}

/* ---------- promos ---------- */

.promo {
  margin: 0 0 18px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow-soft);
}

.promo-head {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.promo-label {
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
  font-weight: 600;
}

.promo-link {
  color: var(--felt);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  border-bottom: 1px solid rgba(28, 53, 44, 0.35);
}

.promo-link:hover {
  border-bottom-color: var(--felt);
}

.promo-btn {
  margin-left: auto;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.promo-btn:hover {
  color: var(--felt);
  border-color: rgba(90, 78, 56, 0.45);
}

.promo-slots {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: stretch;
}

.promo-card {
  flex: 1 1 220px;
  min-width: 200px;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--paper);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.promo-card h3 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 17px;
  color: var(--felt);
}

.promo-card p {
  margin: 0;
  font-size: 13px;
  color: var(--ink-soft);
}

.promo-card a {
  margin-top: 6px;
  align-self: flex-start;
  font-size: 13px;
  font-weight: 600;
  color: var(--gold-deep);
  text-decoration: none;
  border-bottom: 1px solid rgba(163, 130, 26, 0.4);
}

.promo-card a:hover {
  border-bottom-color: var(--gold-deep);
}

.promo-frame {
  flex: 1 1 280px;
  min-width: 240px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px;
  border: 1px dashed rgba(90, 78, 56, 0.35);
  border-radius: 14px;
  background: rgba(243, 236, 218, 0.6);
}

.promo-frame .frame-kicker {
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.promo-frame ins {
  width: 100%;
}

.promo-thanks {
  margin: 0 0 18px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--card);
  color: var(--ink-soft);
  font-size: 14px;
}

.link-btn {
  border: 0;
  background: none;
  padding: 0;
  color: var(--felt);
  font: inherit;
  font-weight: 600;
  text-decoration: underline;
  cursor: pointer;
}

/* ---------- about ---------- */

.help {
  margin: 0 0 10px;
  color: var(--ink-soft);
  font-size: 13.5px;
}

.help p {
  margin: 0;
}

.about {
  border-top: 1px solid var(--line);
  padding-top: 16px;
  color: var(--ink-soft);
  font-size: 13.5px;
}

.about p {
  margin: 0 0 8px;
}

.about strong {
  color: var(--ink);
}

.about a {
  color: var(--felt);
  font-weight: 600;
}

/* ---------- utilities ---------- */

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

@media (max-width: 640px) {
  .app {
    padding: 20px 14px 36px;
  }

  .brand-text h1 {
    font-size: 26px;
  }

  .hud {
    grid-template-columns: repeat(2, 1fr);
  }

  .table {
    padding: 12px;
  }

  .deal-title {
    font-size: 21px;
  }

  .board {
    width: 100%;
  }

  .turn-chip {
    font-size: 12px;
  }

  .promo-btn {
    margin-left: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}