/* ==========================================================================
   meridian — base
   Reset, document typography, the ambient backdrop, scrollbars, focus.
   Consumes tokens.css only; declares no raw colour.
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; }

* { margin: 0; padding: 0; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
}

/* The app shell is a fixed viewport with internal scrolling, matching the rest
   of the platform. --real-vh is set by the shell's inline script to work around
   iOS Safari's dynamic address bar (see CLAUDE.md, "Mobile Viewport Height Fix"). */
html, body {
  height: var(--real-vh, 100vh);
  width: 100%;
  overflow: hidden;
}

body.lx {
  background: var(--lx-bg);
  color: var(--lx-t1);
  font-family: var(--lx-f-ui);
  font-size: var(--lx-fs-base);
  line-height: var(--lx-lh-body);
  letter-spacing: var(--lx-ls-body);
  font-weight: 400;
  font-synthesis-weight: none;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  overscroll-behavior: none;
}

/* ── Ambient backdrop ──────────────────────────────────────────────────────
   Three drifting radial blobs + film grain + vignette. The grain is what stops
   this reading as "a CSS gradient" — without it the mesh looks synthetic at
   any size. All layers are inert to pointer events and sit beneath content.  */

.lx-backdrop {
  position: fixed;
  inset: 0;
  z-index: var(--lx-z-backdrop);
  pointer-events: none;
  overflow: hidden;
  background: var(--lx-bg);
}

.lx-backdrop__mesh {
  position: absolute;
  /* Overscan so the drifting blobs never expose an edge */
  inset: -30%;
  opacity: var(--lx-mesh-opacity);
  background:
    radial-gradient(44% 38% at 16% 20%, rgb(var(--lx-mesh-1) / var(--lx-mesh-str)) 0%, transparent 70%),
    radial-gradient(50% 44% at 84% 26%, rgb(var(--lx-mesh-2) / var(--lx-mesh-str)) 0%, transparent 72%),
    radial-gradient(56% 50% at 44% 92%, rgb(var(--lx-mesh-3) / var(--lx-mesh-str)) 0%, transparent 74%),
    radial-gradient(38% 34% at 68% 66%,
      rgb(var(--lx-mesh-1) / calc(var(--lx-mesh-str) * 0.6)) 0%, transparent 70%);
  filter: blur(34px);
  will-change: transform;
  animation: lx-drift var(--lx-t-drift) ease-in-out infinite alternate;
  transition: background var(--lx-t-slow) var(--lx-ease);
}

@keyframes lx-drift {
  0%   { transform: translate3d(0, 0, 0) scale(1); }
  33%  { transform: translate3d(2.5%, -2%, 0) scale(1.06); }
  66%  { transform: translate3d(-2%, 2.5%, 0) scale(1.03); }
  100% { transform: translate3d(1.5%, 1.5%, 0) scale(1.08); }
}

/* Film grain — an inline fractal-noise SVG, so no image request and no
   dependency on an asset pipeline. */
.lx-backdrop__grain {
  position: absolute;
  inset: 0;
  opacity: var(--lx-grain-opacity);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size: 220px 220px;
  mix-blend-mode: overlay;
}

.lx-backdrop__vignette {
  position: absolute;
  inset: 0;
  background: radial-gradient(120% 90% at 50% 42%, transparent 42%, var(--lx-vignette) 100%);
}

/* ── Typography ─────────────────────────────────────────────────────────── */

h1, h2, h3, h4, h5, h6 {
  font-weight: 500;
  line-height: var(--lx-lh-tight);
  letter-spacing: var(--lx-ls-title);
  color: var(--lx-t1);
  text-wrap: balance;
}

h1 { font-size: var(--lx-fs-2xl); }
h2 { font-size: var(--lx-fs-xl); }
h3 { font-size: var(--lx-fs-lg); }
h4 { font-size: var(--lx-fs-md); }
h5, h6 { font-size: var(--lx-fs-base); }

p { text-wrap: pretty; }

/* The single serif moment in the interface. Used for the ambient greeting and
   for large numerals — never for UI chrome, which stays entirely in Inter. */
.lx-display {
  font-family: var(--lx-f-display);
  font-weight: 400;
  font-size: var(--lx-fs-3xl);
  line-height: 1.05;
  letter-spacing: var(--lx-ls-hero);
  color: var(--lx-t1);
}

/* Uppercase mono micro-label — the recurring structural motif that separates
   sections without needing rules or headings. */
.lx-label {
  font-family: var(--lx-f-mono);
  font-size: var(--lx-fs-micro);
  font-weight: 500;
  letter-spacing: var(--lx-ls-label);
  text-transform: uppercase;
  color: var(--lx-t3);
}

