/* =============================================================================
   Gambit — chess parlour
   1. tokens & themes   2. shell   3. board   4. pieces   5. panel
   6. controls          7. dialogs  8. motion/responsive
   ============================================================================= */

/* ------------------------------------------------------------------ 1. tokens */
:root {
  --font-display: 'Cormorant Garamond', 'Iowan Old Style', Georgia, serif;
  --font-ui: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --radius: 16px;
  --radius-sm: 10px;
  --ease: cubic-bezier(.22, .8, .28, 1);
  --ease-out: cubic-bezier(.16, 1, .3, 1);
}

html[data-theme="obsidian"] {
  --bg0: #05070d; --bg1: #0a1020; --bg2: #101a2e;
  --halo1: #2b4c8f; --halo2: #7a4b23; --halo3: #1b6b6a;
  --ink: #eef2fb; --ink-2: #a9b5cc; --ink-3: #6d7995;
  --panel: rgba(16, 23, 38, .72); --panel-2: rgba(255, 255, 255, .045);
  --line: rgba(255, 255, 255, .09); --line-2: rgba(255, 255, 255, .16);
  --accent: #e8c07a; --accent-ink: #1a1305; --accent-2: #7fb2e8;
  --sq-l: #d9dee9; --sq-l2: #bcc4d4; --sq-d: #23304a; --sq-d2: #16203a;
  --frame-1: #1d2740; --frame-2: #0a1020; --frame-edge: rgba(232, 192, 122, .45);
  --pw1: #fffdf6; --pw2: #f0ead9; --pw3: #b9b09c;
  --pb1: #6a7488; --pb2: #333c4e; --pb3: #10141d;
  --piece-line-w: rgba(92, 78, 52, .55); --piece-line-b: rgba(6, 8, 14, .8);
  --piece-detail: rgba(70, 60, 40, .45); --piece-eye: #2b2417;
  --glw: #f4f0e4; --glb: #8e98ad;
  --ok: #74d6a2; --bad: #f2777a;
}
html[data-theme="walnut"] {
  --bg0: #120c07; --bg1: #1b120a; --bg2: #241708;
  --halo1: #8a5a22; --halo2: #4a2b12; --halo3: #6b7a3a;
  --ink: #f7eee0; --ink-2: #c8b39a; --ink-3: #8d7a63;
  --panel: rgba(32, 22, 13, .74); --panel-2: rgba(255, 236, 200, .05);
  --line: rgba(255, 226, 190, .1); --line-2: rgba(255, 226, 190, .2);
  --accent: #e8b057; --accent-ink: #24170a; --accent-2: #9fc79a;
  --sq-l: #ecdab7; --sq-l2: #d6bf95; --sq-d: #6d4a2f; --sq-d2: #573823;
  --frame-1: #3a2415; --frame-2: #170e07; --frame-edge: rgba(232, 176, 87, .4);
  --pw1: #fffaf0; --pw2: #f0e2c8; --pw3: #bda883;
  --pb1: #6a4a33; --pb2: #3a281b; --pb3: #170f0a;
  --piece-line-w: rgba(90, 62, 30, .5); --piece-line-b: rgba(20, 10, 4, .8);
  --piece-detail: rgba(80, 52, 22, .5); --piece-eye: #2a1c0e;
  --glw: #f6ecd8; --glb: #8a6a4c;
  --ok: #a8d17a; --bad: #ef8168;
}
html[data-theme="lagoon"] {
  --bg0: #03101a; --bg1: #061b28; --bg2: #072533;
  --halo1: #0e6f7f; --halo2: #16588f; --halo3: #9b6a2f;
  --ink: #eafaf7; --ink-2: #9fc7c6; --ink-3: #5f8a8e;
  --panel: rgba(8, 32, 42, .74); --panel-2: rgba(210, 255, 250, .05);
  --line: rgba(200, 255, 248, .1); --line-2: rgba(200, 255, 248, .2);
  --accent: #63e0c4; --accent-ink: #04231d; --accent-2: #7cc4f0;
  --sq-l: #d6ece6; --sq-l2: #b3d2cc; --sq-d: #1c5b60; --sq-d2: #14454b;
  --frame-1: #0d3b47; --frame-2: #04161f; --frame-edge: rgba(99, 224, 196, .4);
  --pw1: #ffffff; --pw2: #eaf4ef; --pw3: #adcbc6;
  --pb1: #4f7f83; --pb2: #22454c; --pb3: #08181e;
  --piece-line-w: rgba(30, 80, 78, .5); --piece-line-b: rgba(2, 14, 18, .8);
  --piece-detail: rgba(20, 70, 68, .45); --piece-eye: #08201f;
  --glw: #f0fbf6; --glb: #79a8ab;
  --ok: #6fe0a8; --bad: #f0857f;
}
html[data-theme="rosewood"] {
  --bg0: #14090a; --bg1: #200e0d; --bg2: #2c1312;
  --halo1: #93383c; --halo2: #6b3f18; --halo3: #7d5a7a;
  --ink: #fbede6; --ink-2: #d0aca4; --ink-3: #95726d;
  --panel: rgba(36, 16, 16, .74); --panel-2: rgba(255, 220, 200, .05);
  --line: rgba(255, 216, 196, .1); --line-2: rgba(255, 216, 196, .2);
  --accent: #f0b27a; --accent-ink: #2a1408; --accent-2: #e79aa0;
  --sq-l: #f2dcc2; --sq-l2: #ddc0a1; --sq-d: #7e3f31; --sq-d2: #66312a;
  --frame-1: #48211c; --frame-2: #1a0908; --frame-edge: rgba(240, 178, 122, .4);
  --pw1: #fffaf4; --pw2: #f4e5d2; --pw3: #c1a888;
  --pb1: #7a4c42; --pb2: #452520; --pb3: #1b0c0a;
  --piece-line-w: rgba(90, 50, 30, .5); --piece-line-b: rgba(18, 6, 4, .8);
  --piece-detail: rgba(86, 44, 26, .5); --piece-eye: #2b1210;
  --glw: #f8ecdc; --glb: #9a6f63;
  --ok: #86d19d; --bad: #f2756e;
}
html[data-theme="slate"] {
  --bg0: #080d10; --bg1: #0e161a; --bg2: #131f24;
  --halo1: #2f6d63; --halo2: #3d5570; --halo3: #7d6a3a;
  --ink: #eef7f5; --ink-2: #a5bcbb; --ink-3: #6b8382;
  --panel: rgba(17, 28, 32, .74); --panel-2: rgba(220, 255, 250, .05);
  --line: rgba(220, 255, 250, .1); --line-2: rgba(220, 255, 250, .19);
  --accent: #7fe3c0; --accent-ink: #05231b; --accent-2: #8fc6ee;
  --sq-l: #dde7e4; --sq-l2: #bccbc9; --sq-d: #3c4f56; --sq-d2: #2c3c43;
  --frame-1: #22343b; --frame-2: #0a1417; --frame-edge: rgba(127, 227, 192, .38);
  --pw1: #ffffff; --pw2: #ecf4f1; --pw3: #aebebc;
  --pb1: #5c7a80; --pb2: #2b3e44; --pb3: #0d171b;
  --piece-line-w: rgba(40, 70, 70, .5); --piece-line-b: rgba(4, 12, 14, .8);
  --piece-detail: rgba(35, 68, 68, .45); --piece-eye: #10201f;
  --glw: #f2faf7; --glb: #7d9a9d;
  --ok: #7fe3c0; --bad: #f08a86;
}

