:root {
  /* Puzzle Box, the dark look; the light look is chosen with the switch beside Home */
  --bg: #1d1a2b;
  --bg2: #2a2640;
  --ink: #f3f0ff;
  --inkDim: #bab3d6;
  --line: #4a446c;
  /* the house amber (game-ui-colour §2): filled on Play and Continue only */
  --accent: #ffb338;
  --accentBorder: #ffd27a;
  --accentInk: #3a2204;
  --sel: #3a3458;
  --shade: rgba(20, 18, 31, 0.92);
  --toastBg: #f6f4ff;
  --toastInk: #1d1a2b;
  --bad: #ff6b5b;
  --good: #6fd38b;
  /* the boards: wood, a hole in it, a peg, a ring round a hole a peg can jump to */
  --wood: #6b4a2a;
  --hole: #2b1d10;
  --peg: #5aa9ff;
  --pegInk: #0b2a4d;
  --hint: #c9f6ff;
  --tileBg: #efe6d2;
  --tileInk: #2b1d10;
  --gap: #14121f;
}
:root[data-theme="light"] {
  --bg: #f1eee6;
  --bg2: #e2dccd;
  --ink: #1d1a2b;
  --inkDim: #4d4766;
  --line: #a99f86;
  --accent: #a26a00;
  --accentBorder: #a26a00;
  --accentInk: #ffffff;
  --sel: #d3cbb6;
  --shade: rgba(241, 238, 230, 0.94);
  --toastBg: #1d1a2b;
  --toastInk: #ffffff;
  --bad: #b91c1c;
  --good: #157f3c;
  --wood: #c99a62;
  --hole: #5a3b1c;
  --peg: #1f6fd1;
  --pegInk: #ffffff;
  --hint: #0b5f73;
  --tileBg: #fffaf0;
  --tileInk: #2b1d10;
  --gap: #b8ad93;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
button { touch-action: manipulation; }
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; -webkit-touch-callout: 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; }
#saveNote { 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; }
#hdrHome { 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 14px; gap: 10px; position: relative; }
.scr.on { display: flex; }

#scr-menu { align-items: stretch; text-align: center; }
#scr-menu h1 { font-size: clamp(30px, 9vw, 42px); color: var(--ink); }
#scr-menu .sub { color: var(--inkDim); font-weight: 600; max-width: 34ch; margin: 0 auto; }
/* R5.1 a tile for each puzzle: its picks, its record, then Continue and Play */
.tile { background: var(--bg2); border: 3px solid var(--line); border-radius: 18px; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.tile h2 { font-size: 20px; }
.rec { color: var(--inkDim); font-weight: 700; font-size: 14px; min-height: 20px; }
.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; }
.tile button.big { background: var(--bg); }
button.big:active { transform: translateY(2px); }
button.big.primary, .tile button.big.primary { background: var(--accent); border-color: var(--accentBorder); color: var(--accentInk); }
button.big[hidden] { display: none; }
button.big:disabled { opacity: 0.45; cursor: default; }
/* Start over armed (the shared controller adds `danger`) */
button.big.danger { border-color: var(--bad); color: var(--bad); min-height: 44px; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; width: 100%; }
.seg button { flex: 1; min-height: 44px; min-width: 44px; border-radius: 12px; border: 3px solid var(--line); background: var(--bg); color: var(--ink); font-family: inherit; font-weight: 800; font-size: 15px; cursor: pointer; padding: 0 4px; }
.seg button.sel { border-color: var(--ink); background: var(--sel); }

