/* Queenspace — mobile-first styles */

/* Light theme. The board always uses these colours, even in dark mode, so
   the pastel regions, dark queens and walls look the same in both themes. */
:root,
:root[data-theme="dark"] .board-frame {
  --bg: #f6f3ee;
  --surface: #fffdf9;
  --surface-2: #efebe4;
  --ink: #29253a;
  --ink-soft: #4a4560;
  --muted: #77718a;
  --line: rgba(41, 37, 58, 0.13);
  --line-strong: rgba(41, 37, 58, 0.28);
  --wall: #2f2a42;
  --accent: #5a4bd1;
  --accent-ink: #ffffff;
  --accent-soft: #ebe7ff;
  --accent-text: #5a4bd1;
  --danger: #d23a48;
  --gold: #c98a0b;
  --badge: #29253a;
  --toast-bg: #29253a;
  --toast-ink: #ffffff;
  --toggle-off: #d9d4cc;
  --overlay: rgba(246, 243, 238, 0.82);
  --sheet-shadow: 0 -10px 40px rgba(41, 37, 58, 0.18);
  --shadow: 0 1px 2px rgba(41, 37, 58, 0.06), 0 6px 20px rgba(41, 37, 58, 0.08);
}

/* Dark theme: only the page around the board changes. The accent stays the
   same for buttons; --accent-text is a lighter shade for text on dark. */
:root[data-theme="dark"] {
  --bg: #16141d;
  --surface: #201d29;
  --surface-2: #2a2635;
  --ink: #ece9f4;
  --ink-soft: #c4bfd3;
  --muted: #9690aa;
  --line: rgba(236, 233, 244, 0.12);
  --line-strong: rgba(236, 233, 244, 0.28);
  --accent-soft: #2b2650;
  --accent-text: #b0a6ff;
  --danger: #ff7a86;
  --badge: #2f2a42;
  --toast-bg: #ece9f4;
  --toast-ink: #1d1a26;
  --toggle-off: #3e3a4c;
  --sheet-shadow: 0 -10px 40px rgba(0, 0, 0, 0.5);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 6px 20px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}

:root {
  --radius: 14px;
  --board-radius: 12px;
  --font: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }

/* `hidden` always wins, even over components that set their own display. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

body { overscroll-behavior: none; }

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  touch-action: manipulation;
}

svg { display: block; }

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

.app {
  height: 100vh;
  height: 100dvh;
  max-width: 620px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding:
    max(6px, env(safe-area-inset-top))
    max(12px, env(safe-area-inset-right))
    max(10px, env(safe-area-inset-bottom))
    max(12px, env(safe-area-inset-left));
}

.topbar {
  display: flex;
  flex-wrap: wrap; /* very narrow screens: the buttons drop below the title */
  align-items: center;
  justify-content: space-between;
  column-gap: 8px;
  min-height: 48px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  font-size: 1.3rem;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.brand-mark {
  width: 28px;
  height: 28px;
  padding: 4px;
  border-radius: 9px;
  background: var(--badge);
  fill: #ffd66e;
}

.topbar-actions { display: flex; gap: 4px; margin-left: auto; }

.icon-btn {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--ink-soft);
}
.icon-btn svg { width: 24px; height: 24px; }
.icon-btn:hover { background: var(--surface-2); }

/* Optional clock in the title bar (off by default: Show timer). */
.timer {
  margin-right: 4px;
  align-self: center;
  font-variant-numeric: tabular-nums;
  font-weight: 650;
  font-size: 0.95rem;
  color: var(--muted);
}

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

/* ----------------------------------------------------------- Colour tray */

/* One tile per region, in its colour: faint until that region has a queen.
   Uses the board's fixed colours (not theme variables) so it matches the
   board in both themes. */