/* ------------------------------------------------------------------ 2. shell */
* { box-sizing: border-box; }
/* An author `display:` rule outranks the UA stylesheet, so anything toggled with
   the hidden attribute needs this guard or it never leaves the screen. */
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-ui);
  color: var(--ink);
  background: radial-gradient(150% 110% at 50% -10%, var(--bg1), var(--bg0) 62%);
  display: flex; flex-direction: column;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
@media (max-width: 1060px) { body { overflow: auto; } }

.ambient { position: fixed; inset: 0; z-index: 0; overflow: hidden; pointer-events: none; }
.glow { position: absolute; border-radius: 50%; filter: blur(90px); opacity: .5; mix-blend-mode: screen; }
.glow.g1 { width: 60vw; height: 60vw; left: -14vw; top: -18vw; background: radial-gradient(circle at 40% 40%, var(--halo1), transparent 62%); animation: drift1 34s var(--ease) infinite alternate; }
.glow.g2 { width: 52vw; height: 52vw; right: -12vw; top: 4vh; background: radial-gradient(circle at 55% 45%, var(--halo2), transparent 62%); animation: drift2 41s var(--ease) infinite alternate; }
.glow.g3 { width: 46vw; height: 46vw; left: 26vw; bottom: -22vw; background: radial-gradient(circle at 50% 50%, var(--halo3), transparent 60%); animation: drift1 47s var(--ease) infinite alternate-reverse; }
@keyframes drift1 { to { transform: translate3d(7vw, 5vh, 0) scale(1.14); } }
@keyframes drift2 { to { transform: translate3d(-6vw, 7vh, 0) scale(1.09); } }
.grain {
  position: absolute; inset: -50%;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)' opacity='.5'/%3E%3C/svg%3E");
  opacity: .045; animation: grainshift 7s steps(6) infinite;
}
@keyframes grainshift { to { transform: translate3d(3%, -4%, 0); } }
body::after {
  content: ''; position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background: radial-gradient(120% 100% at 50% 0%, transparent 40%, rgba(0, 0, 0, .55) 100%);
}

