/* ==========================================================================
   Base: reset, typography, focus, selection, scrollbar, motion preferences
   ========================================================================== */

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

html {
  scrollbar-gutter: stable;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--header-h-compact) + 16px);
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  line-height: var(--lh-body);
  font-feature-settings: "ss01", "cv11";
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  overflow-x: clip;
}

main { flex: 1 0 auto; display: block; }
html.modal-open { overflow: hidden; }

img, svg, video { display: block; max-width: 100%; }
svg { flex: none; }

h1, h2, h3, h4, p, ul, ol, figure, dl, dd { margin: 0; }
ul, ol { padding: 0; list-style: none; }

h1, h2, h3, h4 { text-wrap: balance; }
p { text-wrap: pretty; }

a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; letter-spacing: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
button:disabled, [aria-disabled="true"] { cursor: not-allowed; opacity: .5; }

code, kbd, pre, samp { font-family: var(--font-mono); font-size: 0.92em; }

[hidden] { display: none !important; }

/* ---------- Typography helpers ---------- */
.display {
  font-family: var(--font-display);
  font-weight: 400;
  letter-spacing: -0.015em;
  line-height: var(--lh-tight);
}
.display em, .italic { font-style: italic; }
.mono { font-family: var(--font-mono); }
.eyebrow {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.lede {
  font-size: var(--fs-lg);
  line-height: 1.5;
  color: var(--ink-2);
  max-width: 38em;
}
.muted { color: var(--ink-2); }

/* Text links inside prose: animated underline */
.prose a, .link {
  background-image: linear-gradient(currentColor, currentColor);
  background-repeat: no-repeat;
  background-position: 0 100%;
  background-size: 100% 1px;
  color: var(--primary-text);
  transition: background-size var(--dur-2) var(--ease-out);
}
.prose a:hover, .link:hover { background-size: 100% 2px; }

/* ---------- Focus: always visible for keyboard users ---------- */
:focus { outline: none; }
:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: var(--r-xs);
}

/* ---------- Polish ---------- */
::selection { background: var(--primary); color: var(--on-primary); }

html { scrollbar-color: var(--line-strong) transparent; scrollbar-width: thin; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: var(--r-pill); border: 3px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--ink-3); }
::-webkit-scrollbar-track { background: transparent; }

/* Skip link */
.skip-link {
  position: fixed;
  top: 8px;
  left: 8px;
  z-index: calc(var(--z-toast) + 1);
  padding: 12px 16px;
  min-height: 44px;
  background: var(--ink);
  color: var(--bg);
  border-radius: var(--r-sm);
  font-weight: 600;
  transform: translateY(calc(-100% - 24px));
  transition: transform var(--dur-2) var(--ease-out);
}
.skip-link:focus { transform: none; }

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

/* ---------- Scroll reveals (only when JS is running) ---------- */
.js [data-reveal] {
  opacity: 0;
  transform: translateY(18px);
  transition: opacity var(--dur-4) var(--ease-out), transform var(--dur-4) var(--ease-out);
  transition-delay: calc(var(--i, 0) * 70ms);
}
.js [data-reveal].in { opacity: 1; transform: none; }

/* Smooth theme switching: added briefly by theme.js */
.theme-fade, .theme-fade *, .theme-fade *::before, .theme-fade *::after {
  transition: background-color var(--dur-3) var(--ease-in-out), color var(--dur-3) var(--ease-in-out),
              border-color var(--dur-3) var(--ease-in-out), fill var(--dur-3) var(--ease-in-out) !important;
}

/* Cross-page transitions where the browser supports them */
@view-transition { navigation: auto; }
::view-transition-old(root), ::view-transition-new(root) { animation-duration: 220ms; }

/* ---------- Reduced motion: keep everything, drop the movement ---------- */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    transition-delay: 0ms !important;
  }
  .js [data-reveal] { opacity: 1; transform: none; }
  @view-transition { navigation: none; }
}

/* Elements that only make sense with JavaScript */
html:not(.js) .js-only { display: none !important; }
input[type="search"]::-webkit-search-cancel-button, input[type="search"]::-webkit-search-decoration { -webkit-appearance: none; appearance: none; display: none; }
