/*
 * base.css — reset, typography, prose, scrollbar, global SVG defaults.
 *
 * Loaded on every page (dependency: jacar-tokens).
 *
 * Includes the legacy :root token block (--bg, --text, --teal, etc.)
 * consumed by 200+ rules elsewhere in the theme. These will be migrated
 * to semantic tokens (var(--color-…)) in a later phase, at which point
 * the legacy block can be deleted.
 */

/* The legacy :root token block (--bg, --text, --teal, --footer-*, etc.)
   used to live here. It has been moved to assets/css/tokens.css so the
   light values, dark overrides, and system-dark overrides all sit in
   the same file at equivalent specificity — when this :root lived in
   base.css it loaded AFTER tokens.css and silently overrode every
   [data-theme="dark"] rule, breaking the theme toggle. The
   non-token-y vars (--font, --w-content, --sidebar, --radius, --t, etc.)
   stay below in their own :root since they are theme-invariant. */
:root {
  /* Typography */
  --font:          'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-heading:  'Inter Tight', 'Inter', system-ui, sans-serif;

  /* Layout */
  --w-content:     740px;
  --w-wide:        1100px;
  --w-nav:         1280px;
  --sidebar:       256px;
  --radius:        8px;

  /* Transitions */
  --t:             150ms ease;
  --t-slow:        300ms ease;
}

/* ============================================================
   2. RESET & BASE
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* Default icon size — prevents SVGs without explicit width/height from filling block containers.
   Context-specific rules (post-meta svg, hdr-btn svg, etc.) override this. */
svg[aria-hidden="true"] {
  display: inline-block;
  width: 1em;
  height: 1em;
  vertical-align: -0.125em;
  flex-shrink: 0;
  overflow: visible;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
  /* Sticky-header offset for in-page hash navigation (TOC links, deep
     links from search/share). Replaces the JS `top - 80` handler that
     used to live in core.js — the browser now applies this offset
     natively for any anchor click and for direct page-load with #hash.
     Single posts override this with the dynamic post-hero-stack height
     so anchors land just below the pinned H1+meta strip. */
  scroll-padding-top: 80px;
  -webkit-text-size-adjust: 100%;
  overflow-x: clip;
  /* Native scrollbar follows theme (Firefox + modern Chromium) */
  scrollbar-color: color-mix(in srgb, var(--text) 35%, transparent) transparent;
  scrollbar-width: thin;
}
/* Single-post anchor offset = full sticky band height. The band is
   [site-header (--sticky-top)] + [post-hero stack (--sticky-h1-height)]
   + a small breathing gap. Native fragment scrolls (browser-driven hash
   navigation) auto-detect sticky elements at the top and add their
   heights to the scroll padding implicitly — but Element.scrollIntoView
   (used by the TOC re-click handler) strictly honours the declared
   scroll-padding-top, so we must include both heights here or anchored
   H2s land partially behind the site-header band. Per-H3 anchors layer
   an additional scroll-margin-top in components.css to clear the
   pinned H2 strip above them inside the same section. */
body.is-single { /* on the body, but scroll-padding lives on the scroller */ }
html:has(body.is-single) {
  scroll-padding-top: calc(var(--sticky-top, 62px) + var(--sticky-h1-height, 110px) + .5rem);
}
body { overflow-x: clip; }

/* WebKit scrollbar (Chrome/Safari/Edge) — theme-aware */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--text) 25%, transparent);
  border-radius: 10px;
  border: 2px solid var(--bg);
}
::-webkit-scrollbar-thumb:hover {
  background: color-mix(in srgb, var(--text) 45%, transparent);
}

body {
  font-family: var(--font);
  font-size: 1.0625rem;   /* 17px */
  line-height: 1.75;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background var(--t-slow), color var(--t-slow);
}