.lx-wordmark {
  font-family: var(--lx-f-ui);
  font-weight: 300;
  letter-spacing: var(--lx-ls-wordmark);
  text-transform: uppercase;
  color: var(--lx-t1);
  /* Tracking adds trailing space; pull it back so the mark optically centres */
  margin-right: calc(var(--lx-ls-wordmark) * -1);
}

.lx-lead { font-size: var(--lx-fs-md); color: var(--lx-t2); line-height: var(--lx-lh-snug); }
.lx-muted { color: var(--lx-t3); }
.lx-faint { color: var(--lx-t4); }

.lx-num {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

a {
  color: var(--lx-link);
  text-decoration: none;
  text-underline-offset: 0.2em;
  transition: color var(--lx-t-fast) var(--lx-ease);
}
a:hover { text-decoration: underline; }

/* Long-form reading context — used by the article reader */
.lx-prose {
  max-width: var(--lx-measure);
  color: var(--lx-t2);
  line-height: var(--lx-lh-loose);
}
.lx-prose > * + * { margin-top: var(--lx-s-4); }
.lx-prose h2 { margin-top: var(--lx-s-10); font-size: var(--lx-fs-lg); color: var(--lx-t1); }
.lx-prose h3 { margin-top: var(--lx-s-8); font-size: var(--lx-fs-md); color: var(--lx-t1); }
.lx-prose ul, .lx-prose ol { padding-left: var(--lx-s-5); }
.lx-prose li + li { margin-top: var(--lx-s-2); }
.lx-prose strong { color: var(--lx-t1); font-weight: 500; }
.lx-prose code {
  font-family: var(--lx-f-mono);
  font-size: 0.9em;
  background: var(--lx-fill);
  border-radius: var(--lx-r-sm);
  padding: 0.15em 0.4em;
}
.lx-prose blockquote {
  border-left: 2px solid var(--lx-accent);
  padding-left: var(--lx-s-4);
  color: var(--lx-t3);
  font-style: italic;
}

/* ── Form element inheritance ───────────────────────────────────────────── */

button, input, textarea, select {
  font: inherit;
  letter-spacing: inherit;
  color: inherit;
  background: none;
  border: none;
}
button { cursor: pointer; }
textarea { resize: none; }

::placeholder { color: var(--lx-t4); opacity: 1; }

/* ── Icons ──────────────────────────────────────────────────────────────── */

.lx-icon {
  display: block;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ── Focus ──────────────────────────────────────────────────────────────── */

:focus { outline: none; }

:focus-visible {
  outline: 2px solid var(--lx-focus);
  outline-offset: 2px;
  border-radius: var(--lx-r-sm);
}

/* ── Selection ──────────────────────────────────────────────────────────── */

::selection {
  background: var(--lx-accent-soft);
  color: var(--lx-t1);
}

/* ── Scrollbars ─────────────────────────────────────────────────────────── */

.lx-scroll { overflow-y: auto; overscroll-behavior: contain; }

* { scrollbar-width: thin; scrollbar-color: var(--lx-fill-active) transparent; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--lx-fill-active);
  border-radius: var(--lx-r-full);
  border: 3px solid transparent;
  background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover { background: var(--lx-t4); background-clip: content-box; }

/* ── Utilities ──────────────────────────────────────────────────────────── */

/* Components here set an explicit `display`, which beats the UA stylesheet's
   `[hidden]{display:none}` — so the attribute needs to win outright. */
[hidden] { display: none !important; }

.lx-sr {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.lx-stack   { display: flex; flex-direction: column; }
.lx-row     { display: flex; align-items: center; }
.lx-between { display: flex; align-items: center; justify-content: space-between; }
.lx-grow    { flex: 1 1 auto; min-width: 0; min-height: 0; }
.lx-truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Entrance ───────────────────────────────────────────────────────────────
   Elements marked [data-reveal] rise and fade in, staggered by theme.js. The
   default state is visible, so content is never hidden if JS fails to run.   */

@media (prefers-reduced-motion: no-preference) {
  .lx-js [data-reveal] {
    opacity: 0;
    transform: translateY(12px);
  }
  .lx-js [data-reveal].is-revealed {
    opacity: 1;
    transform: none;
    transition:
      opacity var(--lx-t-slow) var(--lx-ease-out),
      transform var(--lx-t-slow) var(--lx-ease-out);
  }
}

/* ── Reduced motion ─────────────────────────────────────────────────────────
   The ambient drift is the single most motion-heavy element here; freeze it
   entirely rather than merely shortening it.                                */

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }

  .lx-backdrop__mesh { animation: none; }

  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
