/* Dáma — wood, marble and night. Every colour that changes with the look is
   a custom property set under [data-theme]; the pieces are SVG drawings whose
   gradient stops read these properties, the board squares are textures
   painted once by themes.js. Motion is transform and opacity only. */

: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);
  --n: 8;
  --plate: 56px;
  --pad: 4.2%;
}

/* ------------------------------------------------------------- themes */
/* Wood: maple and walnut squares in a walnut frame, boxwood and walnut discs */
:root,
[data-theme="wood"] {
  color-scheme: light;
  --bg-a: #efe5d3;
  --bg-b: #d8c8ae;
  --glow-1: rgba(255, 248, 232, 0.85);
  --glow-2: rgba(154, 91, 46, 0.14);
  --ink: #2d2219;
  --ink-soft: #6b5a48;
  --chip-bg: rgba(255, 255, 255, 0.42);
  --chip-line: rgba(255, 255, 255, 0.7);
  --chip-shadow: 0 1px 2px rgba(60, 40, 20, 0.1);
  --active-bg: rgba(255, 252, 244, 0.92);
  --btn-bg: rgba(255, 255, 255, 0.55);
  --btn-hover: rgba(255, 255, 255, 0.85);
  --btn-line: rgba(70, 45, 25, 0.15);
  --primary-a: #a5643a;
  --primary-b: #7a4425;
  --primary-line: #5a2f17;
  --primary-ink: #fbf3e6;
  --paper: #f9f4eb;
  --paper-2: #efe6d7;
  --line: rgba(70, 45, 25, 0.14);
  --accent: #965626;
  --accent-soft: rgba(154, 90, 44, 0.2);
  --backdrop: rgba(40, 26, 14, 0.4);
  --toast: rgba(38, 27, 18, 0.93);

  --frame-fallback: #3f2415;
  --frame-light: linear-gradient(155deg, rgba(255, 225, 190, 0.26), rgba(255, 255, 255, 0) 34%, rgba(0, 0, 0, 0) 64%, rgba(0, 0, 0, 0.3));
  --board-shadow: 0 28px 50px -22px rgba(50, 28, 10, 0.72), 0 10px 18px -8px rgba(50, 28, 10, 0.45);
  --frame-bevel: inset 0 1px 1px rgba(255, 225, 190, 0.35), inset 0 -2px 3px rgba(0, 0, 0, 0.45);
  --inlay: #c9a35a;
  --field-edge: 0 0 0 1px rgba(20, 10, 4, 0.55), 0 0 0 2.5px rgba(201, 163, 90, 0.45);
  --field-inset: inset 0 1px 5px rgba(0, 0, 0, 0.28);
  --seam: rgba(30, 15, 5, 0.32);

  --pl-f1: #f8e6c0; --pl-f2: #e3c48c; --pl-f3: #bf935a;
  --pl-s1: #a2753f; --pl-s2: #e6c893; --pl-s3: #77502c;
  --pl-grain: #94683a;
  --pd-f1: #8f5b3b; --pd-f2: #5d3521; --pd-f3: #371c0f;
  --pd-s1: #2a150a; --pd-s2: #6d432a; --pd-s3: #1d0e06;
  --pd-grain: #1f0e07;
  --sheen-1: 0.75; --sheen-2: 0.16;
  --cr-1: #fbe8a8; --cr-2: #d8ab4e; --cr-3: #8c6220;
  --piece-shadow: rgba(30, 14, 4, 0.6);

  --last-sq: rgba(255, 214, 130, 0.22);
  --last-line: rgba(255, 238, 196, 0.8);
  --target: rgba(255, 246, 220, 0.82);
  --route: rgba(255, 240, 200, 0.95);
  --route-edge: rgba(40, 20, 6, 0.55);
  --sel: rgba(255, 226, 150, 0.95);
  --sel-fill: rgba(255, 226, 150, 0.12);
  --threat: #f2694a;
  --must: #ffd886;
  --must-glow: rgba(255, 196, 86, 0.55);
  --focus: rgba(255, 240, 200, 0.95);
  --label: rgba(255, 232, 196, 0.62);
  --label-in: rgba(255, 238, 205, 0.55);
}

