/* ==========================================================================
   Akar showcase, base layer: fonts, design tokens, resets, shared components
   and the page-wide effects (atmosphere, spotlight, grain, progress bar).

   Motion model: everything animated is switched on by one class, `html.fx`.
   The head script and motion.js add it only when JavaScript works AND the
   visitor has not asked for less motion. Without it (no JavaScript, reduced
   motion, or the Motion button) all animation and transition is switched off
   and every element simply shows its finished state.
   ========================================================================== */

/* Plus Jakarta Sans: a variable font, so one 27 KB file covers weights 200 to 800.
   It was drawn for Jakarta's own city identity, which suits this story. */
@font-face {
  font-family: "Plus Jakarta Sans";
  src: url("../../assets/fonts/plus-jakarta-sans-latin-wght-normal.woff2") format("woff2");
  font-weight: 200 800;
  font-style: normal;
  font-display: swap;
}

/* Registered properties let the browser tween colours and angles smoothly:
   --a1 / --a2 fade between chapter accents, --ang spins the frame borders. */
@property --a1 { syntax: "<color>"; inherits: true; initial-value: #19f0c8; }
@property --a2 { syntax: "<color>"; inherits: true; initial-value: #ffb020; }
@property --ang { syntax: "<angle>"; inherits: false; initial-value: 0deg; }

:root {
  --ink: #050816;
  --ink-2: #0a1128;
  --text: #eaf3ff;
  --muted: #b4c3dc;
  --teal: #19f0c8;
  --lime: #c8ff3d;
  --amber: #ffb020;
  --coral: #ff4d6d;
  --violet: #8b5cff;
  --sky: #38bdf8;
  --pink: #ff3da5;
  --line: rgb(255 255 255 / 0.13);
  --radius: 24px;
  --gutter: clamp(18px, 5vw, 72px);
  --topbar: 68px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --font: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html {
  -webkit-text-size-adjust: 100%;
  background: var(--ink);
  scroll-padding-top: calc(var(--topbar) + 16px);
}
html.fx { scroll-behavior: smooth; }
/* While the entry gate is open the page behind it must not scroll. */
html.js:not(.entered) { overflow: hidden; }
html:has(#lightbox[open]) { overflow: hidden; }

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: clip;
  /* No background here on purpose: the page colour lives on <html>, which lets the fixed atmosphere layer
     (z-index -3) show through. A body background would paint over it. */
  color: var(--text);
  font: 400 1.0625rem/1.65 var(--font);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  /* The two accents follow the active chapter and cross-fade over 1.4 s. */
  --a1: #19f0c8;
  --a2: #ffb020;
  transition: --a1 1.4s ease, --a2 1.4s ease;
}

/* The tilted ribbons are deliberately wider than the screen. The body rule above is handed to the viewport by
   the browser, so it cannot stop the document itself from growing. Clipping on <main> does, and unlike
   overflow: hidden it creates no scroll container, so the sticky chapter frames keep working. */
main { overflow-x: clip; }

h1, h2, h3, p, figure, blockquote, dl, dd { margin: 0; }
ul, ol { margin: 0; padding: 0; list-style: none; }
img, svg, canvas { display: block; max-width: 100%; }
a { color: inherit; }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* Anything that needs JavaScript stays out of the plain, no-JavaScript page. */
html:not(.js) :is(.gate, .controls, .tourbar, .spot, .progress, .atmos, .dots, [data-tour-start], .hero__hint, .frame__zoom, .map__stage, .map .seg, .chart__plot, .scrub) { display: none; }
html:not(.js) .map, html:not(.js) .chart { grid-template-columns: minmax(0, 1fr); }

/* ---------- Motion off: finished state, no animation ---------- */
html:not(.fx) *, html:not(.fx) *::before, html:not(.fx) *::after {
  animation: none !important;
  transition: none !important;
  scroll-behavior: auto !important;
}

/* ---------- Utilities ---------- */
.sr-only {
  position: absolute !important;
  width: 1px; height: 1px; margin: -1px; padding: 0; border: 0;
  overflow: hidden; clip-path: inset(50%); white-space: nowrap;
}
.skip {
  position: absolute; left: 12px; top: -80px; z-index: 300;
  padding: 12px 18px; border-radius: 12px;
  background: var(--lime); color: #04101c; font-weight: 700; text-decoration: none;
}
.skip:focus { top: 12px; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
/* The sprite's own elements are styled here; clones inside <use> inherit the rest. */
.sprite .solid { fill: currentColor; stroke: none; }
.icon {
  width: 1.25em; height: 1.25em; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}

:focus-visible { outline: 3px solid var(--lime); outline-offset: 3px; }
::selection { background: var(--teal); color: #04101c; }

/* ---------- Shared components ---------- */
.btn {
  position: relative; display: inline-flex; align-items: center; justify-content: center; gap: 0.6em;
  min-height: 54px; padding: 0 1.7em; border: 1px solid transparent; border-radius: 999px;
  font-weight: 700; font-size: 1rem; text-decoration: none; cursor: pointer;
  transition: transform 0.3s var(--ease), box-shadow 0.3s, background-color 0.3s, border-color 0.3s;
}
.btn:hover { transform: translateY(-2px) scale(1.02); }
.btn:active { transform: translateY(0) scale(0.99); }
.btn--primary {
  color: #04101c;
  background: linear-gradient(110deg, var(--lime), var(--teal) 55%, var(--sky)) 0 0 / 200% 100%;
  box-shadow: 0 12px 44px -10px rgb(25 240 200 / 0.7), inset 0 1px 0 rgb(255 255 255 / 0.5);
}
.btn--primary:hover { background-position: 100% 0; box-shadow: 0 16px 56px -8px rgb(25 240 200 / 0.9), inset 0 1px 0 rgb(255 255 255 / 0.5); }
.btn--ghost { color: var(--text); background: rgb(255 255 255 / 0.07); border-color: rgb(255 255 255 / 0.3); }
.btn--ghost:hover { background: rgb(255 255 255 / 0.16); border-color: rgb(255 255 255 / 0.55); }

.icon-btn {
  display: inline-grid; place-items: center; width: 44px; height: 44px; padding: 0;
  border: 1px solid var(--line); border-radius: 50%; cursor: pointer;
  background: rgb(8 12 30 / 0.68); color: var(--text);
  backdrop-filter: blur(10px);
  transition: transform 0.25s var(--ease), background-color 0.25s, border-color 0.25s;
}
.icon-btn:hover { transform: scale(1.08); background: rgb(255 255 255 / 0.18); border-color: rgb(255 255 255 / 0.5); }

.link {
  display: inline-flex; align-items: center; gap: 0.45em;
  font-weight: 600; text-decoration: underline; text-underline-offset: 0.28em; text-decoration-thickness: 2px;
  text-decoration-color: color-mix(in srgb, var(--a1) 65%, transparent);
  transition: color 0.2s, text-decoration-color 0.2s;
}
.link:hover { color: var(--a1); text-decoration-color: currentColor; }
/* A thumb needs a bigger target than a mouse pointer does. */
@media (pointer: coarse) { .link { min-height: 44px; } }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; min-height: 32px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: 999px;
  background: rgb(255 255 255 / 0.07); color: #dbe6f7;
  font-size: 0.8125rem; font-weight: 600; letter-spacing: 0.03em;
}
.chip--n {
  border-color: var(--c1, var(--a1)); color: #fff;
  background: color-mix(in srgb, var(--c1, var(--a1)) 22%, #050816);
}

.card {
  position: relative; padding: clamp(20px, 2.6vw, 32px);
  border: 1px solid var(--line); border-radius: var(--radius);
  background: linear-gradient(155deg, rgb(255 255 255 / 0.09), rgb(255 255 255 / 0.025)), rgb(8 12 30 / 0.6);
  box-shadow: 0 30px 80px -40px rgb(0 0 0 / 0.9);
}
.card__label {
  display: flex; align-items: center; gap: 0.7em; margin-bottom: 0.9em;
  color: var(--c1, var(--a1)); font-size: 0.75rem; font-weight: 800; letter-spacing: 0.16em; text-transform: uppercase;
}
.card__label::before {
  content: ""; width: 8px; height: 8px; border-radius: 50%;
  background: currentColor; box-shadow: 0 0 12px currentColor;
}

/* ---------- Page-wide effects layer (behind the content) ---------- */

/* The atmosphere: a blurred copy of the active chapter's picture plus two tinted glows.
   scroll.js swaps the two <img> elements to cross-fade between chapters. */
.atmos { position: fixed; inset: -8%; z-index: -3; overflow: hidden; pointer-events: none; }
.atmos img {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover;
  filter: blur(50px) saturate(1.7) brightness(0.85); opacity: 0; transform: scale(1.12);
  transition: opacity 1.8s ease;
}
.atmos img.is-on { opacity: 0.4; }
.atmos::before {
  content: ""; position: absolute; inset: 0;
  background:
    radial-gradient(60% 50% at 12% 8%, color-mix(in srgb, var(--a1) 30%, transparent), transparent 70%),
    radial-gradient(50% 45% at 92% 88%, color-mix(in srgb, var(--a2) 24%, transparent), transparent 70%);
}
.atmos::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(rgb(5 8 22 / 0.5), rgb(5 8 22 / 0.82)), radial-gradient(120% 90% at 50% 0%, transparent, rgb(5 8 22 / 0.6));
}

/* Film grain: a tiny noise tile that stops the dark gradients from banding. */
.grain {
  position: fixed; inset: 0; z-index: -2; pointer-events: none; opacity: 0.07;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='180' height='180'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 1  0 0 0 0 1  0 0 0 0 1  0 0 0 .7 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}

/* The pointer spotlight is one fixed glow moved with transform, so it never triggers a repaint. */
.spot {
  position: fixed; left: 0; top: 0; z-index: 5; width: 900px; height: 900px; margin: -450px 0 0 -450px;
  border-radius: 50%; pointer-events: none; opacity: 0; will-change: transform;
  background: radial-gradient(closest-side, color-mix(in srgb, var(--a1) 15%, transparent), transparent);
  transition: opacity 0.8s;
}
html.entered .spot.is-live { opacity: 1; }
@media (hover: none), (pointer: coarse) { .spot { display: none; } }

/* Scroll progress along the very top edge. */
.progress { position: fixed; inset: 0 0 auto 0; z-index: 130; height: 3px; pointer-events: none; }
.progress span {
  display: block; height: 100%; transform-origin: 0 50%; transform: scaleX(var(--scroll, 0));
  background: linear-gradient(90deg, var(--a1), var(--a2)); box-shadow: 0 0 16px var(--a1);
}

/* ---------- Reveal on scroll ----------
   Hidden only while effects are on; scroll.js adds .in-view as each block arrives.
   Individual transform properties (translate, scale) keep this from clashing with the tilt transform. */
html.fx [data-reveal] {
  opacity: 0; translate: 0 48px;
  transition: opacity 1s var(--ease), translate 1s var(--ease), scale 1s var(--ease);
}
html.fx [data-reveal="zoom"] { translate: 0 36px; scale: 0.93; }
html.fx [data-reveal].in-view { opacity: 1; translate: 0 0; scale: 1; }

/* Gradient text needs a plain fallback in forced-colours (high contrast) mode. */
@media (forced-colors: active) {
  :is(.pull p, .chapter__title, .fact__value, .hero__word span, .finale__line, .move__verb, .map__rate, .gate__title) {
    background: none; color: CanvasText; -webkit-text-fill-color: currentColor;
  }
}
