:root {
  --ink: #1f2430;
  --muted: #5b6475;
  --line: #d9dde5;
  --paper: #ffffff;
  --desk: #f3f1ec;
  --s1: #3b82f6; --s1-soft: #e3eeff;   /* step 1: break apart (the pieces) */
  --s2: #22a06b; --s2-soft: #dcf4e8;   /* step 2: multiply (the rooms) */
  --s3: #f08c2e; --s3-soft: #fff0e0;   /* step 3: add (the scoop) */
  --clue: #8b5cf6; --clue-soft: #efe8ff;
  --bad: #e5484d;
  --gold: #f5c518;
  --display: "Fredoka", system-ui, sans-serif;
  --body: "Nunito", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; touch-action: manipulation; background: var(--desk); color: var(--ink); font-family: var(--body); }
#app { max-width: 760px; margin: 0 auto; padding: 16px; min-height: 100vh; display: flex; flex-direction: column; gap: 12px; }

/* chrome */
.top { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px; }
.top .homebtn { justify-self: start; }
.top #ovbtn { justify-self: end; }
.top .brand { text-align: center; }
#ovbtn .ovicon { display: none; }
.homebtn { flex: none; width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; font-size: 18px; text-decoration: none; background: var(--paper); box-shadow: inset 0 0 0 2px var(--line); touch-action: manipulation; }
.homebtn:hover { box-shadow: inset 0 0 0 2px var(--ink); }
.brand { font-family: var(--display); font-weight: 600; font-size: 20px; }
button { font: inherit; touch-action: manipulation; -webkit-tap-highlight-color: transparent; white-space: nowrap; font-weight: 700; cursor: pointer; border: 0; border-radius: 999px; padding: 10px 18px; background: var(--paper); color: var(--ink); box-shadow: inset 0 0 0 2px var(--line); }
button:disabled { opacity: .35; cursor: default; }
button.primary { background: var(--ink); color: #fff; box-shadow: none; }
button.ghost { background: transparent; }
.tabs { position: relative; display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; align-items: center; }
.tabs::-webkit-scrollbar { display: none; }
.tab { white-space: nowrap; padding: 7px 12px; font-size: 13px; }
.tab.on { background: var(--ink); color: #fff; box-shadow: none; }
.grouplab { white-space: nowrap; font-size: 11px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); padding-left: 10px; margin-left: 4px; border-left: 2px solid var(--line); }

/* tracker */
.chbar { height: 6px; background: var(--line); border-radius: 9px; overflow: hidden; }
.chbar span { display: block; height: 100%; background: var(--ink); border-radius: 9px; transition: width .25s; }
.pills { display: flex; gap: 6px; margin-top: 10px; min-height: 38px; }
.pill { flex: 1; display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-radius: 12px; background: var(--paper); opacity: .4; font-size: 12px; font-weight: 700; transition: flex .25s; }
.pill b { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-family: var(--display); flex: none; }
.p1 b { background: var(--s1); } .p2 b { background: var(--s2); } .p3 b { background: var(--s3); }
.pill.past { opacity: .7; }
.pill.on { opacity: 1; flex: 2.2; }
.p1.on { background: var(--s1-soft); box-shadow: inset 0 0 0 2px var(--s1); }
.p2.on { background: var(--s2-soft); box-shadow: inset 0 0 0 2px var(--s2); }
.p3.on { background: var(--s3-soft); box-shadow: inset 0 0 0 2px var(--s3); }
.dots { display: flex; gap: 4px; margin-left: auto; font-style: normal; }
.dots em { width: 9px; height: 9px; border-radius: 50%; background: currentColor; opacity: .2; }
.dots em.f { opacity: 1; }
.p1 .dots { color: var(--s1); } .p2 .dots { color: var(--s2); } .p3 .dots { color: var(--s3); }

/* card */
.stage { flex: 1; display: flex; }
.card { flex: 1; background: var(--paper); border-radius: 22px; padding: 22px 24px 26px; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 14px; border-top: 8px solid var(--line); box-shadow: 0 2px 20px rgba(0, 0, 0, .06); }
.card.s1 { border-color: var(--s1); }
.card.s2 { border-color: var(--s2); }
.card.s3 { border-color: var(--s3); }
.card.notice { border-color: var(--clue); background: linear-gradient(var(--clue-soft), var(--paper) 45%); }
.card.trap { border-color: var(--bad); background: linear-gradient(#fdecec, var(--paper) 45%); }
.card.win { border-color: var(--gold); background: linear-gradient(#fff8d6, var(--paper) 45%); }
.card.choice { border-color: var(--ink); }
.tag { font-size: 12px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.card h2 { font-family: var(--display); font-weight: 600; font-size: 30px; line-height: 1.1; margin: -6px 0 0; }
.vis { display: flex; align-items: center; justify-content: center; gap: 16px; width: 100%; flex-wrap: wrap; }
.vis .v { flex: 1 1 240px; display: flex; justify-content: center; min-width: 0; }
.vis svg { width: 100%; height: auto; max-height: 270px; overflow: visible; }
.arrow { font-size: 30px; color: var(--muted); font-weight: 700; }
.eq { font-family: var(--display); font-weight: 600; font-size: 32px; line-height: 1.3; }
.eq b { font-weight: 700; }
.c1 { color: var(--s1); }
.z { color: var(--s2); text-decoration: underline; text-underline-offset: 4px; }
.chain { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin-top: 8px; font: 700 16px var(--body); }
.chain span { background: var(--s2-soft); padding: 4px 12px; border-radius: 999px; }
.words { font-size: 19px; font-weight: 600; max-width: 32ch; margin: 0; }
.reveal { background: var(--clue-soft); color: #5b2fd6; box-shadow: inset 0 0 0 2px var(--clue); }
.card.shown .reveal { display: none; }
.choices { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.choices .choice { background: var(--ink); color: #fff; box-shadow: none; font-size: 17px; padding: 12px 22px; }

/* hidden answers */
.card.quiz:not(.shown) .ans { color: transparent; border-radius: 6px; box-shadow: inset 0 -3px 0 var(--clue); background: var(--clue-soft); }
.card.quiz:not(.shown) text.ans, .card:not(.quiz) text.q, .card.shown text.q { display: none; }
text.q { fill: var(--clue); }

/* svg: grid */
.lab { font-family: var(--display); font-weight: 600; fill: var(--s1); text-anchor: middle; }
.lab.end-anchor { text-anchor: end; }
.lab.h { fill: #7c3aed; } .lab.o { fill: #b45309; }
.cell { stroke-width: 2; transition: fill .2s; }
.cell.idle { fill: #f6f7f9; stroke: #cfd4dc; stroke-dasharray: 5 4; }
.cell.active { fill: var(--s2-soft); stroke: var(--s2); stroke-width: 3.5; }
.cell.done { fill: #f3faf6; stroke: #a6dcc0; }
.cell.ok { fill: #f3faf6; stroke: var(--s2); stroke-width: 3; }
.cell.collect { fill: var(--s3-soft); stroke: var(--s3); stroke-width: 3; }
.cell.notice { fill: var(--clue-soft); stroke: var(--clue); stroke-width: 3.5; }
.cell.wrong { fill: #fff; stroke: var(--clue); stroke-width: 3.5; stroke-dasharray: 6 4; }
.val { font-family: var(--display); font-weight: 700; fill: var(--ink); text-anchor: middle; }
.cell.idle + .val, .cell.idle + .nm + .val { fill: #9aa3b2; }
.sub { font-family: var(--body); font-weight: 700; fill: var(--muted); text-anchor: middle; }
.nm { text-anchor: start; }

/* svg: blocks, dots, line */
.bk { stroke-width: .7; }
.bk.h { fill: #c4b5fd; stroke: #7c3aed; }
.bk.t { fill: #93c5fd; stroke: #1d4ed8; }
.bk.o { fill: #fcd34d; stroke: #b45309; }
.slot { fill: none; stroke: #cfd4dc; stroke-width: 2; stroke-dasharray: 4 3; }
.plus { font-family: var(--display); fill: var(--muted); text-anchor: middle; }
.dot { fill: var(--s1); }
.axis { stroke: var(--ink); stroke-width: 3; stroke-linecap: round; }
.end { fill: var(--muted); text-anchor: middle; font-family: var(--body); font-weight: 700; }
.mk.good { fill: var(--s2); } .mk.bad { fill: var(--bad); } .mk.pt { fill: var(--s1); } .mk.guess { fill: var(--s3); }
.ml { font-family: var(--display); font-weight: 600; text-anchor: middle; }
.ml.good { fill: var(--s2); } .ml.bad { fill: var(--bad); } .ml.pt { fill: var(--s1); } .ml.guess { fill: #b4610f; }

/* html visuals */
.plates { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.plate { background: #f4e6d4; border: 2px solid #d9b98f; border-radius: 999px; padding: 10px 16px; font-size: 20px; display: flex; gap: 10px; align-items: center; justify-content: center; min-width: 84px; min-height: 52px; }
.cl { letter-spacing: -3px; }
.cl.c1 { padding-left: 10px; border-left: 2px dashed #b08350; }
.empty, .none { font-size: 14px; font-weight: 700; color: var(--muted); }
.none { padding: 16px 24px; border: 2px dashed var(--line); border-radius: 14px; }
.hero { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.hero .emo { font-size: 64px; line-height: 1.1; }
.hero .bigtxt { font-family: var(--display); font-weight: 700; font-size: 54px; line-height: 1.1; }

/* grid labels for division (missing side) */
.lab.qmark { fill: var(--clue); }
.lab.on { fill: var(--s2); font-size: 18px; }

/* place-value chart */
.pv { display: grid; gap: 6px; width: 100%; max-width: 560px; align-items: stretch; }
.pvh { font-weight: 800; font-size: 12px; letter-spacing: .06em; text-transform: uppercase; padding: 4px; border-radius: 8px; }
.pvh.h { color: #7c3aed; } .pvh.t { color: #1d4ed8; } .pvh.o { color: #b45309; }
.pvh.hi { background: var(--s2-soft); color: var(--s2); }
.pvl { font-family: var(--display); font-weight: 600; font-size: 20px; display: flex; align-items: center; justify-content: flex-end; padding-right: 4px; white-space: nowrap; }
.pvc { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 6px; padding: 10px 6px 6px; border-radius: 12px; background: #f6f7f9; border: 2px solid transparent; min-height: 64px; min-width: 0; }
.pvc.digits { min-height: 0; padding: 4px 6px; background: transparent; }
.pvc.hi { background: var(--s2-soft); border-color: var(--s2); }
.pvc.trade { background: var(--clue-soft); border-color: var(--clue); border-style: dashed; }
.pvc.short { background: #fdecec; border-color: var(--bad); }
.pvc.result { background: var(--s3-soft); border-color: var(--s3); }
.pvd { font-family: var(--display); font-weight: 700; font-size: 24px; line-height: 1; }
.pvbadge { position: absolute; top: -9px; right: -4px; background: var(--clue); color: #fff; font-size: 11px; font-weight: 800; padding: 2px 7px; border-radius: 999px; }
.pv-none { font-size: 12px; font-weight: 700; color: var(--muted); padding: 10px 0; }
.units { max-width: 100%; height: auto; }
.units .gone { opacity: .15; }
.flatline { stroke: #7c3aed; stroke-width: .5; opacity: .5; }

/* number-line jumps */
.jump { fill: none; stroke: #c9cfd8; stroke-width: 2.5; stroke-dasharray: 5 4; }
.jump.on { stroke: var(--s2); stroke-dasharray: none; stroke-width: 3; }
.jl { font-family: var(--display); font-weight: 700; fill: var(--muted); text-anchor: middle; }
.jl.on { fill: var(--s2); }
.tick { stroke: var(--ink); stroke-width: 2; }

/* leftovers */
.plate.leftover { background: #fff; border-style: dashed; flex-direction: column; gap: 2px; }
.plate.leftover small { font-size: 11px; font-weight: 800; color: var(--muted); }

/* chips */
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; align-items: center; }
.chip { display: flex; align-items: center; gap: 8px; padding: 10px 16px; border-radius: 16px; background: #f6f7f9; border: 2px solid var(--line); font-weight: 700; font-size: 16px; }
.chip .ce { font-size: 24px; line-height: 1; }
.chip.s1 { background: var(--s1-soft); border-color: var(--s1); }
.chip.s2 { background: var(--s2-soft); border-color: var(--s2); }
.chip.s3 { background: var(--s3-soft); border-color: var(--s3); }
.chip.clue { background: var(--clue-soft); border-color: var(--clue); }
.chip.bad { background: #fdecec; border-color: var(--bad); }
.chip.gold { background: #fff8d6; border-color: var(--gold); }
.chip-arrow { font-size: 22px; font-weight: 800; color: var(--muted); }
.card.mini .chip { font-size: 10px; padding: 4px 8px; gap: 4px; }
.card.mini .chip .ce { font-size: 13px; }
.card.mini .chip-arrow { font-size: 12px; }

/* nav */
.nav { display: flex; justify-content: space-between; align-items: center; position: sticky; bottom: 0; padding: 10px 0; background: linear-gradient(transparent, var(--desk) 35%); }
#count { font-weight: 700; color: var(--muted); font-size: 13px; }

/* overview (parent view: answers shown) */
.overview { position: fixed; inset: 0; background: var(--desk); overflow: auto; padding: 16px; z-index: 10; }
.overview[hidden] { display: none; }
.ovhead { display: flex; justify-content: space-between; align-items: center; max-width: 1100px; margin: 0 auto 12px; }
.overview section { max-width: 1100px; margin: 0 auto 26px; }
.overview h3 { font-family: var(--display); font-weight: 600; font-size: 20px; margin: 0 0 10px; }
.minis { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 10px; }
.card.mini { padding: 12px; gap: 6px; border-radius: 14px; border-top-width: 5px; cursor: pointer; justify-content: flex-start; box-shadow: none; }
.card.mini:hover { box-shadow: 0 0 0 2px var(--ink); }
.card.mini .tag { font-size: 9px; }
.card.mini h2 { font-size: 15px; margin: 0; }
.card.mini .eq { font-size: 14px; }
.card.mini .chain { font-size: 10px; }
.card.mini .words { font-size: 11.5px; }
.card.mini .vis svg { max-height: 110px; }
.card.mini .hero .emo { font-size: 28px; }
.card.mini .hero .bigtxt { font-size: 22px; }
.card.mini .plate { font-size: 10px; padding: 4px 8px; min-width: 0; min-height: 0; }
.card.mini .pv { gap: 3px; }
.card.mini .pvd { font-size: 13px; }
.card.mini .pvl { font-size: 12px; }
.card.mini .pvh { font-size: 8px; }
.card.mini .pvc { min-height: 0; padding: 4px; }

@media (max-width: 560px) {
  #app { padding: 12px 16px; }
  .brand { font-size: 16px; }
  #ovbtn { width: 40px; height: 40px; padding: 0; font-size: 18px; }
  #ovbtn .ovlabel { display: none; }
  #ovbtn .ovicon { display: inline; }
  .card { padding: 18px 16px 22px; }
  .card h2 { font-size: 24px; }
  .eq { font-size: 24px; }
  .words { font-size: 17px; }
  .pill span { display: none; }
  .hero .bigtxt { font-size: 40px; }
  .pvl { font-size: 16px; }
  .pvd { font-size: 20px; }
}
