/* Chess — a wooden, marble or night board between two players. The page
   follows the system's light or dark; the board is its own object with its
   own materials under [data-board]. Pieces are SVG symbols coloured from
   custom properties; everything that moves uses transform and opacity. */

:root {
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --ease: cubic-bezier(0.4, 0.1, 0.2, 1);
  --spring: cubic-bezier(0.25, 0.8, 0.3, 1.15);
  --glide-ease: cubic-bezier(0.3, 0.65, 0.25, 1);
  --turn-ease: cubic-bezier(0.45, 0.05, 0.3, 1);
  --turn-ms: 760ms;

  color-scheme: light;
  --bg-a: #f0e9dd;
  --bg-b: #d8cdbb;
  --glow-1: rgba(255, 250, 240, 0.9);
  --glow-2: rgba(160, 102, 42, 0.13);
  --ink: #2b241c;
  --ink-soft: #6c6153;
  --chip-bg: rgba(255, 255, 255, 0.46);
  --chip-line: rgba(255, 255, 255, 0.7);
  --chip-shadow: 0 1px 2px rgba(60, 45, 30, 0.08);
  --active-bg: rgba(255, 255, 255, 0.86);
  --btn-bg: rgba(255, 255, 255, 0.55);
  --btn-hover: rgba(255, 255, 255, 0.88);
  --btn-line: rgba(60, 45, 30, 0.14);
  --primary-a: #a96f33;
  --primary-b: #7f4c1d;
  --primary-line: #5a3412;
  --primary-ink: #fff7ea;
  --paper: #faf6ef;
  --paper-2: #efe8dc;
  --line: rgba(60, 45, 30, 0.13);
  --accent: #9b5f22;
  --accent-soft: rgba(155, 95, 34, 0.2);
  --danger: #b4432c;
  --backdrop: rgba(40, 30, 18, 0.38);
  --toast: rgba(36, 29, 22, 0.93);
  --clock-bg: rgba(255, 255, 255, 0.6);
  --clock-ink: #3a3026;
  --clock-on-bg: #2e261e;
  --clock-on-ink: #fff6e6;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg-a: #211b16;
    --bg-b: #0d0a08;
    --glow-1: rgba(217, 163, 92, 0.1);
    --glow-2: rgba(120, 150, 200, 0.07);
    --ink: #f2e9db;
    --ink-soft: rgba(242, 233, 219, 0.62);
    --chip-bg: rgba(255, 236, 214, 0.05);
    --chip-line: rgba(255, 222, 186, 0.1);
    --chip-shadow: none;
    --active-bg: rgba(255, 236, 214, 0.11);
    --btn-bg: rgba(255, 236, 214, 0.06);
    --btn-hover: rgba(255, 236, 214, 0.12);
    --btn-line: rgba(255, 222, 186, 0.14);
    --primary-a: #c98d4a;
    --primary-b: #9a6125;
    --primary-line: #5e3610;
    --primary-ink: #fff6e8;
    --paper: #1f1914;
    --paper-2: #2b231d;
    --line: rgba(255, 222, 186, 0.11);
    --accent: #e0aa62;
    --accent-soft: rgba(224, 170, 98, 0.2);
    --danger: #e3735a;
    --backdrop: rgba(4, 2, 1, 0.6);
    --toast: rgba(46, 37, 30, 0.96);
    --clock-bg: rgba(255, 236, 214, 0.07);
    --clock-ink: #efe4d3;
    --clock-on-bg: #efe2cc;
    --clock-on-ink: #241c15;
  }
}

/* ------------------------------------------------------------- boards */
/* walnut: maple and walnut veneer, a dark walnut frame, a brass inlay */
:root,
[data-board="walnut"] {
  --frame-bg: var(--frame-img, none) center / 100% 100%, #47291a;
  --frame-ring: 0 0 0 1px rgba(20, 10, 4, 0.6), inset 0 0 0 1px rgba(255, 220, 180, 0.12);
  --frame-light: linear-gradient(150deg, rgba(255, 228, 196, 0.26), rgba(255, 255, 255, 0) 34%, rgba(0, 0, 0, 0) 62%, rgba(0, 0, 0, 0.26));
  --inlay: #c9a35d;
  --bevel: inset 0 0 0 1px rgba(40, 20, 8, 0.55), 0 0 0 1.5px rgba(255, 226, 180, 0.22);
  --coord: rgba(238, 214, 175, 0.78);
  --coord-shadow: 0 -1px 0 rgba(0, 0, 0, 0.55);
  --squares-bg: var(--squares-img, none) center / 100% 100%, #c9a57a;
  --gloss: radial-gradient(120% 90% at 22% 8%, rgba(255, 246, 228, 0.22), rgba(255, 255, 255, 0) 58%);
  --last: rgba(242, 196, 92, 0.42);
  --sel: rgba(250, 214, 120, 0.55);
  --dot: rgba(42, 22, 8, 0.4);
  --ring: rgba(42, 22, 8, 0.36);
  --hover: rgba(255, 246, 220, 0.85);
  --focus: #fff1c9;
  --check: rgba(214, 52, 34, 0.85);
  --pcw-a: #e9dcc0; --pcw-b: #fffaf0; --pcw-c: #efe2c7; --pcw-d: #c8b28a;
  --pcw-line: #45362a; --pcw-groove: #7d6650; --pcw-shine: #ffffff;
  --pcb-a: #3a3330; --pcb-b: #5d544d; --pcb-c: #2a2421; --pcb-d: #0e0c0b;
  --pcb-line: #0b0908; --pcb-groove: #8d8072; --pcb-shine: #fff3e2;
  --pc-shadow: rgba(30, 14, 4, 0.45);
}

