:root {
  --ink: #eef2ff;
  --dim: rgba(238, 242, 255, 0.66);
  --faint: rgba(238, 242, 255, 0.22);
  --navy: #030628;
  --blue: #2a40ff;
  --serif: "Bodoni Moda", "Didot", "Bodoni 72", serif;
  --sans: "Inter", system-ui, -apple-system, sans-serif;
  --gut: clamp(16px, 4.5vw, 64px);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html { background: var(--navy); }
body {
  margin: 0;
  background: var(--navy);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
body:not(.entered) { overflow: hidden; }
body.flying { overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; }
#game { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; }
body.flying #game { cursor: grab; }
#track { height: 1500vh; }
body.flying #track { display: none; }
a { color: inherit; }
button { font: inherit; color: inherit; }

/* ---------------------------------------------------------------- header */
.top {
  position: fixed; top: 0; left: 0; right: 0; z-index: 20;
  display: flex; justify-content: space-between; align-items: center; gap: 16px;
  padding: 20px var(--gut);
  pointer-events: none;
  opacity: 0; transition: opacity 1.2s ease 0.4s;
}
body.ready .top { opacity: 1; }
.top > * { pointer-events: auto; }
.mark { font-family: var(--serif); font-style: italic; font-size: 30px; line-height: 1; text-decoration: none; letter-spacing: -0.01em; }
.top nav { display: flex; gap: 6px; align-items: center; }
.nav-btn {
  display: inline-flex; align-items: center; gap: 9px;
  padding: 9px 14px; background: none; border: 0; cursor: pointer;
  font-size: 14px; text-decoration: none; color: var(--dim);
  transition: color 0.2s ease;
}
.nav-btn:hover, .nav-btn:focus-visible { color: var(--ink); outline: none; }
.nav-btn.strong { color: var(--ink); border-bottom: 1px solid var(--faint); }
.bars { display: inline-flex; gap: 2px; align-items: flex-end; height: 11px; }
.bars b { width: 2px; height: 3px; background: currentColor; transition: height 0.3s ease; }
#sound[aria-pressed="true"] .bars b { animation: eq 0.9s ease-in-out infinite; }
#sound[aria-pressed="true"] .bars b:nth-child(2) { animation-delay: -0.3s; }
#sound[aria-pressed="true"] .bars b:nth-child(3) { animation-delay: -0.6s; }
@keyframes eq { 0%, 100% { height: 3px; } 50% { height: 11px; } }

/* ---------------------------------------------------------------- intro gate */
#gate {
  position: fixed; left: 0; right: 0; bottom: 7vh; z-index: 15;
  display: grid; justify-items: center; gap: 22px; text-align: center; padding: 0 16px;
  transition: opacity 0.8s ease, transform 0.8s ease;
}
body.entered #gate { opacity: 0; transform: translateY(12px); pointer-events: none; }
.tag { margin: 0; font-family: var(--serif); font-style: italic; font-size: clamp(20px, 2.4vw, 28px); }
.loading { margin: 0; font-size: 13px; letter-spacing: 0.04em; color: var(--dim); animation: breathe 1.6s ease-in-out infinite; }
body.ready .loading { display: none; }
@keyframes breathe { 50% { opacity: 0.35; } }
.choices { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
#gate .choices { opacity: 0; transform: translateY(8px); transition: opacity 0.8s ease 0.6s, transform 0.8s ease 0.6s; pointer-events: none; }
body.ready #gate .choices { opacity: 1; transform: none; pointer-events: auto; }
.btn {
  display: inline-block; padding: 13px 22px; cursor: pointer;
  font-size: 15px; text-decoration: none; letter-spacing: 0.01em;
  background: rgba(3, 6, 40, 0.18); color: var(--ink);
  border: 1px solid rgba(238, 242, 255, 0.4); border-radius: 999px;
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}
.btn:hover, .btn:focus-visible { border-color: var(--ink); background: rgba(238, 242, 255, 0.1); outline: none; }
.btn.solid { background: var(--ink); color: #0a1270; border-color: var(--ink); }
.btn.solid:hover, .btn.solid:focus-visible { background: #fff; }
.btn.small { padding: 8px 14px; font-size: 13px; }

#hint {
  position: fixed; left: 50%; bottom: 5vh; z-index: 5; transform: translateX(-50%);
  display: grid; justify-items: center; gap: 12px;
  font-size: 13px; color: var(--dim); opacity: 0; transition: opacity 0.6s ease; pointer-events: none;
}
body.entered:not(.scrolled):not(.flying) #hint { opacity: 1; transition-delay: 0.9s; }
#hint i { width: 1px; height: 44px; background: linear-gradient(var(--ink), transparent); animation: drip 1.8s ease-in-out infinite; transform-origin: top; }
@keyframes drip { 0% { transform: scaleY(0); } 60% { transform: scaleY(1); opacity: 1; } 100% { transform: scaleY(1); opacity: 0; } }

/* ---------------------------------------------------------------- depth gauge */
#gauge {
  position: fixed; right: calc(var(--gut) * 0.6); top: 30vh; height: 40vh; z-index: 4;
  opacity: 0; transition: opacity 0.8s ease; pointer-events: none;
}
body.entered #gauge { opacity: 1; }
.rail { position: relative; width: 1px; height: 100%; background: var(--faint); }
/* sea level sits at 600 / 720 of the way down */
.sea { position: absolute; left: -6px; width: 13px; height: 1px; top: 83.3%; background: var(--ink); }
#depth-dot { position: absolute; left: 0; top: 0; width: 1px; height: 100%; transition: none; }
#depth-dot::before { content: ""; position: absolute; left: -3px; top: -3px; width: 7px; height: 7px; border-radius: 50%; background: var(--ink); box-shadow: 0 0 12px rgba(160, 190, 255, 0.9); }
#depth-val { position: absolute; right: 14px; top: -8px; font-size: 12px; white-space: nowrap; font-variant-numeric: tabular-nums; color: var(--dim); }

/* ---------------------------------------------------------------- story beats */
.beat {
  position: fixed; inset: 0; z-index: 3;
  display: flex; padding: 120px var(--gut) 15vh;
  pointer-events: none; opacity: 0; will-change: opacity, transform;
  text-shadow: 0 2px 28px rgba(3, 6, 40, 0.55), 0 0 2px rgba(3, 6, 40, 0.4);
}
body.flying .beat { display: none; }
/* a soft pool of shade behind each block of text, so it reads over the brightest frames */
.beat::before { content: ""; position: absolute; inset: 0; z-index: -1; pointer-events: none; }
.beat.left::before { background: radial-gradient(ellipse 60% 55% at 12% 88%, rgba(3, 6, 40, 0.62), rgba(3, 6, 40, 0) 70%); }
.beat.right::before { background: radial-gradient(ellipse 60% 55% at 88% 88%, rgba(3, 6, 40, 0.62), rgba(3, 6, 40, 0) 70%); }
.beat.center::before { background: radial-gradient(ellipse 62% 50% at 50% 50%, rgba(3, 6, 40, 0.55), rgba(3, 6, 40, 0) 72%); }
.beat > div { max-width: min(33rem, 100%); }
.beat.left { justify-content: flex-start; align-items: flex-end; }
.beat.right { justify-content: flex-end; align-items: flex-end; padding-right: calc(var(--gut) + 64px); }
.beat.center { justify-content: center; align-items: center; text-align: center; }
.beat.wide > div { max-width: min(58rem, 100%); }
.beat.live a, .beat.live button { pointer-events: auto; }
.beat h2 {
  margin: 0; font-family: var(--serif); font-weight: 400; font-style: italic;
  font-size: clamp(34px, 4.6vw, 72px); line-height: 1.02; letter-spacing: -0.015em;
  font-variation-settings: "opsz" 96;
}
.beat h2.huge { font-size: clamp(44px, 7.4vw, 124px); line-height: 0.96; }
.beat h2 em { font-style: normal; }
.beat p { margin: 18px 0 0; max-width: 34rem; font-size: clamp(15px, 1.15vw, 18px); line-height: 1.55; color: rgba(238, 242, 255, 0.86); }
.beat.center p { margin-left: auto; margin-right: auto; max-width: 30rem; }
.beat p.lede { font-family: var(--serif); font-size: clamp(22px, 2.2vw, 34px); line-height: 1.22; color: var(--ink); max-width: 36rem; }
.beat .count { font-size: 15px; color: var(--dim); }
.beat .count .num { display: block; font-family: var(--serif); font-size: clamp(64px, 9vw, 140px); line-height: 1; color: var(--ink); font-style: italic; }
.num { font-variant-numeric: tabular-nums lining-nums; }
.cite {
  display: inline-block; margin-left: 4px; vertical-align: super; font-size: 0.66em; line-height: 1;
  font-family: var(--sans); font-style: normal; color: var(--dim); text-decoration: none;
  padding: 2px 3px; border-bottom: 1px solid var(--faint);
}
.cite:hover, .cite:focus-visible { color: var(--ink); outline: none; }
.beat.cta .choices { margin-top: 30px; }

/* ---------------------------------------------------------------- free roam hud */
#hud, #help, #boostbtn, #rollbtn { display: none; }
body.flying #hud {
  position: fixed; left: var(--gut); right: var(--gut); bottom: 24px; z-index: 6;
  display: flex; align-items: flex-end; gap: 36px; flex-wrap: wrap;
}
.stat .num { display: block; font-family: var(--serif); font-style: italic; font-size: 44px; line-height: 1; text-shadow: 0 0 22px rgba(42, 64, 255, 0.8); }
.stat small { display: block; margin-top: 6px; font-size: 12px; color: var(--dim); max-width: 16ch; line-height: 1.35; }
.hud-actions { display: flex; gap: 8px; margin-left: auto; }
#boost { width: min(200px, 30vw); }
#boost small { font-size: 12px; color: var(--dim); }
#boostbar { height: 2px; background: var(--faint); margin-top: 8px; overflow: hidden; }
#boostfill { height: 100%; background: linear-gradient(90deg, #ffc6de, #fff); transform-origin: left center; }
.pop { animation: pop 0.35s cubic-bezier(0.2, 1.8, 0.4, 1); }
@keyframes pop { 0% { transform: scale(1.25); } 100% { transform: scale(1); } }
body.flying #help {
  display: block; position: fixed; left: var(--gut); top: 84px; z-index: 6;
  font-size: 13px; color: var(--dim); transition: opacity 1s ease; pointer-events: none;
}
#help p { margin: 0; }
#help b { color: var(--ink); font-weight: 500; }
#help .touch { display: none; }
body.nohud #hud, body.nohud #help { opacity: 0; }
.gone { opacity: 0 !important; }
#pause {
  position: fixed; inset: 0; z-index: 7; display: grid; place-items: center;
  background: rgba(3, 6, 40, 0.55); font-family: var(--serif); font-style: italic; font-size: 40px;
  opacity: 0; pointer-events: none; transition: opacity 0.3s ease;
}
#pause.on { opacity: 1; }
#boostbtn, #rollbtn {
  position: fixed; bottom: 110px; z-index: 6; border-radius: 50%;
  border: 1px solid rgba(238, 242, 255, 0.5); background: rgba(42, 64, 255, 0.25);
  font-size: 14px; touch-action: none;
}
#boostbtn { right: 20px; width: 76px; height: 76px; }
#rollbtn { right: 108px; width: 58px; height: 58px; background: rgba(255, 198, 222, 0.16); }
body.flying.flying #gauge { opacity: 0.8; }

