:root {
  --p: 0; /* flight progress 0..1, set from game.js */
  --ink: #f5f1e8;
  --muted: rgba(245, 241, 232, 0.68);
  --faint: rgba(245, 241, 232, 0.38);
  --card: rgba(13, 12, 32, 0.76);
  --line: rgba(245, 241, 232, 0.14);
  --accent: #ffc15e;
  --accent-ink: #1d1405;
  --warn: #ff9c85;
  --sans: "Avenir Next", "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  color: var(--ink);
  background: #15123a;
  font: 16px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}

/* ---------- Sky: dusk on the ground, black with stars in deep space ---------- */
.sky {
  position: fixed;
  inset: 0;
  z-index: -1;
  background: linear-gradient(to top, #e08a4c 0%, #a5476e 20%, #43306f 50%, #15123a 100%);
}
.sky::after {
  content: "";
  position: absolute;
  inset: 0;
  background: #05060f;
  opacity: calc(var(--p) * 0.94);
  transition: opacity 0.9s ease;
}
.stars,
.stars::before {
  position: absolute;
  inset: 0;
  z-index: 1;
  background-image:
    radial-gradient(1.2px 1.2px at 24px 38px, #fff, transparent 60%),
    radial-gradient(1px 1px at 148px 82px, #fff, transparent 60%),
    radial-gradient(1.4px 1.4px at 212px 190px, #ffe9c4, transparent 60%),
    radial-gradient(1px 1px at 78px 224px, #fff, transparent 60%),
    radial-gradient(1px 1px at 252px 28px, #cfe0ff, transparent 60%);
  background-size: 280px 280px;
}
.stars {
  opacity: calc(0.18 + var(--p) * 0.82);
  transition: opacity 0.9s ease;
  -webkit-mask-image: linear-gradient(to bottom, #000 30%, transparent 92%);
  mask-image: linear-gradient(to bottom, #000 30%, transparent 92%);
}
.stars::before {
  content: "";
  background-size: 410px 410px;
  background-position: 90px 140px;
  opacity: 0.6;
}

/* ---------- Header ---------- */
.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
}
.mark {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: var(--ink);
  text-decoration: none;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.34em;
}
.mark-tag {
  padding: 2px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.ghost {
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(13, 12, 32, 0.4);
  color: var(--ink);
  font: 600 13px var(--sans);
  cursor: pointer;
}
.ghost:hover { border-color: var(--faint); }

/* ---------- Layout ---------- */
.stage {
  flex: 1;
  display: grid;
  grid-template-columns: 170px minmax(0, 560px);
  gap: 40px;
  justify-content: center;
  align-items: center;
  padding: 16px 16px 56px;
}

/* ---------- Altitude gauge ---------- */
.gauge { text-align: right; }
.alt {
  font: 600 44px/1 var(--mono);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
}
.unit {
  margin-left: 6px;
  color: var(--muted);
  font-size: 15px;
  letter-spacing: 0;
}
.layer {
  margin-top: 8px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}
.track {
  position: relative;
  height: 300px;
  margin-top: 28px;
}
.rail,
.fill {
  position: absolute;
  right: 6px;
  bottom: 0;
  width: 2px;
  border-radius: 2px;
}
.rail { top: 0; background: var(--line); }
.fill {
  height: calc(var(--p) * 100%);
  background: var(--accent);
  transition: height 0.8s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.marker {
  position: absolute;
  right: 0;
  bottom: calc(var(--p) * 100% - 7px);
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(255, 193, 94, 0.2), 0 0 18px rgba(255, 193, 94, 0.7);
  transition: bottom 0.8s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.tick {
  position: absolute;
  right: 0;
  bottom: calc(var(--t) * 100%);
  padding-right: 24px;
  transform: translateY(50%);
  color: var(--faint);
  font-size: 11px;
  letter-spacing: 0.04em;
  white-space: nowrap;
  transition: color 0.4s ease;
}
.tick::after {
  content: "";
  position: absolute;
  right: 3px;
  top: 50%;
  width: 8px;
  height: 1px;
  background: currentColor;
}
.tick.on { color: var(--ink); }

/* ---------- Panel ---------- */
.panel {
  display: flex;
  flex-direction: column;
  min-height: 400px;
  padding: 32px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--card);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.35);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
}
.step {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}
.dots {
  display: flex;
  gap: 6px;
  margin: 14px 0 24px;
}
.dots span {
  flex: 1;
  height: 3px;
  border-radius: 2px;
  background: var(--line);
}
.dots .done { background: var(--accent); }
.dots .now { background: var(--ink); }

.prompt {
  margin: 0 0 26px;
  font-size: clamp(28px, 5vw, 40px);
  font-weight: 650;
  line-height: 1.12;
  letter-spacing: -0.015em;
  text-wrap: balance;
}

.answer { display: flex; gap: 10px; }
.answer input {
  flex: 1;
  min-width: 0;
  height: 54px;
  padding: 0 18px;
  border: 1px solid var(--line);
  border-radius: 14px;
  outline: none;
  background: rgba(255, 255, 255, 0.06);
  color: var(--ink);
  font: 18px var(--sans);
}
.answer input::placeholder { color: var(--faint); }
.answer input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(255, 193, 94, 0.22);
}

.btn {
  height: 54px;
  padding: 0 22px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--ink);
  font: 600 16px var(--sans);
  white-space: nowrap;
  cursor: pointer;
}
.btn:hover { filter: brightness(1.08); }
.btn.primary {
  border-color: transparent;
  background: var(--accent);
  color: var(--accent-ink);
}
.btn:focus-visible,
.ghost:focus-visible,
.link:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

.msg {
  min-height: 22px;
  margin: 12px 0 0;
  color: var(--warn);
  font-size: 14px;
}
.msg.ok { color: var(--muted); }
.link {
  align-self: flex-start;
  margin-top: auto;
  padding: 8px 0 0;
  border: 0;
  background: none;
  color: var(--muted);
  font: 14px var(--sans);
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}
.link:hover { color: var(--ink); }

.shake { animation: shake 0.32s ease; }
@keyframes shake {
  25% { transform: translateX(-6px); }
  50% { transform: translateX(5px); }
  75% { transform: translateX(-3px); }
}

.rules {
  margin: 0 0 28px;
  padding-left: 20px;
  color: var(--muted);
}
.rules li { margin: 6px 0; padding-left: 4px; }
.rules li::marker { color: var(--accent); font-weight: 600; }
.panel > .btn { align-self: flex-start; margin-top: auto; }

/* ---------- Reveal ---------- */
.result {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 6px 16px;
  margin: 18px 0 24px;
}
.your {
  font-size: 30px;
  font-weight: 650;
  line-height: 1.15;
  overflow-wrap: anywhere;
}
.gain {
  color: var(--accent);
  font: 600 32px/1.15 var(--mono);
  white-space: nowrap;
}
.gain.zero { color: var(--faint); }
.rarity {
  grid-column: 1 / -1;
  margin: 0;
  color: var(--muted);
  font-size: 15px;
}
.chip {
  display: inline-block;
  margin-right: 8px;
  padding: 1px 9px;
  border: 1px solid var(--accent);
  border-radius: 999px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.board h2 {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}
.bars {
  display: grid;
  gap: 8px;
  margin: 0 0 26px;
  padding: 0;
  list-style: none;
}
.bars li {
  display: grid;
  grid-template-columns: minmax(96px, 36%) 1fr 44px;
  align-items: center;
  gap: 10px;
  font-size: 14px;
}
.bars .lbl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bars .bar {
  position: relative;
  height: 8px;
  overflow: hidden;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.08);
}
.bars .bar::after {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: var(--w);
  min-width: 3px;
  border-radius: 4px;
  background: rgba(245, 241, 232, 0.55);
}
.bars .pct {
  color: var(--muted);
  font: 13px var(--mono);
  text-align: right;
}
.bars .me .lbl { color: var(--accent); font-weight: 600; }
.bars .me .bar::after { background: var(--accent); }
.bars .gap { color: var(--faint); font-size: 12px; line-height: 1; }

/* ---------- Summary ---------- */
.total {
  margin: 10px 0 0;
  font: 600 clamp(44px, 9vw, 68px) / 1 var(--mono);
  letter-spacing: -0.04em;
}
.total small { margin-left: 8px; color: var(--muted); font-size: 0.32em; letter-spacing: 0; }
.reached { margin: 10px 0 20px; color: var(--accent); font-size: 18px; }
.recap {
  margin: 0 0 24px;
  padding: 0;
  border-top: 1px solid var(--line);
  list-style: none;
}
.recap li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0 14px;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
}
.recap .q { color: var(--muted); font-size: 13px; }
.recap .a { font-size: 16px; overflow-wrap: anywhere; }
.recap .a.none { color: var(--faint); }
.recap .g {
  grid-column: 2;
  grid-row: 1 / 3;
  align-self: center;
  color: var(--accent);
  font: 600 16px var(--mono);
}
.recap .g.zero { color: var(--faint); }
.actions { display: flex; flex-wrap: wrap; gap: 10px; }

/* ---------- Logbook ---------- */
dialog {
  width: min(440px, calc(100vw - 32px));
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: #12112b;
  color: var(--ink);
}
dialog::backdrop { background: rgba(5, 6, 15, 0.62); }
dialog h2 { margin: 0 0 18px; font-size: 22px; }
.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px 16px;
  margin: 0 0 26px;
}
.stats div.wide { grid-column: 1 / -1; }
.stats dt { color: var(--muted); font-size: 12px; letter-spacing: 0.1em; text-transform: uppercase; }
.stats dd { margin: 4px 0 0; font: 600 24px var(--mono); overflow-wrap: anywhere; }
.stats dd.text { font: 600 18px var(--sans); }
.stats dd small { color: var(--muted); font: 13px var(--sans); }

/* ---------- Narrow screens: gauge becomes a strip on top ---------- */
@media (max-width: 760px) {
  .stage {
    grid-template-columns: minmax(0, 560px);
    gap: 18px;
    align-items: start;
    padding-top: 4px;
  }
  .gauge { text-align: left; }
  .readout { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
  .alt { font-size: 32px; }
  .layer { margin-top: 0; }
  .track { height: 14px; margin-top: 12px; }
  .rail, .fill { top: 6px; right: auto; bottom: auto; left: 0; height: 2px; }
  .rail { width: 100%; }
  .fill { width: calc(var(--p) * 100%); transition-property: width; }
  .marker { top: 0; right: auto; bottom: auto; left: calc(var(--p) * 100% - 7px); transition-property: left; }
  .tick {
    top: 3px;
    right: auto;
    bottom: auto;
    left: calc(var(--t) * 100%);
    width: 1px;
    height: 8px;
    padding: 0;
    overflow: hidden;
    transform: none;
    background: currentColor;
    font-size: 0;
  }
  .tick::after { display: none; }
  .panel { min-height: 0; padding: 24px 20px; }
  .answer { flex-direction: column; }
  .link { margin-top: 18px; }
  .panel > .btn { margin-top: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
