/* Collapsing Bridge — cinematic HUD & screens.
   Palette: golden-hour amber on deep slate; red reserved for the collapse.
   Scoped to #app only — never style body/bare elements (hub chrome safety). */

#app {
  --ink: #f5e9d4;
  --ink-dim: #c9b391;
  --amber: #ffb454;
  --ember: #ff7a3c;
  --blood: #e6482e;
  --panel: rgba(12, 10, 9, 0.72);
  --line: rgba(255, 200, 130, 0.28);
  --font-disp: 'Avenir Next Condensed', 'Arial Narrow', 'Oswald', system-ui, sans-serif;
  --font-body: system-ui, -apple-system, 'Segoe UI', sans-serif;

  position: fixed;
  inset: 0;
  overflow: hidden;
  background: #0b0a0e;
  font-family: var(--font-body);
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
  overscroll-behavior: none;
}

#app * { margin: 0; padding: 0; box-sizing: border-box; }

#scene {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

#app .hidden { display: none !important; }

/* ───────────────────────────── cinematic frame ───────────────────────── */

#app .bar {
  position: absolute;
  left: 0; right: 0;
  height: 0;
  background: #000;
  z-index: 30;
  transition: height 0.7s cubic-bezier(0.6, 0, 0.3, 1);
  pointer-events: none;
}
#bar-top { top: 0; }
#bar-bot { bottom: 0; }
#app.cine #bar-top, #app.cine #bar-bot { height: 9vh; }

#vignette {
  position: absolute;
  inset: 0;
  z-index: 8;
  pointer-events: none;
  background: radial-gradient(ellipse at 50% 46%, transparent 52%, rgba(5, 3, 2, 0.55) 100%);
  opacity: 0.8;
}
#danger {
  position: absolute;
  inset: 0;
  z-index: 9;
  pointer-events: none;
  background: radial-gradient(ellipse at 50% 60%, transparent 46%, rgba(190, 40, 16, 0.5) 115%);
  opacity: 0;
  transition: opacity 0.25s linear;
}
#flash {
  position: absolute;
  inset: 0;
  z-index: 10;
  pointer-events: none;
  background: #fff8ea;
  opacity: 0;
}
/* The dust wall between bridges: hides the seam while one crossing is
   swapped for the next. Golden fog, never pure black — the run never stops. */
#wipe {
  position: absolute;
  inset: 0;
  z-index: 35;
  pointer-events: none;
  background:
    radial-gradient(ellipse at 50% 42%, rgba(122, 78, 40, 0.92), rgba(38, 22, 12, 0.98) 72%),
    #1a1008;
  opacity: 0;
}

/* ─────────────────────────────────── HUD ─────────────────────────────── */

#hud { position: absolute; inset: 0; z-index: 20; pointer-events: none; }

#hud-top {
  position: absolute;
  top: max(14px, env(safe-area-inset-top));
  left: 0; right: 0;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

/* The chase bar: you (amber) vs the collapse (red). The whole UI. */
#track {
  width: min(340px, 56vw);
  padding: 7px 12px 9px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  backdrop-filter: blur(3px);
}
#track-label {
  display: flex;
  justify-content: space-between;
  font-family: var(--font-disp);
  font-size: 10px;
  letter-spacing: 0.22em;
  color: var(--ink-dim);
  margin-bottom: 6px;
}
#track-label .pct { color: var(--amber); font-size: 11px; }
#rail {
  position: relative;
  height: 4px;
  border-radius: 2px;
  background: rgba(255, 235, 200, 0.16);
}
#rail-fill {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  border-radius: 2px;
  background: linear-gradient(90deg, rgba(230, 72, 46, 0.85), rgba(230, 72, 46, 0.1));
  pointer-events: none;
}
#front-mark {
  position: absolute;
  top: -4px;
  width: 4px; height: 12px;
  border-radius: 2px;
  background: var(--blood);
  box-shadow: 0 0 8px 2px rgba(230, 72, 46, 0.8);
  transform: translateX(-50%);
}
#you-mark {
  position: absolute;
  top: -5px;
  width: 14px; height: 14px;
  transform: translateX(-50%);
  background: radial-gradient(circle at 50% 40%, #ffe9b0, var(--amber) 60%, rgba(255, 180, 84, 0) 72%);
  clip-path: polygon(50% 0%, 100% 78%, 50% 100%, 0% 78%);
  filter: drop-shadow(0 0 6px rgba(255, 180, 84, 0.9));
}
#goal-mark {
  position: absolute;
  top: -6px;
  right: -3px;
  width: 6px; height: 16px;
  border-radius: 1px;
  background: linear-gradient(180deg, #ffe9b0, #d99a3d);
  box-shadow: 0 0 8px 1px rgba(255, 214, 140, 0.55);
}

