:root {
  --ink: #eef3f9;
  --ink-dim: #9dadbf;
  --panel: rgba(11, 20, 31, 0.62);
  --panel-solid: #0d1622;
  --edge: rgba(174, 199, 226, 0.22);
  --warm: #e8703a;
  --cold: #6fb2e8;
  --good: #63c68b;
  --bad: #e2574a;
  --ui: clamp(11px, 1.35vmin, 15px);
  --radius: 12px;
  --shadow: 0 10px 34px rgba(2, 7, 14, 0.45);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #0d1622;
  color: var(--ink);
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  touch-action: none;
}

#stage {
  position: fixed;
  inset: 0;
  overflow: hidden;
}

#scene {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
  touch-action: none;
}
#scene.grabbing { cursor: grabbing; }

.hidden { display: none !important; }

/* ============ HUD ============ */
#hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  font-size: var(--ui);
  padding: clamp(10px, 2.2vmin, 22px);
  padding-top: max(clamp(10px, 2.2vmin, 22px), env(safe-area-inset-top));
  padding-bottom: max(clamp(10px, 2.2vmin, 22px), env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  padding: 0.7em 0.95em;
  backdrop-filter: blur(9px);
  -webkit-backdrop-filter: blur(9px);
  box-shadow: var(--shadow);
}

.hud-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 1em; }
.hud-bottom { display: flex; justify-content: space-between; align-items: flex-end; gap: 1em; }

.label {
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.78em;
  color: var(--ink-dim);
  font-weight: 600;
}
.value { font-size: 2.1em; font-weight: 650; line-height: 1.05; letter-spacing: -0.01em; }
.value .unit { font-size: 0.44em; color: var(--ink-dim); margin-left: 0.2em; font-weight: 500; }
.sub { font-size: 0.82em; color: var(--ink-dim); margin-top: 0.15em; }
.mono { font-variant-numeric: tabular-nums; font-family: "SF Mono", ui-monospace, "Cascadia Code", Menlo, monospace; }
.run-panel { text-align: right; }

/* altitude rail */
#progress {
  position: absolute;
  right: clamp(10px, 2.2vmin, 22px);
  top: 50%;
  transform: translateY(-50%);
  height: min(46vh, 340px);
  width: 30px;
  display: flex;
  justify-content: center;
}
#progress .track {
  width: 5px;
  height: 100%;
  background: rgba(10, 18, 28, 0.55);
  border: 1px solid var(--edge);
  border-radius: 4px;
  position: relative;
  overflow: hidden;
}
#progress .fill {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 0%;
  background: linear-gradient(to top, var(--cold), #eaf4ff);
  transition: height 0.15s linear;
}
#progress .markers { position: absolute; inset: 0; }
#progress .marker {
  position: absolute;
  right: 0;
  width: 18px;
  height: 2px;
  background: var(--ink-dim);
  border-radius: 2px;
}
#progress .marker.reached { background: var(--warm); box-shadow: 0 0 8px rgba(232, 112, 58, 0.8); height: 3px; }
#progress .marker.summit { width: 24px; background: var(--ink); }

