/* Wild River Boat — UI. Scoped to #app; never styles body or bare elements. */

:root {
  --ink: #f2f6f9;
  --dim: #9db0c2;
  --accent: #ffb03a;
  --water: #3fb8b6;
  --danger: #ff5c5c;
  --panel: rgba(9, 22, 34, 0.72);
  --stroke: rgba(255, 255, 255, 0.14);
  --display: "Avenir Next Condensed", "Arial Narrow", "Helvetica Neue", Impact, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #06121c;
  -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", 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;
  z-index: 5;
}

#hud.hidden {
  display: none;
}

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

.stat {
  background: var(--panel);
  border: 1px solid var(--stroke);
  border-radius: 12px;
  padding: 8px 14px;
  backdrop-filter: blur(6px);
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 96px;
}

.stat.right {
  text-align: right;
}

.stat .k {
  font-size: 9px;
  letter-spacing: 0.18em;
  color: var(--dim);
  font-weight: 700;
}

.stat .v {
  font-family: var(--display);
  font-size: 22px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
}

/* the water meter — the second pressure, always in view */
#meter {
  position: absolute;
  top: max(14px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  width: min(300px, 44vw);
  background: var(--panel);
  border: 1px solid var(--stroke);
  border-radius: 14px;
  padding: 8px 12px 9px;
  backdrop-filter: blur(6px);
  transition: box-shadow 0.25s, border-color 0.25s;
}

#meter-bar {
  height: 12px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.1);
  overflow: hidden;
  margin: 5px 0 4px;
}

#meter-fill {
  height: 100%;
  width: 5%;
  border-radius: 6px;
  background: linear-gradient(90deg, #2f9ec4, #3fb8b6);
  transition: width 0.18s linear;
}

#meter-text {
  display: flex;
  justify-content: space-between;
  font-size: 9px;
  letter-spacing: 0.16em;
  font-weight: 700;
  color: var(--dim);
}

#meter-pct {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

#meter-icon {
  position: absolute;
  top: -9px;
  left: 10px;
  width: 18px;
  height: 18px;
  fill: var(--water);
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.5));
}

#meter.danger {
  border-color: var(--danger);
  box-shadow: 0 0 18px rgba(255, 92, 92, 0.35);
  animation: pulse 0.9s ease-in-out infinite;
}

#meter.danger #meter-fill {
  background: linear-gradient(90deg, #e08030, #ff5c5c);
}

#meter.danger #meter-label {
  color: var(--danger);
}

#meter.critical {
  animation: pulse 0.4s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { transform: translateX(-50%) scale(1); }
  50% { transform: translateX(-50%) scale(1.035); }
}

/* section banners */
#banner {
  position: absolute;
  top: 22%;
  left: 0;
  right: 0;
  text-align: center;
  opacity: 0;
  pointer-events: none;
}

#banner.on {
  animation: bannerIn 2.6s ease forwards;
}

@keyframes bannerIn {
  0% { opacity: 0; transform: translateY(14px); }
  12% { opacity: 1; transform: translateY(0); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-8px); }
}

#banner-title {
  font-family: var(--display);
  font-size: clamp(30px, 6vw, 52px);
  font-weight: 800;
  letter-spacing: 0.22em;
  text-shadow: 0 2px 18px rgba(6, 18, 28, 0.8), 0 1px 0 rgba(0, 0, 0, 0.4);
}

#banner-sub {
  font-size: clamp(12px, 1.8vw, 16px);
  letter-spacing: 0.12em;
  color: var(--accent);
  font-weight: 700;
  text-shadow: 0 1px 8px rgba(6, 18, 28, 0.9);
}

/* contextual hint */
#hint {
  position: absolute;
  bottom: 16%;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--ink);
  text-shadow: 0 1px 8px rgba(6, 18, 28, 0.9);
  opacity: 0;
  transition: opacity 0.3s;
}

#hint.on {
  opacity: 1;
}

/* floating score popups */
#popups {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

