/* Learning Pit — recessed and calm. The pit is a pit; daylight is the exception, so the
   dark palette is the one written out in full and the light one only restates the colours. */
:root, :root[data-theme="dark"] {
  --bg: #06080b; --sunk: #0a0f15; --edge: #16202b; --line: #22323f;
  --surface: #0b1016; --raised: #142029; --well: #121a22; --glow: #101a24;
  --ink: #e9f2f8; --dim: #8ba0b1;
  --cyan: #63e0ff; --copper: #d99b63; --good: #5fd39a; --bad: #e8735f;
  --cyanbg: #0d1b22; --coppbg: #1c1409; --goodbg: #101a14;
  --goodline: #244a3c; --badline: #4b2a29; --coppline: #4a3a22;
  --barbg: rgba(6, 8, 11, .8); --cardring: rgba(10, 16, 22, .6);
  --tap: 56px; --r: 16px;
  color-scheme: dark;
}
/* Daylight on a tablet. The accents darken because they are read as text here, not as light. */
:root[data-theme="light"] {
  --bg: #f2f6fa; --sunk: #e7edf4; --edge: #d4dfe9; --line: #bccbd8;
  --surface: #ffffff; --raised: #eaf1f7; --well: #dbe4ed; --glow: #dfeaf5;
  --ink: #15222c; --dim: #56697a;
  --cyan: #0e6f92; --copper: #8f5a22; --good: #1c7d55; --bad: #b23b2b;
  --cyanbg: #e2f1f8; --coppbg: #f8eee0; --goodbg: #e4f4ec;
  --goodline: #9ed2ba; --badline: #e6b3aa; --coppline: #dfc296;
  --barbg: rgba(242, 246, 250, .85); --cardring: rgba(21, 34, 44, .08);
  color-scheme: light;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 1rem/1.5 ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", sans-serif;
  display: flex; flex-direction: column; min-height: 100dvh; overscroll-behavior: none;
  background-image: radial-gradient(120% 70% at 50% -10%, var(--glow) 0%, var(--bg) 60%);
}
h1 { font-size: clamp(1.4rem, 5vw, 2rem); font-weight: 650; letter-spacing: -.01em; margin: .2em 0 .1em; }
h2 { font-size: .78rem; text-transform: uppercase; letter-spacing: .16em; color: var(--dim); margin: 1.6em 0 .6em; font-weight: 600; }
.lede { color: var(--dim); margin: 0 0 1.2em; }
.center { text-align: center; }
.dim { color: var(--dim); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }

#bar {
  display: flex; gap: 8px; align-items: center; padding: max(8px, env(safe-area-inset-top)) 12px 8px;
  border-bottom: 1px solid var(--edge); position: sticky; top: 0; z-index: 5;
  background: var(--barbg); backdrop-filter: blur(8px);
}
.spacer { flex: 1; }
.chip {
  font: inherit; font-size: .85rem; color: var(--dim); background: var(--raised);
  border: 1px solid var(--edge); border-radius: 999px; padding: 8px 12px; min-height: 40px; cursor: pointer;
}
.chip b { color: var(--ink); font-weight: 600; letter-spacing: .04em; }
.chip.big { min-height: var(--tap); font-size: 1rem; padding: 0 18px; }
.chip.on { border-color: var(--cyan); color: var(--ink); box-shadow: 0 0 0 1px var(--cyan) inset; }
.chip.flame { color: var(--copper); }
.atrisk { color: var(--copper); font-weight: 600; }
.chip.warnchip { color: var(--bad); border-color: var(--badline); }
.li.missed { display: block; }
.li.reading.now { background: var(--cyanbg); border-radius: 10px; }
.list.read .li.reading { align-items: flex-start; gap: 14px; padding: 14px 0; }
.li.reading b { display: block; font-weight: 600; }
.li.reading em { display: block; color: var(--dim); font-style: normal; margin-top: 4px; }
.li.reading .cardimg { max-width: 160px; max-height: 120px; margin: 0 0 8px; }
.li.reading .hint { display: block; color: var(--copper); font-size: .8rem; margin-top: 2px; }
.readside { display: grid; gap: 6px; justify-items: end; flex: none; }
.readside .ghost { margin-top: 0; }
.li.missed em { display: block; color: var(--dim); font-style: normal; font-size: .9rem; margin-top: 3px; }

