/* ============================================================================
   Base + shared components — chai-homelab.com v3
   Consumes css/tokens.css (load tokens FIRST). Every component reads the generic
   --accent, so the same markup restyles per page from the token layer alone.
   Glow is budgeted: primary-button hover/focus, .glow-text, .pulse, the live
   strip. Nothing else glows.
   ========================================================================== */

/* ---------- fonts (self-hosted, variable woff2) ---------- */
@font-face {
  font-family: 'Space Grotesk';
  src: url('../fonts/space-grotesk.woff2') format('woff2');
  font-weight: 300 700;
  font-display: swap;
}
@font-face {
  font-family: 'JetBrains Mono';
  src: url('../fonts/jetbrains-mono.woff2') format('woff2');
  font-weight: 100 800;
  font-display: swap;
}

/* ---------- reset & defaults ---------- */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }

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

body {
  background: var(--bg-0);
  color: var(--text-2);
  font-family: var(--font-sans);
  font-size: var(--fs-2);
  line-height: var(--lh-body);
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

main { flex: 1 0 auto; }

h1, h2, h3, h4, h5 {
  font-family: var(--font-display);
  color: var(--text-1);
  line-height: var(--lh-snug);
  font-weight: 600;
  text-wrap: balance;
  letter-spacing: -0.01em;
}

p { max-width: 68ch; text-wrap: pretty; }

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

a {
  color: var(--accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  transition: color var(--t-fast) var(--ease);
}
a:hover { color: var(--text-1); }

::selection { background: var(--accent-faint); color: var(--text-1); }

code, pre, .mono { font-family: var(--font-mono); }
pre {
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: var(--r-2);
  padding: var(--sp-4);
  overflow-x: auto;
  font-size: var(--fs-1);
}

/* designed focus ring: crisp accent line + soft halo — unmistakable on every surface */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
  box-shadow: 0 0 0 6px var(--accent-faint);
}

/* ---------- layout ---------- */
.container {
  width: 100%;
  max-width: var(--maxw);
  margin-inline: auto;
  padding-inline: max(var(--sp-5), env(safe-area-inset-left)) max(var(--sp-5), env(safe-area-inset-right));
}
.container--wide { max-width: var(--maxw-wide); }

.section { padding-block: clamp(3.5rem, 2.2rem + 3.6vw, 6.5rem); } /* fluid vertical rhythm, mobile -> ultrawide */
.section--tight { padding-block: var(--sp-10); }

.section__title {
  font-size: var(--fs-4);
  margin-bottom: var(--sp-6);
}

.kicker {
  font-family: var(--font-mono);
  font-size: var(--fs-0);
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.16em;
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  margin-bottom: var(--sp-3);
}
.kicker::before {
  content: '';
  width: 1.75rem;
  height: 1px;
  background: var(--accent);
  opacity: 0.7;
}

.lede {
  font-size: var(--fs-3);
  line-height: 1.4;
  color: var(--text-1);
  font-weight: 400;
  max-width: 40ch;
}

/* ---------- a11y primitives ---------- */
.skip-link {
  position: absolute;
  left: var(--sp-4);
  top: calc(-1 * var(--sp-12));
  z-index: 100;
  background: var(--bg-2);
  color: var(--text-1);
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-1);
  transition: top var(--t-fast) var(--ease);
}
.skip-link:focus { top: var(--sp-4); }

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

/* ---------- nav (persistent, identical on every page) ---------- */
.site-nav {
  position: sticky;
  top: 0;
  z-index: 50;
  background: color-mix(in srgb, var(--bg-0) 82%, transparent);
  backdrop-filter: blur(14px) saturate(1.2);
  -webkit-backdrop-filter: blur(14px) saturate(1.2);
  border-bottom: 1px solid var(--line);
}

.site-nav__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
  min-height: 62px;
}

.site-nav__brand {
  color: var(--accent);
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: var(--fs-2);
  letter-spacing: 0.02em;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.1em;
}
.site-nav__brand::after {
  content: '';
  width: 0.5ch;
  height: 1.05em;
  background: var(--accent);
  display: inline-block;
  animation: caret 1.3s steps(1) infinite;
}
@keyframes caret { 0%, 50% { opacity: 1; } 50.01%, 100% { opacity: 0; } }

