/* #279: 44px is the tap floor Apple and Google both publish, and the
   header pill (Home / Mute / Help) is the one control on every screen of
   every product. Measured before this: 31.6px to 42px across 12 products.
   Raised to the floor rather than to taste. */
/* Fusion — presentation only. The board is a canvas: every tile is drawn from
   data.js's rung arithmetic, so nothing in here knows what a tile is worth. */

:root {
  --bg: #0f172a;
  --panel: #1e293b;
  --line: #334155;
  --ink: #e2e8f0;
  --dim: #94a3b8;
  --accent: #38bdf8;
  --gold: #fbbf24;

  /* R18: the board is dark and an EMPTY CELL is the darkest thing on it. No
     tile is ever black — a black tile would read as a hole, which is exactly
     the misreading this palette has to avoid. */
  --felt: #0b1220;
  /* The empty-cell plate, and it is a MEASURED value rather than a taste.
     A coloured numeral sits directly on it (R14b), so it has to be dark
     enough for the darkest face to clear 4.5:1 — #16233a put red at 4.18:1
     and this puts it at 4.53:1 — while staying light enough to draw the grid
     against the felt. The whole usable band is about four hex points wide. */
  --hole: #131c2e;
  --edge: #e2e8f0;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg); color: var(--ink);
  font: 400 16px/1.45 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  overflow: hidden; overscroll-behavior: none;
}

#app { height: 100%; display: flex; flex-direction: column; }
.scr { display: none; flex: 1; min-height: 0; flex-direction: column; }
.scr.on { display: flex; }

#scr-menu, #scr-how, #scr-win {
  overflow-y: auto;
  padding: max(16px, env(safe-area-inset-top)) 16px calc(28px + env(safe-area-inset-bottom));
  align-items: stretch;
}

h1 { font-size: 30px; margin: 8px 0 2px; text-align: center; }
h2 { font-size: 17px; margin: 0 0 6px; }
.sub { text-align: center; color: var(--dim); margin-bottom: 16px; }

/* ---- buttons ---- */