/* gauges */
.gauges { display: flex; flex-direction: column; gap: 0.55em; min-width: min(240px, 40vw); }
.gauge {
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  padding: 0.55em 0.8em;
  backdrop-filter: blur(9px);
  -webkit-backdrop-filter: blur(9px);
  box-shadow: var(--shadow);
}
.gauge-head {
  display: flex;
  justify-content: space-between;
  font-size: 0.8em;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-dim);
  margin-bottom: 0.35em;
  font-weight: 600;
}
.bar { height: 8px; border-radius: 5px; background: rgba(6, 12, 20, 0.7); overflow: hidden; }
.bar-fill { height: 100%; width: 100%; border-radius: 5px; transition: width 0.1s linear, background-color 0.3s; }
.bar-fill.stamina { background: linear-gradient(90deg, #4e9a6a, var(--good)); }
.bar-fill.warmth { background: linear-gradient(90deg, #b8641f, var(--warm)); }
.bar-fill.low { background: linear-gradient(90deg, #8d2b22, var(--bad)) !important; }

/* slope meter */
.slope-panel { min-width: min(190px, 36vw); }
.slope-meter {
  position: relative;
  height: 10px;
  margin: 0.5em 0 0.4em;
  border-radius: 5px;
  overflow: hidden;
  display: flex;
  border: 1px solid var(--edge);
}
.zone { height: 100%; }
.zone.walkable { flex: 27; background: rgba(99, 198, 139, 0.62); }
.zone.climbable { flex: 30; background: rgba(232, 176, 58, 0.62); }
.zone.deadly { flex: 33; background: rgba(226, 87, 74, 0.68); }
.needle {
  position: absolute;
  top: -3px;
  width: 3px;
  height: 16px;
  background: var(--ink);
  border-radius: 2px;
  box-shadow: 0 0 6px rgba(0, 0, 0, 0.7);
  transform: translateX(-50%);
  left: 0%;
  transition: left 0.09s linear;
}
.slope-read { font-size: 0.85em; color: var(--ink-dim); display: flex; align-items: baseline; gap: 0.35em; }
.slope-read #slope-num { color: var(--ink); font-size: 1.15em; font-weight: 650; }

/* toast + warnings */
#toast {
  position: absolute;
  left: 50%;
  top: 16%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4em;
  pointer-events: none;
}
#toast .msg {
  background: rgba(9, 16, 26, 0.86);
  border: 1px solid var(--edge);
  border-radius: 999px;
  padding: 0.5em 1.2em;
  font-size: 1.05em;
  font-weight: 600;
  letter-spacing: 0.02em;
  backdrop-filter: blur(9px);
  -webkit-backdrop-filter: blur(9px);
  box-shadow: var(--shadow);
  animation: rise 0.35s ease-out;
  white-space: nowrap;
}
#toast .msg.warm { color: var(--warm); }
#toast .msg.cold { color: var(--cold); }
#toast .msg.bad { color: var(--bad); }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

#rockfall {
  position: absolute;
  left: 50%;
  top: 30%;
  transform: translateX(-50%);
  color: var(--bad);
  font-weight: 800;
  letter-spacing: 0.2em;
  font-size: 1.25em;
  text-shadow: 0 2px 14px rgba(0, 0, 0, 0.8);
  animation: pulse 0.7s ease-in-out infinite;
}
@keyframes pulse { 0%, 100% { opacity: 0.45; } 50% { opacity: 1; } }

#vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  background: radial-gradient(ellipse at center, rgba(0,0,0,0) 38%, rgba(90, 20, 14, 0.85) 100%);
  transition: opacity 0.35s ease;
}

#menu-btn {
  position: absolute;
  right: clamp(10px, 2.2vmin, 22px);
  bottom: max(clamp(10px, 2.2vmin, 22px), env(safe-area-inset-bottom));
  pointer-events: auto;
  width: 2.6em; height: 2.6em;
  border-radius: 50%;
  border: 1px solid var(--edge);
  background: var(--panel);
  color: var(--ink);
  font-size: 1em;
  cursor: pointer;
  backdrop-filter: blur(9px);
  -webkit-backdrop-filter: blur(9px);
}
#menu-btn:hover { background: rgba(30, 46, 66, 0.8); }

/* touch controls */
#touch { position: absolute; inset: 0; pointer-events: none; }
#stick {
  position: absolute;
  width: 108px; height: 108px;
  border-radius: 50%;
  border: 2px solid rgba(200, 220, 240, 0.35);
  background: rgba(10, 18, 28, 0.3);
  transform: translate(-50%, -50%);
  display: none;
}
#stick-knob {
  position: absolute;
  left: 50%; top: 50%;
  width: 46px; height: 46px;
  margin: -23px 0 0 -23px;
  border-radius: 50%;
  background: rgba(226, 238, 250, 0.5);
}
#anchor-btn {
  position: absolute;
  right: max(18px, env(safe-area-inset-right));
  bottom: max(96px, calc(env(safe-area-inset-bottom) + 96px));
  width: 92px; height: 92px;
  border-radius: 50%;
  border: 2px solid var(--edge);
  background: rgba(20, 34, 50, 0.72);
  color: var(--ink);
  font-weight: 800;
  letter-spacing: 0.1em;
  font-size: 13px;
  pointer-events: auto;
  -webkit-user-select: none;
  user-select: none;
}
#anchor-btn.on { background: var(--warm); color: #14202e; }

/* ============ overlays ============ */
.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 50% 30%, rgba(18, 34, 54, 0.72), rgba(5, 10, 17, 0.92));
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  z-index: 5;
  padding: 20px;
}

/* The view you earned should still be visible behind the scorecard. */
#result, #paused {
  background: linear-gradient(180deg, rgba(6, 12, 20, 0.3), rgba(6, 12, 20, 0.62));
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

.card {
  width: min(560px, 92vw);
  max-height: 92vh;
  overflow-y: auto;
  background: linear-gradient(180deg, rgba(19, 32, 48, 0.95), rgba(11, 19, 30, 0.97));
  border: 1px solid var(--edge);
  border-radius: 18px;
  padding: clamp(20px, 4vmin, 36px);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
  text-align: center;
}

