/* Thin Ice Crossing — UI.
   Scoped to #app (plus the minimal html/body reset the standalone page needs).
   The 3D scene is the real backdrop: screens are scrims over it, never opaque
   panels, so the lake stays visible behind every menu. */

:root {
  --ink: #eaf4ff;
  --dim: #86a3c0;
  --faint: #4a647f;
  --ice: #9fe0ff;
  --ice-deep: #2b6f9e;
  --warm: #ffb877;
  --bg: #050c16;
  --panel: rgba(8, 20, 34, 0.55);
  --edge: rgba(159, 224, 255, 0.24);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

#app {
  position: relative;
  width: 100%;
  height: 100%;
  color: var(--ink);
  font: 500 16px/1.45 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
  overflow: hidden;
}

#scene {
  display: block;
  width: 100%;
  height: 100%;
}

/* ============================== HUD ============================== */

#hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  transition: opacity 0.5s ease;
}

#hud.hidden {
  display: none;
}

#hud.veiled {
  opacity: 0;
}

/* danger vignette — closes in as the ice under you fails */
#danger {
  position: absolute;
  inset: 0;
  opacity: 0;
  background: radial-gradient(
    ellipse 120% 90% at 50% 50%,
    rgba(0, 0, 0, 0) 38%,
    rgba(6, 30, 52, 0.55) 72%,
    rgba(2, 10, 20, 0.92) 100%
  );
  transition: opacity 0.35s ease;
}

/* frost creep — a cold bloom at the corners while the surface is critical */
#frost {
  position: absolute;
  inset: -2px;
  opacity: 0;
  mix-blend-mode: screen;
  background:
    radial-gradient(140% 110% at 50% 50%, rgba(255, 255, 255, 0) 55%, rgba(190, 232, 255, 0.18) 82%, rgba(226, 246, 255, 0.42) 100%),
    radial-gradient(60% 50% at 4% 6%, rgba(214, 240, 255, 0.3), rgba(255, 255, 255, 0) 70%),
    radial-gradient(60% 50% at 96% 6%, rgba(214, 240, 255, 0.3), rgba(255, 255, 255, 0) 70%),
    radial-gradient(70% 60% at 4% 96%, rgba(214, 240, 255, 0.3), rgba(255, 255, 255, 0) 70%),
    radial-gradient(70% 60% at 96% 96%, rgba(214, 240, 255, 0.3), rgba(255, 255, 255, 0) 70%);
  transition: opacity 0.2s linear;
}

#flash {
  position: absolute;
  inset: 0;
  opacity: 0;
  background: #dff2ff;
  pointer-events: none;
}

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

#hud-left {
  display: flex;
  align-items: flex-end;
  gap: 12px;
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.stat .k {
  font-size: 10px;
  letter-spacing: 0.22em;
  color: var(--dim);
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.8);
}

.stat .v {
  font-size: 30px;
  font-weight: 800;
  letter-spacing: 0.01em;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 2px 14px rgba(0, 0, 0, 0.85);
  line-height: 1;
}

.stat .v.small {
  font-size: 18px;
  font-weight: 700;
}

#hud-right {
  text-align: right;
}

.chip {
  align-self: center;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid rgba(255, 184, 119, 0.55);
  background: rgba(255, 150, 60, 0.16);
  color: var(--warm);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.06em;
  font-variant-numeric: tabular-nums;
  transition: opacity 0.3s, transform 0.2s;
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.7);
}

.chip.off {
  opacity: 0;
  transform: translateY(4px);
}

.chip.pop {
  animation: chip-pop 0.3s ease;
}

@keyframes chip-pop {
  0% { transform: scale(1); }
  40% { transform: scale(1.22); }
  100% { transform: scale(1); }
}

/* progress — how far across the water you are */
#progress {
  position: absolute;
  left: 50%;
  bottom: max(22px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(380px, 62vw);
  text-align: center;
}

#progress-track {
  position: relative;
  height: 3px;
  border-radius: 2px;
  background: rgba(160, 200, 235, 0.22);
  box-shadow: 0 0 12px rgba(0, 0, 0, 0.6);
}

#progress-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0%;
  border-radius: 2px;
  background: linear-gradient(90deg, #7fd4ff, #d8f2ff);
  box-shadow: 0 0 10px rgba(143, 216, 255, 0.75);
}

#progress-mark {
  position: absolute;
  top: 50%;
  left: 0%;
  width: 9px;
  height: 9px;
  margin: -4.5px 0 0 -4.5px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 12px rgba(180, 230, 255, 0.95);
}

