/* The Grid on the web (g.html, and teach.html). Playground tokens, the kids'
   palette in MathBlitz/Sources/UI/Theme.swift, the same ones the front page
   (styles.css) uses. The layout follows Theme+Grid.swift. One mint per
   screen: Start on the cover, then the final strike on the paper. */

@font-face {
  font-family: "Baloo 2";
  src: url("/assets/fonts/Baloo2-ExtraBold.ttf") format("truetype");
  font-weight: 800;
  font-display: swap;
}

:root {
  --ground: #202A52; --surface: #2B3563; --raised: #3A467E;
  --plate: #F7F2E6; --plate-ink: #1B2140; --plate-ink2: rgba(27, 33, 64, .62);
  --line: rgba(247, 242, 230, .16);
  --ink: #F4F6FF; --ink2: rgba(244, 246, 255, .7); --ink3: rgba(244, 246, 255, .5);
  --mint: #2BF0A8; --mint-ink: #062418; --orange: #FFA94D; --loss: #FF6B6B;
  --r: 14px; --cg: 3px; --cs: 44px;
  --display: "Baloo 2", system-ui, sans-serif;
  --round: ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; margin: 0; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--ground); color: var(--ink);
  font: 600 16px/1.35 var(--round);
  min-height: 100svh; overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; border: 0; background: none; padding: 0; cursor: pointer; touch-action: manipulation; }
button:disabled { cursor: default; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }
.num { font-family: var(--display); font-variant-numeric: tabular-nums; line-height: 1; }
.micro { font-weight: 900; font-size: 12px; line-height: 1.2; letter-spacing: 1.4px; text-transform: uppercase; color: var(--ink3); }

/* ---------- header ---------- */
.bar {
  position: sticky; top: 0; z-index: 20; background: var(--ground);
  display: flex; align-items: center; gap: 12px;
  width: 100%; max-width: 440px; margin: 0 auto; padding: 10px 16px; min-height: 64px;
}
.bar .home { width: 36px; height: 36px; border-radius: 9px; overflow: hidden; flex: none; }
.bar .home img { width: 100%; height: 100%; display: block; }
.ttl { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1; white-space: nowrap; overflow: hidden; }
.ttl .micro { overflow: hidden; text-overflow: ellipsis; }
.ttl b { font-family: var(--display); font-size: 22px; line-height: 1; }
.rv {
  display: inline-flex; align-items: baseline; gap: 5px; height: 28px; padding: 6px 10px 0; border-radius: 14px;
  background: var(--surface); flex: none; transition: color .2s, box-shadow .2s;
}
.rv .num { font-size: 17px; }
.rv small { font-weight: 800; font-size: 12px; color: var(--ink3); }
.rv.over { box-shadow: inset 0 0 0 1.5px var(--loss); }
.rv.over .num, .rv.over small { color: var(--loss); }
.clockw { display: flex; align-items: baseline; gap: 6px; flex: none; }
.pen { font-weight: 900; font-size: 12px; color: var(--ink2); opacity: 0; transition: opacity .2s; }
.pen.on { opacity: 1; }
#clock { font-size: 19px; color: var(--ink2); min-width: 48px; text-align: right; }

/* ---------- stage ---------- */
.wrap { width: 100%; max-width: 440px; margin: 0 auto; padding: 0 16px 32px; }
.meta { display: flex; justify-content: space-between; gap: 12px; font-weight: 700; font-size: 14px; color: var(--ink3); min-height: 20px; margin-bottom: 10px; }
.meta b { color: var(--ink); font-weight: 800; }
.stage { position: relative; display: flex; justify-content: center; }
.paperw { filter: drop-shadow(0 14px 18px rgba(0, 0, 0, .55)); transform: rotate(-.6deg); }
.paper { background: var(--plate); padding: 12px; }
.gx {
  display: grid; gap: var(--cg);
  grid-template-columns: repeat(var(--cols), var(--cs)); grid-template-rows: repeat(var(--rows), var(--cs));
  transition: filter .2s;
}
.stage.veil .gx { filter: blur(9px); opacity: .85; pointer-events: none; }

