/* ============================================================
   Base: reset, document rhythm, focus, utility primitives
   ============================================================ */

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font-ui);
  font-size: var(--fs-md);
  line-height: var(--lh-body);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-wrap: break-word;
}

/* Starfield + nebula wash. Purely decorative; sits behind everything. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -2;
  background:
    radial-gradient(1100px 620px at 12% -8%, #1b3a6b4d, transparent 60%),
    radial-gradient(900px 520px at 92% 4%, #4a2b7a40, transparent 62%),
    radial-gradient(760px 480px at 50% 108%, #0d4f5e40, transparent 60%);
  pointer-events: none;
}
html[data-theme="light"] body::before { opacity: 0.5; }

h1, h2, h3, h4, h5 {
  margin: 0 0 var(--sp-3);
  line-height: var(--lh-tight);
  font-weight: 700;
  letter-spacing: -0.015em;
  text-wrap: balance;
}
h1 { font-size: var(--fs-3xl); }
h2 { font-size: var(--fs-2xl); }
h3 { font-size: var(--fs-xl); }
h4 { font-size: var(--fs-lg); }
p  { margin: 0 0 var(--sp-4); }
p:last-child { margin-bottom: 0; }

a {
  color: var(--accent);
  text-decoration-color: color-mix(in srgb, var(--accent) 45%, transparent);
  text-underline-offset: 0.18em;
}
a:hover { text-decoration-color: currentColor; }

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

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

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; }

ul, ol { margin: 0 0 var(--sp-4); padding-left: var(--sp-5); }
ul:last-child, ol:last-child { margin-bottom: 0; }

hr { border: 0; border-top: 1px solid var(--border); margin: var(--sp-6) 0; }

/* ---------- Focus ------------------------------------------- */
:focus { outline: none; }
:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-xs);
}
html[data-contrast="high"] :focus-visible { outline-width: 4px; }

/* The router focuses #main after a navigation so screen readers land in the new
   content. It is a skip target rather than a control, and it spans the whole
   viewport, so a focus ring around it would be a page-sized rectangle that
   tells a sighted user nothing. Real controls keep their ring. */
#main:focus, #main:focus-visible { outline: none; }

/* ---------- Selection --------------------------------------- */
::selection { background: var(--beam); color: var(--accent-contrast); }

/* ---------- Scrollbars -------------------------------------- */
* { scrollbar-width: thin; scrollbar-color: var(--hull-500) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb {
  background: var(--hull-500); border-radius: var(--r-pill);
  border: 3px solid transparent; background-clip: content-box;
}
*::-webkit-scrollbar-thumb:hover { background: var(--hull-400); background-clip: content-box; }

/* ---------- Utilities --------------------------------------- */
.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}
.skip-link {
  position: absolute;
  left: var(--sp-4); top: var(--sp-4);
  z-index: 200;
  transform: translateY(-160%);
  background: var(--accent);
  color: var(--accent-contrast);
  padding: var(--sp-3) var(--sp-5);
  border-radius: var(--r-sm);
  font-weight: 700;
  text-decoration: none;
  transition: transform var(--dur-2) var(--ease-out);
}
.skip-link:focus-visible { transform: translateY(0); }

.stack   { display: flex; flex-direction: column; gap: var(--sp-4); }
.stack-2 { display: flex; flex-direction: column; gap: var(--sp-2); }
.stack-6 { display: flex; flex-direction: column; gap: var(--sp-6); }
.row     { display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap; }
.row-tight { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; }
.spacer  { flex: 1 1 auto; }
.muted   { color: var(--text-muted); }
.dim     { color: var(--text-dim); }
.tiny    { font-size: var(--fs-2xs); }
.small   { font-size: var(--fs-sm); }
.center  { text-align: center; }
.mono    { font-family: var(--font-mono); }
.nowrap  { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hidden  { display: none !important; }
.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }

@keyframes cb-fade-up {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: none; }
}
@keyframes cb-pop {
  0%   { transform: scale(0.85); opacity: 0; }
  60%  { transform: scale(1.04); opacity: 1; }
  100% { transform: scale(1); }
}
@keyframes cb-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-7px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(2px); }
}
@keyframes cb-spin { to { transform: rotate(360deg); } }
@keyframes cb-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}
