/* ============================================================
   Dark theme, shared by every page. theme.js sets
   <html data-theme="light|dark"> from the OS setting or the nav switch.
   Each page keeps its own light palette in :root; this file only
   swaps the variables, so tweak the dark look here, in one place.
   Screen only: printing always uses the light page.
   ============================================================ */

html{color-scheme:light}

@media screen{
  html[data-theme="dark"]{
    color-scheme:dark;
    /* warm near-black paper and parchment ink, the light page's inverse */
    --paper:#141310;
    --paper-2:#1E1D18;
    --card:#1B1A16;
    --ink:#ECE7DA;
    --ink-soft:#BEB8A8;
    --ink-faint:#908B7D;
    --line:#3B3930;
    --line-soft:#2A2822;
    --shadow:rgba(0,0,0,.45);
    /* the teal accent, lifted so it reads on dark */
    --teal:#74C3CF;
    --teal-deep:#A6DCE3;
    --signal:#5DB8C6;
    --mid:#5DB8C6;
    --clay:#D49B6F;
  }

  /* translucent bars and overlays were written as light rgba() */
  html[data-theme="dark"] nav.bar{background:color-mix(in srgb,var(--paper) 92%,transparent)}
  html[data-theme="dark"] .lb{background:color-mix(in srgb,var(--paper) 97%,transparent)}
  html[data-theme="dark"] ::selection{background:var(--teal);color:var(--paper)}

  /* photos and figures: take the glare off, keep the portrait as is */
  html[data-theme="dark"] img:not(.portrait img):not(.authorcard img){filter:brightness(.88)}

  /* Inline SVG diagrams (the blog) hard-code the light palette as
     presentation attributes. CSS beats those, so map each colour to its
     variable rather than editing the drawings. */
  html[data-theme="dark"] svg [fill="#1B1A15" i]{fill:var(--ink)}
  html[data-theme="dark"] svg [fill="#4E4C42" i]{fill:var(--ink-soft)}
  html[data-theme="dark"] svg [fill="#6E6C60" i]{fill:var(--ink-faint)}
  html[data-theme="dark"] svg [fill="#FCFBF7" i]{fill:var(--card)}
  html[data-theme="dark"] svg [fill="#F4F2EC" i]{fill:var(--paper)}
  html[data-theme="dark"] svg [fill="#EAE7DD" i]{fill:var(--paper-2)}
  html[data-theme="dark"] svg [fill="#D6D2C4" i]{fill:var(--line)}
  html[data-theme="dark"] svg [fill="#E6E3D8" i]{fill:var(--line-soft)}
  html[data-theme="dark"] svg [fill="#0B5563" i]{fill:var(--teal)}
  html[data-theme="dark"] svg [fill="#073C47" i]{fill:var(--teal-deep)}
  html[data-theme="dark"] svg [fill="#127287" i]{fill:#7CC8D4}
  html[data-theme="dark"] svg [fill="#1CA0B5" i]{fill:#35A7BA}
  html[data-theme="dark"] svg [fill="#9C5B33" i],
  html[data-theme="dark"] svg [fill="#8C5230" i]{fill:var(--clay)}

  html[data-theme="dark"] svg [stroke="#1B1A15" i]{stroke:var(--ink)}
  html[data-theme="dark"] svg [stroke="#4E4C42" i]{stroke:var(--ink-soft)}
  html[data-theme="dark"] svg [stroke="#6E6C60" i]{stroke:var(--ink-faint)}
  html[data-theme="dark"] svg [stroke="#FCFBF7" i]{stroke:var(--card)}
  html[data-theme="dark"] svg [stroke="#D6D2C4" i]{stroke:var(--line)}
  html[data-theme="dark"] svg [stroke="#E6E3D8" i]{stroke:var(--line-soft)}
  html[data-theme="dark"] svg [stroke="#0B5563" i]{stroke:var(--teal)}
  html[data-theme="dark"] svg [stroke="#073C47" i]{stroke:var(--teal-deep)}
  html[data-theme="dark"] svg [stroke="#127287" i]{stroke:#7CC8D4}
  html[data-theme="dark"] svg [stroke="#1CA0B5" i]{stroke:#35A7BA}
  html[data-theme="dark"] svg [stroke="#9C5B33" i],
  html[data-theme="dark"] svg [stroke="#8C5230" i]{stroke:var(--clay)}
  html[data-theme="dark"] svg [stop-color="#1CA0B5" i]{stop-color:#35A7BA}
  html[data-theme="dark"] svg [stop-color="#127287" i]{stop-color:#7CC8D4}
}

/* the switch cross-fades the whole page (theme.js, View Transitions) */
::view-transition-old(root),
::view-transition-new(root){animation-duration:.35s;animation-timing-function:ease}

/* ---------- the nav switch: an iOS-style "dark mode" toggle ---------- */
.theme-switch{
  display:inline-flex;align-items:center;gap:7px;align-self:center;
  background:none;border:0;padding:4px 0;margin:0;cursor:pointer;
  /* last in the bar, set off from the links by a hairline */
  border-left:1px solid var(--line);padding-left:18px;margin-left:-4px;
  color:var(--ink-faint);-webkit-tap-highlight-color:transparent;
}
.theme-switch .ts-icon{width:14px;height:14px;flex:none;display:block;transition:color .2s,opacity .2s}
.theme-switch .track{
  position:relative;flex:none;width:32px;height:19px;border-radius:999px;
  background:var(--line);transition:background-color .25s ease;
}
.theme-switch .knob{
  position:absolute;top:2px;left:2px;width:15px;height:15px;border-radius:50%;
  background:#FCFBF7;box-shadow:0 1px 2px rgba(0,0,0,.28);
  transition:transform .25s cubic-bezier(.3,.7,.4,1);
}
.theme-switch[aria-checked="true"] .track{background:var(--teal)}
.theme-switch[aria-checked="true"] .knob{transform:translateX(13px)}
/* sun on the off side, moon on the on side: the knob points at the current
   mode, whose icon is lit while the other fades back */
.theme-switch .ts-sun{color:var(--ink-soft)}
.theme-switch .ts-moon{opacity:.45}
.theme-switch[aria-checked="true"] .ts-sun{color:var(--ink-faint);opacity:.45}
.theme-switch[aria-checked="true"] .ts-moon{color:var(--teal);opacity:1}
.theme-switch:hover .track{box-shadow:0 0 0 1px var(--teal)}
@media (prefers-reduced-motion:reduce){.theme-switch .knob,.theme-switch .track{transition:none}}
@media print{.theme-switch{display:none}}
