/* Flock Rush — ice theme.
   Verified at 320x568, 375x812 and 820x1180 per the playbook. */
:root {
  --bg: #071726;
  --panel: #0e2338;
  --panel-2: #143050;
  --line: #1e3c5c;
  --ink: #e8f4ff;
  --muted: #90b2cc;
  --accent: #38bdf8;
  --accent-ink: #04222f;
  --gain: #22c55e;
  --gain-ink: #052e16;
  --loss: #9f1239;
  --loss-ink: #ffe4e6;
  --gold: #fbbf24;
  --tap: 44px;
  --r: 14px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0;
  height: 100vh;          /* Safari < 15.4 has no dvh; this MUST come first */
  height: 100dvh;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overscroll-behavior: none;
}
body { display: flex; flex-direction: column; }

/* ---------------- header ---------------- */
.hdr {
  flex: none; display: flex; align-items: center; gap: 8px;
  padding: 6px 10px; padding-top: max(6px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--line); background: var(--panel);
}
.ttl {
  flex: 1; margin: 0; text-align: center; font-size: 1.05rem; letter-spacing: .01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0;
}
.ico {
  min-width: var(--tap); min-height: var(--tap);
  display: inline-flex; align-items: center; justify-content: center;
  background: none; border: 0; color: var(--ink); font-size: 1.15rem; cursor: pointer;
  border-radius: 10px;
}
.ico:active { background: var(--panel-2); }

/* ---------------- screens ---------------- */
.scr { display: none; flex: 1; min-height: 0; flex-direction: column; padding: 12px; gap: 10px;
       overflow-y: auto; width: 100%; max-width: 820px; margin: 0 auto; }
.scr.on { display: flex; }
#scr-play { padding: 6px 8px 8px; gap: 6px; overflow: hidden; }

.lead { margin: 0; color: var(--muted); font-size: .92rem; line-height: 1.45; }
h2 { margin: 0 0 4px; font-size: 1.15rem; }

.grp { display: flex; flex-direction: column; gap: 6px; }
.grp-lbl { font-size: .74rem; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; color: var(--muted); }

/* Fluid so three cards never wrap at 320px (the yahtzee lesson). */
.picks { display: flex; gap: 8px; flex-wrap: nowrap; }
.pick {
  flex: 1 1 0; min-width: 0;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 10px 6px; border-radius: var(--r); cursor: pointer;
  background: var(--panel); border: 2px solid var(--line); color: var(--ink);
  font-family: inherit; text-align: center;
}
.pick .te { font-size: 1.35rem; line-height: 1.1; }
.pick b { font-size: clamp(.82rem, 3.4vw, .95rem); }
.pick small { font-size: clamp(.6rem, 2.5vw, .7rem); color: var(--muted); line-height: 1.25; }
.pick.sel { border-color: var(--accent); background: var(--panel-2); }
.pick.sel small { color: #bfe4f7; }

.stats { font-size: .84rem; color: var(--muted); text-align: center; min-height: 1.2em; }

/* ---------------- crew ---------------- */
.crew-list { display: flex; flex-direction: column; gap: 8px; }
.crew {
  display: flex; align-items: center; gap: 12px; text-align: left;
  padding: 10px 12px; border-radius: var(--r); cursor: pointer;
  background: var(--panel); border: 2px solid var(--line); color: var(--ink);
  font-family: inherit; min-height: var(--tap); width: 100%;
}
.crew .te { font-size: 1.5rem; flex: none; width: 30px; text-align: center; }
.crew .txt { flex: 1; min-width: 0; }
.crew b { display: block; font-size: .95rem; }
.crew small { display: block; font-size: .72rem; color: var(--muted); }
.crew .tick { flex: none; font-size: .95rem; color: var(--accent); font-weight: 800; }
.crew.sel { border-color: var(--accent); background: var(--panel-2); }
/* Locked entries stay legible: a child needs to read what to DO, so this
   dims the row without hiding the requirement (that is the whole point). */
.crew.locked { cursor: default; opacity: .72; }
.crew.locked b { color: var(--muted); }
.crew.locked small { color: var(--gold); }

.menu-btns { display: flex; flex-direction: column; gap: 8px; margin-top: auto; padding-top: 6px; }
.btn {
  min-height: var(--tap); padding: 0 16px; border-radius: 12px; cursor: pointer;
  font-size: 1rem; font-weight: 700; font-family: inherit;
  background: var(--panel); border: 2px solid var(--line); color: var(--ink);
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); font-weight: 600; }
.btn.block { width: 100%; }
.btn:active { transform: scale(.985); }

