:root {
  /* the night look (this product's own); the light look is chosen with the switch beside Home */
  --bg: #0b1226;
  --bg2: #18223d;
  --ink: #e6ecf7;
  --inkDim: #9fb0cc;
  --line: #2c3a5c;
  --accent: #7dd3fc;
  --accentInk: #06121f;
  --sel: #23365e;
  --skyBg: #050914;
  --wordInk: #ffffff;
  --wordDone: #7dffb0;
  --wordLock: #fde68a;
  --shade: rgba(5, 9, 20, 0.86);
  --toastBg: #f8fafc;
  --toastInk: #0b1226;
  --danger: #f87171;
  /* R6.6 the key colours: Math Flash's own looks, dark (MF R62a) */
  --lkUnmet: #4a4f5a; --lkGetting: #e9973f; --lkRelaxed: #2f7d8c; --lkSteady: #2fae7e; --lkQuick: #7fd36a; --lkSnap: #f6e27a;
  --lkInk: #0b1226; --lkInkUnmet: #e6ecf7;
  /* R6.5 the fingers, as a school chart colours them */
  --fPinky: #6b4f9e; --fRing: #3f6aa0; --fMiddle: #3f8a6a; --fIndex: #a07a2e; --fThumb: #5a6478; --fInk: #f4f7fb;
}
:root[data-theme="light"] {
  --bg: #eef3fb;
  --bg2: #d9e2f1;
  --ink: #0e1730;
  --inkDim: #3f4f6b;
  --line: #a9b7cf;
  --accent: #0369a1;
  --accentInk: #ffffff;
  --sel: #c3d4ee;
  --skyBg: #1a2747;
  --wordInk: #ffffff;
  --wordDone: #86efac;
  --wordLock: #fde68a;
  --shade: rgba(238, 243, 251, 0.9);
  --toastBg: #0e1730;
  --toastInk: #ffffff;
  --danger: #b91c1c;
  --lkUnmet: #a2adb7; --lkGetting: #cb7b19; --lkRelaxed: #158076; --lkSteady: #15ac6f; --lkQuick: #88c060; --lkSnap: #f7bf12;
  --lkInk: #0e1730; --lkInkUnmet: #0e1730;
  --fPinky: #d9c9f3; --fRing: #c7dbf5; --fMiddle: #c6ead9; --fIndex: #f1ddb0; --fThumb: #dfe4ec; --fInk: #0e1730;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: linear-gradient(180deg, var(--bg) 0%, var(--bg2) 100%);
  color: var(--ink); user-select: none; -webkit-user-select: none; overflow: hidden;
}
#app { height: 100%; display: flex; flex-direction: column; max-width: min(100%, 900px); margin: 0 auto; }

#hdr { display: flex; align-items: center; gap: 8px; padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top)); }
#hdr .pill { background: var(--bg2); border: 2px solid var(--line); border-radius: 999px; padding: 6px 11px; font-weight: 800; font-size: 15px; min-width: 44px; min-height: 44px; display: flex; align-items: center; cursor: pointer; justify-content: center; color: inherit; font-family: inherit; }
#hdrHome { border: none; background: var(--accent); color: var(--accentInk); font-size: 18px; }
#hdrStatus { flex: 1; min-width: 0; text-align: center; font-weight: 800; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--inkDim); }

.scr { flex: 1; display: none; flex-direction: column; overflow-y: auto; padding: 6px 14px 18px; gap: 10px; }
.scr.on { display: flex; }
.scrTitle { color: var(--ink); font-size: 22px; }

#scr-menu { align-items: center; text-align: center; justify-content: center; }
#scr-menu h1 { font-size: clamp(32px, 9vw, 46px); color: var(--ink); }
#scr-menu .sub { color: var(--inkDim); font-weight: 600; }
.menuGrid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; width: 100%; }
button.big { width: 100%; border-radius: 16px; min-height: 52px; font-size: 18px; font-weight: 800; background: var(--bg2); color: var(--ink); border: 3px solid var(--line); cursor: pointer; font-family: inherit; padding: 6px 10px; }
button.big:active { transform: translateY(2px); }
button.big.primary { background: var(--accent); border-color: var(--accent); color: var(--accentInk); }
button.big.danger { border-color: var(--danger); color: var(--danger); min-height: 52px; }
button.big[hidden] { display: none; }
#statsLine { color: var(--inkDim); font-weight: 700; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; width: 100%; }
.seg button { flex: 1; min-height: 44px; min-width: 64px; border-radius: 12px; border: 3px solid var(--line); background: var(--bg); color: var(--ink); font: 800 15px inherit; cursor: pointer; }
.seg button.sel { border-color: var(--accent); background: var(--sel); }

