/* ==========================================================================
   NightScroll - Base
   Reset, document defaults, typography, accessibility primitives, utilities.
   Load order: tokens.css -> base.css -> components.css -> layouts.css -> pages/*.
   ========================================================================== */

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

* { margin: 0; }

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

body {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;          /* sticky footer on short pages */
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: var(--leading-base);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: clip;
}

main { flex: 1 0 auto; }

/* ---- Typography ----------------------------------------------------------------- */
h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 400;
  line-height: var(--leading-tight);
  letter-spacing: var(--display-tracking);
  text-wrap: balance;
}

h1 { font-size: var(--text-3xl); }
h2 { font-size: var(--text-2xl); }
h3 { font-size: var(--text-xl); }
h4 { font-size: var(--text-lg); }

p { text-wrap: pretty; }

strong { font-weight: 700; }

small { font-size: var(--text-xs); }

a { color: inherit; text-decoration: none; }

/* Inline text links (use inside paragraphs, not on nav/buttons) */
.link {
  color: var(--purple-400);
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--purple-400) 45%, transparent);
  text-underline-offset: 3px;
  transition: color var(--dur-fast) var(--ease-out),
              text-decoration-color var(--dur-fast) var(--ease-out);
}

.link:hover {
  color: var(--purple-300);
  text-decoration-color: currentColor;
}

/* ---- Forms + interactive defaults -------------------------------------------------- */
button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  background: none;
  border: none;
}

button:disabled { cursor: not-allowed; }

/* ---- Media ---------------------------------------------------------------------------- */
img,
svg,
video { display: block; max-width: 100%; }

img { height: auto; }

svg.icon { flex: none; }

ul[class], ol[class] { list-style: none; padding: 0; }

/* ---- Selection ------------------------------------------------------------------------ */
::selection {
  background: var(--purple-600);
  color: var(--white);
}

/* ---- Keyboard focus ------------------------------------------------------------------ */
:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

:focus:not(:focus-visible) { outline: none; }

/* The hidden attribute must win over class-based display rules: components
   like .btn, .suggest-login, .admin-gate, .modal and .lb-summary all set
   `display`, and an author rule beats the UA stylesheet's [hidden] rule.
   Without this, JS-owned toggles (heroSuggest.hidden = true, form.hidden,
   adminGate.hidden = true, ...) silently stay visible. */
[hidden] {
  display: none !important;
}

/* ---- Scrollbars ------------------------------------------------------------------------ */
* {
  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-radius: var(--radius-full);
}
::-webkit-scrollbar-thumb:hover { background: #43435c; }

/* ---- Reduced motion ---------------------------------------------------------------------- */
@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;
  }
}

/* ---- Utilities ----------------------------------------------------------------------------- */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* Line clamps: truncate descriptions / titles without breaking layout */
.clamp-1,
.clamp-2,
.clamp-3,
.clamp-4 {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.clamp-1 { -webkit-line-clamp: 1; line-clamp: 1; }
.clamp-2 { -webkit-line-clamp: 2; line-clamp: 2; }
.clamp-3 { -webkit-line-clamp: 3; line-clamp: 3; }
.clamp-4 { -webkit-line-clamp: 4; line-clamp: 4; }

.text-muted { color: var(--text-muted); }
.text-faint { color: var(--text-faint); }

/* Skip link - first focusable element on every page */
.skip-link {
  position: absolute;
  left: var(--space-4);
  top: calc(-1 * var(--space-9));
  z-index: var(--z-toast);
  padding: var(--space-2) var(--space-4);
  background: var(--purple-600);
  color: var(--white);
  font-weight: 600;
  border-radius: var(--radius-sm);
  transition: top var(--dur-base) var(--ease-out);
}

.skip-link:focus { top: var(--space-4); }

/* ---- Spinners ---------------------------------------------------------------------------------- */
@keyframes ns-spin { to { transform: rotate(360deg); } }

.spin { animation: ns-spin 0.9s linear infinite; }
