:root {
  /* Tangram, the dark look; the light look is chosen with the switch beside Home */
  --bg: #161a24;
  --bg2: #222838;
  --ink: #f1f4fa;
  --inkDim: #a9b2c6;
  --line: #3a4258;
  /* the house amber (game-ui-colour §2): filled on Play and Continue only */
  --accent: #ffb338;
  --accentBorder: #ffd27a;
  --accentInk: #3a2204;
  --shade: rgba(14, 17, 25, 0.9);
  --toastBg: #f1f4fa;
  --toastInk: #161a24;
  --bad: #ff6b5b;
  --good: #6fd38b;
  /* R9.1 the board: the picture to fill, the tray, the outline of the picked piece */
  --sil: #5d6680;
  --tray: #1d2230;
  --edge: rgba(0, 0, 0, 0.45);
  /* R9.2 the seven pieces, each its own colour (content, not chrome) */
  --p0: #e8574e;
  --p1: #4a8ff0;
  --p2: #f2c94c;
  --p3: #3fbf6a;
  --p4: #a970ee;
  --p5: #f39236;
  --p6: #ef6aae;
}
:root[data-theme="light"] {
  --bg: #eef1f6;
  --bg2: #dde3ee;
  --ink: #161a24;
  --inkDim: #3d4659;
  --line: #a4aec4;
  --accent: #a26a00;
  --accentBorder: #a26a00;
  --accentInk: #ffffff;
  --shade: rgba(238, 241, 246, 0.94);
  --toastBg: #161a24;
  --toastInk: #ffffff;
  --bad: #b91c1c;
  --good: #157f3c;
  --sil: #8c95aa;
  --tray: #e3e8f1;
  --edge: rgba(0, 0, 0, 0.4);
  --p0: #d9443b;
  --p1: #2f74dc;
  --p2: #e8b923;
  --p3: #22a556;
  --p4: #9150dc;
  --p5: #ee7d1c;
  --p6: #e04f99;
}

* { 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: var(--bg); 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%, 760px); 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: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--inkDim); font-variant-numeric: tabular-nums; }

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

#scr-menu { align-items: center; text-align: center; justify-content: safe center; }
#scr-menu h1 { font-size: clamp(32px, 9vw, 46px); color: var(--ink); }
#scr-menu .sub { color: var(--inkDim); font-weight: 600; max-width: 34ch; }
#menuArt { width: 96px; height: 96px; }
.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(--accentBorder); color: var(--accentInk); }
button.big.danger { border-color: var(--bad); color: var(--bad); min-height: 52px; }
button.big[hidden] { display: none; }
button.big:disabled { opacity: 0.45; cursor: default; }
#statsLine { color: var(--inkDim); font-weight: 700; }

/* R5.3 the pictures, in three groups */
#pickList { display: flex; flex-direction: column; gap: 8px; }
.grpHead { font-size: 18px; font-weight: 800; margin-top: 4px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 8px; }
.tile { min-height: 104px; border-radius: 14px; border: 3px solid var(--line); background: var(--bg2); color: var(--ink); font-family: inherit; cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: 6px 4px; }
.tile .mini { width: 52px; height: 52px; }
.tileName { font-size: 12.5px; font-weight: 800; line-height: 1.15; max-width: 100%; overflow-wrap: anywhere; hyphens: auto; }
.tileBadge { font-size: 12px; font-weight: 800; color: var(--inkDim); min-height: 15px; font-variant-numeric: tabular-nums; }
.silp { fill: var(--sil); stroke: var(--sil); stroke-width: 1px; vector-effect: non-scaling-stroke; stroke-linejoin: round; }

/* play */
#scr-play { padding-bottom: 8px; gap: 6px; }
#boardWrap { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; overflow: hidden; }
#board { display: block; touch-action: none; -webkit-user-select: none; user-select: none; }
.trayBg { fill: var(--tray); }
/* R9.2 a piece: its colour, and a thin dark edge so two pieces side by side read as two */
.pc { stroke: var(--edge); stroke-width: 1px; vector-effect: non-scaling-stroke; stroke-linejoin: round; cursor: grab; }
.pc0 { fill: var(--p0); } .pc1 { fill: var(--p1); } .pc2 { fill: var(--p2); } .pc3 { fill: var(--p3); }
.pc4 { fill: var(--p4); } .pc5 { fill: var(--p5); } .pc6 { fill: var(--p6); }
/* R9.3 the picked piece is ringed, never filled with the accent */
.pc.sel { stroke: var(--ink); stroke-width: 3px; }
.pc.done { stroke: var(--edge); }
#say { text-align: center; font-weight: 800; font-size: 15px; min-height: 20px; }
#toolRow { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding-bottom: max(0px, env(safe-area-inset-bottom)); }
#toolRow button.big { min-height: 48px; }

/* 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: 24px; 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; }

/* R9.4 a short phone (360 x 640): the header and the gaps give way before the board does */
@media (max-height: 700px) {
  #hdr { padding-top: max(4px, env(safe-area-inset-top)); padding-bottom: 4px; }
  #scr-play { gap: 4px; padding-bottom: 6px; }
  #say { min-height: 18px; font-size: 14px; }
}

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