:root {
  /* the night look (this product's own): a walnut frame and brass beads; the light look is chosen with the switch beside Home */
  --bg: #1d1810;
  --bg2: #2b2418;
  --ink: #f6eedd;
  --inkDim: #c2b394;
  --line: #4d4130;
  --accent: #e2a83a;
  --accentInk: #2c1a02;
  --wood: #6b4a26;
  --woodEdge: #3e2a14;
  --wire: #d9c9a3;
  --beadUp: #e2a83a;
  --beadUpEdge: #9a6a1c;
  --beadDown: #7a5a34;
  --beadDownEdge: #4f3920;
  --tapRod: rgba(226, 168, 58, 0.18);
  --shade: rgba(14, 12, 8, 0.88);
  --toastBg: #fbf6ea;
  --toastInk: #20180c;
  --danger: #f87171;
}
:root[data-theme="light"] {
  --bg: #f6efe2;
  --bg2: #ebe0cb;
  --ink: #241a0c;
  --inkDim: #5b4a30;
  --line: #bba783;
  --accent: #8a5a00;
  --accentInk: #ffffff;
  --wood: #9a6b3a;
  --woodEdge: #6d4a23;
  --wire: #f3e8cf;
  --beadUp: #d48f1c;
  --beadUpEdge: #8a5a00;
  --beadDown: #c9b48e;
  --beadDownEdge: #8c7a58;
  --tapRod: rgba(138, 90, 0, 0.16);
  --shade: rgba(246, 239, 226, 0.94);
  --toastBg: #241a0c;
  --toastInk: #ffffff;
  --danger: #b91c1c;
}

* { 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%, 720px); 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); }
#saveNote { flex: none; margin: 0 12px 6px; padding: 8px 12px; border-radius: 12px; background: var(--bg2); border: 2px solid var(--line); color: var(--ink); font-weight: 800; font-size: 14px; line-height: 1.4; text-align: center; }
#saveNote[hidden] { display: none; }

.scr { flex: 1; display: none; flex-direction: column; overflow-y: auto; padding: 6px 14px 14px; gap: 10px; position: relative; }
.scr.on { display: flex; }

#scr-menu { align-items: center; text-align: center; justify-content: center; }
#scr-menu h1 { font-size: clamp(30px, 8.5vw, 44px); 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); }
button.big:disabled { opacity: 0.45; cursor: default; }
#statsLine { color: var(--inkDim); font-weight: 700; }
.scrTitle { text-align: center; }

/* play: the number, the abacus, the machines */
/* R1.2c the readout opens the whole number; there it breaks only between groups, balanced */
#wholeNum { font: 900 22px/1.4 ui-monospace, Menlo, monospace; font-variant-numeric: tabular-nums; text-align: center; text-wrap: balance; word-break: keep-all; overflow-wrap: normal; }
#readout { cursor: pointer; text-align: center; display: flex; flex-direction: column; gap: 2px; container-type: inline-size; }
/* R1.2a the whole number on one line: it shrinks to fit the width instead of
   wrapping, down to 15px; a number too long for that (past about 10^27)
   wraps at 15px rather than shrinking past reading. --chars is its length
   (app.js); a monospace digit or comma is about 0.6 of the size wide. */
#numNow { font: 900 clamp(26px, 8vw, 40px)/1.1 ui-monospace, Menlo, monospace; font-size: max(15px, min(clamp(26px, 8vw, 40px), calc(100cqi / (var(--chars, 1) * 0.62)))); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
#numWords { font-weight: 800; font-size: clamp(15px, 4.4vw, 18px); color: var(--inkDim); min-height: 1.3em; }
/* R1.2b the rods line: rods reached of 101, thin like a reading app's */
#rodbar { height: 2px; width: 100%; background: var(--line); border-radius: 1px; overflow: hidden; }
#rodfill { display: block; height: 100%; width: 0; background: var(--inkDim); } /* not the accent: it is for the next thing to do (game-ui-colour) */
#numRate { font-weight: 700; font-size: 14px; color: var(--inkDim); min-height: 1.3em; }
#abacus { flex: none; width: 100%; height: clamp(190px, 36vh, 320px); height: clamp(190px, 36dvh, 320px); border: 0; padding: 0; background: none; cursor: pointer; touch-action: manipulation; font-family: inherit; color: inherit; }
#frame, #ggFrame { display: grid; gap: 2px; width: 100%; height: 100%; padding: 10px 10px 0; border: 10px solid var(--wood); border-bottom-width: 0; border-radius: 16px 16px 0 0; box-shadow: inset 0 0 0 2px var(--woodEdge); background: var(--bg2); }
.rod { position: relative; height: 100%; border-radius: 8px; }
.rod.tap { background: var(--tapRod); }
.rod .wire { position: absolute; left: 50%; top: 0; bottom: 30px; width: 3px; margin-left: -1.5px; background: var(--wire); border-radius: 2px; }
/* the beads sit in the space above the label: their top is a share of that space */
.rod .bead { position: absolute; left: 8%; right: 8%; height: calc((100% - 30px) * 0.062); max-height: 22px; border-radius: 999px; background: var(--beadDown); box-shadow: inset 0 -3px 0 var(--beadDownEdge); transition: top 0.12s ease-out, background 0.12s; transform: scaleY(1); }
.rod .bead.up { background: var(--beadUp); box-shadow: inset 0 -3px 0 var(--beadUpEdge); }
#frame.slow .rod .bead { transition: top 0.6s ease-in-out, background 0.6s; }
.rod .lbl { position: absolute; left: -4px; right: -4px; bottom: 0; height: 30px; display: flex; align-items: center; justify-content: center; font: 800 clamp(9px, 2.6vw, 12px)/1.05 ui-monospace, Menlo, monospace; white-space: pre-line; text-align: center; color: var(--accentInk); background: var(--wood); border-top: 2px solid var(--woodEdge); }
/* R13 the googol abacus: the same rods, to look at; the bar above stays, so a scroll to it clears the bar */
#ggBlock { flex: none; display: flex; flex-direction: column; gap: 10px; margin-top: 8px; scroll-margin-top: 68px; }
.ggTitle { margin: 0; text-align: center; font-size: 18px; }
#ggFrame { flex: none; height: 180px; }
/* R13.5 over the number, whose tap opens the same screen: nothing moves under a finger when it comes or goes */
#ggNote { position: absolute; top: 6px; left: 14px; right: 14px; width: auto; z-index: 2; margin: 0; min-height: 44px; padding: 6px 10px; font-size: 14px; line-height: 1.25; background: var(--bg2); }
.ggSay { text-align: center; font-weight: 800; font-size: 16px; }
#ggStats { display: flex; flex-direction: column; gap: 4px; }
#hint { text-align: center; font-weight: 800; font-size: clamp(14px, 4.2vw, 17px); min-height: 2.6em; color: var(--ink); }