.big {
  display: block; width: 100%; margin: 8px 0; padding: 14px 16px;
  font: 600 16px/1 inherit; color: var(--ink);
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  cursor: pointer; text-align: center; text-decoration: none;
  -webkit-appearance: none; appearance: none; touch-action: manipulation;
}
.big.primary { background: var(--accent); color: #04233a; border-color: transparent; }
.big:active { transform: translateY(1px); }

.btn {
  padding: 9px 12px; min-height: 44px; font: 600 14px/1 inherit; color: var(--ink);
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  cursor: pointer; -webkit-appearance: none; appearance: none;
  touch-action: manipulation;
}
/* R-C22a: DISABLED, never hidden. A control that vanishes teaches a child it
   was never there. */
.btn:disabled { opacity: .38; cursor: default; }

.pill {
  padding: 8px 10px; min-width: 44px; min-height: 44px;
  font: 600 14px/1 inherit; color: var(--ink);
  background: rgba(255, 255, 255, .06); border: 1px solid var(--line);
  border-radius: 10px; cursor: pointer; white-space: nowrap;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  -webkit-appearance: none; appearance: none; touch-action: manipulation;
}

/* ---- the rungs and the modes ---- */

#tierRow, #modeRow { display: flex; gap: 8px; margin-bottom: 4px; }
#modeRow { margin-top: 10px; }
.tierBtn {
  flex: 1; padding: 12px 6px; border-radius: 12px; cursor: pointer;
  background: var(--panel); border: 1px solid var(--line); color: var(--ink);
  font: 600 13px/1.2 inherit; text-align: center; min-height: 44px;
  -webkit-appearance: none; appearance: none; touch-action: manipulation;
}
.tierBtn .te { display: block; font-size: 18px; line-height: 1.1; }
.tierBtn small { display: block; font-weight: 400; font-size: 11px; color: var(--dim); margin-top: 3px; }
.tierBtn[aria-checked="true"] { border-color: var(--accent); background: #10344a; }

/* ---- settings ---- */

details#custom {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; margin: 8px 0; padding: 0 14px;
}
details#custom summary {
  padding: 14px 0; font-weight: 600; cursor: pointer; list-style: none;
  display: flex; align-items: center; gap: 8px;
}
details#custom summary::-webkit-details-marker { display: none; }
.badge {
  margin-left: auto; font: 400 12px/1 inherit; color: var(--dim);
  max-width: 60%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.fields { padding-bottom: 12px; }
.field { display: flex; align-items: center; gap: 10px; margin: 10px 0; min-height: 44px; }
.field .lbl { flex: 0 0 92px; font-size: 13px; color: var(--dim); }
.hint { font-size: 12px; color: var(--dim); margin: 10px 0 0; }
#statsLine { text-align: center; font-size: 12px; color: var(--dim); margin-top: 14px; }

/* R25's goal slider. The readout is a fixed column so the row does not jog
   sideways as "512" becomes "131,072". */
.slideRow { display: flex; flex: 1; align-items: center; gap: 10px; min-width: 0; }
.slideRow input[type=range] {
  flex: 1 1 auto; min-width: 0; height: 44px;
  accent-color: var(--accent); background: none; border: 0; padding: 0;
  cursor: pointer; touch-action: manipulation;
}
.slideVal {
  flex: 0 0 66px; text-align: right; font-size: 13px; color: var(--edge);
  font-variant-numeric: tabular-nums;
}

/* A setting inside the panel. The chosen one is marked by BACKGROUND AND
   WEIGHT, never by hue alone. */
.seg { display: flex; flex: 1; gap: 6px; min-width: 0; }
/* R14a's eight positions do not fit across a phone in one row at the 44px
   floor, so they WRAP — one radiogroup, two lines, still one control. The
   label goes above rather than beside it, or the row would be 92px narrower
   than it needs to be. */
.field.stack { display: block; }
.field.stack .lbl { display: block; margin-bottom: 8px; }
.seg.wrap { flex-wrap: wrap; }
.seg.wrap .segBtn { flex: 1 1 18%; min-width: 62px; }
.segBtn {
  flex: 1 1 0; min-width: 0; min-height: 44px; border-radius: 10px; cursor: pointer;
  background: rgba(0, 0, 0, .24); border: 2px solid rgba(255, 255, 255, .13);
  color: var(--ink); font: inherit; font-size: 14px; font-weight: 700;
  -webkit-appearance: none; appearance: none; touch-action: manipulation;
}
.segBtn.on { background: var(--accent); border-color: #fff; color: #04233a; font-weight: 900; }
.segBtn:disabled { opacity: .35; cursor: default; }

/* ---- play ---- */

#hdr {
  flex: 0 0 auto; display: flex; gap: 6px; align-items: center;
  padding: max(6px, env(safe-area-inset-top)) 8px 6px;
  border-bottom: 1px solid var(--line); background: var(--bg);
}
#hdrTitle {
  flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; font-weight: 700; font-size: 15px;
}
#hdr .pill { min-width: 44px; min-height: 44px; font-size: 17px; }

#bar {
  display: flex; gap: 6px; align-items: center;
  padding: 6px 8px; border-bottom: 1px solid var(--line); background: var(--bg);
}
#barSpace { flex: 1; min-width: 0; }
/* R-C19: a number the player watches change gets tabular figures, or the pill
   beside it slides sideways on every merge. */
#hudScore, #hudBest, #hudTop { font-variant-numeric: tabular-nums; }
#hudScore { font-weight: 800; min-width: 62px; }
#hudTop { color: #04233a; background: var(--edge); border-color: transparent; font-weight: 800; }
#hudNext .nextLbl { font-weight: 400; font-size: 11px; color: var(--dim); }
#hudTop .topArt {
  width: 18px; height: 18px; border-radius: 50%; display: block;
  background: var(--m, var(--edge));
}
#hudNext .nextArt {
  width: 18px; height: 18px; border-radius: 50%; display: block;
  background: var(--m, var(--edge));
}

/* R-C16, the shared shape: the count is a badge OVERLAID on the bulb, never
   text beside it, or the row reflows every time it falls. */
.hintBtn { position: relative; overflow: visible; }
.hintBtn .bulb { position: relative; display: inline-block; line-height: 1; }
.hintBtn .hintN {
  position: absolute; right: -9px; bottom: -6px;
  min-width: 16px; height: 16px; padding: 0 3px; border-radius: 999px;
  background: #0f172a; color: #f8fafc; box-shadow: 0 0 0 1.5px rgba(255, 255, 255, .6);
  font: 800 10px/16px inherit; letter-spacing: 0; pointer-events: none;
}
.hintBtn:disabled .hintN, .hintBtn[disabled] .hintN { background: #64748b; }
.pill:disabled { opacity: .38; cursor: default; }
/* The playbook's rule for an automation control: it stays LIT throughout, and
   the human's action buttons go inert beside it, which is also what stops a
   tap and a timer resolving the same move. */
#watchBtn.on { background: var(--accent); color: #04233a; border-color: transparent; }

#stageWrap {
  flex: 1; min-height: 0; position: relative; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  background: var(--felt);
}
#cv { touch-action: none; display: block; }

