/* ==========================================================================
   Lines of Action — styles
   ========================================================================== */

:root {
  --bg-0: #0c0f15;
  --bg-1: #141923;
  --surface: rgba(255, 255, 255, 0.045);
  --surface-2: rgba(255, 255, 255, 0.08);
  --surface-3: rgba(255, 255, 255, 0.12);
  --border: rgba(255, 255, 255, 0.09);
  --border-strong: rgba(255, 255, 255, 0.16);
  --text: #eef1f6;
  --text-dim: #a6afbf;
  --text-faint: #6c778a;
  --accent: #f2b45a;
  --accent-2: #ffd48f;
  --accent-ink: #2b1a04;
  --accent-soft: rgba(242, 180, 90, 0.14);
  --good: #63d69f;
  --bad: #ff7f70;
  --radius: 16px;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.42);
  --ease: cubic-bezier(0.22, 0.8, 0.24, 1);
  --move-ms: 300ms;

  /* Board theme (wood by default) */
  --sq-light: #ebcd9e;
  --sq-dark: #ba8653;
  --frame-a: #70472a;
  --frame-b: #3a2413;
  --frame-edge: rgba(255, 220, 170, 0.18);
  --coord-light: #9b6a39;
  --coord-dark: #f6e4c4;
  --texture: repeating-linear-gradient(97deg, rgba(90, 50, 15, 0.07) 0 2px, transparent 2px 9px),
             repeating-linear-gradient(83deg, rgba(255, 240, 210, 0.05) 0 1px, transparent 1px 13px);
  --link-black: rgba(28, 18, 8, 0.78);
  --link-white: rgba(255, 252, 244, 0.96);
  --link-white-under: rgba(70, 40, 10, 0.35);
  --hl-last: rgba(255, 196, 70, 0.42);
  --hl-sel: rgba(255, 214, 102, 0.62);
  --hl-hint: rgba(99, 214, 159, 0.5);
  --dot: rgba(48, 26, 6, 0.34);
  --cap-ring: rgba(205, 52, 30, 0.8);
  --path: rgba(255, 236, 190, 0.85);

  --board-size: min(calc(100vh - 250px), calc(100vw - 480px), 720px);
  --frame-pad: clamp(8px, 1.6vmin, 14px);
  --eval-w: 14px;
  --eval-gap: 10px;
}

/* Evaluation bar switched off: give its space back to the board. */
:root.no-eval { --eval-w: 0px; --eval-gap: 0px; }

[data-theme="slate"] {
  --sq-light: #a3afbf;
  --sq-dark: #6c7a8e;
  --frame-a: #323a4a;
  --frame-b: #171c26;
  --frame-edge: rgba(190, 215, 255, 0.14);
  --coord-light: #566377;
  --coord-dark: #dbe3ee;
  --texture: radial-gradient(circle at 20% 30%, rgba(255, 255, 255, 0.05), transparent 40%),
             radial-gradient(circle at 80% 70%, rgba(0, 0, 0, 0.08), transparent 45%);
  --link-black: rgba(8, 12, 20, 0.8);
  --link-white: rgba(255, 255, 255, 0.95);
  --link-white-under: rgba(10, 20, 40, 0.3);
  --hl-last: rgba(120, 200, 255, 0.36);
  --hl-sel: rgba(140, 215, 255, 0.55);
  --dot: rgba(8, 18, 36, 0.4);
  --path: rgba(225, 240, 255, 0.85);
}

[data-theme="jade"] {
  --sq-light: #dfe8cf;
  --sq-dark: #7ea66d;
  --frame-a: #35553a;
  --frame-b: #172a1b;
  --frame-edge: rgba(210, 255, 200, 0.14);
  --coord-light: #5f8650;
  --coord-dark: #eef5e4;
  --texture: radial-gradient(circle at 70% 20%, rgba(255, 255, 255, 0.06), transparent 50%);
  --link-black: rgba(10, 22, 10, 0.78);
  --link-white: rgba(255, 255, 250, 0.96);
  --link-white-under: rgba(20, 50, 20, 0.3);
  --hl-last: rgba(255, 232, 92, 0.48);
  --hl-sel: rgba(255, 236, 120, 0.66);
  --dot: rgba(18, 44, 14, 0.36);
  --path: rgba(255, 252, 220, 0.9);
}