/* marble: Carrara and verde, a dark stone frame with a gold inlay */
[data-board="marble"] {
  --frame-bg: var(--frame-img, none) center / 100% 100%, #353c3a;
  --frame-ring: 0 0 0 1px rgba(0, 0, 0, 0.55), inset 0 0 0 1px rgba(255, 255, 255, 0.1);
  --frame-light: linear-gradient(150deg, rgba(255, 255, 255, 0.24), rgba(255, 255, 255, 0) 36%, rgba(0, 0, 0, 0) 60%, rgba(0, 0, 0, 0.24));
  --inlay: #cdb173;
  --bevel: inset 0 0 0 1px rgba(0, 0, 0, 0.4), 0 0 0 1.5px rgba(255, 255, 255, 0.16);
  --coord: rgba(226, 232, 228, 0.72);
  --coord-shadow: 0 -1px 0 rgba(0, 0, 0, 0.5);
  --squares-bg: var(--squares-img, none) center / 100% 100%, #b8beb8;
  --gloss: radial-gradient(120% 90% at 22% 8%, rgba(255, 255, 255, 0.34), rgba(255, 255, 255, 0) 55%);
  --last: rgba(214, 178, 84, 0.45);
  --sel: rgba(226, 196, 110, 0.55);
  --dot: rgba(24, 36, 32, 0.38);
  --ring: rgba(24, 36, 32, 0.34);
  --hover: rgba(255, 255, 255, 0.9);
  --focus: #fff4d0;
  --check: rgba(206, 50, 38, 0.85);
  --pcw-a: #ece6db; --pcw-b: #ffffff; --pcw-c: #efeae1; --pcw-d: #c3bcae;
  --pcw-line: #3b3a36; --pcw-groove: #78736a; --pcw-shine: #ffffff;
  --pcb-a: #343a3a; --pcb-b: #57605e; --pcb-c: #262b2b; --pcb-d: #0c0f0f;
  --pcb-line: #080a0a; --pcb-groove: #8f9a96; --pcb-shine: #eef8f4;
  --pc-shadow: rgba(10, 18, 16, 0.42);
}

/* night: blue slate in an ink frame, a silver inlay */
[data-board="night"] {
  --frame-bg: linear-gradient(160deg, #1a212d 0%, #0e131b 48%, #080b10 100%);
  --frame-ring: 0 0 0 1px rgba(0, 0, 0, 0.7), inset 0 0 0 1px rgba(190, 210, 240, 0.1);
  --frame-light: linear-gradient(150deg, rgba(200, 220, 255, 0.16), rgba(255, 255, 255, 0) 32%, rgba(0, 0, 0, 0) 64%, rgba(0, 0, 0, 0.3));
  --inlay: #aeb9c9;
  --bevel: inset 0 0 0 1px rgba(0, 0, 0, 0.5), 0 0 0 1.5px rgba(190, 210, 240, 0.12);
  --coord: rgba(186, 200, 222, 0.62);
  --coord-shadow: 0 -1px 0 rgba(0, 0, 0, 0.7);
  --squares-bg: var(--squares-img, none) center / 100% 100%, #5f6e83;
  --gloss: radial-gradient(120% 90% at 22% 8%, rgba(210, 226, 255, 0.16), rgba(255, 255, 255, 0) 56%);
  --last: rgba(150, 196, 255, 0.32);
  --sel: rgba(170, 210, 255, 0.42);
  --dot: rgba(4, 8, 16, 0.5);
  --ring: rgba(4, 8, 16, 0.46);
  --hover: rgba(214, 230, 255, 0.85);
  --focus: #d8e7ff;
  --check: rgba(232, 76, 60, 0.85);
  --pcw-a: #e6e2d8; --pcw-b: #fdfbf6; --pcw-c: #ebe6dc; --pcw-d: #b9b2a4;
  --pcw-line: #2b2e36; --pcw-groove: #6e7280; --pcw-shine: #ffffff;
  --pcb-a: #2d3440; --pcb-b: #4f5a6b; --pcb-c: #1f2530; --pcb-d: #090c11;
  --pcb-line: #05070a; --pcb-groove: #8b9ab0; --pcb-shine: #e4eeff;
  --pc-shadow: rgba(0, 4, 12, 0.5);
}

.pc-w-a { stop-color: var(--pcw-a); }
.pc-w-b { stop-color: var(--pcw-b); }
.pc-w-c { stop-color: var(--pcw-c); }
.pc-w-d { stop-color: var(--pcw-d); }
.pc-b-a { stop-color: var(--pcb-a); }
.pc-b-b { stop-color: var(--pcb-b); }
.pc-b-c { stop-color: var(--pcb-c); }
.pc-b-d { stop-color: var(--pcb-d); }

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

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  font-family: var(--sans);
  color: var(--ink);
  background: linear-gradient(165deg, var(--bg-a), var(--bg-b)) fixed;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-text-size-adjust: 100%;
}

.defs { position: absolute; width: 0; height: 0; overflow: hidden; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* ---------------------------------------------------------- background */
.bg {
  position: fixed;
  inset: 0;
  overflow: hidden;
  z-index: 0;
  pointer-events: none;
}
.bg .glow { position: absolute; border-radius: 50%; filter: blur(70px); will-change: transform; }
.bg .g1 { width: 70vmax; height: 70vmax; left: -25vmax; top: -30vmax; background: var(--glow-1); animation: drift 60s ease-in-out infinite alternate; }
.bg .g2 { width: 60vmax; height: 60vmax; right: -25vmax; bottom: -25vmax; background: var(--glow-2); animation: drift 74s ease-in-out infinite alternate-reverse; }
@keyframes drift {
  from { transform: translate(0, 0) scale(1); }
  to { transform: translate(7vmax, 5vmax) scale(1.1); }
}

/* -------------------------------------------------------------- layout */
.app {
  position: fixed;
  inset: 0;
  z-index: 1;
  display: flex;
  flex-direction: column;
  max-width: 760px;
  margin: 0 auto;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  opacity: 0;
}
.ready .app { opacity: 1; transition: opacity 0.25s; }

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 10px 2px 16px;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand img { width: 40px; height: 40px; flex: 0 0 auto; filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.25)); }
.brand span { display: flex; flex-direction: column; line-height: 1.1; min-width: 0; }
.brand b { font-family: var(--serif); font-weight: 600; font-size: 23px; letter-spacing: 0.02em; }
.brand small {
  font-size: 11px;
  color: var(--ink-soft);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.menu { display: flex; align-items: center; gap: 2px; flex: 0 0 auto; }
.account-chip:empty { display: none; }
.account-chip { display: flex; align-items: center; margin-left: 4px; }

.icon-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--ink);
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.2s, transform 0.2s;
  flex: 0 0 auto;
}
.icon-btn:hover { background: var(--btn-bg); }
.icon-btn:active { transform: scale(0.92); }
.icon-btn svg, .btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.surface:focus-visible { outline: none; }

