/* A Day in the Life — UI chrome.
   The 3D canvas is the background layer; every screen is a DOM overlay on top of it.
   Mobile-first: nothing here assumes hover, and all tap targets clear 44px. */

:root {
  --bg: #12131a;
  --bg-panel: rgba(18, 19, 26, 0.92);
  --ink: #f3f2ee;
  --ink-muted: #9a9aa8;
  --accent: #e8b64c;
  --accent-ink: #1a1408;
  --good: #6fcf7f;
  --bad: #e2705f;
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

#stage-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: manipulation;
}

/* ---------- Screens ---------- */

.screen {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  padding-bottom: calc(24px + var(--safe-b));
  background: linear-gradient(180deg, rgba(10, 11, 16, 0.72), rgba(10, 11, 16, 0.92));
  backdrop-filter: blur(3px);
  z-index: 20;
}
.screen.is-active { display: flex; }

.panel {
  width: min(420px, 100%);
  background: var(--bg-panel);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius);
  padding: 28px 24px;
  text-align: center;
}

.logo {
  margin: 0 0 6px;
  font-size: clamp(26px, 7vw, 34px);
  font-weight: 700;
  letter-spacing: -0.02em;
}
h2 { margin: 0 0 10px; font-size: 22px; font-weight: 650; }

.lede { margin: 10px 0 22px; line-height: 1.55; color: #d8d7d0; }
.muted { color: var(--ink-muted); }
.small { font-size: 14px; }
.xsmall { font-size: 12px; margin-top: 16px; }

.rank {
  margin: 6px 0 4px;
  font-size: clamp(28px, 8vw, 38px);
  font-weight: 750;
  letter-spacing: -0.02em;
  color: var(--accent);
}
.score { margin: 0 0 14px; font-size: 15px; color: var(--ink-muted); }

/* ---------- Rotate-to-landscape gate ----------
   Mobile is a LANDSCAPE target by decision. A portrait phone shows roughly a third of
   the horizontal extent the stages are framed for, so rather than squeeze six scenes
   into a slot we ask for the rotation. The camera fitting in engine.js still exists as
   a safety net for odd aspect ratios, but on a phone it should never need to fire. */

#screen-rotate {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 28px;
  text-align: center;
  background: linear-gradient(170deg, #1b1d29, #0b0c11);
}
#screen-rotate.is-active { display: flex; }

.rotate-inner { max-width: 30ch; }
#screen-rotate h2 { margin: 26px 0 10px; font-size: 21px; }
#screen-rotate p { margin: 0; font-size: 15px; line-height: 1.5; color: var(--ink-muted); }

/* A phone outline that tips from upright to sideways, on a loop. */
.rotate-phone {
  width: 54px;
  height: 92px;
  margin: 0 auto;
  border: 3px solid var(--accent);
  border-radius: 10px;
  position: relative;
  animation: tip 2.6s ease-in-out infinite;
}
.rotate-phone span {
  position: absolute;
  left: 50%;
  bottom: 6px;
  width: 18px;
  height: 3px;
  border-radius: 2px;
  background: var(--accent);
  transform: translateX(-50%);
}
@keyframes tip {
  0%, 28%   { transform: rotate(0deg); }
  55%, 100% { transform: rotate(-90deg); }
}
@media (prefers-reduced-motion: reduce) {
  .rotate-phone { animation: none; transform: rotate(-90deg); }
}

/* ---------- Transitions ----------
   Deliberately DOM rather than 3D: these are four-second beats with nothing asked of
   the player, and a CSS wash costs no triangles on a phone that has none to spare.
   The next stage builds behind this overlay, so the build cost is hidden inside the
   pause rather than showing up as a hitch. */

#screen-transition {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px;
  text-align: center;
  opacity: 0;
  transition: opacity 620ms ease;
  background: linear-gradient(165deg, var(--tr-a, #1a1c26), var(--tr-b, #0c0d12));
}
#screen-transition.is-active { display: flex; }
#screen-transition.is-visible { opacity: 1; }

/* Soft light source — sunrise, noon glare, dusk — driven by the transition data. */
.tr-glow {
  position: absolute;
  width: min(70vw, 420px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle, var(--tr-glow, transparent) 0%, transparent 68%);
  top: var(--tr-glow-y, 62%);
  opacity: 0;
  transform: translateY(30px);
  transition: opacity 1.6s ease, transform 3.4s cubic-bezier(0.22, 0.9, 0.3, 1);
}
#screen-transition.is-visible .tr-glow {
  opacity: 1;
  transform: translateY(-18px);
}

.tr-body { position: relative; }

.tr-time {
  margin: 0 0 10px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--tr-ink-dim, rgba(255, 255, 255, 0.55));
}
.tr-title {
  margin: 0 0 12px;
  font-size: clamp(24px, 6.5vw, 32px);
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--tr-ink, #f3f2ee);
}
.tr-line {
  margin: 0;
  max-width: 30ch;
  font-size: clamp(15px, 4vw, 17px);
  line-height: 1.5;
  color: var(--tr-ink-dim, rgba(255, 255, 255, 0.72));
}

