/* ============================================================================
   Decanting the Web: styles
   Dark, editorial scrollytelling. Layout = a column of narrative "steps" beside a
   sticky chart that updates as you scroll. One palette, shared with js/config.js.
   ========================================================================== */

:root {
  --bg: #0a0e16;
  --panel: #121826;
  --panel-hi: #18202f;
  --ink: #e7edf5;
  --muted: #8a96a8;
  --line: #1f2a3a;
  --blue: #5b9bff;
  --orange: #ff9f45;
  --green: #46d39a;
  --purple: #b98cff;
  --teal: #37c9d6;
  --red: #ff6b6b;
  --yellow: #ffd166;
  --maxw: 1280px;
  --radius: 16px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
a { color: var(--blue); text-decoration: none; border-bottom: 1px solid transparent; transition: border-color .2s; }
a:hover { border-color: var(--blue); }
code { font-family: "JetBrains Mono", ui-monospace, monospace; font-size: .88em;
  background: var(--panel-hi); padding: .12em .4em; border-radius: 5px; color: var(--teal); }
h1, h2, h3, h4 { line-height: 1.15; margin: 0 0 .5em; font-weight: 700; letter-spacing: -.01em; }
.accent { color: var(--blue); }
.muted { color: var(--muted); }

/* ── loader ─────────────────────────────────────────────────────────────── */
#loader {
  position: fixed; inset: 0; z-index: 999; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 1.1rem; background: var(--bg);
  color: var(--muted); transition: opacity .6s ease, visibility 0s linear .6s; font-size: .95rem;
}
#loader.hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.spinner { width: 42px; height: 42px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--blue); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loader-err { max-width: 460px; text-align: center; color: var(--red); line-height: 1.5; }
.loader-err span { color: var(--muted); font-size: .85rem; }
.loader-err code { display: inline-block; margin-top: .6rem; color: var(--muted); }

/* ── scroll progress + nav dots ─────────────────────────────────────────── */
.scroll-progress {
  position: fixed; top: 0; left: 0; height: 3px; width: 100%; z-index: 200;
  background: linear-gradient(90deg, var(--blue), var(--teal), var(--green));
  transform: scaleX(0); transform-origin: 0 50%;
}
.nav-dots {
  position: fixed; right: 22px; top: 50%; transform: translateY(-50%); z-index: 150;
  display: flex; flex-direction: column; gap: 13px;
}
.nav-dot {
  width: 11px; height: 11px; border-radius: 50%; border: 1.5px solid var(--muted);
  background: transparent; cursor: pointer; padding: 0; transition: all .25s;
}
.nav-dot:hover { border-color: var(--blue); transform: scale(1.25); }
.nav-dot.is-active { background: var(--blue); border-color: var(--blue); box-shadow: 0 0 10px var(--blue); }

/* ── hero ───────────────────────────────────────────────────────────────── */
.hero { position: relative; min-height: 100vh; display: flex; align-items: center;
  justify-content: center; overflow: hidden; padding: 2rem; }
.hero-bg {
  position: absolute; inset: 0; z-index: 0;
  background:
    radial-gradient(60% 50% at 25% 20%, rgba(91,155,255,.18), transparent 70%),
    radial-gradient(55% 55% at 80% 75%, rgba(55,201,214,.14), transparent 70%),
    radial-gradient(50% 50% at 60% 30%, rgba(185,140,255,.10), transparent 70%);
  animation: drift 22s ease-in-out infinite alternate;
}
@keyframes drift { to { transform: translate3d(0, -18px, 0) scale(1.05); } }
.hero-inner { position: relative; z-index: 1; max-width: 820px; text-align: center; }
.eyebrow { text-transform: uppercase; letter-spacing: .28em; font-size: .72rem;
  color: var(--teal); font-weight: 600; margin-bottom: 1.6rem; }
.hero h1 { font-size: clamp(3.2rem, 11vw, 7.5rem); font-weight: 800; letter-spacing: -.03em;
  margin: 0 0 1.4rem; }
.hero-lead { font-size: clamp(1.02rem, 2.1vw, 1.32rem); color: #c4cfde; max-width: 640px;
  margin: 0 auto 2.4rem; }
.hero-stat { display: inline-flex; align-items: center; gap: 1.6rem; padding: 1.1rem 1.8rem;
  background: rgba(18,24,38,.6); border: 1px solid var(--line); border-radius: var(--radius);
  backdrop-filter: blur(8px); margin-bottom: 2.4rem; }
