/* =============================================================================
 * styles.css - UI laid OVER the 3D canvas
 * =============================================================================
 * Concerns:
 *  - Full-bleed canvas behind everything.
 *  - HTML game UI positioned on top (questions, answers, ladder, lifelines).
 *  - Lock the page so it never scrolls / rubber-bands during play (iOS).
 *  - Large, instantly-tappable controls; adapts to portrait & landscape.
 * ===========================================================================*/

:root {
  --teal: #1ad6c2;
  --blue: #2f6bff;
  --gold: #ffd34d;
  --green: #18e06a;
  --red: #ff3b4e;
  --panel: rgba(10, 16, 28, 0.82);
  --panel-solid: #0c1322;
  --stroke: rgba(120, 200, 220, 0.25);
  --text: #eaf3ff;
  --muted: #9fb3cc;
  --font: 'Segoe UI', system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
}

/* ---- Page lock: no scroll, no rubber-banding, no double-tap zoom --------- */
* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;          /* kill pull-to-refresh / bounce */
  background: #1e2a44;
  color: var(--text);
  font-family: var(--font);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  position: fixed;                    /* pin the page so it can't move */
  inset: 0;
  touch-action: none;                 /* we handle all gestures ourselves */
  user-select: none;
  -webkit-user-select: none;
}

#app { position: fixed; inset: 0; }

/* ---- The 3D canvas (and 2D fallback backdrop) --------------------------- */
#scene {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

/* When 3D can't run, paint a moody gradient instead of a black void. */
body.no-3d #scene { display: none; }
body.no-3d #app {
  background:
    radial-gradient(1200px 800px at 50% 120%, #14304a 0%, transparent 60%),
    radial-gradient(900px 700px at 15% -10%, #21155c 0%, transparent 55%),
    radial-gradient(900px 700px at 85% -10%, #062c3a 0%, transparent 55%),
    #05060a;
}

/* ---- HUD: the in-game layer over the canvas ----------------------------- */
#hud {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
  pointer-events: none;               /* let empty areas pass through */
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
           env(safe-area-inset-bottom) env(safe-area-inset-left);
}
#hud > * { pointer-events: auto; }
#hud.hidden,
.overlay.hidden,
.modal.hidden { display: none; }

/* Generic hide utility (covers the flag shop / reveal blocks too). */
.hidden { display: none !important; }

/* ---- Top bar: settings (right); hearts float centrally (below) ---------- */
#top-bar {
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 14px;
}

/* Help menu (hearts + lifelines) - central, in the question panel. */
#lifelines {
  display: flex;
  gap: 14px;
  pointer-events: auto;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  margin: 2px 0 12px;
}

.lifeline {
  -webkit-appearance: none;
  appearance: none;
  border: 1px solid var(--stroke);
  background: var(--panel);
  color: var(--text);
  border-radius: 50%;
  width: 66px;
  height: 66px;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.05;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  backdrop-filter: blur(6px);
  transition: transform .08s ease, box-shadow .15s ease, opacity .2s ease;
  touch-action: manipulation;
}
.lifeline .ll-ico { font-size: 24px; }
.lifeline:active { transform: scale(0.92); }
.lifeline.used,
.lifeline.disabled { opacity: 0.35; pointer-events: none; }
.lifeline.used::after {
  content: '✕';
  position: absolute;
  color: var(--red);
  font-size: 34px;
  font-weight: 900;
  text-shadow: 0 0 8px rgba(0,0,0,0.6);
}
.lifeline { position: relative; }

#settings { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

/* Hearts (lives) - sit AMONG the help menu (next to the lifelines). */
#hearts {
  display: flex;
  gap: 6px;
  align-items: center;
  pointer-events: auto;
  font-size: 26px;
  line-height: 1;
  padding: 8px 13px;
  background: var(--panel);
  border: 1px solid var(--stroke);
  border-radius: 999px;
  backdrop-filter: blur(6px);
}
.heart { transition: transform .25s ease; }
.heart.lost { opacity: 0.5; filter: grayscale(0.4); transform: scale(0.85); }

.chip {
  -webkit-appearance: none;
  appearance: none;
  border: 1px solid var(--stroke);
  background: var(--panel);
  color: var(--text);
  border-radius: 999px;
  padding: 9px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  backdrop-filter: blur(6px);
  touch-action: manipulation;
}
.chip:active { transform: scale(0.95); }