.topbar {
  position: relative; z-index: 3;
  display: flex; align-items: center; gap: 18px;
  padding: 14px clamp(14px, 3vw, 34px) 10px;
}
.brand { display: flex; align-items: center; gap: 12px; margin-right: auto; }
.brand .mark {
  width: 40px; height: 40px; display: grid; place-items: center;
  font-size: 25px; color: var(--accent-ink);
  background: linear-gradient(160deg, var(--accent), color-mix(in srgb, var(--accent) 55%, #000));
  border-radius: 12px; box-shadow: 0 6px 18px -6px var(--accent), inset 0 1px 0 rgba(255, 255, 255, .5);
}
.wordmark { display: flex; flex-direction: column; line-height: 1.05; }
.wordmark b { font-family: var(--font-display); font-size: 23px; letter-spacing: .24em; font-weight: 600; }
.wordmark i { font-size: 10.5px; letter-spacing: .3em; text-transform: uppercase; color: var(--ink-3); font-style: normal; }

.modes { display: flex; gap: 4px; padding: 4px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--line); }
.tools { display: flex; align-items: center; gap: 8px; }

button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
button:focus-visible, select:focus-visible, input:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.chip, .icon, .primary, .ghost, .controls button, .opts button, .share-body button, .fenrow button {
  border-radius: var(--radius-sm); border: 1px solid var(--line);
  background: var(--panel-2); color: var(--ink-2);
  padding: 8px 13px; font-size: 12.5px; font-weight: 550; letter-spacing: .01em;
  transition: transform .16s var(--ease), background .2s, color .2s, border-color .2s, box-shadow .2s;
}
.chip:hover, .icon:hover, .controls button:hover, .opts button:hover, .share-body button:hover {
  color: var(--ink); background: color-mix(in srgb, var(--accent) 12%, var(--panel-2)); border-color: var(--line-2);
  transform: translateY(-1px);
}
.chip:active, .controls button:active, .opts button:active { transform: translateY(0) scale(.98); }
.chip.is-on, .opts button.on {
  color: var(--accent-ink); border-color: transparent;
  background: linear-gradient(165deg, var(--accent), color-mix(in srgb, var(--accent) 68%, #000));
  box-shadow: 0 6px 16px -8px var(--accent);
}
.icon { width: 36px; height: 36px; display: grid; place-items: center; padding: 0; font-size: 14px; }
.icon[aria-pressed="false"] { opacity: .42; }
.primary {
  color: var(--accent-ink); border-color: transparent;
  background: linear-gradient(165deg, var(--accent), color-mix(in srgb, var(--accent) 66%, #000));
  box-shadow: 0 8px 22px -10px var(--accent); font-weight: 650;
}
.primary:hover { filter: brightness(1.07); transform: translateY(-1px); }
.ghost { color: var(--ink-2); }
button:disabled { opacity: .35; pointer-events: none; }

/* ------------------------------------------------------------------ 3. board */
.stage {
  position: relative; z-index: 2; flex: 1; min-height: 0;
  display: grid; grid-template-columns: minmax(0, 1fr) clamp(310px, 26vw, 384px);
  gap: clamp(14px, 2.2vw, 30px);
  padding: 4px clamp(14px, 3vw, 34px) clamp(12px, 2vh, 22px);
  align-items: start;
}
.table { display: flex; flex-direction: column; align-items: center; gap: 9px; min-width: 0; }
.boardzone { display: flex; gap: 12px; align-items: stretch; width: 100%; justify-content: center; }

.frame {
  position: relative;
  width: min(100%, calc(100dvh - 268px));
  min-width: 300px; aspect-ratio: 1;
  padding: clamp(9px, 1.2vw, 15px);
  border-radius: calc(var(--radius) + 6px);
  background:
    linear-gradient(150deg, var(--frame-1), var(--frame-2) 62%),
    var(--frame-2);
  box-shadow:
    0 46px 90px -40px rgba(0, 0, 0, .95),
    0 2px 0 rgba(255, 255, 255, .07) inset,
    0 -2px 12px rgba(0, 0, 0, .6) inset,
    0 0 0 1px var(--line);
}
.frame::before {
  content: ''; position: absolute; inset: 6px; border-radius: var(--radius);
  border: 1px solid var(--frame-edge); opacity: .5; pointer-events: none;
}
.frame::after {
  content: 'GAMBIT'; position: absolute; right: 14px; bottom: 6px;
  font-size: 8px; letter-spacing: .36em; color: var(--frame-edge); opacity: .85;
}
html[data-coord="off"] .frame::after { display: none; }

.board {
  position: relative; width: 100%; height: 100%;
  border-radius: 8px; overflow: hidden;
  isolation: isolate;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .5), 0 18px 40px -22px rgba(0, 0, 0, .9);
  touch-action: none;
}
.board:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }
.squares, .marks { position: absolute; inset: 0; display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr); }
.squares { z-index: 1; }
.marks { z-index: 2; pointer-events: none; }
.pieces { position: absolute; inset: 0; z-index: 3; }
.arrows, .fx { position: absolute; inset: 0; z-index: 4; pointer-events: none; width: 100%; height: 100%; }

.sq { position: relative; }
.sq.l { background: linear-gradient(157deg, var(--sq-l), var(--sq-l2)); }
.sq.d { background: linear-gradient(157deg, var(--sq-d2), var(--sq-d)); }
.sq::after {
  content: ''; position: absolute; inset: 0;
  background: radial-gradient(120% 120% at 22% 12%, rgba(255, 255, 255, .16), transparent 46%);
  opacity: .8;
}
/* woven texture over the whole board */
.board::before {
  content: ''; position: absolute; inset: 0; z-index: 2; pointer-events: none;
  background-image:
    repeating-linear-gradient(45deg, rgba(255, 255, 255, .028) 0 1px, transparent 1px 4px),
    radial-gradient(115% 95% at 50% -10%, rgba(255, 255, 255, .12), transparent 55%),
    radial-gradient(120% 120% at 50% 120%, rgba(0, 0, 0, .4), transparent 55%);
}

/* coordinate etching on the outer ring of squares */
.sq .coord {
  position: absolute; font-size: clamp(7px, 1.05vw, 10.5px); font-weight: 650;
  letter-spacing: .04em; opacity: .55; pointer-events: none;
}
.sq.file-lab .coord { bottom: 2px; right: 3px; }
.sq.rank-lab .coord { top: 2px; left: 3px; }
.sq.l .coord { color: color-mix(in srgb, var(--sq-d) 80%, #000); }
.sq.d .coord { color: color-mix(in srgb, var(--sq-l) 78%, #fff); }
html[data-coord="off"] .sq .coord { display: none; }

/* square states */
.mk { display: grid; place-items: center; position: relative; }
.mk::before, .mk::after { content: ''; position: absolute; }
.mk.from::before, .mk.lastfrom::before {
  inset: 0; background: linear-gradient(160deg, color-mix(in srgb, var(--accent) 42%, transparent), color-mix(in srgb, var(--accent) 16%, transparent));
  box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--accent) 55%, transparent);
}
.mk.lastto::before {
  inset: 0; background: linear-gradient(160deg, color-mix(in srgb, var(--accent) 52%, transparent), color-mix(in srgb, var(--accent) 22%, transparent));
  box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--accent) 72%, transparent);
}
.mk.sel::before {
  inset: 0; background: radial-gradient(circle at 50% 50%, color-mix(in srgb, var(--accent) 40%, transparent), color-mix(in srgb, var(--accent) 12%, transparent));
  box-shadow: inset 0 0 0 2.5px var(--accent), 0 0 22px -4px var(--accent) inset;
  animation: selRing 1.9s ease-in-out infinite;
}
@keyframes selRing { 50% { box-shadow: inset 0 0 0 2.5px color-mix(in srgb, var(--accent) 55%, transparent), 0 0 26px -2px var(--accent) inset; } }
.mk.move::after {
  inset: 36.5%; border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, color-mix(in srgb, var(--accent-2) 90%, #fff 12%), color-mix(in srgb, var(--accent-2) 55%, #000));
  opacity: .68; box-shadow: 0 1px 5px rgba(0, 0, 0, .45);
  transition: transform .15s var(--ease), opacity .15s;
}
.mk.move.hovered::after { transform: scale(1.55); opacity: .95; }
.mk.cap::after {
  inset: 7%; border-radius: 50%;
  box-shadow: inset 0 0 0 3.5px color-mix(in srgb, var(--bad) 88%, transparent);
  background: radial-gradient(circle, transparent 58%, color-mix(in srgb, var(--bad) 34%, transparent));
  opacity: .85;
}
.mk.cap.hovered::after { inset: 4%; opacity: 1; }
.mk.hint::before {
  inset: 0; background: color-mix(in srgb, var(--ok) 22%, transparent);
  box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--ok) 70%, transparent);
  animation: hintFade 2.4s ease-in-out 1 both;
}
@keyframes hintFade { 0%, 12% { opacity: 0; } 30%, 80% { opacity: 1; } 100% { opacity: .35; } }
.mk.check::before {
  inset: -12%;
  background: radial-gradient(circle at 50% 50%, color-mix(in srgb, var(--bad) 78%, transparent), transparent 62%);
  animation: checkPulse 1.15s ease-in-out infinite;
}
@keyframes checkPulse { 50% { opacity: .45; transform: scale(.9); } }

/* ------------------------------------------------------------------ 4. pieces */
.piece {
  position: absolute; top: 0; left: 0; width: 12.5%; height: 12.5%;
  transform: translate(calc(var(--x) * 100%), calc(var(--y) * 100%));
  transition: transform .19s var(--ease);
  will-change: transform; cursor: default; z-index: 1;
}
.piece.mine { cursor: grab; }
.piece.dragging { transition: none; z-index: 40; cursor: grabbing; }
.piece.dragging .pc { filter: drop-shadow(0 14px 14px rgba(0, 0, 0, .55)) brightness(1.06); }
.piece.pop { animation: popIn .34s var(--ease-out) both; }
.piece.drop-in .pc { animation: dropIn .34s var(--ease-out) both; }
@keyframes dropIn { from { transform: translateY(-7%) scale(1.07); opacity: .15; } }
.piece.captured { animation: vanish .28s ease-in forwards; pointer-events: none; }
@keyframes vanish {
  to { opacity: 0; filter: brightness(1.7); transform: translate(calc(var(--x) * 100%), calc(var(--y) * 100%)) scale(.62) rotate(6deg); }
}
@keyframes popIn { from { opacity: 0; } to { opacity: 1; } }
.pc { width: 100%; height: 100%; display: block; filter: drop-shadow(0 3px 3px rgba(0, 0, 0, .42)); }
.pf { stroke-linejoin: round; stroke-width: 1.15; }
.pc-w .pf { fill: url(#pcw); stroke: var(--piece-line-w); }
.pc-b .pf { fill: url(#pcb); stroke: var(--piece-line-b); }
.pc-w .pf.alt { fill: url(#pcwd); }
.pc-b .pf.alt { fill: url(#pcbd); }
.pl { fill: none; stroke: var(--piece-detail); stroke-width: 1.5; stroke-linecap: round; opacity: .55; }
.pc-b .pl { stroke: rgba(255, 255, 255, .3); opacity: .5; }
.pd { fill: var(--piece-eye); }
#piece-defs { position: absolute; width: 0; height: 0; overflow: hidden; }
#pcw .w1 { stop-color: var(--pw1); } #pcw .w2 { stop-color: var(--pw2); } #pcw .w3 { stop-color: var(--pw3); }
#pcb .b1 { stop-color: var(--pb1); } #pcb .b2 { stop-color: var(--pb2); } #pcb .b3 { stop-color: var(--pb3); }
#pcwd .w1 { stop-color: var(--pw1); } #pcwd .w3 { stop-color: var(--pw3); }
#pcbd .b1 { stop-color: var(--pb1); } #pcbd .b3 { stop-color: var(--pb3); }

/* capture sparks */
.burst { position: absolute; width: 12.5%; height: 12.5%; pointer-events: none; }
.burst i {
  position: absolute; left: 50%; top: 50%; width: 6px; height: 6px; margin: -3px;
  border-radius: 50%; background: var(--accent);
  animation: spark .62s var(--ease-out) forwards;
}
@keyframes spark {
  from { transform: rotate(var(--a)) translateX(6%) scale(1); opacity: .95; }
  to { transform: rotate(var(--a)) translateX(var(--d, 70%)) scale(.15); opacity: 0; }
}
.arrows path { fill: none; stroke: var(--ok); stroke-width: 9; stroke-linecap: round; opacity: .82; }
.arrows path.opp { stroke: var(--bad); }
.arrows polygon { fill: var(--ok); opacity: .9; }
.arrows polygon.opp { fill: var(--bad); }

/* veil over board during game end */
.veil { position: absolute; inset: 0; z-index: 45; display: grid; place-items: center; background: rgba(6, 8, 14, .55); backdrop-filter: blur(3px); animation: fade .3s both; }
.veilcard {
  padding: 16px 22px; border-radius: 14px; background: var(--panel); border: 1px solid var(--line-2);
  font-family: var(--font-display); font-size: 22px; letter-spacing: .02em; text-align: center;
  box-shadow: 0 30px 60px -30px #000;
}
.veilcard small { display: block; font-family: var(--font-ui); font-size: 11.5px; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-3); margin-top: 5px; }

/* player bars */
.playerbar {
  width: min(100%, calc(100dvh - 268px)); min-width: 300px;
  display: flex; align-items: center; gap: 11px;
  padding: 7px 12px; border-radius: 13px;
  background: var(--panel); border: 1px solid var(--line);
  box-shadow: 0 16px 34px -26px rgba(0, 0, 0, .9);
  transition: border-color .3s, box-shadow .3s;
}
.playerbar.active { border-color: color-mix(in srgb, var(--accent) 55%, transparent); box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 25%, transparent), 0 16px 34px -26px rgba(0, 0, 0, .9); }
.avatar {
  width: 34px; height: 34px; flex: none; display: grid; place-items: center;
  border-radius: 10px; font-size: 19px; line-height: 1;
  background: linear-gradient(160deg, color-mix(in srgb, var(--accent) 22%, transparent), var(--panel-2));
  border: 1px solid var(--line-2); color: var(--glw);
}
.playerbar[data-color="b"] .avatar { color: var(--glb); }
.who { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.who b { font-size: 13.5px; font-weight: 650; letter-spacing: .01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who em { font-style: normal; font-size: 10.5px; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-3); }
.tray { display: flex; flex-wrap: wrap; gap: 1px; flex: 1; min-width: 0; align-items: center; }
.tray i { font-style: normal; font-size: 15px; line-height: 1; opacity: .82; }
.tray i.glyph { font-style: normal; }
.adv { font-size: 12px; font-weight: 700; color: var(--accent-2); min-width: 22px; text-align: right; }
.clock {
  flex: none; font-variant-numeric: tabular-nums; font-size: 15px; font-weight: 650;
  padding: 6px 11px; border-radius: 9px; border: 1px solid var(--line);
  background: var(--panel-2); letter-spacing: .03em;
}
.clock.run { border-color: color-mix(in srgb, var(--accent) 45%, transparent); color: var(--ink); }
.clock.low { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 50%, transparent); animation: lowPulse 1s ease-in-out infinite; }
@keyframes lowPulse { 50% { background: color-mix(in srgb, var(--bad) 16%, transparent); } }

/* eval rail */
.evalrail {
  position: relative; width: 15px; border-radius: 8px; overflow: hidden;
  background: linear-gradient(180deg, #10141d, #05070d);
  border: 1px solid var(--line); flex: none;
}
.evalfill {
  position: absolute; left: 0; right: 0; bottom: 0; height: 50%;
  background: linear-gradient(180deg, var(--pw1), var(--pw2));
  transition: height .5s var(--ease);
  box-shadow: 0 0 14px -2px rgba(255, 255, 255, .4);
}
.evalnotch { position: absolute; left: 0; right: 0; top: 50%; height: 1px; background: var(--accent); opacity: .55; }
.evaltext {
  position: absolute; bottom: 4px; left: 50%; transform: translateX(-50%) rotate(-90deg);
  font-size: 8px; font-weight: 700; color: var(--ink-3); letter-spacing: .06em; white-space: nowrap;
}

/* ------------------------------------------------------------------ 5. panel */
.panel {
  display: flex; flex-direction: column; gap: 11px; min-width: 0;
  padding: 15px; border-radius: var(--radius);
  background: var(--panel); border: 1px solid var(--line);
  backdrop-filter: blur(20px) saturate(1.25);
  box-shadow: 0 40px 80px -50px rgba(0, 0, 0, .95), inset 0 1px 0 rgba(255, 255, 255, .05);
  max-height: calc(100dvh - 96px); overflow: auto; scrollbar-width: thin;
}
.statusrow { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 22px; }
.toplay { font-family: var(--font-display); font-size: 18px; letter-spacing: .01em; }
.toplay.check { color: var(--bad); }
.toplay.win { color: var(--ok); }
.thinking { display: flex; align-items: center; gap: 5px; font-size: 10.5px; letter-spacing: .14em; text-transform: uppercase; color: var(--accent); }
.thinking i { width: 5px; height: 5px; border-radius: 50%; background: var(--accent); animation: dots 1.1s ease-in-out infinite; }
.thinking i:nth-child(2) { animation-delay: .15s; } .thinking i:nth-child(3) { animation-delay: .3s; }
@keyframes dots { 0%, 60%, 100% { opacity: .25; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }

.movelist { border: 1px solid var(--line); border-radius: 12px; background: rgba(0, 0, 0, .22); }
.movelist-scroll { max-height: clamp(140px, 26dvh, 260px); overflow: auto; padding: 5px; scrollbar-width: thin; }
.mrow { display: grid; grid-template-columns: 30px 1fr 1fr; gap: 4px; align-items: center; padding: 1px 2px; border-radius: 7px; }
.mrow:nth-child(odd) { background: rgba(255, 255, 255, .028); }
.mrow .no { font-size: 10.5px; color: var(--ink-3); font-variant-numeric: tabular-nums; text-align: right; padding-right: 4px; }
.mrow button {
  text-align: left; padding: 4px 7px; border-radius: 6px; font-size: 13px; font-weight: 550;
  color: var(--ink-2); font-variant-numeric: tabular-nums; transition: background .15s, color .15s;
}
.mrow button:hover { background: var(--panel-2); color: var(--ink); }
.mrow button.cur { background: color-mix(in srgb, var(--accent) 24%, transparent); color: var(--ink); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 40%, transparent); }
.mrow button.black { color: color-mix(in srgb, var(--ink-2) 80%, var(--ink-3)); }
.movelist-empty { padding: 14px; font-size: 12px; color: var(--ink-3); text-align: center; }
.graphwrap { border-radius: 10px; border: 1px solid var(--line); background: rgba(0, 0, 0, .25); padding: 4px; }
#graph { width: 100%; height: 62px; display: block; }

/* ------------------------------------------------------------------ 6. controls */
.controls { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.controls .nav { width: 34px; padding: 8px 0; display: grid; place-items: center; font-size: 11px; }
.controls .sep { flex: 1; }
.panel-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.field { display: flex; flex-direction: column; gap: 5px; font-size: 10.5px; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-3); }
.field.wide { grid-column: 1 / -1; }
.field select, .field input[type=text] {
  font: inherit; text-transform: none; letter-spacing: 0; font-size: 12.5px;
  color: var(--ink); background: rgba(0, 0, 0, .3); border: 1px solid var(--line);
  border-radius: 9px; padding: 8px 10px;
}
.field.check { flex-direction: row; align-items: center; justify-content: space-between; gap: 8px; }
.field.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.share { border-top: 1px solid var(--line); padding-top: 9px; }
.share summary {
  cursor: pointer; font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-3); list-style: none;
}
.share summary::-webkit-details-marker { display: none; }
.share summary::before { content: '▸ '; }
.share[open] summary::before { content: '▾ '; }
.share-body { display: flex; flex-direction: column; gap: 9px; padding-top: 10px; }
.share-body .line { display: flex; gap: 6px; flex-wrap: wrap; }
.fenrow { display: flex; gap: 6px; }
.fenrow input { flex: 1; min-width: 0; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px !important; }
.engine-info { font-size: 11px; color: var(--ink-3); font-variant-numeric: tabular-nums; margin: 0; line-height: 1.5; }
.hintline { font-size: 10.5px; color: var(--ink-3); margin: 0; letter-spacing: .02em; }
kbd {
  font: inherit; font-size: 10px; padding: 1px 4px; border-radius: 4px;
  border: 1px solid var(--line-2); background: var(--panel-2); color: var(--ink-2); margin: 0 1px;
}

/* ------------------------------------------------------------------ 7. dialogs */
.modal {
  position: fixed; inset: 0; z-index: 60; display: grid; place-items: center;
  background: rgba(4, 6, 12, .62); backdrop-filter: blur(9px);
  animation: fade .22s both; padding: 20px;
}
@keyframes fade { from { opacity: 0; } }
.card {
  width: min(420px, 100%); padding: 22px 24px; border-radius: 20px;
  background: linear-gradient(165deg, color-mix(in srgb, var(--bg2) 92%, #fff 3%), var(--bg0));
  border: 1px solid var(--line-2);
  box-shadow: 0 50px 100px -40px rgba(0, 0, 0, .95), inset 0 1px 0 rgba(255, 255, 255, .07);
  animation: rise .32s var(--ease-out) both;
}
.card.wide { width: min(560px, 100%); }
.card.small { width: min(340px, 100%); text-align: center; }
@keyframes rise { from { opacity: 0; transform: translateY(16px) scale(.97); } }
.card h2 { font-family: var(--font-display); font-size: 27px; margin: 0 0 4px; font-weight: 600; }
.card h3 { font-family: var(--font-display); font-size: 20px; margin: 0 0 14px; font-weight: 600; }
.card p { color: var(--ink-2); font-size: 13.5px; margin: 0 0 16px; line-height: 1.55; }
.opt-group { margin: 15px 0; }
.opt-label { display: block; font-size: 10px; letter-spacing: .16em; text-transform: uppercase; color: var(--ink-3); margin-bottom: 7px; }
.opts { display: flex; flex-wrap: wrap; gap: 6px; }
.card-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 20px; }
.promo-row { display: flex; gap: 8px; justify-content: center; }
.promo-row button {
  width: 62px; height: 62px; border-radius: 14px; display: grid; place-items: center;
  background: var(--panel-2); border: 1px solid var(--line-2);
  transition: transform .16s var(--ease), background .2s, box-shadow .2s;
}
.promo-row button:hover { transform: translateY(-4px); background: color-mix(in srgb, var(--accent) 18%, var(--panel-2)); box-shadow: 0 14px 26px -14px var(--accent); }
.promo-row .pc { width: 44px; height: 44px; }

.toast {
  position: fixed; z-index: 80; left: 50%; bottom: 26px; transform: translateX(-50%);
  padding: 10px 16px; border-radius: 11px; font-size: 12.5px; font-weight: 550;
  background: var(--panel); border: 1px solid var(--line-2); color: var(--ink);
  box-shadow: 0 24px 50px -24px rgba(0, 0, 0, .9); animation: rise .25s var(--ease-out) both;
}

/* ------------------------------------------------------------------ 8. responsive */
@media (max-width: 1060px) {
  .stage { grid-template-columns: minmax(0, 1fr); }
  .panel { max-height: none; }
  .frame, .playerbar { width: min(100%, 620px); }
  .evalrail { height: auto; }
}
@media (max-width: 720px) {
  .wordmark i, .modes .chip:not(.is-on) { display: none; }
  .modes { padding: 3px; }
  .topbar { gap: 8px; padding-bottom: 6px; }
  .brand .mark { width: 34px; height: 34px; font-size: 21px; }
  .panel-grid { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001s !important; animation-iteration-count: 1 !important; transition-duration: .06s !important; }
}
