/*
 * IVORY GAMBIT — interface styles.
 *
 * Every colour here is a custom property written by the theme manager, so switching theme is one
 * write to `<html>` rather than a stylesheet swap. The only hard-coded colours are inside the
 * boot screen, which has to paint before any JavaScript has run.
 *
 * Layout is driven by `html[data-layout]`, set by the layout manager from the aspect ratio. The
 * three modes rearrange the same elements rather than hiding and duplicating them — a phone gets
 * the identical move list the desktop does, moved into a drawer.
 */

:root {
  /* Overwritten by the theme manager on first paint; these keep the boot screen coherent. */
  --bg: #1d1710;
  --bg-accent: #33261a;
  --surface: rgba(48, 36, 24, 0.72);
  --surface-edge: rgba(233, 205, 158, 0.14);
  --text: #f4ead9;
  --muted: #bda887;
  --accent: #e0a44a;
  --accent-ink: #2a1c0c;
  --frame: #4b3221;
  --frame-edge: #2e2114;
  --sq-light: #efdfc0;
  --sq-dark: #a9784f;
  --check: #dc3c2d;

  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --radius: 16px;
  --radius-sm: 10px;
  --pad: 16px;
  --shadow: 0 18px 44px rgba(0, 0, 0, 0.45);
  --transition: 220ms cubic-bezier(0.22, 1, 0.36, 1);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  overflow: hidden;         /* the game manages its own scrolling regions */
  overscroll-behavior: none;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  /* Selection makes drag-to-move feel broken: the pointer picks up text instead of a piece. */
  user-select: none;
  -webkit-user-select: none;
}

/*
 * The page background.
 *
 * Pure CSS, deliberately. An animated canvas behind the board would compete with the board for
 * frames and for battery, and this achieves the same "the board is somewhere, not nowhere" with
 * zero per-frame cost: two large radial washes and one very slow drift the GPU composites on its
 * own thread.
 */
body::before {
  content: '';
  position: fixed;
  inset: -20%;
  z-index: -2;
  background:
    radial-gradient(58% 46% at 22% 8%, var(--bg-accent), transparent 62%),
    radial-gradient(52% 44% at 84% 92%, var(--bg-accent), transparent 60%);
  opacity: 0.85;
  animation: drift 44s ease-in-out infinite alternate;
  will-change: transform;
}

/* A faint vignette, so the corners sit back and the board sits forward. */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background: radial-gradient(120% 90% at 50% 45%, transparent 42%, rgba(0, 0, 0, 0.55) 100%);
}

@keyframes drift {
  from { transform: translate3d(-2%, -1%, 0) scale(1.02); }
  to   { transform: translate3d(2.5%, 2%, 0) scale(1.08); }
}

@media (prefers-reduced-motion: reduce) {
  body::before { animation: none; }
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

/* ── boot screen ─────────────────────────────────────────────────────────── */

#boot {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  background: #1d1710;
  transition: opacity 420ms ease, visibility 420ms;
}
#boot.gone { opacity: 0; visibility: hidden; pointer-events: none; }

.boot-inner { text-align: center; }

/* A 4x4 checker that fades its squares in one by one — a chess board assembling itself. */
.boot-mark {
  width: 108px; height: 108px;
  margin: 0 auto 26px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.5);
}
/*
 * The checker pattern is listed square by square rather than derived with `nth-child(2n)`.
 *
 * A 4-wide grid alternating on every cell produces vertical stripes, not a checkerboard — the
 * pattern has to invert on each row, and expressing that in modular arithmetic across a
 * 16-element list is both unreadable and easy to get subtly wrong. Eight indices is clearer
 * than a formula nobody can verify at a glance.
 */