/* ---- Money ladder (right rail) ------------------------------------------ */
#ladder {
  position: absolute;
  top: 84px;
  right: 14px;
  width: 168px;
  max-height: calc(100% - 200px);
  overflow: hidden;                   /* shrink rows to fit; never scroll */
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 8px;
  background: var(--panel);
  border: 1px solid var(--stroke);
  border-radius: 14px;
  backdrop-filter: blur(6px);
  pointer-events: auto;
}
.ladder-row {
  display: flex;
  align-items: center;
  gap: 8px;
  /* Rows compress (font + padding scale with viewport height) so all 15 tiers
     always fit the rail without a scrollbar. */
  min-height: 0;
  padding: clamp(3px, 0.5vh, 6px) 8px;
  border-radius: 8px;
  font-size: clamp(11px, 1.45vh, 13px);
  font-weight: 600;
  color: var(--muted);
}
.ladder-row .ladder-num {
  width: 20px;
  text-align: center;
  font-size: 11px;
  opacity: 0.6;
}
.ladder-row .ladder-amount { margin-left: auto; }
.ladder-row.safe { color: #cfe9ff; }
.ladder-row.safe .ladder-amount { color: var(--teal); }
.ladder-row.passed { color: #5d7799; }
.ladder-row.current {
  background: linear-gradient(90deg, rgba(255,211,77,0.18), rgba(255,211,77,0.05));
  color: var(--gold);
  box-shadow: inset 0 0 0 1px rgba(255,211,77,0.55);
}
.ladder-row.current .ladder-amount { color: var(--gold); }
.ladder-row.top-flag {
  color: #d9ffe9;
  box-shadow: inset 0 0 0 1px rgba(24,224,106,0.5);
}
.ladder-row.top-flag .ladder-amount { color: var(--green); font-weight: 800; }

/* ---- Bottom: question panel --------------------------------------------- */
#question-panel {
  align-self: end;
  width: min(900px, 100%);
  margin: 0 auto;
  padding: 12px 16px 16px;
}

#prize-bar {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 16px;
  margin-bottom: 8px;
  font-weight: 700;
}
#prize-stake { color: var(--gold); font-size: 22px; }
#prize-safe { color: var(--teal); font-size: 13px; opacity: 0.9; }
#status-line {
  min-height: 18px;
  text-align: center;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--text);
  margin-bottom: 6px;
}

#question-text {
  text-align: center;
  font-size: clamp(16px, 2.4vw, 23px);
  font-weight: 600;
  line-height: 1.35;
  background: var(--panel);
  border: 1px solid var(--stroke);
  border-radius: 14px;
  padding: 14px 18px;
  margin-bottom: 12px;
  backdrop-filter: blur(6px);
}

#answers {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.answer {
  -webkit-appearance: none;
  appearance: none;
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
  border: 1px solid var(--stroke);
  background: var(--panel);
  color: var(--text);
  border-radius: 12px;
  padding: 14px 16px;
  font-size: clamp(14px, 1.8vw, 18px);
  font-weight: 600;
  cursor: pointer;
  min-height: 58px;
  backdrop-filter: blur(6px);
  transition: transform .08s ease, background .15s ease, box-shadow .15s ease;
  touch-action: manipulation;
}
.answer:active { transform: scale(0.98); }
.answer-letter {
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(47,107,255,0.25);
  border: 1px solid rgba(120,180,255,0.4);
  color: #cfe0ff;
  font-weight: 800;
  font-size: 14px;
}
.answer.selected {
  background: linear-gradient(90deg, rgba(255,211,77,0.22), rgba(255,211,77,0.08));
  box-shadow: inset 0 0 0 2px var(--gold);
}
.answer.pending { animation: pulse 0.7s ease-in-out infinite alternate; }
.answer.correct {
  background: linear-gradient(90deg, rgba(24,224,106,0.3), rgba(24,224,106,0.1));
  box-shadow: inset 0 0 0 2px var(--green);
}
.answer.wrong {
  background: linear-gradient(90deg, rgba(255,59,78,0.3), rgba(255,59,78,0.1));
  box-shadow: inset 0 0 0 2px var(--red);
}
.answer.removed { visibility: hidden; }    /* keep grid layout stable */
.answer.locked { pointer-events: none; }

@keyframes pulse {
  from { box-shadow: inset 0 0 0 2px var(--gold); }
  to   { box-shadow: inset 0 0 0 2px var(--gold), 0 0 22px rgba(255,211,77,0.6); }
}