@media (pointer: coarse) {
  body.flying #boostbtn, body.flying #rollbtn { display: block; }
  #help .keys { display: none; }
  #help .touch { display: block; }
}

/* ---------------------------------------------------------------- panel */
dialog#more {
  width: min(860px, calc(100vw - 32px)); max-height: calc(100vh - 48px); padding: 0;
  color: var(--ink); background: rgba(5, 10, 60, 0.82); border: 1px solid var(--faint); border-radius: 18px;
  backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
}
dialog#more::backdrop { background: rgba(2, 4, 28, 0.55); }
.sheet { position: relative; padding: clamp(24px, 4vw, 52px); }
.sheet .close { position: absolute; top: 18px; right: 18px; background: none; border: 1px solid var(--faint); border-radius: 999px; padding: 7px 14px; cursor: pointer; font-size: 13px; color: var(--dim); }
.sheet .close:hover, .sheet .close:focus-visible { color: var(--ink); border-color: var(--ink); outline: none; }
.sheet h2 { margin: 0 0 26px; font-family: var(--serif); font-style: italic; font-weight: 400; font-size: clamp(36px, 5vw, 60px); line-height: 1; }
.sheet h3 { margin: 44px 0 14px; font-family: var(--serif); font-style: italic; font-weight: 400; font-size: 28px; }
.acts { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 12px; }
.acts li { padding: 20px; border: 1px solid var(--faint); border-radius: 14px; display: grid; gap: 8px; align-content: start; }
.acts a { font-family: var(--serif); font-size: 23px; font-style: italic; text-decoration: none; }
.acts a:hover { text-decoration: underline; text-underline-offset: 4px; text-decoration-thickness: 1px; }
.acts span { font-size: 14px; line-height: 1.5; color: var(--dim); }
.acts .cite { font-family: var(--sans); font-size: 10px; font-style: normal; }
.srcs { margin: 0; padding-left: 1.4em; display: grid; gap: 9px; font-size: 13px; line-height: 1.5; color: var(--dim); }
.srcs li:target, .srcs li.hl { color: var(--ink); }
.srcs a { color: var(--ink); }
.credit { margin: 36px 0 0; font-size: 13px; color: var(--dim); }

@media (max-width: 720px) {
  .top { padding: 14px 16px; }
  .mark { font-size: 24px; }
  .nav-btn { padding: 8px 8px; font-size: 13px; }
  .top nav a[data-more] { display: none; }
  .beat { padding: 96px 16px 12vh; }
  .beat.right { justify-content: flex-start; padding-right: 48px; }
  .beat.left { padding-right: 48px; }
  #gauge { right: 14px; }
  #depth-val { display: none; }
  body.flying #hud { gap: 18px; bottom: 16px; }
  .stat .num { font-size: 32px; }
  .hud-actions { margin-left: 0; width: 100%; order: 3; }
  #boost { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  #hint i, .loading, #sound[aria-pressed="true"] .bars b { animation: none; }
}