.boot-mark span { background: #a9784f; animation: bootsq 1.9s ease-in-out infinite; }
.boot-mark span:nth-child(1), .boot-mark span:nth-child(3),
.boot-mark span:nth-child(6), .boot-mark span:nth-child(8),
.boot-mark span:nth-child(9), .boot-mark span:nth-child(11),
.boot-mark span:nth-child(14), .boot-mark span:nth-child(16) { background: #efdfc0; }
.boot-mark span:nth-child(1) { animation-delay: 0ms; }
.boot-mark span:nth-child(2) { animation-delay: 60ms; }
.boot-mark span:nth-child(3) { animation-delay: 120ms; }
.boot-mark span:nth-child(4) { animation-delay: 180ms; }
.boot-mark span:nth-child(5) { animation-delay: 60ms; }
.boot-mark span:nth-child(6) { animation-delay: 120ms; }
.boot-mark span:nth-child(7) { animation-delay: 180ms; }
.boot-mark span:nth-child(8) { animation-delay: 240ms; }
.boot-mark span:nth-child(9) { animation-delay: 120ms; }
.boot-mark span:nth-child(10) { animation-delay: 180ms; }
.boot-mark span:nth-child(11) { animation-delay: 240ms; }
.boot-mark span:nth-child(12) { animation-delay: 300ms; }
.boot-mark span:nth-child(13) { animation-delay: 180ms; }
.boot-mark span:nth-child(14) { animation-delay: 240ms; }
.boot-mark span:nth-child(15) { animation-delay: 300ms; }
.boot-mark span:nth-child(16) { animation-delay: 360ms; }

@keyframes bootsq { 0%, 100% { opacity: 0.35; } 45% { opacity: 1; } }

.boot-title {
  font-size: 26px; font-weight: 800; letter-spacing: 0.34em;
  color: #f4ead9; text-indent: 0.34em;
}
.boot-sub { margin-top: 10px; font-size: 13px; letter-spacing: 0.16em; color: #bda887; text-transform: uppercase; }

.noscript { display: grid; place-items: center; height: 100vh; text-align: center; padding: 24px; }
.noscript h1 { letter-spacing: 0.3em; margin-bottom: 12px; }

/* ── app shell ───────────────────────────────────────────────────────────── */

#app {
  position: fixed;
  inset: 0;
  display: grid;
  /* Respect the notch and the home indicator; without this the bottom bar sits under the bar. */
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
           env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.screen {
  grid-area: 1 / 1;
  display: none;
  min-height: 0;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity var(--transition), transform var(--transition);
}
.screen.active { display: grid; }
/*
 * `.shown` is added a paint after `.active`, never in the same frame.
 *
 * A transition from `display: none` does not run — the browser has no previous computed style to
 * animate from — so the class that starts the animation has to land after the element is
 * already laid out. This bit us on a previous game, where every menu button stopped responding
 * because a transition that never ended left the screen permanently mid-fade.
 */
.screen.shown { opacity: 1; transform: none; }

/* ── typography and controls ─────────────────────────────────────────────── */

h1, h2, h3 { font-weight: 750; letter-spacing: -0.01em; }

.title {
  font-size: clamp(34px, 8vw, 62px);
  letter-spacing: 0.16em;
  text-indent: 0.16em;
  line-height: 1;
  background: linear-gradient(180deg, var(--text), var(--muted));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 2px 20px rgba(0, 0, 0, 0.35);
}
.tagline {
  margin-top: 10px;
  font-size: 12px; letter-spacing: 0.32em; text-transform: uppercase; color: var(--muted);
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
  /* A button that is hard to hit on a phone is the single most common mobile UI failure. */
  min-height: 44px;
  touch-action: manipulation;
}
button:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 6px;
}

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  padding: 13px 26px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.06em;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.32);
  transition: transform 130ms ease, box-shadow 130ms ease, filter 130ms ease;
}
.btn:hover { transform: translateY(-1px); filter: brightness(1.06); }
.btn:active { transform: translateY(1px) scale(0.985); box-shadow: 0 4px 12px rgba(0,0,0,0.3); }

.btn.ghost {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--surface-edge);
  box-shadow: none;
  backdrop-filter: blur(8px);
}
.btn.ghost:hover { border-color: var(--accent); }
.btn.wide { width: 100%; }
.btn.small { padding: 9px 16px; font-size: 13px; min-height: 38px; }
.btn[disabled] { opacity: 0.4; pointer-events: none; }