#app {
  flex: 1; width: 100%; max-width: 760px; margin: 0 auto;
  padding: 16px 16px calc(24px + env(safe-area-inset-bottom));
  /* The alcove glow is drawn wider than the card on purpose; clip it rather than let it
     push a phone into sideways scrolling. `clip` doesn't create a scroll container. */
  overflow-x: clip;
}
.back { background: none; border: 0; color: var(--dim); font: inherit; padding: 8px 0; min-height: 44px; cursor: pointer; }

/* ---- home tiles ---- */
.welcome {
  background: linear-gradient(180deg, var(--raised), var(--surface)); border: 1px solid var(--edge);
  border-left: 3px solid var(--cyan); border-radius: var(--r); padding: 14px 18px; margin-bottom: 16px;
}
.welcome p { margin: 0 0 8px; color: var(--dim); font-size: .92rem; line-height: 1.5; }
.welcome p:last-child { margin-bottom: 0; }
.welcome b { color: var(--ink); }

.tiles { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
.tile {
  position: relative; text-align: left; display: flex; flex-direction: column; gap: 2px;
  background: linear-gradient(180deg, var(--raised), var(--surface)); border: 1px solid var(--edge);
  border-radius: var(--r); padding: 16px; min-height: 132px; color: var(--ink); font: inherit; cursor: pointer;
}
.tile:active { transform: scale(.985); }
.tile-icon { font-size: 1.4rem; line-height: 1; margin-bottom: 4px; }
.tile.big-icon { min-height: 160px; }
.tile.big-icon .tile-icon { font-size: 3rem; margin-bottom: 8px; }
.tile.big-icon .tile-title { font-size: 1.15rem; }
.icon-field { width: 84px; flex: none; }
.icon-field input { text-align: center; font-size: max(20px, 1.25rem); }
.stack.grow { flex: 1; }
.tile-title { font-weight: 650; font-size: 1.05rem; padding-right: 46px; }
.tile-sub { color: var(--dim); font-size: .8rem; }
.tile.add { align-items: center; justify-content: center; text-align: center; font-size: 1.6rem; color: var(--dim); border-style: dashed; }
.ring {
  position: absolute; top: 12px; right: 12px; width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center;
  background: conic-gradient(var(--cyan) calc(var(--pct) * 1%), var(--well) 0);
}
.ring i { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; background: var(--surface); font-size: .75rem; font-style: normal; color: var(--dim); }
.tile .tile-sub:last-child { margin-top: auto; }
.tile-sub.deadline { color: var(--copper); }

/* activity heatmap: 17 weeks of columns, scrolls on a phone */
.heat {
  display: grid; grid-auto-flow: column; grid-template-rows: repeat(7, 1fr);
  gap: 3px; overflow-x: auto; padding-bottom: 6px;
}
.heat .cell { width: 12px; height: 12px; border-radius: 3px; background: var(--well); }
.heat .l1 { background: #1d4a55; } .heat .l2 { background: #2a7f8f; }
.heat .l3 { background: #3fb6c9; } .heat .l4 { background: var(--cyan); }

.fc { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; align-items: end; height: 120px; }
.fc span { display: grid; grid-template-rows: 1fr auto auto; height: 100%; align-items: end; justify-items: center; gap: 4px; }
.fc i { width: 70%; min-height: 3px; background: var(--cyan); border-radius: 4px 4px 0 0; opacity: .8; align-self: end; }
.fc small { color: var(--dim); font-size: .68rem; }
.fc b { font-size: .8rem; color: var(--ink); min-height: 1em; }

.bar-row { margin-bottom: 12px; }
.bar-row > span { display: flex; justify-content: space-between; gap: 10px; font-size: .9rem; margin-bottom: 5px; }
.bar-row small { color: var(--dim); }
.bar-row .who { font-weight: 500; }
.bar { height: 8px; background: var(--well); border-radius: 4px; overflow: hidden; }
.bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--cyan), var(--copper)); }