.tray {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 5px;
  height: 22px;
  margin-bottom: -4px;
}
.tray-chip {
  flex: 0 1 22px;
  min-width: 0;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: var(--c, #eee);
  box-shadow: inset 0 0 0 1px rgba(41, 37, 58, 0.14);
  opacity: var(--tray-faint, 0.3);
  transition: opacity 0.2s ease, box-shadow 0.2s ease;
}
:root[data-theme="dark"] { --tray-faint: 0.38; }
.tray-chip svg { width: 72%; height: 72%; fill: #29253a; opacity: 0.45; }
.tray-chip.found { opacity: 1; }
.tray-chip.found svg { opacity: 1; animation: pop 0.2s ease-out; }
.tray-chip.bad { opacity: 1; box-shadow: inset 0 0 0 1.5px #d23a48; }
.tray-chip.bad svg { fill: #d23a48; }
.tray.solved .tray-chip svg { fill: #c98a0b; }

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

.stage {
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  container-type: size;
}

.play {
  /* colour tray (22) + gap + frame ring fit in the stage; new players also
     get the two-line intro under the board */
  width: min(100cqw - 6px, 100cqh - 40px);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.has-intro .play { width: min(100cqw - 6px, 100cqh - 116px); }

.intro { margin-top: 2px; text-align: center; }
.intro p { margin: 0; }
.intro-rules { font-size: 0.85rem; font-weight: 650; color: var(--ink-soft); line-height: 1.4; }

.caption {
  margin: 2px 0 0;
  height: 20px;
  line-height: 20px;
  font-size: 0.85rem;
  font-weight: 550;
  color: var(--muted);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.caption .ci { display: inline-block; width: 1.05em; height: 1.05em; vertical-align: -0.17em; fill: var(--ink-soft); }
.caption .ci.x { color: var(--muted); }
.for-mouse { display: none; }
@media (hover: hover) and (pointer: fine) {
  .for-mouse { display: inline; }
  .for-touch { display: none; }
}

.board-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  border-radius: var(--board-radius);
  box-shadow: var(--shadow), 0 0 0 3px var(--wall);
  background: var(--surface);
}

.board {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(var(--n, 8), 1fr);
  grid-template-rows: repeat(var(--n, 8), 1fr);
  border-radius: var(--board-radius);
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  outline: none;
}

.board-lines {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: visible;
}
.board-lines .grid { stroke: var(--line); stroke-width: 1; vector-effect: non-scaling-stroke; fill: none; }
.board-lines .walls {
  stroke: var(--wall);
  stroke-width: 2.6;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
  fill: none;
}
.board-lines .cursor {
  fill: none;
  stroke: var(--accent);
  stroke-width: 3;
  vector-effect: non-scaling-stroke;
  opacity: 0;
}
.board:focus ~ .board-lines .cursor.on { opacity: 1; }

.cell {
  position: relative;
  display: grid;
  place-items: center;
  background: var(--c, #eee);
  min-width: 0;
  min-height: 0;
}

.cell .mark {
  position: relative;
  z-index: 1;
  width: 64%;
  height: 64%;
  pointer-events: none;
}

.cell.queen .mark { fill: var(--ink); animation: pop 0.16s ease-out; }
/* Crosses take a larger share of the cell as the grid grows, so they stay
   readable on big boards: 44% of the cell at 6×6 up to 68% at 14×14. */
.cell.cross .mark {
  --x: min(72%, calc(26% + var(--n, 8) * 3%));
  width: var(--x);
  height: var(--x);
  color: rgba(41, 37, 58, 0.4);
  transition: color 1.2s ease-out;
}
/* Crosses from the last tap or drag pulse gently in the accent colour until
   the next move (15 s at most), then fade back to normal (see markFresh in
   app.js, which also keeps every cross in step via --pulse-delay). */
.cell.cross.fresh .mark {
  color: rgba(90, 75, 209, 0.85);
  transition: none;
  animation:
    pop 0.14s ease-out,
    cross-pulse 1.6s ease-in-out var(--pulse-delay, 0s) infinite;
}
@keyframes cross-pulse {
  0%, 100% { color: rgba(90, 75, 209, 0.9); scale: 1; }
  50% { color: rgba(90, 75, 209, 0.45); scale: 0.86; }
}

/* Cells ruled out by a queen (optional auto-mark setting) */
.cell.auto::before {
  content: "";
  width: 16%;
  height: 16%;
  border-radius: 50%;
  background: rgba(41, 37, 58, 0.3);
}

/* Conflicts */
.cell.bad::after {
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    -45deg,
    rgba(210, 58, 72, 0.32) 0 3px,
    rgba(210, 58, 72, 0) 3px 8px
  );
  pointer-events: none;
}
.cell.queen.clash .mark { fill: var(--danger); animation: shake 0.3s ease-in-out; }

/* "Show mistakes" setting: a queen off the solution, or a cross on it */
.cell.wrong { box-shadow: inset 0 0 0 2.5px rgba(210, 58, 72, 0.85); }
.cell.queen.wrong .mark { fill: var(--danger); }
.cell.cross.wrong .mark { color: var(--danger); }

/* Hint-placed queens: locked, shown in the accent colour */
.cell.locked .mark { fill: var(--accent); }
.cell.flash { animation: flash 0.9s ease-out; }
.cell.nope { animation: nudge 0.25s ease-in-out; }

/* Solved */
.board.solved .cell.queen .mark {
  fill: var(--gold);
  animation: win-pop 0.5s ease-out both;
  animation-delay: calc(var(--d, 0) * 60ms);
}
.board.solved .cell { animation: win-wave 0.7s ease-out both; animation-delay: calc(var(--w, 0) * 28ms); }

@keyframes pop { from { transform: scale(0.55); opacity: 0.4; } to { transform: scale(1); opacity: 1; } }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-8%); }
  75% { transform: translateX(8%); }
}
@keyframes nudge {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(0.92); }
}
@keyframes flash {
  0% { box-shadow: inset 0 0 0 999px rgba(90, 75, 209, 0.45); }
  100% { box-shadow: inset 0 0 0 999px rgba(90, 75, 209, 0); }
}
@keyframes win-pop {
  0% { transform: scale(1); }
  45% { transform: scale(1.3) rotate(-6deg); }
  100% { transform: scale(1); }
}
@keyframes win-wave {
  0% { filter: brightness(1); }
  40% { filter: brightness(1.12) saturate(1.2); }
  100% { filter: brightness(1); }
}

/* Loading overlay */
.loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 12px;
  border-radius: var(--board-radius);
  background: var(--overlay);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  font-weight: 600;
  color: var(--ink-soft);
  z-index: 2;
}
.loading[hidden] { display: none; }
.loading p { margin: 0; padding: 0 16px; text-align: center; white-space: pre-line; line-height: 1.5; }
.spinner {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3.5px solid var(--accent-soft);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --------------------------------------------------------------- Actions */

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  padding-top: 10px;
}

.action {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-height: 60px;
  padding: 6px 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 0.82rem;
  font-weight: 650;
  color: var(--ink-soft);
  transition: transform 0.08s ease, background 0.15s ease;
}
.action svg { width: 24px; height: 24px; }
.action:active { transform: scale(0.96); }
.action:disabled { opacity: 0.4; cursor: default; transform: none; }

@media (hover: hover) {
  .action:not(:disabled):hover { background: var(--surface-2); }
}

/* ----------------------------------------------------------------- Toast */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(96px + env(safe-area-inset-bottom));
  transform: translate(-50%, 12px);
  max-width: min(92vw, 420px);
  padding: 10px 16px;
  border-radius: 12px;
  background: var(--toast-bg);
  color: var(--toast-ink);
  font-size: 0.92rem;
  font-weight: 550;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 10;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------------------------------------------------------------- Sheets */

.sheet {
  width: 100%;
  max-width: 520px;
  max-height: 92dvh;
  margin: auto auto 0;
  padding: 0;
  border: 0;
  border-radius: 22px 22px 0 0;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--sheet-shadow);
  overflow: auto;
  overflow-x: hidden; /* menu pages slide in sideways */
}
.sheet[open] { animation: sheet-up 0.22s ease-out; }
/* Written out in full: older browsers do not pass variables to ::backdrop. */
.sheet::backdrop { background: rgba(30, 26, 44, 0.38); }
:root[data-theme="dark"] .sheet::backdrop { background: rgba(0, 0, 0, 0.55); }

