:root {
  --bg: #ffffff;
  --ink: #121317;
  --ink-2: #5f646e;
  --ink-3: #a1a5ad;
  --line: #ebedf0;
  --a: #5f86d3;
  --serif: 'Instrument Serif', Georgia, serif;
  --sans: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, monospace;
  --spring: cubic-bezier(.34, 1.56, .64, 1);
  --ease: cubic-bezier(.22, 1, .36, 1);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body { background: var(--bg); color: var(--ink); font-family: var(--sans); -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; cursor: pointer; }

/* ---------- top bar ---------- */
.topbar {
  position: fixed; inset: 0 0 auto 0; z-index: 20;
  display: flex; justify-content: space-between; align-items: center;
  padding: 22px 28px; pointer-events: none;
}
.brand { display: flex; align-items: center; gap: 11px; color: inherit; text-decoration: none; pointer-events: auto; }
.brand img { filter: drop-shadow(0 4px 8px rgba(30, 35, 50, .14)); }
.wordmark { display: flex; align-items: baseline; gap: 7px; line-height: 1; }
.w1 { font-family: var(--serif); font-size: 27px; letter-spacing: -.01em; }
.w2 { font-size: 11px; font-weight: 600; letter-spacing: .2em; text-transform: uppercase; color: var(--ink-3); }
.counter { font-family: var(--mono); font-size: 12px; color: var(--ink-3); }
.counter b { color: var(--ink); font-weight: 500; }

/* ---------- stage ---------- */
.stage { position: fixed; inset: 0; }
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; transition: opacity 1.2s; touch-action: pan-y; }
body.ready .stage canvas { opacity: 1; }
.loading {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  font-family: var(--serif); font-style: italic; font-size: 22px; color: var(--ink-3);
  animation: breathe 1.4s ease-in-out infinite; transition: opacity .6s;
}
.loading.done { animation: none; opacity: 0; pointer-events: none; }
@keyframes breathe { 50% { opacity: .35; } }

/* ---------- scene heading ---------- */
.scene-head {
  position: absolute; z-index: 5; top: 92px; left: 0; right: 0;
  text-align: center; pointer-events: none;
  transition: opacity .6s, transform .8s var(--ease);
}
.eyebrow { margin: 0 0 10px; font-family: var(--mono); font-size: 12px; color: var(--ink-3); }
.scene-head h1, .end-card h1 {
  margin: 0; font-family: var(--serif); font-weight: 400;
  font-size: clamp(42px, 6vw, 76px); line-height: .98; letter-spacing: -.025em;
}
.intro { margin: 14px auto 0; max-width: 440px; padding: 0 20px; font-size: 15px; line-height: 1.55; color: var(--ink-2); transition: opacity .5s; }
.scene-head.focused { transform: translateY(-14px) scale(.78); }
.scene-head.focused .intro { opacity: 0; }
.scene-head.off { opacity: 0; }
body:not(.ready) .scene-head { opacity: 0; transform: translateY(12px); }