.site-nav__links {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  flex-wrap: wrap;
}

.nav-link {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: var(--sp-2) var(--sp-3);
  border: 0;
  border-radius: var(--r-1);
  background: none;
  color: var(--text-2);
  font: inherit;
  font-size: var(--fs-1);
  text-decoration: none;
  cursor: pointer;
  transition: color var(--t-fast) var(--ease), background var(--t-fast) var(--ease);
}
.nav-link:hover { color: var(--text-1); background: var(--bg-2); }
.nav-link[aria-current='page'] { color: var(--accent); }

.nav-cmd {
  gap: var(--sp-2);
  border: 1px solid var(--line-strong);
  color: var(--text-3);
}
.nav-cmd:hover { border-color: var(--accent-dim); color: var(--text-1); }
.nav-cmd kbd {
  font-family: var(--font-mono);
  font-size: var(--fs-0);
  color: var(--accent);
  background: none;
}

@media (max-width: 600px) {
  .site-nav__inner {
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    padding-block: var(--sp-2);
  }
  .site-nav__brand { padding-block: var(--sp-1); }
  .site-nav__links { width: 100%; justify-content: space-between; gap: 0; }
  .nav-link { padding: var(--sp-2); font-size: var(--fs-0); }
  .nav-cmd { border: 0; }
  .nav-cmd .nav-cmd__label { display: none; }
}

/* ---------- buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  min-height: 46px;
  padding: var(--sp-2) var(--sp-5);
  border-radius: var(--r-1);
  border: 1px solid var(--line-strong);
  background: none;
  color: var(--text-1);
  font: inherit;
  font-size: var(--fs-1);
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  transition: border-color var(--t-fast) var(--ease), background var(--t-fast) var(--ease),
    box-shadow var(--t-med) var(--ease), color var(--t-fast) var(--ease), transform var(--t-fast) var(--ease);
}
.btn:active { transform: translateY(1px); }

.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}
.btn--primary:hover, .btn--primary:focus-visible {
  box-shadow: 0 0 28px var(--accent-glow);
  background: color-mix(in srgb, var(--accent) 88%, white);
}

.btn--ghost { color: var(--text-1); }
.btn--ghost:hover { border-color: var(--accent); color: var(--accent); }

.btn[disabled] { opacity: 0.55; cursor: not-allowed; box-shadow: none; }

.btn .ico { font-size: 1.1em; }

/* ---------- cards, chips, stats ---------- */
.card {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--r-3);
  padding: var(--sp-6);
  transition: border-color var(--t-med) var(--ease), transform var(--t-med) var(--ease),
    box-shadow var(--t-med) var(--ease);
}
.card:hover { border-color: var(--accent-dim); }

.card__title { font-size: var(--fs-3); margin-bottom: var(--sp-2); }
.card__meta {
  color: var(--text-3);
  font-size: var(--fs-0);
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: calc(var(--sp-1) + 1px) var(--sp-3);
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg-3);
  color: var(--text-2);
  font-family: var(--font-mono);
  font-size: var(--fs-0);
  white-space: nowrap;
}

/* Inline SVG icons — <svg class="ico"><use href="#i-name"></use></svg> against the
   per-page sprite. Tints to currentColor (so an icon follows --accent), adds no
   extra requests, and renders identically everywhere (CSS masks are avoided —
   some renderers don't apply mask-image from an external SVG). Icon sources:
   Lucide (ISC, stroke) and Simple Icons (CC0, fill), carried into <symbol>s. */
.ico {
  display: inline-block;
  width: 1em;
  height: 1em;
  flex: none;
  vertical-align: -0.14em;
  color: inherit;
}
.kicker .ico { font-size: 1.05em; }
.chip .ico { font-size: 1em; opacity: 0.9; }
.footer__links .ico,
.duo__label .ico { opacity: 0.95; }

.stat { display: grid; gap: var(--sp-1); }
.stat__value {
  font-family: var(--font-mono);
  font-size: var(--fs-4);
  font-weight: 600;
  color: var(--text-1);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}