#hud-left {
  position: absolute;
  top: max(14px, env(safe-area-inset-top));
  left: 16px;
  font-family: var(--font-disp);
  letter-spacing: 0.14em;
}
#hud-left .k { display: block; font-size: 9px; color: var(--ink-dim); }
#hud-left .v { font-size: 21px; color: var(--ink); text-shadow: 0 1px 6px rgba(0, 0, 0, 0.7); }
#hud-left .k.t2 { margin-top: 7px; }
#hud-left .sub { font-size: 10px; color: var(--ink-dim); margin-top: 3px; }

#hud-btns {
  position: absolute;
  top: max(14px, env(safe-area-inset-top));
  right: 16px;
  display: flex;
  gap: 8px;
  pointer-events: auto;
}
.hbtn {
  width: 34px; height: 34px;
  display: grid;
  place-items: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink-dim);
  font-size: 15px;
  cursor: pointer;
}
.hbtn:hover { color: var(--ink); border-color: var(--amber); }

/* Contextual hint, bottom centre */
#hint {
  position: absolute;
  bottom: 13vh;
  left: 0; right: 0;
  text-align: center;
  font-family: var(--font-disp);
  font-size: clamp(15px, 2.4vw, 21px);
  letter-spacing: 0.34em;
  color: var(--ink);
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.9);
  opacity: 0;
  transition: opacity 0.35s ease;
}
#hint.show { opacity: 0.96; }
#hint .sub {
  display: block;
  margin-top: 6px;
  font-size: 0.62em;
  letter-spacing: 0.28em;
  color: var(--amber);
}

/* Touch controls (shown only on touch devices). Two zones, one thumb each:
   the pad catches the touch and the stick drops under it — anywhere in the
   left 58% works; the right 42% is a jump zone (the button is the affordance,
   the zone is the hit area). The top strip stays chrome. */
#touch {
  position: absolute;
  inset: 0;
  z-index: 22;
  display: none;
  pointer-events: none;
}
#app.touch #touch { display: block; }
#move-zone, #jump-zone {
  position: absolute;
  top: max(24%, 96px);
  bottom: 0;
  pointer-events: auto;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}
#move-zone { left: 0; width: 58%; }
#jump-zone { right: 0; width: 42%; }
/* The stick lives inside the pad and is placed under the thumb on contact.
   margin -58px (half of 116px) makes left/top centre it on the touch point. */
#stick {
  position: absolute;
  width: 116px; height: 116px;
  margin: -58px 0 0 -58px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: rgba(12, 10, 9, 0.35);
  pointer-events: none;
  opacity: 0;
}
#stick.on { opacity: 1; }
#stick .nub {
  position: absolute;
  left: 50%; top: 50%;
  width: 44px; height: 44px;
  margin: -22px 0 0 -22px;
  border-radius: 50%;
  background: rgba(255, 200, 130, 0.35);
  border: 1px solid var(--amber);
}
#btn-jump {
  position: absolute;
  right: max(26px, env(safe-area-inset-right));
  bottom: max(26px, env(safe-area-inset-bottom));
  width: 96px; height: 96px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: rgba(12, 10, 9, 0.45);
  color: var(--amber);
  font-family: var(--font-disp);
  font-size: 12px;
  letter-spacing: 0.18em;
  pointer-events: auto;
  transition: transform 0.1s ease, background 0.1s ease;
}
#btn-jump.held {
  transform: scale(0.96);
  background: rgba(255, 180, 84, 0.3);
  border-color: var(--amber);
}