/* play: R6.2 three fixed tracks of one height, whatever their numbers say */
#scr-play { padding-left: 6px; padding-right: 6px; }
#statRow { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; padding: 0 8px; }
.stat { background: var(--bg2); border-radius: 12px; padding: 4px 6px; text-align: center; display: flex; flex-direction: column; justify-content: space-between; min-width: 0; height: 64px; }
.stat small { font-size: 12px; line-height: 1.1; font-weight: 700; color: var(--inkDim); overflow: hidden; }
.stat b { font-size: 20px; font-weight: 900; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#boardWrap { flex: 1; min-height: 200px; overflow: auto; display: flex; align-items: safe center; justify-content: safe center; touch-action: manipulation; }
#board { position: relative; flex: none; }
#sayLine { text-align: center; font-weight: 800; font-size: 16px; min-height: 22px; }
#tools { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 0 8px max(0px, env(safe-area-inset-bottom)); }
#btnRestart.armed { border-color: var(--bad); color: var(--bad); }

/* R1 Peg Solitaire: a wooden board, a hole in it, a blue peg in a hole */
#board.b-peg { background: var(--wood); border-radius: 22px; }
.hole { position: absolute; min-width: 44px; min-height: 44px; border: none; background: transparent; padding: 0; cursor: pointer; display: flex; align-items: center; justify-content: center; font-family: inherit; color: inherit; }
.hole::before { content: ""; position: absolute; width: 46%; height: 46%; border-radius: 50%; background: var(--hole); box-shadow: inset 0 3px 4px rgba(0, 0, 0, 0.45); }
.pegdot { position: relative; width: 64%; height: 64%; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #ffffff 0 12%, var(--peg) 34%); box-shadow: 0 3px 4px rgba(0, 0, 0, 0.45); }
/* the picked peg is lifted and ringed, never filled; a hole it can jump to is ringed */
.hole.sel .pegdot { transform: translateY(-4px); box-shadow: 0 0 0 3px var(--ink), 0 6px 7px rgba(0, 0, 0, 0.45); }
.hole.to::after { content: ""; position: absolute; width: 62%; height: 62%; border-radius: 50%; box-shadow: 0 0 0 3px var(--hint), 0 0 10px var(--hint); }
.hole:focus-visible { outline: 3px solid var(--ink); outline-offset: -2px; border-radius: 50%; }

/* R2 Tower of Hanoi: three pegs, each one tall button; a disc's width says its size */
.peg { position: absolute; border: 3px solid transparent; border-radius: 14px; background: transparent; padding: 0; cursor: pointer; font-family: inherit; color: inherit; min-width: 44px; min-height: 44px; }
.peg.sel { border-color: var(--ink); background: var(--sel); }
.peg:focus-visible { outline: 3px solid var(--ink); outline-offset: -3px; }
.rod { position: absolute; left: 50%; bottom: 4px; top: 22px; width: 10px; margin-left: -5px; border-radius: 5px; background: var(--wood); }
.rod::after { content: ""; position: absolute; left: -40px; right: -40px; bottom: -4px; height: 6px; border-radius: 3px; background: var(--wood); }
.goal { position: absolute; top: 0; left: 0; right: 0; text-align: center; font-size: 16px; }
.disc { position: absolute; left: 50%; transform: translateX(-50%); height: 24px; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-weight: 900; font-size: 13px; box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.2), 0 2px 2px rgba(0, 0, 0, 0.3); }
.disc.up { transform: translateX(-50%) translateY(-18px); box-shadow: 0 0 0 3px var(--ink), 0 6px 6px rgba(0, 0, 0, 0.35); }
/* lint:runtime disc1 disc2 disc3 disc4 disc5 disc6 disc7 */
.disc1 { background: #f2a46b; color: #3d1d05; }
.disc2 { background: #f3d35b; color: #3a2e00; }
.disc3 { background: #9fd18b; color: #173a10; }
.disc4 { background: #5fb7a8; color: #062a25; }
.disc5 { background: #7f9cec; color: #0b1636; }
.disc6 { background: #c9a0e0; color: #2c1340; }
.disc7 { background: #e58c8c; color: #3d0f0f; }

/* R3 Sliding Tiles: square tiles; a tile in its own place has a green edge; the gap is a dark hole */
#board.b-slide { background: var(--gap); border-radius: 14px; }
#board .sq { position: absolute; border: 3px solid var(--line); border-radius: 12px; background: var(--tileBg); color: var(--tileInk); font-family: inherit; font-weight: 900; cursor: pointer; padding: 0; min-width: 44px; min-height: 44px; box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.12); }
#board .sq.home { border-color: var(--good); }
/* a tile in the gap's row or column: it can slide */
#board .sq.line { box-shadow: inset 0 -5px 0 rgba(0, 0, 0, 0.22); }
#board .sq.gap { background: transparent; border-color: transparent; box-shadow: none; cursor: default; }
#board .sq:focus-visible { outline: 3px solid var(--ink); outline-offset: -5px; }

/* 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: 10px; font-size: 15px; line-height: 1.55; font-weight: 600; }
.setNote { font-size: 13.5px; color: var(--inkDim); }

.ovl { position: absolute; inset: 0; display: none; align-items: flex-start; justify-content: center; background: var(--shade); 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; }
#ovlSub { color: var(--inkDim); font-weight: 700; }

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

/* a short phone (under 700 px tall): the gaps give way before the boards do */
@media (max-height: 700px) {
  #hdr { padding-top: max(4px, env(safe-area-inset-top)); padding-bottom: 4px; }
  #scr-play { gap: 6px; padding-bottom: 8px; }
  .stat { height: 60px; }
}

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