/* R-C24: named furniture below the play surface, so the shared stylesheet can
   reserve the version chip's corner for it. */
#pad {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
}
/* R-C19. This line sits BESIDE the buttons and is a SIBLING of #stageWrap, so
   if it wraps the pad grows and the whole board re-lays out. It gained a
   third button in v1.5 and immediately started wrapping to two lines at
   375px. It may never wrap: it truncates instead, and the row keeps one
   height for ever. */
#playHint {
  flex: 1 1 0; min-width: 0; font-size: 12px; color: var(--dim);
  text-align: right; white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis;
}

/* ---- cards ---- */

.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 14px; margin: 8px 0; font-size: 14px;
}
.card.win { text-align: center; }
#winArt { font-size: 34px; letter-spacing: 4px; min-height: 40px; }
#winBest { color: var(--gold); font-weight: 600; margin-top: 8px; min-height: 20px; }
/* A result carries its evidence (#173). */
.evid { text-align: left; font-size: 13px; color: var(--dim); margin-top: 10px; }
.evid .row { display: flex; justify-content: space-between; gap: 12px; padding: 3px 0; }
.evid .row b { color: var(--ink); }

/* ---- the legend (docs/offline-games-pwa.md R-L1) ---- */
.lgSub { font-weight: 600; font-size: 13px; color: var(--dim); margin: 10px 0 6px; }
.legend { display: flex; flex-direction: column; gap: 8px; }
.lgRow { display: flex; align-items: center; gap: 10px; }
.lgArt { flex: none; width: 44px; height: 24px; display: flex; align-items: center;
         justify-content: center; font-style: normal; }
.lgArt.lg-circle::after { content: ''; width: 20px; height: 20px; border-radius: 50%; background: var(--m); }
.lgArt.lg-square::after { content: ''; width: 18px; height: 18px; border-radius: 3px; background: var(--m); }
.lgArt.lg-tri::after {
  content: ''; width: 0; height: 0;
  border-left: 11px solid transparent; border-right: 11px solid transparent;
  border-bottom: 19px solid var(--m);
}
.lgArt.lg-ring::after {
  content: ''; width: 20px; height: 20px; border-radius: 50%;
  background: var(--m); box-shadow: inset 0 0 0 2px var(--felt);
  outline: 3px solid var(--m); outline-offset: -7px;
}
.lgArt.lg-hole::after { content: ''; width: 22px; height: 22px; border-radius: 5px; background: var(--hole); }
.lgArt.lg-ramp::after {
  content: ''; width: 34px; height: 18px;
  background: linear-gradient(90deg, var(--m) 0 33%, transparent 33% 100%);
  border-bottom: 2px solid var(--m);
}
.lgTxt { display: flex; flex-direction: column; min-width: 0; }
.lgTxt b { font-weight: 700; }
.lgTxt small { font-size: 12.5px; color: var(--dim); line-height: 1.35; }

/* ---- toast ---- */
#toast {
  position: fixed; left: 50%; bottom: calc(64px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(12px);
  background: #0b1220; border: 1px solid var(--line); color: var(--ink);
  padding: 10px 14px; border-radius: 10px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .18s, transform .18s;
  z-index: 50; max-width: calc(100vw - 32px); text-align: center;
}
#toast.on { opacity: 1; transform: translateX(-50%) translateY(0); }

/* R-C21: cap the column and CENTRE it. A capped flex item under
   align-items:stretch falls back to flex-start, which is invisible on a phone
   and wrong on every other screen. */
@media (min-width: 720px) {
  #scr-menu, #scr-how, #scr-win { max-width: 560px; margin-inline: auto; width: 100%; }
}

/* #228: a landscape window under 500px tall must not spend a 44px row on the
   version chip. The board is square and simply gets whatever is left. */
@media (orientation: landscape) and (max-height: 500px) and (min-width: 600px) {
  #app { position: relative; }
  #footer { position: absolute; right: 0; bottom: 0;
            padding-bottom: env(safe-area-inset-bottom); }
  /* R-C19: #pad is a SIBLING of #stageWrap, so hiding it would resize the
     board the moment the phone turned. It keeps its box and gets tighter. */
  #pad { padding: 3px 10px 4px; }
}
