/* ============================================================================
   Zero to a Trillion - "Engraved Currency / Financial Broadsheet"
   A descent from cream paper ($0) into a gold-flecked vault ($1T).
   Color, ink, and atmosphere all interpolate from --depth (set by scroll.js).
   ========================================================================== */

:root {
  /* depth: 0 at the surface ($0), 1 at the bottom ($1T). Updated by JS. */
  --depth: 0;

  /* palette stops */
  --paper:  #efe6cf;
  --paper-2:#e3d8bb;
  --vault:  #070a08;
  --vault-2:#02040a;
  --green:  #1d5d3c;
  --ink-dark:  #16261b;
  --gold:   #d8b049;
  --gold-hi:#f1d488;
  --gold-ink:#7a5a12; /* deep antique gold - readable on the light parchment */

  /* ── Crossover-free color system ────────────────────────────────────────────
     Lesson learned the hard way: if ink and background both pass through mid-tones
     at the same depth, contrast collapses (the muddy middle). So we never flip the
     ink. Milestone text is ALWAYS dark; as the page descends into the vault, a
     light parchment "plate" fades in behind the text - so dark-ink-on-light-surface
     holds at every depth. The rail is a constant dark ledger spine with light
     chrome. No surface ever crosses mid-tone against its text.                    */

  /* page background descends parchment → vault (visible around the cards) */
  --night: clamp(0, calc((var(--depth) - 0.42) / 0.5), 1);
  --bg: color-mix(in oklab, var(--paper), var(--vault) calc(var(--night) * 108%));

  /* milestone ink: constant dark */
  --ink: var(--ink-dark);
  --ink-soft: color-mix(in oklab, var(--ink-dark), transparent 28%);
  --rule: color-mix(in oklab, var(--ink-dark), transparent 72%); /* dark hairline on the light plate */

  /* light plate: 0 while the page is light, fades in as it darkens and stays to
     the end (the $1T finale opts out for its gold-on-vault payoff) */
  --plate-op: clamp(0, calc((var(--depth) - 0.46) * 9), 0.96);
  --plate: color-mix(in oklab, var(--paper), transparent calc((1 - var(--plate-op)) * 100%));

  /* rail chrome lives on a constant dark spine - always legible */
  --chrome: var(--paper);
  --chrome-soft: color-mix(in oklab, var(--paper), transparent 42%);
  --hairline: color-mix(in oklab, var(--paper), transparent 82%);
  --rail-bg: #0c1310;

  --rail-w: 10.5rem;

  --font-display: "Fraunces", "Frank Ruhl Libre", Georgia, serif;
  --font-body: "Archivo", "Heebo", system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;
}

:lang(he) {
  --font-display: "Frank Ruhl Libre", "Fraunces", serif;
  --font-body: "Heebo", "Archivo", system-ui, sans-serif;
}

/* The small mono/uppercase/letter-spaced labels are English typography devices -
   in Hebrew they're unreadable. Render Hebrew labels in the Hebrew sans with
   normal spacing instead. (The eyebrow & rail-hint follow the page language.) */
:lang(he) .milestone__eyebrow,
:lang(he) #rail-hint {
  font-family: "Heebo", sans-serif;
  letter-spacing: normal;
  text-transform: none;
  font-weight: 700;
}
/* The mono "ledger" look reads fine for English digits, but mangles Hebrew -
   so the amount caption and the salary sentence use the Hebrew sans in Hebrew. */
:lang(he) .milestone__amount,
:lang(he) .milestone__blurb--mono {
  font-family: "Heebo", sans-serif;
  letter-spacing: normal;
}

* { box-sizing: border-box; }

html { scroll-behavior: auto; }

body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--ink);
  background: var(--vault-2);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* ----------------------------------------------------------------------------
   Background: paper → vault gradient + paper grain + gold vignette near the end
   -------------------------------------------------------------------------- */
