/* ===========================================================================
   base.css — reset, typography, layout primitives, utilities
   =========================================================================== */

/* --- Reset --------------------------------------------------------------- */

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

* { margin: 0; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
  /* Sticky nav is ~66px; keep anchored headings clear of it. */
  scroll-padding-top: 88px;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: var(--step-0);
  line-height: var(--leading-body);
  font-weight: var(--weight-normal);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
  transition: background-color var(--dur-mid) var(--ease-out),
              color var(--dur-mid) var(--ease-out);
}

img, svg, video, canvas, picture {
  display: block;
  max-width: 100%;
  height: auto;
}

input, button, textarea, select {
  font: inherit;
  color: inherit;
}

button { background: none; border: none; }

ul[role="list"],
ol[role="list"] {
  list-style: none;
  padding: 0;
}

table { border-collapse: collapse; border-spacing: 0; }

:target { scroll-margin-top: 96px; }

/* --- Typography ---------------------------------------------------------- */

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-display);
  font-weight: var(--weight-bold);
  line-height: var(--leading-tight);
  letter-spacing: var(--tracking-tight);
  color: var(--text-strong);
  text-wrap: balance;
}

h1 { font-size: var(--step-6); }
h2 { font-size: var(--step-4); }
h3 { font-size: var(--step-2); line-height: var(--leading-snug); }
h4 { font-size: var(--step-1); line-height: var(--leading-snug); letter-spacing: var(--tracking-snug); }
h5 { font-size: var(--step-0); letter-spacing: var(--tracking-snug); }
h6 { font-size: var(--step--1); letter-spacing: var(--tracking-snug); }

p { text-wrap: pretty; }

a {
  color: var(--accent-text);
  text-decoration-color: color-mix(in srgb, var(--accent-text) 40%, transparent);
  text-underline-offset: 3px;
}

a:hover { text-decoration-color: currentColor; }

strong, b { font-weight: var(--weight-semi); color: var(--text-strong); }

code, kbd, samp, pre, .mono {
  font-family: var(--font-mono);
  font-size: 0.92em;
  font-variant-numeric: tabular-nums;
}

code:not(pre code) {
  background: var(--surface-3);
  border: var(--hairline) solid var(--border-soft);
  border-radius: var(--radius-xs);
  padding: 0.12em 0.4em;
}

/* Khmer copy needs a little more line height to avoid clipped diacritics. */
[lang="km"] { line-height: 1.9; }

/* --- Focus --------------------------------------------------------------- */

:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 3px;
  border-radius: var(--radius-xs);
}

/* Mouse users don't get the ring, keyboard users always do. */
:focus:not(:focus-visible) { outline: none; }

/* --- Selection ----------------------------------------------------------- */

::selection {
  background: color-mix(in srgb, var(--brand) 26%, transparent);
  color: var(--text-strong);
}

/* --- Scrollbar (opt-in, subtle) ------------------------------------------ */

* {
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border: 3px solid transparent;
  border-radius: var(--radius-full);
  background-clip: content-box;
}
*::-webkit-scrollbar-thumb:hover { background-color: var(--text-faint); background-clip: content-box; }

/* ===========================================================================
   LAYOUT PRIMITIVES
   =========================================================================== */

.container {
  width: 100%;
  max-width: var(--content);
  margin-inline: auto;
  padding-inline: var(--gutter);
}

.container--wide { max-width: var(--content-wide); }
.container--narrow { max-width: 780px; }

.section {
  padding-block: var(--section-y);
  /* Scroll-reveal offsets slide elements sideways before they land, which on a
     narrow screen would stick out past the viewport and add a horizontal
     scrollbar. `clip` contains that without creating a scroll container, so
     overflow-y stays visible and hover shadows are unaffected. */
  overflow-x: clip;
}

.section--tight { padding-block: calc(var(--section-y) * 0.6); }
.section--sunk { background: var(--bg-sunk); }

/* Vertical stack with a single rhythm knob. */
.stack { display: flex; flex-direction: column; gap: var(--flow, var(--space-2xs)); }
.stack--xs { --flow: var(--space-3xs); }
.stack--sm { --flow: var(--space-2xs); }
.stack--md { --flow: var(--space-xs); }
.stack--lg { --flow: var(--space-sm); }
.stack--xl { --flow: var(--space-md); }

/* Horizontal cluster that wraps gracefully. */
.cluster {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--gap, var(--space-2xs));
}

.cluster--center { justify-content: center; }
.cluster--between { justify-content: space-between; }
.cluster--tight { --gap: var(--space-3xs); }

/* Auto-fitting grid: cards flow into as many columns as fit. */
.grid-auto {
  display: grid;
  gap: var(--gap, var(--space-xs));
  grid-template-columns: repeat(auto-fit, minmax(min(var(--col, 280px), 100%), 1fr));
}