input[type=search] {
  width: 100%; background: var(--surface); color: var(--ink); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px 14px; font: inherit; font-size: max(16px, 1rem); margin-bottom: 12px;
  min-height: var(--tap); -webkit-appearance: none;
}
.tagrow { margin: 0 0 14px; }
.tagrow .chip { min-height: 38px; }
.avatars { gap: 6px; margin-bottom: 14px; }
.avatars .chip { font-size: 1.2rem; padding: 6px 10px; min-height: 44px; }
.chip.swatch { padding: 0; width: 44px; display: grid; place-items: center; }
.chip.swatch span { width: 22px; height: 22px; border-radius: 50%; background: var(--sw); display: block; }
.source {
  display: inline-block; margin-top: 10px; font-size: .8rem; color: var(--dim);
  text-decoration: underline; text-underline-offset: 3px;
}

.due-all { margin-bottom: 14px; border-color: var(--cyan); color: var(--cyan); background: var(--cyanbg); }
.due-all small { color: var(--dim); font-weight: 400; margin-left: 8px; }
.due-all.urgent { border-color: var(--copper); color: var(--copper); background: var(--coppbg); }
.spread { display: block; margin: -6px auto 14px; }
.newtag { color: var(--cyan); font-size: .68rem; text-transform: uppercase; letter-spacing: .08em; font-weight: 650; }
.from { display: block; margin-top: 12px; font-size: .7rem; letter-spacing: .16em; text-transform: uppercase; color: var(--dim); }
.verdict { margin-top: 14px; padding: 14px 16px; border-radius: var(--r); border: 1px solid var(--line); background: var(--surface); }
.verdict.exact, .verdict.close { border-color: var(--good); }
.verdict.exact b, .verdict.close b { color: var(--good); }
.verdict.wrong { border-color: var(--bad); }
.verdict.wrong b { color: var(--bad); }
.verdict p { margin: 6px 0 0; font-size: 1.1rem; }
.verdict .linky { margin-top: 10px; display: inline-block; }

.stats { display: flex; gap: 18px; flex-wrap: wrap; color: var(--dim); font-size: .8rem; }
.stats b { display: block; color: var(--ink); font-size: 1.4rem; font-weight: 650; }

/* ---- game menu ---- */
.small-note { font-size: .8rem; margin-top: 8px; }
.games { display: grid; gap: 10px; }
.game {
  display: flex; align-items: center; gap: 14px; text-align: left; font: inherit; color: var(--ink); cursor: pointer;
  background: var(--surface); border: 1px solid var(--edge); border-radius: var(--r); padding: 14px 16px; min-height: var(--tap);
}
.game[disabled] { opacity: .35; }
.game small { display: block; color: var(--dim); font-size: .82rem; }
.glyph { font-size: 1.5rem; color: var(--cyan); width: 32px; text-align: center; }

/* ---- the pit ---- */
.prog { height: 4px; background: var(--well); border-radius: 4px; overflow: hidden; margin-bottom: 2px; }
.pcount { text-align: center; color: var(--dim); font-size: .68rem; letter-spacing: .1em; margin-bottom: 6px; }
.prog i { display: block; height: 100%; background: var(--cyan); transition: width .3s ease; }
.prog.clock { height: 8px; }
.prog.clock i { background: linear-gradient(90deg, var(--bad), var(--copper) 40%, var(--cyan)); transition: width .2s linear; }
.tools { display: flex; flex-wrap: wrap; gap: 4px 14px; justify-content: center; }
.undo { display: block; margin: 6px auto 0; background: none; border: 0; color: var(--dim); font: inherit; font-size: .78rem; cursor: pointer; min-height: 36px; }
.duelbar { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 8px 0 4px; }
.duelbar span {
  padding: 6px 14px; border-radius: 999px; border: 1px solid var(--edge);
  color: var(--dim); font-size: .85rem; background: var(--surface);
}
.duelbar span.up { border-color: var(--cyan); color: var(--ink); }
.duelbar b { font-weight: 600; margin-right: 6px; }

