/* ─────────────────────────────────────────
   LOADER  —  brand pre-loader
   The logo IS the progress indicator: a dimmed copy sits underneath, and
   an identical copy on top is revealed left → right by an SVG clipPath
   whose width js/loader.js drives from real load progress.

   Progressive enhancement, same contract as .js-reveal in layout.css:
   everything here only applies while <html> carries .has-loader, which
   is added by a tiny inline script in <head> (index.html) — and only when
   JS runs, the visitor hasn't reduced motion, and the loader hasn't
   already played this session. Without that class the markup is
   display:none, so no-JS visitors never see (or get stuck behind) it.
───────────────────────────────────────── */

.site-loader { display: none; }

.has-loader .site-loader {
  position: fixed;
  inset: 0;
  z-index: 10000;                 /* above toast / skip-link (9999) and every modal (≤ 8600) */
  display: grid;
  grid-template-rows: auto 1fr auto;   /* header rule · logo stage · status row */
  /* env() keeps the status row clear of the iPhone home indicator / notch (0 elsewhere). */
  padding: max(var(--loader-pad), env(safe-area-inset-top)) max(var(--loader-pad), env(safe-area-inset-right))
           max(var(--loader-pad), env(safe-area-inset-bottom)) max(var(--loader-pad), env(safe-area-inset-left));
  background: var(--loader-bg);
  color: var(--loader-fg);
  /* Exit: the whole sheet lifts away. transform-only, so it stays on the compositor. */
  transition: transform var(--loader-exit) var(--ease-out);
  will-change: transform;
  /* Last-resort escape hatch with zero JS: if loader.js never tears this
     down (script error, blocked module…), hide it after --loader-failsafe. */
  animation: loader-failsafe 0s linear var(--loader-failsafe) forwards;
}

.site-loader.is-leaving {
  transform: translate3d(0, -100%, 0);
  pointer-events: none;
}

/* ── Editorial frame ───────────────────────────────────────────
   Quiet technical annotations around the logo, borrowing the vocabulary of
   spec-sheet / index-card layouts: parenthetical titles, numbered steps,
   coordinates, a three-digit counter. Same mono voice as the rest of the
   site (.sidebar-logo: Geist Mono, 10px, +.06em). Everything shares one
   4-column grid (2 on phones) so header and status row line up. */
.site-loader__label {
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 500;
  line-height: 1.4;
  letter-spacing: .06em;
  text-transform: uppercase;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  color: var(--loader-fg);
  opacity: var(--loader-meta);
}

.site-loader__bar,
.site-loader__steps {
  position: relative;               /* anchors the drawn hairline (pseudo-element) */
  display: grid;
  column-gap: 20px;
  margin: 0;
  padding: 0;
  list-style: none;
}

/* Header: title | coordinates | counter. Equal outer tracks (1fr) around an
   auto middle track put the coordinates on the frame's true centre line,
   independent of how wide the title and counter are. */
.site-loader__bar   { grid-template-columns: 1fr auto 1fr; padding-bottom: 12px; }
/* Status row: four equal columns. */
.site-loader__steps { grid-template-columns: repeat(4, minmax(0, 1fr)); padding-top: 14px; row-gap: 18px; }

.site-loader__title  { grid-column: 1; justify-self: start; }
.site-loader__coords { grid-column: 2; justify-self: center; }
.site-loader__count  { grid-column: 3; justify-self: end; opacity: 1; }  /* the one full-strength label */

/* ── Hairlines ─────────────────────────────────────────────────
   Drawn as 1px pseudo-elements (not borders) so they can animate with a
   compositor-only scaleX, left → right. */
.site-loader__bar::after,
.site-loader__steps::before {
  content: '';
  position: absolute;
  left: 0; right: 0;
  height: 1px;
  background: var(--loader-line);
  transform: scaleX(0);
  transform-origin: 0 50%;
}
.site-loader__bar::after    { bottom: -1px; }
.site-loader__steps::before { top: -1px; }

/* ── Entrance choreography ─────────────────────────────────────
   One clock: js/loader.js adds .is-running on the same frame the logo fill
   starts and sets --loader-draw to the fill's duration (= CONFIG.minFillMs).
   Scramble and rules are driven off that same t0 (not their own timers).
   EVERYTHING starts at 0; each element then has its own length and end time,
   as a fraction of --loader-draw:
     text scramble   ends 0.48 → 0.70   (per element, data-scramble in index.html)
     upper rule      ends 0.78          (--loader-line-top-end)
     lower rule      ends 0.86          (--loader-line-bottom-end)
     logo fill       ends 1.00          ← defines total duration; untouched
   So the order is: text resolves → rules settle → logo completes → curtain. */
/* Resting (= final) state once running. The draw-in itself is a Web
   Animation started by js/loader.js with an explicit startTime equal to the
   logo fill's t0 — a plain CSS animation would start a few frames late on a
   busy first load and drift behind the fill. It stays compositor-only. */
.site-loader.is-running .site-loader__bar::after,
.site-loader.is-running .site-loader__steps::before { transform: scaleX(1); }

/* Labels are held invisible until the sequence starts (so the final text
   never flashes before scrambling), then fade in over the first 12% — a
   short ease so scrambled glyphs and the non-scrambled counter / state
   words don't pop. The scramble itself is JS (text can't be animated in CSS). */
.site-loader:not(.is-running) .site-loader__label { opacity: 0; }
.site-loader.is-running .site-loader__label {
  animation: loader-fade calc(var(--loader-draw) * .12) var(--ease-out) backwards;
}

.site-loader__stage { display: grid; place-items: center; }

.site-loader__step { display: grid; gap: 6px; align-content: start; }

/* State line: a 6px square (hollow → solid) + word, drawn in CSS so JS only flips data-state. */
.site-loader__state { display: inline-flex; align-items: center; gap: 7px; }
.site-loader__state::before {
  content: '';
  width: 6px; height: 6px;
  box-sizing: border-box;
  border: 1px solid currentColor;
  transition: background-color .3s var(--ease-out);
}
.site-loader__state::after { content: 'Loading'; }
.site-loader__step[data-state='ready'] .site-loader__state { opacity: 1; }
.site-loader__step[data-state='ready'] .site-loader__state::before { background: currentColor; }
.site-loader__step[data-state='ready'] .site-loader__state::after  { content: 'Ready'; }

/* On exit the annotations step aside first so the logo lifts away alone. */
.site-loader__bar,
.site-loader__steps { transition: opacity .3s var(--ease); }
.site-loader.is-leaving .site-loader__bar,
.site-loader.is-leaving .site-loader__steps { opacity: 0; }

@media (max-width: 560px) {
  .site-loader__bar,
  .site-loader__steps { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .site-loader__coords { display: none; }
  .site-loader__count  { grid-column: 2; }
}

.site-loader__logo {
  display: block;
  /* Wordmark is ~7.3:1, so width drives everything (token in tokens.css). */
  width: var(--loader-logo-w);
  height: auto;
  overflow: visible;              /* anti-aliased edges never get cropped by the tight viewBox */
}

.site-loader__base { fill: var(--loader-fg); opacity: var(--loader-dim); }
.site-loader__fill { fill: var(--loader-fg); }

@keyframes loader-fade { from { opacity: 0; } }

@keyframes loader-failsafe {
  to { visibility: hidden; pointer-events: none; }
}