img, video { max-width: 100%; height: auto; display: block; }
a { color: var(--teal); text-decoration: none; }
a:hover { color: var(--teal-hover); }
button { cursor: pointer; font: inherit; }
input, textarea { font: inherit; }
ul, ol { padding-left: 1.5em; }
hr { border: none; border-top: 1px solid var(--border); margin: 2rem 0; }

/* ============================================================
   3. TYPOGRAPHY
   ============================================================ */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-heading);
  font-weight: 700;
  line-height: 1.25;
  color: var(--text);
}
h1 { font-size: clamp(1.75rem, 4vw, 2.5rem); }
h2 { font-size: clamp(1.35rem, 3vw, 1.75rem); }
h3 { font-size: clamp(1.1rem, 2.5vw, 1.3rem); }
h4 { font-size: 1.1rem; }
h5, h6 { font-size: 1rem; }

p { margin-bottom: 1.25em; }
p:last-child { margin-bottom: 0; }

strong, b { font-weight: 700; }
em, i { font-style: italic; }

blockquote {
  border-left: 4px solid var(--teal);
  margin: 1.5rem 0;
  padding: .75rem 1.25rem;
  background: var(--teal-lighter);
  border-radius: 0 var(--radius) var(--radius) 0;
  color: var(--text-muted);
  font-style: italic;
}

code {
  font-family: var(--font-mono);
  font-size: .875em;
  background: var(--surface);
  color: var(--teal-dark);
  padding: .15em .4em;
  border-radius: 4px;
  border: 1px solid var(--border);
}

pre {
  background: #0d1117;
  color: #e6edf3;
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  overflow-x: auto;
  margin: 1.5rem 0;
  font-size: .875rem;
  line-height: 1.6;
  box-shadow: var(--shadow);
}

pre code {
  background: none;
  border: none;
  padding: 0;
  color: inherit;
  font-size: inherit;
}

table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.5rem 0;
  font-size: .9375rem;
}
th {
  background: var(--teal);
  color: #fff;
  font-weight: 600;
  text-align: left;
  padding: .6rem 1rem;
}
td {
  padding: .6rem 1rem;
  border-bottom: 1px solid var(--border);
}
tr:nth-child(even) td { background: var(--bg-2); }

/* ============================================================
   4. LAYOUT (.container — global page wrapper)
   ============================================================ */
.container {
  width: 100%;
  max-width: var(--w-nav);
  margin-inline: auto;
  padding-inline: 1.25rem;
}
.container--content {
  max-width: var(--w-content);
}
.container--wide {
  max-width: var(--w-wide);
}

/* ============================================================
   19. SKIP LINK & ACCESSIBILITY
   ============================================================ */
.skip-link {
  position: absolute;
  top: -100%;
  left: 1rem;
  background: var(--teal);
  color: #fff;
  padding: .5rem 1rem;
  border-radius: 0 0 var(--radius) var(--radius);
  font-weight: 700;
  font-size: .875rem;
  z-index: 9999;
  transition: top var(--t);
}
.skip-link:focus { top: 0; }
:focus-visible {
  outline: 3px solid var(--teal);
  outline-offset: 2px;
  border-radius: 3px;
}

/* ============================================================
   20. UTILITIES
   ============================================================ */
.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;
}
.text-muted { color: var(--text-muted); }
.text-teal  { color: var(--teal); }
.mt-auto    { margin-top: auto; }
.flex       { display: flex; }
.gap-sm     { gap: .5rem; }
.gap        { gap: 1rem; }
.items-center { align-items: center; }
.flex-wrap  { flex-wrap: wrap; }

/* ============================================================
   21. PRINT
   ============================================================ */
@media print {
  .site-header, .post-sidebar, .toc-mobile,
  .related-posts, .site-footer, #jacar-progress,
  .author-box__links, .hdr-btn { display: none !important; }
  body { font-size: 12pt; line-height: 1.5; }
  a { color: #000; text-decoration: underline; }
  .post-content a::after { content: " (" attr(href) ")"; font-size: .8em; }
}