.panel {
  background: var(--surface);
  border: 1px solid var(--surface-edge);
  border-radius: var(--radius);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

/* ── main menu ───────────────────────────────────────────────────────────── */

/* Screens are given ids of the form `screen-<name>` by the app; matching on the bare name
   silently styles nothing, and the menu ends up jammed into the top-left corner. */
#screen-menu {
  place-items: center;
  align-content: center;
  overflow-y: auto;
  padding: 32px 20px;
}
.menu-inner { width: min(440px, 100%); text-align: center; }
.menu-buttons { display: grid; gap: 11px; margin-top: 34px; }

.menu-foot {
  margin-top: 26px; font-size: 11.5px; color: var(--muted); letter-spacing: 0.08em;
  display: flex; gap: 14px; justify-content: center; flex-wrap: wrap;
}
.menu-foot b { color: var(--text); font-weight: 700; }

/* ── setup / list screens ────────────────────────────────────────────────── */

.sheet {
  width: min(560px, 100%);
  margin: auto;
  padding: 22px;
  display: grid;
  gap: 18px;
}
.screen.sheet-screen { overflow-y: auto; place-items: start center; padding: 20px 16px 40px; }

.sheet h2 { font-size: 22px; letter-spacing: 0.06em; }
.sheet-head { display: flex; align-items: center; gap: 14px; }
.sheet-head .back { font-size: 22px; line-height: 1; padding: 8px 12px; border-radius: 10px; }
.sheet-head .back:hover { background: var(--surface); }

.field { display: grid; gap: 9px; }
.field > label { font-size: 11.5px; letter-spacing: 0.18em; text-transform: uppercase; color: var(--muted); }

.choices { display: flex; flex-wrap: wrap; gap: 8px; }
.choice {
  padding: 11px 16px;
  border-radius: 12px;
  border: 1px solid var(--surface-edge);
  background: rgba(0, 0, 0, 0.18);
  font-size: 14px;
  transition: border-color 140ms ease, background 140ms ease, transform 140ms ease;
  text-align: left;
}
.choice:hover { border-color: var(--accent); transform: translateY(-1px); }
.choice[aria-pressed="true"] {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 22%, transparent);
  box-shadow: inset 0 0 0 1px var(--accent);
}
.choice small { display: block; font-size: 11px; color: var(--muted); margin-top: 3px; }
.choice.grow { flex: 1 1 150px; }

/* ── game screen ─────────────────────────────────────────────────────────── */

#screen-game { min-height: 0; }

.game-grid {
  display: grid;
  width: 100%;
  height: 100%;
  min-height: 0;
  gap: 14px;
  padding: 12px;
  align-content: center;
  justify-content: center;
}

/*
 * Three arrangements of the same five elements: the two player strips, the board, the move
 * panel and the control bar. Nothing is duplicated or hidden per layout except the move panel,
 * which becomes a drawer where there is no room beside the board.
 */
html[data-layout="desktop"] .game-grid {
  grid-template-columns: auto 300px;
  grid-template-rows: auto auto auto;
  grid-template-areas:
    "top    side"
    "board  side"
    "bottom bar";
  align-items: center;
}
html[data-layout="portrait"] .game-grid {
  grid-template-columns: 1fr;
  grid-template-rows: auto auto auto auto;
  grid-template-areas: "top" "board" "bottom" "bar";
  align-content: center;
  gap: 10px;
}
html[data-layout="landscape-compact"] .game-grid {
  grid-template-columns: minmax(140px, 210px) auto minmax(140px, 210px);
  grid-template-rows: auto auto 1fr;
  grid-template-areas:
    "top   board bottom"
    "side  board bar"
    "side  board .";
  align-items: start;
  gap: 8px;
  padding: 8px;
}
html[data-layout="landscape-compact"] .board-area { align-self: center; }

.board-area { grid-area: board; display: grid; place-items: center; position: relative; }
.board-canvas { display: block; border-radius: 14px; }

.side { grid-area: side; display: grid; gap: 12px; align-content: start; min-height: 0; max-height: 100%; }