/* first-run coach marks — what each thumb does; each fades on first use */
#coach {
  position: absolute;
  inset: 0;
  z-index: 23;
  pointer-events: none;
}
#coach-run, #coach-jump {
  position: absolute;
  top: 46%;
  font-family: var(--font-disp);
  font-size: 13px;
  letter-spacing: 0.14em;
  color: var(--ink);
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.9);
  white-space: nowrap;
  animation: coachPulse 1.6s ease-in-out infinite;
}
#coach-run { left: 8%; }
#coach-jump {
  right: max(18px, env(safe-area-inset-right));
  width: 96px;
  text-align: center;
}
#coach .used {
  opacity: 0;
  animation: none;
  transition: opacity 0.3s;
}
@keyframes coachPulse {
  0%, 100% { opacity: 0.55; }
  50% { opacity: 1; }
}

/* ───────────────────────────────── screens ───────────────────────────── */

.screen {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  background: radial-gradient(ellipse at 50% 38%, rgba(20, 12, 6, 0.42), rgba(5, 4, 6, 0.88) 78%);
  backdrop-filter: blur(2px);
}
.screen .inner {
  text-align: center;
  padding: 34px 44px;
  max-width: min(560px, 92vw);
  animation: rise 0.55s cubic-bezier(0.2, 0.9, 0.3, 1) both;
}
@keyframes rise {
  from { transform: translateY(18px); opacity: 0; }
  to { transform: none; opacity: 1; }
}