/* Staggered so the beat has a shape instead of appearing all at once. */
.tr-time, .tr-title, .tr-line {
  opacity: 0;
  transform: translateY(9px);
  transition: opacity 520ms ease, transform 520ms ease;
}
#screen-transition.is-visible .tr-time { opacity: 1; transform: none; transition-delay: 180ms; }
#screen-transition.is-visible .tr-title { opacity: 1; transform: none; transition-delay: 320ms; }
#screen-transition.is-visible .tr-line { opacity: 1; transform: none; transition-delay: 480ms; }

.tr-skip {
  position: absolute;
  bottom: calc(26px + var(--safe-b));
  margin: 0;
  font-size: 12px;
  letter-spacing: 0.08em;
  color: rgba(255, 255, 255, 0.3);
  opacity: 0;
  transition: opacity 400ms ease;
}
#screen-transition.can-skip .tr-skip { opacity: 1; }

/* ---------- Buttons ---------- */

.btn {
  display: block;
  width: 100%;
  min-height: 48px;
  margin-top: 10px;
  padding: 13px 18px;
  border: 0;
  border-radius: 11px;
  font: inherit;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.08s ease, opacity 0.15s ease;
}
.btn:active { transform: scale(0.985); }
.btn:disabled { opacity: 0.5; cursor: default; }

.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-ghost {
  background: transparent;
  color: var(--ink-muted);
  border: 1px solid rgba(255, 255, 255, 0.12);
}

/* ---------- Loader ---------- */

.loader {
  height: 5px;
  margin: 20px 0 12px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.09);
  overflow: hidden;
}
.loader-bar {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.25s ease;
}

/* ---------- HUD (visible only during a stage) ---------- */

#hud {
  position: fixed;
  inset: 0;
  display: none;
  flex-direction: column;
  justify-content: flex-end;
  padding: 16px;
  padding-bottom: calc(16px + var(--safe-b));
  pointer-events: none;
  z-index: 10;
}
#hud.is-active { display: flex; }

#hud-top {
  position: absolute;
  top: calc(12px + env(safe-area-inset-top, 0px));
  left: 16px;
  right: 16px;
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-muted);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
}

#hud-prompt {
  margin-bottom: 12px;
  font-size: clamp(17px, 4.6vw, 20px);
  font-weight: 650;
  text-align: center;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.75);
}

/* Countdown for timed stages (mechanic B). */
#hud-timer {
  display: none;
  height: 6px;
  margin-bottom: 12px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.13);
  overflow: hidden;
}
#hud-timer.is-shown { display: block; }
#hud-timer-bar {
  height: 100%;
  width: 100%;
  background: var(--accent);
  transform-origin: left center;
}
#hud-timer-bar.is-urgent { background: var(--bad); }

#hud-choices {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 9px;
  pointer-events: auto;
}

.choice {
  min-height: 52px;
  padding: 12px 10px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 11px;
  background: rgba(22, 23, 31, 0.86);
  color: var(--ink);
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.08s ease, background 0.15s ease, border-color 0.15s ease;
}
.choice:active { transform: scale(0.97); }

/* Ordered-puzzle stages number each tap. Empty until the player picks it. */
.choice-badge:empty { display: none; }
.choice-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 21px;
  height: 21px;
  margin-right: 7px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 12px;
  font-weight: 750;
  vertical-align: middle;
}
.choice.is-picked { border-color: var(--accent); background: rgba(40, 34, 14, 0.9); }
.choice.is-right .choice-badge { background: var(--good); color: #0d2412; }
.choice.is-wrong .choice-badge { background: var(--bad); color: #2c0d08; }
.choice.is-hot { border-color: var(--accent); background: rgba(40, 34, 14, 0.9); }
.choice.is-right { border-color: var(--good); background: rgba(20, 46, 26, 0.92); }
.choice.is-wrong { border-color: var(--bad); background: rgba(52, 22, 18, 0.92); }
.choice:disabled { cursor: default; }

#hud-feedback {
  min-height: 22px;
  margin-top: 12px;
  font-size: 15px;
  font-weight: 600;
  text-align: center;
  opacity: 0;
  transition: opacity 0.25s ease;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.75);
}
#hud-feedback.is-shown { opacity: 1; }
#hud-feedback.good { color: var(--good); }
#hud-feedback.bad { color: var(--bad); }