/* --------------------------------------------------------------- stage */
.stage {
  flex: 1;
  min-height: 0;
  container-type: size;
  display: grid;
  place-items: center;
  padding: 4px 12px 4px;
  position: relative;
}
.table {
  --plate-h: 52px;
  --moves-h: 40px;
  --gap: 10px;
  width: min(100cqw, 100cqh - 2 * var(--plate-h) - var(--moves-h) - 3 * var(--gap));
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}
.plate.top { order: 0; }
.board-wrap { order: 1; }
.plate.bottom { order: 2; }
.moves { order: 3; }

/* --------------------------------------------------------------- plates */
.plate {
  position: relative;
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  column-gap: 8px;
  min-height: var(--plate-h);
  padding: 4px 5px 4px 4px;
  border-radius: 18px;
  background: var(--chip-bg);
  border: 1px solid var(--chip-line);
  box-shadow: var(--chip-shadow);
  transition: background 0.35s, box-shadow 0.35s, opacity 0.3s, transform 0.4s var(--ease);
}
.plate::after {
  content: "";
  position: absolute;
  left: 14%;
  right: 14%;
  bottom: -1px;
  height: 2.5px;
  border-radius: 2px;
  background: var(--accent);
  transform: scaleX(0);
  opacity: 0;
  transition: transform 0.4s var(--ease), opacity 0.3s;
}
.plate.active { background: var(--active-bg); box-shadow: 0 6px 18px -10px rgba(60, 40, 20, 0.45); }
.plate.active::after { transform: scaleX(1); opacity: 1; }
.plate.in-check::after { background: var(--danger); }
.plate.won { box-shadow: 0 0 0 1.5px var(--accent), 0 6px 20px -8px var(--accent); }
.plate.nudge { animation: nudge 0.45s var(--ease); }
@keyframes nudge {
  25% { transform: translateX(-4px); }
  60% { transform: translateX(3px); }
}
[data-mode="face"] .plate.top { transform: rotate(180deg); }
[data-mode="face"] .plate.top.nudge { animation: nudge-top 0.45s var(--ease); }
@keyframes nudge-top {
  0%, 100% { transform: rotate(180deg); }
  25% { transform: rotate(180deg) translateX(-4px); }
  60% { transform: rotate(180deg) translateX(3px); }
}
.app.turning .plate { opacity: 0; transition-duration: 0.3s; }

.who {
  appearance: none;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  display: flex;
  flex: 0 1 auto;
  align-items: center;
  gap: 9px;
  min-width: 0;
  min-height: 44px;
  padding: 2px 8px 2px 2px;
  border-radius: 14px;
  cursor: pointer;
  text-align: left;
}
.who:hover { background: var(--btn-bg); }
.who .badge {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 40% 35%, var(--paper), var(--paper-2));
  box-shadow: inset 0 0 0 1px var(--line), 0 1px 2px rgba(0, 0, 0, 0.12);
}
.who .badge svg { width: 34px; height: 34px; margin-top: -1px; }
.plate.active .who .badge { box-shadow: inset 0 0 0 1.5px var(--accent), 0 0 0 3px var(--accent-soft); }
.who-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.15; }
.who-text b { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who-text small {
  font-size: 10.5px;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--ink-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 3px;
  min-height: 1.15em;
}
.plate.in-check .who-text small { color: var(--danger); font-weight: 600; }
.plate.won .who-text small { color: var(--accent); font-weight: 600; }
.who .more { width: 16px; height: 16px; fill: none; stroke: currentColor; flex: 0 0 auto; opacity: 0.4; margin-left: -2px; }

.captured { display: flex; flex: 1 1 0; align-items: center; justify-content: flex-start; min-width: 0; overflow: hidden; gap: 4px; padding-left: 2px; }
.caps { display: flex; align-items: center; min-width: 0; flex-wrap: nowrap; }
.caps .mini { width: 19px; height: 19px; flex: 0 0 auto; margin-right: -7px; filter: drop-shadow(0 1px 0.5px rgba(0, 0, 0, 0.18)); }
.caps .mini:last-child { margin-right: 0; }
.caps .mini.t1 + .mini:not(.t1), .caps .mini.t2 + .mini.t3, .caps .mini.t3 + .mini.t4, .caps .mini.t2 + .mini.t4, .caps .mini.t4 + .mini.t5, .caps .mini.t3 + .mini.t5, .caps .mini.t2 + .mini.t5 { margin-left: 9px; }
.adv { font-family: var(--serif); font-size: 13px; font-weight: 600; color: var(--ink-soft); font-variant-numeric: tabular-nums; flex: 0 0 auto; }

.clock {
  display: none;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  min-width: 78px;
  height: 40px;
  padding: 0 12px;
  border-radius: 12px;
  background: var(--clock-bg);
  color: var(--clock-ink);
  box-shadow: inset 0 0 0 1px var(--line);
  font-family: var(--serif);
  font-size: 21px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
  transition: background 0.3s, color 0.3s, box-shadow 0.3s;
}
.has-clock .clock { display: flex; }
.clock.active { background: var(--clock-on-bg); color: var(--clock-on-ink); box-shadow: 0 4px 12px -6px rgba(0, 0, 0, 0.5); }
.clock.low { color: var(--danger); }
.clock.active.low { background: var(--danger); color: #fff; }
.clock.running.low { animation: breathe 1s ease-in-out infinite; }
.clock.out { background: var(--danger); color: #fff; }
.plate.paused .clock.active { opacity: 0.65; }
@keyframes breathe { 50% { opacity: 0.72; } }

.claim { display: flex; align-items: center; flex: 0 1 auto; min-width: 0; order: 2; margin-left: auto; animation: fade 0.3s; }
.claim .pill { min-width: 0; overflow: hidden; }
.claim .pill span { overflow: hidden; text-overflow: ellipsis; }
.plate .clock { order: 3; }
.plate.claiming .captured { display: none; }
.plate.claiming .who { flex: 1 1 auto; }
.pill svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex: 0 0 auto; }
.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  appearance: none;
  border: 1px solid var(--accent);
  background: var(--accent-soft);
  color: var(--ink);
  font: 600 13px var(--sans);
  padding: 8px 13px;
  min-height: 36px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  flex: 0 0 auto;
}
.pill:active { transform: scale(0.97); }

/* --------------------------------------------------------------- board */
.board-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  container-type: inline-size;
}
.contact {
  position: absolute;
  inset: 2% 1.5% -1%;
  border-radius: 3%;
  box-shadow: 0 1.8cqw 4cqw -1.2cqw rgba(30, 18, 8, 0.6), 0 0.6cqw 1.4cqw -0.4cqw rgba(30, 18, 8, 0.35);
  transition: opacity 0.3s;
}
.board {
  --pad: 5.2%;
  position: absolute;
  inset: 0;
  border-radius: 2.4%;
  transform: rotate(var(--turn, 0deg));
  transition: transform var(--turn-ms) var(--turn-ease);
}
.board.no-anim, .board.no-anim * { transition: none !important; }
.frame {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: var(--frame-bg);
  box-shadow: var(--frame-ring);
}
/* the inlay line in the rail, and a bevel round the playing field */
.frame::before {
  content: "";
  position: absolute;
  inset: calc(var(--pad) * 0.2);
  border-radius: 1.6%;
  border: 1px solid var(--inlay);
  opacity: 0.55;
}
.frame::after {
  content: "";
  position: absolute;
  inset: calc(var(--pad) - 0.5%);
  border-radius: 0.7%;
  box-shadow: var(--bevel);
  background: rgba(0, 0, 0, 0.18);
}
.sheen {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: var(--frame-light);
  pointer-events: none;
  transform: rotate(var(--unturn, 0deg));
  transition: transform var(--turn-ms) var(--turn-ease), opacity 0.25s;
}
.board.turning .sheen, .board.turning .gloss { opacity: 0; }