/* missions */
#missionGrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.mission { min-height: 64px; border-radius: 14px; border: 3px solid var(--line); background: var(--bg2); color: var(--ink); font-family: inherit; cursor: pointer; display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; gap: 0 8px; padding: 8px 10px; text-align: left; align-items: center; }
.mission .mn { grid-row: 1 / span 2; font-size: 22px; font-weight: 900; color: var(--accent); }
.mission .mt { font-weight: 800; font-size: 15px; }
.mission .ms { font-size: 13px; min-height: 16px; }
.mission.locked { opacity: 0.5; cursor: default; }

/* play */
#playTop { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-weight: 800; font-size: 15px; min-height: 22px; }
#lvlLabel { color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
#shieldOut { white-space: nowrap; letter-spacing: 2px; }
#accOut { color: var(--inkDim); white-space: nowrap; }
#stageWrap { flex: 1; position: relative; min-height: 0; border-radius: 12px; overflow: hidden; background: var(--skyBg); }
canvas#stage { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
/* R6.2 the words: page text over the sky, crisp at any detail */
#labels .word { position: absolute; transform: translate(-50%, 0); font: 800 clamp(20px, 5.4vw, 30px)/1 ui-monospace, "SF Mono", Menlo, monospace; color: var(--wordInk); white-space: nowrap; pointer-events: none;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.85), 0 0 2px rgba(0, 0, 0, 0.9); padding: 2px 4px; border-radius: 6px; }
#labels .word b { color: var(--wordDone); font-weight: 800; }
#labels .word.lock { color: var(--wordLock); outline: 2px solid var(--wordLock); outline-offset: 2px; }
#labels .word i { font-style: normal; color: var(--wordLock); margin-left: 4px; }
#labels .word i[hidden] { display: none; }
#count { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 72px; font-weight: 900; color: #ffffff; text-shadow: 0 4px 16px rgba(0, 0, 0, 0.6); pointer-events: none; }
#calm, #tapType { position: absolute; left: 50%; top: 40%; transform: translate(-50%, -50%); background: var(--shade); color: var(--ink); font-weight: 900; font-size: 22px; padding: 10px 18px; border-radius: 14px; pointer-events: none; }
#calm[hidden], #tapType[hidden] { display: none; }
#glFail { position: absolute; inset: 16px; display: flex; align-items: center; justify-content: center; text-align: center; font-weight: 800; font-size: 16px; line-height: 1.5; color: #ffffff; }
#glFail[hidden] { display: none; }
#fpsNow { position: absolute; left: 6px; bottom: 6px; font: 11px/1.3 ui-monospace, monospace; color: #c9d3df; background: rgba(5, 9, 20, 0.8); padding: 2px 6px; border-radius: 6px; pointer-events: none; }
#fpsNow[hidden] { display: none; }
#nextLine { text-align: center; font-weight: 800; color: var(--inkDim); min-height: 20px; font-size: 15px; }
/* the text field the screen keyboard types into: on the page but out of sight */
#thumbIn { position: absolute; left: 0; bottom: 0; width: 1px; height: 1px; opacity: 0.01; font-size: 16px; border: 0; padding: 0; pointer-events: none; }
body.thumbs #guide { display: none; }