[data-theme="marble"] {
  --sq-light: #efede8;
  --sq-dark: #b7b0a6;
  --frame-a: #8d867c;
  --frame-b: #4b4640;
  --frame-edge: rgba(255, 255, 255, 0.22);
  --coord-light: #8b8377;
  --coord-dark: #f6f3ee;
  --texture: linear-gradient(115deg, transparent 30%, rgba(120, 110, 100, 0.08) 31%, transparent 34%, transparent 62%, rgba(120, 110, 100, 0.07) 63%, transparent 66%),
             linear-gradient(35deg, transparent 45%, rgba(255, 255, 255, 0.12) 46%, transparent 50%);
  --link-black: rgba(25, 22, 18, 0.78);
  --link-white: rgba(255, 255, 255, 0.98);
  --link-white-under: rgba(60, 50, 40, 0.35);
  --hl-last: rgba(240, 175, 70, 0.4);
  --hl-sel: rgba(245, 195, 90, 0.6);
  --dot: rgba(40, 32, 22, 0.32);
  --path: rgba(255, 245, 220, 0.9);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: 'Outfit', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color: var(--text);
  background:
    radial-gradient(1100px 700px at 12% -12%, rgba(84, 110, 170, 0.28), transparent 60%),
    radial-gradient(900px 650px at 105% 110%, rgba(190, 120, 50, 0.2), transparent 60%),
    linear-gradient(180deg, var(--bg-1), var(--bg-0));
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

button { font: inherit; color: inherit; }
svg { display: block; }

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 14px clamp(12px, 3vw, 32px) 18px;
}

/* ---------- Top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 1180px;
  width: 100%;
  margin: 0 auto 14px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  width: 40px;
  height: 40px;
  padding: 6px;
  border-radius: 12px;
  background: linear-gradient(145deg, #232b3b, #121722);
  border: 1px solid var(--border);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
}
.brand-mark path { stroke: var(--accent); stroke-width: 5; stroke-linecap: round; fill: none; }
.brand-mark .m-white { fill: #f6efe0; }
.brand-mark .m-black { fill: #f6efe0; opacity: 0.55; }

.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-title { font-size: 1.3rem; font-weight: 600; letter-spacing: 0.02em; }
.brand-tag { font-size: 0.8rem; color: var(--text-dim); font-weight: 300; }

.top-actions { display: flex; gap: 8px; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, transform 0.15s;
}
.icon-btn:hover { background: var(--surface-2); border-color: var(--border-strong); }
.icon-btn:active { transform: scale(0.95); }
.icon-btn:disabled { opacity: 0.35; cursor: default; transform: none; }
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn.sm { width: 30px; height: 30px; border-radius: 9px; }
.icon-btn.sm svg { width: 16px; height: 16px; }
.icon-btn.off { color: var(--text-faint); }

/* ---------- Layout ---------- */

.layout {
  flex: 1;
  display: grid;
  grid-template-columns: auto 340px;
  gap: clamp(18px, 3vw, 36px);
  justify-content: center;
  align-items: start;
  max-width: 1180px;
  width: 100%;
  margin: 0 auto;
}

.stage {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: calc(var(--board-size) + 2 * var(--frame-pad) + var(--eval-w) + var(--eval-gap));
}

.board-row { display: flex; gap: var(--eval-gap); align-items: stretch; }

/* ---------- Player cards ---------- */

.player-card {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 60px;
  padding: 10px 14px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  transition: border-color 0.3s, box-shadow 0.3s, background 0.3s;
}
.player-card.active {
  border-color: rgba(242, 180, 90, 0.55);
  background: linear-gradient(90deg, rgba(242, 180, 90, 0.1), var(--surface) 60%);
  box-shadow: 0 0 0 3px rgba(242, 180, 90, 0.1), 0 10px 30px rgba(0, 0, 0, 0.25);
}
.player-card.winner {
  border-color: rgba(99, 214, 159, 0.6);
  background: linear-gradient(90deg, rgba(99, 214, 159, 0.14), var(--surface) 65%);
}

