/*
  One dark theme, dealt rather than inverted.

  The light page is white paper, navy ink and one orange band. The dark page keeps the same three
  materials and changes the paper, not the ink's job: the ground goes to the deep navy of the
  closing band (#0c1220), the ink to a cool white, and the orange moves from a marker on paper to
  the only lit thing on the page. The closing band inverts the other way, to paper white, so the
  page still ends on a change of ground.

  Every pair below passes WCAG AA; the ratios are in the comment beside each line.

  Selector note: html[data-theme="dark"] has a higher specificity than :root, so these win over the
  inline :root block each page carries, in the same order or not.
*/

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

  --p-bg: #0c1220;          /* ink #eef1f7 on it: 16.53 */
  --p-surface: #141c2e;     /* ink on it: 15.03, muted: 7.54 */
  --p-ink: #eef1f7;
  --p-muted: #a3adc2;       /* on bg: 8.29 */
  --p-accent: #f7941d;      /* on bg: 8.20 */
  --p-accent-ink: #0c1220;
  --p-action: #f7941d;      /* the lit button: ink #0c1220 on it: 8.20 */
  --p-action-ink: #0c1220;

  /* the closing band flips to paper, so the page still ends on a different ground */
  --p-inv-bg: #f4f4f2;
  --p-inv-surface: #ffffff;
  --p-inv-ink: #101828;     /* on #f4f4f2: 16.11 */
  --p-inv-muted: #5b6478;   /* 5.39 */
  --p-inv-accent: #9c4a0a;  /* 5.60, orange darkened for paper */
  --p-inv-accent-ink: #ffffff;
  --p-inv-action: #1f2b4d;
  --p-inv-action-ink: #ffffff;

  --ground-bg: #d9ccb7; --ground-surface: #e9e0d2; --ground-ink: #2a2622;
  --ground-muted: #5a534a; --ground-accent: #a8794a;
}

/* the portrait sits on the same paper in both themes; nothing to do in the dark except keep it lit */
html[data-theme="dark"] .hero__photo,
html[data-theme="dark"] .portrait { background: #141c2e; }

/* ---------------------------------------------------------------- the toggle */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--btn-h);
  height: var(--btn-h);
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--r-btn);
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: border-color var(--m-in, 160ms) ease, background-color var(--m-in, 160ms) ease,
              transform var(--m-press, 120ms) ease;
}

.theme-toggle:hover {
  border-color: color-mix(in oklab, var(--ink) 32%, transparent);
  background: color-mix(in oklab, var(--ink) 5%, transparent);
}

.theme-toggle:active { transform: translateY(1px) scale(.97); }

/* the two glyphs cross-turn in place: the one for the theme you would get on click */
.theme-toggle__glyph {
  position: relative;
  width: 18px;
  height: 18px;
}

.theme-toggle__glyph svg {
  position: absolute;
  inset: 0;
  width: 18px;
  height: 18px;
  transition: opacity var(--m-in, 160ms) ease, transform var(--m-in, 160ms) ease;
}

.theme-toggle__glyph .is-moon { opacity: 0; transform: rotate(-40deg) scale(.72); }
html[data-theme="dark"] .theme-toggle__glyph .is-moon { opacity: 1; transform: none; }
html[data-theme="dark"] .theme-toggle__glyph .is-sun { opacity: 0; transform: rotate(40deg) scale(.72); }

@media (prefers-reduced-motion: reduce) {
  .theme-toggle, .theme-toggle__glyph svg { transition: none; }
  .theme-toggle:active { transform: none; }
}

/* no javascript: the control is not rendered at all */
html:not([data-theme-ready]) .theme-toggle { display: none; }

/* --------------------------------------------------------------- its place in the bar */
/* In the markup the toggle follows the menu button, so the menu stays the bar's first button.
   The order property puts it on the left of the menu where it reads, without moving it in the DOM. */
.nav__bar > .nav__links { order: 0; }
.nav__bar > .theme-toggle { order: 1; margin-left: var(--s-3); flex: none; }
.nav__bar > .nav__actions { order: 2; }
.nav__bar > .nav__toggle { order: 3; }

@media (max-width: 1023px) {
  .nav__bar > .theme-toggle { margin-left: auto; }
  .nav__bar > .nav__toggle { margin-left: var(--s-2); }
}

@media (max-width: 639px) {
  /* 390 wide: the name, the theme button and the menu. The main action is the sheet's. */
  .nav:not(.is-open) .nav__actions { display: none; }
  .nav__bar > .theme-toggle { margin-left: auto; }
  .nav__bar > .nav__toggle { margin-left: var(--s-2); }
}

/* the open sheet's own action bar takes the foot; the toggle stays in the bar above it */
.nav.is-open .theme-toggle { display: none; }