/* Marble: Carrara and verde squares in a slate frame; alabaster and onyx */
[data-theme="marble"] {
  color-scheme: light;
  --bg-a: #eeeeea;
  --bg-b: #d3d6d1;
  --glow-1: rgba(255, 255, 255, 0.95);
  --glow-2: rgba(63, 107, 92, 0.14);
  --ink: #222826;
  --ink-soft: #5b6461;
  --chip-bg: rgba(255, 255, 255, 0.5);
  --chip-line: rgba(255, 255, 255, 0.78);
  --chip-shadow: 0 1px 2px rgba(30, 45, 40, 0.08);
  --active-bg: rgba(255, 255, 255, 0.92);
  --btn-bg: rgba(255, 255, 255, 0.6);
  --btn-hover: rgba(255, 255, 255, 0.9);
  --btn-line: rgba(30, 45, 40, 0.14);
  --primary-a: #4d7c6b;
  --primary-b: #2f5446;
  --primary-line: #22403a;
  --primary-ink: #f4f6f2;
  --paper: #f9f9f6;
  --paper-2: #edeeea;
  --line: rgba(30, 45, 40, 0.13);
  --accent: #376556;
  --accent-soft: rgba(61, 108, 92, 0.2);
  --backdrop: rgba(25, 32, 30, 0.38);
  --toast: rgba(30, 36, 34, 0.93);

  --frame-fallback: #3d4449;
  --frame-light: linear-gradient(155deg, rgba(255, 255, 255, 0.3), rgba(255, 255, 255, 0) 36%, rgba(0, 0, 0, 0) 64%, rgba(0, 0, 0, 0.25));
  --board-shadow: 0 26px 46px -22px rgba(20, 30, 30, 0.6), 0 8px 16px -8px rgba(20, 30, 30, 0.4);
  --frame-bevel: inset 0 1px 1px rgba(255, 255, 255, 0.4), inset 0 -2px 3px rgba(0, 0, 0, 0.35);
  --inlay: rgba(235, 238, 236, 0.6);
  --field-edge: 0 0 0 1px rgba(10, 15, 14, 0.5), 0 0 0 2.5px rgba(235, 238, 236, 0.35);
  --field-inset: inset 0 1px 5px rgba(0, 0, 0, 0.2);
  --seam: rgba(20, 25, 24, 0.25);

  --pl-f1: #ffffff; --pl-f2: #eeeae2; --pl-f3: #cfc8ba;
  --pl-s1: #b3ab9d; --pl-s2: #f4f0e8; --pl-s3: #948d7f;
  --pl-grain: #a59d8f;
  --pd-f1: #62716b; --pd-f2: #2f3c38; --pd-f3: #141b19;
  --pd-s1: #0f1513; --pd-s2: #47544f; --pd-s3: #090d0c;
  --pd-grain: #a3b8ae;
  --sheen-1: 0.9; --sheen-2: 0.22;
  --cr-1: #f7edcb; --cr-2: #ccb079; --cr-3: #85703f;
  --piece-shadow: rgba(15, 25, 22, 0.52);

  --last-sq: rgba(255, 236, 170, 0.26);
  --last-line: rgba(255, 250, 232, 0.9);
  --target: rgba(255, 255, 246, 0.88);
  --route: rgba(255, 250, 226, 0.97);
  --route-edge: rgba(15, 25, 22, 0.5);
  --sel: rgba(255, 236, 170, 0.95);
  --sel-fill: rgba(255, 236, 170, 0.14);
  --threat: #e4583c;
  --must: #ffe08c;
  --must-glow: rgba(255, 210, 100, 0.58);
  --focus: rgba(255, 250, 235, 0.95);
  --label: rgba(255, 255, 255, 0.66);
  --label-in: rgba(255, 255, 255, 0.62);
}

/* Night: dark stone with silver flecks; moonstone and obsidian, gold crowns */
[data-theme="night"] {
  color-scheme: dark;
  --bg-a: #151b2c;
  --bg-b: #070a13;
  --glow-1: rgba(120, 150, 220, 0.13);
  --glow-2: rgba(224, 185, 115, 0.08);
  --ink: #e8ecf5;
  --ink-soft: rgba(232, 236, 245, 0.66);
  --chip-bg: rgba(200, 215, 255, 0.05);
  --chip-line: rgba(200, 215, 255, 0.1);
  --chip-shadow: none;
  --active-bg: rgba(200, 215, 255, 0.12);
  --btn-bg: rgba(200, 215, 255, 0.07);
  --btn-hover: rgba(200, 215, 255, 0.13);
  --btn-line: rgba(200, 215, 255, 0.15);
  --primary-a: #5268a0;
  --primary-b: #33437a;
  --primary-line: #232f57;
  --primary-ink: #f0f3fb;
  --paper: #161c2c;
  --paper-2: #20283c;
  --line: rgba(200, 215, 255, 0.11);
  --accent: #e0bb76;
  --accent-soft: rgba(224, 187, 118, 0.2);
  --backdrop: rgba(2, 4, 10, 0.62);
  --toast: rgba(30, 38, 58, 0.96);

  --frame-fallback: #090d17;
  --frame-light: linear-gradient(150deg, rgba(190, 210, 255, 0.14), rgba(255, 255, 255, 0) 30%, rgba(255, 255, 255, 0) 72%, rgba(190, 210, 255, 0.05));
  --board-shadow: 0 30px 60px -18px rgba(0, 0, 0, 0.85), 0 8px 18px -6px rgba(0, 0, 0, 0.6);
  --frame-bevel: inset 0 1px 0 rgba(200, 215, 255, 0.16), inset 0 -2px 4px rgba(0, 0, 0, 0.7);
  --inlay: rgba(214, 190, 130, 0.62);
  --field-edge: 0 0 0 1px rgba(0, 0, 0, 0.7), 0 0 0 2.5px rgba(214, 190, 130, 0.32);
  --field-inset: inset 0 1px 6px rgba(0, 0, 0, 0.45);
  --seam: rgba(0, 0, 0, 0.4);

  --pl-f1: #f7f9ff; --pl-f2: #cfd8eb; --pl-f3: #93a2c0;
  --pl-s1: #7a89aa; --pl-s2: #e1e7f5; --pl-s3: #5a6888;
  --pl-grain: rgba(150, 168, 205, 0.45);
  --pd-f1: #5a6080; --pd-f2: #2a2f48; --pd-f3: #0e1020;
  --pd-s1: #080a14; --pd-s2: #424a6c; --pd-s3: #05060c;
  --pd-grain: rgba(141, 152, 196, 0.32);
  --sheen-1: 0.78; --sheen-2: 0.2;
  --cr-1: #fff0c4; --cr-2: #e2b65e; --cr-3: #9a6f26;
  --piece-shadow: rgba(0, 0, 0, 0.72);

  --last-sq: rgba(224, 187, 118, 0.17);
  --last-line: rgba(240, 215, 160, 0.82);
  --target: rgba(242, 226, 186, 0.85);
  --route: rgba(246, 228, 180, 0.96);
  --route-edge: rgba(0, 0, 0, 0.6);
  --sel: rgba(240, 210, 140, 0.95);
  --sel-fill: rgba(240, 210, 140, 0.12);
  --threat: #ff7a5c;
  --must: #f4d27f;
  --must-glow: rgba(243, 209, 126, 0.5);
  --focus: rgba(240, 215, 160, 0.95);
  --label: rgba(214, 190, 130, 0.7);
  --label-in: rgba(220, 230, 255, 0.5);
}