/* the keyboard pictures: the guide in play, My keyboard */
.kb { display: flex; flex-direction: column; gap: 4px; width: 100%; max-width: 640px; margin: 0 auto; }
.kbRow { display: flex; gap: 4px; }
/* R2.7 a computer's number pad: three across, 7 8 9 on top */
.kb.pad { max-width: 240px; }
.kb.pad .k { flex: 0 0 calc((100% - 2 * 4px) / 3); min-height: 44px; }
.k { flex: 0 0 calc((100% - 10 * 4px) / 11 * 0.92); min-height: 34px; border-radius: 7px; display: flex; align-items: center; justify-content: center; font: 800 16px/1 ui-monospace, Menlo, monospace; border: 2px solid transparent; }
.k.space { flex: 0 0 52%; margin-left: 22%; font-size: 12px; }
.k.next { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent); }
.f-pinky { background: var(--fPinky); color: var(--fInk); } .f-ring { background: var(--fRing); color: var(--fInk); }
.f-middle { background: var(--fMiddle); color: var(--fInk); } .f-index { background: var(--fIndex); color: var(--fInk); }
.f-thumb { background: var(--fThumb); color: var(--fInk); } .f-none { background: var(--bg2); color: var(--inkDim); }
.look-unmet { background: var(--lkUnmet); color: var(--lkInkUnmet); } .look-getting { background: var(--lkGetting); color: var(--lkInk); }
.look-relaxed { background: var(--lkRelaxed); color: #ffffff; } .look-steady { background: var(--lkSteady); color: var(--lkInk); }
.look-quick { background: var(--lkQuick); color: var(--lkInk); } .look-snap { background: var(--lkSnap); color: var(--lkInk); }
.look-space { background: var(--bg2); color: var(--inkDim); }
#keysNote { color: var(--inkDim); font-weight: 600; font-size: 14px; }

/* the Test tab */
#testText { background: var(--bg2); border: 3px solid var(--line); border-radius: 14px; padding: 14px; font: 600 clamp(18px, 4.6vw, 24px)/1.6 ui-monospace, Menlo, monospace; min-height: 120px; overflow-wrap: anywhere; }
#testText .done { color: var(--wordDone); }
:root[data-theme="light"] #testText .done { color: #15803d; }
#testText .cur { background: var(--sel); color: var(--ink); border-bottom: 3px solid var(--accent); border-radius: 4px 4px 0 0; padding: 0 2px; }
#testText .rest { color: var(--inkDim); }
#testInfo { font-weight: 800; color: var(--inkDim); text-align: center; min-height: 20px; }

/* settings, help */
#scr-set .card, #scr-how .card { background: var(--bg2); border: 3px solid var(--line); border-radius: 16px; padding: 14px; display: flex; flex-direction: column; gap: 12px; font-size: 15px; line-height: 1.55; font-weight: 600; }
#scr-set h2, #scr-how h2 { color: var(--ink); }
.setRow { display: flex; flex-direction: column; gap: 6px; font-size: 15px; }
.setNote { font: 12.5px/1.4 ui-monospace, monospace; color: var(--inkDim); }
.lgSub { font-weight: 800; font-size: 13.5px; color: var(--inkDim); }
.legend { display: flex; flex-direction: column; gap: 6px; }
.lgRow { display: flex; align-items: center; gap: 10px; }
.lgRow .k.sw { flex: 0 0 34px; min-height: 22px; }
.lgRow b { font-size: 14px; font-weight: 800; }

.ovl { position: absolute; inset: 0; display: none; align-items: flex-start; justify-content: center; background: var(--shade); border-radius: 12px; padding: 16px; overflow-y: auto; overscroll-behavior: contain; }
.ovl.on { display: flex; }
.ovlCard { text-align: center; width: 100%; max-width: 320px; display: flex; flex-direction: column; gap: 10px; margin: auto; }
#ovlTitle { font-size: 26px; font-weight: 800; color: var(--ink); }
#ovlStars { font-size: 28px; min-height: 8px; font-weight: 800; color: var(--ink); }
#ovlSub, #ovlKeys { color: var(--inkDim); font-weight: 700; }
/* the way back to Spell Flash (R11) beside Menu, so a short sky shows every button */
.ovlRow { display: flex; gap: 10px; }
.ovlRow > button { flex: 1 1 0; min-width: 0; }

#toast { position: fixed; left: 50%; bottom: 78px; transform: translateX(-50%); background: var(--toastBg); color: var(--toastInk); font-weight: 800; padding: 9px 16px; border-radius: 999px; opacity: 0; transition: opacity 0.25s; pointer-events: none; z-index: 40; max-width: 90vw; text-align: center; }
#toast.on { opacity: 1; }
/* R9.2 a lasting note while a write has not gone in (the toast says it once; this stays until a save goes in) */
#saveNote { position: fixed; left: 50%; top: 8px; transform: translateX(-50%); background: var(--toastBg); color: var(--toastInk); font-weight: 800; font-size: 14px; padding: 8px 14px; border-radius: 12px; pointer-events: none; z-index: 41; max-width: 90vw; text-align: center; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3); }
#saveNote[hidden] { display: none; }

/* docs/offline-pwa.md R-C15 — the page never scrolls; each screen does */
html, body { overflow: hidden; overscroll-behavior: none; }
.scr { overscroll-behavior: contain; }
button.big:disabled { opacity: 0.45; cursor: default; }