.cl {
  position: relative; border-radius: 5px; display: grid; place-items: center;
  box-shadow: inset 0 0 0 1px rgba(27, 33, 64, .14); color: var(--plate-ink);
  font-family: var(--display); font-size: calc(var(--cs) * .55); line-height: 1; padding-top: .1em;
  font-variant-numeric: tabular-nums; transition: background-color .12s;
  width: var(--cs); height: var(--cs);
}
.cl.n3 { font-size: calc(var(--cs) * .42); }
.cl.op { font-family: var(--round); font-weight: 800; font-size: calc(var(--cs) * .42); color: var(--plate-ink2); padding-top: 0; }
.cl.band { background: rgba(27, 33, 64, .07); }
.cl.well {
  background: var(--ground); color: var(--orange);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, .65), inset 0 0 0 1px rgba(0, 0, 0, .35);
}
.cl.well.opw { font-family: var(--round); font-weight: 800; font-size: calc(var(--cs) * .5); padding-top: 0; }
.cl.well.act { box-shadow: inset 0 2px 4px rgba(0, 0, 0, .65), 0 0 0 2px var(--orange); z-index: 2; }
.cl.well.lk { box-shadow: inset 0 3px 6px rgba(0, 0, 0, .8), inset 0 0 0 1px rgba(0, 0, 0, .4); }
.cl.well.hint { color: var(--ink2); }
.cl.well.bad { color: var(--loss); }
.cl .cv { display: flex; align-items: center; gap: 1px; }
.caret { display: inline-block; width: 2px; height: calc(var(--cs) * .5); background: var(--orange); margin-top: -.1em; animation: blink 1s steps(1) infinite; }
.cl.shake { animation: shake .36s ease-in-out; }

/* The strike through a line that checks; the last one is the mint. */
.st { position: absolute; pointer-events: none; background: rgba(27, 33, 64, .5); z-index: 3; }
.cl.well .st { background: rgba(241, 238, 232, .4); }
.st.h { left: calc(var(--cg) / -2 - .5px); right: calc(var(--cg) / -2 - .5px); top: 50%; height: 1.5px; margin-top: -.75px; transform-origin: left center; }
.st.v { top: calc(var(--cg) / -2 - .5px); bottom: calc(var(--cg) / -2 - .5px); left: 50%; width: 1.5px; margin-left: -.75px; transform-origin: center top; }
.st.mint, .cl.well .st.mint { background: var(--mint); }
.st.h.mint { height: 3px; margin-top: -1.5px; }
.st.v.mint { width: 3px; margin-left: -1.5px; }
.st.h.draw { animation: drawH .22s ease-out both; animation-delay: var(--d); }
.st.v.draw { animation: drawV .22s ease-out both; animation-delay: var(--d); }
.st.mint.draw { animation-duration: .32s; }

.status { margin-top: 16px; font-weight: 700; font-size: 14px; color: var(--ink3); text-align: center; min-height: 20px; }
.status.loss { color: var(--loss); }
.status.soft { color: var(--ink); }

