:root {
  --bg: #f7f6f2;
  --surface: #ffffff;
  --ink: #1f2328;
  --muted: #5f6670;
  --line: #e2e0d8;
  --accent: #2f5fd0;
  --accent-ink: #ffffff;
  --accent-soft: #e8eefc;
  --good: #1d7a46;
  --good-soft: #e5f4ea;
  --bad: #b3261e;
  --bad-soft: #fbe9e7;
  --gold: #e9b949;
  --gold-ink: #4a3500;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 2px 8px rgba(0, 0, 0, .05);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171a;
    --surface: #1e2125;
    --ink: #e8e6e1;
    --muted: #a0a6ad;
    --line: #33373d;
    --accent: #7ea2ff;
    --accent-ink: #0d1530;
    --accent-soft: #232c45;
    --good: #6fcf97;
    --good-soft: #1b3326;
    --bad: #ff8a80;
    --bad-soft: #3a1f1d;
    --gold: #e0b44a;
    --gold-ink: #2a1e00;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--accent); }

h1 { font-size: 1.6rem; line-height: 1.25; margin: .4em 0 .6em; }
h2 { font-size: 1.15rem; margin: 0; }

/* ------------------------------------------------------------ top bar --- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.topbar .home { font-weight: 700; text-decoration: none; color: var(--ink); }
.topbar-title { color: var(--muted); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ------------------------------------------------------------- layout --- */

.layout { display: flex; align-items: flex-start; justify-content: center; }
main { flex: 1 1 auto; min-width: 0; max-width: 760px; padding: 16px 16px 96px; }

/* ------------------------------------------------------------ buttons --- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 8px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.small { min-height: 36px; padding: 4px 12px; font-size: .9rem; }
button:focus-visible, a:focus-visible, select:focus-visible, input:focus-visible,
textarea:focus-visible, .pblock:focus-visible, summary:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* ------------------------------------------------------------- picker --- */

.lede { color: var(--muted); }
.picker { list-style: none; padding: 0; margin: 24px 0; display: grid; gap: 12px; }
.picker-card {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 12px;
  padding: 18px 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  color: var(--ink);
  text-decoration: none;
}
a.picker-card:hover { border-color: var(--accent); }
.picker-num { color: var(--muted); font-size: .85rem; text-transform: uppercase; letter-spacing: .04em; }
.picker-title { font-size: 1.2rem; font-weight: 700; flex: 1; }
.picker-card.soon { opacity: .55; box-shadow: none; }
.picker-soon { font-size: .85rem; color: var(--muted); }

/* ---------------------------------------------------------- step page --- */

.progress {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0;
  margin: 4px 0 0;
}
.progress li {
  min-width: 30px;
  padding: 2px 9px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: .8rem;
  text-align: center;
}
.progress li.done { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.progress li.current { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 700; }

.statement {
  margin: 0 0 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}
.statement summary { padding: 10px 14px; cursor: pointer; font-weight: 600; }
.statement .prose { padding: 0 14px 4px; }

.prose p { margin: .6em 0; }
.prose ul { margin: .4em 0; padding-left: 1.4em; }
.prose pre {
  overflow-x: auto;
  margin: .8em 0;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}
.prose code {
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: .9rem;
}
.recap {
  margin: 8px 0 16px;
  padding: 6px 14px;
  border-left: 4px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 0 var(--radius) var(--radius) 0;
}
.recap li { margin: .2em 0; }
.recap ul ul { color: var(--muted); }

.instructions, .hint { color: var(--muted); }
.notice { padding: 12px 14px; border: 1px dashed var(--line); border-radius: var(--radius); }

.part { margin: 20px 0; }
.question { font-weight: 600; }
.part-actions, .game-actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 12px 0; }
.continue { margin: 16px 0 8px; }

/* -------------------------------------------------- multiple choice ---- */

.options { display: grid; gap: 8px; }
.opt {
  display: block;
  width: 100%;
  padding: 12px 14px;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
  overflow-x: auto;
}
.opt:hover:not(:disabled) { border-color: var(--accent); }
.opt:disabled { cursor: default; }
.opt.on { border-color: var(--accent); background: var(--accent-soft); }
.opt.right { border-color: var(--good); background: var(--good-soft); }
.opt.wrong { border-color: var(--bad); background: var(--bad-soft); }
.solved .opt:not(.right) { opacity: .55; }

.feedback:empty { display: none; }
.feedback {
  margin-top: 10px;
  padding: 10px 14px;
  border-radius: var(--radius);
}
.feedback.good { background: var(--good-soft); color: var(--good); }
.feedback.bad { background: var(--bad-soft); color: var(--bad); }
.feedback ul { margin: 0; padding-left: 1.2em; }
.feedback.flash { animation: flash .35s ease-out; }
@keyframes flash { from { transform: translateY(-3px); opacity: .3; } to { transform: none; opacity: 1; } }

/* Iteration-order visual inside an option. */
.ov { display: inline-block; margin-top: 8px; color: var(--muted); }
.ov-cells { display: flex; }
.ov-cells span {
  width: 40px;
  padding: 2px 0;
  border: 1px solid currentColor;
  margin-left: -1px;
  font-size: .8rem;
  text-align: center;
}
.ov-arrow { display: block; position: relative; height: 2px; margin: 9px 8px 4px; background: currentColor; }
.ov-arrow::after {
  content: "";
  position: absolute;
  top: -5px;
  border: 6px solid transparent;
}
.ov-ltr .ov-arrow::after { right: -10px; border-left: 9px solid currentColor; }
.ov-rtl .ov-arrow::after { left: -10px; border-right: 9px solid currentColor; }
.ov2 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 2px; width: 108px; }
.ov2 span {
  display: grid;
  place-items: center;
  height: 22px;
  border: 1px solid currentColor;
  border-radius: 3px;
  font-size: .7rem;
}