#depth-bg {
  position: fixed;
  inset: 0;
  z-index: -2;
  background:
    linear-gradient(
      178deg,
      var(--bg),
      color-mix(in oklab, var(--bg), var(--vault-2) calc(var(--night) * 18%))
    );
}

/* engraved paper grain */
#depth-bg::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.5'/%3E%3C/svg%3E");
  opacity: 0.05;
  mix-blend-mode: overlay;
}

/* gold vault glow - ramps in only over the final stretch */
#depth-bg::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(120% 70% at 50% 118%,
    color-mix(in oklab, var(--gold), transparent 30%),
    transparent 60%);
  opacity: clamp(0, calc((var(--depth) - 0.72) * 3.6), 0.85);
  z-index: 1;
}

/* ----------------------------------------------------------------------------
   Side rail - fixed on the inline-start edge (flips for RTL automatically)
   -------------------------------------------------------------------------- */
#rail {
  position: fixed;
  inset-block: 0;
  inset-inline-start: 0;
  width: var(--rail-w);
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.1rem;
  padding-block: 1.4rem;
  border-inline-end: 1px solid color-mix(in oklab, var(--gold), transparent 78%);
  background: var(--rail-bg);
}

#lang-toggle {
  /* the label is always the OTHER language, so use a font that reads in both
     Hebrew and Latin and skip the letter-spacing/uppercase that break Hebrew */
  font-family: "Heebo", "Archivo", sans-serif;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--chrome);
  background: transparent;
  border: 1px solid var(--hairline);
  border-radius: 999px;
  padding: 0.35rem 0.7rem;
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s, background 0.2s;
}
#lang-toggle:hover {
  color: var(--gold-hi);
  border-color: var(--gold);
  background: color-mix(in oklab, var(--gold), transparent 88%);
}

#share-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-family: "Heebo", "Archivo", sans-serif;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--chrome);
  background: transparent;
  border: 1px solid var(--hairline);
  border-radius: 999px;
  padding: 0.3rem 0.7rem;
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s, background 0.2s;
}
#share-btn:hover {
  color: var(--gold-hi);
  border-color: var(--gold);
  background: color-mix(in oklab, var(--gold), transparent 88%);
}
.share-ic {
  width: 0.85rem;
  height: 0.85rem;
  flex: none;
}

#counter {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  font-size: 0.82rem;
  letter-spacing: -0.02em;
  color: var(--gold);
  text-align: center;
  line-height: 1.2;
  white-space: nowrap;
  text-shadow: 0 0 18px color-mix(in oklab, var(--gold), transparent 65%);
}

#stack-track {
  position: relative;
  flex: 1;
  width: 0.62rem;
  border-radius: 999px;
  background: var(--hairline);
  display: flex;
  align-items: flex-end;
  min-height: 0;
}
#stack-fill {
  width: 100%;
  height: calc(var(--fill, 0) * 100%);
  border-radius: 999px;
  background: linear-gradient(180deg, var(--gold-hi), var(--gold) 55%, #8a6a1f);
  box-shadow: 0 0 12px color-mix(in oklab, var(--gold), transparent 55%);
}
/* percentage marker that rides the top edge of the gold fill */
#stack-pct {
  position: absolute;
  inset-inline-start: 50%;
  bottom: calc(var(--fill, 0) * 100%);
  transform: translate(-50%, 50%);
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 0.58rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--gold-hi);
  background: color-mix(in oklab, var(--rail-bg), #000 25%);
  border: 1px solid color-mix(in oklab, var(--gold), transparent 55%);
  border-radius: 999px;
  padding: 0.12rem 0.4rem;
  white-space: nowrap;
  pointer-events: none;
}

#rail-hint {
  font-family: var(--font-mono);
  font-size: 0.58rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--chrome-soft);
  writing-mode: vertical-lr;
  text-orientation: mixed;
}

/* ----------------------------------------------------------------------------
   Scene + intro hero
   -------------------------------------------------------------------------- */
#scene {
  position: relative;
  margin-inline-start: var(--rail-w);
}

