/* Layout: a full-screen 3D stage. One slide at a time; its text panel sits on the left (desktop)
   or as a bottom sheet (phone) while the camera flies to that slide's formation on the right. */
:root {
  --void: #05070d;
  --ink: #e9eef7;
  --dim: #8d97ab;
  --hair: rgba(150, 175, 220, 0.16);
  --glass: rgba(9, 13, 24, 0.74);
  --cyan: #5ee7f0;
  --amber: #ffb547;
  --violet: #9a8cff;
  --display: "Unbounded", "Arial Black", system-ui, sans-serif;
  --body: "Manrope", "Segoe UI", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace;
  --dir: 1;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
html { background: var(--void); }
body {
  margin: 0; overflow: hidden;
  background: var(--void); color: var(--ink);
  font: 400 17px/1.6 var(--body);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
a { color: var(--cyan); }
a:focus-visible, summary:focus-visible, button:focus-visible { outline: 2px solid var(--cyan); outline-offset: 3px; }

#field { position: fixed; inset: 0; width: 100%; height: 100%; display: block; z-index: 0; }
.vignette { position: fixed; inset: 0; z-index: 1; pointer-events: none; background: radial-gradient(ellipse at 65% 50%, transparent 45%, rgba(5,7,13,0.65) 100%); }

/* 3D-anchored labels, positioned every frame by field3d.js */
.labels3d { position: fixed; inset: 0; z-index: 2; pointer-events: none; overflow: hidden; }
.lbl3d {
  position: absolute; left: 0; top: 0; white-space: nowrap;
  font: 500 11px/1 var(--mono); letter-spacing: .08em; text-transform: uppercase;
  color: var(--ink); padding: 4px 7px; border: 1px solid var(--hair); background: rgba(5,7,13,0.55);
  border-radius: 2px; transition: opacity .5s ease; opacity: 0; will-change: transform;
}
.lbl3d.c { color: var(--cyan); border-color: rgba(94,231,240,.35); }
.lbl3d.a { color: var(--amber); border-color: rgba(255,181,71,.35); }
.lbl3d.v { color: var(--violet); border-color: rgba(154,140,255,.35); }

/* HUD */
.hud {
  position: fixed; top: 0; left: 0; right: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: calc(14px + env(safe-area-inset-top, 0px)) max(20px, env(safe-area-inset-right, 0px)) 14px max(20px, env(safe-area-inset-left, 0px));
  font: 500 12px/1 var(--mono); letter-spacing: .14em; text-transform: uppercase;
  background: linear-gradient(var(--void), rgba(5,7,13,0));
}
.brand { font-family: var(--display); font-weight: 600; letter-spacing: .08em; font-size: 13px; }
.brand span { color: var(--cyan); }
.hud-name { color: var(--dim); }
.hud-bar { position: absolute; left: 0; right: 0; bottom: 0; height: 1px; background: var(--hair); }
.hud-bar span { display: block; height: 100%; background: linear-gradient(90deg, var(--cyan), var(--amber)); transform-origin: left; transform: scaleX(0); transition: transform .9s cubic-bezier(.2,.7,.2,1); box-shadow: 0 0 12px var(--cyan); }

/* Slides */
.deck { position: fixed; inset: 0; z-index: 5; perspective: 1600px; }
.slide {
  position: absolute; inset: 0; display: flex; align-items: center;
  padding: calc(70px + env(safe-area-inset-top, 0px)) max(20px, env(safe-area-inset-right, 0px)) calc(86px + env(safe-area-inset-bottom, 0px)) max(20px, env(safe-area-inset-left, 0px));
  pointer-events: none; visibility: hidden;
}
.slide.active { pointer-events: auto; visibility: visible; }
.panel {
  width: min(520px, 100%); max-height: 100%; overflow-y: auto; overscroll-behavior: contain;
  margin-left: clamp(0px, 5vw, 88px);
  display: flex; flex-direction: column; gap: 16px; min-width: 0;
  scrollbar-width: thin; scrollbar-color: var(--hair) transparent;
  opacity: 0; transform: translate3d(calc(var(--dir) * 60px), 0, -160px) rotateY(calc(var(--dir) * -18deg));
  transform-origin: left center;
  transition: opacity .7s ease, transform 1.1s cubic-bezier(.16,.84,.24,1);
}
.panel.wide { width: min(620px, 100%); }
.hero .panel { width: min(640px, 100%); padding-right: 10px; overflow: visible; }
.panel > * { margin: 0; }
.slide.active .panel { opacity: 1; transform: none; transition-delay: .35s; }
.slide.before .panel { transform: translate3d(-60px, 0, -160px) rotateY(18deg); }
@media (prefers-reduced-motion: reduce) {
  .panel, .slide.before .panel { transform: none !important; transition: opacity .3s ease; }
  .slide.active .panel { transition-delay: 0s; }
}
/* stagger the panel's children in */
.slide .panel > * { transition: opacity .6s ease, transform .8s cubic-bezier(.16,.84,.24,1); }
.slide:not(.active) .panel > * { opacity: 0; transform: translateY(14px); }
.slide.active .panel > *:nth-child(1) { transition-delay: .4s; }
.slide.active .panel > *:nth-child(2) { transition-delay: .5s; }
.slide.active .panel > *:nth-child(3) { transition-delay: .6s; }
.slide.active .panel > *:nth-child(4) { transition-delay: .7s; }
.slide.active .panel > *:nth-child(n+5) { transition-delay: .8s; }

.eyebrow { font: 500 12px/1.4 var(--mono); letter-spacing: .16em; text-transform: uppercase; color: var(--cyan); }
h1, h2, h3 { font-family: var(--display); text-wrap: balance; margin: 0; }
h1 {
  font-size: clamp(44px, 6.6vw, 96px); line-height: .92; font-weight: 800; letter-spacing: -.02em; text-transform: uppercase;
  text-shadow: 1px 1px 0 #0d3a44, 2px 2px 0 #0c3440, 3px 3px 0 #0a2d38, 4px 4px 0 #082631, 5px 5px 0 #061f29, 6px 6px 18px rgba(94,231,240,.25);
}
h1 em { font-style: normal; color: transparent; -webkit-text-stroke: 1.5px var(--cyan); text-shadow: 0 0 40px rgba(94,231,240,.35); }
h2 { font-size: clamp(26px, 3.8vw, 44px); line-height: 1.06; font-weight: 600; letter-spacing: -.01em; }
h3 { font-size: 17px; font-weight: 600; }
p { max-width: 58ch; }
.lede { font-size: clamp(17px, 1.8vw, 20px); text-shadow: 0 0 18px var(--void), 0 0 4px var(--void); }
.byline { font: 500 13px var(--mono); letter-spacing: .08em; color: var(--dim); }

/* Doors slide: choose a starting course */
.track { display: flex; gap: 8px; flex-wrap: wrap; }
.track button {
  appearance: none; cursor: pointer; padding: 9px 14px; border-radius: 2px;
  font: 500 12px var(--mono); letter-spacing: .1em; text-transform: uppercase;
  color: var(--dim); background: rgba(9,13,24,.6); border: 1px solid var(--hair);
  transition: color .2s, border-color .2s, box-shadow .2s;
}
.track button:hover { color: var(--ink); border-color: var(--cyan); }
.track button[aria-pressed="true"] { color: var(--amber); border-color: var(--amber); box-shadow: 0 0 14px rgba(255,181,71,.3); }
.track-note { font-size: 15px; color: var(--ink); min-height: 3em; }
.lbl3d.dim { color: #5d6678; border-color: rgba(150,175,220,.08); }
.lbl3d.lock { color: #ff8a7a; border-color: rgba(255,138,122,.45); }

/* Big sourced number */
.callout { display: grid; grid-template-columns: auto 1fr; gap: 16px; align-items: center; padding: 14px 0; border-top: 1px solid var(--hair); border-bottom: 1px solid var(--hair); }
.callout b { font: 800 clamp(34px, 4.4vw, 52px)/1 var(--display); color: var(--amber); white-space: nowrap; }
.callout p { margin: 0; font-size: 15px; }
.callout .src { display: block; margin-top: 4px; }

/* "What you're seeing": the legend that makes each 3D visual readable */
.seeing { font-size: 14px; line-height: 1.5; color: var(--dim); border-left: 2px solid var(--amber); padding: 2px 0 2px 12px; }
.seeing b { display: block; font: 500 11px/1.6 var(--mono); letter-spacing: .14em; text-transform: uppercase; color: var(--amber); }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); margin: 4px 0 0; border-top: 1px solid var(--hair); border-bottom: 1px solid var(--hair); }
.stats div { padding: 12px 10px 10px 0; min-width: 0; }
.stats div + div { padding-left: 12px; border-left: 1px solid var(--hair); }
.stats dt { font: 600 clamp(24px, 3vw, 36px)/1 var(--display); color: var(--amber); font-variant-numeric: tabular-nums; }
.stats dd { margin: 6px 0 0; font-size: 12px; line-height: 1.35; color: var(--dim); }

.tag { display: inline-block; font: 500 11px var(--mono); letter-spacing: .14em; text-transform: uppercase; color: var(--cyan); border: 1px solid currentColor; padding: 3px 8px; border-radius: 2px; }
.q { padding: 14px 0 14px 18px; border-left: 2px solid var(--cyan); background: linear-gradient(90deg, rgba(94,231,240,.08), transparent 80%); }
.q p { margin: 8px 0 0; }
.q-b { border-left-color: var(--amber); background: linear-gradient(90deg, rgba(255,181,71,.08), transparent 80%); }
.q-b .tag { color: var(--amber); }

.vars { display: grid; margin: 0; }
.vars div { padding: 12px 0; border-top: 1px solid var(--hair); display: grid; gap: 4px; }
.vars dt { font: 600 16px var(--display); }
.v-a dt { color: var(--cyan); } .v-b dt { color: var(--amber); } .v-c dt { color: var(--violet); }
.vars dd { margin: 0; font-size: 16px; }
.src { font: 400 12px var(--mono); color: var(--dim); }

.hyp { list-style: none; padding: 0; margin: 0; display: grid; gap: 12px; }
.hyp li { display: grid; grid-template-columns: 40px 1fr; gap: 12px; }
.hyp b { font: 600 14px var(--mono); color: var(--amber); padding-top: 3px; }

.studies { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 210px), 1fr)); gap: 12px; }
.studies article { padding: 16px; border: 1px solid var(--hair); background: var(--glass); display: grid; gap: 8px; align-content: start; min-width: 0; }
.studies article.warm .tag { color: var(--amber); }
.studies p { margin: 0; font-size: 15px; color: var(--dim); }