/* ---------- start cover ---------- */
.cover { position: absolute; inset: 0; z-index: 6; display: flex; align-items: flex-start; justify-content: center; padding-top: 72px; }
.card {
  width: 100%; max-width: 360px; background: var(--surface); border-radius: var(--r); padding: 20px;
  display: flex; flex-direction: column; gap: 10px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, .55), inset 0 0 0 1px var(--line);
}
.card h1 { font-family: var(--display); font-size: 28px; line-height: 1.02; }
.card p { font-weight: 600; font-size: 15px; color: var(--ink2); }
.card p b { color: var(--ink); }
.facts { display: flex; gap: 8px; flex-wrap: wrap; }
.fact { height: 28px; padding: 0 10px; border-radius: 14px; background: var(--raised); display: inline-flex; align-items: center; font-weight: 800; font-size: 12px; color: var(--ink2); }
.btn { display: grid; place-items: center; width: 100%; min-height: 48px; padding: 0 16px; border-radius: var(--r); font-weight: 800; font-size: 18px; text-decoration: none; text-align: center; }
.btn.accent { background: var(--mint); color: var(--mint-ink); }
.btn.bone { background: var(--plate); color: var(--plate-ink); }
.btn.sec { background: var(--surface); color: var(--ink); box-shadow: inset 0 0 0 1px var(--line); }
.btn.raised { background: var(--raised); color: var(--ink); }
.btn:disabled { opacity: .5; }
.quiet { color: var(--ink2); font-weight: 700; font-size: 14px; text-decoration: underline; text-underline-offset: 3px; text-align: center; }