@keyframes sheet-up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }

@media (min-width: 700px) and (min-height: 600px) {
  .sheet { margin: auto; border-radius: 22px; }
}

.sheet-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 18px 20px calc(20px + env(safe-area-inset-bottom));
}

.sheet-head { display: flex; align-items: center; gap: 2px; margin: -4px -8px -4px 0; }
.sheet-title { flex: 1; min-width: 0; }
.back-btn { margin-left: -10px; }
.sheet h2:focus { outline: none; }
.sheet h2 { margin: 0; font-size: 1.3rem; font-weight: 800; }
.puzzle-meta { margin: 3px 0 0; color: var(--muted); font-size: 0.92rem; font-variant-numeric: tabular-nums; }
.sheet h3 { margin: 6px 0 -6px; font-size: 1rem; }

.field { margin: 0; padding: 0; border: 0; min-width: 0; }
.field legend { padding: 0; margin-bottom: 8px; font-weight: 700; font-size: 0.9rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }

.segmented {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(48px, 1fr));
  gap: 6px;
}

.opt {
  position: relative;
  display: block;
}
.opt input { position: absolute; opacity: 0; pointer-events: none; }
.opt > span {
  display: grid;
  place-items: center;
  min-height: 46px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  font-weight: 700;
  cursor: pointer;
}
.opt > input:checked + span { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-text); }
.opt > input:focus-visible + span { outline: 2px solid var(--accent-text); outline-offset: 2px; }