.scoreline { text-align: center; color: var(--dim); font-size: .8rem; margin: 8px 0 -4px; }
.scoreline b { color: var(--cyan); font-size: 1.1rem; }
.pit { position: relative; display: grid; place-items: center; padding: clamp(10px, 4vw, 28px) 0; isolation: isolate; }
.pit::before {
  content: ''; position: absolute; z-index: -1; inset: -6% -12%; border-radius: 50%;
  opacity: var(--lit, 1); transition: opacity .6s ease;
  background:
    radial-gradient(circle at 50% 45%, rgba(99, 224, 255, .10), transparent 62%),
    repeating-radial-gradient(circle at 50% 45%, transparent 0 26px, rgba(99, 224, 255, .06) 26px 27px);
}
/* A card is lowered into the alcove rather than swapped. */
.screen.session .card, .screen.results .card { animation: descend .34s cubic-bezier(.2, .7, .3, 1); }
@keyframes descend {
  from { opacity: 0; transform: translateY(-10px) scale(.985); }
  to   { opacity: 1; transform: none; }
}
.pit.done::before { animation: flare 1.6s ease-out; }
@keyframes flare { from { opacity: .15; } 40% { opacity: 1; } to { opacity: 1; } }
.card {
  position: relative; width: 100%; min-height: min(46dvh, 340px); display: grid; place-items: center; text-align: center;
  padding: clamp(18px, 5vw, 34px); font: inherit; color: var(--ink); cursor: pointer;
  background: radial-gradient(120% 100% at 50% 0%, var(--raised), var(--surface));
  border: 1px solid var(--line); border-radius: 24px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .06), 0 24px 60px -30px #000, 0 0 0 6px var(--cardring);
}
.pit.small .card { min-height: min(26dvh, 200px); }
.card.static { cursor: default; }
.card .face { font-size: clamp(1.15rem, 4.2vw, 1.7rem); font-weight: 500; text-wrap: balance; }
.card.flipped { border-color: var(--cyan); box-shadow: inset 0 1px 0 rgba(255, 255, 255, .06), 0 0 60px -20px var(--cyan); }
.card .face.long { font-size: clamp(.95rem, 2.6vw, 1.1rem); font-weight: 400; text-align: left; line-height: 1.55; }
.card .face.long .answer, .card .face.long .note { font-size: 1em; }
.card .hint { display: block; margin-top: 14px; color: var(--copper); font-size: .85rem; }
.card .prompt { display: block; margin-bottom: 14px; color: var(--dim); font-size: .8rem; font-weight: 400; }
.cardimg {
  display: block; margin: 0 auto 14px; max-width: min(100%, 320px); max-height: 34dvh;
  object-fit: contain; border-radius: 12px; background: var(--surface);
}
.pit.small .cardimg { max-height: 22dvh; }
.thumb { width: 64px; height: 64px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); }
.picrow { align-items: center; }
.ghost.recording { color: var(--bad); border-color: var(--bad); animation: pulse 1.2s ease-in-out infinite; }
.tap { position: absolute; bottom: 26px; color: var(--dim); font-size: .72rem; letter-spacing: .18em; text-transform: uppercase; }
.micbtn {
  min-width: var(--tap); min-height: var(--tap); border-radius: 14px; font-size: 1.1rem; cursor: pointer;
  background: var(--raised); color: var(--ink); border: 1px solid var(--line); flex: none;
}
.micbtn.on { border-color: var(--bad); color: var(--bad); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .45; } }
.pulsing { color: var(--cyan); animation: pulse 1.4s ease-in-out infinite; }

.speak { position: absolute; top: 22px; right: 14px; background: none; border: 0; font-size: 1.2rem; opacity: .5; min-height: 44px; min-width: 44px; cursor: pointer; }
.score { font-size: 4rem; font-weight: 650; color: var(--cyan); display: block; }
.stars { font-size: clamp(2.6rem, 12vw, 4rem); color: var(--copper); letter-spacing: .1em; display: block; }
.stars.big { color: var(--copper); }
.won { color: var(--copper); font-size: 1.05rem; margin-top: 10px; }
.shelf { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 12px; }
.sticker {
  position: relative; width: 56px; height: 56px; display: grid; place-items: center;
  font-size: 1.9rem; background: var(--raised); border: 1px solid var(--edge); border-radius: 14px;
}
.sticker.locked { filter: grayscale(1) brightness(.45); }
.sticker.locked small {
  position: absolute; bottom: 2px; right: 4px; font-size: .58rem; color: var(--dim);
  filter: none; background: var(--raised); border-radius: 4px; padding: 0 2px;
}
.grades.kid { grid-template-columns: repeat(2, 1fr); }
.grades.kid .btn { min-height: 76px; font-size: 1.1rem; }
select { background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; font: inherit; min-height: 44px; }
label.row { justify-content: flex-start; gap: 12px; }
label.row small { margin-left: -6px; }
.score small { font-size: 1.4rem; color: var(--dim); }
.pit.done .card { border-color: var(--copper); }