/* ---------- Form ---------- */

#lead-form { text-align: left; margin-top: 8px; }

label {
  display: block;
  margin: 12px 0 5px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-muted);
}

input[type="text"], input[type="email"] {
  width: 100%;
  min-height: 48px;
  padding: 12px 14px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 11px;
  background: rgba(0, 0, 0, 0.28);
  color: var(--ink);
  font: inherit;
  font-size: 16px; /* 16px or iOS zooms the viewport on focus */
}
input:focus {
  outline: none;
  border-color: var(--accent);
}
input[aria-invalid="true"] { border-color: var(--bad); }

.field-error {
  min-height: 18px;
  margin: 10px 0 0;
  font-size: 13px;
  color: var(--bad);
}

.noscript-panel {
  position: fixed;
  inset: 0;
  margin: auto;
  height: fit-content;
  z-index: 50;
}

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: 0.01ms !important; }
}

/* ---------- Short viewports (a phone in landscape is ~375px tall) ----------

   MUST STAY LAST IN THIS FILE. These rules have the same specificity as the base ones
   they override, so the cascade decides on order alone — placed earlier, .btn's
   min-height:48px silently beat the 44px here and the panels stayed tall.

   Landscape phone is the mobile target, so ~375px of height is the real budget. The
   lead form is the screen that matters: at full size it runs 448px and pushes the skip
   button below the fold, on the one screen where a below-fold control costs signups. */

@media (max-height: 480px) {
  .screen { padding: 12px; align-items: flex-start; overflow-y: auto; }
  .panel { padding: 14px 18px; margin: auto; }

  .logo { font-size: 21px; margin-bottom: 2px; }
  h2 { font-size: 17px; margin-bottom: 5px; }
  .lede { margin: 5px 0 10px; font-size: 13.5px; line-height: 1.38; }
  .rank { font-size: 24px; margin: 2px 0 3px; }
  .score { margin-bottom: 7px; font-size: 12.5px; }
  .small { font-size: 13px; }
  .xsmall { margin-top: 7px; font-size: 11px; }
  .loader { margin: 12px 0 7px; }

  .btn { min-height: 44px; margin-top: 7px; padding: 9px 16px; font-size: 15px; }

  /* Name and email share a row — saves ~56px, which is the difference between the
     skip button being on screen and under it. */
  #lead-form {
    display: grid;
    grid-template-columns: 1fr 1fr;
    column-gap: 12px;
    margin-top: 4px;
  }
  #lead-form > label[for="lead-name"]  { grid-area: 1 / 1 / 2 / 2; }
  #lead-form > #lead-name              { grid-area: 2 / 1 / 3 / 2; }
  #lead-form > label[for="lead-email"] { grid-area: 1 / 2 / 2 / 3; }
  #lead-form > #lead-email             { grid-area: 2 / 2 / 3 / 3; }
  #lead-form > .field-error            { grid-area: 3 / 1 / 4 / 3; }
  #lead-form > #btn-lead-submit        { grid-area: 4 / 1 / 5 / 3; }
  #lead-form > #btn-lead-skip          { grid-area: 5 / 1 / 6 / 3; }

  label { margin: 6px 0 3px; font-size: 12px; }
  input[type="text"], input[type="email"] { min-height: 44px; padding: 9px 12px; }
  .field-error { min-height: 15px; margin-top: 7px; font-size: 12px; }

  /* HUD has to survive the same 375px frame. */
  #hud { padding: 10px 12px; }
  #hud-top { top: calc(8px + env(safe-area-inset-top, 0px)); font-size: 12px; }
  #hud-prompt { margin-bottom: 7px; font-size: 16px; }
  #hud-timer { margin-bottom: 7px; height: 5px; }
  #hud-choices { gap: 7px; }
  .choice { min-height: 44px; padding: 8px 8px; font-size: 14px; }
  #hud-feedback { min-height: 17px; margin-top: 7px; font-size: 13.5px; }

  /* The rotate gate itself never shows in landscape, but keep it sane if it ever does. */
  #screen-rotate h2 { margin: 14px 0 6px; }
  .rotate-phone { width: 40px; height: 68px; }
}
