/* gammon. Design tokens follow the Kame family: a dark table by default, paper and ink materials,
   one vermilion accent for action and targets, Bricolage Grotesque with JetBrains Mono. */

:root {
  color-scheme: dark;
  --table: #0f1311;
  --table-2: #161b18;
  --table-3: #1e2521;
  --table-4: #273029;
  --ink: #e9ede7;
  --ink-2: #a5afa8;
  --ink-3: #6e7871;
  --rule: rgb(233 237 231 / 0.09);
  --rule-strong: rgb(233 237 231 / 0.2);

  --accent: #f2552c;
  --accent-2: #ff6a40;
  --accent-ink: #1c0a04;
  --accent-soft: rgb(242 85 44 / 0.16);
  --accent-ring: rgb(242 85 44 / 0.8);

  --paper: #eceee8;
  --paper-ink: #131714;
  --shadow: rgb(2 6 4 / 0.55);
  --shadow-soft: rgb(2 6 4 / 0.28);

  /* Board materials */
  --frame: #1c231f;
  --frame-rim: #2a332d;
  --felt: #1d3a2e;
  --felt-hi: #24493a;
  --pt-a: #ddd6c6;
  --pt-b: #4f7464;
  --bar: #151a17;
  --tray: #141916;
  --label: #6f8579;
  --chk-me-hi: #ffffff;
  --chk-me: #ecebe4;
  --chk-me-lo: #c4c0b2;
  --chk-me-line: rgb(60 50 30 / 0.16);
  --chk-opp-hi: #4b5550;
  --chk-opp: #262d2a;
  --chk-opp-lo: #101413;
  --chk-opp-line: rgb(255 255 255 / 0.1);
  --chk-shadow: rgb(0 0 0 / 0.35);
  --die: #f3f1ea;
  --die-pip: #171b19;

  /* Grades (semantic) */
  --g-best: #3fae74;
  --g-excellent: #66b98a;
  --g-inaccuracy: #e0a336;
  --g-mistake: #f07a3a;
  --g-blunder: #ef4b45;

  --font: "Bricolage Grotesque", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;

  --r-sheet: 24px;
  --r-card: 20px;
  --r-pill: 999px;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-sheet: cubic-bezier(0.32, 0.72, 0, 1);
  --spring: cubic-bezier(0.34, 1.56, 0.64, 1);

  --bar-h: 56px;
  --safe-t: env(safe-area-inset-top);
  --safe-b: env(safe-area-inset-bottom);
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --table: #e3e7e1; --table-2: #d9ded7; --table-3: #ccd3ca; --table-4: #bfc7bd;
    --ink: #121613; --ink-2: #4b544d; --ink-3: #7a837c;
    --rule: rgb(18 22 19 / 0.09); --rule-strong: rgb(18 22 19 / 0.2);
    --accent: #c43b16; --accent-2: #d84a22; --accent-ink: #fff8f5;
    --accent-soft: rgb(196 59 22 / 0.12); --accent-ring: rgb(196 59 22 / 0.75);
    --shadow: rgb(40 52 44 / 0.3); --shadow-soft: rgb(40 52 44 / 0.14);
    --frame: #27302b; --frame-rim: #34403a;
    --g-best: #23864f; --g-excellent: #3f9a67; --g-inaccuracy: #b07a12; --g-mistake: #c95a1d; --g-blunder: #c23631;
  }
}
:root[data-theme="light"] {
  color-scheme: light;
  --table: #e3e7e1; --table-2: #d9ded7; --table-3: #ccd3ca; --table-4: #bfc7bd;
  --ink: #121613; --ink-2: #4b544d; --ink-3: #7a837c;
  --rule: rgb(18 22 19 / 0.09); --rule-strong: rgb(18 22 19 / 0.2);
  --accent: #c43b16; --accent-2: #d84a22; --accent-ink: #fff8f5;
  --accent-soft: rgb(196 59 22 / 0.12); --accent-ring: rgb(196 59 22 / 0.75);
  --shadow: rgb(40 52 44 / 0.3); --shadow-soft: rgb(40 52 44 / 0.14);
  --frame: #27302b; --frame-rim: #34403a;
  --g-best: #23864f; --g-excellent: #3f9a67; --g-inaccuracy: #b07a12; --g-mistake: #c95a1d; --g-blunder: #c23631;
}

/* ---------- base ---------- */
* { box-sizing: border-box; }
html, body { margin: 0; }
html { -webkit-tap-highlight-color: transparent; background: var(--table); }
body {
  min-height: 100dvh;
  background: var(--table);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;
}
button, input { font: inherit; color: inherit; }
a { color: inherit; }
kbd, .mono { font-family: var(--mono); }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent-ring); outline-offset: 2px; border-radius: 8px; }

/* Film grain on a fixed layer, never on scrolling content. */
.grain {
  position: fixed; inset: 0; pointer-events: none; z-index: 90; opacity: 0.06; mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

.app { min-height: 100dvh; display: flex; flex-direction: column; padding-top: var(--safe-t); }

/* ---------- top bar ---------- */
.bar {
  height: var(--bar-h);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  padding: 0 12px 0 16px;
  flex: none;
}
.bar__lead { display: flex; align-items: center; gap: 6px; min-width: 0; }
.bar__center { display: flex; justify-content: center; min-width: 0; }
.bar__actions { display: flex; align-items: center; justify-content: flex-end; gap: 2px; }

.wordmark {
  font-weight: 800;
  font-stretch: 75%;
  font-size: 27px;
  letter-spacing: -0.02em;
  line-height: 1;
  text-decoration: none;
}
.wordmark span { color: var(--accent); }
.bar__title { margin: 0; font-size: 20px; font-weight: 750; font-stretch: 80%; letter-spacing: -0.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.icon-btn {
  width: 44px; height: 44px; flex: none;
  display: grid; place-items: center;
  border: 0; border-radius: var(--r-pill);
  background: none; color: var(--ink);
  font-size: 22px; cursor: pointer; text-decoration: none;
  transition: background 0.2s, transform 0.2s var(--ease);
}
.icon-btn:hover { background: var(--table-3); }
.icon-btn:active { transform: scale(0.94); }

.status-pill {
  display: inline-flex; align-items: center; gap: 8px;
  height: 34px; padding: 0 14px;
  border-radius: var(--r-pill);
  background: var(--table-3);
  font: 500 13px var(--mono);
  color: var(--ink-2);
  white-space: nowrap;
}
.status-pill b { color: var(--ink); font-weight: 600; }
.status-pill .sep { width: 4px; height: 4px; border-radius: 50%; background: var(--ink-3); }
.status-pill .tag { font-family: var(--font); }

.segmented {
  display: inline-flex; gap: 2px; padding: 3px;
  border-radius: var(--r-pill); background: var(--table-3);
}
.seg {
  display: inline-flex; align-items: center; gap: 6px;
  height: 32px; padding: 0 14px; border: 0; border-radius: var(--r-pill);
  background: none; color: var(--ink-2); font-weight: 600; font-size: 14px;
  text-decoration: none; cursor: pointer; white-space: nowrap;
  transition: background 0.25s var(--ease), color 0.2s;
}
.seg[aria-selected="true"], .seg[aria-checked="true"] { background: var(--paper); color: var(--paper-ink); }
.seg .count:not(:empty) {
  display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: var(--r-pill); background: var(--accent); color: var(--accent-ink);
  font: 700 11px var(--mono);
}

.desk-nav { display: none; }

/* ---------- game view ---------- */
.view--game {
  height: calc(100dvh - var(--bar-h) - var(--safe-t));
  display: flex;
  flex-direction: column;
  padding: 0 10px calc(10px + var(--safe-b));
  gap: 8px;
}
.table { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 6px; }

.seat {
  display: flex; align-items: center; gap: 10px;
  height: 30px; padding: 0 6px;
  font-size: 13px; color: var(--ink-2);
}
.seat__chip { width: 16px; height: 16px; border-radius: 50%; flex: none; }
.seat__chip--me { background: radial-gradient(circle at 35% 30%, #fff, var(--chk-me) 70%, var(--chk-me-lo)); }
.seat__chip--opp { background: radial-gradient(circle at 35% 30%, var(--chk-opp-hi), var(--chk-opp) 70%, var(--chk-opp-lo)); box-shadow: 0 0 0 1px var(--rule-strong); }
.seat__name { font-weight: 700; color: var(--ink); margin-right: auto; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.seat__stat b { font: 600 13px var(--mono); color: var(--ink); }
.seat__off { min-width: 52px; text-align: right; }

.board-area { flex: 1; min-height: 0; position: relative; display: grid; place-items: center; }
.board-shell { position: absolute; inset: 0; }
#board { display: block; width: 100%; height: 100%; user-select: none; -webkit-user-select: none; }
#board:not(.ready) { opacity: 0; }
#board { transition: opacity 0.4s var(--ease); }
.board-shell.dealing #board { opacity: 0.45; }

.board-loading {
  position: absolute; inset: 0; display: grid; place-content: center; gap: 6px; text-align: center; padding: 24px;
  border-radius: 26px; background: linear-gradient(110deg, var(--frame) 30%, var(--felt) 50%, var(--frame) 70%);
  background-size: 250% 100%; animation: shimmer 1.8s linear infinite; color: #e9ede7;
  transition: opacity 0.4s var(--ease);
}
.board-loading.hidden { opacity: 0; pointer-events: none; }
.loading-title { font-weight: 750; font-size: 19px; font-stretch: 85%; }
.loading-sub { opacity: 0.7; font-size: 14px; }
@keyframes shimmer { to { background-position: -150% 0; } }

/* Board materials */
.b-frame { fill: var(--frame); stroke: var(--frame-rim); stroke-width: 3; }
.b-felt { fill: url(#felt); }
.b-bar, .b-tray { fill: var(--bar); }
.b-tray-split { stroke: var(--label); stroke-opacity: 0.25; stroke-width: 1.5; }
.pt-a { fill: var(--pt-a); opacity: 0.88; }
.pt-b { fill: var(--pt-b); }
.b-label { fill: var(--label); font: 600 12px var(--mono); text-anchor: middle; }
#board.portrait .b-label { font-size: 15px; }
.b-hit { fill: transparent; }
#board.interactive { touch-action: none; }
#board.interactive .b-hit { cursor: pointer; }

.chk { transition: transform 0.36s var(--ease); }
.no-anim .chk, .no-anim .target, .no-anim .die { transition: none !important; }
.chk-shadow { fill: var(--chk-shadow); }
.chk-me .chk-body { stroke: var(--chk-me-lo); stroke-width: 1.5; }
.chk-opp .chk-body { stroke: var(--chk-opp-lo); stroke-width: 1.5; }
.chk-groove, .chk-core { fill: none; stroke-width: 1.5; }
.chk-me .chk-groove { stroke: var(--chk-me-line); }
.chk-me .chk-core { stroke: rgb(255 255 255 / 0.7); }
.chk-opp .chk-groove { stroke: var(--chk-opp-line); }
.chk-opp .chk-core { stroke: rgb(255 255 255 / 0.05); }
.chk.is-off .chk-shadow, .chk.is-off .chk-groove, .chk.is-off .chk-core { opacity: 0; }
.chk.movable .chk-body { stroke: var(--accent); stroke-width: 3; }
.chk.selected .chk-body { stroke: var(--accent); stroke-width: 6; }
.chk.dragging { transition: none; pointer-events: none; }
.chk.dragging .chk-shadow { transform: translate(5px, 9px); opacity: 0.6; }
.chk-count { font: 700 16px var(--mono); text-anchor: middle; pointer-events: none; fill: #2a2418; }
.chk-count.opp { fill: #e9e3d6; }

.target-ring { fill: var(--accent-soft); stroke: var(--accent); stroke-width: 3; stroke-dasharray: 6 5; }
.target-dot { fill: var(--accent); }
.target { animation: target-in 0.35s var(--spring); }
@keyframes target-in { from { opacity: 0; transform: scale(0.6); } }
.b-tray-target { fill: var(--accent-soft); stroke: var(--accent); stroke-width: 3; stroke-dasharray: 8 6; opacity: 0; transition: opacity 0.2s; pointer-events: none; }
.b-tray-target.on { opacity: 1; }

.die-shadow { fill: var(--chk-shadow); }
.die-body { fill: var(--die); }
.die-pip { fill: var(--die-pip); }
.die-opp .die-body { fill: #232a26; stroke: rgb(255 255 255 / 0.12); stroke-width: 1.5; }
.die-opp .die-pip { fill: #ece9e1; }
.die { transition: opacity 0.25s; animation: die-in 0.45s var(--spring) backwards; }
.die.used { opacity: 0.3; }
@keyframes die-in { from { opacity: 0; transform: translateY(-14px); } }
.cube-body { fill: var(--die); }
.cube-num { fill: var(--die-pip); font: 700 21px var(--mono); text-anchor: middle; }
.cube.offered .cube-body { stroke: var(--accent); stroke-width: 4; }
.cube { transition: transform 0.45s var(--ease); }

.shot-ring { fill: none; stroke: var(--g-blunder); stroke-width: 3; stroke-dasharray: 6 4; }
.shot-badge { fill: var(--g-blunder); }
.shot-num { fill: #fff; font: 700 14px var(--mono); text-anchor: middle; }
.b-shots { pointer-events: none; }

/* ---------- dock: prompt and actions ---------- */
.dock { flex: none; display: grid; gap: 10px; }
.prompt { padding: 2px 6px 0; min-height: 52px; position: relative; }
.prompt__title { margin: 0; font-size: 22px; font-weight: 750; font-stretch: 82%; letter-spacing: -0.01em; line-height: 1.1; }
.prompt__sub { margin: 3px 0 0; font-size: 14px; color: var(--ink-2); }
.prompt__sub:empty, .prompt__status:empty { display: none; }
.prompt__status { margin: 4px 0 0; font-size: 14px; font-weight: 600; color: var(--ink); }

.scoreline { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; margin-bottom: 6px; font-size: 12px; color: var(--ink-2); }
.scoreline strong { color: var(--ink); }
.lesson-dots { display: inline-flex; gap: 4px; }
.lesson-dots .dot { width: 10px; height: 10px; border-radius: 3px; background: var(--table-4); }
.lesson-dots .dot.current { background: none; box-shadow: inset 0 0 0 2px var(--accent); }
.lesson-dots .dot[class*="grade-"] { background: var(--grade); }

.verdict-chip {
  display: inline-flex; align-items: center; gap: 8px; margin-top: 8px;
  height: 34px; padding: 0 6px 0 12px; border: 0; border-radius: var(--r-pill);
  background: var(--table-3); color: var(--ink); font-weight: 650; font-size: 14px; cursor: pointer;
  animation: rise 0.4s var(--spring);
}
.verdict-chip .vc-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--grade); }
.verdict-chip .vc-loss { font: 500 12px var(--mono); color: var(--ink-2); }
.verdict-chip .vc-go { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--table-4); font-size: 13px; }

.actions { display: flex; gap: 8px; }
.actions--wrap { flex-wrap: wrap; }
.actions--wrap .btn { flex: 1 1 calc(50% - 4px); }

.btn {
  position: relative; flex: 1;
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  height: 54px; padding: 0 22px; border: 0; border-radius: var(--r-pill);
  font-weight: 700; font-size: 16px; cursor: pointer; white-space: nowrap; text-decoration: none;
  transition: transform 0.18s var(--ease), background 0.2s, opacity 0.2s, box-shadow 0.3s;
}
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn:disabled { opacity: 0.38; cursor: not-allowed; }
.btn--primary { background: var(--accent); color: var(--accent-ink); box-shadow: 0 10px 28px -12px var(--accent); }
.btn--primary:hover:not(:disabled) { background: var(--accent-2); }
.btn--ghost { background: var(--table-3); color: var(--ink); }
.btn--ghost:hover:not(:disabled) { background: var(--table-4); }
.btn--icon { flex: 0 0 auto; padding: 0 18px; }
.btn--icon i { font-size: 20px; }
.btn--wide { width: 100%; }
.btn kbd { font-size: 11px; padding: 2px 6px; border-radius: 6px; background: rgb(0 0 0 / 0.12); }
.btn__orb {
  display: grid; place-items: center; width: 32px; height: 32px; margin-right: -12px; border-radius: 50%;
  background: rgb(0 0 0 / 0.14); font-size: 17px;
  transition: transform 0.3s var(--spring);
}
.btn:hover .btn__orb { transform: translateX(2px) scale(1.06); }
.btn--primary.ready { animation: ready 1.8s var(--ease) infinite; }
@keyframes ready { 50% { box-shadow: 0 0 0 7px var(--accent-soft), 0 10px 28px -12px var(--accent); } }

.link-btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 2px; border: 0; background: none;
  color: var(--ink-2); font-weight: 600; font-size: 14px; cursor: pointer; text-decoration: none;
}
.link-btn:hover { color: var(--ink); }
.dock__resign { justify-self: start; margin-top: -4px; }

@media (pointer: coarse) { kbd { display: none; } }

/* ---------- analysis (bottom sheet on phones) ---------- */
.analysis {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  max-height: 84dvh; overflow-y: auto; overscroll-behavior: contain;
  padding: 10px 18px calc(22px + var(--safe-b));
  border-radius: var(--r-sheet) var(--r-sheet) 0 0;
  background: var(--table-2);
  box-shadow: 0 -20px 60px -20px var(--shadow);
  transform: translateY(calc(100% + 24px));
  transition: transform 0.5s var(--ease-sheet);
}
.analysis.open { transform: translateY(0); }
.analysis__grab { width: 40px; height: 5px; margin: 0 auto 6px; border-radius: 3px; background: var(--rule-strong); cursor: pointer; }
.analysis__close { position: absolute; top: 8px; right: 10px; }
.analysis__empty { display: none; }
.scrim { position: fixed; inset: 0; z-index: 35; background: rgb(4 7 5 / 0.5); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); animation: fade 0.3s; }
@keyframes fade { from { opacity: 0; } }

/* Result content */
.result { animation: rise 0.45s var(--ease); }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }
.verdict { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding-right: 44px; }
.verdict-label { font-size: 30px; font-weight: 800; font-stretch: 78%; letter-spacing: -0.02em; color: var(--grade); line-height: 1.05; }
.verdict-loss { font: 600 15px var(--mono); color: var(--ink-2); }
.verdict-note { margin: 6px 0 0; color: var(--ink-2); font-size: 14px; }
.grade-best { --grade: var(--g-best); }
.grade-excellent { --grade: var(--g-excellent); }
.grade-inaccuracy { --grade: var(--g-inaccuracy); }
.grade-mistake { --grade: var(--g-mistake); }
.grade-blunder { --grade: var(--g-blunder); }

.why { margin-top: 16px; padding: 4px; border-radius: var(--r-card); background: var(--table-3); }
.why > * { margin-left: 14px; margin-right: 14px; }
.why-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 12px; }
.why-title { margin: 0; font-size: 16px; font-weight: 750; }
.why-cat { font-size: 12px; font-weight: 700; padding: 3px 10px; border-radius: var(--r-pill); color: var(--grade); background: color-mix(in srgb, var(--grade) 16%, transparent); }
.why-summary { margin-top: 6px; font-size: 14px; color: var(--ink-2); }
.why-list { margin: 10px 14px 0; padding: 0; list-style: none; display: grid; gap: 9px; }
.why-list li { position: relative; padding-left: 18px; font-size: 14.5px; line-height: 1.45; }
.why-list li::before { content: ""; position: absolute; left: 1px; top: 0.55em; width: 7px; height: 7px; border-radius: 2px; background: var(--grade); }
.why-tradeoff { margin-top: 10px; font-size: 13px; color: var(--ink-2); font-style: italic; }
.why .link-btn { margin: 6px 12px 8px; }
.why .link-btn[aria-pressed="true"] { color: var(--accent); }
.why > :last-child:not(.link-btn) { margin-bottom: 14px; }

.cands-head { display: flex; justify-content: space-between; margin: 18px 4px 6px; font-size: 12px; color: var(--ink-3); font-weight: 600; }
.cands { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.cand {
  display: grid; grid-template-columns: 22px 1fr auto; align-items: center; gap: 10px;
  width: 100%; padding: 11px 12px; border: 0; border-radius: 14px; background: none; text-align: left; cursor: pointer;
  transition: background 0.2s;
}
.cand:hover { background: var(--table-3); }
.cand.active { background: var(--accent-soft); box-shadow: inset 0 0 0 1.5px var(--accent-ring); }
.cand-rank { font: 500 12px var(--mono); color: var(--ink-3); }
.cand-move { font: 600 14px var(--mono); display: flex; align-items: center; gap: 8px; min-width: 0; }
.cand-move span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cand-eq { font: 500 13px var(--mono); color: var(--ink-2); }
.cand.best .cand-eq { color: var(--g-best); }
.tag { font-family: var(--font); font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: var(--r-pill); background: var(--accent); color: var(--accent-ink); flex: none; }

.probs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 16px 0 0; }
.prob { padding: 10px 12px; border-radius: 14px; background: var(--table-3); }
.prob dt { font-size: 12px; color: var(--ink-3); }
.prob dd { margin: 2px 0 0; font: 600 16px var(--mono); }
.prob dd.small { font: 700 14px var(--font); }

.cube-table { margin: 14px 0 0; display: grid; gap: 4px; }
.cube-row { display: flex; justify-content: space-between; padding: 11px 14px; border-radius: 14px; background: var(--table-3); }
.cube-row.correct { box-shadow: inset 0 0 0 1.5px var(--g-best); }
.cube-row.picked { background: var(--accent-soft); }
.cube-row span:last-child { font-family: var(--mono); }
.cube-proper { margin: 12px 4px 0; font-size: 14px; color: var(--ink-2); }
.cube-proper strong { color: var(--ink); }
.game-line { margin: 14px 4px 0; padding-top: 12px; border-top: 1px solid var(--rule); font-size: 13px; color: var(--ink-2); }
.lesson-stars { display: flex; gap: 6px; font-size: 32px; color: var(--accent); margin-top: 10px; }

/* ---------- sheets (dialogs) ---------- */
.sheet {
  position: fixed; inset: auto 0 0 0; margin: 0 auto; width: min(560px, 100%); max-width: 100%;
  max-height: 90dvh; overflow-y: auto; overscroll-behavior: contain;
  padding: 10px 20px calc(24px + var(--safe-b));
  border: 0; border-radius: var(--r-sheet) var(--r-sheet) 0 0;
  background: var(--table-2); color: var(--ink);
  box-shadow: 0 -24px 70px -24px var(--shadow);
}
.sheet[open] { animation: sheet-in 0.55s var(--ease-sheet); }
.sheet.closing { animation: sheet-out 0.28s var(--ease) forwards; }
.sheet::backdrop { background: rgb(4 7 5 / 0.55); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); }
@keyframes sheet-in { from { transform: translateY(100%); } }
@keyframes sheet-out { to { transform: translateY(100%); } }
.sheet__grab { width: 40px; height: 5px; margin: 0 auto 10px; border-radius: 3px; background: var(--rule-strong); }
.sheet__head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.sheet:focus { outline: none; }
.sheet__head h2 { margin: 0; font-size: 28px; font-weight: 800; font-stretch: 78%; letter-spacing: -0.02em; }
.sheet__foot { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--rule); }
.sheet__note { margin: 18px 0 0; font-size: 12px; color: var(--ink-3); }

.menu-nav { display: grid; gap: 2px; }
.menu-nav a {
  display: grid; grid-template-columns: 28px 1fr auto; align-items: center; gap: 10px;
  min-height: 52px; padding: 0 12px; border-radius: 16px; text-decoration: none; font-weight: 650; font-size: 17px;
  transition: background 0.2s;
}
.menu-nav a i:first-child { font-size: 22px; color: var(--ink-2); }
.menu-nav a i:last-child { color: var(--ink-3); }
.menu-nav a:hover { background: var(--table-3); }
.menu-nav a[aria-current="page"] { background: var(--table-3); }
.menu-nav a[aria-current="page"] i:first-child { color: var(--accent); }

.stats-row { display: grid; grid-template-columns: repeat(4, 1fr); margin: 16px 0 0; padding: 14px 0; border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule); text-align: center; }
.stats-row b { display: block; font: 600 18px var(--mono); }
.stats-row span { font-size: 12px; color: var(--ink-3); }
.recent { list-style: none; padding: 0; margin: 12px 0 0; display: flex; gap: 4px; flex-wrap: wrap; justify-content: center; }
.recent li { width: 12px; height: 12px; border-radius: 3px; background: var(--grade); }
.recent:empty { display: none; }

.settings { display: grid; margin-top: 8px; }
.switch {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  min-height: 54px; border-bottom: 1px solid var(--rule); font-weight: 600; font-size: 16px; cursor: pointer;
}
.switch:last-child { border-bottom: 0; }
.switch small { display: block; font-size: 12.5px; font-weight: 400; color: var(--ink-3); }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch i { position: relative; width: 50px; height: 30px; flex: none; border-radius: var(--r-pill); background: var(--table-4); transition: background 0.25s; }
.switch i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: var(--ink-2); transition: transform 0.35s var(--spring), background 0.25s; }
.switch input:checked + i { background: var(--accent); }
.switch input:checked + i::after { transform: translateX(20px); background: #fff; }
.switch input:focus-visible + i { outline: 2px solid var(--accent-ring); outline-offset: 2px; }
.segmented--small .seg { height: 30px; padding: 0 12px; font-size: 13px; }

.opt-group { display: grid; gap: 18px; }
.field { display: grid; gap: 10px; }
.field__label { font-size: 13px; font-weight: 700; color: var(--ink-3); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  height: 40px; padding: 0 16px; border: 0; border-radius: var(--r-pill);
  background: var(--table-3); color: var(--ink-2); font-weight: 600; font-size: 14px; cursor: pointer;
  transition: background 0.2s, color 0.2s, transform 0.18s var(--ease);
}
.chip:active { transform: scale(0.96); }
.chip[aria-checked="true"] { background: var(--paper); color: var(--paper-ink); }
.credits p { margin: 0 0 12px; color: var(--ink-2); font-size: 14.5px; }
.credits strong { color: var(--ink); }
.credits a { color: var(--accent); }

/* ---------- toasts ---------- */
.toasts { position: fixed; left: 12px; right: 12px; top: calc(var(--safe-t) + 62px); display: grid; justify-items: center; gap: 8px; z-index: 80; pointer-events: none; }
.toast {
  display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 12px; width: min(380px, 100%);
  padding: 10px 16px 10px 10px; border-radius: var(--r-pill); background: var(--paper); color: var(--paper-ink);
  box-shadow: 0 18px 40px -18px var(--shadow); animation: toast-in 0.55s var(--spring); pointer-events: auto;
}
.toast.leaving { opacity: 0; transform: translateY(-10px); transition: opacity 0.4s, transform 0.4s var(--ease); }
.toast-icon { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; font-size: 21px; background: var(--accent); color: var(--accent-ink); }
.toast.tier-0 .toast-icon { background: #e7cfb3; color: #7c4f22; }
.toast.tier-1 .toast-icon { background: #d9e0e6; color: #4f5d6a; }
.toast.tier-2 .toast-icon { background: #f1dc9c; color: #81600c; }
.toast-body { display: grid; }
.toast-body strong { font-size: 14px; }
.toast-body span { font-size: 12.5px; color: #4b544d; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-14px) scale(0.96); } }

/* ---------- pages (home, learn, daily, profile) ---------- */
.view--page { flex: 1; width: 100%; max-width: 1100px; margin: 0 auto; padding: 4px 16px calc(32px + var(--safe-b)); animation: rise 0.45s var(--ease); }
.page-head { max-width: 660px; margin: 10px 0 24px; }
.page-head h1 { margin: 0; font-size: 44px; font-weight: 800; font-stretch: 75%; letter-spacing: -0.025em; line-height: 0.98; }
.page-head p { margin: 10px 0 0; color: var(--ink-2); font-size: 16px; }
.eyebrow-date { display: block; font: 500 12.5px var(--mono); color: var(--ink-3); margin-bottom: 8px; text-transform: uppercase; letter-spacing: 0.06em; }
.out-of { font-size: 24px; color: var(--ink-3); font-weight: 600; }
.back-link { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-2); text-decoration: none; font-size: 14px; font-weight: 600; }

/* Double-bezel card: an outer tray holding an inner plate. */
.bezel { padding: 5px; border-radius: 26px; background: var(--table-2); box-shadow: inset 0 0 0 1px var(--rule); }
.bezel > .plate { border-radius: 21px; background: var(--table-3); box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.05); }

/* Home */
.home-hero { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin: 6px 0 22px; }
.home-hero h1 { margin: 0; font-size: 50px; font-weight: 800; font-stretch: 75%; letter-spacing: -0.03em; line-height: 0.9; }
.home-hero h1 span { color: var(--accent); }
.home-hero p { margin: 10px 0 0; color: var(--ink-2); font-size: 15px; }
.home-level { display: grid; justify-items: center; gap: 2px; text-decoration: none; }
.home-level .level-ring { position: relative; display: grid; place-items: center; }
.home-level .level-ring > * { grid-area: 1 / 1; }
.home-level .level-num { font: 700 19px var(--mono); }
.home-level small { font-size: 11.5px; color: var(--ink-3); font-weight: 600; }

.home-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.tile {
  position: relative; display: grid; align-content: space-between; gap: 18px; min-height: 152px;
  padding: 18px; border-radius: 24px; text-decoration: none; overflow: hidden; isolation: isolate;
  background: var(--table-3); box-shadow: inset 0 0 0 1px var(--rule);
  transition: transform 0.35s var(--ease);
}
.tile:active { transform: scale(0.985); }
.tile__icon { width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center; font-size: 23px; background: var(--table-4); }
.tile__title { display: block; font-size: 24px; font-weight: 800; font-stretch: 78%; letter-spacing: -0.015em; line-height: 1; }
.tile__meta { display: block; margin-top: 6px; font-size: 13px; color: var(--ink-2); }
.tile__go { position: absolute; top: 16px; right: 16px; width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: var(--table-4); font-size: 16px; transition: transform 0.35s var(--spring); }
.tile:hover .tile__go { transform: translate(2px, -2px) scale(1.06); }
.tile--hero {
  grid-column: 1 / -1; min-height: 210px; color: #eef2ec;
  background: radial-gradient(120% 140% at 85% 10%, #2b5745 0%, var(--felt) 45%, #12261d 100%);
  box-shadow: inset 0 0 0 1px rgb(255 255 255 / 0.06), 0 30px 60px -36px #000;
}
.tile--hero .tile__title { font-size: 40px; }
.tile--hero .tile__meta { color: rgb(238 242 236 / 0.75); font-size: 14px; }
.tile--hero .tile__icon, .tile--hero .tile__go { background: rgb(255 255 255 / 0.12); }
.tile--accent { background: var(--accent); color: var(--accent-ink); box-shadow: 0 24px 44px -28px var(--accent); }
.tile--accent .tile__meta { color: color-mix(in srgb, var(--accent-ink) 75%, transparent); }
.tile--accent .tile__icon, .tile--accent .tile__go { background: rgb(0 0 0 / 0.14); }
/* Three checkers seen from above, stacked like on a point. */
.tile-stack { position: absolute; right: 64px; top: 22px; z-index: 0; display: flex; transform: rotate(-10deg); pointer-events: none; }
.tile-stack i {
  display: block; width: 64px; height: 64px; margin-left: -20px; border-radius: 50%;
  box-shadow: 0 10px 18px -6px rgb(0 0 0 / 0.55), inset 0 0 0 1.5px rgb(0 0 0 / 0.18);
  position: relative;
}
.tile-stack i::after { content: ""; position: absolute; inset: 11px; border-radius: 50%; box-shadow: inset 0 0 0 1.5px var(--ring), 0 0 0 9px transparent; }
.tile-stack .me { --ring: rgb(60 50 30 / 0.16); background: radial-gradient(circle at 35% 30%, #fff, var(--chk-me) 70%, var(--chk-me-lo)); }
.tile-stack .opp { --ring: rgb(255 255 255 / 0.12); background: radial-gradient(circle at 35% 30%, var(--chk-opp-hi), var(--chk-opp) 70%, var(--chk-opp-lo)); }
.tile--hero > span:not(.tile-stack):not(.tile__go) { position: relative; z-index: 1; }
.tile-badge { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: var(--r-pill); background: rgb(0 0 0 / 0.16); font: 600 12px var(--mono); }
.home-foot { margin: 22px 2px 0; display: flex; justify-content: space-between; color: var(--ink-3); font-size: 12.5px; }

/* Learn */
.learn-top { display: grid; grid-template-columns: 1.4fr 1fr; gap: 12px; margin-bottom: 22px; }
.feature-card {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 14px;
  padding: 18px; border-radius: 24px; text-decoration: none;
  background: radial-gradient(120% 140% at 90% 0%, #2b5745 0%, var(--felt) 50%, #12261d 100%); color: #eef2ec;
  transition: transform 0.35s var(--ease);
}
.feature-card:active { transform: scale(0.985); }
.feature-card.quiet { background: var(--table-3); color: var(--ink); }
.feature-icon { width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center; font-size: 24px; background: rgb(255 255 255 / 0.12); color: var(--accent); }
.feature-card.quiet .feature-icon { background: var(--table-4); }
.feature-body { display: grid; gap: 2px; min-width: 0; }
.feature-label { font: 600 11.5px var(--mono); text-transform: uppercase; letter-spacing: 0.06em; opacity: 0.7; }
.feature-body strong { font-size: 19px; font-weight: 750; }
.feature-text { font-size: 13.5px; opacity: 0.8; }
.feature-go { font-size: 20px; opacity: 0.7; }

.chapter-grid { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.chapter-card {
  position: relative; display: grid; gap: 10px; height: 100%; padding: 16px;
  border-radius: 22px; background: var(--table-3); text-decoration: none;
  box-shadow: inset 0 0 0 1px var(--rule); transition: transform 0.3s var(--ease), box-shadow 0.2s;
}
.chapter-card:active { transform: scale(0.98); }
.chapter-card.done { box-shadow: inset 0 0 0 1.5px var(--g-best); }
.chapter-num { position: absolute; top: 14px; right: 16px; font: 500 12px var(--mono); color: var(--ink-3); }
.chapter-icon { width: 42px; height: 42px; border-radius: 13px; display: grid; place-items: center; font-size: 22px; background: var(--accent-soft); color: var(--accent); }
.chapter-icon.big { width: 58px; height: 58px; font-size: 30px; margin-bottom: 14px; border-radius: 18px; }
.chapter-title { font-size: 19px; font-weight: 800; font-stretch: 80%; line-height: 1.05; }
.chapter-meta { display: flex; justify-content: space-between; align-items: center; font-size: 12.5px; color: var(--ink-2); }
.stars { display: inline-flex; gap: 2px; color: var(--accent); font-size: 14px; }

.lesson-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; }
.lesson-tile {
  display: grid; gap: 6px; padding: 16px; border-radius: 20px; background: var(--table-3);
  text-decoration: none; box-shadow: inset 0 0 0 1px var(--rule); transition: transform 0.3s var(--ease);
}
.lesson-tile:not(.locked):active { transform: scale(0.97); }
.lesson-tile.locked { opacity: 0.45; cursor: not-allowed; }
.lesson-tile.passed { box-shadow: inset 0 0 0 1.5px var(--g-best); }
.lesson-num { font-weight: 800; font-stretch: 80%; font-size: 19px; }
.lesson-meta { font-size: 12.5px; color: var(--ink-2); }
.tier { justify-self: start; font-size: 11.5px; font-weight: 700; padding: 3px 9px; border-radius: var(--r-pill); background: var(--table-4); }
.tier-easy { color: var(--g-best); }
.tier-medium { color: var(--g-inaccuracy); }
.tier-hard { color: var(--g-mistake); }
.tier-close { color: var(--g-blunder); }

/* Daily */
.daily-grid { display: grid; grid-template-columns: 1.15fr 1fr; gap: 14px; align-items: start; }
.daily-main { display: grid; gap: 14px; }
.daily-start { justify-self: stretch; }
.daily-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.daily-actions .btn { flex: 1 1 auto; }
.squares { display: flex; gap: 6px; }
.squares .sq { width: 28px; height: 28px; border-radius: 8px; background: var(--grade); animation: rise 0.45s var(--spring) backwards; animation-delay: calc(var(--i, 0) * 50ms); }
.streak { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 14px; padding: 16px; border-radius: 22px; background: var(--table-3); }
.streak-icon { width: 50px; height: 50px; border-radius: 16px; display: grid; place-items: center; font-size: 27px; background: var(--table-4); color: var(--ink-3); }
.streak-icon.on { background: var(--accent-soft); color: var(--accent); }
.streak-body { display: grid; }
.streak-body strong { font-size: 24px; font-weight: 800; font-stretch: 80%; }
.streak-body span { font-size: 13px; color: var(--ink-2); }
.streak-freeze { display: grid; justify-items: end; font: 700 15px var(--mono); color: #6cb2d8; }
.freeze-note { font: 400 11.5px var(--font); color: var(--ink-3); }
.calendar { padding: 16px; border-radius: 22px; background: var(--table-3); }
.cal-title { font-weight: 750; margin-bottom: 12px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; }
.cal-head { font: 500 11px var(--mono); color: var(--ink-3); text-align: center; }
.cal-cell { aspect-ratio: 1; display: grid; place-items: center; border-radius: 9px; font: 500 12px var(--mono); color: var(--ink-3); background: var(--table-4); }
.cal-cell.empty { background: none; }
.cal-cell.done { background: var(--g-excellent); color: #fff; }
.cal-cell.perfect { background: var(--g-best); box-shadow: inset 0 0 0 2px var(--accent); }
.cal-cell.frozen { background: color-mix(in srgb, #6cb2d8 22%, transparent); color: #6cb2d8; }
.cal-cell.today { box-shadow: inset 0 0 0 2px var(--accent); }

/* Profile */
:root { --chart-line: #b97614; }
.ring-track { fill: none; stroke: var(--table-4); stroke-width: 5; }
.ring-fill { fill: none; stroke: var(--accent); stroke-width: 5; stroke-linecap: round; transform: rotate(-90deg); transform-origin: center; transition: stroke-dashoffset 0.9s var(--ease); }
.profile-head { display: flex; align-items: center; gap: 20px; margin: 6px 0 24px; }
.profile-head h1 { margin: 0; font-size: 40px; font-weight: 800; font-stretch: 76%; letter-spacing: -0.02em; line-height: 1; }
.profile-head p { margin: 6px 0 0; color: var(--ink-2); }
.level-ring { position: relative; display: grid; place-items: center; }
.level-ring > * { grid-area: 1 / 1; }
.level-num { font: 700 28px var(--mono); }
.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin: 0 0 14px; }
.tiles .tile { min-height: 0; gap: 4px; padding: 14px 16px; border-radius: 20px; }
.tiles dt { font-size: 12.5px; color: var(--ink-2); }
.tiles dd { margin: 0; font: 700 26px var(--mono); }
.tiles dd span { font: 500 13px var(--font); color: var(--ink-3); margin-left: 4px; }
.profile-grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: 12px; margin-bottom: 24px; }
.card { padding: 18px; border-radius: 22px; background: var(--table-3); min-width: 0; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.card-head h2 { margin: 0; font-size: 18px; font-weight: 800; font-stretch: 82%; }
.card-sub { margin: 4px 0 14px; font-size: 13px; color: var(--ink-2); }
.chart { position: relative; }
.chart svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart .grid { stroke: var(--rule-strong); stroke-width: 1; }
.chart .axis { fill: var(--ink-3); font: 500 11px var(--mono); }
.chart .series { fill: none; stroke: var(--chart-line); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .series-area { fill: var(--chart-line); opacity: 0.12; }
.chart .series-dot, .chart .hover-dot { fill: var(--chart-line); stroke: var(--table-3); stroke-width: 2; }
.chart .end-label { fill: var(--ink); font: 600 12px var(--mono); }
.chart .crosshair { stroke: var(--ink-3); stroke-width: 1; }
.chart .hit { fill: transparent; cursor: crosshair; }
.chart-tip { position: absolute; top: -6px; transform: translate(-50%, -100%); display: grid; gap: 2px; padding: 8px 10px; border-radius: 10px; background: var(--paper); color: var(--paper-ink); font-size: 12px; pointer-events: none; white-space: nowrap; box-shadow: 0 12px 28px -14px var(--shadow); }
.chart-tip span { display: flex; align-items: center; gap: 6px; color: #4b544d; }
.tip-key { width: 12px; height: 2px; border-radius: 1px; background: var(--chart-line); display: inline-block; }
.chart-empty { margin: 30px 0; color: var(--ink-2); text-align: center; }
.trend-table { width: 100%; border-collapse: collapse; margin-top: 12px; font-size: 13px; }
.trend-table th { text-align: left; color: var(--ink-3); font-weight: 600; padding: 6px 4px; }
.trend-table td { padding: 6px 4px; font-family: var(--mono); border-top: 1px solid var(--rule); }
.phase-table { display: grid; }
.phase-row { display: grid; grid-template-columns: 1.6fr 0.8fr 0.8fr 0.8fr; gap: 8px; padding: 10px 0; font-size: 14px; align-items: center; }
.phase-row + .phase-row { border-top: 1px solid var(--rule); }
.phase-row.head { font-size: 12px; color: var(--ink-3); padding-top: 0; }
.phase-row span:not(:first-child) { text-align: right; font-family: var(--mono); }
.phase-row.head span { font-family: var(--font); }
.weak-tag { font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: var(--r-pill); background: var(--table-4); color: var(--ink-2); }
.badges .card-head { margin-bottom: 4px; }
.badge-group { margin: 18px 0 10px; font: 600 12px var(--mono); text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-3); }
.badge-grid { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; }
.badge { display: grid; justify-items: center; gap: 4px; padding: 14px 8px; border-radius: 20px; background: var(--table-3); text-align: center; }
.badge-icon { width: 50px; height: 50px; border-radius: 50%; display: grid; place-items: center; font-size: 24px; background: var(--table-4); color: var(--ink-3); }
.badge-name { font-weight: 750; font-size: 14px; }
.badge-sub { font: 500 11.5px var(--mono); color: var(--ink-3); }
.badge.locked { opacity: 0.55; }
.badge.tier-0 .badge-icon { background: #e7cfb3; color: #7c4f22; }
.badge.tier-1 .badge-icon { background: #d9e0e6; color: #4f5d6a; }
.badge.tier-2 .badge-icon { background: #f1dc9c; color: #81600c; }

/* ---------- wide screens: board left, prompt and analysis right ---------- */
@media (min-width: 960px) and (min-height: 600px) {
  :root { --bar-h: 68px; }
  .bar { padding: 0 24px; }
  .desk-nav { display: flex; gap: 2px; margin-right: 8px; padding: 4px; border-radius: var(--r-pill); background: var(--table-2); }
  .desk-nav a { padding: 8px 16px; border-radius: var(--r-pill); text-decoration: none; font-weight: 650; font-size: 14px; color: var(--ink-2); transition: background 0.2s, color 0.2s; }
  .desk-nav a:hover { color: var(--ink); }
  .desk-nav a[aria-current="page"] { background: var(--paper); color: var(--paper-ink); }
  .view--game {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 390px;
    grid-template-rows: auto minmax(0, 1fr);
    gap: 16px 24px;
    padding: 4px 24px 24px;
    max-width: 1560px; width: 100%; margin: 0 auto;
  }
  .table { grid-row: 1 / 3; }
  .dock { padding: 18px; border-radius: var(--r-card); background: var(--table-2); box-shadow: inset 0 0 0 1px var(--rule); }
  .analysis {
    position: static; transform: none; max-height: none; min-height: 0; overflow-y: auto;
    padding: 18px; border-radius: var(--r-card); box-shadow: inset 0 0 0 1px var(--rule);
  }
  .analysis__grab, .analysis__close, .verdict-chip { display: none !important; }
  .analysis__empty { display: block; margin: 0; color: var(--ink-3); font-size: 14px; }
  .result:not([hidden]) + .analysis__empty { display: none; }
  .verdict { padding-right: 0; }
  .scrim { display: none !important; }
  .sheet { inset: 0; margin: auto; max-height: 86dvh; border-radius: var(--r-sheet); }
  .sheet[open] { animation: pop-in 0.45s var(--ease-sheet); }
  .sheet.closing { animation: pop-out 0.22s var(--ease) forwards; }
  .sheet__grab { display: none; }
  .view--page { padding-top: 16px; }
  .home-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .tile--hero { grid-column: span 2; grid-row: span 2; }
  .page-head h1 { font-size: 56px; }
  .toasts { left: auto; right: 24px; top: auto; bottom: 24px; justify-items: end; }
}
@keyframes pop-in { from { opacity: 0; transform: translateY(16px) scale(0.97); } }
@keyframes pop-out { to { opacity: 0; transform: translateY(10px) scale(0.98); } }

/* Phones held sideways: board left, dock right, analysis stays a sheet. */
@media (max-height: 520px) and (orientation: landscape) {
  :root { --bar-h: 46px; }
  .view--game {
    display: grid; grid-template-columns: minmax(0, 1fr) 300px; grid-template-rows: minmax(0, 1fr); gap: 14px;
    padding-left: max(10px, env(safe-area-inset-left)); padding-right: max(10px, env(safe-area-inset-right));
  }
  .btn { padding: 0 16px; }
  .btn kbd, .btn--icon span { display: none; }
  .seat { height: 24px; }
  .dock { align-content: end; padding-bottom: 4px; }
  .prompt__title { font-size: 19px; }
  .btn { height: 48px; }
  .analysis { left: auto; width: min(460px, 70vw); right: 0; max-height: 100dvh; border-radius: var(--r-sheet) 0 0 var(--r-sheet); top: 0; transform: translateX(105%); }
  .analysis.open { transform: translateX(0); }
}

@media (max-width: 640px) {
  .learn-top, .daily-grid, .profile-grid { grid-template-columns: 1fr; }
  .tiles { grid-template-columns: 1fr 1fr; }
  .page-head h1 { font-size: 40px; }
  .home-hero h1 { font-size: 52px; }
  .chapter-grid, .lesson-list { grid-template-columns: 1fr 1fr; }
  .chapter-card { padding: 14px; }
  .chapter-title { font-size: 17px; }
  .badge-grid { grid-template-columns: repeat(3, 1fr); }
  .phase-row { grid-template-columns: 1.4fr 0.7fr 0.8fr 0.8fr; font-size: 13px; }
  .status-pill { height: 32px; padding: 0 12px; font-size: 12px; }
  .segmented--bar .seg { height: 30px; padding: 0 11px; font-size: 13px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