/* ---- buttons ---- */
.row { display: flex; gap: 10px; margin-top: 14px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grades { display: grid; grid-template-columns: repeat(3, 1fr); }
.btn {
  flex: 1; min-height: var(--tap); border-radius: 14px; font: inherit; font-weight: 600; cursor: pointer;
  background: var(--raised); color: var(--ink); border: 1px solid var(--line); padding: 0 16px;
}
.btn:active { transform: translateY(1px); }
.btn.wide { width: 100%; }
.btn.kidplay { min-height: 88px; font-size: 1.5rem; border-color: var(--cyan); color: var(--cyan); margin-bottom: 14px; }
.btn small { display: block; font-weight: 400; font-size: .75rem; color: var(--dim); }
.btn.again { border-color: var(--badline); color: var(--bad); }
.btn.good { border-color: var(--goodline); color: var(--good); }
.btn.easy { border-color: var(--coppline); color: var(--copper); }
.ghost { background: none; border: 1px solid var(--edge); color: var(--dim); border-radius: 14px; min-height: var(--tap); font: inherit; padding: 0 16px; cursor: pointer; margin-top: 18px; }
.ghost.sm { min-height: 36px; margin: 0; font-size: .8rem; }

.options { display: grid; gap: 10px; margin-top: 14px; }
.opt {
  min-height: var(--tap); border-radius: 14px; background: var(--raised); color: var(--ink); font: inherit;
  border: 1px solid var(--line); padding: 12px 16px; text-align: left; cursor: pointer;
}
.opt.right { border-color: var(--good); color: var(--good); }
.opt.wrong { border-color: var(--bad); color: var(--bad); }
.opt.faded { opacity: .55; }   /* dimmed, still readable — they are part of the feedback */

.addcard { display: inline-block; margin-bottom: 10px; }
.field { display: block; color: var(--dim); font-size: .8rem; margin-bottom: 12px; }
.field select, .field textarea { display: block; width: 100%; margin-top: 4px; font-size: 1rem; }

.answer { margin: 10px 0 0; font-size: 1.15rem; color: var(--cyan); }

.bar.weak i { background: var(--bad); }

.li b.clean { color: var(--good); }

/* The certificate — worth a spot on the fridge */
.cert {
  text-align: center; border: 3px double var(--copper); border-radius: var(--r);
  padding: 40px 24px; margin-top: 18px; background: var(--surface);
}
.cert-icon { font-size: 3.4rem; }
.cert-head { text-transform: uppercase; letter-spacing: .28em; font-size: .8rem; color: var(--copper); margin: 10px 0 18px; }
.cert-who { font-size: 1.7rem; font-weight: 650; margin: 0; }
.cert-what { color: var(--dim); margin: 8px 0; }
.cert-module { font-size: 1.4rem; font-weight: 650; color: var(--cyan); margin: 0 0 16px; }
.cert-meta { color: var(--dim); font-size: .8rem; }
@media print {
  .screen.certificate .cert { border-color: #000; color: #000; background: #fff; }
  .screen.certificate .cert-module, .screen.certificate .cert-head { color: #000; }
}

/* Rank — where this learner stands in the pit */
.rank { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; align-items: center; margin: 14px 0 18px; }
.rank-glyph { font-size: 1.6rem; color: var(--cyan); grid-row: span 2; }
.rank b { font-weight: 650; }
.rank small { color: var(--dim); font-size: .78rem; margin-left: 8px; }
.rank-bar { display: block; height: 4px; border-radius: 3px; background: var(--well); overflow: hidden; }
.rank-bar i { display: block; height: 100%; background: var(--cyan); }

.claim { margin: 14px 0 0; font-size: 1.2rem; color: var(--copper); }
.claim.yes { color: var(--good); }
.claim.no { color: var(--bad); text-decoration: line-through; }

.slate {
  position: relative; margin-top: 14px; height: min(38dvh, 300px);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
  --guide: rgba(140, 160, 176, .35);
}
.slate canvas { display: block; width: 100%; height: 100%; touch-action: none; color: var(--cyan); border-radius: var(--r); }
.slate .wipe { position: absolute; top: 8px; right: 8px; }

/* Number pad — big targets, nothing to read */
.pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; max-width: 340px; margin: 16px auto 0; }
.key {
  min-height: 64px; border-radius: 14px; font: inherit; font-size: 1.5rem; font-weight: 650; cursor: pointer;
  background: var(--raised); color: var(--ink); border: 1px solid var(--line);
}
.key:active { transform: translateY(1px); }
.key.ok { color: var(--good); border-color: var(--good); }
.key.dim { color: var(--dim); }
.key[disabled] { opacity: .4; }
.entry { display: block; margin-top: 14px; font-size: 2.6rem; font-weight: 650; letter-spacing: .06em; color: var(--cyan); }
.entry.wrong { color: var(--bad); }
.entry.exact { color: var(--good); }

/* Explain it — the words the answer is made of, hit and missed */
.hits { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.hit { font-size: .78rem; padding: 4px 9px; border-radius: 999px; border: 1px solid var(--line); }
.hit.got { color: var(--good); border-color: var(--good); }
.hit.miss { color: var(--dim); opacity: .6; }

/* Point at it — the options are pictures, so nothing has to be read */
.asking { display: flex; align-items: center; justify-content: center; gap: 10px; margin: 16px 0 18px; }
.asking b { font-size: clamp(1.7rem, 9vw, 2.6rem); font-weight: 650; }
.asking .speak { position: static; opacity: .6; }
.pics { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.pictile {
  background: var(--raised); border: 2px solid var(--line); border-radius: 18px; padding: 8px;
  min-height: 26dvh; display: grid; place-items: center; cursor: pointer;
}
.pictile .cardimg { margin: 0; width: min(100%, 200px); max-height: 22dvh; }
.pictile.right { border-color: var(--good); }
.pictile.wrong { border-color: var(--bad); }
.pictile.faded { opacity: .35; }   /* still visible — the dimming is the feedback */
.pictile:active { transform: scale(.98); }

/* Spell it */
.slots { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-top: 14px; }
.slot {
  width: 42px; height: 52px; border-radius: 10px; font: inherit; font-size: 1.4rem; font-weight: 650;
  background: var(--surface); color: var(--ink); border: 2px dashed var(--line); cursor: pointer;
}
.slot.full { border-style: solid; border-color: var(--cyan); background: var(--raised); }
.letters { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 18px; }
.letter {
  min-width: 52px; min-height: 56px; border-radius: 12px; font: inherit; font-size: 1.3rem; font-weight: 650;
  background: var(--raised); color: var(--ink); border: 1px solid var(--line); cursor: pointer;
}
.letter:disabled { opacity: .2; }
.letter:active { transform: translateY(2px); }

.bins { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-top: 16px; }
.bin {
  min-height: 92px; border-radius: var(--r); font: inherit; font-weight: 600; cursor: pointer;
  background: var(--raised); color: var(--ink); border: 1px solid var(--line);
  display: grid; place-items: center; gap: 6px; padding: 12px; text-align: center;
}
.bin .glyph { font-size: 1.6rem; }
.bin.right { border-color: var(--good); color: var(--good); }
.bin.wrong { border-color: var(--bad); color: var(--bad); }
.bin.faded { opacity: .5; }

.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-top: 10px; }
@media (min-width: 640px) { .grid { grid-template-columns: repeat(3, 1fr); } }
.mtile {
  min-height: 84px; border-radius: 14px; font: inherit; font-size: .9rem; cursor: pointer; padding: 10px;
  background: var(--raised); color: var(--ink); border: 1px solid var(--line);
  display: grid; place-items: center; text-align: center;
}
.mtile.back { background: var(--goodbg); }
.mtile.sel { border-color: var(--cyan); box-shadow: 0 0 24px -8px var(--cyan); }
.mtile.done { opacity: .18; }

textarea, input[type=text], input:not([type]) {
  width: 100%; background: var(--surface); color: var(--ink); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px; font: inherit; font-size: max(16px, 1rem); /* never under 16px: iOS zooms on focus */
}
textarea { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: max(16px, .85rem); }
input[type=checkbox] { width: 26px; height: 26px; accent-color: var(--cyan); }
label.btn { display: grid; place-items: center; position: relative; }
/* The file input inside is screen-reader-only but still focusable, so show its ring here. */
label.btn:focus-within { outline: 2px solid var(--cyan); outline-offset: 2px; }
.err { color: var(--bad); min-height: 1.4em; }
.warn { color: var(--copper); font-size: .85rem; margin: 8px 0 0; line-height: 1.4; }
.linky { background: none; border: 0; color: var(--cyan); font: inherit; text-decoration: underline; cursor: pointer; padding: 0; }
.linky.skip { display: block; margin: 12px auto 0; color: var(--dim); font-size: .82rem; min-height: 36px; }
.picklist { margin: 8px 0 0; padding-left: 18px; max-height: 46dvh; overflow-y: auto; }
.picklist li { margin-bottom: 6px; }
.picklist label { display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; align-items: baseline; cursor: pointer; }
.picklist em { grid-column: 2; color: var(--dim); font-style: normal; font-size: .85rem; }
.picklist input { grid-row: span 2; }

.preview.audit { border-color: var(--coppline); }
.preview.audit em { color: var(--copper); }

.preview { background: var(--surface); border: 1px solid var(--edge); border-radius: var(--r); padding: 14px 16px; margin-bottom: 10px; }
.preview ol { margin: 10px 0 4px; padding-left: 20px; }
.preview li { margin-bottom: 8px; font-size: .88rem; }
.preview li span { display: block; }
.preview li em { color: var(--dim); font-style: normal; }
.row input:not([type=checkbox]) { flex: 1; }
.list .li { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--edge); }
label.li { cursor: pointer; min-height: 48px; }
.stack { display: block; margin-bottom: 12px; color: var(--dim); font-size: .8rem; }
.stack input, .stack textarea { margin-top: 5px; color: var(--ink); font-size: max(16px, 1rem); }
.rowbtn { flex: 1; text-align: left; background: none; border: 0; color: var(--ink); font: inherit; padding: 6px 0; cursor: pointer; min-height: 44px; }
.rowbtn em { display: block; color: var(--dim); font-style: normal; font-size: .85rem; }
.li.paused .rowbtn { opacity: .45; }
.li.chosen { background: var(--cyanbg); border-radius: 8px; }
.pick { flex: none; width: 22px; height: 22px; accent-color: var(--cyan); }
.bulk { align-items: center; background: var(--raised); border: 1px solid var(--line); border-radius: var(--r); padding: 10px 14px; }
.bulk b { color: var(--cyan); margin-right: 4px; }
.bulk .ghost { margin-top: 0; }
.state .log { letter-spacing: 1px; color: var(--copper); font-size: .8em; }
.li.editing { display: block; background: var(--surface); border: 1px solid var(--cyan); border-radius: var(--r); padding: 14px; margin: 10px 0; }
.li.editing .row { margin-top: 0; }
.list small { color: var(--dim); }
code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--copper);
  font-size: .88em; background: var(--raised); border: 1px solid var(--edge);
  border-radius: 6px; padding: .1em .35em; overflow-wrap: anywhere;
}
.card .face code { font-size: .8em; }

