/* Page theme flip: the WHOLE page (ground, ink, rules, nav, buttons) turns dark when a marked section's top passes
   the middle of the window, and turns back when it scrolls back below the middle. Measured from Cypher Capital's
   ThemeScroll (teardown 10-08), rewritten.

   How: every colour on the page reads a token, and every token is a REGISTERED custom property (@property, syntax
   <color>). Registered properties interpolate, so one transition on :root cross-fades every token at once and every
   element that reads one (background, text, borders, SVG fills, buttons) fades with it, with no per-element
   transitions. part.js only toggles html[data-theme=dark].

   Use the tokens for every colour you want to turn: background: var(--pf-ground); color: var(--pf-ink);
   border-color: var(--pf-rule) ... Add your own: register it with @property below AND add it to the
   transition-property list, then give it a value in each theme block.

   [data-theme=invert] on any element flips that subtree to the opposite of the page theme (a dark band on a light
   page that turns light when the page goes dark), as in the source. */

@property --pf-ground       { syntax: "<color>"; inherits: true; initial-value: #ffffff; }
@property --pf-ground-soft  { syntax: "<color>"; inherits: true; initial-value: #fbfbfb; }
@property --pf-ground-80    { syntax: "<color>"; inherits: true; initial-value: #ffffffcc; }
@property --pf-ink          { syntax: "<color>"; inherits: true; initial-value: #181818; }
@property --pf-ink-60       { syntax: "<color>"; inherits: true; initial-value: #18181899; }
@property --pf-ink-50       { syntax: "<color>"; inherits: true; initial-value: #18181880; }
@property --pf-rule         { syntax: "<color>"; inherits: true; initial-value: #18181833; }
@property --pf-rule-soft    { syntax: "<color>"; inherits: true; initial-value: #1818181a; }
@property --pf-accent       { syntax: "<color>"; inherits: true; initial-value: #181818; }
@property --pf-on-accent    { syntax: "<color>"; inherits: true; initial-value: #ffffff; }

:root {
  --pf-dur: .4s;                                   /* source --duration-theme */
  --pf-ease: cubic-bezier(.4, 0, .2, 1);           /* source --easing-in-out */
}

/* light (default) */
:root, [data-theme=light] {
  --pf-ground: #ffffff;      --pf-ground-soft: #fbfbfb; --pf-ground-80: #ffffffcc;
  --pf-ink: #181818;         --pf-ink-60: #18181899;    --pf-ink-50: #18181880;
  --pf-rule: #18181833;      --pf-rule-soft: #1818181a;
  --pf-accent: #181818;      --pf-on-accent: #ffffff;
  color-scheme: light;
}
/* dark: the page flips here (html[data-theme=dark]) */
[data-theme=dark], [data-theme=invert], [data-theme=light] [data-theme=invert] {
  --pf-ground: #181818;      --pf-ground-soft: #1e1e1e; --pf-ground-80: #181818cc;
  --pf-ink: #ffffff;         --pf-ink-60: #ffffff99;    --pf-ink-50: #ffffff80;
  --pf-rule: #ffffff33;      --pf-rule-soft: #ffffff1a;
  --pf-accent: #ffffff;      --pf-on-accent: #181818;
  color-scheme: dark;
}
/* an inverted band inside a dark page turns light */
[data-theme=dark] [data-theme=invert] {
  --pf-ground: #ffffff;      --pf-ground-soft: #fbfbfb; --pf-ground-80: #ffffffcc;
  --pf-ink: #181818;         --pf-ink-60: #18181899;    --pf-ink-50: #18181880;
  --pf-rule: #18181833;      --pf-rule-soft: #1818181a;
  --pf-accent: #181818;      --pf-on-accent: #ffffff;
  color-scheme: light;
}

/* the cross-fade: one transition on the root (and on every themed scope), every token at once */
@media (prefers-reduced-motion: no-preference) {
  :root, [data-theme] {
    transition-property: --pf-ground, --pf-ground-soft, --pf-ground-80, --pf-ink, --pf-ink-60, --pf-ink-50,
      --pf-rule, --pf-rule-soft, --pf-accent, --pf-on-accent;
    transition-duration: var(--pf-dur);
    transition-timing-function: var(--pf-ease);
  }
}

/* the page itself reads the tokens */
.pf-page, html.pf-page body { background: var(--pf-ground); color: var(--pf-ink); }