#intro {
  position: absolute;
  inset-block-start: 0;
  inset-inline: 0;
  min-height: 82vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding-inline: clamp(1.5rem, 7vw, 7rem);
}
#intro-title {
  font-family: var(--font-display);
  font-weight: 900;
  font-size: clamp(3rem, 11vw, 8.5rem);
  line-height: 0.92;
  letter-spacing: -0.02em;
  margin: 0;
  max-width: 14ch;
  font-variation-settings: "SOFT" 0, "WONK" 1;
}
#intro-sub {
  font-family: var(--font-body);
  font-size: clamp(1rem, 2vw, 1.4rem);
  color: var(--ink-soft);
  margin: 1.4rem 0 0;
  max-width: 36ch;
}
#intro-chevron {
  margin-block-start: 2.6rem;
  font-size: 1.8rem;
  color: var(--gold);
  animation: bob 1.8s ease-in-out infinite;
}
@keyframes bob {
  0%, 100% { transform: translateY(0); opacity: 0.6; }
  50%      { transform: translateY(0.5rem); opacity: 1; }
}

/* date stamp in the glow space at the very bottom (sits inside the scene, so it
   doesn't add scroll past the finale) */
#page-footer {
  position: absolute;
  inset-block-end: 1.6rem;
  inset-inline: 0;
  text-align: center;
  font-family: "Heebo", "Archivo", sans-serif;
  font-size: 0.7rem;
  letter-spacing: 0.06em;
  color: color-mix(in oklab, var(--paper), transparent 62%);
}

/* ----------------------------------------------------------------------------
   Milestones - editorial bands, alternating inline alignment for rhythm
   -------------------------------------------------------------------------- */
.milestone {
  position: absolute;
  inset-inline-start: clamp(1.25rem, 6vw, 6.5rem);
  width: min(31rem, 62vw);
  /* premium card: parchment surface that fades in as the page descends, with a
     layered elevation shadow + hairline that also scale with depth (so the card
     is fully invisible up top where text sits on the page, and lifts off the
     vault below) */
  background: var(--plate);
  padding: clamp(1.4rem, 2.4vw, 1.9rem) clamp(1.5rem, 2.6vw, 2.1rem);
  border-radius: 10px;
  box-shadow:
    0 1px 2px rgba(8, 10, 8, calc(var(--plate-op) * 0.2)),
    0 20px 44px -16px rgba(0, 0, 0, calc(var(--plate-op) * 0.62)),
    inset 0 0 0 1px rgba(22, 32, 24, calc(var(--plate-op) * 0.1));
  /* reveal: fade the whole card (opacity doesn't change the observed geometry) */
  opacity: 0;
  transition: opacity 0.7s ease;
}
.milestone.is-visible { opacity: 1; }
/* the slide lives on the inner wrapper, so the observed .milestone box never
   moves - no IntersectionObserver feedback flicker at the threshold */
.milestone__inner {
  transform: translateY(1.6rem);
  transition: transform 0.7s cubic-bezier(0.16, 1, 0.3, 1);
}
.milestone.is-visible .milestone__inner { transform: none; }

/* every other milestone hugs the inline-end edge for editorial rhythm */
.milestone:nth-of-type(even) {
  inset-inline-start: auto;
  inset-inline-end: clamp(1.25rem, 6vw, 6.5rem);
  text-align: end;
}

.milestone__icon {
  display: inline-block;
  width: 1.85rem;
  height: 1.85rem;
  color: color-mix(in oklab, var(--ink), transparent 10%);
  margin-block-end: 0.85rem;
}
.milestone__eyebrow {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--gold-ink);
  margin: 0 0 0.8rem;
}
.milestone__headline {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(1.5rem, 2.6vw, 2.35rem);
  line-height: 1.06;
  letter-spacing: -0.01em;
  margin: 0;
  text-wrap: balance;
  color: var(--ink);
}
.milestone__amount {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 0.92rem;
  letter-spacing: 0.01em;
  color: var(--ink-soft);
  margin: 0.75rem 0 0;
}
.milestone__blurb {
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.5;
  color: var(--ink-soft);
  margin: 0.7rem 0 0;
  max-width: 34ch;
}
.milestone__blurb--mono {
  font-family: var(--font-mono);
  font-size: 0.86rem;
  line-height: 1.55;
}
.milestone:nth-of-type(even) .milestone__blurb { margin-inline-start: auto; }