.grid-2, .grid-3, .grid-4 { display: grid; gap: var(--gap, var(--space-xs)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

@media (max-width: 900px) {
  .grid-3, .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 620px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: minmax(0, 1fr); }
}

/* Two-column split that collapses to one. */
.split {
  display: grid;
  gap: clamp(var(--space-sm), 4vw, var(--space-lg));
  grid-template-columns: repeat(auto-fit, minmax(min(420px, 100%), 1fr));
  align-items: center;
}

.split--top { align-items: start; }

/* Any wide, unbreakable block (table, chart, code) scrolls inside itself so
   the page body never scrolls sideways. */
.scroll-x {
  overflow-x: auto;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
}

/* ===========================================================================
   TYPE UTILITIES
   =========================================================================== */

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3xs);
  font-family: var(--font-mono);
  font-size: var(--step--2);
  font-weight: var(--weight-semi);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  color: var(--brand-text);
}

.eyebrow::before {
  content: "";
  width: 22px;
  height: 2px;
  border-radius: var(--radius-full);
  background: currentColor;
  opacity: 0.65;
}

.eyebrow--plain::before { display: none; }

.display   { font-size: var(--step-7); line-height: 0.98; letter-spacing: -0.03em; }
.title-xl  { font-size: var(--step-5); }
.title-lg  { font-size: var(--step-4); }
.title-md  { font-size: var(--step-3); }
.title-sm  { font-size: var(--step-2); }

.lede {
  font-size: var(--step-1);
  line-height: var(--leading-loose);
  color: var(--text-muted);
  max-width: 62ch;
}

.text-sm    { font-size: var(--step--1); }
.text-xs    { font-size: var(--step--2); }
.text-muted { color: var(--text-muted); }
.text-subtle{ color: var(--text-subtle); }
.text-faint { color: var(--text-faint); }
.text-brand { color: var(--brand-text); }
.text-center{ text-align: center; }
.text-balance { text-wrap: balance; }

.measure { max-width: var(--measure); }
.measure--center { max-width: var(--measure); margin-inline: auto; }

.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

/* Gradient headline treatment, used sparingly. */
.gradient-text {
  background: linear-gradient(104deg, var(--brand) 8%, var(--accent) 92%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  /* Fallback for the rare engine that ignores background-clip: text. */
  -webkit-text-fill-color: transparent;
}

/* Marker used to flag content the owner still needs to supply. */
.todo-marker {
  font-family: var(--font-mono);
  font-size: var(--step--2);
  font-weight: var(--weight-semi);
  letter-spacing: 0.04em;
  color: var(--warn-text);
  background: var(--warn-soft);
  border: 1px dashed color-mix(in srgb, var(--warn) 55%, transparent);
  border-radius: var(--radius-xs);
  padding: 0.25em 0.6em;
  display: inline-block;
}

/* ===========================================================================
   MISC UTILITIES
   =========================================================================== */

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

.skip-link {
  position: absolute;
  top: 0;
  left: var(--space-2xs);
  z-index: var(--z-toast);
  transform: translateY(-120%);
  background: var(--brand);
  color: var(--text-on-brand);
  font-weight: var(--weight-semi);
  font-size: var(--step--1);
  padding: var(--space-3xs) var(--space-2xs);
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  text-decoration: none;
  transition: transform var(--dur-fast) var(--ease-out);
}

.skip-link:focus-visible { transform: translateY(0); }

.hidden { display: none !important; }
.relative { position: relative; }
.full-width { width: 100%; }
.no-wrap { white-space: nowrap; }

.divider {
  height: 1px;
  border: 0;
  background: linear-gradient(90deg, transparent, var(--border), transparent);
}

/* Decorative graph-paper backdrop — evokes the field-notebook theme. */
.paper-grid {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(to right, var(--grid-line) 1px, transparent 1px),
    linear-gradient(to bottom, var(--grid-line) 1px, transparent 1px);
  background-size: 34px 34px;
  mask-image: radial-gradient(ellipse 80% 65% at 50% 22%, #000 20%, transparent 78%);
  -webkit-mask-image: radial-gradient(ellipse 80% 65% at 50% 22%, #000 20%, transparent 78%);
}

/* ===========================================================================
   MOTION PREFERENCES
   Everything animated is additive: with motion reduced the page still shows
   its final, complete state — nothing stays hidden or half-drawn.
   =========================================================================== */

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

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

/* --- Print --------------------------------------------------------------- */

@media print {
  .site-nav, .site-footer, .scroll-progress, .theme-toggle { display: none !important; }
  body { background: #fff; color: #000; }
  .section { padding-block: 18px; }
  a::after { content: " (" attr(href) ")"; font-size: 0.8em; color: #555; }
}