.how { margin: 0; padding-left: 18px; color: var(--muted); font-size: .9rem; line-height: 1.55; }
.how li { margin-bottom: 7px; }
.how b { color: var(--ink); }

/* ---------------- legend (on the PLAY screen, not only in How to play) ---- */
.legend { flex: none; display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }
.chip {
  font-size: .7rem; font-weight: 800; padding: 3px 9px; border-radius: 999px;
  border: 1px solid transparent; white-space: nowrap;
}
.chip.gain { background: var(--gain); color: var(--gain-ink); }
.chip.loss { background: var(--loss); color: var(--loss-ink); }
.chip.hint { background: #1e3a5f; color: var(--gold); border-color: var(--gold); }
.chip.rival { background: var(--panel-2); color: var(--ink); border-color: var(--line); }
.chip.fish { background: #7c2d12; color: #ffedd5; }
.chip.ice  { background: #0c4a6e; color: #e0f2fe; }

/* ---------------- play ---------------- */
.hud { flex: none; display: flex; align-items: center; gap: 8px; }
.hud-i {
  flex: 1 1 0; min-width: 0; font-size: .8rem; font-weight: 700; color: var(--muted);
  /* Reserved space: HUD text changes every frame and MUST NOT reflow the field. */
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; height: 1.3em; line-height: 1.3em;
}
.hud-i:last-child { text-align: right; }
.hud-i.flock { text-align: center; color: var(--ink); font-size: .95rem; font-variant-numeric: tabular-nums; }

.stage-wrap { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; }
/* Matches the sky's top stop, so the rounded corners and any sub-pixel gap
   read as part of the scene rather than as a seam. */
#stage { display: block; touch-action: none; border-radius: var(--r); background: #061020; }

/* ---------------- overlay ---------------- */
/* Closes only via its own buttons — never on an outside tap, so a finished run
   can never strand the player on a dead field (the yahtzee lesson). */
.ovl {
  position: fixed; inset: 0; z-index: 50; display: none;
  align-items: center; justify-content: center; padding: 18px;
  background: rgba(3, 12, 22, .78);
}
.ovl.on { display: flex; }
.ovl-card {
  width: 100%; max-width: 360px; background: var(--panel); border: 2px solid var(--line);
  border-radius: 18px; padding: 20px; text-align: center;
}
.ovl-card h2 { margin: 0 0 8px; font-size: 1.3rem; }
.ovl-card p { margin: 0 0 16px; color: var(--muted); white-space: pre-line; line-height: 1.5; }
.ovl-btns { display: flex; flex-direction: column; gap: 8px; }

/* ---------------- toast ---------------- */
.toast-host {
  position: fixed; top: 0; left: 0; right: 0; z-index: 60;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: calc(8px + env(safe-area-inset-top)) 12px 0; pointer-events: none;
}
.toast {
  pointer-events: auto; max-width: 90%; background: var(--panel-2); color: var(--ink);
  border: 1px solid var(--line); border-radius: 12px; padding: 9px 14px;
  font-size: .88rem; font-weight: 600; box-shadow: 0 8px 24px rgba(0,0,0,.4);
  opacity: 0; transform: translateY(-8px); transition: opacity .18s ease, transform .18s ease;
}
.toast.in { opacity: 1; transform: none; }
.toast.gold { border-color: var(--gold); color: var(--gold); }

@media (prefers-reduced-motion: reduce) {
  .toast { transition: none; }
  .btn:active { transform: none; }
}