.pc-avatar {
  position: relative;
  width: 38px;
  height: 38px;
  flex: none;
  border-radius: 50%;
}
.pc-avatar.black { background: radial-gradient(circle at 34% 30%, #6d7381 0%, #2a2e37 40%, #0d0f13 75%, #050506 100%); box-shadow: 0 4px 10px rgba(0, 0, 0, 0.5), inset 0 -3px 6px rgba(0, 0, 0, 0.6); }
.pc-avatar.white { background: radial-gradient(circle at 34% 30%, #fff 0%, #f5efe3 38%, #ddd2bd 75%, #bfb196 100%); box-shadow: 0 4px 10px rgba(0, 0, 0, 0.4), inset 0 -3px 6px rgba(120, 95, 60, 0.35); }
.pc-avatar svg {
  position: absolute;
  right: -4px;
  bottom: -4px;
  width: 20px;
  height: 20px;
  padding: 3px;
  border-radius: 50%;
  background: var(--bg-1);
  border: 1px solid var(--border-strong);
  fill: none;
  stroke: var(--text-dim);
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.pc-main { flex: 1; min-width: 0; }
.pc-name { font-weight: 600; font-size: 1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pc-sub { font-size: 0.82rem; color: var(--text-dim); display: flex; align-items: center; gap: 8px; min-height: 1.2em; }

.pc-stats { display: flex; gap: 6px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  font-size: 0.8rem;
  color: var(--text-dim);
  white-space: nowrap;
}
.chip b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.chip svg { width: 13px; height: 13px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; opacity: 0.8; }
.chip.good b { color: var(--good); }

.thinking { display: inline-flex; gap: 3px; align-items: center; }
.thinking i { width: 5px; height: 5px; border-radius: 50%; background: var(--accent); animation: blink 1.1s infinite ease-in-out; }
.thinking i:nth-child(2) { animation-delay: 0.15s; }
.thinking i:nth-child(3) { animation-delay: 0.3s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; transform: scale(0.8); } 40% { opacity: 1; transform: scale(1); } }

.turn-pill {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent-ink);
  background: var(--accent);
  border-radius: 999px;
  padding: 2px 8px;
}
.turn-pill.win { background: var(--good); color: #062417; }

/* ---------- Evaluation bar ---------- */

.eval-bar {
  position: relative;
  width: var(--eval-w);
  border-radius: 8px;
  overflow: hidden;
  background: linear-gradient(180deg, #f4efe4, #d9cfbb);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.3);
  transition: opacity 0.3s;
}
.eval-bar.top-black { background: linear-gradient(180deg, #2c3039, #0e1014); }
.eval-fill {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 50%;
  background: linear-gradient(180deg, #2c3039, #0e1014);
  transition: height 0.7s var(--ease);
}
.eval-bar.top-black .eval-fill { background: linear-gradient(180deg, #f4efe4, #d9cfbb); }
.eval-bar::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 1px;
  background: rgba(242, 180, 90, 0.7);
}
.eval-label {
  position: absolute;
  left: 50%;
  bottom: 4px;
  transform: translateX(-50%) rotate(180deg);
  writing-mode: vertical-rl;
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: #d8d2c4;
  mix-blend-mode: difference;
  white-space: nowrap;
}
.eval-bar.hidden { display: none; }
.eval-bar.pending { opacity: 0.55; }
.eval-bar.pending .eval-label { visibility: hidden; }

/* ---------- Board ---------- */

.board-frame {
  position: relative;
  padding: var(--frame-pad);
  border-radius: 18px;
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.08), transparent 40%),
    linear-gradient(145deg, var(--frame-a), var(--frame-b));
  box-shadow:
    0 30px 70px rgba(0, 0, 0, 0.55),
    0 6px 18px rgba(0, 0, 0, 0.35),
    inset 0 1px 0 var(--frame-edge),
    inset 0 -2px 6px rgba(0, 0, 0, 0.35);
}

.board {
  position: relative;
  width: var(--board-size);
  height: var(--board-size);
  border-radius: 6px;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35), inset 0 0 22px rgba(0, 0, 0, 0.22);
}
.board::after {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--texture);
  pointer-events: none;
  z-index: 1;
}

.squares {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
}

.sq {
  position: relative;
  background: var(--sq-light);
  transition: background-color 0.3s;
}
.sq.dark { background: var(--sq-dark); }
.sq::before, .sq::after {
  content: '';
  position: absolute;
  pointer-events: none;
}
.sq::before { inset: 0; background: transparent; transition: background 0.2s; }
.sq.last::before { background: var(--hl-last); }
.sq.sel::before { background: var(--hl-sel); }
.sq.hint::before { background: var(--hl-hint); animation: hintPulse 1.4s ease-in-out infinite; }
@keyframes hintPulse { 50% { opacity: 0.45; } }

.sq.target { cursor: pointer; }
.sq.target::after {
  left: 50%;
  top: 50%;
  width: 28%;
  height: 28%;
  border-radius: 50%;
  background: var(--dot);
  transform: translate(-50%, -50%);
  transition: width 0.15s, height 0.15s;
  z-index: 3;
}
.sq.target.hover::after { width: 36%; height: 36%; }
.sq.target.capture::after {
  width: 92%;
  height: 92%;
  background: transparent;
  box-shadow: inset 0 0 0 calc(var(--board-size) * 0.007) var(--cap-ring);
  z-index: 6;
}
.sq.target.capture.hover::after { box-shadow: inset 0 0 0 calc(var(--board-size) * 0.011) var(--cap-ring); }

.sq .coord {
  position: absolute;
  font-size: calc(var(--board-size) * 0.024);
  font-weight: 600;
  line-height: 1;
  pointer-events: none;
  z-index: 2;
  color: var(--coord-light);
}
.sq.light .coord { color: var(--coord-light); }
.sq.dark .coord { color: var(--coord-dark); }
.sq .coord.rank { left: 5%; top: 6%; }
.sq .coord.file { right: 6%; bottom: 5%; }
.no-coords .coord { display: none; }

.layer { position: absolute; inset: 0; pointer-events: none; }
.links { z-index: 4; transition: opacity 0.3s; }
.links line { stroke-linecap: round; }
.links .lk-b { stroke: var(--link-black); stroke-width: 0.13; }
.links .lk-w-under { stroke: var(--link-white-under); stroke-width: 0.19; }
.links .lk-w { stroke: var(--link-white); stroke-width: 0.12; }
.links .lk.win { stroke-width: 0.17; }
.links g { animation: fadeIn 0.35s ease-out; }
.no-links .links { opacity: 0; }

.pieces { z-index: 5; }
.arrows { z-index: 8; overflow: visible; }
.arrows marker path { fill: var(--path); }
.arrows line { stroke: var(--path); stroke-width: 0.1; stroke-linecap: round; marker-end: url(#arrowhead); opacity: 0.85; }
.arrows line.hint { stroke: var(--good); stroke-width: 0.14; opacity: 0.95; marker-end: url(#arrowhead-hint); }
.arrows .hint-head path { fill: var(--good); }

/* ---------- Pieces ---------- */

.piece {
  position: absolute;
  left: 0;
  top: 0;
  width: 12.5%;
  height: 12.5%;
  transition: transform var(--move-ms) var(--ease);
  will-change: transform;
}
.no-anim .piece, .piece.instant { transition: none; }
.piece.moving { z-index: 3; }
.piece.dragging { z-index: 10; transition: none; cursor: grabbing; }

.stone {
  position: absolute;
  inset: 9%;
  border-radius: 50%;
  transition: transform 0.18s var(--ease), box-shadow 0.18s;
}
.stone::after {
  content: '';
  position: absolute;
  inset: 17%;
  border-radius: 50%;
}

.piece.b .stone {
  background: radial-gradient(circle at 33% 28%, #757b89 0%, #353a45 26%, #16181e 62%, #060708 100%);
  box-shadow:
    0 calc(var(--board-size) * 0.006) calc(var(--board-size) * 0.012) rgba(0, 0, 0, 0.5),
    inset 0 -3px 7px rgba(0, 0, 0, 0.6),
    inset 0 2px 2px rgba(255, 255, 255, 0.12);
}
.piece.b .stone::after {
  border: 1px solid rgba(255, 255, 255, 0.07);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.5);
}
.piece.w .stone {
  background: radial-gradient(circle at 33% 28%, #ffffff 0%, #fbf7ef 28%, #e7ddca 66%, #c9bb9f 100%);
  box-shadow:
    0 calc(var(--board-size) * 0.006) calc(var(--board-size) * 0.012) rgba(0, 0, 0, 0.42),
    inset 0 -3px 7px rgba(130, 100, 60, 0.4),
    inset 0 2px 2px rgba(255, 255, 255, 0.9);
}
.piece.w .stone::after {
  border: 1px solid rgba(150, 120, 80, 0.18);
  box-shadow: inset 0 2px 3px rgba(130, 100, 60, 0.25);
}

.piece.mine { cursor: grab; }
.piece.lifted .stone, .piece.dragging .stone {
  transform: scale(1.1);
  box-shadow: 0 calc(var(--board-size) * 0.02) calc(var(--board-size) * 0.03) rgba(0, 0, 0, 0.45), inset 0 -3px 7px rgba(0, 0, 0, 0.4);
}

.piece.appear .stone { animation: popIn 0.45s var(--ease) both; }
@keyframes popIn { from { transform: scale(0.2); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.piece.captured { z-index: 2; }
.piece.captured .stone { animation: vanish 0.38s ease-in forwards; }
@keyframes vanish { to { transform: scale(0.15) rotate(25deg); opacity: 0; } }

.piece.win .stone { animation: winGlow 1.6s ease-in-out infinite; }
@keyframes winGlow {
  0%, 100% { filter: drop-shadow(0 0 0 rgba(255, 214, 102, 0)); }
  50% { filter: drop-shadow(0 0 calc(var(--board-size) * 0.018) rgba(255, 214, 102, 0.95)); }
}

.fx {
  position: absolute;
  width: 12.5%;
  height: 12.5%;
  pointer-events: none;
  z-index: 7;
}
.fx::before {
  content: '';
  position: absolute;
  inset: 12%;
  border-radius: 50%;
  border: calc(var(--board-size) * 0.006) solid var(--fx-color, #ff9a6b);
  animation: ring 0.55s ease-out forwards;
}
@keyframes ring { from { transform: scale(0.4); opacity: 1; } to { transform: scale(1.5); opacity: 0; } }
.fx i {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 7%;
  height: 7%;
  border-radius: 50%;
  background: var(--fx-color, #ff9a6b);
  animation: spark 0.6s ease-out forwards;
}
@keyframes spark { to { transform: translate(var(--dx), var(--dy)) scale(0.2); opacity: 0; } }

.board-banner {
  position: absolute;
  left: 50%;
  bottom: 3%;
  transform: translateX(-50%);
  z-index: 12;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 8px 7px 14px;
  border-radius: 999px;
  background: rgba(14, 18, 26, 0.86);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border-strong);
  font-size: 0.85rem;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  white-space: nowrap;
  animation: fadeUp 0.25s var(--ease);
}
.board-banner button {
  border: 0;
  border-radius: 999px;
  padding: 5px 12px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
  cursor: pointer;
}
.board-banner[hidden] { display: none; }

/* ---------- Side panel ---------- */

.panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  position: sticky;
  top: 14px;
}

.status-card, .moves-card {
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  backdrop-filter: blur(6px);
}

.status-card { padding: 16px 18px; }
.status-main { font-size: 1.35rem; font-weight: 600; display: flex; align-items: center; gap: 10px; min-height: 1.6rem; }
.status-main .swatch-dot { width: 14px; height: 14px; border-radius: 50%; flex: none; }
.status-main .swatch-dot.black { background: radial-gradient(circle at 34% 30%, #7a808e, #22252c 55%, #050506); box-shadow: 0 0 0 1.5px rgba(255, 255, 255, 0.22); }
.status-main .swatch-dot.white { background: radial-gradient(circle at 34% 30%, #fff, #efe7d6 55%, #c3b496); }
.status-sub { color: var(--text-dim); font-size: 0.9rem; margin-top: 4px; min-height: 1.2em; }

.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.actions .btn.primary { grid-column: 1 / -1; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 16px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, transform 0.15s, box-shadow 0.2s, opacity 0.2s;
}
.btn:hover { background: var(--surface-3); border-color: var(--border-strong); }
.btn:active { transform: translateY(1px) scale(0.99); }
.btn:disabled { opacity: 0.4; cursor: default; transform: none; }
.btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.btn.primary {
  border: 0;
  color: var(--accent-ink);
  font-weight: 600;
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
  box-shadow: 0 8px 22px rgba(242, 180, 90, 0.28), inset 0 1px 0 rgba(255, 255, 255, 0.5);
}
.btn.primary:hover { background: linear-gradient(180deg, #ffe0a8, #f6bf6a); }
.btn.wide { width: 100%; padding: 13px; font-size: 1.02rem; margin-top: 6px; }
.btn.busy svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.moves-card { padding: 12px 10px 10px 14px; display: flex; flex-direction: column; min-height: 0; }
.moves-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-right: 4px;
  margin-bottom: 8px;
  font-weight: 600;
  font-size: 0.85rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
}
.nav-btns { display: flex; gap: 4px; }

.move-list {
  list-style: none;
  margin: 0;
  padding: 0 4px 0 0;
  max-height: calc(var(--board-size) - 230px);
  min-height: 120px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.15) transparent;
  font-variant-numeric: tabular-nums;
}
.move-list li {
  display: grid;
  grid-template-columns: 34px 1fr 1fr;
  align-items: center;
  border-radius: 8px;
}
.move-list li:nth-child(odd) { background: rgba(255, 255, 255, 0.025); }
.move-list .num { color: var(--text-faint); font-size: 0.82rem; padding-left: 6px; }
.move-list button {
  border: 0;
  background: transparent;
  text-align: left;
  padding: 6px 8px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 0.92rem;
  display: flex;
  align-items: center;
  gap: 7px;
}
.move-list button:hover { background: var(--surface-2); }
.move-list button.current { background: var(--accent-soft); color: var(--accent-2); box-shadow: inset 0 0 0 1px rgba(242, 180, 90, 0.35); }
.move-list button .cap { color: var(--bad); font-weight: 600; }
.move-list button i { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.move-list button i.b { background: radial-gradient(circle at 34% 30%, #8a909c, #2a2d34 55%, #050506); box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.25); }
.move-list button i.w { background: radial-gradient(circle at 34% 30%, #fff, #efe7d6 55%, #c3b496); }
.moves-empty { color: var(--text-faint); font-size: 0.9rem; padding: 6px 4px 10px; }
.moves-empty[hidden] { display: none; }

.info-line { color: var(--text-faint); font-size: 0.8rem; padding: 0 4px; min-height: 1em; font-variant-numeric: tabular-nums; }

.footer {
  margin-top: 22px;
  text-align: center;
  color: var(--text-faint);
  font-size: 0.8rem;
  display: flex;
  gap: 12px;
  justify-content: center;
}
.footer a { color: var(--text-dim); }

/* ---------- Modals ---------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(5, 7, 12, 0.6);
  backdrop-filter: blur(6px);
  animation: fadeIn 0.2s ease-out;
}
.modal[hidden] { display: none; }
#modal-over { background: rgba(5, 7, 12, 0.42); backdrop-filter: blur(1.5px); }

.modal-card {
  position: relative;
  width: min(560px, 100%);
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  padding: 26px 26px 22px;
  border-radius: 22px;
  background: linear-gradient(180deg, #1b2130, #131823);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow);
  animation: popCard 0.3s var(--ease);
}
.modal-card.narrow { width: min(430px, 100%); }
.modal-card.wide-card { width: min(860px, 100%); }
.modal-card h2 { margin: 0 0 18px; font-size: 1.45rem; font-weight: 600; }
.modal-close { position: absolute; top: 16px; right: 16px; }
@keyframes popCard { from { opacity: 0; transform: translateY(14px) scale(0.97); } }
@keyframes fadeIn { from { opacity: 0; } }
@keyframes fadeUp { from { opacity: 0; transform: translate(-50%, 8px); } }

.field { margin-bottom: 18px; }
.field[hidden] { display: none; }
.field-label { font-size: 0.78rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--text-dim); margin-bottom: 8px; font-weight: 500; }

.choice-grid { display: grid; gap: 10px; }
.choice-grid.three { grid-template-columns: repeat(3, 1fr); }
.choice {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 14px 8px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  text-align: center;
  font-size: 0.88rem;
  line-height: 1.2;
  transition: all 0.2s;
}
.choice svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; color: var(--text-dim); }
.choice:hover { background: var(--surface-2); }
.choice.selected { border-color: var(--accent); background: var(--accent-soft); box-shadow: 0 0 0 3px rgba(242, 180, 90, 0.12); }
.choice.selected svg { color: var(--accent); }

.segmented {
  display: flex;
  gap: 4px;
  padding: 4px;
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--border);
}
.segmented button {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 8px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--text-dim);
  transition: all 0.2s;
}
.segmented button:hover { color: var(--text); }
.segmented button.selected { background: var(--surface-3); color: var(--text); box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3); }
.dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; flex: none; }
.dot.black { background: #111317; box-shadow: 0 0 0 1.5px rgba(255, 255, 255, 0.35); }
.dot.white { background: #f4efe4; }
.dot.random { background: linear-gradient(90deg, #111317 50%, #f4efe4 50%); box-shadow: 0 0 0 1.5px rgba(255, 255, 255, 0.35); }

.levels { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.levels button {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 10px 4px 9px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  font-size: 0.8rem;
  transition: all 0.2s;
}
.levels button:hover { background: var(--surface-2); }
.levels button.selected { border-color: var(--accent); background: var(--accent-soft); }
.levels .bars { display: flex; gap: 2px; align-items: flex-end; height: 16px; }
.levels .bars span { width: 4px; border-radius: 2px; background: var(--surface-3); }
.levels .bars span.on { background: var(--accent); }
.level-desc { margin-top: 8px; font-size: 0.86rem; color: var(--text-dim); min-height: 2.4em; }
.level-desc b { color: var(--text); font-weight: 500; }

.themes { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.themes button {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 8px 4px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  font-size: 0.8rem;
}
.themes button.selected { border-color: var(--accent); background: var(--accent-soft); }
.swatch {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  box-shadow: 0 0 0 3px var(--sw-frame), 0 4px 10px rgba(0, 0, 0, 0.35);
  background:
    conic-gradient(var(--sw-dark) 25%, var(--sw-light) 0 50%, var(--sw-dark) 0 75%, var(--sw-light) 0) 0 0 / 50% 50%;
}
.swatch.wood { --sw-light: #ebcd9e; --sw-dark: #ba8653; --sw-frame: #5a3820; }
.swatch.slate { --sw-light: #a3afbf; --sw-dark: #6c7a8e; --sw-frame: #252c39; }
.swatch.jade { --sw-light: #dfe8cf; --sw-dark: #7ea66d; --sw-frame: #26402a; }
.swatch.marble { --sw-light: #efede8; --sw-dark: #b7b0a6; --sw-frame: #6c665e; }

.toggles { display: flex; flex-direction: column; margin-bottom: 18px; border-radius: 14px; border: 1px solid var(--border); overflow: hidden; }
.toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  cursor: pointer;
  font-size: 0.95rem;
}
.toggle + .toggle { border-top: 1px solid var(--border); }
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle i {
  position: relative;
  width: 42px;
  height: 24px;
  flex: none;
  border-radius: 999px;
  background: var(--surface-3);
  transition: background 0.2s;
}
.toggle i::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
  transition: transform 0.2s var(--ease);
}
.toggle input:checked + i { background: var(--accent); }
.toggle input:checked + i::after { transform: translateX(18px); }
.toggle input:focus-visible + i { outline: 2px solid var(--accent-2); outline-offset: 2px; }

/* Rules */
.rules-lead { color: var(--text-dim); margin: -6px 0 18px; line-height: 1.5; }
.rules-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.rule {
  border-radius: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 12px;
}
.rule svg { width: 100%; height: auto; border-radius: 8px; box-shadow: 0 6px 16px rgba(0, 0, 0, 0.35); }
.rule h3 { margin: 12px 0 4px; font-size: 1rem; font-weight: 600; }
.rule p { margin: 0; color: var(--text-dim); font-size: 0.86rem; line-height: 1.45; }
.rules-extra { margin: 18px 0 8px; }
.rules-extra h3 { font-size: 0.78rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--text-dim); margin: 0 0 8px; font-weight: 500; }
.rules-extra ul { margin: 0; padding-left: 18px; color: var(--text-dim); line-height: 1.55; font-size: 0.92rem; }
.rules-extra li { margin-bottom: 4px; }
.rules-extra li b { color: var(--text); font-weight: 500; }

/* Game over */
.over-card { text-align: center; padding-top: 30px; }
.over-emblem { display: grid; place-items: center; margin-bottom: 10px; }
.over-emblem .big-stone {
  width: 78px;
  height: 78px;
  border-radius: 50%;
  animation: popIn 0.6s var(--ease) both;
}
.over-emblem .big-stone.black { background: radial-gradient(circle at 33% 28%, #757b89 0%, #353a45 26%, #16181e 62%, #060708 100%); box-shadow: 0 12px 30px rgba(0, 0, 0, 0.6), 0 0 0 6px rgba(242, 180, 90, 0.25); }
.over-emblem .big-stone.white { background: radial-gradient(circle at 33% 28%, #fff 0%, #fbf7ef 28%, #e7ddca 66%, #c9bb9f 100%); box-shadow: 0 12px 30px rgba(0, 0, 0, 0.5), 0 0 0 6px rgba(242, 180, 90, 0.25); }
.over-emblem .big-stone.draw { background: linear-gradient(90deg, #16181e 50%, #f4efe4 50%); box-shadow: 0 12px 30px rgba(0, 0, 0, 0.5), 0 0 0 6px rgba(255, 255, 255, 0.12); }
.over-card h2 { margin-bottom: 6px; font-size: 1.7rem; }
.over-card h2.good { color: var(--good); }
.over-card h2.bad { color: var(--bad); }
.over-sub { color: var(--text-dim); margin: 0 0 16px; }
.over-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 18px; }
.over-stats div { border-radius: 12px; background: var(--surface); border: 1px solid var(--border); padding: 10px 6px; }
.over-stats b { display: block; font-size: 1.25rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.over-stats span { font-size: 0.76rem; color: var(--text-dim); }
.over-record { grid-column: 1 / -1; font-size: 0.85rem; color: var(--text-dim); }
.over-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  z-index: 150;
  transform: translate(-50%, 20px);
  opacity: 0;
  pointer-events: none;
  padding: 11px 18px;
  border-radius: 999px;
  background: rgba(22, 27, 38, 0.95);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow);
  font-size: 0.92rem;
  transition: opacity 0.25s, transform 0.25s var(--ease);
  max-width: calc(100vw - 32px);
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 120; }

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

/* ---------- Responsive ---------- */

@media (max-width: 960px) {
  :root {
    --board-size: min(calc(100vw - 2 * clamp(12px, 3vw, 32px) - 2 * var(--frame-pad) - var(--eval-w) - var(--eval-gap)), 620px);
    --eval-w: 10px;
  }
  .layout { grid-template-columns: 1fr; justify-items: center; }
  .stage { max-width: 100%; }
  .panel { position: static; width: calc(var(--board-size) + 2 * var(--frame-pad) + var(--eval-w) + var(--eval-gap)); max-width: 100%; }
  .actions { grid-template-columns: repeat(3, 1fr); }
  .actions .btn.primary { grid-column: auto; }
  .move-list { max-height: 220px; }
  .rules-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 560px) {
  .app { padding-top: 10px; }
  .brand-tag { display: none; }
  .brand-title { font-size: 1.1rem; }
  .brand-mark { width: 36px; height: 36px; }
  .icon-btn { width: 38px; height: 38px; }
  .player-card { min-height: 52px; padding: 8px 10px; gap: 10px; }
  .pc-avatar { width: 32px; height: 32px; }
  .chip { padding: 4px 8px; font-size: 0.74rem; }
  .chip .lbl { display: none; }
  .actions { grid-template-columns: 1fr 1fr; }
  .actions .btn.primary { grid-column: 1 / -1; }
  .choice-grid.three { grid-template-columns: 1fr; }
  .choice { flex-direction: row; justify-content: flex-start; padding: 12px 14px; }
  .levels button { font-size: 0.68rem; }
  .modal-card { padding: 22px 16px 16px; }
  .themes { grid-template-columns: repeat(2, 1fr); }
  .rules-grid { grid-template-columns: 1fr; gap: 10px; }
  .rule { display: grid; grid-template-columns: 40% 1fr; gap: 12px; align-items: start; padding: 10px; }
  .rule h3 { margin-top: 0; }
  .rule p { font-size: 0.82rem; }
  .over-actions { grid-template-columns: 1fr; }
}

@media (max-height: 620px) and (min-width: 961px) {
  :root { --board-size: min(calc(100vh - 210px), calc(100vw - 480px), 720px); }
}

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