/* ---- Controls: walk away + lock in -------------------------------------- */
#controls {
  display: flex;
  gap: 10px;
  margin-top: 12px;
  justify-content: center;
}
.ctrl {
  -webkit-appearance: none;
  appearance: none;
  border: none;
  border-radius: 12px;
  padding: 14px 22px;
  font-size: 16px;
  font-weight: 800;
  cursor: pointer;
  min-height: 52px;
  letter-spacing: 0.03em;
  touch-action: manipulation;
  transition: transform .08s ease, opacity .2s ease;
}
.ctrl:active { transform: scale(0.97); }
.ctrl.disabled { opacity: 0.4; pointer-events: none; }
#walk-btn { background: rgba(255,255,255,0.1); color: var(--text); border: 1px solid var(--stroke); }
#lock-btn { background: linear-gradient(90deg, var(--gold), #ffb838); color: #2a1d00; }

/* ---- Overlays: start / end ---------------------------------------------- */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  background: radial-gradient(ellipse at 50% 40%, rgba(10,16,30,0.95), rgba(3,5,10,0.99));
  z-index: 20;
}
.overlay h1 {
  font-size: clamp(34px, 7vw, 72px);
  margin: 0 0 8px;
  letter-spacing: 0.06em;
  background: linear-gradient(180deg, #fff, var(--gold));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 0 40px rgba(255,211,77,0.25);
}
.overlay p { color: var(--muted); font-size: clamp(17px, 2.7vw, 23px); margin: 0 0 28px; max-width: 600px; }
.overlay .big-amount {
  font-size: clamp(40px, 9vw, 84px);
  font-weight: 900;
  color: var(--gold);
  text-shadow: 0 0 30px rgba(255,211,77,0.4);
  margin: 4px 0 24px;
}

.cta {
  -webkit-appearance: none;
  appearance: none;
  border: none;
  border-radius: 14px;
  padding: 18px 40px;
  font-size: 19px;
  font-weight: 800;
  letter-spacing: 0.04em;
  cursor: pointer;
  background: linear-gradient(90deg, var(--teal), var(--blue));
  color: #05121a;
  box-shadow: 0 10px 40px rgba(47,107,255,0.4);
  touch-action: manipulation;
}
.cta:active { transform: scale(0.97); }
.cta.disabled { opacity: 0.45; pointer-events: none; filter: grayscale(0.4); }
.cta-secondary {
  background: rgba(255,255,255,0.12);
  color: var(--text);
  border: 1px solid var(--stroke);
  box-shadow: none;
  margin-top: 18px;
}

.rules { color: var(--muted); font-size: clamp(15px, 2vw, 18px); margin-top: 22px; max-width: 600px; line-height: 1.6; }

/* ---- Goal banner (start screen) + flag shop / reveal (end screen) -------- */
.goal-banner {
  margin: 0 0 22px;
  padding: 12px 20px;
  border-radius: 999px;
  font-size: clamp(15px, 2.4vw, 20px);
  font-weight: 800;
  color: #2a1d00;
  background: linear-gradient(90deg, var(--gold), #ffb838);
  box-shadow: 0 8px 30px rgba(255,179,56,0.35);
}

#flag-shop, #flag-reveal {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: min(560px, 100%);
  margin-top: 6px;
}

/* The buy-the-flag button - deliberately the biggest, loudest thing on screen. */
.cta-flag {
  background: linear-gradient(90deg, #18e06a, #0fbf8c);
  color: #042b16;
  font-size: clamp(18px, 3vw, 24px);
  padding: 20px 36px;
  width: 100%;
  box-shadow: 0 12px 44px rgba(24,224,106,0.45);
  animation: flagpulse 1.4s ease-in-out infinite;
}
@keyframes flagpulse {
  0%, 100% { box-shadow: 0 12px 44px rgba(24,224,106,0.40); }
  50%      { box-shadow: 0 12px 60px rgba(24,224,106,0.75); }
}
.cta-flag.disabled { animation: none; }
.flag-note { color: var(--muted); font-size: 14px; margin: 0; max-width: 520px; line-height: 1.5; }

.flag-banner { font-size: clamp(20px, 3.4vw, 28px); font-weight: 900; color: var(--green); }
.flag-value {
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
  font-size: clamp(16px, 2.6vw, 22px);
  font-weight: 700;
  color: #d9ffe9;
  background: rgba(24,224,106,0.12);
  border: 1px dashed rgba(24,224,106,0.6);
  border-radius: 12px;
  padding: 14px 18px;
  width: 100%;
  word-break: break-all;
  user-select: all;
  -webkit-user-select: all;
}

/* ---- Modals: audience chart + phone a friend ---------------------------- */
.modal {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(3,5,10,0.6);
  z-index: 25;
}
.modal-card {
  width: min(440px, 100%);
  background: var(--panel-solid);
  border: 1px solid var(--stroke);
  border-radius: 18px;
  padding: 20px;
  box-shadow: 0 20px 70px rgba(0,0,0,0.6);
}
.modal-card h2 { margin: 0 0 14px; font-size: 20px; }

#audience-chart {
  display: flex;
  align-items: flex-end;
  justify-content: space-around;
  gap: 12px;
  height: 200px;
}
.aud-bar { display: flex; flex-direction: column; align-items: center; height: 100%; justify-content: flex-end; flex: 1; }
.aud-track { width: 70%; height: 150px; display: flex; align-items: flex-end; background: rgba(255,255,255,0.05); border-radius: 8px 8px 0 0; }
.aud-fill {
  width: 100%;
  height: 0;
  background: linear-gradient(180deg, var(--teal), var(--blue));
  border-radius: 8px 8px 0 0;
  transition: height 0.7s cubic-bezier(.2,.8,.2,1);
}
.aud-label { margin-top: 8px; font-weight: 800; }
.aud-pct { font-size: 13px; color: var(--muted); }

#phone-text {
  font-size: 17px;
  line-height: 1.5;
  font-style: italic;
  color: #dbe8ff;
  min-height: 60px;
  display: flex;
  align-items: center;
}