#progress-label {
  margin-top: 7px;
  font-size: 10px;
  letter-spacing: 0.26em;
  color: var(--dim);
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.85);
}

#toast {
  position: absolute;
  left: 50%;
  top: 26%;
  transform: translate(-50%, 6px);
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.2em;
  color: var(--warm);
  opacity: 0;
  pointer-events: none;
  text-shadow: 0 2px 18px rgba(0, 0, 0, 0.9), 0 0 26px rgba(255, 160, 70, 0.45);
  transition: opacity 0.28s ease, transform 0.28s ease;
  white-space: pre;
  text-align: center;
}

#toast.on {
  opacity: 1;
  transform: translate(-50%, 0);
}

#toast.cold {
  color: var(--ice);
  text-shadow: 0 2px 18px rgba(0, 0, 0, 0.9), 0 0 26px rgba(120, 210, 255, 0.5);
}

#prompt {
  position: absolute;
  left: 50%;
  bottom: 11%;
  transform: translateX(-50%);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.18em;
  color: var(--ink);
  opacity: 0;
  transition: opacity 0.2s;
  text-shadow: 0 2px 14px rgba(0, 0, 0, 0.9);
  white-space: nowrap;
}

#prompt.on {
  opacity: 0.92;
}

#prompt em {
  font-style: normal;
  color: var(--warm);
}

/* ============================ screens ============================ */

.screen {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 28px;
  overflow-y: auto;
  background:
    linear-gradient(180deg, rgba(3, 9, 16, 0.46) 0%, rgba(3, 9, 16, 0) 24%, rgba(3, 9, 16, 0) 70%, rgba(3, 9, 16, 0.42) 100%),
    radial-gradient(
      ellipse 95% 78% at 50% 44%,
      rgba(4, 12, 22, 0.22) 0%,
      rgba(4, 12, 22, 0.6) 66%,
      rgba(3, 9, 16, 0.86) 100%
    );
  animation: fade-in 0.45s ease both;
}