/* waypoints read a touch louder */
.milestone--waypoint .milestone__headline {
  font-weight: 900;
  font-size: clamp(1.7rem, 3vw, 2.75rem);
}

/* quantity: a tidy grid of monochrome glyphs - an infographic, not stickers */
.milestone--quantity { width: min(34rem, 66vw); }
.milestone__grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 0.55rem;
  margin: 1.2rem 0 0;
  max-width: 26rem;
  color: color-mix(in oklab, var(--ink), transparent 6%);
}
.milestone__glyph { width: 1.4rem; height: 1.4rem; display: block; flex: none; }
.milestone:nth-of-type(even) .milestone__grid { justify-content: flex-end; margin-inline-start: auto; }

/* the bottom: Elon at $1T opts out of the card - gold on the bare vault */
.milestone[data-amount="1000000000000"] {
  inset-inline: 0 !important;
  text-align: center;
  width: auto;
  padding-inline: 6vw;
  background: none;
  box-shadow: none;
}
.milestone[data-amount="1000000000000"] .milestone__icon {
  display: block;
  width: 3rem;
  height: 3rem;
  margin: 0 auto 0.6rem;
  color: var(--gold-hi);
}
.milestone[data-amount="1000000000000"] .milestone__eyebrow {
  color: color-mix(in oklab, var(--gold), transparent 25%);
}
.milestone[data-amount="1000000000000"] .milestone__headline {
  font-weight: 900;
  font-size: clamp(3.4rem, 12vw, 8.5rem);
  color: var(--gold-hi);
  letter-spacing: -0.02em;
  text-shadow: 0 0 60px color-mix(in oklab, var(--gold), transparent 45%);
}
.milestone[data-amount="1000000000000"] .milestone__amount {
  color: var(--gold);
  margin-block-start: 0.4rem;
}
.milestone[data-amount="1000000000000"] .milestone__blurb {
  margin-inline: auto;
  color: color-mix(in oklab, var(--paper), transparent 28%);
}

/* ----------------------------------------------------------------------------
   Responsive - on narrow screens the rail becomes a slim top bar
   -------------------------------------------------------------------------- */
@media (max-width: 640px) {
  :root { --rail-w: 0rem; }
  #rail {
    inset: 0 0 auto 0;
    flex-direction: row;
    width: 100%;
    height: 3.2rem;
    padding: 0 0.9rem;
    gap: 0.8rem;
    border-inline-end: none;
    border-block-end: 1px solid var(--hairline);
  }
  #stack-track {
    flex: 1;
    width: auto;
    height: 0.5rem;
    align-items: stretch;
    flex-direction: row;
  }
  #stack-fill {
    width: calc(var(--fill, 0) * 100%);
    height: 100%;
    align-self: stretch;
  }
  /* Pin the % to the end of the horizontal bar. It can't ride the fill edge here:
     the value sits near 0% for most of the scroll, so an edge marker would land
     under the counter. */
  #stack-pct {
    display: block;
    inset-inline-start: auto;
    inset-inline-end: 0.15rem;
    bottom: auto;
    top: 50%;
    transform: translateY(-50%);
  }
  #rail-hint { display: none; }
  #scene { margin-block-start: 3.2rem; }
  .milestone, .milestone:nth-of-type(even) {
    inset-inline: 1.4rem auto;
    width: auto;
    text-align: start;
  }
}

@media (prefers-reduced-motion: reduce) {
  .milestone { transition: opacity 0.3s; }
  .milestone__inner { transform: none; transition: none; }
  #intro-chevron { animation: none; }
}