/* the machines scroll in their own area, beneath the number, the abacus, the
   hint and the stars bar, which stay in view (the owner, 2026-10-25) */
#scr-play { overflow: hidden; }
#scr-play > * { flex: none; }
#machines { display: flex; flex-direction: column; gap: 6px; flex: 1 1 0; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
#machines > * { flex: none; }
.mrow { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; gap: 6px; background: var(--bg2); border: 2px solid var(--line); border-radius: 14px; padding: 4px 6px; }
.mrow.locked { display: block; padding: 12px; color: var(--inkDim); font-weight: 700; text-align: center; }
.mname { min-width: 0; min-height: 44px; display: flex; align-items: center; gap: 6px; background: none; border: 0; color: var(--ink); font-family: inherit; font-weight: 800; font-size: 15px; text-align: left; cursor: pointer; }
.mname .me { font-size: 22px; flex: none; }
.mname .mt { min-width: 0; display: flex; flex-direction: column; line-height: 1.2; }
.mname .mn { overflow-wrap: anywhere; }
.mname .my { font-size: 12px; font-weight: 700; color: var(--inkDim); }
.mown { font: 800 13px/1.25 ui-monospace, Menlo, monospace; color: var(--inkDim); min-width: 3.2em; text-align: right; white-space: pre-line; }
.mbuy { min-width: 92px; min-height: 44px; border-radius: 12px; border: 3px solid var(--accent); background: var(--bg); color: var(--ink); font: 800 15px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; cursor: pointer; }
.mbuy:disabled { background: none; color: var(--inkDim); border-color: var(--line); cursor: default; }
/* R8 the stars bar and a machine's upgrade */
.starbar[hidden] { display: none; }
.starbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 4px 6px; border: 2px dashed var(--line); border-radius: 14px; }
.shave { font-weight: 800; font-size: 16px; }
.sbuy { min-height: 44px; border-radius: 12px; border: 3px solid var(--accent); background: var(--bg); color: var(--ink); font: 800 14px -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; padding: 0 10px; cursor: pointer; }
/* R8.9 the five upgrades as a row of stars */
/* R10 a machine's switches and the abacus upgrades screen */
.mtog { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.mtog[hidden], .mtb[hidden] { display: none; }
.mtb { min-height: 44px; border-radius: 12px; border: 2px solid var(--line); background: var(--bg); color: var(--ink); font: 700 13px -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; cursor: pointer; }
/* R10.3 the 🧰 store: each upgrade a card, name and dots, now and next on their own lines, then its buttons */
.abar { position: sticky; top: 0; z-index: 1; background: var(--bg); padding: 8px 0; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
#abilHave { font-weight: 800; font-size: 15px; }
#abilBack { white-space: nowrap; flex: none; }
#abilRows { display: flex; flex-direction: column; gap: 10px; padding-bottom: 12px; }
.agroup { margin: 12px 2px 0; font-size: 15px; color: var(--inkDim); }
.arow { background: var(--bg2); border: 2px solid var(--line); border-radius: 14px; padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; }
.ahead { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.aname { font-weight: 800; font-size: 17px; }
.pips { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; font-weight: 800; font-size: 14px; color: var(--inkDim); }
.pip { width: 11px; height: 11px; border-radius: 50%; border: 2px solid var(--line); }
.pip.on { background: var(--ink); border-color: var(--ink); }
.atext { display: flex; flex-direction: column; gap: 2px; }
.atext:empty { display: none; }
.anow, .anext { margin: 0; font-size: 15px; line-height: 1.4; }
.anext { color: var(--inkDim); }
.aact { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.aact .sbuy { padding: 0 14px; }
.amax { font-weight: 800; color: var(--inkDim); }
/* R10.4 Off and the five levels: one row of six, or two of three on a narrow phone (6 x 44 px does not fit 320) */
.apick { display: grid; grid-template-columns: repeat(6, minmax(44px, 1fr)); gap: 6px; }
.apickl { grid-column: 1 / -1; font-size: 15px; font-weight: 700; }
.apick .tsw { min-width: 44px; padding: 0 4px; }
@media (max-width: 380px) { .apick { grid-template-columns: repeat(3, minmax(44px, 1fr)); } }
.aslide { display: grid; grid-template-columns: 44px minmax(0, 1fr) 44px; gap: 6px 8px; align-items: center; }
.aslide .tsw { min-width: 44px; padding: 0; font-size: 20px; }
.aslide .tsw:disabled { opacity: .45; cursor: default; }
.aslide input[type=range] { width: 100%; min-width: 0; height: 44px; margin: 0; accent-color: var(--accent); cursor: pointer; }
.tsw { min-height: 44px; min-width: 64px; border-radius: 22px; border: 2px solid var(--line); background: var(--bg); color: var(--inkDim); font: 800 14px -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; cursor: pointer; }
.tsw.on { color: var(--ink); border-color: var(--ink); }
.mups { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.mups[hidden] { display: none; }
.mupc { min-height: 44px; border-radius: 12px; border: 2px solid var(--line); background: var(--bg); color: var(--inkDim); font: 800 14px -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; padding: 0; cursor: pointer; }
.mupc.done { color: var(--ink); border-style: solid; }
.mupc.next, .mupc.short { color: var(--ink); border-style: dashed; }
.mupc.ready { color: var(--ink); border: 3px solid var(--accent); }
.sbuy:disabled, .sbuy.wait { background: none; color: var(--inkDim); border-color: var(--line); cursor: default; }
.mfact { grid-column: 1 / -1; font-size: 14px; line-height: 1.5; font-weight: 600; color: var(--inkDim); padding: 2px 4px 6px; }
.mfact[hidden] { display: none; }

/* away, firsts, settings, help */
/* centred by its margins: centred by justify-content, a card taller than the screen loses its top (R14) */
#scr-away > :first-child { margin-top: auto; }
#scr-away > :last-child { margin-bottom: auto; }
#scr-set .card, #scr-how .card, #scr-away .card { background: var(--bg2); border: 3px solid var(--line); border-radius: 16px; padding: 14px; display: flex; flex-direction: column; gap: 10px; font-size: 15px; line-height: 1.55; font-weight: 600; }
.aact.awake { justify-content: center; }
.setNote { font-size: 13.5px; color: var(--inkDim); text-align: center; }
#firstRows { display: flex; flex-direction: column; gap: 4px; }
.frow { display: grid; grid-template-columns: 4.2em minmax(0, 1fr) auto; gap: 8px; align-items: center; padding: 6px 10px; border-radius: 10px; background: var(--bg2); font-weight: 700; font-size: 15px; }
.frow .fk { font: 800 13px ui-monospace, Menlo, monospace; color: var(--accent); }
.frow .fn { min-width: 0; overflow-wrap: anywhere; }
.frow .fd { color: var(--inkDim); font-size: 13px; }
.frow.dim { opacity: 0.55; }

#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; }

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

@media (prefers-reduced-motion: reduce) {
  .rod .bead, #frame.slow .rod .bead { transition: none; }
}
@media (max-height: 640px) {
  #abacus { height: clamp(160px, 32vh, 240px); height: clamp(160px, 32dvh, 240px); }
  #numNow { font-size: 24px; font-size: max(15px, min(24px, calc(100cqi / (var(--chars, 1) * 0.62)))); }
}

/* R12 every rod's name: a card a name, one row a rod; its zeros go under the words, so the longest name fits unbroken at 320 px */
.ngroup { background: var(--bg2); border: 3px solid var(--line); border-radius: 16px; padding: 14px; display: flex; flex-direction: column; gap: 8px; font-size: 15px; line-height: 1.4; margin-bottom: 10px; }
.ngroup h3, .ngroup p { margin: 0; }
.nwritten { font: 700 13px/1.5 ui-monospace, Menlo, monospace; word-break: keep-all; overflow-wrap: normal; color: var(--inkDim); }
.nrow { display: grid; grid-template-columns: 4.2em minmax(0, 1fr); gap: 0 8px; align-items: baseline; padding: 6px 0 0; border-top: 1px solid var(--line); font-weight: 700; }
.nrow .nk { font: 800 13px ui-monospace, Menlo, monospace; color: var(--inkDim); }
.nrow .nw { min-width: 0; overflow-wrap: anywhere; }
.nrow .nz { grid-column: 2; color: var(--inkDim); font-size: 13.5px; font-weight: 600; white-space: nowrap; }
