* { 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, #312e81 0%, #4338ca 60%, #312e81 100%);
  color: #eef2ff; user-select: none; -webkit-user-select: none;
  touch-action: none; overflow: hidden;
}
#app { height: 100%; display: flex; flex-direction: column; max-width: min(100%, 860px); 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: rgba(0,0,0,0.24); border: 2px solid rgba(255,255,255,0.14); 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: #312e81; 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: #c7d2fe; }

.scr { flex: 1; display: none; flex-direction: column; overflow-y: auto; padding: 6px 14px 18px; }
/* The field gets the full width — the cell size divides whatever is left, so
   padding here comes straight off every square. Menu and help keep theirs. */
#scr-play { padding: 6px 4px 6px; }
.scr.on { display: flex; }

#scr-menu { align-items: center; text-align: center; gap: 12px; justify-content: center; }
#scr-menu h1 { font-size: clamp(30px, 8.5vw, 44px); color: #f8fafc; }
#scr-menu .sub { color: #c7d2fe; font-weight: 600; margin-bottom: 4px; }
#tierRow { display: flex; gap: 8px; width: 100%; }
.tierCard { flex: 1; background: rgba(0,0,0,0.22); border: 3px solid rgba(255,255,255,0.13); border-radius: 16px; padding: 10px 4px; font-weight: 800; font-size: 14px; line-height: 1.35; cursor: pointer; color: #eef2ff; font-family: inherit; }
.tierCard small { display: block; color: #c7d2fe; font-weight: 700; font-size: 11.5px; }
.tierCard .te { font-size: 26px; display: block; }
.tierCard.sel { border-color: #f59e0b; background: rgba(245,158,11,0.14); }
/* Settings, behind a disclosure. Same shape as every other game so a player
   who has met one has met them all (docs/offline-pwa.md R-C17). This whole
   block was MISSING when the game shipped: the markup was right, the JS was
   right, and with no rules behind it the panel rendered as browser-default
   buttons at min-height 0 — under the 44px touch floor, with no selected
   state at all, because grey-on-grey is what a UA button looks like. */
#custom { width: 100%; margin: 2px 0; text-align: left; background: rgba(0,0,0,0.2); border: 3px solid rgba(255,255,255,0.13); border-radius: 16px; padding: 6px 12px 10px; }
#custom > summary { list-style: none; cursor: pointer; font-weight: 800; font-size: 16px; padding: 10px 2px; min-height: 44px; display: flex; align-items: center; gap: 8px; }
#custom > summary::-webkit-details-marker { display: none; }
#custom > summary::before { content: "\25B8"; transition: transform .12s; }
#custom[open] > summary::before { transform: rotate(90deg); }
.field { display: flex; align-items: center; gap: 10px; margin: 7px 0; }
.field .lbl { flex: 0 0 104px; font-size: 13.5px; font-weight: 800; color: #c7d2fe; }
.seg { flex: 1; display: flex; gap: 6px; }
.seg button { flex: 1; min-height: 44px; border-radius: 11px; border: 2px solid rgba(255,255,255,0.16); background: rgba(0,0,0,0.24); color: #eef2ff; font-family: inherit; font-weight: 800; font-size: 13.5px; cursor: pointer; padding: 4px 2px; }
.seg button.on { background: #f59e0b; border-color: #d97706; color: #312e81; min-height: 44px;}
#optNote, .blurb { font-size: 12.5px; line-height: 1.45; color: #c7d2fe; font-weight: 600; margin: 8px 2px 2px; }

button.big { width: 100%; border-radius: 16px; min-height: 56px; font-size: 19px; font-weight: 800; background: rgba(0,0,0,0.22); color: #eef2ff; border: 3px solid rgba(255,255,255,0.13); cursor: pointer; font-family: inherit; }
button.big:active { transform: translateY(2px); }
button.big.primary { background: #f59e0b; border-color: #d97706; color: #312e81; min-height: 44px;}
#statsLine { color: #c7d2fe; font-weight: 700; font-size: 13px; }

/* play */
#playTop { display: flex; align-items: center; justify-content: space-between; font-weight: 800; padding: 2px 6px 6px; font-size: 16px; min-height: 22px; }
#timeOut { color: #e0e7ff; font-variant-numeric: tabular-nums; }

#stageWrap { flex: 1; position: relative; min-height: 0; }

/* R-C21 pause veil. R-C15b: flex-start + margin:auto, never align-items:center
   on a box that can scroll. */
#pauseVeil {
  position: absolute; inset: 0; z-index: 25;
  display: flex; align-items: flex-start; justify-content: center;
  padding: 18px; overflow-y: auto;
  background: rgba(6, 14, 30, .74);
  backdrop-filter: blur(2px);
}
#pauseVeil[hidden] { display: none; }
#pauseCard {
  margin: auto; text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  width: 100%; max-width: 330px;
  background: var(--panel, #16213a); border: 2px solid var(--line, #2b3d63);
  border-radius: 18px; padding: 20px;
}
#pauseCard .big { width: 100%; }
.pauseTitle { font-size: 1.25rem; font-weight: 800; }
.pauseSub { color: var(--muted, #9fb0d0); font-size: .92rem; }
canvas#stage { display: block; touch-action: none; }

/* The board is not generated until the first tap, because the no-guess proof
   is a proof FROM that opening square. This line is what makes that visible
   rather than feeling like a dead tap. */

#pad { flex: none; display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 8px 4px max(4px, env(safe-area-inset-bottom)); }
.pb { min-height: 54px; border-radius: 14px; background: rgba(0,0,0,0.24); border: 3px solid rgba(255,255,255,0.13); color: #eef2ff; font-size: 20px; font-weight: 800; font-family: inherit; cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; touch-action: manipulation; }
.pb span { font-size: 11px; font-weight: 800; color: #c7d2fe; }
.pb:active { transform: translateY(2px); }
/* The mode button is the one control whose STATE matters, so it looks
   different in each state rather than only saying so in words. */

.ovl { position: absolute; inset: 0; display: none; align-items: flex-start; justify-content: center; background: rgba(2,6,23,0.9); border-radius: 12px; 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; color: #f8fafc; }
#ovlSub { color: #c7d2fe; font-weight: 700; min-height: 22px; line-height: 1.45; }

#scr-how .card { background: rgba(0,0,0,0.22); border: 3px solid rgba(255,255,255,0.12); 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 (R-L1). The number swatches are generated from the same NUM
   table the board paints with, so a recoloured number cannot leave a stale
   swatch behind here. */
.lgSub { font-weight: 800; font-size: 13.5px; color: #c7d2fe; margin: 10px 0 5px; }
.legend { display: flex; flex-direction: column; gap: 6px; }
.lgRow { display: flex; align-items: center; gap: 10px; }
.lgArt { flex: none; width: 42px; display: flex; align-items: center; justify-content: center; }

.lgRing { width: 28px; height: 28px; border-radius: 3px; background: #64748b; box-shadow: inset 0 0 0 3px #38bdf8; display: inline-block; }

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

#toast { position: fixed; left: 50%; bottom: 86px; transform: translateX(-50%); background: #f8fafc; color: #0f172a; font-weight: 800; padding: 10px 16px; border-radius: 14px; opacity: 0; transition: opacity 0.25s; pointer-events: none; z-index: 40; max-width: calc(100vw - 28px); text-align: center; line-height: 1.35; }
#toast.on { opacity: 1; }

/* docs/offline-pwa.md R-C15 — the PAGE must never scroll. */
html, body { overflow: hidden; overscroll-behavior: none; }
.scr { overscroll-behavior: contain; }

/* --- match three only ----------------------------------------------------- */
#playTop { font-size: 15px; }
#scoreOut { color: #fbbf24; font-variant-numeric: tabular-nums; font-weight: 800; }
#levelOut { color: #c7d2fe; }
#timeOut { color: #eef2ff; font-variant-numeric: tabular-nums; }
#pad { grid-template-columns: repeat(2, 1fr); }

.lgGem { font-size: 26px; line-height: 1; }
.lgRing { width: 28px; height: 28px; border-radius: 4px; background: rgba(255,255,255,0.08); display: inline-block; }
.lgRing.white { box-shadow: inset 0 0 0 3px #ffffff; }
.lgRing.gold { box-shadow: inset 0 0 0 3px #fbbf24; }
.lgChain { display: inline-flex; align-items: center; justify-content: center; min-width: 30px; height: 26px;
           border-radius: 7px; background: #fbbf24; color: #312e81; font-weight: 800; font-size: 13px; }

/* The "+2s" that floats over the clock when a swap earns time.
   Absolutely positioned against #playTop, so it is not a layout participant
   (R-C19). It is a SIBLING of #timeOut and not a child, because paintHud()
   sets #timeOut.textContent every frame and that deletes anything nested
   inside it — which is exactly what the first version did, silently.

   AND IT HANGS BELOW THE ROW, NOT ABOVE IT. `top: -13px` put it thirteen
   pixels above #playTop — which is where #hdr is. The chip was drawn behind
   the header on every single swap, so the one visible signal that the clock
   rule exists shipped invisible. There was no space above; there is space
   below, over the top of the board, and it rises from there as it fades. */
#playTop { position: relative; }
#timeGain { position: absolute; right: 4px; top: calc(100% - 2px);
            font-size: 13px; font-weight: 800; color: #052e16;
            background: #4ade80; border-radius: 999px; padding: 1px 8px;
            box-shadow: 0 2px 8px rgba(0,0,0,0.35);
            white-space: nowrap; z-index: 5;
            opacity: 0; transform: translateY(-4px);
            transition: opacity .15s, transform .25s; pointer-events: none; }
#timeGain.on { opacity: 1; transform: translateY(0); }