.screen.hidden {
  display: none;
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.inner {
  max-width: 460px;
  width: 100%;
}

.inner.wide {
  max-width: 560px;
}

.crest {
  width: 132px;
  margin: 0 auto 6px;
}

.crest svg {
  width: 100%;
  height: auto;
  display: block;
}

.crest path {
  fill: rgba(150, 205, 240, 0.5);
}

.crest path.snow {
  fill: rgba(230, 246, 255, 0.92);
}

h1 {
  margin: 0;
  font-size: clamp(40px, 12.5vw, 74px);
  line-height: 0.92;
  letter-spacing: 0.02em;
  font-weight: 900;
  background: linear-gradient(180deg, #ffffff 0%, #d5ecfb 46%, #7fb9dd 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 4px 22px rgba(0, 20, 40, 0.85));
}

h1.sub {
  font-size: clamp(24px, 7.4vw, 44px);
  letter-spacing: 0.44em;
  margin-left: 0.44em;
  background: linear-gradient(180deg, #eaf7ff 0%, #a9d4ee 100%);
  -webkit-background-clip: text;
  background-clip: text;
}

.kicker {
  margin: 14px 0 0;
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.42em;
  color: var(--ice);
  opacity: 0.85;
}

/* The poster's handwritten asides: warm, informal, set against the cold caps. */
.script {
  position: absolute;
  margin: 0;
  font-family: "Snell Roundhand", "Segoe Script", "Bradley Hand", cursive;
  font-size: clamp(15px, 2.2vw, 22px);
  line-height: 1.25;
  color: #ffe6cf;
  opacity: 0.9;
  text-shadow: 0 2px 14px rgba(0, 0, 0, 0.75);
  pointer-events: none;
}

.script.tl {
  top: max(26px, env(safe-area-inset-top));
  right: 5%;
  transform: rotate(-3deg);
  text-align: right;
}

.script.br {
  top: 42%;
  right: 3.5%;
  transform: rotate(-3deg);
  text-align: right;
}

@media (max-width: 900px) {
  .script.tl,
  .script.br {
    display: none;
  }
}

h2 {
  margin: 6px 0 4px;
  font-size: clamp(26px, 7vw, 38px);
  letter-spacing: 0.05em;
  font-weight: 800;
}

.tagline {
  color: var(--dim);
  margin: 14px 0 22px;
  font-size: 15px;
}

.tagline.small {
  font-size: 14px;
  margin: 10px 0 20px;
}

.motto {
  margin-top: 22px;
  font-size: 13px;
  font-style: italic;
  color: var(--ice);
  opacity: 0.75;
  letter-spacing: 0.06em;
}

.motto.dim {
  color: var(--dim);
}

/* the four rules, echoing the poster */
.steps {
  list-style: none;
  margin: 0 0 26px;
  padding: 0;
  display: grid;
  gap: 9px;
  text-align: left;
}

.steps li {
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 9px 14px;
  border: 1px solid rgba(159, 224, 255, 0.14);
  border-radius: 11px;
  background: linear-gradient(180deg, rgba(20, 44, 70, 0.42), rgba(10, 24, 40, 0.34));
}

.steps b,
.steps .ico {
  flex: 0 0 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: rgba(143, 216, 255, 0.1);
  border: 1px solid rgba(143, 216, 255, 0.34);
}

.steps b {
  color: var(--ice);
  font-size: 12px;
  font-weight: 800;
}

.steps .ico svg {
  width: 18px;
  height: 18px;
  fill: rgba(190, 232, 255, 0.9);
}

.steps .ico svg .ink {
  fill: none;
  stroke: rgba(190, 232, 255, 0.9);
  stroke-width: 1.5;
  stroke-linecap: round;
}

.steps .ico svg .snow {
  fill: rgba(235, 248, 255, 0.95);
}

.steps strong {
  display: block;
  font-size: 11.5px;
  letter-spacing: 0.2em;
  font-weight: 800;
}

.steps span {
  font-size: 12.5px;
  color: var(--dim);
  letter-spacing: 0.01em;
}

.controls {
  margin: 18px 0 0;
  font-size: 12px;
  color: var(--dim);
  line-height: 2;
}

.best {
  margin: 14px 0 0;
  font-size: 11.5px;
  letter-spacing: 0.2em;
  color: var(--dim);
  font-weight: 700;
}

.best span {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.tally {
  display: grid;
  gap: 7px;
  margin: 16px 0 22px;
}

.tally div {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  padding: 8px 14px;
  border-radius: 9px;
  background: rgba(16, 36, 58, 0.42);
  border: 1px solid rgba(159, 224, 255, 0.12);
  font-size: 13.5px;
}

.tally span {
  color: var(--dim);
  letter-spacing: 0.08em;
  font-size: 12px;
  text-transform: uppercase;
}

.tally b {
  font-variant-numeric: tabular-nums;
  font-weight: 800;
}

.tally div.hero {
  background: rgba(36, 84, 122, 0.42);
  border-color: rgba(159, 224, 255, 0.34);
}

.tally div.hero b {
  color: var(--ice);
  font-size: 17px;
}

.row {
  display: flex;
  gap: 12px;
  justify-content: center;
}

kbd {
  display: inline-block;
  padding: 1px 6px;
  margin: 0 1px;
  border: 1px solid rgba(140, 190, 230, 0.3);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: rgba(14, 30, 48, 0.75);
  font: inherit;
  font-size: 11px;
  font-weight: 700;
  color: var(--ink);
}

.btn {
  appearance: none;
  border: 1px solid rgba(140, 190, 230, 0.3);
  border-radius: 11px;
  background: rgba(14, 30, 48, 0.72);
  color: var(--ink);
  font: inherit;
  font-weight: 700;
  letter-spacing: 0.08em;
  padding: 12px 26px;
  cursor: pointer;
  transition: transform 0.12s, background 0.15s, border-color 0.15s, box-shadow 0.15s;
  backdrop-filter: blur(6px);
}

.btn:hover {
  background: rgba(26, 54, 84, 0.85);
  border-color: rgba(159, 224, 255, 0.5);
}

.btn:active {
  transform: translateY(1px);
}

.btn.primary {
  background: linear-gradient(180deg, rgba(126, 205, 245, 0.95), rgba(46, 124, 176, 0.95));
  border-color: rgba(198, 236, 255, 0.75);
  color: #04202f;
  box-shadow: 0 8px 30px rgba(60, 150, 210, 0.32), inset 0 1px 0 rgba(255, 255, 255, 0.45);
}

.btn.primary:hover {
  background: linear-gradient(180deg, rgba(158, 222, 255, 1), rgba(62, 146, 200, 1));
  box-shadow: 0 10px 38px rgba(80, 175, 235, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.5);
}

.btn.big {
  padding: 15px 40px;
  font-size: 13px;
  letter-spacing: 0.18em;
}

.screen.card {
  background: radial-gradient(ellipse 80% 60% at 50% 50%, rgba(6, 20, 34, 0.55) 0%, rgba(3, 10, 18, 0.86) 70%);
}

/* =========================== touch input =========================== */

#touch {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

#touch.hidden {
  display: none;
}

/* A thumb rarely lands on a small fixed circle. The pad catches the touch and
   the stick is placed under it, so anywhere in the lower-left works. */
#move-zone {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 46%;
  height: 72%;
  pointer-events: auto;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}

/* The look zone tiles the rest of the lower screen, so there is no dead
   column between the thumbs: a drag here orbits the camera. The LEAP button
   sits inside this rectangle but is its own hit target above it — a drag
   starting on LEAP is a LEAP, a drag starting on the zone is a look. */
#look-zone {
  position: absolute;
  right: 0;
  top: 22%;
  bottom: 0;
  width: 54%;
  pointer-events: auto;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}

#stick {
  position: absolute;
  left: max(22px, env(safe-area-inset-left));
  bottom: max(28px, env(safe-area-inset-bottom));
  width: 124px;
  height: 124px;
  border-radius: 50%;
  border: 1.5px solid rgba(159, 224, 255, 0.26);
  background: rgba(10, 26, 42, 0.3);
  pointer-events: none;
  touch-action: none;
}