.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { display: grid; grid-template-columns: 72px 1fr; gap: 14px; padding: 9px 0; border-top: 1px solid var(--hair); font-size: 16px; }
.mins { font: 500 13px var(--mono); color: var(--cyan); padding-top: 3px; font-variant-numeric: tabular-nums; }

.checks { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.checks li { display: grid; grid-template-columns: 22px 1fr; gap: 12px; font-size: 16px; }
.checks li::before { content: ""; width: 10px; height: 10px; margin-top: 8px; border: 1px solid var(--cyan); transform: rotate(45deg); box-shadow: 0 0 8px rgba(94,231,240,.6); }

/* Results */
.results-body { display: grid; gap: 16px; }
.awaiting { border: 1px dashed rgba(94,231,240,.4); padding: 20px; display: grid; gap: 14px; background: var(--glass); }
.awaiting p { margin: 0; color: var(--dim); }
.chip { display: inline-flex; align-items: center; gap: 8px; width: max-content; font: 500 12px var(--mono); letter-spacing: .12em; text-transform: uppercase; color: var(--amber); }
.chip i { width: 8px; height: 8px; border-radius: 50%; background: var(--amber); box-shadow: 0 0 10px var(--amber); animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .3; } }
.slots { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 150px), 1fr)); gap: 10px; }
.slots li { border: 1px solid var(--hair); padding: 12px; display: grid; gap: 4px; }
.slots b { font: 600 22px var(--display); color: var(--dim); }
.slots span { font-size: 13px; color: var(--dim); }
.r-card { border: 1px solid var(--hair); background: var(--glass); padding: 16px; display: grid; gap: 12px; min-width: 0; }
.r-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.r-head h3 { font-size: 15px; }
.r-n { font: 500 12px var(--mono); color: var(--dim); }
.chart { overflow-x: auto; }
.chart svg { display: block; width: 100%; height: auto; min-width: 300px; }
.chart text { font-family: var(--mono); font-size: 11px; fill: var(--dim); }
.chart .lbl { fill: var(--ink); font-family: var(--body); font-size: 12px; }
.legend { display: flex; gap: 16px; font: 500 12px var(--mono); color: var(--dim); flex-wrap: wrap; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: -1px; }
.big-delta { font: 800 clamp(32px, 4.6vw, 50px)/1 var(--display); color: var(--amber); font-variant-numeric: tabular-nums; }
.r-foot { font-size: 13px; color: var(--dim); margin: 0; }