.popup {
  position: absolute;
  transform: translate(-50%, -50%);
  font-family: var(--display);
  font-weight: 800;
  font-size: 20px;
  letter-spacing: 0.08em;
  color: var(--accent);
  text-shadow: 0 1px 8px rgba(6, 18, 28, 0.9);
  animation: popUp 1.05s ease-out forwards;
  white-space: nowrap;
}

.popup.close {
  color: #7ce0ff;
}

@keyframes popUp {
  0% { opacity: 0; transform: translate(-50%, -30%) scale(0.7); }
  15% { opacity: 1; transform: translate(-50%, -50%) scale(1.1); }
  30% { transform: translate(-50%, -55%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -160%) scale(1); }
}

/* cinema overlays */
#vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 4;
  opacity: 0;
  transition: opacity 0.6s;
  background:
    radial-gradient(ellipse at center, transparent 58%, rgba(4, 12, 20, 0.42) 100%);
}

#vignette.on {
  opacity: 1;
}

#danger-flash {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 4;
  opacity: 0;
  transition: opacity 0.5s;
  background: radial-gradient(ellipse at center, transparent 55%, rgba(140, 20, 20, 0.35) 100%);
}

#danger-flash.on {
  opacity: 1;
  animation: pulseFlat 1s ease-in-out infinite;
}

@keyframes pulseFlat {
  0%, 100% { opacity: 0.35; }
  50% { opacity: 1; }
}

/* ------------------------------ screens ---------------------------- */

.screen {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  background: linear-gradient(180deg, rgba(6, 18, 28, 0.55) 0%, rgba(6, 18, 28, 0.78) 100%);
  text-align: center;
  padding: 24px;
  backdrop-filter: blur(3px);
  /* #app sets touch-action: none for the game; menus must still be
     scrollable by touch on the short-landscape backstop below */
  touch-action: pan-y;
}

.screen.hidden {
  display: none;
}

.inner {
  max-width: 560px;
  animation: screenIn 0.5s ease;
}

@keyframes screenIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.kicker {
  font-size: 12px;
  letter-spacing: 0.34em;
  text-transform: uppercase;
  color: var(--dim);
  margin: 0 0 10px;
  font-weight: 700;
}

h1 {
  margin: 0;
  font-family: var(--display);
  font-weight: 800;
  line-height: 0.92;
  letter-spacing: 0.06em;
  display: flex;
  flex-direction: column;
  gap: 0;
  text-shadow: 0 3px 24px rgba(6, 18, 28, 0.9);
}

.t-main {
  font-size: clamp(44px, 11vw, 84px);
  color: var(--ink);
}

.t-accent {
  font-size: clamp(52px, 13vw, 100px);
  font-style: italic;
  color: var(--accent);
  letter-spacing: 0.1em;
}

h2 {
  margin: 0 0 6px;
  font-family: var(--display);
  font-size: clamp(28px, 6vw, 42px);
  letter-spacing: 0.14em;
  font-weight: 800;
}

h2.win {
  color: var(--accent);
}

.tagline {
  color: var(--dim);
  margin: 10px 0 20px;
  letter-spacing: 0.3em;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
}

.howto {
  color: var(--dim);
  font-size: 14px;
  margin-bottom: 26px;
  line-height: 2;
}

.best {
  color: var(--dim);
  font-size: 14px;
  margin-top: 20px;
  letter-spacing: 0.08em;
}

.best.new {
  color: var(--accent);
  font-weight: 800;
  letter-spacing: 0.2em;
}

.fineprint {
  color: var(--dim);
  font-size: 12px;
  margin-top: 16px;
  letter-spacing: 0.06em;
}

#over-stats {
  margin: 18px auto 6px;
  max-width: 340px;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  padding: 9px 4px;
  border-bottom: 1px solid var(--stroke);
}

.stat-row .k {
  color: var(--dim);
  font-size: 13px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-weight: 700;
}

.stat-row .v {
  font-family: var(--display);
  font-weight: 800;
  font-size: 19px;
  letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums;
}

.row {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 18px;
}

kbd {
  display: inline-block;
  padding: 2px 8px;
  border: 1px solid var(--stroke);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.08);
  font: inherit;
  font-size: 12px;
  color: var(--ink);
  margin: 0 2px;
}