.coords { position: absolute; inset: 0; pointer-events: none; transition: opacity 0.3s; }
.no-coords .coords { opacity: 0; }
.coords span {
  position: absolute;
  font-family: var(--serif);
  font-size: 2.55cqw;
  font-weight: 600;
  line-height: 1;
  color: var(--coord);
  text-shadow: var(--coord-shadow);
  --at: calc(var(--pad) + (var(--i) + 0.5) * (100% - 2 * var(--pad)) / 8);
}
.coords .file.near { left: var(--at); bottom: calc(var(--pad) * 0.52); transform: translate(-50%, 50%); }
.coords .file.far { left: var(--at); top: calc(var(--pad) * 0.52); transform: translate(-50%, -50%) rotate(180deg); }
.coords .rank.near { top: var(--at); left: calc(var(--pad) * 0.52); transform: translate(-50%, -50%); }
.coords .rank.far { top: var(--at); right: calc(var(--pad) * 0.52); transform: translate(50%, -50%) rotate(180deg); }

.surface {
  position: absolute;
  inset: var(--pad);
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  cursor: default;
}
.squares {
  position: absolute;
  inset: 0;
  background: var(--squares-bg);
  box-shadow: inset 0 0 1.2cqw rgba(0, 0, 0, 0.22);
}
.gloss {
  position: absolute;
  inset: 0;
  background: var(--gloss);
  pointer-events: none;
  transform: rotate(var(--unturn, 0deg));
  transition: transform var(--turn-ms) var(--turn-ease), opacity 0.25s;
}
.layer { position: absolute; inset: 0; pointer-events: none; }
.pieces { z-index: 2; }
.hints { z-index: 4; }

.mark, .pc {
  position: absolute;
  left: 0;
  top: 0;
  width: 12.5%;
  height: 12.5%;
  transform: translate(calc(var(--x) * 100%), calc(var(--y) * 100%));
}
.mark.last { background: var(--last); }
.mark.sel { background: var(--sel); }
.mark.check { background: radial-gradient(closest-side, var(--check) 0%, color-mix(in srgb, var(--check) 45%, transparent) 55%, transparent 100%); animation: fade 0.3s; }
.mark.dot::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 30%;
  height: 30%;
  margin: -15% 0 0 -15%;
  border-radius: 50%;
  background: var(--dot);
  animation: dot-in 0.25s var(--ease) both;
}
.mark.dot.ring::before {
  width: 100%;
  height: 100%;
  margin: -50% 0 0 -50%;
  background: radial-gradient(closest-side, transparent 0 80%, var(--ring) 82% 97%, transparent 99%);
}
@keyframes dot-in { from { opacity: 0; transform: scale(0.4); } }
.mark.hover { box-shadow: inset 0 0 0 0.45cqw var(--hover); border-radius: 2px; }
.mark.focus { box-shadow: inset 0 0 0 0.5cqw var(--focus), 0 0 1cqw color-mix(in srgb, var(--focus) 50%, transparent); border-radius: 4px; transition: transform 0.12s var(--ease); }

/* ----------------------------------------------------------------- pieces */
.pc {
  z-index: 1;
  transition: transform var(--glide, 240ms) var(--glide-ease) var(--glide-delay, 0ms);
}
.pc.moving { z-index: 3; }
.pc.drag { transition: none; transform: translate(var(--dx), var(--dy)); z-index: 6; }
.pc.dropped { transition: none; }
.pc.return { transition: transform 0.2s var(--ease); z-index: 3; }
.pc .turn {
  position: absolute;
  inset: 0;
  transform: rotate(var(--spin-w, 0deg));
  transition: transform 0.45s var(--ease);
}
.pc.b .turn { transform: rotate(var(--spin-b, 0deg)); }
.board.turning .pc .turn { transition: transform var(--turn-ms) var(--turn-ease); }
.pc .turn::before {
  content: "";
  position: absolute;
  left: 17%;
  right: 17%;
  bottom: 6.5%;
  height: 11%;
  border-radius: 50%;
  background: radial-gradient(closest-side, var(--pc-shadow), transparent);
  transition: transform 0.18s var(--ease), opacity 0.18s;
}
.pc .art {
  position: absolute;
  inset: 3%;
  width: 94%;
  height: 94%;
  overflow: visible;
  transform-origin: 50% 88%;
  transition: transform 0.18s var(--ease);
}
.pc.drag .art { transform: scale(1.16) translateY(-3%); }
.pc.drag .turn::before { transform: translateY(42%) scale(1.35); opacity: 0.55; }
.pc.taken .art { animation: taken 0.34s ease-in forwards; }
.pc.taken .turn::before { animation: fade-out 0.25s forwards; }
@keyframes taken { to { opacity: 0; transform: translateY(-12%) scale(1.14); } }
@keyframes fade-out { to { opacity: 0; } }
.pc.appear .art { animation: appear 0.42s var(--ease) both; }
@keyframes appear { from { opacity: 0; transform: scale(0.84); } }
.pc.morph .art { animation: morph 0.52s var(--spring) both; }
@keyframes morph {
  0% { opacity: 0.25; transform: scale(0.55); }
  55% { opacity: 1; transform: scale(1.12); }
  100% { transform: scale(1); }
}
.pc.topple .art { animation: topple 1.1s cubic-bezier(0.55, 0.05, 0.4, 1) forwards; }
.pc.toppled .art { transform: translate(38%, -24%) rotate(-80deg) scale(0.92); }
.pc.topple .turn::before, .pc.toppled .turn::before { animation: none; transform: translateY(-160%) scaleX(1.25) scaleY(2.6); opacity: 0.55; transition: transform 0.9s var(--ease), opacity 0.9s; }
@keyframes topple {
  0% { transform: none; }
  16% { transform: rotate(5deg); }
  68% { transform: translate(38%, -24%) rotate(-86deg) scale(0.92); }
  82% { transform: translate(38%, -24%) rotate(-76deg) scale(0.92); }
  100% { transform: translate(38%, -24%) rotate(-80deg) scale(0.92); }
}