.card h1 {
  margin: 0 0 0.1em;
  font-size: clamp(38px, 8vmin, 64px);
  letter-spacing: 0.22em;
  font-weight: 800;
  background: linear-gradient(180deg, #ffffff, #9fc2e4);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.card h2 { margin: 0 0 0.4em; font-size: clamp(24px, 5vmin, 34px); letter-spacing: 0.06em; }
.tagline { margin: 0 0 1.4em; color: var(--ink-dim); font-size: 0.98em; font-style: italic; }
.brief { text-align: left; font-size: 0.96em; line-height: 1.6; color: #cfdcea; margin-bottom: 1.3em; }
.brief b { color: var(--ink); }

.keys {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 0.7em 1em;
  margin-bottom: 1.5em;
  font-size: 0.86em;
  color: var(--ink-dim);
}
.keys > div { display: flex; align-items: center; gap: 0.35em; justify-content: center; flex-wrap: wrap; }
kbd {
  display: inline-block;
  min-width: 1.9em;
  padding: 0.25em 0.45em;
  border-radius: 6px;
  border: 1px solid var(--edge);
  border-bottom-width: 2px;
  background: rgba(255, 255, 255, 0.07);
  color: var(--ink);
  font-family: inherit;
  font-size: 0.9em;
  font-weight: 600;
}
.keys span { margin-left: 0.2em; }

button {
  font: inherit;
  font-weight: 650;
  padding: 0.75em 1.6em;
  border-radius: 999px;
  border: 1px solid var(--edge);
  background: rgba(255, 255, 255, 0.06);
  color: var(--ink);
  cursor: pointer;
  transition: transform 0.12s ease, background 0.2s ease;
}
button:hover { background: rgba(255, 255, 255, 0.12); transform: translateY(-1px); }
button:active { transform: translateY(0); }
button.primary {
  background: linear-gradient(180deg, #ef8248, var(--warm));
  color: #16222f;
  border-color: transparent;
  box-shadow: 0 8px 24px rgba(232, 112, 58, 0.32);
}
button.primary:hover { background: linear-gradient(180deg, #f79155, #f07a42); }

.row { display: flex; gap: 0.7em; justify-content: center; flex-wrap: wrap; margin-top: 0.4em; }

.seed-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5em;
  margin-top: 1.3em;
  font-size: 0.84em;
  color: var(--ink-dim);
}
.seed-row input {
  font: inherit;
  width: 9em;
  padding: 0.45em 0.7em;
  border-radius: 8px;
  border: 1px solid var(--edge);
  background: rgba(0, 0, 0, 0.32);
  color: var(--ink);
  text-align: center;
}
.seed-row button { padding: 0.45em 1em; font-size: 0.95em; }
.fineprint { color: #6f8096; font-size: 0.78em; margin: 1.2em 0 0; }

.stats { display: grid; grid-template-columns: 1fr auto; gap: 0.45em 1.2em; margin: 1.2em 0 1.5em; font-size: 0.94em; text-align: left; }
.stats dt { color: var(--ink-dim); }
.stats dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; font-weight: 650; }
.stats dd.good { color: var(--good); }
.stats dd.warm { color: var(--warm); }

.key-help { font-size: 0.84em; color: var(--ink-dim); line-height: 2.1; margin-bottom: 1.2em; }

#result-line { color: #cfdcea; margin: 0 0 0.4em; line-height: 1.6; }

/* loading */
.loader { text-align: center; }
.peak-mark {
  width: 72px; height: 52px;
  margin: 0 auto 18px;
  clip-path: polygon(0% 100%, 38% 8%, 58% 46%, 72% 26%, 100% 100%);
  background: linear-gradient(180deg, #ffffff, #7ea6cd);
  animation: breathe 1.7s ease-in-out infinite;
}
@keyframes breathe { 0%, 100% { opacity: 0.45; transform: translateY(2px); } 50% { opacity: 1; transform: none; } }
#loading-text { color: var(--ink-dim); letter-spacing: 0.1em; font-size: 0.9em; text-transform: uppercase; }

.noscript { color: #eef3f9; text-align: center; padding: 3em; font-size: 1.1em; }

@media (max-width: 640px) {
  .value { font-size: 1.7em; }
  #progress { height: 34vh; }
  .gauges { min-width: 46vw; }
  .slope-panel { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  #rockfall, .peak-mark { animation: none; }
  #toast .msg { animation: none; }
}
