/* =========================================================
   base.css — tokens, typography, header, footer
   Reference: nathanchen.me (Spectral serif, generous whitespace, constellation background)
   ========================================================= */

:root {
  color-scheme: light;

  --serif: 'Spectral', 'Iowan Old Style', 'Palatino', Georgia, serif;
  --mono: ui-monospace, 'SF Mono', 'JetBrains Mono', Menlo, Consolas, monospace;

  --bg: #ffffff;
  --text: #1b1b1f;
  --text-soft: #3f3f46;
  --muted: #8e8e96;
  --faint: #b8b8b8;
  --rule: #e4e4e7;
  --rule-soft: rgba(24, 24, 27, 0.06);
  --link: #52525b;
  --link-underline: rgba(145, 145, 160, 0.5);
  --code-bg: #f5f5f5;
  --panel: rgba(255, 255, 255, 0.72);

  --particle-rgb: 166, 128, 166;
  --selection: rgba(166, 128, 166, 0.24);
  --cat-alpha: 0.075;
}

html[data-theme='dark'] {
  color-scheme: dark;

  --bg: #121212;
  --text: #e6e6e6;
  --text-soft: #d4d4d8;
  --muted: #a1a1a1;
  --faint: #5a5a5a;
  --rule: #3b3d3e;
  --rule-soft: rgba(255, 255, 255, 0.075);
  --link: #cfcfcf;
  --link-underline: #6b6b6b;
  --code-bg: #242424;
  --panel: rgba(18, 18, 18, 0.74);

  --particle-rgb: 200, 168, 200;
  --selection: rgba(166, 128, 166, 0.3);
  --cat-alpha: 0.2;
}

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

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--serif);
  font-weight: 300;
  font-size: 18px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background-color 0.35s ease, color 0.35s ease;
}

::selection { background: var(--selection); }

a {
  color: var(--link);
  text-decoration: none;
  border-bottom: 0.08em solid var(--link-underline);
  transition: color 0.25s ease, border-color 0.25s ease;
}

a:hover {
  color: var(--text);
  border-bottom-color: var(--text);
}

img { max-width: 100%; height: auto; }

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}

:focus-visible {
  outline: 2px solid var(--link-underline);
  outline-offset: 4px;
  border-radius: 2px;
}

/* ---------- Background constellation ---------- */

#bg-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
}

.page {
  position: relative;
  z-index: 1;
}

/* ---------- Header ---------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 1.5rem 2rem 0.95rem;
  background: var(--panel);
  -webkit-backdrop-filter: saturate(180%) blur(10px);
  backdrop-filter: saturate(180%) blur(10px);
}

.site-header::after {
  content: '';
  position: absolute;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: 200px;
  height: 1px;
  background: var(--rule);
}

.brand {
  position: absolute;
  left: 2rem;
  top: 1.42rem;
  display: flex;
  align-items: center;
  gap: 0.55rem;
  font-size: 18px;
  color: var(--link);
  border-bottom: 0;
  opacity: 0.82;
  transition: opacity 0.25s ease;
}

.brand:hover { opacity: 1; color: var(--text); border-bottom: 0; }

.brand-mark {
  width: 23px;
  height: 23px;
  border-radius: 50%;
  display: block;
}

.site-nav {
  display: flex;
  gap: 2.6rem;
}

.site-nav a {
  position: relative;
  display: inline-block;
  font-size: 16px;
  color: var(--link);
  border-bottom: 0;
  padding: 0 0.1rem 3px;
  transition: color 0.25s ease;
}

.site-nav a::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 1px;
  background: currentColor;
  transform: scaleX(0);
  transform-origin: center;
  transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}

.site-nav a:hover { color: var(--text); border-bottom: 0; }
.site-nav a:hover::after,
.site-nav a[aria-current='page']::after { transform: scaleX(1); }

.site-aside {
  position: absolute;
  right: 2rem;
  top: 1.42rem;
  display: flex;
  align-items: center;
  gap: 1.1rem;
}

.icon-link,
.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  color: var(--link);
  border-bottom: 0;
  opacity: 0.72;
  transition: opacity 0.2s ease, color 0.2s ease, transform 0.2s ease;
}

.icon-link:hover,
.theme-toggle:hover {
  opacity: 1;
  color: var(--text);
  border-bottom: 0;
  transform: translateY(-1px);
}

.icon-link svg,
.theme-toggle svg { width: 17px; height: 17px; display: block; }

.theme-toggle .icon-moon { display: none; }
html[data-theme='dark'] .theme-toggle .icon-sun { display: none; }
html[data-theme='dark'] .theme-toggle .icon-moon { display: block; }

/* ---------- Footer ---------- */

.site-footer {
  position: relative;
  z-index: 1;
  margin-top: 5rem;
  padding: 2.6rem 1.5rem 3.2rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.82rem;
  letter-spacing: 0.02em;
}

.site-footer p { margin: 0 0 0.9rem; }

.site-footer a {
  color: var(--muted);
  border-bottom: 1px solid transparent;
}

.site-footer a:hover {
  color: var(--text);
  border-bottom-color: var(--text);
}

/* ---------- Reveal animation ---------- */

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

.reveal {
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 0.55s ease, transform 0.55s ease;
  will-change: opacity, transform;
}

.reveal.is-visible { opacity: 1; transform: none; }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .reveal { opacity: 1; transform: none; transition: none; }
  * { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; }
}

/* ---------- Mobile header ---------- */

@media (max-width: 768px) {
  body { font-size: 16px; }

  .site-header {
    padding: 0.85rem 1rem 0.7rem;
  }

  .site-header::after { width: 130px; }

  .brand {
    position: static;
    font-size: 16px;
    margin-right: auto;
  }

  .brand-mark { width: 20px; height: 20px; }

  .site-nav { gap: 1.15rem; margin-left: 0.4rem; }
  .site-nav a { font-size: 14.5px; }

  .site-aside {
    position: static;
    margin-left: 0.9rem;
    gap: 0.7rem;
  }

  .site-aside .icon-link { display: none; }
  .site-aside .theme-toggle { width: 20px; height: 20px; }
}