* { 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, #0f172a 0%, #1e293b 100%);
  color: #e2e8f0; user-select: none; -webkit-user-select: none;
  touch-action: none; overflow: hidden;
}
#app { height: 100%; display: flex; flex-direction: column; max-width: min(100%, 820px); 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: #1e293b; border: 2px solid #334155; 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: #f59e0b; color: #0f172a; 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: #94a3b8; }

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

#scr-menu { align-items: center; text-align: center; gap: 12px; justify-content: center; }
#scr-menu h1 { font-size: clamp(32px, 9vw, 44px); color: #f8fafc; }
#scr-menu .sub { color: #94a3b8; font-weight: 600; margin-bottom: 4px; }
#tierRow { display: flex; gap: 8px; width: 100%; }
.tierCard { flex: 1; background: #1e293b; border: 3px solid #334155; border-radius: 16px; padding: 10px 4px; font-weight: 800; font-size: 14px; line-height: 1.35; cursor: pointer; color: #e2e8f0; }
.tierCard small { display: block; color: #94a3b8; font-weight: 700; }
.tierCard .te { font-size: 26px; display: block; }
.tierCard.sel { border-color: #f59e0b; background: #422006; }
button.big { width: 100%; border-radius: 16px; min-height: 56px; font-size: 19px; font-weight: 800; background: #1e293b; color: #e2e8f0; border: 3px solid #334155; cursor: pointer; font-family: inherit; }
button.big:active { transform: translateY(2px); }
button.big.primary { background: #f59e0b; border-color: #d97706; color: #0f172a; min-height: 44px;}
#statsLine { color: #94a3b8; font-weight: 700; }

/* play */
#playTop { position: relative; display: flex; align-items: center; justify-content: space-between; font-weight: 800; padding: 2px 2px 6px; font-size: 15px; min-height: 22px; }
#linesOut { position: absolute; left: 50%; transform: translateX(-50%); white-space: nowrap; pointer-events: none; color: #94a3b8; }
#lvlLabel, #score { white-space: nowrap; }
#lvlLabel { color: #a5b4fc; }
#score { color: #fbbf24; }

/* The trays. A fixed height so the canvas below never resizes when a wide
   piece replaces a narrow one -- a well that jumps by a few pixels every lock
   is the reserved-slot lesson from Diner Rush's status line. */
#trays { flex: none; display: flex; align-items: center; gap: 12px; height: 46px; margin-bottom: 4px; }
.tray { display: flex; align-items: center; gap: 7px; min-width: 0; }
.tray.tnext { margin-left: auto; }
.tray b { font-size: 11px; font-weight: 800; letter-spacing: 0.06em; color: #64748b; }
.slot { display: flex; align-items: center; gap: 9px; min-height: 30px; }
.slot .pv { display: grid; gap: 1px; }
.slot .pv i { width: 9px; height: 9px; border-radius: 2px; }
.slot .pv i.on { box-shadow: inset 0 2px 0 rgba(255,255,255,0.3), inset 0 -2px 0 rgba(0,0,0,0.25); }
/* A used-up keep slot is greyed, not emptied: an empty box and a spent box
   mean different things and must not look the same. */
.slot.spent { opacity: 0.35; }
.slot.empty::after { content: '—'; color: #475569; font-weight: 800; }

#stageWrap { flex: 1; position: relative; display: flex; align-items: center; justify-content: center; min-height: 0; }
canvas#stage { display: block; background: #020617; border-radius: 12px; box-shadow: 0 0 0 3px #1e293b; touch-action: none; }

/* The control pad. A readout that grows and a tap target that cannot shrink
   must not share a row (docs/offline-pwa.md) -- so the score line above is its
   own row and the pad is its own grid, sized in fractions of the width with a
   hard 48px floor on height. */
/* TWO THUMB CLUSTERS, not one row of six.

   The first pad was four equal columns across the full width: ◀ ⟳ ▶ 🅿️ over
   ▼ ⤓. Three things were wrong with it on a phone, and all three are about
   where thumbs actually are rather than about how the row looks.

     - The two most-used controls, ◀ and ▶, were SPLIT BY ⟳. Moving a piece
       left then right meant crossing the rotate key every time.
     - 🅿️ sat next to ▶. It is the rarest control and the most expensive to
       hit by accident — it takes your piece away.
     - Everything was equidistant from the middle of the screen, which is the
       one place a thumb does not rest.

   Now: movement under the LEFT thumb, rotate and hard-drop under the RIGHT,
   and the hold key exiled to a narrow strip between them where neither thumb
   travels. 58px rather than 52 — this is a game played at speed, and the 44px
   floor is a floor, not a target. */
#pad { flex: none; display: grid;
       grid-template-columns: 1fr 1fr 0.5fr 1.25fr;
       grid-template-rows: auto auto; gap: 8px;
       padding: 10px 0 max(4px, env(safe-area-inset-bottom)); }
.pb { min-height: 58px; border-radius: 14px; background: #1e293b; border: 3px solid #334155; color: #e2e8f0; font-size: 24px; font-weight: 800; font-family: inherit; cursor: pointer; display: flex; align-items: center; justify-content: center; touch-action: manipulation; -webkit-user-select: none; user-select: none; }
.pb:active { transform: translateY(2px); background: #334155; }
#bLeft  { grid-column: 1; grid-row: 1; }
#bRight { grid-column: 2; grid-row: 1; }
#bDown  { grid-column: 1 / span 2; grid-row: 2; }
#bRot   { grid-column: 4; grid-row: 1; }
#bSlam  { grid-column: 4; grid-row: 2; }
/* Narrow, dimmer, and out of both thumbs' way. Still a 44px target. */
#bHold  { grid-column: 3; grid-row: 1 / span 2; font-size: 19px; opacity: 0.78;
          background: #172033; border-color: #263449; }

/* A wide screen has room to put the clusters where the hands are rather than
   stretching them across a metre of desk. */
@media (min-width: 560px) {
  #pad { max-width: 520px; margin: 0 auto; }
}
#bSlam { background: #422006; border-color: #b45309; color: #fcd34d; }

.ovl { position: absolute; inset: 0; display: none; align-items: flex-start; justify-content: center; background: rgba(2,6,23,0.86); border-radius: 12px; padding: 16px; overflow-y: auto; overscroll-behavior: contain;}
.ovl.on { display: flex; }
.ovlCard { text-align: center; width: 100%; max-width: 300px; display: flex; flex-direction: column; gap: 10px; margin: auto;}
#ovlTitle { font-size: 26px; font-weight: 800; color: #f8fafc; }
#ovlSub { color: #94a3b8; font-weight: 700; min-height: 22px; }

#scr-how .card { background: #1e293b; border: 3px solid #334155; border-radius: 16px; padding: 14px; margin-bottom: 10px; font-size: 15px; line-height: 1.55; font-weight: 600; }
#scr-how h2 { margin-bottom: 8px; color: #f8fafc; }

/* The legend (docs/offline-games-pwa.md R-L1). Same row shape as the other
   games' -- one column of swatches at a fixed width, so the eye can run the
   column instead of the text. Piece colours come from data.js, never from
   here: a palette retuned in the data must not need a stylesheet edit to stay
   honest. */
.lgSub { font-weight: 800; font-size: 13.5px; color: #94a3b8; margin: 10px 0 5px; }
.legend { display: flex; flex-direction: column; gap: 7px; }
.lgRow { display: flex; align-items: center; gap: 10px; }
.lgArt { flex: none; width: 46px; height: 30px; display: flex; align-items: center; justify-content: center; font-style: normal; position: relative; }
/* A shape swatch is a real mini-grid of the piece's own cells, drawn from
   pieceCells() -- not an emoji standing in for it. A picture of the thing. */
.lg-shape { display: grid; gap: 1px; }
.lg-shape i { width: 6px; height: 6px; border-radius: 1px; }
.lg-shape i.on { box-shadow: inset 0 2px 0 rgba(255,255,255,0.3), inset 0 -2px 0 rgba(0,0,0,0.25); }

/* The four marks. Each is drawn, not described: a legend whose swatch is the
   word "dotted" explains nothing. */
.lg-guide { width: 26px; height: 20px; border: 2px dashed #f59e0b; border-radius: 3px; }
.lg-next { display: flex; gap: 3px; align-items: center; }
/* Indigo, matching the O piece. The old violet here outlived the palette
   change that removed it -- a legend swatch in a colour the game no longer
   paints is a small lie in the one place that exists to stop lies. */
.lg-next i { width: 8px; height: 8px; border-radius: 2px; background: #4f46e5; }
.lg-next i:nth-child(2) { opacity: 0.6; }
.lg-next i:nth-child(3) { opacity: 0.3; }
.lg-hold { width: 26px; height: 20px; border: 2px solid #64748b; border-radius: 4px; background: #0f172a; display: flex; align-items: center; justify-content: center; font-size: 11px; }
.lg-danger { width: 34px; height: 20px; border-top: 3px dashed #ef4444; display: flex; align-items: flex-end; justify-content: center; }
.lg-danger i { width: 26px; height: 7px; background: #475569; border-radius: 2px; }

.lgTxt { display: flex; flex-direction: column; min-width: 0; }
.lgTxt b { font-size: 14px; font-weight: 800; }
.lgTxt small { font-size: 12.5px; color: #94a3b8; line-height: 1.3; font-weight: 600; }

#toast { position: fixed; left: 50%; bottom: 78px; transform: translateX(-50%); background: #f8fafc; color: #0f172a; font-weight: 800; padding: 9px 16px; border-radius: 999px; opacity: 0; transition: opacity 0.25s; pointer-events: none; z-index: 40; }
#toast.on { opacity: 1; }

/* docs/offline-pwa.md R-C15 — the PAGE must never scroll. The product is a
   fixed frame: header, a named scroll region, footer. If the document scrolls
   too, the header scrolls away and a drag that reaches the end of the inner
   region chains out and drags the whole board under the player's thumb. */
html, body { overflow: hidden; overscroll-behavior: none; }
.scr { overscroll-behavior: contain; }
