/* =========================================================================
   BASE — reset, global typography, focus & accessibility defaults
   Depends on: tokens.css (load first)
   ========================================================================= */

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

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

@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;
  }
}

body {
  margin: 0;
  min-width: 320px;
  background-color: var(--color-background);
  color: var(--color-foreground);
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  font-weight: var(--weight-regular);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden; /* belt-and-suspenders alongside no-horizontal-scroll layout rules */
  transition: background-color var(--duration-slow) var(--ease-standard),
              color var(--duration-slow) var(--ease-standard);
}

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

/* Reserve layout space for images to avoid CLS — pages should also set
   explicit width/height or aspect-ratio on real <img> tags. */
img { aspect-ratio: attr(width) / attr(height); }

h1, h2, h3, h4, h5, h6 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: var(--weight-semibold);
  line-height: var(--leading-tight);
  letter-spacing: var(--tracking-wide);
  color: var(--color-foreground);
}

h1 { font-size: var(--text-3xl); }
h2 { font-size: var(--text-2xl); }
h3 { font-size: var(--text-xl); }
h4 { font-size: var(--text-lg); font-family: var(--font-body); font-weight: var(--weight-semibold); letter-spacing: var(--tracking-normal); }
h5, h6 { font-size: var(--text-md); font-family: var(--font-body); font-weight: var(--weight-semibold); letter-spacing: var(--tracking-normal); }

p {
  margin: 0 0 var(--space-4);
  max-width: var(--prose-max-width);
}
p:last-child { margin-bottom: 0; }

a {
  color: var(--color-accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.15em;
  transition: color var(--duration-fast) var(--ease-standard);
}
a:hover { color: var(--color-accent-hover); }
a:active { color: var(--color-accent-active); }

small, .text-caption {
  font-size: var(--text-xs);
  color: var(--color-muted-foreground);
}

/* Data / telemetry text — stream status, live indicator, coordinates */
.text-mono {
  font-family: var(--font-mono);
  letter-spacing: var(--tracking-normal);
}

ul, ol { padding-left: var(--space-5); margin: 0 0 var(--space-4); }

hr {
  border: none;
  border-top: var(--border-width) solid var(--color-border);
  margin: var(--space-6) 0;
}

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

/* ---------------------------------------------------------------------
   FOCUS STATES — never removed, always visible, 2–4px per guidelines
   --------------------------------------------------------------------- */
:focus-visible {
  outline: 3px solid var(--color-ring);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* Only hide the default browser outline once :focus-visible is supported
   and re-applied above — never remove focus indication outright. */
:focus:not(:focus-visible) {
  outline: none;
}

/* ---------------------------------------------------------------------
   SKIP LINK — keyboard users can bypass nav
   --------------------------------------------------------------------- */
.skip-link {
  position: absolute;
  left: var(--space-4);
  top: -100px;
  z-index: var(--z-toast);
  background: var(--color-primary);
  color: var(--color-primary-foreground);
  padding: var(--space-3) var(--space-5);
  border-radius: var(--radius-md);
  font-weight: var(--weight-semibold);
  transition: top var(--duration-base) var(--ease-out);
}
.skip-link:focus {
  top: var(--space-4);
}

/* ---------------------------------------------------------------------
   SCREEN-READER ONLY UTILITY
   --------------------------------------------------------------------- */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ---------------------------------------------------------------------
   LAYOUT PRIMITIVES
   --------------------------------------------------------------------- */
.container {
  width: 100%;
  max-width: var(--content-max-width);
  margin-inline: auto;
  padding-inline: var(--section-padding-x);
}

.section {
  padding-block: var(--section-padding-y);
}

@media (min-width: 768px) {
  :root { --section-padding-x: var(--space-6); }
}
@media (min-width: 1024px) {
  :root {
    --section-padding-x: var(--space-8);
    --section-padding-y: var(--space-9);
  }
}