/* before the script runs, dark mode starts on night colours (no flash) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    color-scheme: dark;
    --bg-a: #151b2c;
    --bg-b: #070a13;
    --ink: #e8ecf5;
    --ink-soft: rgba(232, 236, 245, 0.66);
    --chip-bg: rgba(200, 215, 255, 0.05);
    --chip-line: rgba(200, 215, 255, 0.1);
    --btn-bg: rgba(200, 215, 255, 0.07);
    --btn-line: rgba(200, 215, 255, 0.15);
    --frame-fallback: #090d17;
  }
}

/* gradient stops of the pieces */
.pl-f1 { stop-color: var(--pl-f1); } .pl-f2 { stop-color: var(--pl-f2); } .pl-f3 { stop-color: var(--pl-f3); }
.pl-s1 { stop-color: var(--pl-s1); } .pl-s2 { stop-color: var(--pl-s2); } .pl-s3 { stop-color: var(--pl-s3); }
.pd-f1 { stop-color: var(--pd-f1); } .pd-f2 { stop-color: var(--pd-f2); } .pd-f3 { stop-color: var(--pd-f3); }
.pd-s1 { stop-color: var(--pd-s1); } .pd-s2 { stop-color: var(--pd-s2); } .pd-s3 { stop-color: var(--pd-s3); }
.p-sheen1 { stop-opacity: var(--sheen-1); } .p-sheen2 { stop-opacity: var(--sheen-2); }
.cr-1 { stop-color: var(--cr-1); } .cr-2 { stop-color: var(--cr-2); } .cr-3 { stop-color: var(--cr-3); }

* { box-sizing: border-box; }
[hidden] { display: none !important; }
/* until the first frames are drawn nothing slides into place */
.no-anim *, .no-anim *::before, .no-anim *::after { transition: 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%;
}

/* the drawing of the pieces lives in a zero-size svg (not display:none, or
   its gradients would not paint) */
.defs { position: absolute; width: 0; height: 0; overflow: hidden; }

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