/* Player strips. In portrait they stack; in landscape they split left and right. */
.player {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 13px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--surface-edge);
  transition: border-color 200ms ease, box-shadow 200ms ease;
}
.player.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent), 0 8px 22px rgba(0,0,0,.28); }
.player .who { display: grid; gap: 2px; min-width: 0; flex: 1; }
.player .name { font-weight: 700; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.player .meta { font-size: 11px; color: var(--muted); }
.player .dot { width: 13px; height: 13px; border-radius: 50%; flex: none; border: 1px solid rgba(0,0,0,.35); }
.player .dot.w { background: linear-gradient(160deg, #fdfaf3, #cdbfa4); }
.player .dot.b { background: linear-gradient(160deg, #5a606e, #191c24); }

.clock {
  font-family: var(--mono);
  font-size: 21px; font-weight: 700;
  padding: 5px 11px; border-radius: 9px;
  background: rgba(0, 0, 0, 0.3);
  font-variant-numeric: tabular-nums;
  min-width: 84px; text-align: center;
}
.player.active .clock { background: color-mix(in srgb, var(--accent) 20%, rgba(0,0,0,.3)); }
.clock.low { color: var(--check); animation: lowpulse 1s ease-in-out infinite; }
@keyframes lowpulse { 50% { opacity: 0.45; } }

/* Captured pieces + material edge. */
.captures { display: flex; align-items: center; gap: 1px; flex-wrap: wrap; min-height: 20px; }
.captures img { width: 19px; height: 19px; display: block; margin-right: -6px; }
.captures .edge { margin-left: 12px; font-size: 12px; font-weight: 700; color: var(--accent); }

.player.top { grid-area: top; }
.player.bottom { grid-area: bottom; }
.controls { grid-area: bar; }

/* Move history. */
.history { display: grid; grid-template-rows: auto 1fr; min-height: 0; }
.history h3 {
  font-size: 11px; letter-spacing: 0.18em; text-transform: uppercase;
  color: var(--muted); padding: 12px 14px 8px;
  display: flex; justify-content: space-between; align-items: center;
}
.moves {
  overflow-y: auto;
  padding: 0 8px 10px;
  font-family: var(--mono);
  font-size: 13px;
  scrollbar-width: thin;
  max-height: 42vh;
}
html[data-layout="desktop"] .moves { max-height: min(46vh, 420px); }
.moves .row { display: grid; grid-template-columns: 34px 1fr 1fr; gap: 2px; align-items: center; }
.moves .no { color: var(--muted); font-size: 11.5px; text-align: right; padding-right: 8px; }
.moves .san {
  padding: 4px 7px; border-radius: 6px; cursor: pointer;
  transition: background 120ms ease;
}
.moves .san:hover { background: rgba(255, 255, 255, 0.07); }
.moves .san.current { background: color-mix(in srgb, var(--accent) 26%, transparent); font-weight: 700; }
.moves .empty { padding: 10px 14px; color: var(--muted); font-family: var(--font); font-size: 12.5px; }

/* Control bar. */
.controls { display: flex; gap: 7px; flex-wrap: wrap; align-content: start; }
html[data-layout="portrait"] .controls { justify-content: center; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 14px; min-height: 40px;
  border-radius: 11px;
  background: var(--surface);
  border: 1px solid var(--surface-edge);
  font-size: 12.5px; font-weight: 600;
  transition: border-color 140ms ease, transform 140ms ease;
}
.icon-btn:hover { border-color: var(--accent); transform: translateY(-1px); }
.icon-btn[disabled] { opacity: 0.35; pointer-events: none; }
.icon-btn .k { font-size: 15px; }

.thinking {
  position: absolute; left: 50%; bottom: -34px; transform: translateX(-50%);
  display: none; align-items: center; gap: 9px;
  font-size: 12px; color: var(--muted); letter-spacing: 0.05em; white-space: nowrap;
}
.thinking.on { display: flex; }
.thinking .spin {
  width: 13px; height: 13px; border-radius: 50%;
  border: 2px solid var(--surface-edge); border-top-color: var(--accent);
  animation: spin 700ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* A brief banner over the board: CHECK, or a puzzle verdict. */
.flash {
  position: absolute; left: 50%; top: 12%;
  transform: translate(-50%, -6px);
  padding: 9px 22px; border-radius: 999px;
  font-weight: 800; letter-spacing: 0.22em; font-size: 13px;
  background: var(--check); color: #fff;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
  opacity: 0; pointer-events: none;
  transition: opacity 200ms ease, transform 200ms ease;
}
.flash.on { opacity: 1; transform: translate(-50%, 0); }
.flash.good { background: var(--accent); color: var(--accent-ink); }

/* ── modals ──────────────────────────────────────────────────────────────── */

.modal-root {
  position: fixed; inset: 0; z-index: 60;
  display: none; place-items: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.62);
  backdrop-filter: blur(5px);
  opacity: 0;
  transition: opacity 200ms ease;
}
.modal-root.active { display: grid; }
.modal-root.shown { opacity: 1; }

/*
 * Modals are near-opaque, unlike the translucent panels elsewhere.
 *
 * A dialog sits over the board, and the board is the busiest, highest-contrast thing on the
 * screen. At the panel's usual 74% the promotion pieces were competing with the rank behind
 * them — readable, but reading as an overlay rather than as a decision the game is waiting on.
 */
.modal {
  width: min(430px, 100%);
  background: color-mix(in srgb, var(--bg) 92%, #000);
  padding: 26px;
  text-align: center;
  transform: translateY(12px) scale(0.97);
  transition: transform 260ms cubic-bezier(0.22, 1, 0.36, 1);
  max-height: 88vh;
  overflow-y: auto;
}
.modal-root.shown .modal { transform: none; }
.modal h2 { font-size: 15px; letter-spacing: 0.26em; color: var(--muted); text-transform: uppercase; }
.modal .headline { font-size: 30px; margin: 8px 0 4px; letter-spacing: 0.02em; }
.modal .reason { color: var(--muted); font-size: 13.5px; margin-bottom: 18px; }
.modal .actions { display: grid; gap: 9px; margin-top: 20px; }
.modal .actions.row { grid-auto-flow: column; }

.result-stats {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 9px;
  margin-top: 6px;
}
.result-stats div {
  padding: 11px; border-radius: 11px;
  background: rgba(0, 0, 0, 0.24);
  border: 1px solid var(--surface-edge);
}
.result-stats .v { font-size: 19px; font-weight: 750; }
.result-stats .l { font-size: 10.5px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); margin-top: 2px; }

/* Promotion picker. */
.promo-choices { display: grid; grid-template-columns: repeat(4, 1fr); gap: 9px; margin-top: 16px; }
.promo-choices button {
  padding: 9px; border-radius: 13px;
  background: rgba(0, 0, 0, 0.24);
  border: 1px solid var(--surface-edge);
  display: grid; place-items: center; gap: 5px;
  transition: border-color 140ms ease, transform 140ms ease, background 140ms ease;
}
.promo-choices button:hover { border-color: var(--accent); transform: translateY(-2px); }
.promo-choices img { width: 100%; max-width: 72px; display: block; }
.promo-choices span { font-size: 10px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); }

/* ── settings, stats, themes ─────────────────────────────────────────────── */

.rows { display: grid; gap: 2px; }
.row-item {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 13px 14px;
  border-radius: 11px;
  transition: background 140ms ease;
}
.row-item:hover { background: rgba(255, 255, 255, 0.045); }
.row-item .rl { display: grid; gap: 2px; min-width: 0; }
.row-item .rl b { font-weight: 650; font-size: 14px; }
.row-item .rl small { font-size: 11.5px; color: var(--muted); }

.toggle {
  width: 50px; height: 29px; border-radius: 999px; flex: none;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--surface-edge);
  position: relative;
  transition: background 180ms ease, border-color 180ms ease;
  min-height: 29px;
}
.toggle::after {
  content: ''; position: absolute; top: 3px; left: 3px;
  width: 21px; height: 21px; border-radius: 50%;
  background: var(--muted);
  transition: transform 200ms cubic-bezier(0.22, 1, 0.36, 1), background 180ms ease;
}
.toggle[aria-pressed="true"] { background: color-mix(in srgb, var(--accent) 40%, transparent); border-color: var(--accent); }
.toggle[aria-pressed="true"]::after { transform: translateX(21px); background: var(--accent); }

input[type="range"] {
  width: 130px; accent-color: var(--accent); background: none; flex: none;
}

.theme-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 11px; }
.theme-card {
  padding: 0; overflow: hidden; border-radius: 14px;
  border: 1px solid var(--surface-edge);
  background: var(--surface);
  text-align: left;
  transition: border-color 150ms ease, transform 150ms ease;
  display: grid;
}
.theme-card:hover { transform: translateY(-2px); }
.theme-card[aria-pressed="true"] { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.theme-swatch { height: 68px; display: grid; grid-template-columns: repeat(4, 1fr); grid-template-rows: repeat(2, 1fr); }
.theme-card .tl { padding: 10px 12px 12px; }
.theme-card .tl b { display: block; font-size: 13.5px; }
.theme-card .tl small { font-size: 11px; color: var(--muted); }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 9px; }
.stat {
  padding: 13px 12px; border-radius: 12px;
  background: rgba(0, 0, 0, 0.24); border: 1px solid var(--surface-edge);
}
.stat .v { font-size: 22px; font-weight: 750; line-height: 1.1; }
.stat .l { font-size: 10px; letter-spacing: 0.13em; text-transform: uppercase; color: var(--muted); margin-top: 4px; }

.match-list { display: grid; gap: 6px; }
.match {
  display: flex; align-items: center; gap: 11px;
  padding: 11px 13px; border-radius: 11px;
  background: rgba(0, 0, 0, 0.2); border: 1px solid var(--surface-edge);
  font-size: 12.5px;
}
.match .badge {
  font-size: 10px; font-weight: 800; letter-spacing: 0.1em;
  padding: 4px 8px; border-radius: 6px; flex: none;
}
.match .badge.win { background: color-mix(in srgb, var(--accent) 82%, #000); color: var(--accent-ink); }
.match .badge.loss { background: color-mix(in srgb, var(--check) 70%, #000); color: #fff; }
.match .badge.draw { background: rgba(255, 255, 255, 0.14); color: var(--text); }
.match .m { color: var(--muted); margin-left: auto; white-space: nowrap; }

/* Puzzle list. */
.puzzle-list { display: grid; gap: 8px; }
.puzzle-card {
  display: flex; align-items: center; gap: 13px;
  padding: 13px 15px; border-radius: 13px;
  background: var(--surface); border: 1px solid var(--surface-edge);
  text-align: left;
  transition: border-color 150ms ease, transform 150ms ease;
}
.puzzle-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.puzzle-card .pk {
  font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase;
  padding: 4px 8px; border-radius: 6px; flex: none;
  background: rgba(0, 0, 0, 0.3); color: var(--muted);
}
.puzzle-card .pt { display: grid; gap: 2px; flex: 1; min-width: 0; }
.puzzle-card .pt b { font-size: 14px; }
.puzzle-card .pt small { font-size: 11.5px; color: var(--muted); }
.puzzle-card .done { color: var(--accent); font-size: 17px; flex: none; }

.hint-text { font-size: 12.5px; color: var(--muted); line-height: 1.55; }

/* ── history drawer (portrait / compact) ─────────────────────────────────── */

.drawer {
  position: fixed; inset: auto 0 0 0; z-index: 50;
  max-height: 72vh;
  border-radius: 20px 20px 0 0;
  transform: translateY(101%);
  transition: transform 300ms cubic-bezier(0.22, 1, 0.36, 1);
  display: grid; grid-template-rows: auto 1fr;
  padding-bottom: env(safe-area-inset-bottom);
}
.drawer.open { transform: none; }
.drawer .grip { width: 42px; height: 4px; border-radius: 99px; background: var(--surface-edge); margin: 10px auto 2px; }

/* ── scrollbars ──────────────────────────────────────────────────────────── */

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--surface-edge); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }
