/* Snap to Fit, game shell: one level on screen at a time, lesson navigation and progress on top.
   Uses the tokens from base.css. Level-specific rules are scoped under #l<n>. */
[hidden] { display: none !important; }
body.game { min-height: 100vh; display: flex; flex-direction: column; }
.gbar { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20; display: flex; align-items: center; gap: 10px; padding: 8px 16px;
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); border-bottom: 1px solid var(--rule); }
.brand { font-family: var(--f-display); font-weight: 800; font-size: 1.15rem; text-decoration: none; color: var(--ink); white-space: nowrap; }
.src { color: var(--source); } .tgt { color: var(--target); }
.rail { list-style: none; display: flex; gap: 6px; margin: 0; padding: 5px; min-width: 0; flex: 1; overflow-x: auto; scrollbar-width: none; }
.rail::-webkit-scrollbar { display: none; }
.rail li { margin: 0; flex-shrink: 0; }
.rail li:first-child { margin-left: auto; }
.rail li:last-child { margin-right: auto; }
.rail button { font: inherit; font-family: var(--f-mono); font-size: 0.78rem; width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--rule);
  background: var(--surface); color: var(--muted); cursor: pointer; padding: 0; }
.rail button.done { border-color: var(--good); color: var(--good); }
.rail button.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.gbtn { font: inherit; font-size: 0.82rem; padding: 5px 10px; border-radius: 999px; border: 1px solid var(--rule); background: var(--surface); color: var(--muted);
  cursor: pointer; text-decoration: none; white-space: nowrap; }
.gbtn[aria-pressed="false"] { text-decoration: line-through; opacity: 0.7; }
.gbtn:hover { border-color: var(--accent); color: var(--ink); }

.gmain { flex: 1; padding: 0 16px; }
.lvl { display: none; max-width: var(--wide); margin: 0 auto; padding: 22px 0 10px; }
.lvl.on { display: block; }
.lvl-kicker { display: flex; align-items: center; gap: 10px; font-family: var(--f-mono); font-size: 0.78rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--source); margin: 0 0 4px; }
.lvl-kicker button { font: inherit; letter-spacing: 0; text-transform: none; font-size: 0.76rem; padding: 1px 9px; border-radius: 999px; border: 1px solid var(--rule); background: none; color: var(--muted); cursor: pointer; }
.lvl-kicker button:hover { color: var(--ink); border-color: var(--accent); }
.lvl-head h2 { margin-bottom: 6px; font-size: clamp(1.6rem, 3.4vw, 2.25rem); }
.brief { font-size: 1.12rem; max-width: 50rem; margin: 0 0 14px; }
.brief b.src, .brief b.tgt { font-weight: 700; }
.irl { font-size: 0.93rem; color: var(--muted); max-width: 50rem; margin: -6px 0 14px; padding-left: 10px; border-left: 3px solid var(--rule); }
.irl b { font-family: var(--f-mono); font-size: 0.7rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--accent); margin-right: 6px; }
.irl code, .say code { font-family: var(--f-mono); font-size: 0.86em; }
.duo { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
@media (min-width: 620px) { .duo { grid-template-columns: 1fr 1fr; } }
.duo .caption { margin-top: 6px; }
.hid { font-family: var(--f-mono); font-size: 0.66rem; letter-spacing: 0.04em; text-transform: uppercase; color: var(--bad); margin-left: 6px; white-space: nowrap; }
.lvl-body { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; align-items: start; }
@media (min-width: 900px) { .lvl-body { grid-template-columns: minmax(0, 1fr) 19.5rem; } }
.lvl-stage { position: relative; min-width: 0; }
.lvl-stage canvas.plot { cursor: grab; }
.lvl-stage canvas.plot:active { cursor: grabbing; }
.lvl-stage canvas.strip { display: block; width: 100%; height: 132px; margin-top: 10px; background: var(--surface); border: 1px solid var(--rule); border-radius: 8px; touch-action: none; }
.lvl-stage.with-strip canvas.plot { aspect-ratio: 2 / 1; }
.lvl-side { display: grid; gap: 10px; align-content: start; min-width: 0; }
@media (max-width: 899px) { .lvl-stage canvas.plot, .lvl-stage.with-strip canvas.plot { aspect-ratio: 4 / 3; } }

.stat { background: var(--surface); border: 1px solid var(--rule); border-radius: 10px; padding: 8px 12px; }
.stat .k { display: block; font-size: 0.8rem; color: var(--muted); line-height: 1.3; }
.stat b { font-family: var(--f-mono); font-size: 1.3rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.stat small { font-family: var(--f-mono); font-size: 0.78rem; color: var(--muted); margin-left: 6px; }
.stats2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.goals { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.goals li { margin: 0; display: block; position: relative; font-size: 0.95rem; padding: 7px 10px 7px 38px; border-radius: 8px;
  background: var(--surface); border: 1px solid var(--rule); line-height: 1.35; }
.goals li::before { content: ""; position: absolute; left: 9px; top: 8px; width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--rule); }
.goals li.done { border-color: var(--good); }
.goals li.done::before { background: var(--good); border-color: var(--good); }
.say { font-size: 0.95rem; margin: 0; padding: 8px 10px; border-radius: 8px; background: var(--tint); min-height: 2.6em; line-height: 1.4; }
.say.bad { background: color-mix(in srgb, var(--bad) 13%, var(--surface)); color: var(--ink); }
.say.good { background: color-mix(in srgb, var(--good) 14%, var(--surface)); color: var(--ink); }
.seg { display: flex; gap: 0; border: 1px solid var(--rule); border-radius: 8px; overflow: hidden; background: var(--bg); }
.seg button { flex: 1; font: inherit; font-size: 0.88rem; padding: 7px 6px; border: 0; border-right: 1px solid var(--rule); background: none; color: var(--muted); cursor: pointer; }
.seg button:last-child { border-right: 0; }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--bg); font-weight: 700; }
.board { width: 100%; border-collapse: collapse; font-size: 0.9rem; background: var(--surface); border: 1px solid var(--rule); border-radius: 10px; overflow: hidden; }
.board th, .board td { padding: 6px 9px; text-align: left; border-bottom: 1px solid var(--rule); }
.board tr:last-child th, .board tr:last-child td { border-bottom: 0; }
.board thead th { font-family: var(--f-mono); font-size: 0.7rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); background: var(--tint); }
.board td { font-family: var(--f-mono); font-variant-numeric: tabular-nums; }
.board tr.best th, .board tr.best td { color: var(--good); font-weight: 700; }
/* Keep status labels in the document flow so wrapped hints never overlap them. */
.hud { display: flex; gap: 6px; flex-wrap: wrap; align-items: flex-start; margin-bottom: 8px; }
.pill { min-width: 0; max-width: 100%; overflow-wrap: anywhere; font-family: var(--f-mono); font-size: 0.78rem; background: var(--surface); border: 1px solid var(--rule); border-radius: 999px; padding: 2px 9px; }

.explain { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; margin: 16px 0 0; max-width: 72rem; }
@media (min-width: 900px) { .explain { grid-template-columns: 1fr 1fr; } }
.explain > div { background: var(--surface); border: 1px solid var(--rule); border-radius: 10px; padding: 12px 14px; overflow-x: auto; }
.explain h3 { font-family: var(--f-mono); font-size: 0.72rem; font-weight: 600; letter-spacing: 0.1em; text-transform: uppercase; color: var(--accent); margin: 0 0 6px; }
.explain p, .explain li { font-size: 0.97rem; margin-bottom: 8px; }
.explain p:last-child { margin-bottom: 0; }
.explain code { font-family: var(--f-mono); font-size: 0.86em; }
.next { display: block; margin-top: 6px; font-weight: 700; }
.pick { margin-bottom: 0; }
.idea { background: var(--surface); border: 1px solid var(--rule); border-left: 4px solid var(--accent); border-radius: 10px; padding: 12px 16px; margin: 0 0 14px; max-width: 72rem; }
.idea h3 { font-family: var(--f-mono); font-size: 0.72rem; font-weight: 600; letter-spacing: 0.1em; text-transform: uppercase; color: var(--accent); margin: 0 0 4px; }
.idea .brief { margin: 0; font-size: 1.08rem; max-width: 62rem; }
.todo { font-family: var(--f-mono); font-size: 0.72rem; font-weight: 600; letter-spacing: 0.1em; text-transform: uppercase; color: var(--source); margin: 0 0 -4px; }
.goals { counter-reset: g; }
.goals li { counter-increment: g; }
.goals li::before { content: counter(g); display: grid; place-items: center; width: 20px; height: 20px; top: 6px; font-family: var(--f-mono); font-size: 0.72rem; color: var(--muted); }
.goals li.done::before { content: "\2713"; color: var(--surface); }
.goals li:not(.done) { border-color: var(--source); font-weight: 700; }
.goals li:not(.done) ~ li:not(.done) { border-color: var(--rule); font-weight: 400; color: var(--muted); }
.cards { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; max-width: 72rem; }
@media (min-width: 800px) { .cards { grid-template-columns: 1fr 1fr; } }
.card { font: inherit; text-align: left; color: var(--ink); background: var(--surface); border: 1px solid var(--rule); border-radius: 10px; padding: 12px 14px; display: grid; gap: 4px; align-content: start; }
button.card { cursor: pointer; } button.card:hover { border-color: var(--accent); }
.card .when { font-family: var(--f-mono); font-size: 0.7rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--source); }
.card b { font-family: var(--f-display); font-size: 1.12rem; }
.card .more { display: none; gap: 6px; font-size: 0.97rem; line-height: 1.5; }
.card.open .more { display: grid; } .card .more i { font-style: normal; font-weight: 700; color: var(--accent); }
button.card:not(.open)::after { content: "Open"; font-family: var(--f-mono); font-size: 0.74rem; color: var(--accent); }
.card-icp { border-color: var(--accent); }
.lvl-win { margin: 14px 0 0; padding: 12px 14px; border-radius: 10px; background: color-mix(in srgb, var(--good) 13%, var(--surface)); border: 1px solid color-mix(in srgb, var(--good) 45%, var(--rule)); font-size: 1.05rem; max-width: 56rem; }
.lvl-win b:first-child { font-family: var(--f-mono); font-size: 0.72rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--good); margin-right: 8px; }
details.math { margin: 14px 0 0; max-width: 56rem; border: 1px solid var(--rule); border-radius: 10px; background: var(--surface); padding: 0 14px; }
details.math summary { cursor: pointer; padding: 9px 0; font-weight: 700; font-size: 0.95rem; color: var(--muted); }
details.math[open] summary { color: var(--ink); border-bottom: 1px solid var(--rule); margin-bottom: 10px; }
details.math p, details.math li { font-size: 0.98rem; }
.lvl-nav { display: flex; justify-content: space-between; gap: 10px; margin: 18px 0 8px; }
.lvl-nav .btn.ready { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.gfoot { padding: 18px 16px 28px; text-align: center; color: var(--muted); font-size: 0.82rem; border-top: 1px solid var(--rule); margin-top: 18px; }
@media (max-width: 520px) { .brief { font-size: 1.02rem; } .gbar { gap: 6px; padding: 6px 10px; } .brand { font-size: 1rem; } .gbtn { padding: 4px 8px; font-size: 0.76rem; } }
@keyframes snap-pop { 0% { transform: scale(0.96); opacity: 0; } 100% { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: no-preference) { .lvl-win:not([hidden]) { animation: snap-pop 0.25s ease-out; } }

/* One current task; supporting material remains available in labelled drawers. */
.current-task { margin: 10px 0; padding: 10px 14px; border: 1px solid var(--accent); border-left-width: 3px; border-radius: 8px; background: var(--tint); }
.task-label { font: 600 0.72rem var(--f-mono); text-transform: uppercase; letter-spacing: 0.08em; color: var(--accent); }
.task-text { margin: 3px 0 0; font-size: clamp(1.02rem, 1.7vw, 1.14rem); line-height: 1.4; max-width: 65ch; }
.control-hint { margin: 0 0 8px; color: var(--muted); font-size: 0.87rem; line-height: 1.4; }
.chart-key { display: flex; flex-wrap: wrap; gap: 4px 16px; margin-top: 10px; font: 0.75rem/1.5 var(--f-mono); color: var(--muted); }
.chart-key > span:first-child:not(.src):not(.tgt) { flex-basis: 100%; }
#l8-plot-caption { margin: 0 0 8px; }
.seg button { min-width: 0; overflow-wrap: anywhere; }
.stat { min-width: 0; overflow-wrap: anywhere; }
.ctl { grid-template-columns: minmax(0, 1fr) auto; }
.lvl-stage, .lvl-side > * { scroll-margin-top: 150px; }
.lesson-drawer { margin: 8px 0; border: 1px solid var(--rule); border-radius: 8px; background: var(--surface); min-width: 0; }
.lesson-drawer > summary { padding: 9px 12px; min-height: 44px; cursor: pointer; font-size: 0.88rem; color: var(--muted); font-weight: 600; }
.lesson-drawer[open] > summary { color: var(--ink); border-bottom: 1px solid var(--rule); }
.drawer-body { padding: 12px; display: grid; gap: 12px; min-width: 0; }
.drawer-body .idea { border: 0; padding: 0; margin: 0; }
.drawer-body .explain { margin: 0; }
.drawer-body .caption { margin: 0; }
.lvl-side .lesson-drawer { margin: 0; }
.lvl-body { margin-top: 12px; }
.game .lvl { scroll-margin-top: 84px; }
.lvl-side > .btns:empty { display: none; }
.btn.current-action, .current-action > .btn { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
canvas.current-action { outline: 2px solid var(--accent); outline-offset: 3px; }
.seg.current-action, .ctl.current-action { outline: 2px solid var(--accent); outline-offset: 3px; }
.game button, .game summary, .game select { touch-action: manipulation; }
.game button:focus-visible, .game summary:focus-visible, .game select:focus-visible, .game input:focus-visible, .game canvas:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
.game .btn { min-height: 44px; }
.game .btn:disabled { opacity: 0.5; cursor: default; }
.card-nav { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px; max-width: 52rem; margin: 12px auto; }
.card-count { font-family: var(--f-mono); font-size: 0.85rem; color: var(--muted); }
#why .cards, #now .cards { grid-template-columns: minmax(0, 1fr); max-width: 52rem; margin: 12px auto; }
#why .card, #now .card { padding: clamp(16px, 3vw, 24px); gap: 10px; }
#why .card .more, #now .card .more { gap: 10px; font-size: 1.02rem; }
.lesson-drawer .board { table-layout: fixed; }
.gbar { display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto; gap: 6px 12px; }
.course-progress { grid-column: 1 / -1; display: flex; align-items: center; gap: 12px; font: 0.7rem var(--f-mono); color: var(--muted); padding: 2px 0 3px; }
.course-progress progress { flex: 1; min-width: 0; height: 6px; appearance: none; border: 0; border-radius: 10px; overflow: hidden; background: var(--rule); accent-color: var(--accent); }
.course-progress progress::-webkit-progress-bar { background: var(--rule); border-radius: 10px; }
.course-progress progress::-webkit-progress-value { background: var(--accent); border-radius: 10px; }
.course-progress progress::-moz-progress-bar { background: var(--accent); border-radius: 10px; }
#g-progress-count { white-space: nowrap; font-variant-numeric: tabular-nums; }
.lvl-win { max-width: none; font-size: 0.98rem; padding: 10px 12px; }
.explore-more { margin-top: 12px; padding: 4px 12px; border: 1px solid var(--rule); border-radius: 10px; background: var(--surface); }
.explore-heading { display: flex; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; }
.explore-heading::before { content: '▸'; color: var(--muted); }
.explore-more[open] > .explore-heading::before { content: '▾'; }
.explore-more[open] > .explore-heading { margin-bottom: 10px; }
.explore-more[open] { padding-bottom: 12px; }
.explore-heading h3 { margin: 0; font-family: var(--f-display); font-size: 1.2rem; }
.explore-heading > span { font: 0.68rem var(--f-mono); padding: 2px 7px; border: 1px solid var(--rule); border-radius: 20px; color: var(--muted); }
.explore-content { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px 24px; align-items: center; }
.explore-content h4 { margin: 0 0 4px; font-size: 0.98rem; }
.explore-content p { margin: 0; max-width: 65ch; font-size: 0.92rem; line-height: 1.45; color: var(--muted); }
.explore-actions { display: grid; gap: 8px; justify-items: start; }
.explore-actions a { font-size: 0.84rem; padding-block: 5px; }
.lvl-nav { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--rule); }
.lvl-stage canvas.strip { height: 112px; margin-top: 8px; }
@media (min-width: 900px) { .lvl-stage.with-strip canvas.plot { max-height: 380px; } }
@media (max-width: 1100px) {
  .gbar { grid-template-columns: minmax(0, 1fr) auto auto; }
  .rail { order: 4; grid-column: 1 / -1; }
  .course-progress { order: 5; }
  .game .lvl { scroll-margin-top: 140px; }
}
@media (max-width: 600px) {
  .course-progress { order: 5; gap: 8px; font-size: 0.63rem; }
  #g-progress-label { display: none; }
  .gbar .brand { margin-right: auto; }
  .lvl-kicker { font-size: 0.66rem; letter-spacing: 0.02em; flex-wrap: wrap; }
  .current-task { padding: 11px 12px; }
  .lvl { padding-top: 16px; }
  .lvl-side .board { font-size: 0.78rem; }
  .board th, .board td { padding: 6px; overflow-wrap: anywhere; }
  .seg button { min-height: 44px; }
  .lvl-body { display: flex; flex-direction: column; }
  .lvl-side { display: contents; }
  .lvl-stage { order: 2; }
  .lvl-side > * { order: 3; width: 100%; }
  .lvl-side > .btns, .lvl-side > .seg,
  .lvl-side > #l6-ask, .lvl-side > #l9-ask, .lvl-side > #l8-p0, .lvl-side > #l8-p1 { order: 1; }
  .explore-more { padding: 4px 12px; }
  .explore-content { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .explore-actions { width: 100%; }
  .explore-actions .btn { width: 100%; }
}

/* Boss rounds share one workspace: controls become results in the same panel. */
#l10 > .idea { padding: 0; margin: 6px 0 12px; border: 0; background: none; }
#l10 > .idea h3 { display: none; }
#l10 > .idea .brief { font-size: 0.96rem; max-width: 95ch; line-height: 1.5; }
.boss-rounds { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; padding: 0; margin: 16px 0 12px; list-style: none; }
.boss-rounds li { margin: 0; padding: 8px 10px; border: 1px solid var(--rule); border-radius: 8px; font: 0.8rem/1.5 var(--f-mono); color: var(--muted); }
.boss-rounds li[aria-current] { border-color: var(--accent); background: var(--tint); color: var(--ink); }
.boss-rounds li.done::after { content: ' ✓'; color: var(--good); }
.boss-body { grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 20px; }
.boss-body .lvl-side { display: grid; gap: 8px; }
.boss-body .lvl-stage { position: sticky; top: 105px; }
.boss-body canvas.plot { aspect-ratio: 1.65; max-height: 380px; }
.boss-body .control-hint { font-size: 0.82rem; line-height: 1.4; margin: 0 0 8px; }
.boss-brief { margin: 0; }
.boss-brief h3 { margin: 2px 0 6px; font-size: 1.25rem; }
.boss-brief .caption { margin: 0; }
.boss-brief p:last-child { margin: 0; font-size: 0.94rem; line-height: 1.45; }
.boss-body .current-task { margin: 0 0 4px; padding: 8px 10px; }
.boss-body .current-task p { font-size: 0.92rem; }
#l10[data-boss-stage="review"] .boss-body .current-task,
#l10[data-boss-stage="review"] #boss-brief { display: none; }
.boss-controls, .boss-answers { display: grid; gap: 10px; }
#boss-controls:has(> :not([hidden])) { margin-bottom: 4px; }
#boss-act, #boss-next { width: 100%; min-height: 44px; }
#boss-cutoff .tgl { margin-top: 10px; }
#boss-result-rows { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.boss-result { padding: 9px 10px; border: 1px solid var(--rule); border-radius: 8px; background: var(--surface); min-width: 0; overflow-wrap: anywhere; }
.boss-result h4 { margin: 0 0 5px; font-size: 0.95rem; }
.boss-result p { margin: 4px 0; font-size: 0.88rem; }
.boss-small-heading { margin: 8px 0; font-size: 1rem; }
.boss-review { padding: 12px; margin: 0; background: var(--tint); border: 1px solid var(--accent); border-radius: 10px; }
.boss-review h3 { margin: 0 0 6px; font-size: 1rem; }
.boss-review > p { margin: 0; font-size: 0.94rem; line-height: 1.5; }
#boss-explore { margin: 8px 0; border-block: 1px solid var(--rule); padding-block: 0; }
#boss-explore summary, #boss-daily > summary { cursor: pointer; min-height: 44px; padding: 8px 0; font-weight: 700; }
#boss-explore p { margin: 8px 0; font-size: 0.9rem; }
#boss-explore a { display: inline-block; padding: 10px 0; }
#boss-check { border-block: 1px solid var(--rule); padding: 8px 0; }
#boss-check-feedback:empty { display: none; }
#boss-title { scroll-margin-top: 150px; }
.boss-body .chart-key { margin: 0 0 8px; }
#boss-options .drawer-body { display: block; }
#boss-options .daily-body { display: grid; }
@media (max-width: 1100px) { .boss-body .lvl-stage { top: 145px; } }
@media (max-width: 760px) {
 .boss-body { display: flex; flex-direction: column; gap: 10px; }
 .boss-body .lvl-side { display: contents; }
 .boss-body .lvl-side > * { width: 100%; order: 3; }
 .boss-body .boss-brief { order: 0; }
 .boss-body .current-task { order: 1; }
 .boss-body .lvl-stage { position: static; width: 100%; order: 2; }
 .boss-body canvas.plot { aspect-ratio: 1.65; max-height: 280px; }
 .boss-body .boss-review { order: 4; }
 .boss-rounds { gap: 4px; }
 .boss-rounds li { padding: 6px 4px; font-size: 0.7rem; text-align: center; }
 #boss-options .daily-body { display: flex; }
}