/* the promotion picker: a column of choices from the square inwards */
.picker {
  z-index: 7;
  pointer-events: auto;
  background: rgba(16, 10, 4, 0.38);
  animation: fade 0.2s;
}
.promo {
  appearance: none;
  border: 0;
  padding: 0;
  margin: 0;
  cursor: pointer;
  background: none;
  z-index: 1;
}
.promo::before {
  content: "";
  position: absolute;
  inset: 4%;
  border-radius: 50%;
  background: radial-gradient(circle at 45% 38%, #fffaf0, #e6dccb);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.4), inset 0 0 0 1px rgba(0, 0, 0, 0.15);
  animation: promo-in 0.3s var(--spring) both;
  animation-delay: calc(var(--k) * 45ms);
}
.promo.b::before { background: radial-gradient(circle at 45% 38%, #fffaf0, #d9cdb8); }
.promo .turn { animation: promo-in 0.3s var(--spring) both; animation-delay: calc(var(--k) * 45ms); }
.promo:hover::before, .promo:focus-visible::before { background: radial-gradient(circle at 45% 38%, #fff, #f2d9a8); }
.promo:focus-visible { outline: none; }
@keyframes promo-in { from { opacity: 0; transform: scale(0.5); } }

/* paused: the board rests under a veil */
.paused-veil {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  border-radius: 2.4%;
  background: rgba(20, 14, 8, 0.32);
  backdrop-filter: blur(2.5px);
  -webkit-backdrop-filter: blur(2.5px);
  animation: fade 0.3s;
}
.paused-veil .btn { flex: none; padding: 12px 22px; font-size: 16px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4); }
.paused-veil.nudge .btn { animation: nudge 0.45s var(--ease); }
[data-mode="face"] .paused-veil.facing-top .btn { transform: rotate(180deg); }

/* ---------------------------------------------------------------- moves */
.moves { min-height: var(--moves-h, 40px); min-width: 0; }
.move-list {
  list-style: none;
  margin: 0;
  padding: 0 2px;
  display: flex;
  align-items: center;
  gap: 2px;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  white-space: nowrap;
  height: 40px;
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 10px, #000 calc(100% - 10px), transparent);
  mask-image: linear-gradient(90deg, transparent, #000 10px, #000 calc(100% - 10px), transparent);
}
.move-list::-webkit-scrollbar { display: none; }
.move-list li { display: inline-flex; align-items: center; flex: 0 0 auto; }
.move-list li.empty { color: var(--ink-soft); font-size: 13px; padding: 0 8px; }
.move-list li.result { font-family: var(--serif); font-weight: 600; padding: 0 10px; color: var(--accent); }
.move-list .num { font-size: 12px; color: var(--ink-soft); padding: 0 1px 0 8px; font-variant-numeric: tabular-nums; }
.mv {
  appearance: none;
  border: 0;
  background: none;
  color: var(--ink);
  font: 500 14.5px var(--sans);
  padding: 6px 6px;
  min-height: 34px;
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  font-variant-numeric: tabular-nums;
}
.mv:hover { background: var(--btn-bg); }
.mv.current { background: var(--active-bg); box-shadow: inset 0 0 0 1px var(--accent); }
.mv.gap { color: var(--ink-soft); cursor: default; }
.mv .mini, .review-text .mini { width: 17px; height: 17px; margin: -2px 1px 0 -1px; }

/* --------------------------------------------------------------- actions */
.actions {
  position: relative;
  display: flex;
  gap: 8px;
  padding: 6px 12px 12px;
}
.btn {
  appearance: none;
  flex: 1;
  border: 1px solid var(--btn-line);
  background: var(--btn-bg);
  color: var(--ink);
  font: 500 15px var(--sans);
  padding: 10px 10px;
  min-height: 46px;
  min-width: 0;
  border-radius: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  transition: transform 0.15s, background 0.2s, opacity 0.2s, box-shadow 0.2s;
}
.btn svg { width: 19px; height: 19px; flex: 0 0 auto; }
.btn:hover { background: var(--btn-hover); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.36; cursor: default; transform: none; }
.btn.primary {
  background: linear-gradient(180deg, var(--primary-a), var(--primary-b));
  color: var(--primary-ink);
  border-color: var(--primary-line);
  box-shadow: 0 4px 12px -4px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.22);
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.25);
}
.btn.primary:hover { filter: brightness(1.06); }
.btn.subtle { flex: 0 0 auto; background: transparent; border-color: transparent; color: var(--ink-soft); font-size: 13.5px; margin: 14px auto 0; display: flex; min-height: 40px; }
.btn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#btn-pause svg { color: var(--accent); }
.paused #btn-pause { border-color: var(--accent); background: var(--accent-soft); }

/* reviewing: the bar takes the place of the buttons */
.review {
  position: absolute;
  inset: 6px 12px 12px;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 4px 0 14px;
  border-radius: 14px;
  background: var(--paper);
  box-shadow: 0 0 0 1px var(--line), 0 8px 24px -12px rgba(0, 0, 0, 0.35);
  animation: fade 0.2s;
}
.review-text { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.2; }
.review-text b { font-family: var(--serif); font-size: 16px; display: inline-flex; align-items: center; }
.review-text span { font-size: 12px; color: var(--ink-soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.review .btn { flex: 0 0 auto; min-height: 40px; padding: 8px 14px; }
.review.nudge { animation: nudge 0.45s var(--ease); }

/* -------------------------------------------------------- sheets, dialogs */
.backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: var(--backdrop);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  animation: fade 0.25s;
}
.backdrop.soft { background: rgba(0, 0, 0, 0.26); backdrop-filter: none; -webkit-backdrop-filter: none; }
@keyframes fade { from { opacity: 0; } }

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  margin: 0 auto;
  z-index: 21;
  max-width: 560px;
  max-height: 88dvh;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  color: var(--ink);
  border-radius: 24px 24px 0 0;
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.25);
  padding-bottom: env(safe-area-inset-bottom);
  animation: rise 0.32s var(--ease);
}
.sheet.small { max-width: 440px; }
@keyframes rise { from { transform: translateY(40px); opacity: 0; } }
/* face to face: the far player's sheet comes in from their edge, facing them */
.sheet.facing-top {
  bottom: auto;
  top: 0;
  transform: rotate(180deg);
  padding-bottom: env(safe-area-inset-top);
  animation: rise-top 0.32s var(--ease);
}
@keyframes rise-top { from { transform: rotate(180deg) translateY(40px); opacity: 0; } }
.sheet header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 12px 6px 22px;
  flex: 0 0 auto;
  gap: 8px;
}
.sheet h2, .dialog h2 { font-family: var(--serif); font-weight: 600; font-size: 24px; margin: 0; letter-spacing: 0.01em; overflow: hidden; text-overflow: ellipsis; }
.sheet-body {
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 2px 22px 26px;
  font-size: 15px;
  line-height: 1.55;
}
.sheet-body.prose, .sheet-body .code, .sheet-body table { -webkit-user-select: text; user-select: text; }
.sheet-body h3 { font-family: var(--serif); font-weight: 600; font-size: 17px; margin: 20px 0 8px; color: var(--ink); }
.sheet-body h3:first-child { margin-top: 6px; }
.prose p { margin: 0 0 12px; }
.prose ul { margin: 0; padding-left: 20px; }
.prose li { margin: 4px 0; }
.muted { color: var(--ink-soft); }
.small { font-size: 13px; }
.about { font-size: 13px; margin-top: 22px; text-align: center; }

@media (min-width: 700px) and (min-height: 560px) {
  .sheet {
    bottom: auto;
    top: 50%;
    transform: translateY(-50%);
    border-radius: 24px;
    max-height: 84dvh;
    animation: pop 0.28s var(--ease);
  }
  .sheet.facing-top { top: 50%; transform: translateY(-50%) rotate(180deg); animation: pop-top 0.28s var(--ease); padding-bottom: 0; }
}
@keyframes pop { from { opacity: 0; transform: translateY(-50%) scale(0.96); } }
@keyframes pop-top { from { opacity: 0; transform: translateY(-50%) rotate(180deg) scale(0.96); } }

.dialog {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 22;
  width: min(92vw, 400px);
  background: var(--paper);
  color: var(--ink);
  border-radius: 24px;
  padding: 26px 22px 22px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
  text-align: center;
  animation: popc 0.32s var(--ease);
  overflow: hidden;
}
.dialog.facing-top { transform: translate(-50%, -50%) rotate(180deg); animation: popc-top 0.32s var(--ease); }
@keyframes popc { from { opacity: 0; transform: translate(-50%, -46%) scale(0.95); } }
@keyframes popc-top { from { opacity: 0; transform: translate(-50%, -54%) rotate(180deg) scale(0.95); } }
.dialog p { position: relative; margin: 6px 0 18px; color: var(--ink-soft); font-size: 15.5px; line-height: 1.5; }
#confirm p { color: var(--ink); font-size: 16.5px; }
.dialog .row { position: relative; display: flex; gap: 10px; }
.dialog .row .btn { min-width: 0; }

.result .glow {
  position: absolute;
  inset: -45% -20% auto;
  height: 75%;
  background: radial-gradient(ellipse at 50% 42%, var(--accent-soft), transparent 66%);
  pointer-events: none;
}
.result h2 { position: relative; font-size: 29px; margin-top: 4px; }
.result-mark { position: relative; display: flex; justify-content: center; gap: 2px; margin: -6px 0 4px; }
.result-mark .king { width: 64px; height: 64px; filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.25)); animation: crown 0.6s var(--spring) both 0.1s; }
.result[data-outcome="draw"] .result-mark .king { width: 52px; height: 52px; }
@keyframes crown { from { opacity: 0; transform: translateY(10px) scale(0.85); } }
.result p#result-text { margin: 6px 0 14px; }
.result .mirror {
  display: none;
  position: relative;
  margin: -12px -6px 12px;
  padding: 0 0 10px;
  border-bottom: 1px solid var(--line);
  transform: rotate(180deg);
  font-family: var(--serif);
  font-size: 16px;
  font-weight: 600;
  color: var(--ink);
}
[data-mode="face"] .result .mirror { display: block; }
.result-stats {
  position: relative;
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 6px;
  margin: -2px 0 12px;
}
.result-stats > span {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  background: var(--paper-2);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 10.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.result-stats b { font-family: var(--serif); font-size: 16px; font-weight: 600; color: var(--ink); letter-spacing: 0; }
.result .toggle { justify-content: center; margin: 0 0 16px; font-size: 14px; }
.result .btn.subtle { margin-top: 10px; gap: 6px; }
.result .btn.subtle svg { width: 17px; height: 17px; }
/* phones: the result card sits low, so the board stays in view */
@media (max-width: 600px) and (min-height: 600px) {
  .dialog.result {
    top: auto;
    bottom: calc(12px + env(safe-area-inset-bottom));
    transform: translateX(-50%);
    padding: 18px 20px 14px;
    animation: popb 0.34s var(--ease);
  }
  .result-mark .king { width: 52px; height: 52px; }
  .result h2 { font-size: 26px; }
}
@keyframes popb { from { opacity: 0; transform: translate(-50%, 24px); } }

/* --------------------------------------------------------------- options */
.opts { display: flex; flex-wrap: wrap; gap: 8px; }
.opt {
  appearance: none;
  border: 1.5px solid var(--line);
  background: var(--paper-2);
  color: var(--ink);
  font: 500 14px var(--sans);
  padding: 8px 14px 8px 10px;
  min-height: 44px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s, transform 0.15s, box-shadow 0.2s;
}
.opt:active { transform: scale(0.97); }
.opt[aria-checked="true"] { border-color: var(--accent); background: var(--paper); box-shadow: 0 0 0 3px var(--accent-soft); }
.opts.plain .opt { padding-left: 15px; padding-right: 15px; min-width: 72px; justify-content: center; font-variant-numeric: tabular-nums; }
.swatch {
  display: inline-block;
  width: 28px;
  height: 28px;
  border-radius: 7px;
  flex: 0 0 auto;
  padding: 3px;
  background: var(--sf);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.25);
}
.swatch::before {
  content: "";
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 2px;
  background: conic-gradient(var(--sd) 0 25%, var(--sl) 0 50%, var(--sd) 0 75%, var(--sl) 0) 0 0 / 50% 50%;
}
.swatch.auto { background: linear-gradient(135deg, #47291a 50%, #0e131b 50%); }

.choices { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.choice {
  appearance: none;
  text-align: left;
  border: 1.5px solid var(--line);
  background: var(--paper-2);
  color: var(--ink);
  font: 600 14.5px var(--sans);
  padding: 10px 11px 11px;
  border-radius: 14px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
  line-height: 1.25;
  transition: border-color 0.2s, background 0.2s, transform 0.15s, box-shadow 0.2s;
}
.choice small { font-size: 12px; color: var(--ink-soft); font-weight: 400; }
.choice:active { transform: scale(0.98); }
.choice[aria-checked="true"] { border-color: var(--accent); background: var(--paper); box-shadow: 0 0 0 3px var(--accent-soft); }
/* little diagrams of the three ways to sit */
.mode-pic { position: relative; width: 44px; height: 38px; margin-bottom: 2px; }
.mode-pic .bd { position: absolute; left: 11px; top: 8px; width: 22px; height: 22px; border-radius: 3px; background: conic-gradient(#8d5b39 0 25%, #e8cfa0 0 50%, #8d5b39 0 75%, #e8cfa0 0) 0 0 / 50% 50%; box-shadow: 0 0 0 1.5px #47291a; }
.mode-pic .p1, .mode-pic .p2 { position: absolute; width: 10px; height: 10px; border-radius: 50%; border: 1.5px solid var(--ink-soft); }
.mode-pic .p1 { left: 17px; bottom: -3px; background: #f4ecdc; }
.mode-pic .p2 { left: 17px; top: -3px; background: #2b2420; }
.mode-pic.fixed .p2 { left: 29px; top: auto; bottom: -3px; }
.mode-pic.fixed .p1 { left: 5px; }
.mode-pic.pass .p2 { display: none; }
.mode-pic.pass .bd { animation: none; }
.mode-pic.pass::after { content: ""; position: absolute; right: -2px; top: 4px; width: 9px; height: 9px; border: 1.5px solid var(--ink-soft); border-left-color: transparent; border-radius: 50%; }
@media (max-width: 460px) {
  .choices.modes { grid-template-columns: 1fr; }
  .choices.modes .choice { display: grid; grid-template-columns: 50px 1fr; grid-template-rows: auto auto; column-gap: 8px; align-items: center; }
  .choices.modes .mode-pic { grid-row: 1 / span 2; }
}
.note { font-size: 13px; color: var(--ink-soft); margin: 10px 0 0; }
.note.bad { color: var(--danger); }
.start { width: 100%; margin-top: 22px; flex: none; }
.toggle { display: flex; align-items: center; gap: 12px; margin-top: 18px; cursor: pointer; font-size: 15px; line-height: 1.35; min-height: 32px; }
.toggle input { position: absolute; opacity: 0; width: 0; height: 0; }
.toggle .track { flex: 0 0 auto; width: 46px; height: 28px; border-radius: 999px; background: var(--line); position: relative; transition: background 0.25s; box-shadow: inset 0 0 0 1px var(--line); }
.toggle .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3); transition: transform 0.25s var(--ease); }
.toggle input:checked + .track { background: var(--accent); }
.toggle input:checked + .track::after { transform: translateX(18px); }
.toggle input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }

/* names */
.names { display: grid; grid-template-columns: 1fr 44px; grid-template-rows: auto auto; gap: 8px 6px; align-items: center; }
.names .swap { grid-column: 2; grid-row: 1 / span 2; }
.name-row { display: flex; align-items: center; gap: 8px; padding: 2px 4px 2px 6px; border-radius: 14px; background: var(--paper-2); border: 1.5px solid var(--line); }
.name-row:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.name-row .king { width: 34px; height: 34px; flex: 0 0 auto; }
.name-row input, input.fen {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  font: 500 16px var(--sans);
  padding: 10px 6px;
  outline: none;
  -webkit-user-select: text;
  user-select: text;
}
.fen-box { margin-top: 18px; }
.fen-box summary { cursor: pointer; font-size: 14px; color: var(--ink-soft); padding: 6px 0; min-height: 32px; }
input.fen { width: 100%; border: 1.5px solid var(--line); border-radius: 12px; background: var(--paper-2); font: 13px ui-monospace, SFMono-Regular, Menlo, monospace; padding: 11px 12px; margin-top: 4px; }
input.fen:focus { border-color: var(--accent); }

.player-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 18px; }
.player-actions .btn { flex: none; justify-content: flex-start; padding-left: 16px; }

/* PGN, FEN */
.code {
  margin: 0;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--paper-2);
  font: 12.5px/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 34dvh;
  overflow: auto;
}
.code.fen { max-height: none; }
.row-btns { display: flex; gap: 10px; margin-top: 12px; }

/* results */
.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 4px; }
.tile { background: var(--paper-2); border-radius: 14px; padding: 10px 8px 9px; display: flex; flex-direction: column; align-items: center; gap: 2px; text-align: center; }
.tile b { font-family: var(--serif); font-size: 26px; font-weight: 600; line-height: 1.1; font-variant-numeric: tabular-nums; }
.tile span { font-size: 10.5px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-soft); line-height: 1.25; }
.share-bar { display: flex; height: 8px; border-radius: 999px; overflow: hidden; margin: 12px 0 6px; background: var(--paper-2); gap: 2px; }
.share-bar i { flex: var(--n) 1 0; min-width: 0; }
.share-bar i.w { background: #e9dcc0; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12); }
.share-bar i.d { background: var(--accent); opacity: 0.55; }
.share-bar i.b { background: #241d18; box-shadow: inset 0 0 0 1px rgba(255, 240, 220, 0.22); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip-n { display: inline-flex; align-items: baseline; gap: 6px; background: var(--paper-2); border-radius: 999px; padding: 5px 12px; font-size: 13px; }
.chip-n b { font-family: var(--serif); font-size: 15px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
th { text-align: left; font-weight: 500; color: var(--ink-soft); font-size: 10.5px; letter-spacing: 0.06em; text-transform: uppercase; padding: 4px; border-bottom: 1px solid var(--line); }
td { padding: 8px 4px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td.who { font-weight: 600; max-width: 10em; overflow: hidden; text-overflow: ellipsis; }
th.num, td.num { text-align: right; }
td.won { color: var(--accent); font-weight: 600; }
.games { list-style: none; margin: 0; padding: 0; }
.game { position: relative; padding: 9px 44px 9px 0; border-bottom: 1px solid var(--line); }
.g-top { display: flex; align-items: center; gap: 10px; min-width: 0; }
.g-res { font-family: var(--serif); font-size: 15px; min-width: 3.2em; }
.g-res.rd { color: var(--ink-soft); }
.g-who { display: inline-flex; align-items: center; gap: 2px; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 14.5px; }
.g-who .king { width: 22px; height: 22px; flex: 0 0 auto; }
.g-meta { font-size: 12.5px; color: var(--ink-soft); margin: 2px 0 0 calc(3.2em * 15 / 12.5 + 10px); }
.g-copy { position: absolute; right: 0; top: 50%; transform: translateY(-50%); }
.g-copy svg { width: 19px; height: 19px; }

/* ---------------------------------------------------------------- toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(80px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(10px);
  z-index: 30;
  background: var(--toast);
  color: #fff;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 14px;
  width: max-content;
  max-width: min(88vw, 420px);
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.copy-area { position: fixed; left: -9999px; top: 0; width: 1px; height: 1px; opacity: 0; }
.toast.facing-top { bottom: auto; top: calc(80px + env(safe-area-inset-top)); transform: translateX(-50%) rotate(180deg) translateY(10px); }
.toast.facing-top.show { transform: translateX(-50%) rotate(180deg); }

/* ------------------------------------------------------- small screens */
@media (max-height: 700px) {
  .top { padding-top: 6px; }
  .brand img { width: 34px; height: 34px; }
  .brand b { font-size: 20px; }
  .table { --plate-h: 46px; --moves-h: 36px; --gap: 8px; }
  .who .badge { width: 34px; height: 34px; }
  .who .badge svg { width: 29px; height: 29px; }
  .clock { height: 36px; font-size: 19px; min-width: 70px; }
  .actions { padding-bottom: 8px; }
  .btn { min-height: 44px; padding: 7px 8px; }
  .move-list { height: 36px; }
}
@media (max-width: 520px) {
  .actions .btn { flex-direction: column; gap: 2px; padding: 6px 4px 5px; font-size: 11.5px; }
  .actions .btn svg { width: 21px; height: 21px; }
  .tiles { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 374px) {
  .top { padding-left: 12px; padding-right: 6px; }
  .menu .icon-btn { width: 40px; }
  .stage { padding-left: 8px; padding-right: 8px; }
  .plate { column-gap: 5px; }
  .who { gap: 6px; padding-right: 4px; }
  .who-text b { font-size: 14px; }
  .who .more { display: none; }
  .caps .mini { width: 16px; height: 16px; margin-right: -6px; }
  .clock { min-width: 62px; padding: 0 8px; font-size: 18px; }
  .actions { padding-left: 8px; padding-right: 8px; gap: 5px; }
}

/* landscape, and roomy screens: the board on the left at full height, the
   players, the moves and the buttons in a column beside it */
@media (min-aspect-ratio: 5/4) {
  .app {
    display: grid;
    max-width: none;
    grid-template-columns: auto minmax(260px, 360px);
    grid-template-rows: auto auto minmax(0, 1fr) auto auto;
    grid-template-areas: "board top" "board ptop" "board moves" "board pbottom" "board actions";
    justify-content: center;
    column-gap: 22px;
    padding-left: max(14px, env(safe-area-inset-left));
    padding-right: max(8px, env(safe-area-inset-right));
  }
  .top { grid-area: top; padding-left: 0; padding-top: 10px; }
  .stage, .table { display: contents; }
  .board-wrap {
    grid-area: board;
    align-self: center;
    width: auto;
    height: calc(100dvh - 28px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    max-height: calc(100vw - 420px);
    max-width: calc(100vw - 420px);
    margin: 14px 0;
  }
  .plate.top { grid-area: ptop; margin: 6px 0 0; }
  .plate.bottom { grid-area: pbottom; margin: 0 0 8px; }
  .moves { grid-area: moves; padding: 8px 0; min-height: 0; display: flex; flex-direction: column; }
  .move-list {
    display: grid;
    grid-template-columns: 1fr;
    align-content: start;
    height: auto;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-mask-image: linear-gradient(180deg, transparent, #000 8px, #000 calc(100% - 8px), transparent);
    mask-image: linear-gradient(180deg, transparent, #000 8px, #000 calc(100% - 8px), transparent);
    background: var(--chip-bg);
    border-radius: 16px;
    padding: 6px 4px;
    gap: 0;
  }
  .move-list li { display: grid; grid-template-columns: 3em 1fr 1fr; align-items: center; }
  .move-list li.empty, .move-list li.result { display: block; padding: 8px 10px; }
  .move-list .num { padding: 0 0 0 8px; }
  .mv { justify-content: flex-start; width: 100%; }
  .actions { grid-area: actions; padding: 0 0 14px; }
  .actions .btn { flex-direction: column; gap: 2px; padding: 6px 4px 5px; font-size: 11.5px; }
  .review { inset: 0 0 14px; }
}
@media (min-aspect-ratio: 5/4) and (max-height: 520px) {
  .top { padding-top: 6px; padding-bottom: 0; }
  .brand img { width: 30px; height: 30px; }
  .brand b { font-size: 18px; }
  .brand small { display: none; }
  .plate { --plate-h: 44px; min-height: 44px; }
  .board-wrap { height: calc(100dvh - 16px - env(safe-area-inset-top) - env(safe-area-inset-bottom)); margin: 8px 0; }
  .actions { padding-bottom: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  .bg .glow { animation: none; }
  .board, .pc, .pc .turn, .sheen, .gloss, .plate { transition-duration: 0.01s !important; }
  .pc.taken .art { animation-duration: 0.15s; }
  .pc.appear .art, .pc.morph .art { animation-duration: 0.15s; }
  .sheet, .dialog, .backdrop, .mark.dot::before, .promo::before, .promo .turn, .result-mark .king { animation: none; }
}