#stick-nub {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 52px;
  height: 52px;
  margin: -26px 0 0 -26px;
  border-radius: 50%;
  background: rgba(170, 220, 250, 0.32);
  border: 1px solid rgba(200, 236, 255, 0.5);
}

/* the stick pushed to its rim — sprint is a commitment, so it is visible */
#stick.sprint {
  border-color: rgba(255, 184, 119, 0.55);
}

.tbtn {
  position: absolute;
  right: max(24px, env(safe-area-inset-right));
  bottom: max(38px, env(safe-area-inset-bottom));
  width: 104px;
  height: 104px;
  border-radius: 50%;
  border: 1.5px solid rgba(159, 224, 255, 0.3);
  background: rgba(20, 52, 80, 0.42);
  color: var(--ink);
  font: inherit;
  font-size: 11.5px;
  font-weight: 800;
  letter-spacing: 0.12em;
  pointer-events: auto;
  touch-action: none;
}

.tbtn:active,
.tbtn.pressed {
  background: rgba(60, 130, 180, 0.6);
}

/* The pause control. Safe-area aware: on a notched phone in landscape the
   top-right corner is where the grip and the notch both live. It starts above
   the zones (22 % height) so it never fights a thumb for a touch. */
#btn-pause {
  position: absolute;
  top: calc(14px + env(safe-area-inset-top));
  right: max(18px, env(safe-area-inset-right));
  width: 44px;
  height: 44px;
  border-radius: 10px;
  border: 1px solid var(--edge);
  background: var(--panel);
  color: var(--ink);
  font: inherit;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  appearance: none;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
  touch-action: none;
  cursor: pointer;
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}

/* first-run coach marks — what each thumb does; each fades on first use */
#coach {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

#coach.hidden {
  display: none;
}

#coach-move,
#coach-look,
#coach-leap {
  position: absolute;
  top: 46%;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.14em;
  color: var(--ink);
  text-shadow: 0 1px 8px rgba(6, 18, 28, 0.9);
  white-space: nowrap;
  animation: coachPulse 1.6s ease-in-out infinite;
}

#coach-move {
  left: 8%;
}

#coach-look {
  right: 34%;
}

/* centred on the LEAP button's footprint */
#coach-leap {
  right: max(24px, env(safe-area-inset-right));
  width: 104px;
  text-align: center;
}

#coach .used {
  opacity: 0;
  animation: none;
  transition: opacity 0.3s;
}

@keyframes coachPulse {
  0%, 100% { opacity: 0.55; }
  50% { opacity: 1; }
}

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

/* On a coarse pointer the keyboard howto row is meaningless — swap in the
   touch one — and the lake-distance readout keeps clear of the ⏸ button. */
@media (pointer: coarse) {
  .controls:not(.touch-controls) {
    display: none;
  }
  .touch-controls {
    display: block;
  }
  #hud-right {
    margin-right: 52px;
  }
}

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

/* ── 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: 66%;
  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: #dcecf7;
  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: 40;
}
#story-line.on { opacity: 1; }