.sheet {
  position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; padding: 20px;
  background: rgba(3, 5, 8, .72); backdrop-filter: blur(3px);
}
.sheet-box {
  width: min(420px, 100%); background: var(--raised); border: 1px solid var(--line);
  border-radius: 20px; padding: 22px; box-shadow: 0 30px 60px -25px #000;
}
.sheet-box p { margin: 0 0 14px; font-size: 1.05rem; }
.sheet-box input { margin-bottom: 4px; }
.choices { display: grid; gap: 8px; max-height: 46dvh; overflow-y: auto; margin-bottom: 14px; }
.choices .opt { min-height: 52px; }

/* Tablet held sideways: the card and the answers sit side by side instead of the card
   eating the screen and the buttons falling below the fold. */
@media (orientation: landscape) and (min-width: 820px) and (min-height: 500px) {
  .screen.session { max-width: 1100px; }
  .screen.session .pit { padding: 0; }
  .screen.session .card { min-height: min(62dvh, 460px); }
  .screen.session .prog, .screen.session .undo, .screen.session .clock, .screen.session .scoreline,
  .screen.session .tools, .screen.session .asking { grid-column: 1 / -1; }
  .screen.session:has(.options), .screen.session:has(.grades), .screen.session:has(#typef),
  .screen.session:has(.pad), .screen.session:has(.pics) {
    display: grid; grid-template-columns: 1.15fr 1fr; gap: 16px 26px; align-content: start;
  }
  /* The card holds the left column; everything else auto-places down the right one. */
  .screen.session .pit { grid-column: 1; grid-row: span 4; align-self: center; }
  .screen.session .options, .screen.session .grades, .screen.session #typef,
  .screen.session .verdict, .screen.session .pad, .screen.session .pics { margin-top: 0; }
  .screen.session .pad { max-width: none; }
  .grades { grid-template-columns: 1fr; }
  .grades .btn { min-height: 68px; }
}

#toasts {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 20;
  bottom: calc(16px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column-reverse; gap: 8px; align-items: center;
  pointer-events: none;                      /* the screen underneath stays usable */
}
.toast {
  pointer-events: auto;
  display: flex; gap: 14px; align-items: center; max-width: min(92vw, 520px);
  background: var(--raised); border: 1px solid var(--line); border-radius: 14px;
  padding: 12px 16px; box-shadow: 0 20px 40px -20px #000;
}

:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }
h1:focus { outline: none; }   /* focused for orientation only, not a control */