/* ---------- keypad ---------- */
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  background: var(--surface); border-radius: var(--r) var(--r) 0 0;
  padding: 10px max(16px, calc(50% - 204px)) calc(14px + env(safe-area-inset-bottom));
  box-shadow: 0 -1px 0 var(--line), 0 -18px 34px rgba(0, 0, 0, .55);
  transform: translateY(110%); transition: transform .32s cubic-bezier(.22, 1.1, .36, 1);
}
.sheet.open { transform: none; }
.strip { display: flex; align-items: center; gap: 12px; min-height: 48px; margin-bottom: 10px; }
.eqs { flex: 1; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.eqline { display: flex; align-items: center; gap: 7px; font-family: var(--display); font-size: 20px; line-height: 1; white-space: nowrap; }
.eqline .g { font-family: var(--round); font-weight: 800; font-size: 17px; color: var(--ink3); }
.eqline .bx { min-width: 26px; height: 22px; padding: 2px 3px 0; border-radius: 5px; background: var(--ground); box-shadow: inset 0 0 0 1px var(--line); color: var(--orange); display: inline-grid; place-items: center; font-size: 18px; }
.eqline .bx.on { box-shadow: inset 0 0 0 1.5px var(--orange); }
.eqline.two { font-size: 17px; }
.eqline.two .bx { height: 19px; font-size: 16px; }
.fill { height: 44px; padding: 0 14px; border-radius: var(--r); background: var(--raised); display: flex; align-items: center; gap: 6px; flex: none; font-weight: 700; font-size: 14px; }
.fill small { font-weight: 900; font-size: 12px; color: var(--ink3); }
.pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.pad.ops { grid-template-columns: repeat(4, 1fr); }
.key {
  height: 48px; border-radius: 8px; background: var(--raised); box-shadow: inset 0 0 0 1px var(--line);
  font-family: var(--display); font-size: 26px; display: grid; place-items: center; padding-top: 4px;
  transition: transform .12s; user-select: none; -webkit-user-select: none;
}
.key:active:not(:disabled) { transform: scale(.97); }
.key.ctl { background: var(--plate-ink); padding-top: 0; }
.key.ctl svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.pad.ops .key { height: 102px; font-family: var(--round); font-weight: 800; font-size: 36px; padding-top: 0; }
.key:disabled, .fill:disabled { opacity: .4; }
/* Room under the paper so a focused well can scroll clear of the keypad. */
body.keys .wrap { padding-bottom: 340px; }

/* ---------- end ---------- */
.end { display: flex; flex-direction: column; gap: 16px; margin-top: 24px; animation: rise .34s ease-out; }
.hero { background: var(--plate); color: var(--plate-ink); border-radius: var(--r); padding: 16px 20px; display: flex; flex-direction: column; gap: 8px; }
.hero .micro { color: var(--plate-ink2); }
.hero .top { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 24px; }
.hero .time { font-size: 64px; line-height: .95; }
.hero .sub { font-weight: 700; font-size: 14px; color: var(--plate-ink2); }
.hero .verdict { font-weight: 800; font-size: 19px; line-height: 1.2; text-wrap: balance; border-top: 1px solid rgba(27, 33, 64, .18); padding-top: 10px; margin-top: 2px; }
.cleanb { white-space: nowrap; flex: none; display: inline-flex; align-items: center; height: 24px; padding: 0 8px; border-radius: 12px; box-shadow: inset 0 0 0 1.5px var(--plate-ink); font-weight: 900; font-size: 12px; letter-spacing: 1.4px; text-transform: uppercase; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.panel { background: var(--surface); border-radius: var(--r); padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.panel h2 { font-weight: 800; font-size: 19px; line-height: 1.15; }
.panel p { font-weight: 600; font-size: 14px; color: var(--ink2); }
.panel p.err { color: var(--loss); }
.field { display: flex; gap: 8px; }
.field > * { min-width: 0; }
input, select {
  font: 700 17px/1 var(--round); color: var(--ink); background: var(--ground);
  border: 0; border-radius: 10px; box-shadow: inset 0 0 0 1px var(--line);
  height: 48px; padding: 0 12px; width: 100%; appearance: none; -webkit-appearance: none;
}
input::placeholder { color: var(--ink3); }
input.code { font-family: var(--display); font-size: 22px; letter-spacing: 2px; text-transform: uppercase; padding-top: 3px; }
.field .btn { width: auto; flex: none; }
label.lab { font-weight: 800; font-size: 12px; color: var(--ink3); letter-spacing: .4px; text-transform: uppercase; }
.rows { display: flex; flex-direction: column; gap: 6px; }
.crow { display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 6px 12px; border-radius: 10px; background: var(--ground); }
.crow.you { background: var(--raised); }
.crow .rk { width: 16px; text-align: center; color: var(--ink3); font-size: 17px; }
.crow .nm { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 700; }
.crow .tm { font-size: 22px; }
.crow .no { font-weight: 700; font-size: 14px; color: var(--ink3); }
.bdg { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; flex: none; font-size: 18px; line-height: 1; font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif; }
.panel .foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; font-weight: 700; font-size: 13px; color: var(--ink3); }
.panel .foot button { text-decoration: underline; text-underline-offset: 3px; color: var(--ink2); font-weight: 700; font-size: 13px; }

.note { text-align: center; padding: 96px 16px; display: flex; flex-direction: column; gap: 16px; align-items: center; }
.note h1 { font-family: var(--display); font-size: 28px; line-height: 1.05; }
.note p { color: var(--ink2); max-width: 30ch; }

/* ---------- wide: the keypad sits beside the paper ---------- */
@media (min-width: 860px) {
  .bar, .wrap { max-width: 860px; }
  .wrap { display: grid; grid-template-columns: minmax(0, 1fr) 340px; column-gap: 40px; align-items: start; }
  .wrap > .meta, .wrap > .stage, .wrap > .status { grid-column: 1; }
  .wrap > .side { grid-column: 2; grid-row: 1 / span 4; position: sticky; top: 80px; display: flex; flex-direction: column; gap: 16px; }
  .sheet { position: static; transform: none; border-radius: var(--r); padding: 16px; box-shadow: inset 0 0 0 1px var(--line); }
  .end { margin-top: 0; }
  body.keys .wrap { padding-bottom: 32px; }
  body.solved .sheet { display: none; }
}

@keyframes blink { 50% { opacity: 0; } }
@keyframes shake { 0%, 100% { transform: translateX(0); } 17% { transform: translateX(-6px); } 33% { transform: translateX(6px); } 50% { transform: translateX(-6px); } 67% { transform: translateX(6px); } 83% { transform: translateX(-3px); } }
@keyframes drawH { from { transform: scaleX(0); } to { transform: scaleX(1); } }
@keyframes drawV { from { transform: scaleY(0); } to { transform: scaleY(1); } }
@keyframes rise { from { transform: translateY(16px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001s !important; animation-delay: 0s !important; animation-iteration-count: 1 !important; transition: none !important; }
  .caret { opacity: 1; }
}

/* A narrow phone has no room for the chip's label beside the clock. */
@media (max-width: 400px) {
  .rv small { display: none; }
  .rv { padding: 6px 9px 0; }
}

/* ---------- a class (the join card on g.html, and teach.html) ---------- */
.card .lab, .panel .lab { margin-top: 4px; }
.card .quiet, .panel .quiet, .foot2 .quiet { background: none; }
.card p.err { color: var(--loss); }
.fine { font-weight: 600; font-size: 13px; color: var(--ink3); }

body.teach .wrap { display: flex; flex-direction: column; gap: 16px; max-width: 560px; padding-top: 8px; }
body.teach .bar { max-width: 560px; }
body.teach .panel h1 { font-family: var(--display); font-size: 28px; line-height: 1.05; }
label.check { display: flex; gap: 12px; align-items: flex-start; font-weight: 600; font-size: 14px; color: var(--ink2); cursor: pointer; }
label.check input { flex: none; width: 24px; height: 24px; padding: 0; margin: 0; appearance: auto; -webkit-appearance: checkbox; accent-color: var(--plate); box-shadow: none; }
.linkrow { display: flex; align-items: center; gap: 8px; background: var(--ground); border-radius: 10px; padding: 6px 6px 6px 12px; }
.linkrow .link { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--display); font-size: 17px; padding-top: 3px; }
.linkrow .btn { width: auto; min-height: 40px; font-size: 15px; flex: none; }
.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.tiles > div { background: var(--ground); border-radius: 10px; padding: 10px 8px; display: flex; flex-direction: column; gap: 6px; align-items: center; }
.tiles .micro { font-size: 10px; letter-spacing: 1px; }
.tiles b { font-size: 22px; font-weight: 800; }
.crow .nm small { font-weight: 600; font-size: 12px; color: var(--ink3); }
.crow .rm { font-weight: 700; font-size: 12px; color: var(--ink3); text-decoration: underline; text-underline-offset: 3px; min-height: 44px; padding: 0 2px; }
.cmp { display: grid; grid-template-columns: minmax(0, 1fr) auto auto auto; gap: 10px 16px; align-items: baseline; }
.cmp .h { font-weight: 900; font-size: 10px; letter-spacing: 1px; text-transform: uppercase; color: var(--ink3); }
.cmp .n { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cmp .num { font-size: 19px; text-align: right; }
.foot2 { display: flex; flex-direction: column; gap: 10px; align-items: center; text-align: center; }
@media (min-width: 860px) {
  body.teach .wrap { display: flex; }
}

/* The kids' numpad colours (Theme.swift playground.keyColors), as on the
   front page's round: a digit is found by its colour. */
.pad .key[data-key] { color: #141A33; box-shadow: 0 2px 0 rgba(0, 0, 0, .3); }
.pad .key[data-key="1"] { background: #FF6B6B; } .pad .key[data-key="2"] { background: #FF9F4D; }
.pad .key[data-key="3"] { background: #FFD24A; } .pad .key[data-key="4"] { background: #C6E85F; }
.pad .key[data-key="5"] { background: #6FE07B; } .pad .key[data-key="6"] { background: #45D8D2; }
.pad .key[data-key="7"] { background: #5FB4FF; } .pad .key[data-key="8"] { background: #8A93FF; }
.pad .key[data-key="9"] { background: #E08CFF; } .pad .key[data-key="0"] { background: #EDE7D8; }
.pad .key[data-key="del"] { background: var(--plate-ink); color: var(--ink); }

/* The teacher's own solve, and how to try the link as a student. */
.panel p.self { font-size: 13px; color: var(--ink3); border-top: 1px solid var(--line); padding-top: 12px; }
.panel p.self b { color: var(--ink2); font-size: 15px; }