.segmented.themes { grid-template-columns: repeat(3, 1fr); }

.difficulty-list { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.difficulty-list .opt > span {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 10px 12px;
  min-height: 64px;
  text-align: left;
}
.difficulty-list .opt small { font-weight: 500; color: var(--muted); font-size: 0.78rem; line-height: 1.25; }
.difficulty-list .opt > input:checked + span small { color: var(--accent-text); opacity: 0.85; }
.pips { display: inline-flex; gap: 3px; margin-left: 6px; vertical-align: middle; }
.pips i { width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: 0.25; }
.pips i.on { opacity: 1; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 18px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  font-weight: 700;
}
.btn svg { width: 20px; height: 20px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.wide { width: 100%; min-height: 52px; font-size: 1.05rem; }
.btn:disabled { opacity: 0.5; }

.code-entry summary { cursor: pointer; color: var(--muted); font-weight: 600; font-size: 0.92rem; }
.code-row { display: flex; gap: 8px; margin-top: 10px; }
.code-row input {
  flex: 1;
  min-width: 0;
  min-height: 46px;
  padding: 0 12px;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
  color: inherit;
  font: inherit;
  font-size: 16px; /* stops iOS zooming in */
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
}
.code-row input:focus { outline: none; border-color: var(--accent); }
.code-error { margin: 6px 0 0; min-height: 1.2em; color: var(--danger); font-size: 0.88rem; }
.code-error:empty { display: none; }

.lead { margin: 0; line-height: 1.5; color: var(--ink-soft); }
.rules, .controls { margin: 0; padding: 0; list-style: none; display: grid; gap: 8px; line-height: 1.45; }
.rules li { display: flex; align-items: center; gap: 10px; }
.rule-num {
  flex: none;
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent-text);
  font-weight: 800;
  font-size: 0.85rem;
}
.controls li { color: var(--ink-soft); }
.inline-icon { display: inline-block; width: 1.1em; height: 1.1em; vertical-align: -0.18em; }
.inline-icon svg { width: 100%; height: 100%; fill: var(--ink); }
.inline-icon.x svg { color: var(--muted); }
kbd {
  display: inline-block;
  padding: 0 5px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
  font: 600 0.8em var(--font);
  background: var(--bg);
}
@media (hover: none) { .kbd-only { display: none; } }

.toggle { display: flex; align-items: center; gap: 12px; cursor: pointer; }
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle-ui {
  flex: none;
  position: relative;
  width: 48px;
  height: 28px;
  border-radius: 999px;
  background: var(--toggle-off);
  transition: background 0.15s ease;
}
.toggle-ui::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.2);
  transition: transform 0.15s ease;
}
.toggle input:checked + .toggle-ui { background: var(--accent); }
.toggle input:checked + .toggle-ui::after { transform: translateX(20px); }
.toggle input:focus-visible + .toggle-ui { outline: 2px solid var(--accent-text); outline-offset: 2px; }
.toggle-text { display: flex; flex-direction: column; gap: 2px; }
/* A switch that belongs to the one above it: indented under its text. */
.toggle.sub { margin: -6px 0 0 60px; }
.toggle input:disabled + .toggle-ui,
.toggle input:disabled + .toggle-ui + .toggle-text { opacity: 0.45; }
.toggle:has(input:disabled) { cursor: default; }
.toggle-text small { color: var(--muted); }

