* { 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, #134e4a 0%, #0f766e 60%, #134e4a 100%);
  color: #f0fdfa; 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: #134e4a; 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: #99f6e4; }

.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: #99f6e4; 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: #f0fdfa; font-family: inherit; }
.tierCard small { display: block; color: #99f6e4; 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: #99f6e4; }
.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: #f0fdfa; font-family: inherit; font-weight: 800; font-size: 13.5px; cursor: pointer; padding: 4px 2px; }
.seg button.on { background: #f59e0b; border-color: #d97706; color: #134e4a; min-height: 44px;}
#optNote, .blurb { font-size: 12.5px; line-height: 1.45; color: #99f6e4; 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: #f0fdfa; 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: #134e4a; min-height: 44px;}
#statsLine { color: #99f6e4; 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; }
#minesOut { color: #fca5a5; }
#timeOut { color: #ccfbf1; font-variant-numeric: tabular-nums; }

#stageWrap { flex: 1; position: relative; min-height: 0; }
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. */
#note { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-weight: 800; color: #99f6e4; pointer-events: none; text-align: center; padding: 20px; font-size: 15px; }
#note:empty { display: none; }

#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: #f0fdfa; 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: #99f6e4; }
.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. */
#modeBtn.flagging { background: #7f1d1d; border-color: #dc2626; }
#modeBtn.flagging span { color: #fecaca; }

.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: #99f6e4; font-weight: 700; min-height: 22px; line-height: 1.45; }

/* The chain, rebuilt inside the result panel. The three columns are fixed so
   the words line up into one, which is what makes it readable as a chain
   rather than as a list. */
#ovlChain { display: flex; flex-direction: column; gap: 2px;
            max-height: 46vh; max-height: 46dvh;   /* R-C13 */
            overflow-y: auto; margin: 4px 0 2px; }
.wcRow { display: grid; grid-template-columns: 2.6em 1fr 3em; align-items: baseline;
         gap: 6px; padding: 3px 8px; border-radius: 8px; font-size: 15px;
         font-weight: 700; text-align: left; }
.wcRow .who { font-size: 11px; text-transform: uppercase; letter-spacing: 0.6px;
              color: rgba(255,255,255,0.45); }
.wcRow .wd { letter-spacing: 0.4px; }
.wcRow .pt { text-align: right; font-variant-numeric: tabular-nums; color: #5eead4; }
.wcRow.them { background: rgba(0,0,0,0.28); color: #ccfbf1; }
.wcRow.you { background: #0f766e; color: #f0fdfa; }
.wcRow.start { background: rgba(251,191,36,0.18); color: #fde68a; }
.wcRow.more { display: block; text-align: center; font-size: 12px; font-weight: 700;
              color: rgba(255,255,255,0.45); padding: 2px 0; }
.wcRow.total { border-top: 2px solid rgba(255,255,255,0.22); margin-top: 4px;
               padding-top: 6px; color: #f8fafc; font-weight: 800; font-size: 16px; }
.wcRow.total .pt { color: #fde68a; font-size: 18px; }

#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. */
.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; }

.lgTxt { display: flex; flex-direction: column; min-width: 0; }
.lgTxt b { font-size: 14px; font-weight: 800; }
.lgTxt small { font-size: 12.5px; color: #99f6e4; 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; }

/* --- word chain only ------------------------------------------------------ */
#playTop { font-size: 13px; gap: 8px; }
#scoreOut { color: #fbbf24; font-weight: 800; font-variant-numeric: tabular-nums; }
#needWrap { flex: 1; text-align: center; color: #99f6e4; font-weight: 700; }
#needWrap b { display: inline-block; min-width: 26px; font-size: 20px; color: #fbbf24; }
#timeOut { color: #f0fdfa; font-variant-numeric: tabular-nums; }

/* The chain is the named scroll region (R-C15): the PAGE never scrolls, this
   does. Newest word at the bottom, scrolled to. */
#chainWrap { flex: 1; position: relative; min-height: 0; display: flex; }

/* R-C21 pause veil. R-C15b: flex-start + margin:auto on anything scrollable. */
#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; }
#chain { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 8px 10px;
         display: flex; flex-direction: column; gap: 6px; }
.link { align-self: flex-start; max-width: 82%; padding: 8px 13px; border-radius: 14px;
        font-size: 19px; font-weight: 700; letter-spacing: 0.4px; }
.link.them { background: rgba(0,0,0,0.28); color: #ccfbf1; }
.link.you { align-self: flex-end; background: #0f766e; color: #f0fdfa; }
.link.start { align-self: center; background: rgba(251,191,36,0.18); color: #fde68a; }
/* The joining letters are marked in BOTH words, so the rule is visible in the
   chain itself and not only in the help. */
.link .j { color: #fbbf24; }

#pickRow { flex: none; display: none; flex-wrap: wrap; gap: 8px; justify-content: center;
           padding: 8px 6px max(4px, env(safe-area-inset-bottom)); }
#pickRow.on { display: flex; }
.pickBtn { min-height: 52px; padding: 0 16px; border-radius: 14px; font-family: inherit;
           font-weight: 800; font-size: 17px; cursor: pointer; color: #f0fdfa;
           background: rgba(0,0,0,0.26); border: 3px solid rgba(255,255,255,0.14); }
.pickBtn:active { transform: translateY(2px); }

#typeRow { flex: none; display: none; gap: 8px; padding: 8px 6px max(4px, env(safe-area-inset-bottom)); }
#typeRow.on { display: flex; }
#wordIn { flex: 1; min-width: 0; min-height: 52px; border-radius: 14px; padding: 0 14px;
          font-family: inherit; font-size: 18px; font-weight: 700; color: #f0fdfa;
          background: rgba(0,0,0,0.3); border: 3px solid rgba(255,255,255,0.16); }
#wordIn::placeholder { color: rgba(240,253,250,0.4); font-weight: 600; }
#typeRow .pb { flex: 0 0 60px; min-height: 52px; }

.lgLink { display: inline-block; padding: 4px 8px; border-radius: 9px; font-size: 13px; font-weight: 700; }
.lgLink.them { background: rgba(0,0,0,0.28); color: #ccfbf1; }
.lgLink.you { background: #0f766e; color: #f0fdfa; }
.lgLink .j { color: #fbbf24; }
.lgJ { color: #fbbf24; font-size: 22px; font-weight: 800; }
.lgNeed { color: #fbbf24; font-size: 24px; font-weight: 800; }