.stat__label {
  color: var(--text-3);
  font-size: var(--fs-0);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

/* ---------- forms ---------- */
.field { display: grid; gap: var(--sp-2); margin-bottom: var(--sp-5); }
.field__label { color: var(--text-1); font-weight: 500; }
.field__input {
  background: var(--bg-1);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-1);
  color: var(--text-1);
  font: inherit;
  padding: var(--sp-3) var(--sp-4);
  min-height: 46px;
  transition: border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
}
.field__input:hover { border-color: var(--text-3); }
.field__input:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-faint);
}
.field__input[aria-invalid='true'] { border-color: var(--err); }
.field__error { color: var(--err); font-size: var(--fs-1); }

/* ---------- footer (one footer, every page) ---------- */
.footer {
  border-top: 1px solid var(--line);
  padding-block: var(--sp-8);
  color: var(--text-3);
  font-size: var(--fs-1);
  background: var(--bg-1);
}
.footer a { color: var(--text-2); }
.footer a:hover { color: var(--accent); }
.footer__inner {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-4) var(--sp-5);
  justify-content: space-between;
  align-items: center;
}
.footer__links {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-4);
}
.footer__links a { display: inline-flex; align-items: center; gap: var(--sp-2); }
.footer__links .ico { font-size: 1em; opacity: 0.85; }

/* ---------- effects (budgeted) ---------- */
.glow-text { color: var(--accent); text-shadow: 0 0 20px var(--accent-glow); }

.pulse {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--ok);
  flex: none;
  animation: pulse 2.4s var(--ease) infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--ok) 55%, transparent); }
  50% { box-shadow: 0 0 0 6px transparent; }
}

/* Progressive enhancement: .reveal is visible by default; scroll-reveal.js
   adds .reveal-armed (hidden) + .visible (shown) only when it is running. */
.reveal { transition: opacity var(--t-slow) var(--ease), transform var(--t-slow) var(--ease); }
.reveal.reveal-armed:not(.visible) { opacity: 0; transform: translateY(14px); }
.reveal.visible { opacity: 1; transform: none; }
.stagger-armed { opacity: 0; }

/* ---------- command palette (Ctrl+K) ---------- */
.palette[hidden] { display: none; }
.palette {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 12vh var(--sp-4) var(--sp-4);
  background: rgba(3, 3, 6, 0.72);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
}
.palette__panel {
  width: min(580px, 100%);
  background: var(--bg-1);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-3);
  box-shadow: 0 28px 70px rgba(0, 0, 0, 0.55), 0 0 0 1px var(--accent-faint);
  overflow: hidden;
}
.palette__input {
  width: 100%;
  background: none;
  border: 0;
  border-bottom: 1px solid var(--line);
  color: var(--text-1);
  font-family: var(--font-mono);
  font-size: var(--fs-2);
  padding: var(--sp-4) var(--sp-5);
}
.palette__input:focus { outline: none; }
.palette__input::placeholder { color: var(--text-3); }
.palette__list {
  list-style: none;
  margin: 0;
  padding: var(--sp-2);
  max-height: 340px;
  overflow-y: auto;
}
.palette__item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--sp-4);
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-1);
  color: var(--text-2);
  cursor: pointer;
}
.palette__item[aria-selected='true'] { background: var(--accent-faint); color: var(--text-1); }
.palette__hint { color: var(--text-3); font-family: var(--font-mono); font-size: var(--fs-0); }
.palette__output {
  padding: var(--sp-3) var(--sp-5);
  border-top: 1px solid var(--line);
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: var(--fs-1);
  white-space: pre-wrap;
}
.palette__output:empty { display: none; }
.palette__item--empty { color: var(--text-3); cursor: default; justify-content: center; }

/* ---------- 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;
  }
  .site-nav__brand::after { animation: none; opacity: 1; }
  .reveal.reveal-armed:not(.visible) { opacity: 1; transform: none; }
  .stagger-armed { opacity: 1; }
}


/* ---------- craft pass ---------- */
/* on-brand thin scrollbars (terminal, palette, tree, page) */
html { scrollbar-width: thin; scrollbar-color: var(--bg-3) transparent; }

/* palette rows respond to the pointer, without masking the selected row */
.palette__item:not([aria-selected='true']):not(.palette__item--empty):hover { background: var(--bg-2); color: var(--text-1); }

/* touch: every control clears 44px without loosening the pointer-dense layout */
@media (pointer: coarse) {
  .chip-toggle, .dash-refresh, .terminal__skip, .tree__folder, .palette__item { min-height: 44px; }
}