/* ---------------------------------------------------------- dimensions --- */

.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; margin: 8px 0 12px; }
.seg {
  min-width: 64px;
  min-height: 40px;
  border: 0;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.seg + .seg { border-left: 1px solid var(--line); }
.seg.on { background: var(--accent); color: var(--accent-ink); }
.dims-fields { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px; }
.dims-field { display: grid; gap: 4px; font-size: .9rem; color: var(--muted); }
.dims-times { padding-bottom: 10px; }
select, input[type="text"], textarea {
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
}

/* ---------------------------------------------------------- base cells --- */

.cells-wrap { display: flex; align-items: flex-start; gap: 10px; overflow-x: auto; padding: 4px 2px 8px; }
.cells-name { padding-top: 12px; white-space: nowrap; }
.cells { display: flex; }
.cell-col { display: grid; justify-items: center; gap: 4px; }
.cell {
  width: 48px;
  height: 48px;
  margin-left: -1px;
  border: 2px solid var(--muted);
  border-radius: 0;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  cursor: pointer;
}
.cell[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); }
.cell[aria-pressed="true"].right { background: var(--good); border-color: var(--good); }
.cell[aria-pressed="true"].wrong { background: var(--bad); border-color: var(--bad); }
.feedback li.ok { color: var(--good); }
.feedback li.no { color: var(--bad); }
.cell.gap {
  display: grid;
  place-items: center;
  border-style: dashed;
  color: var(--muted);
  cursor: default;
}
.cell-index { font-size: .8rem; color: var(--muted); min-height: 1.4em; white-space: nowrap; }
.cell-index .katex { font-size: 1em; }