/* ---------- end card ---------- */
.end-card {
  position: absolute; z-index: 5; inset: 0; display: grid; place-content: center; text-align: center;
  opacity: 0; pointer-events: none; transform: scale(.96); transition: opacity .7s, transform .9s var(--ease);
}
.end-card.on { opacity: 1; pointer-events: auto; transform: none; }
.end-card h1 em { color: var(--ink-3); }
.pill {
  justify-self: center; margin-top: 28px; padding: 11px 20px;
  border: 1px solid var(--line); border-radius: 999px; background: #fff; font-size: 14px;
  transition: transform .3s var(--ease), background .3s;
}
.pill:hover { background: #f6f7f9; transform: translateY(-1px); }

/* ---------- bubble ---------- */
.bubble {
  position: absolute; z-index: 6; width: 280px; padding: 18px 20px 14px;
  border-radius: 22px;
  background: rgba(255, 255, 255, .84);
  -webkit-backdrop-filter: blur(18px) saturate(1.4); backdrop-filter: blur(18px) saturate(1.4);
  border: 1px solid rgba(20, 25, 35, .07);
  box-shadow: 0 28px 70px -28px rgba(20, 30, 50, .32), 0 2px 6px rgba(20, 30, 50, .04);
  opacity: 0; transform: scale(.55); pointer-events: none;
  transition: opacity .25s, transform .65s var(--spring);
}
.bubble.on { opacity: 1; transform: none; pointer-events: auto; }
.bubble .idx { display: flex; align-items: center; gap: 8px; font-family: var(--mono); font-size: 11px; color: var(--a); }
.bubble .idx::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--a); box-shadow: 0 0 0 4px color-mix(in srgb, var(--a) 18%, transparent); }
.bubble h2 { margin: 9px 0 0; font-size: 22px; font-weight: 600; letter-spacing: -.02em; }
.bubble em { display: block; margin-top: 1px; font-family: var(--serif); font-size: 19px; color: var(--ink-2); }
.bubble ul { margin: 12px 0 0; padding: 12px 0 0; border-top: 1px solid var(--line); list-style: none; display: grid; gap: 7px; }
.bubble li { display: flex; gap: 10px; font-size: 14px; color: #363a42; }
.bubble li::before { content: ''; flex: none; width: 5px; height: 5px; margin-top: 7px; border-radius: 50%; background: color-mix(in srgb, var(--a) 70%, white); }
.bubble .more { display: grid; grid-template-rows: 0fr; transition: grid-template-rows .5s var(--ease); }
.bubble .more-inner { overflow: hidden; }
.bubble.expanded .more { grid-template-rows: 1fr; }
.bubble .more p { margin: 12px 0 0; font-size: 13.5px; line-height: 1.55; color: var(--ink-2); }
.bubble .fact { padding: 10px 12px; border-radius: 12px; background: color-mix(in srgb, var(--a) 9%, white); color: #3a3e46 !important; }
.bubble .fact span { display: block; margin-bottom: 3px; font-family: var(--mono); font-size: 10.5px; color: var(--a); }
.more-btn {
  margin-top: 12px; padding: 0; border: 0; background: none;
  font-size: 12.5px; font-weight: 500; color: var(--ink-2);
}
.more-btn span { display: inline-block; margin-left: 2px; color: var(--a); }
.more-btn:hover { color: var(--ink); }

.wire { position: absolute; inset: 0; z-index: 4; width: 100%; height: 100%; pointer-events: none; opacity: 0; transition: opacity .4s; }
.wire.on { opacity: 1; }
.wire line { stroke: var(--a); stroke-width: 1; stroke-dasharray: 3 4; }
.wire circle { fill: #fff; stroke: var(--a); stroke-width: 2; }

/* ---------- scene change ---------- */
.veil {
  position: absolute; inset: 0; z-index: 7; pointer-events: none; opacity: 0;
  background: radial-gradient(circle at 50% 50%, #fff 0, #fff 45%, rgba(255, 255, 255, .92) 100%);
}
.scale-jump {
  position: absolute; z-index: 8; left: 50%; top: 50%; transform: translate(-50%, -50%);
  text-align: center; opacity: 0; pointer-events: none; white-space: nowrap;
}
.sj-cap { margin: 0 0 12px; font-family: var(--mono); font-size: 12px; letter-spacing: .08em; color: var(--ink-3); }
.sj-nums { margin: 0; font-family: var(--serif); font-size: clamp(40px, 6vw, 68px); line-height: 1; letter-spacing: -.02em; color: var(--ink-3); }
.sj-nums span { margin: 0 .2em; color: var(--ink-3); }
.sj-nums b { font-weight: 400; color: var(--ink); }
body.switching .scene-head, body.switching .bubble, body.switching .wire { opacity: 0 !important; transition: opacity .35s; }

/* ---------- scene arrows (jump straight to the previous / next scene) ---------- */
.scene-nav {
  position: fixed; z-index: 20; top: 50%;
  display: flex; align-items: center; gap: 0;
  height: 56px; padding: 0 6px; border-radius: 999px;
  border: 1px solid var(--line); background: rgba(255, 255, 255, .88);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  box-shadow: 0 10px 30px -18px rgba(20, 30, 50, .3);
  transform: translateY(-50%);
  transition: opacity .4s, transform .5s var(--ease), box-shadow .3s, gap .4s var(--ease);
}
.scene-nav.prev { left: 24px; }
.scene-nav.next { right: 24px; }
.scene-nav.off { opacity: 0; pointer-events: none; }
.scene-nav.prev.off { transform: translate(-12px, -50%); }
.scene-nav.next.off { transform: translate(12px, -50%); }
.sn-arrow { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 50%; font-size: 18px; transition: background .3s, color .3s; }
.sn-label { display: grid; overflow: hidden; max-width: 0; opacity: 0; white-space: nowrap; text-align: left; transition: max-width .5s var(--ease), opacity .3s; }
.scene-nav.prev .sn-label { text-align: left; }
.scene-nav.next .sn-label { text-align: right; }
.sn-label small { font-family: var(--mono); font-size: 10.5px; color: var(--ink-3); }
.sn-label b { font-family: var(--serif); font-weight: 400; font-size: 20px; line-height: 1.1; letter-spacing: -.01em; }
.scene-nav:hover, .scene-nav:focus-visible { box-shadow: 0 16px 40px -18px rgba(20, 30, 50, .4); }
.scene-nav:hover .sn-label, .scene-nav:focus-visible .sn-label { max-width: 220px; opacity: 1; padding: 0 10px; }
.scene-nav:hover .sn-arrow { background: var(--ink); color: #fff; }
.scene-nav.nudge .sn-arrow { animation: nudge 1.6s ease-in-out infinite; background: var(--ink); color: #fff; }
.scene-nav.prev.nudge .sn-arrow { animation-name: nudge-l; }
@keyframes nudge { 50% { transform: translateX(4px); } }
@keyframes nudge-l { 50% { transform: translateX(-4px); } }
body.switching .scene-nav { pointer-events: none; }

/* ---------- controls ---------- */
.controls {
  position: fixed; z-index: 20; left: 50%; bottom: 26px; transform: translateX(-50%);
  display: grid; justify-items: center; gap: 14px;
}
.stepper { display: flex; align-items: center; gap: 14px; }
.stepper button {
  width: 46px; height: 46px; border-radius: 50%;
  border: 1px solid var(--line); background: rgba(255, 255, 255, .9); font-size: 17px;
  transition: transform .3s var(--ease), background .3s, opacity .3s;
}
.stepper button:hover:not(:disabled) { transform: scale(1.07); background: #f5f6f8; }
.stepper button:disabled { opacity: .3; cursor: default; }
#next:not(:disabled) { background: var(--ink); color: #fff; border-color: var(--ink); }
#next:hover:not(:disabled) { background: #2a2c33; }
.step-label { min-width: 150px; text-align: center; font-size: 14px; color: var(--ink-2); }
.step-label b { margin-right: 9px; font-family: var(--mono); font-weight: 500; font-size: 12px; color: var(--ink); }
.step-label .muted { color: var(--ink-3); }
.ticks { display: flex; gap: 6px; height: 6px; }
.ticks button {
  width: 22px; height: 4px; padding: 0; border: 0; border-radius: 99px;
  background: #e4e6ea; transition: background .4s, width .5s var(--ease);
}
.ticks button.seen { background: color-mix(in srgb, var(--c) 45%, white); }
.ticks button.on { width: 36px; background: var(--c); }

/* ---------- small screens ---------- */
@media (max-width: 640px) {
  .topbar { padding: 18px 16px; }
  .w1 { font-size: 23px; }
  .w2 { display: none; }
  .scene-head { top: 78px; }
  .intro { font-size: 14px; }
  .bubble { width: min(320px, calc(100vw - 32px)); }
  .controls { bottom: 20px; }
  .scene-nav { height: 42px; padding: 0 2px; top: 40%; }
  .scene-nav.prev { left: 8px; } .scene-nav.next { right: 8px; }
  .sn-arrow { width: 36px; height: 36px; font-size: 15px; }
  .scene-nav:hover .sn-label { max-width: 0; opacity: 0; padding: 0; }
  .controls { left: 50%; }
  .stepper { gap: 8px; }
  .stepper button { width: 40px; height: 40px; }
  .step-label { min-width: 0; max-width: 150px; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}

@media (prefers-reduced-motion: reduce) {
  .bubble { transition: opacity .2s; transform: none; }
}