.modal .cta { margin-top: 18px; width: 100%; padding: 14px; font-size: 16px; }

/* =========================================================================
 * RESPONSIVE: portrait phones/tablets & landscape
 * ======================================================================= */

/* Desktop (>1263px): the money ladder is a fixed right-hand rail, so the
   centred question/answer panel must reserve room for it — otherwise on
   mid-size screens the answers slide underneath the rail. The width scales
   smoothly with the viewport (never wider than 900px, never under the rail). */
@media (min-width: 1264px) {
  #question-panel {
    width: min(900px, calc(100vw - 420px));
  }
}

/* iPad & narrower (≤1263px): move the money ladder to a horizontal strip at the
   TOP so it can never hide behind the bottom question box. Covers every iPad
   size (portrait 768-834, landscape 1024-1194) in both orientations. */
@media (max-width: 1263px) {
  #ladder {
    position: static;
    width: auto;
    max-height: 140px;
    margin: 8px 14px 0;
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
  }
  /* Grow each tier to share the strip's width so it reaches the right edge on
     wide iPads; on narrow ones they keep their content width and scroll. */
  .ladder-row { flex: 1 0 auto; flex-direction: column; gap: 2px; text-align: center; }
  .ladder-row .ladder-num { width: auto; }
  .ladder-row .ladder-amount { margin-left: 0; }
  /* The ladder strip is the topmost element; everything else sits below it. */
  #hud { grid-template-rows: auto 1fr; }

  /* The mute button moves to BELOW the ladder, top-right (it was above before). */
  #top-bar {
    position: absolute;
    top: calc(env(safe-area-inset-top, 0px) + 98px);
    right: 0;
    left: auto;
    padding: 0 14px;
    z-index: 6;
  }

  /* Lifelines (with hearts) sit at the TOP-LEFT just below the ladder, with a
     little margin between them and the ladder strip. */
  #lifelines {
    position: absolute;
    top: calc(env(safe-area-inset-top, 0px) + 98px);
    left: 14px;
    right: auto;
    margin: 0;
    z-index: 5;
    justify-content: flex-start;
    gap: 12px;
    max-width: calc(100% - 110px);
  }
}

/* Narrow / portrait phones: stack answers in one column, tune the help menu. */
@media (max-width: 620px), (orientation: portrait) and (max-width: 820px) {
  #answers { grid-template-columns: 1fr; }
  .lifeline { width: 60px; height: 60px; font-size: 11px; }
  .lifeline .ll-ico { font-size: 22px; }
  #hearts { font-size: 24px; padding: 7px 11px; }
}

/* Short landscape (e.g. phone landscape): tighten vertical spacing. */
@media (orientation: landscape) and (max-height: 480px) {
  #question-text { padding: 8px 14px; margin-bottom: 8px; }
  .answer { min-height: 46px; padding: 9px 12px; }
  #prize-stake { font-size: 18px; }
  #ladder { top: 72px; max-height: calc(100% - 150px); }
  .ctrl { padding: 10px 18px; min-height: 44px; }
}