/* ------------------------------------------------------------------ Menu */

.page-body { display: flex; flex-direction: column; gap: 16px; }

.menu-list { display: grid; gap: 8px; }
.menu-item {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  min-height: 62px;
  padding: 10px 12px 10px 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  text-align: left;
  transition: background 0.15s ease, transform 0.08s ease;
}
.menu-item > svg { flex: none; width: 24px; height: 24px; color: var(--ink-soft); }
.menu-item .chev { width: 20px; height: 20px; color: var(--muted); }
.mi-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.mi-text b { font-weight: 700; }
.mi-text small { color: var(--muted); font-size: 0.82rem; }
.menu-item:active:not(:disabled) { transform: scale(0.985); }
.menu-item:disabled { opacity: 0.45; cursor: default; }
.menu-item:focus-visible { outline: 2px solid var(--accent-text); outline-offset: 2px; }
@media (hover: hover) {
  .menu-item:not(:disabled):hover { background: var(--surface-2); }
}

/* Pages slide in from the side they come from. */
.menu-page.enter-fwd { animation: page-in-fwd 0.18s ease-out; }
.menu-page.enter-back { animation: page-in-back 0.18s ease-out; }
@keyframes page-in-fwd { from { transform: translateX(28px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes page-in-back { from { transform: translateX(-28px); opacity: 0; } to { transform: none; opacity: 1; } }

.stats { font-size: 0.88rem; color: var(--muted); }
.stats:empty { display: none; }
.stats table { width: 100%; border-collapse: collapse; margin-top: 4px; }
.stats th, .stats td { padding: 5px 4px; text-align: left; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.stats th { font-weight: 700; color: var(--ink-soft); }

/* Win sheet */
.win .sheet-body { align-items: center; text-align: center; gap: 10px; padding-top: 26px; }
.win-crown {
  width: 64px;
  height: 64px;
  display: grid;
  place-items: center;
  border-radius: 20px;
  background: var(--badge);
  animation: win-pop 0.6s ease-out;
}
.win-crown svg { width: 40px; height: 40px; fill: #ffd66e; }
.win h2 { font-size: 1.6rem; }
.win-sub { margin: -4px 0 4px; color: var(--muted); }
.win-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  width: 100%;
  margin: 4px 0 8px;
}
.win-stats div { padding: 10px 6px; border-radius: 12px; background: var(--bg); }
.win-stats dt { font-size: 0.75rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; font-weight: 700; }
.win-stats dd { margin: 2px 0 0; font-size: 1.2rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.win-stats .new-best dd { color: var(--accent-text); }
.win-actions { display: grid; grid-template-columns: 1fr 1.4fr; gap: 10px; width: 100%; }
.link-btn { border: 0; background: none; color: var(--muted); font-weight: 600; padding: 10px; }

/* ------------------------------------------------------------ Small/large */

@media (max-width: 360px) {
  .brand { font-size: 1.1rem; }
  .action { font-size: 0.74rem; min-height: 54px; }
}

@media (min-width: 700px) {
  .app { padding-top: 20px; padding-bottom: 24px; }
  .topbar { margin-bottom: 4px; }
}

/* Phones held sideways: board on the left, controls on the right. */
@media (orientation: landscape) and (max-height: 540px) {
  .app {
    max-width: 980px;
    display: grid;
    grid-template-columns: 1fr minmax(220px, 280px);
    grid-template-rows: auto 1fr auto;
    column-gap: 20px;
  }
  .topbar { grid-column: 2; grid-row: 1; }
  .brand { font-size: 1.1rem; }
  .icon-btn { width: 40px; }
  .stage { grid-column: 1; grid-row: 1 / 4; }
  .actions { grid-column: 2; grid-row: 3; }
  .menu-list { grid-template-columns: 1fr 1fr; }
  .menu-item { min-height: 56px; }
  .action { min-height: 52px; }
  .play, .has-intro .play { width: min(100cqw - 6px, 100cqh - 40px); }
  .intro { display: none; }
  .toast { bottom: 50%; }
}

@media (prefers-reduced-motion: reduce) {
  /* Play each animation once, instantly; looping ones would flicker. */
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-delay: 0ms !important;
    animation-iteration-count: 1 !important;
    transition: none !important;
  }
}