.hs-block { display: flex; flex-direction: column; }
.hs-num { font-size: 2.4rem; font-weight: 800; font-family: "JetBrains Mono", monospace; line-height: 1; }
.hs-lbl { font-size: .76rem; color: var(--muted); text-transform: uppercase; letter-spacing: .1em; margin-top: .4rem; }
.hs-arrow { font-size: 1.8rem; color: var(--muted); }
.cta { display: inline-block; background: var(--blue); color: #07101f; border: none; cursor: pointer;
  font-family: inherit; font-weight: 700; font-size: 1rem; padding: .85rem 1.8rem; border-radius: 999px;
  transition: transform .2s, box-shadow .2s; }
.cta:hover { transform: translateY(-2px); box-shadow: 0 10px 30px rgba(91,155,255,.4); }

/* ── prose / intro / outro ──────────────────────────────────────────────── */
.intro, .outro { max-width: 760px; margin: 0 auto; padding: 14vh 1.5rem; }
.prose h2 { font-size: clamp(1.9rem, 4vw, 2.8rem); margin-bottom: 1rem; }
.prose p { font-size: 1.1rem; color: #c4cfde; margin: 0 0 1.2rem; }
.hint { color: var(--muted) !important; font-size: .95rem !important; text-align: center; margin-top: 2.5rem !important; }
.stat-strip { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; margin: 2.4rem 0; }
.stat-strip > div { background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 1.1rem .8rem; text-align: center; }
.stat-strip b { display: block; font-size: 1.5rem; font-family: "JetBrains Mono", monospace; color: var(--ink); }
.stat-strip span { font-size: .74rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }

/* fade-in on scroll */
[data-reveal] { opacity: 0; transform: translateY(26px); transition: opacity .8s ease, transform .8s ease; }
[data-reveal].in-view { opacity: 1; transform: none; }

/* ── scrollytelling layout ──────────────────────────────────────────────── */
.section { max-width: var(--maxw); margin: 0 auto; }
.scrolly { display: grid; grid-template-columns: 40% 60%; align-items: start; }
.scrolly .steps { padding: 0 2.4rem; }
.section-tag { position: sticky; top: 0; padding: 1.6rem 0 .6rem; font-size: .8rem;
  text-transform: uppercase; letter-spacing: .18em; color: var(--teal); font-weight: 600;
  background: linear-gradient(var(--bg) 70%, transparent); z-index: 2; }
.section-tag .num { color: var(--muted); margin-right: .4rem; }
.step { min-height: 86vh; display: flex; align-items: center; }
.step:first-of-type { min-height: 70vh; }
.step:last-of-type { min-height: 80vh; }
.step-inner {
  background: var(--panel); border: 1px solid var(--line); border-left: 3px solid var(--line);
  border-radius: 12px; padding: 1.5rem 1.6rem; transition: border-color .35s, transform .35s, opacity .35s;
  opacity: .45; transform: translateX(-6px);
}
.step.is-active .step-inner { opacity: 1; border-left-color: var(--blue); transform: none;
  box-shadow: 0 14px 40px rgba(0,0,0,.35); }
.step-inner h3 { font-size: 1.4rem; color: var(--ink); }
.step-inner p { margin: 0; color: #b9c4d4; font-size: 1.02rem; }
.step-inner b { color: var(--ink); }
.step-inner code { font-size: .82em; }

.sticky { position: sticky; top: 0; height: 100vh; display: flex; align-items: center;
  justify-content: center; padding: 1.5rem 1.5rem 1.5rem 0; }
.chart-card {
  width: 100%; height: 86vh; max-height: 820px; background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 1.2rem 1.3rem;
  display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.4);
}
.chart-head { flex: 0 0 auto; margin-bottom: .4rem; }
.chart-head h4 { font-size: 1.1rem; margin: 0; }
.chart-sub { font-size: .85rem; color: var(--muted); margin: .15rem 0 0; }
.chart-holder { position: relative; flex: 1 1 auto; min-height: 0; width: 100%; }
.chart-svg { display: block; width: 100%; height: 100%; overflow: visible; }

/* ── chart controls ─────────────────────────────────────────────────────── */
.chart-controls { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem;
  margin: .2rem 0 .7rem; }
.ctrl-btn {
  font-family: inherit; font-size: .82rem; font-weight: 600; color: var(--muted);
  background: var(--panel-hi); border: 1px solid var(--line); border-radius: 999px;
  padding: .38rem .9rem; cursor: pointer; transition: all .2s;
}
.ctrl-btn:hover { color: var(--ink); border-color: var(--muted); }
.ctrl-btn.is-on { color: #07101f; background: var(--blue); border-color: var(--blue); }
.ctrl-sep { width: 1px; height: 20px; background: var(--line); margin: 0 .3rem; }
.ctrl-input {
  font-family: inherit; font-size: .82rem; color: var(--ink); background: var(--panel-hi);
  border: 1px solid var(--line); border-radius: 999px; padding: .38rem .9rem; min-width: 170px;
  outline: none; transition: border-color .2s;
}
.ctrl-input:focus { border-color: var(--blue); }
.ctrl-input::placeholder { color: var(--muted); }

/* ── galaxy legend ──────────────────────────────────────────────────────── */
.galaxy-legend { display: flex; flex-wrap: wrap; gap: .5rem .9rem; margin-top: .6rem; }
.galaxy-legend .lg { display: inline-flex; align-items: center; gap: .35rem; font-size: .76rem;
  color: var(--muted); cursor: pointer; user-select: none; transition: opacity .2s; }
.galaxy-legend .lg:hover { color: var(--ink); }
.galaxy-legend .lg.dim { opacity: .3; }
.galaxy-legend .sw { width: 11px; height: 11px; border-radius: 3px; display: inline-block; }

/* ── tooltip ────────────────────────────────────────────────────────────── */
.tooltip {
  position: fixed; z-index: 500; pointer-events: none; opacity: 0; transition: opacity .12s;
  background: rgba(10,14,22,.96); border: 1px solid var(--line); border-radius: 10px;
  padding: .6rem .75rem; font-size: .82rem; color: var(--ink); max-width: 260px;
  box-shadow: 0 14px 40px rgba(0,0,0,.5); backdrop-filter: blur(4px);
}
.tooltip b { color: var(--ink); }
.tooltip .t-sub { color: var(--teal); font-size: .74rem; margin: .1rem 0 .4rem; }
.tooltip .t-row { display: flex; justify-content: space-between; gap: 1.2rem; color: var(--muted); }
.tooltip .t-row b { color: var(--ink); font-family: "JetBrains Mono", monospace; }
.tooltip .t-note { color: var(--muted); font-size: .76rem; margin-top: .45rem; line-height: 1.4;
  border-top: 1px solid var(--line); padding-top: .4rem; }

/* ── outro cards + credits ──────────────────────────────────────────────── */
.outro { max-width: 1000px; }
.outro .closer { font-size: 1.18rem; color: var(--ink); border-left: 3px solid var(--blue);
  padding-left: 1.2rem; margin-top: 2.5rem; }
.cards { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1rem; margin: 2.4rem 0; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 1.4rem; }
.card .c-ico { font-size: 1.6rem; }
.card h4 { font-size: 1.12rem; margin: .5rem 0 .4rem; }
.card p { font-size: .94rem; color: var(--muted); margin: 0; }
.card span[data-stat] { color: var(--blue); font-weight: 700; }
.credits { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1.6rem;
  border-top: 1px solid var(--line); margin-top: 4rem; padding-top: 2.2rem; }
.credit-col h5 { font-size: .74rem; text-transform: uppercase; letter-spacing: .14em;
  color: var(--teal); margin: 0 0 .6rem; }
.credit-col p { font-size: .9rem; color: var(--muted); margin: 0; line-height: 1.7; }
.data-note { font-size: .8rem; color: var(--muted); text-align: center; margin: 3rem auto 1rem;
  max-width: 640px; line-height: 1.6; }

/* ── responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .nav-dots { display: none; }
  .scrolly { display: flex; flex-direction: column; }
  .sticky { order: -1; position: sticky; top: 0; height: 64vh; padding: .6rem 0;
    background: var(--bg); z-index: 5; }
  .chart-card { height: 100%; max-height: none; }
  .scrolly .steps { padding: 0; }
  .section-tag { position: static; }
  .step { min-height: 62vh; }
  .step-inner { opacity: 1; }
  .stat-strip { grid-template-columns: repeat(2, 1fr); }
  .cards, .credits { grid-template-columns: 1fr; }
}
@media (max-width: 520px) {
  .hero-stat { flex-direction: column; gap: .8rem; }
  .stat-strip { grid-template-columns: 1fr 1fr; }
}