/* ---------------------------------------------------------- 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 56s ease-in-out infinite alternate; }
.bg .g2 { width: 60vmax; height: 60vmax; right: -25vmax; bottom: -25vmax; background: var(--glow-2); animation: drift 70s 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: 820px;
  margin: 0 auto;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 10px 4px 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 { display: flex; align-items: center; min-width: 0; }
.account-chip:empty { display: none; }

.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, opacity 0.2s;
  flex: 0 0 auto;
}
.icon-btn:hover { background: var(--btn-bg); }
.icon-btn:active { transform: scale(0.92); }
.icon-btn:disabled { opacity: 0.3; cursor: default; transform: none; background: transparent; }
.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; }

/* --------------------------------------------------------------- stage */
.stage {
  flex: 1;
  min-height: 0;
  container-type: size;
  display: grid;
  place-items: center;
  padding: 4px 14px 6px;
  position: relative;
}
/* plates and board travel together as one table, centred in the stage */
.table {
  width: min(100cqw, 100cqh - 2 * var(--plate) - 20px);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* -------------------------------------------------------------- plates */
.plate {
  position: relative;
  height: var(--plate);
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: 5px 4px 5px 5px;
  border-radius: 999px;
  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.35s, rotate 0.5s var(--ease);
}
.plate::after {
  content: "";
  position: absolute;
  left: 16%;
  right: 16%;
  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 0 0 1px var(--accent-soft), 0 6px 22px -10px var(--accent); }
.plate.active::after { transform: scaleX(1); opacity: 1; }
.plate.won { box-shadow: 0 0 0 1.5px var(--accent), 0 6px 20px -8px var(--accent); }
.plate.swap-in { animation: plate-in 0.42s var(--ease); }
@keyframes plate-in { from { opacity: 0; transform: translateY(6px); } }
/* face to face: the far player reads their own plate */
.app.face .plate.seat-top { rotate: 180deg; }

.token {
  position: relative;
  flex: 0 0 auto;
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
}
.token svg { position: absolute; inset: -2px; width: 50px; height: 50px; overflow: visible; }
.token.l svg { color: var(--pl-grain); }
.token.d svg { color: var(--pd-grain); }
.token .count {
  position: relative;
  margin-top: -5px;
  font-family: var(--serif);
  font-size: 18px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.token.l .count { color: #3b2a18; text-shadow: 0 1px 0 rgba(255, 255, 255, 0.45); }
.token.d .count { color: #fbf2e4; text-shadow: 0 1px 1px rgba(0, 0, 0, 0.5); }
[data-theme="night"] .token.l .count { color: #26304a; }
.token.bump { animation: bump 0.26s var(--ease); }
@keyframes bump { 50% { transform: scale(1.12); } }

.who { display: flex; flex-direction: column; min-width: 0; flex: 1; line-height: 1.15; }
.who b { font-size: 15.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who 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.active .who small { color: var(--accent); font-weight: 600; }
.kings {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 3px 8px 3px 6px;
  border-radius: 999px;
  background: var(--paper-2);
  color: var(--ink);
  font: 600 13px var(--serif);
  font-variant-numeric: tabular-nums;
  opacity: 0;
  transform: scale(0.7);
  transition: opacity 0.3s, transform 0.3s var(--spring);
}
.kings.on { opacity: 1; transform: none; }
.kings svg { width: 15px; height: 15px; fill: none; stroke: var(--accent); stroke-width: 1.8; stroke-linejoin: round; stroke-linecap: round; }
.plate .icon-btn { width: 42px; height: 42px; color: var(--ink-soft); }
.plate .icon-btn svg { width: 20px; height: 20px; }
.plate .icon-btn:hover { color: var(--ink); }

/* ---------------------------------------------------------------- board */
.board {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  border-radius: 2.4%;
  box-shadow: var(--board-shadow);
}
/* the frame and the field turn together in pass-and-play; the light that
   falls on the frame does not */
.rot {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  padding: var(--pad);
  background: var(--frame-img, none) center / cover, var(--frame-fallback);
  box-shadow: var(--frame-bevel);
}
.rot::before {
  content: "";
  position: absolute;
  inset: calc(var(--pad) * 0.42);
  border-radius: 1.6%;
  border: 1px solid var(--inlay);
  opacity: 0.8;
  pointer-events: none;
}
.board::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: var(--frame-light);
  pointer-events: none;
  z-index: 2;
}
.board.flipped .rot { rotate: 180deg; }
.board.turning .rot { transition: rotate 0.72s cubic-bezier(0.55, 0.05, 0.25, 1); }
.board.flipped .pc { rotate: -180deg; }
.board.turning .pc { transition: rotate 0.72s cubic-bezier(0.55, 0.05, 0.25, 1); }
.board.flipped .focus-ring { rotate: 180deg; }

.field {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 0.5%;
  box-shadow: var(--field-edge);
  touch-action: none;
  outline: none;
  z-index: 1;
}
.field::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  box-shadow: var(--field-inset);
  pointer-events: none;
  z-index: 1;
}
.field:focus-visible { box-shadow: var(--field-edge), 0 0 0 4px var(--accent-soft); }
.squares, .marks {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}
.squares { border-radius: inherit; }
.squares .seam { fill: none; stroke: var(--seam); stroke-width: 1; vector-effect: non-scaling-stroke; }
.marks { overflow: visible; pointer-events: none; z-index: 1; }
.pieces { position: absolute; inset: 0; pointer-events: none; z-index: 2; }

/* where the board is touched by the active player's hand */
.board .edge-glow {
  position: absolute;
  left: 14%;
  right: 14%;
  height: 2px;
  border-radius: 2px;
  background: var(--accent);
  box-shadow: 0 0 9px 0 var(--accent);
  opacity: 0;
  transition: opacity 0.45s, transform 0.45s var(--ease);
  pointer-events: none;
  z-index: 3;
}
.board .edge-glow.edge-top { top: -1.5px; }
.board .edge-glow.edge-bottom { bottom: -1.5px; }
.board .edge-glow.on { opacity: var(--edge-glow, 0.7); }
[data-theme="night"] { --edge-glow: 0.42; }

/* --------------------------------------------------------------- marks */
.m-last-sq { fill: var(--last-sq); }
.m-last-path { fill: none; stroke: var(--last-line); stroke-width: 0.055; stroke-linecap: round; stroke-linejoin: round; opacity: 0.75; }
.m-last-dot { fill: var(--last-line); opacity: 0.8; }
.m-last-cap { fill: none; stroke: var(--last-line); stroke-width: 0.035; stroke-dasharray: 0.08 0.07; opacity: 0.55; }
.m-sel { fill: var(--sel-fill); stroke: var(--sel); stroke-width: 0.045; }
.m-route-edge { fill: none; stroke: var(--route-edge); stroke-width: 0.13; stroke-linecap: round; stroke-linejoin: round; opacity: 0.45; }
.m-route { fill: none; stroke: var(--route); stroke-width: 0.07; stroke-linecap: round; stroke-linejoin: round; }
.m-route.faint, .m-route-edge.faint { opacity: 0.38; }
.m-target { fill: var(--target); }
.m-target-shadow { fill: rgba(0, 0, 0, 0.35); }
.m-final { fill: none; stroke: var(--target); stroke-width: 0.05; }
.marks .fade-in { animation: mark-in 0.32s var(--ease) both; }
@keyframes mark-in { from { opacity: 0; } }
.marks.quiet .m-target, .marks.quiet .m-target-shadow { display: none; }
.m-deny { fill: none; stroke: var(--threat); stroke-width: 0.06; animation: deny 0.5s ease-out both; transform-box: fill-box; transform-origin: center; }
@keyframes deny {
  0% { opacity: 0.9; transform: translateX(0); }
  25% { transform: translateX(-8%); }
  50% { transform: translateX(7%); }
  75% { transform: translateX(-4%); opacity: 0.6; }
  100% { opacity: 0; transform: translateX(0); }
}

/* --------------------------------------------------------------- pieces */
.pc {
  position: absolute;
  left: 0;
  top: 0;
  width: calc(100% / var(--n));
  height: calc(100% / var(--n));
  translate: calc(var(--x) * 100%) calc(var(--y) * 100%);
}
.pc.l svg { color: var(--pl-grain); }
.pc.d svg { color: var(--pd-grain); }
.pc .sh {
  position: absolute;
  left: 9%;
  top: 12%;
  width: 84%;
  height: 84%;
  border-radius: 50%;
  background: radial-gradient(closest-side, var(--piece-shadow) 0%, var(--piece-shadow) 55%, transparent 100%);
  transform: translate(4%, 7%);
  opacity: 0.85;
  transition: transform 0.25s var(--ease), opacity 0.25s;
}
.pc.king .sh { transform: translate(5%, 8%) scale(1.04); }
.pc .lift {
  position: absolute;
  inset: 0;
  transition: transform 0.25s var(--spring);
}
.pc svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.pc .up { translate: 0 -9.5%; }
.pc:not(.king) .up { opacity: 0; }
.pc .glow {
  position: absolute;
  inset: -18%;
  border-radius: 50%;
  background: radial-gradient(closest-side, var(--must-glow), transparent);
  opacity: 0;
  pointer-events: none;
}

/* picked up */
.pc.sel { z-index: 3; }
.pc.moving { z-index: 5; }
.pc.sel .lift { transform: translateY(-7%) scale(1.06); }
.pc.sel .sh { transform: translate(10%, 13%) scale(1.08); opacity: 0.55; }
.pc.dragging { z-index: 6; translate: var(--drag-x) var(--drag-y); }
.pc.dragging .lift { transform: translateY(-12%) scale(1.12); transition: none; }
.pc.dragging .sh { transform: translate(14%, 18%) scale(1.14); opacity: 0.45; transition: none; }

/* must capture: a soft halo breathes under the piece */
.pc.must::before {
  content: "";
  position: absolute;
  left: 4%;
  top: 0%;
  width: 92%;
  height: 92%;
  border-radius: 50%;
  box-shadow: 0 0 0 1.5px var(--must), 0 0 14px 3px var(--must-glow);
  animation: must 1.9s ease-in-out infinite;
}
.pc.must.king::before { top: -6%; height: 100%; }
@keyframes must { 0%, 100% { opacity: 0.28; } 50% { opacity: 1; } }
.pc.must.flash::before { animation: must-flash 0.42s ease-in-out 3; }
@keyframes must-flash { 50% { opacity: 1; transform: scale(1.06); } }

/* a piece the chosen route would take */
.pc.threat::after {
  content: "";
  position: absolute;
  left: 7%;
  top: 2%;
  width: 86%;
  height: 86%;
  border-radius: 50%;
  box-shadow: 0 0 0 2px var(--threat), 0 0 12px 1px color-mix(in oklab, var(--threat) 55%, transparent);
  animation: mark-in 0.3s var(--ease) both;
  pointer-events: none;
}
.pc.threat.king::after { top: -7%; height: 95%; }

/* taken during a capture: still on the board, but already lost */
.pc.taken .lift { opacity: 0.62; transition: opacity 0.2s; }
.pc.taken .sh { opacity: 0.4; }

/* a piece that cannot move gives a little shake */
.pc.nope .lift { animation: nope 0.42s ease-out; }
@keyframes nope {
  25% { transform: translateX(-6%); }
  50% { transform: translateX(5%); }
  75% { transform: translateX(-3%); }
}

/* -------------------------------------------------------- coordinates */
.labels { position: absolute; inset: var(--pad); pointer-events: none; z-index: 3; transition: opacity 0.3s; }
.labels.hide { opacity: 0; }
.lab {
  position: absolute;
  font: 600 clamp(7px, 1.9cqw, 12px) var(--sans);
  letter-spacing: 0.02em;
  color: var(--label);
  line-height: 1;
}
.lab.file { left: calc((var(--c) + 0.5) * 100% / var(--n)); top: 100%; translate: -50% 28%; }
.lab.rank { top: calc((var(--r) + 0.5) * 100% / var(--n)); right: 100%; translate: -38% -50%; }
.lab.num {
  left: calc(var(--c) * 100% / var(--n));
  top: calc(var(--r) * 100% / var(--n));
  translate: 0.4em 0.35em;
  font-size: clamp(6px, 1.5cqw, 10px);
  font-weight: 500;
  color: var(--label-in);
}

/* ----------------------------------------------------- keyboard frame */
.focus-ring {
  position: absolute;
  left: 0;
  top: 0;
  width: calc(100% / var(--n));
  height: calc(100% / var(--n));
  translate: calc(var(--x) * 100%) calc(var(--y) * 100%);
  transition: translate 0.14s var(--ease);
  pointer-events: none;
  z-index: 4;
}
.focus-ring::before {
  content: "";
  position: absolute;
  inset: 3%;
  border-radius: 14%;
  border: 2px solid var(--focus);
  box-shadow: 0 0 10px color-mix(in oklab, var(--focus) 45%, transparent);
}

/* ---------------------------------------------------------------- banner */
.banner {
  appearance: none;
  position: absolute;
  left: 50%;
  bottom: 0;
  z-index: 4;
  width: max-content;
  max-width: 88%;
  padding: 8px 18px;
  border-radius: 999px;
  border: 0;
  background: var(--toast);
  color: #fff;
  font: 600 15px var(--serif);
  letter-spacing: 0.02em;
  text-align: center;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.3);
  transform: translate(-50%, 50%);
  cursor: pointer;
  animation: banner-in 0.35s var(--ease);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.banner small { font: 400 12px var(--sans); opacity: 0.7; margin-left: 8px; letter-spacing: 0; }
@keyframes banner-in { from { opacity: 0; transform: translate(-50%, 50%) scale(0.94); } }

/* --------------------------------------------------------------- actions */
.actions {
  display: flex;
  gap: 10px;
  padding: 4px 16px 14px;
}
.btn {
  appearance: none;
  flex: 1;
  border: 1px solid var(--btn-line);
  background: var(--btn-bg);
  color: var(--ink);
  font: 500 15px var(--sans);
  padding: 11px 12px;
  min-height: 46px;
  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; }
.btn:hover { background: var(--btn-hover); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.38; 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.danger { color: #fff; background: linear-gradient(180deg, #c0563c, #933723); border-color: #6e2615; text-shadow: 0 1px 1px rgba(0, 0, 0, 0.25); }
.btn.subtle { flex: 0 0 auto; background: transparent; border-color: transparent; color: var(--ink-soft); font-size: 13.5px; }

/* -------------------------------------------------------- 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.22); 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);
}
@keyframes rise { from { transform: translateY(40px); opacity: 0; } }
.sheet header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 12px 6px 22px;
  flex: 0 0 auto;
}
.sheet h2, .dialog h2 { font-family: var(--serif); font-weight: 600; font-size: 24px; margin: 0; letter-spacing: 0.01em; }
.sheet-body {
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 2px 22px 26px;
  font-size: 15px;
  line-height: 1.55;
}
.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: 5px 0; }
.prose, .prose * { -webkit-user-select: text; user-select: text; }
.muted { color: var(--ink-soft); }
.about { font-size: 13px; margin-top: 22px; text-align: center; color: var(--ink-soft); }
.about b { font-weight: 600; color: var(--ink); }

@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);
  }
}
@keyframes pop { from { opacity: 0; transform: translateY(-50%) scale(0.96); } }

/* dialogs: centred; in face-to-face play each faces the player it speaks to */
.dialogs { position: fixed; inset: 0; z-index: 22; pointer-events: none; }
.dialog {
  position: absolute;
  left: 50%;
  top: 50%;
  translate: -50% -50%;
  width: min(92vw, 400px);
  max-height: 92dvh;
  overflow: auto;
  background: var(--paper);
  color: var(--ink);
  border-radius: 24px;
  padding: 24px 22px 20px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
  text-align: center;
  pointer-events: auto;
  animation: popc 0.32s var(--ease);
}
@keyframes popc { from { opacity: 0; scale: 0.95; } }
.dialog p { position: relative; margin: 4px 0 18px; color: var(--ink-soft); font-size: 15.5px; line-height: 1.5; }
.dialog p.lead { color: var(--ink); font-size: 17px; margin-bottom: 4px; }
.dialog .row { position: relative; display: flex; gap: 10px; }
.dialog .row .btn { min-width: 0; }
.dialogs.face .dialog.to-top { top: 25%; rotate: 180deg; max-height: 48dvh; }
.dialogs.face .dialog.to-bottom { top: 75%; max-height: 48dvh; }
.dialogs.face .dialog.result { width: min(92vw, 380px); padding: 14px 16px 14px; }
.dialogs.face .result .crest { width: 44px; height: 44px; margin: -2px auto 2px; }
.dialogs.face .result h2 { font-size: 23px; }
.dialogs.face .result p { margin: 2px 0 10px; font-size: 14.5px; }
.dialogs.face .result-stats { margin-bottom: 10px; }
.dialogs.face .result .toggle { margin: 0 0 12px; font-size: 13.5px; min-height: 28px; }
.dialogs.face .dialog .btn { min-height: 42px; padding: 9px 10px; }

.result { overflow: hidden; }
.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.won .glow { background: radial-gradient(ellipse at 50% 42%, color-mix(in oklab, var(--accent) 42%, transparent), transparent 66%); }
.result .crest { position: relative; width: 70px; height: 70px; margin: -4px auto 6px; }
.result .crest svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.result .crest .up { translate: 0 -9.5%; }
.result .crest svg.l { color: var(--pl-grain); }
.result .crest svg.d { color: var(--pd-grain); }
.result .crest.draw svg.l { translate: -24% 0; }
.result .crest.draw svg.d { translate: 24% 4%; }
.result h2 { position: relative; font-size: 28px; }
.result.won h2 { animation: shimmer 2.6s ease-in-out infinite; }
@keyframes shimmer { 50% { text-shadow: 0 0 18px color-mix(in oklab, var(--accent) 70%, transparent); } }
.result p { margin: 6px 0 14px; }
.result-stats {
  position: relative;
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0 0 14px;
}
.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: 15px; font-weight: 600; color: var(--ink); letter-spacing: 0; text-transform: none; }
.result .toggle { justify-content: center; margin: 0 0 16px; font-size: 14px; }

/* phones: the result card sits low, so the board stays in view */
@media (max-width: 600px) and (min-height: 600px) {
  .dialogs:not(.face) .dialog.result { top: auto; bottom: calc(12px + env(safe-area-inset-bottom)); translate: -50% 0; padding: 18px 18px 16px; }
  .result .crest { width: 56px; height: 56px; }
  .result h2 { font-size: 25px; }
}

/* ------------------------------------------------------------- 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: 16px; padding-right: 16px; min-width: 84px; justify-content: center; }
.swatch {
  display: inline-block;
  width: 28px;
  height: 28px;
  border-radius: 7px;
  flex: 0 0 auto;
  position: relative;
  background: conic-gradient(var(--sa) 0 25%, var(--sb) 0 50%, var(--sa) 0 75%, var(--sb) 0) 0 0 / 14px 14px;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.2);
  overflow: hidden;
}
.swatch::before, .swatch::after { content: ""; position: absolute; width: 10px; height: 10px; border-radius: 50%; box-shadow: 0 1px 1.5px rgba(0, 0, 0, 0.45); }
.swatch::before { left: 2px; bottom: 2px; background: var(--sl); }
.swatch::after { right: 2px; top: 2px; background: var(--sd); }
.swatch.auto { background: linear-gradient(135deg, #e3c38c 0 50%, #141a2a 50%); }
.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.choice {
  appearance: none;
  text-align: left;
  border: 1.5px solid var(--line);
  background: var(--paper-2);
  color: var(--ink);
  font: 500 15px var(--sans);
  padding: 10px 12px 11px;
  border-radius: 14px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 3px;
  line-height: 1.25;
  transition: border-color 0.2s, background 0.2s, transform 0.15s, box-shadow 0.2s;
}
.choice small { font-size: 12.5px; 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); }
.choice .grid-mini { width: 26px; height: 26px; border-radius: 5px; margin-bottom: 4px; background: conic-gradient(var(--sq-l, #e3c38c) 0 25%, var(--sq-d, #5b3620) 0 50%, var(--sq-l, #e3c38c) 0 75%, var(--sq-d, #5b3620) 0) 0 0 / calc(200% / var(--g)) calc(200% / var(--g)); box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.2); }
.modes .choice { flex-direction: row; align-items: center; gap: 12px; }
.modes .choice svg { width: 30px; height: 30px; flex: 0 0 auto; fill: none; stroke: var(--accent); stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.modes .choice span { display: flex; flex-direction: column; gap: 2px; }
.modes { grid-template-columns: 1fr; }
@media (min-width: 520px) { .modes { grid-template-columns: 1fr 1fr 1fr; } .modes .choice { flex-direction: column; align-items: flex-start; } }

.players-edit { display: flex; flex-direction: column; gap: 8px; }
.player-row { display: flex; align-items: center; gap: 10px; }
.player-row .mini { width: 34px; height: 34px; flex: 0 0 auto; position: relative; }
.player-row .mini svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.player-row .mini.l svg { color: var(--pl-grain); }
.player-row .mini.d svg { color: var(--pd-grain); }
.player-row label { display: flex; flex-direction: column; flex: 1; min-width: 0; font-size: 12px; color: var(--ink-soft); letter-spacing: 0.04em; gap: 3px; }
.text-in {
  appearance: none;
  width: 100%;
  min-height: 44px;
  border: 1.5px solid var(--line);
  background: var(--paper-2);
  color: var(--ink);
  font: 500 16px var(--sans);
  padding: 8px 12px;
  border-radius: 12px;
  -webkit-user-select: text;
  user-select: text;
}
.text-in:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.text-in::placeholder { color: var(--ink-soft); opacity: 0.75; }
.swap-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.swap-row .btn { flex: 0 0 auto; padding: 8px 14px; min-height: 40px; font-size: 14px; }
.note { font-size: 13px; color: var(--ink-soft); margin: 6px 0 0; }
.start { width: 100%; margin-top: 22px; flex: none; }
.toggle { display: flex; align-items: center; gap: 12px; margin-top: 16px; 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; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin: 2px 0 6px; }
.tabs .opt { min-height: 38px; padding: 6px 14px; font-size: 13.5px; }

/* ------------------------------------------------------------- results */
.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 6px 0 4px; }
.tile { background: var(--paper-2); border-radius: 14px; padding: 10px 8px 9px; text-align: center; min-width: 0; }
.tile b { display: block; font: 600 24px var(--serif); font-variant-numeric: tabular-nums; line-height: 1.1; }
.tile small { display: block; font-size: 10.5px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-soft); margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; font-variant-numeric: tabular-nums; }
th { text-align: left; vertical-align: bottom; 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: 7px 4px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th.num, td.num { text-align: right; }
td.name { font-weight: 500; max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recent { list-style: none; margin: 0; padding: 0; }
.recent li { display: grid; grid-template-columns: auto 1fr auto; gap: 2px 10px; padding: 9px 0; border-bottom: 1px solid var(--line); align-items: center; }
.recent .when { font-size: 12px; color: var(--ink-soft); grid-row: span 2; min-width: 46px; }
.recent .who { font-size: 14px; font-weight: 500; flex-direction: row; gap: 6px; align-items: center; display: flex; overflow: hidden; }
.recent .who i { width: 10px; height: 10px; border-radius: 50%; flex: 0 0 auto; }
.recent .who i.l { background: var(--pl-f2); box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.25); }
.recent .who i.d { background: var(--pd-f2); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.15); }
.recent .who span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.recent .res { font: 600 14px var(--serif); text-align: right; white-space: nowrap; }
.recent .why { grid-column: 2 / 4; font-size: 12px; color: var(--ink-soft); }

/* ---------------------------------------------------------------- toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(84px + 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, 440px);
  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); }
.toast.to-top { bottom: auto; top: calc(84px + env(safe-area-inset-top)); rotate: 180deg; }

/* ------------------------------------------------------- small screens */
@media (max-height: 700px) {
  :root { --plate: 50px; }
  .top { padding-top: 6px; }
  .brand img { width: 34px; height: 34px; }
  .brand b { font-size: 20px; }
  .token { width: 40px; height: 40px; }
  .token svg { inset: -2px; width: 44px; height: 44px; }
  .token .count { font-size: 16px; }
  .actions { padding-bottom: 10px; }
  .btn { min-height: 44px; padding: 8px 10px; }
  .table { gap: 8px; }
}
@media (max-width: 520px) {
  .dialog .btn, .sheet .btn { font-size: 14.5px; padding: 11px 10px; }
  .tiles { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 374px) {
  .top { padding-left: 12px; padding-right: 6px; }
  .menu .icon-btn { width: 40px; }
  .plate { gap: 7px; }
  .who b { font-size: 14px; }
  .plate .icon-btn { width: 38px; }
  .actions { padding-left: 12px; padding-right: 12px; gap: 8px; }
  .stage { padding-left: 10px; padding-right: 10px; }
}

/* short landscape: the board fills the height on the left; header, plates
   and actions stack beside it (the far plate on top, the near one below) */
@media (min-aspect-ratio: 5/4) and (max-height: 620px) {
  .app {
    display: grid;
    max-width: none;
    grid-template-columns: auto minmax(250px, 360px);
    grid-template-rows: auto auto 1fr auto auto;
    justify-content: center;
    column-gap: 22px;
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(8px, env(safe-area-inset-right));
  }
  .stage, .table { display: contents; }
  .board {
    grid-column: 1;
    grid-row: 1 / -1;
    align-self: center;
    width: auto;
    height: calc(100dvh - 24px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  }
  .top { grid-column: 2; grid-row: 1; padding-left: 0; }
  .plate.seat-top { grid-column: 2; grid-row: 2; margin: 8px 12px 0 0; }
  .plate.seat-bottom { grid-column: 2; grid-row: 4; margin: 0 12px 8px 0; }
  .actions { grid-column: 2; grid-row: 5; padding-left: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .bg .glow { animation: none; }
  .pc .lift, .pc .sh, .focus-ring, .plate { transition-duration: 0.01s; }
  .pc.must::before { animation: none; opacity: 0.85; }
  .board.turning .rot, .board.turning .pc { transition-duration: 0.01s; }
  .sheet, .dialog, .backdrop, .result h2, .banner, .marks .fade-in, .plate.swap-in { animation: none; }
}
