/* =====================================================================
   Light / dark theme — shared across every page.

   Usage (each page):
     <html data-theme="dark">   dark is the default
     <head>  inline pre-paint script (applies a saved "light" before CSS)
             <link rel="stylesheet" href="assets/css/theme.css">   ← after the page <style>
     nav     <button class="theme-switch" id="themeSwitch" …> beside Connect
     body    <script src="assets/js/theme.js" defer></script>

   Colour flips live in design system/tokens.css (:root[data-theme="dark"]).
   This file holds the switch itself plus the dark overrides every page
   chassis shares (grain, nav glass, ghost buttons, sound pill). Anything
   page-specific stays in that page's own "DARK THEME" block.
   ===================================================================== */

/* ---- the switch — sun | moon track, the ink thumb slides under the active one */
.theme-switch {
  position: relative;
  display: inline-grid;
  grid-template-columns: 26px 26px;
  grid-template-rows: 26px;
  align-items: center;
  justify-items: center;
  flex-shrink: 0;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--ink-mute);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: border-color 0.2s ease, background 0.2s ease;
}
.theme-switch:hover { border-color: var(--ink-faint); background: var(--wash-ink); }
.theme-switch:focus-visible { outline: 2px solid var(--coral); outline-offset: 3px; }
.theme-switch__thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--ink);
  box-shadow: 0 2px 8px -2px rgba(0, 0, 0, 0.35);
  transition: transform 0.45s cubic-bezier(0.22, 1, 0.36, 1), background 0.3s ease;
}
.theme-switch__icon {
  position: relative;
  width: 14px;
  height: 14px;
  transition: color 0.3s ease, transform 0.45s cubic-bezier(0.22, 1, 0.36, 1);
}
.theme-switch__icon--sun { color: var(--paper); }
[data-theme="dark"] .theme-switch__thumb { transform: translateX(26px); }
[data-theme="dark"] .theme-switch__icon--sun { color: var(--ink-mute); transform: rotate(-90deg) scale(0.86); }
[data-theme="dark"] .theme-switch__icon--moon { color: var(--paper); }
:root:not([data-theme="dark"]) .theme-switch__icon--moon { transform: rotate(20deg) scale(0.86); }

/* compact — for slim strips (resume metastrip) */
.theme-switch--compact { grid-template-columns: 20px 20px; grid-template-rows: 20px; padding: 2px; }
.theme-switch--compact .theme-switch__thumb { top: 2px; left: 2px; width: 20px; height: 20px; }
.theme-switch--compact .theme-switch__icon { width: 11px; height: 11px; }
[data-theme="dark"] .theme-switch--compact .theme-switch__thumb { transform: translateX(20px); }

@media print { .theme-switch { display: none !important; } }

/* ---- theme change spreads as a circle from the switch (View Transitions) */
::view-transition-old(root),
::view-transition-new(root) { animation: none; mix-blend-mode: normal; }

/* =====================================================================
   Shared dark overrides — the chassis every page is built on
   ===================================================================== */

/* page grain: light noise screened on, instead of dark noise multiplied */
[data-theme="dark"] body::before {
  background-image:
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='240' height='240'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 1  0 0 0 0 0.95  0 0 0 0 0.85  0 0 0 0.05 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  background-size: 240px 240px;
  mix-blend-mode: screen;
  opacity: 0.3;   /* kept faint: solid-paper sections sit flush against it */
}

/* nav glass */
[data-theme="dark"] .nav { background: rgba(18, 17, 13, 0.72); }
[data-theme="dark"] .nav.is-scrolled { box-shadow: var(--shadow-nav); }

/* ghost buttons (light-mode rgba ink hairline → token hairline) */
[data-theme="dark"] .btn-ghost { border-color: var(--line); }
[data-theme="dark"] .btn-ghost:hover { background: var(--wash-ink); }

/* sound pill (injected by soundscape.js) */
[data-theme="dark"] .sound-toggle {
  background: rgba(28, 26, 21, 0.84);
  box-shadow: 0 2px 14px rgba(0, 0, 0, 0.4), inset 0 0 0 1px var(--line);
}