.goal { height: 6px; background: var(--well); border-radius: 4px; overflow: hidden; margin: -6px 0 16px; }
.goal i { display: block; height: 100%; background: linear-gradient(90deg, var(--cyan), var(--copper)); transition: width .4s ease; }
.note { margin: 14px 0 0; font-size: .9rem; color: var(--dim); line-height: 1.45; text-wrap: pretty; }
.verdict .note { margin-top: 8px; }

/* Cut-out cards: front above the fold, answer below it. */
.cutgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; }
.cut { border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.cut-front, .cut-back { padding: 14px; min-height: 70px; display: grid; place-items: center; text-align: center; }
.cut-front { font-weight: 600; border-bottom: 1px dashed var(--line); }
.cut-back { color: var(--dim); }

@media print {
  .screen.cutouts .cutgrid { grid-template-columns: repeat(2, 1fr); gap: 0; }
  .screen.cutouts .cut { border: 1px solid #999; border-radius: 0; break-inside: avoid; }
  .screen.cutouts .cut-front { border-bottom: 1px dashed #bbb; color: #000; font-size: 12pt; }
  .screen.cutouts .cut-back { color: #333; font-size: 11pt; }
  .noprint { display: none !important; }
}

/* The edit screen doubles as the print sheet: cards as a plain two-column list. */
@media print {
  body { background: #fff; color: #000; display: block; }
  #bar, .back, .row, .stack, h2, .toast, .li.editing, #err { display: none !important; }
  #app { max-width: none; padding: 0; }
  h1 { font-size: 20pt; margin-bottom: 12pt; }
  .list .li { border-bottom: 1px solid #ccc; padding: 6pt 0; break-inside: avoid; }
  .rowbtn { color: #000; font-size: 11pt; }
  .rowbtn em { color: #444; }
}

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

@media (prefers-contrast: more) {
  :root, :root[data-theme="dark"] { --dim: #b9cbd8; --line: #4a6376; --edge: #3a5063; }
  :root[data-theme="light"] { --dim: #2b3c49; --line: #7c8fa0; --edge: #93a7b7; }
  .btn, .opt, .tile, .game, .chip { border-width: 2px; }
  .tile-sub, .lede, small { color: var(--dim); }
}