/* Themes */
.themes { list-style: none; padding: 0; margin: 0; display: grid; gap: 14px; }
.themes li { display: grid; gap: 6px; }
.t-head { display: flex; justify-content: space-between; gap: 12px; }
.t-head span { font: 500 12px var(--mono); color: var(--dim); font-variant-numeric: tabular-nums; }
.t-bar { display: block; height: 4px; background: var(--hair); }
.t-bar i { display: block; height: 100%; background: var(--cyan); box-shadow: 0 0 8px currentColor; }
.themes .t1 .t-bar i { background: var(--amber); } .themes .t2 .t-bar i { background: var(--violet); }
.themes p { margin: 0; font-size: 14px; color: var(--dim); }

/* Log */
.log { list-style: none; padding: 0; margin: 0; position: relative; }
.log::before { content: ""; position: absolute; left: 6px; top: 8px; bottom: 8px; width: 1px; background: var(--hair); }
.log li { position: relative; display: grid; grid-template-columns: 26px 1fr; gap: 12px; padding: 6px 0; }
.log .dot { width: 13px; height: 13px; border-radius: 50%; margin-top: 6px; border: 1.5px solid var(--dim); background: var(--void); position: relative; z-index: 1; }
.log .done .dot { border-color: var(--amber); background: var(--amber); box-shadow: 0 0 12px var(--amber); }
.log .active .dot { border-color: var(--cyan); box-shadow: 0 0 12px var(--cyan); animation: pulse 1.6s ease-in-out infinite; }
.log .when { font: 500 12px var(--mono); letter-spacing: .08em; color: var(--dim); text-transform: uppercase; }
.log .done .when { color: var(--amber); } .log .active .when { color: var(--cyan); }
.log .what { font-weight: 700; }
.log .detail { font-size: 14px; color: var(--dim); }