.btn {
  appearance: none;
  border: 1px solid var(--stroke);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--ink);
  font: inherit;
  font-weight: 700;
  letter-spacing: 0.08em;
  padding: 13px 28px;
  cursor: pointer;
  transition: transform 0.12s, background 0.12s, border-color 0.12s;
}

.btn:hover {
  background: rgba(255, 255, 255, 0.16);
  border-color: rgba(255, 255, 255, 0.3);
}

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

.btn.primary {
  background: linear-gradient(180deg, #ffb03a, #e0862a);
  border-color: rgba(255, 214, 150, 0.7);
  color: #241304;
  font-size: 17px;
  padding: 15px 34px;
  box-shadow: 0 6px 24px rgba(224, 134, 42, 0.35);
}

.btn.primary:hover {
  background: linear-gradient(180deg, #ffc05c, #eb9434);
}

/* --------------------------- touch controls ------------------------ */
/* Hidden by default; on a coarse pointer they appear while the HUD is up
   (#app.touch-on mirrors hud visibility — set by UI.setHudVisible). */

.touch-zone {
  position: absolute;
  top: 22%;
  bottom: 0;
  width: 58%;
  z-index: 6;
  display: none;
  touch-action: none;
}

#pad-zone {
  left: 0;
}

#bail-zone {
  right: 0;
  width: 42%;
}

/* the dynamic stick — JS drops it under the thumb and slides the nub */
#pad-stick {
  position: absolute;
  width: 112px;
  height: 112px;
  margin: -56px 0 0 -56px; /* centered on the touch point */
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.28);
  background: rgba(9, 22, 34, 0.18);
  opacity: 0;
  transition: opacity 0.15s;
  pointer-events: none;
}

#pad-stick.on {
  opacity: 1;
}

#pad-stick .nub {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 44px;
  height: 44px;
  margin: -22px 0 0 -22px;
  border-radius: 50%;
  background: rgba(255, 176, 58, 0.55);
  border: 1px solid rgba(255, 214, 150, 0.7);
}

#btn-bail {
  position: absolute;
  /* a notched phone in landscape insets ~47px on the right — respect it */
  right: max(18px, env(safe-area-inset-right));
  bottom: max(26px, env(safe-area-inset-bottom));
  width: 104px;
  height: 104px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.4);
  background: rgba(63, 184, 182, 0.35);
  color: var(--ink);
  font: 800 16px var(--display);
  letter-spacing: 0.1em;
  z-index: 7;
  display: none;
  touch-action: none;
  -webkit-appearance: none;
  appearance: none;
}

#btn-bail.held,
#btn-bail:active {
  background: rgba(63, 184, 182, 0.65);
  transform: scale(0.96);
}

/* small pause icon in the top-right strip, clear of both zones (they start
   at 22% height). 52px clears the hub shell's docked bar on phones. */
#btn-pause {
  position: absolute;
  top: 52px;
  right: max(18px, env(safe-area-inset-right));
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid var(--stroke);
  background: var(--panel);
  color: var(--ink);
  font: 700 13px/1 ui-sans-serif, system-ui, sans-serif;
  padding: 0;
  z-index: 7;
  display: none;
  touch-action: none;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
}

@media (pointer: coarse) {
  #app.touch-on .touch-zone,
  #app.touch-on #btn-bail,
  #app.touch-on #btn-pause {
    display: block;
  }
  /* nudge the score clear of the pause icon */
  #hud-stats .stat.right {
    margin-right: 56px;
  }
  /* the keyboard howto row is meaningless on a phone */
  .howto:not(.touch-howto) {
    display: none;
  }
  .touch-howto {
    display: block;
  }
}

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

#coach.hidden {
  display: none;
}

#coach-steer,
#coach-bail {
  position: absolute;
  top: 46%;
  font: 800 13px var(--display);
  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-steer {
  left: 10%;
}

#coach-bail {
  right: max(18px, 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);
  }
}

/* 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 (ui.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: #eaf4ef;
  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: 30;
}
#story-line.on { opacity: 1; }