.eyebrow {
  font-family: var(--font-disp);
  font-size: 11px;
  letter-spacing: 0.5em;
  color: var(--amber);
  margin-bottom: 10px;
}
h1 {
  font-family: var(--font-disp);
  font-weight: 700;
  font-size: clamp(44px, 9vw, 74px);
  line-height: 0.92;
  letter-spacing: 0.045em;
  text-transform: uppercase;
  color: var(--ink);
  text-shadow: 0 4px 30px rgba(0, 0, 0, 0.8), 0 0 60px rgba(255, 150, 60, 0.25);
}
h1 .red { color: var(--ember); }
h2 {
  font-family: var(--font-disp);
  font-weight: 700;
  font-size: clamp(30px, 6vw, 46px);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.tagline {
  margin-top: 12px;
  font-size: 15px;
  font-style: italic;
  color: var(--ink-dim);
}
.howto {
  margin: 22px auto 0;
  display: inline-flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 18px;
  font-size: 12.5px;
  color: var(--ink-dim);
  letter-spacing: 0.06em;
}
.howto b { color: var(--ink); font-weight: 600; }
/* The touch howto row is coarse-pointer-only; keyboard players never see it. */
.howto.touch-howto { display: none; }
kbd {
  display: inline-block;
  min-width: 20px;
  padding: 2px 6px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: rgba(255, 235, 200, 0.07);
  font-family: var(--font-body);
  font-size: 11px;
  color: var(--ink);
}

.btn {
  margin-top: 26px;
  padding: 13px 44px;
  font-family: var(--font-disp);
  font-size: 17px;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: #1c0f06;
  background: linear-gradient(180deg, #ffd27a, var(--amber) 55%, #e08a2e);
  border: none;
  border-radius: 4px;
  cursor: pointer;
  box-shadow: 0 6px 26px rgba(255, 150, 60, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.5);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.btn:hover { transform: translateY(-2px); box-shadow: 0 10px 34px rgba(255, 150, 60, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.5); }
.btn:active { transform: translateY(1px); }
.btn.ghost {
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--line);
  box-shadow: none;
}
.btn.ghost:hover { border-color: var(--amber); color: var(--amber); }
.row { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.row .btn { margin-top: 26px; }

.stat-line {
  margin-top: 18px;
  font-family: var(--font-disp);
  font-size: 13px;
  letter-spacing: 0.2em;
  color: var(--ink-dim);
}
.stat-line b { color: var(--amber); font-size: 15px; }
.stat-line .new {
  display: inline-block;
  margin-left: 8px;
  padding: 2px 8px;
  border-radius: 3px;
  background: var(--ember);
  color: #1c0f06;
  font-size: 10px;
  letter-spacing: 0.16em;
  animation: pulse 1s ease infinite alternate;
}
@keyframes pulse { from { opacity: 0.75; } to { opacity: 1; } }

.press {
  margin-top: 26px;
  font-size: 11px;
  letter-spacing: 0.3em;
  color: var(--ink-dim);
  animation: blink 1.6s ease infinite;
}
@keyframes blink { 0%, 100% { opacity: 0.25; } 50% { opacity: 0.9; } }

#screen-title .inner { padding-top: 0; }
#screen-dead h2 { color: #ff8d76; }

/* Error card (bootstrap failure) */
.screen.error .inner { max-width: 620px; text-align: left; }
.screen.error p { word-break: break-word; color: var(--ink-dim); margin-top: 10px; font-size: 13px; }

/* ------------------------------------------------ mobile pass
   Phones play in landscape. In portrait, a small non-blocking nudge — it never
   eats a touch, and it disappears the moment the device is turned. */
@media (orientation: portrait) and (hover: none) and (pointer: coarse) {
  #app::after {
    content: "↻  Best played in landscape";
    position: fixed;
    left: 50%;
    bottom: max(10px, env(safe-area-inset-bottom));
    transform: translateX(-50%);
    z-index: 9999;
    padding: 0.42rem 0.9rem;
    border: 1px solid rgba(243, 237, 225, 0.18);
    border-radius: 999px;
    background: rgba(8, 10, 16, 0.82);
    color: #f3ede1;
    font: 600 0.72rem/1.2 system-ui, -apple-system, sans-serif;
    letter-spacing: 0.04em;
    white-space: nowrap;
    pointer-events: none;
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
  }
}

/* Phone landscape leaves ~300px of height once the browser's own UI is showing
   — far less than the menu is tall. A launch button you cannot reach is a game
   you cannot start, so the menu scales to whatever height it is given, with
   scrolling as the backstop for anything extreme. */
@media (max-height: 520px) {
  .screen {
    padding: 8px;
    overflow-y: auto;
    align-content: center;
  }
  .screen > .inner {
    transform: scale(0.72);
  }
}
@media (max-height: 460px) { .screen > .inner { transform: scale(0.62); } }
@media (max-height: 400px) { .screen > .inner { transform: scale(0.54); } }
@media (max-height: 360px) { .screen > .inner { transform: scale(0.48); } }
@media (max-height: 320px) { .screen > .inner { transform: scale(0.42); } }
@media (max-height: 280px) { .screen > .inner { transform: scale(0.36); } }

/* ------------------------------------------------ coarse-pointer pass
   Phones only — every rule here is invisible to a mouse: keyboard + mouse
   play is pixel-identical. The HUD strip drops below the hub player shell's
   docked bar (~52px) and grows to 44px thumb targets; the title screen swaps
   the kbd chips for the touch howto; the dead screen loses the keyboard-only
   retry line. */
@media (pointer: coarse) {
  #hud-top, #hud-left, #hud-btns {
    top: max(50px, calc(env(safe-area-inset-top) + 12px));
  }
  #hud-btns {
    right: max(16px, env(safe-area-inset-right));
    gap: 10px;
  }
  .hbtn { width: 44px; height: 44px; font-size: 16px; }
  /* the keyboard howto row is meaningless on a phone */
  .howto:not(.touch-howto) { display: none; }
  .howto.touch-howto { display: block; }
  /* "OR PRESS R" — keyboard-only line; touch retry is RUN AGAIN */
  #screen-dead .press { display: none; }
}

/* ── promo capture: narrative captions (?cine=1) ──────────────────────────
   Fades on GAME time (hud.storyUpdate), so fixed-stepped video capture keeps
   each line on screen for its full scripted duration. */
#story-line {
  position: absolute;
  left: 50%;
  top: 68%;
  transform: translateX(-50%);
  width: min(82vw, 760px);
  text-align: center;
  font-family: Georgia, 'Times New Roman', serif;
  font-style: italic;
  font-size: clamp(19px, 3.2vw, 28px);
  line-height: 1.45;
  color: #ffe9c8;
  background: rgba(5, 7, 10, 0.48);
  padding: 10px 28px;
  border-radius: 8px;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.95), 0 0 22px rgba(0, 0, 0, 0.6);
  opacity: 0;
  transition: opacity 0.8s ease;
  pointer-events: none;
  z-index: 4;
}
#story-line.on { opacity: 1; }