.refs { border-top: 1px solid var(--hair); padding-top: 12px; }
.refs summary { cursor: pointer; font: 500 13px var(--mono); letter-spacing: .12em; text-transform: uppercase; color: var(--cyan); }
.refs ol { padding-left: 20px; margin: 14px 0 0; display: grid; gap: 10px; font-size: 13px; color: var(--dim); }
.foot { font: 400 12px var(--mono); color: var(--dim); border-top: 1px solid var(--hair); padding-top: 12px; }

/* Controls */
.controls {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 14px max(20px, env(safe-area-inset-right, 0px)) calc(16px + env(safe-area-inset-bottom, 0px)) max(20px, env(safe-area-inset-left, 0px));
  background: linear-gradient(rgba(5,7,13,0), var(--void) 70%);
  font: 500 12px var(--mono); letter-spacing: .12em; color: var(--dim);
}
.controls button {
  appearance: none; width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--hair); background: rgba(9,13,24,.6);
  color: var(--ink); font: 500 15px var(--mono); cursor: pointer; display: grid; place-items: center; position: relative;
  transition: border-color .2s, box-shadow .2s, opacity .2s;
}
.controls button:hover:not(:disabled) { border-color: var(--cyan); box-shadow: 0 0 14px rgba(94,231,240,.35); }
.controls button:disabled { opacity: .3; cursor: default; }
#playBtn { width: 46px; height: 46px; color: var(--amber); }
#playBtn svg { position: absolute; inset: -1px; width: calc(100% + 2px); height: calc(100% + 2px); transform: rotate(-90deg); }
#playBtn circle { fill: none; stroke-width: 1.5; }
.ring-bg { stroke: transparent; }
.ring { stroke: var(--amber); stroke-linecap: round; }
#playIcon { font-size: 12px; letter-spacing: 0; }
.counter b { color: var(--cyan); font-weight: 500; }
.dots { display: flex; gap: 8px; margin-left: 8px; }
.dots button { width: 9px; height: 9px; border-radius: 50%; padding: 0; background: transparent; }
.dots button.on { background: var(--cyan); border-color: var(--cyan); box-shadow: 0 0 10px var(--cyan); }
.hint { margin-left: auto; }

/* Phone: field on top, panel as a bottom sheet */
@media (max-width: 899px) {
  .vignette { background: radial-gradient(ellipse at 50% 25%, transparent 40%, rgba(5,7,13,.7) 100%); }
  .slide { align-items: flex-end; padding-top: calc(36vh + env(safe-area-inset-top, 0px)); padding-bottom: calc(76px + env(safe-area-inset-bottom, 0px)); }
  .slide.hero { align-items: center; padding-top: calc(70px + env(safe-area-inset-top, 0px)); }
  .panel, .panel.wide { margin-left: 0; width: 100%; padding: 18px; background: var(--glass); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border: 1px solid var(--hair); transform-origin: center bottom; }
  .hero .panel { background: transparent; border: 0; backdrop-filter: none; -webkit-backdrop-filter: none; padding: 0; }
  .hud-name { display: none; }
  .dots, .hint { display: none; }
  .counter { margin-left: auto; }
  .controls button { width: 44px; height: 44px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stats div:nth-child(3) { padding-left: 0; border-left: 0; }
  .stats div:nth-child(n+3) { border-top: 1px solid var(--hair); }
  .lbl3d { font-size: 9px; padding: 3px 5px; }
}
@media (max-width: 1150px) and (min-width: 900px) { .hint { display: none; } }