/* 2D: the same cells in a grid, with clickable row and column headings. */
.cells-grid { display: grid; grid-template-columns: repeat(var(--cols), auto); align-items: stretch; }
.cell-head {
  min-width: 48px;
  display: grid;
  place-items: center;
  padding: 4px 6px;
  border: 0;
  border-radius: 4px;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: .8rem;
  cursor: pointer;
}
.cell-head.corner, .cell-head.gap { cursor: default; }
.cell-head.corner { justify-self: end; padding-right: 10px; white-space: nowrap; color: var(--ink); }
.cell-head[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.cell-head[aria-pressed="true"].right { background: var(--good); }
.cell-head[aria-pressed="true"].wrong { background: var(--bad); }
.cell-head .katex { font-size: 1em; }
.cells-grid .cell { margin: -1px 0 0 -1px; }
.cells-grid .cell.lit { background: var(--accent-soft); }

/* --------------------------------------------------------------- games --- */

.game-stage { margin: 12px 0; }
.game-total { font-weight: 700; font-size: 1.1rem; margin: 8px 0; }
.game-status:empty { display: none; }
.game-status { margin: 8px 0; padding: 10px 14px; border-radius: var(--radius); }
.game-status.good { background: var(--good-soft); color: var(--good); }
.game-status.bad { background: var(--bad-soft); color: var(--bad); }

.coins { display: flex; flex-wrap: wrap; gap: 10px; padding: 6px 0; }
.coin-col { display: grid; justify-items: center; gap: 2px; }
.coin {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 3px solid #c9a227;
  background: #fbf0c8;
  color: #5b4500;
  font: inherit;
  font-size: 1.1rem;
  cursor: pointer;
  transition: opacity .15s, transform .15s;
}
.coin.taken {
  background: var(--gold);
  color: var(--gold-ink);
  border-color: #8a6d00;
  font-weight: 800;
  transform: scale(1.08);
  box-shadow: 0 0 0 3px var(--accent);
}
.coin.blocked { opacity: .25; cursor: default; }
.coin-index { font-size: .75rem; color: var(--muted); }

/* Frog Jump: a row of bars, tall bar = tall stone. --h is height/tallest.
   The arc band above is drawn by the game, which owns the geometry and hands
   the stone width and gap down as variables. */
.stones-wrap { position: relative; overflow-x: auto; margin: 6px 0; }
.stones { display: flex; align-items: end; }
.jump-arcs { position: absolute; top: 0; left: 0; pointer-events: none; }
.jump-arcs path { fill: none; stroke-width: 2; stroke-linecap: round; }
.jump-arcs text { font-size: .7rem; font-weight: 600; }
.jump-arcs .frog { font-size: 15px; }
.arc.taken path { stroke: var(--good); }
.arc.taken text { fill: var(--good); }
.arc.preview path { stroke: var(--accent); stroke-dasharray: 4 3; }
.arc.preview text { fill: var(--accent); }
.stone-col { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.stone {
  display: grid;
  align-items: end;
  justify-items: center;
  padding: 0 0 4px;
  border: 2px solid var(--line);
  border-radius: 8px 8px 4px 4px;
  background: var(--surface);
  color: var(--muted);
  font: inherit;
  font-size: .95rem;
  cursor: default;
  transition: background .15s, border-color .15s;
}
.stone.reachable { border-color: var(--accent); color: var(--ink); cursor: pointer; }
.stone.reachable:hover { background: var(--accent-soft); }
.stone.visited { border-color: var(--good); background: var(--good-soft); color: var(--ink); }
.stone.here { box-shadow: 0 0 0 3px var(--accent); }
.stone-index { font-size: .75rem; color: var(--muted); }

/* Gift Packing: blocks sized by their gift, and a box that fills up. */
.gifts { display: flex; flex-wrap: wrap; gap: 8px; padding: 6px 0; }
.gift {
  --size: 1;
  width: calc(22px + var(--size) * 7px);
  min-width: 34px;
  height: 44px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: .95rem;
  cursor: pointer;
  transition: background .15s, border-color .15s, opacity .15s;
}
.gift.packed { border-color: var(--good); background: var(--good-soft); font-weight: 700; }
.gift.toobig { opacity: .25; cursor: default; }
.box {
  position: relative;
  max-width: 360px;
  height: 26px;
  margin: 10px 0 4px;
  border: 2px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  overflow: hidden;
}
.box-fill { height: 100%; width: 0; background: var(--accent-soft); transition: width .15s; }
.box-fill.exact { background: var(--good-soft); }
.box-cap { position: absolute; inset: 0; display: grid; place-items: center; font-size: .8rem; color: var(--muted); }

/* Mining: a row of tunnel sections, gold or cost, with one stretch dug. */
.tunnel { display: flex; flex-wrap: wrap; gap: 6px; padding: 6px 0; }
.section-col { display: grid; justify-items: center; gap: 2px; }
.section {
  width: 46px;
  height: 46px;
  border: 2px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  font: inherit;
  font-size: .95rem;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.section.gold { color: var(--good); }
.section.cost { color: var(--bad); }
.section.dug { border-color: var(--accent); background: var(--accent-soft); font-weight: 700; }
.section-index { font-size: .75rem; color: var(--muted); }

/* Knapsack: jewels on a table, and a bag that can only take so much. */
.jewels { display: flex; flex-wrap: wrap; gap: 8px; padding: 6px 0; }
.jewel {
  display: grid;
  justify-items: center;
  gap: 1px;
  width: 72px;
  padding: 7px 4px 6px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: .95rem;
  cursor: pointer;
  transition: background .15s, border-color .15s, opacity .15s;
}
.jewel svg { width: 26px; height: 26px; display: block; }
.jewel-worth { font-weight: 700; font-variant-numeric: tabular-nums; }
.jewel-kg { font-size: .75rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.jewel.packed { border-color: var(--good); background: var(--good-soft); }
.jewel.toobig { opacity: .25; cursor: default; }
/* The reveal marks jewels the student may not have taken, so it has to read
   over both a plain and a packed one: a ring outside the border, not a fill. */
.jewel.best { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); opacity: 1; }
.bag {
  position: relative;
  max-width: 360px;
  height: 26px;
  margin: 10px 0 4px;
  border: 2px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  overflow: hidden;
}
.bag-fill { height: 100%; width: 0; background: var(--accent-soft); transition: width .15s; }
.bag-fill.full { background: var(--good-soft); }
.bag-cap { position: absolute; inset: 0; display: grid; place-items: center; font-size: .8rem; color: var(--muted); }

/* ------------------------------------------------------------- parsons --- */

.parsons { list-style: none; padding: 0; margin: 8px 0; display: grid; gap: 6px; }
.pblock {
  --indent: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: calc(var(--indent) * 28px);
  padding: 6px 8px 6px 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: .95rem;
  cursor: pointer;
  user-select: none;
  transition: margin-left .1s;
}
.pblock .ptext { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.pblock .grip {
  align-self: stretch;
  display: grid;
  place-items: center;
  min-width: 32px;
  padding: 0 4px;
  font-size: 1.1rem;
  color: var(--muted);
  cursor: grab;
  touch-action: none;
  font-family: system-ui, sans-serif;
  letter-spacing: -2px;
}
.pblock .pctrl { display: none; gap: 4px; }
.pblock.selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.pblock.selected .pctrl { display: flex; }
.pblock.dragging { z-index: 5; position: relative; box-shadow: 0 6px 18px rgba(0, 0, 0, .18); transition: none; }
.pblock.wrong { border-color: var(--bad); background: var(--bad-soft); }
.parsons.solved .pblock { border-color: var(--good); cursor: default; }
.pbtn {
  min-width: 36px;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
  color: var(--ink);
  font: inherit;
  cursor: pointer;
}

textarea.free { width: 100%; font-family: ui-monospace, Consolas, monospace; }

.solution-nav { display: flex; flex-wrap: wrap; gap: 10px; margin: 24px 0; }

/* -------------------------------------------------- free-play panel ---- */

.freeplay {
  background: var(--surface);
  border: 1px solid var(--line);
  padding: 14px 16px 20px;
}
.freeplay .coins { gap: 5px; }
.freeplay .coin { width: 44px; height: 44px; font-size: 1rem; }
.fp-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.freeplay .hint { margin: 6px 0 0; font-size: .9rem; }
.custom { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px; margin-top: 12px; }
.custom label { display: grid; gap: 4px; flex: 1 1 200px; font-size: .9rem; color: var(--muted); }
.custom input { width: 100%; }

/* Wide screens: a side panel beside the step. */
@media (min-width: 1000px) {
  .freeplay {
    position: sticky;
    top: 70px;
    flex: 0 0 380px;
    margin: 16px 16px 16px 0;
    border-radius: var(--radius);
    max-height: calc(100vh - 90px);
    overflow-y: auto;
  }
}

/* Phones and tablets: a bottom sheet. */
@media (max-width: 999px) {
  .freeplay {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    max-height: 72vh;
    overflow-y: auto;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -8px 24px rgba(0, 0, 0, .18);
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
  }
  body.fp-open main { padding-bottom: 75vh; }
}

@media (max-width: 480px) {
  h1 { font-size: 1.35rem; }
  .coin { width: 42px; height: 42px; font-size: 1rem; }
  .coins { gap: 5px; }
  .cells-wrap { flex-direction: column; gap: 2px; }
  .cells-name { padding-top: 0; }
  .cell { width: 46px; height: 46px; }
  .pblock { flex-wrap: wrap; }
  .pblock.selected .pctrl { flex-basis: 100%; justify-content: flex-end; }
}

/* The student's own write-up, carried onto the solution page. Set apart so it
   can't be read as part of the solution, and wrapped rather than scrolled,
   since the prompt invites plain English as much as pseudocode. */
.draft { margin: 0 0 28px; }
.draft h2 {
  margin: 0 0 6px;
  font-size: 1rem;
  font-weight: 600;
  color: var(--muted);
}
.draft pre {
  margin-top: 0;
  border-style: dashed;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Some people get motion sick, and nothing here needs to move to be understood. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
