/* ui.css: in-world UI shared by every scene (chapter rail, reveal, footer) */

/* Small-caps labels. Alegreya SC draws lowercase as small capitals, so no
   text-transform is needed, which keeps screen readers from spelling words out. */
.kicker {
  font-family: var(--font-label);
  font-size: 0.85rem;
  letter-spacing: 0.22em;
  color: var(--accent);
}

/* Content fades up the first time its scene comes into view (see js/reveal.js). */
.js .scene__content > * {
  opacity: 0;
  translate: 0 2rem;
  transition:
    opacity 1.2s var(--ease-out),
    translate 1.2s var(--ease-out);
}

.js .scene.is-revealed .scene__content > * {
  opacity: 1;
  translate: 0 0;
}

/* Never let keyboard focus land on content that is still invisible. */
.js .scene:focus-within .scene__content > * {
  opacity: 1;
  translate: 0 0;
  transition-duration: 0.2s;
}

@media print {
  .js .scene__content > * {
    opacity: 1;
    translate: none;
  }
}

/* Chapter rail: roman numerals pinned to the right edge. */
.chapters {
  position: fixed;
  right: var(--gutter);
  top: 50%;
  z-index: 10;
  translate: 0 -50%;
}

.chapters ol {
  display: grid;
  gap: var(--space-2);
  justify-items: end;
}

.chapters a {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  font-family: var(--font-label);
  text-decoration: none;
  color: var(--ink-muted);
  text-shadow: 0 1px 6px rgb(0 0 0 / 0.8);
  transition: color 0.3s;
}

.chapters__numeral {
  display: grid;
  place-items: center;
  width: 2.5rem;
  aspect-ratio: 1;
  border: 1px solid currentColor;
  border-radius: 50%;
  background: rgb(0 0 0 / 0.35);
  backdrop-filter: blur(4px);
  font-size: 0.85rem;
}

.chapters__label {
  order: -1;
  font-size: 0.85rem;
  letter-spacing: 0.2em;
  /* No text-transform: Alegreya SC draws lowercase as small capitals anyway, and
     uppercased names can be spelled out letter by letter by screen readers. */
  opacity: 0;
  translate: 0.5rem 0;
  transition:
    opacity 0.3s,
    translate 0.3s var(--ease-out);
}

.chapters a:hover,
.chapters a:focus-visible,
.chapters a[aria-current="true"] {
  color: var(--accent);
}

.chapters a:hover .chapters__label,
.chapters a:focus-visible .chapters__label {
  opacity: 1;
  translate: 0 0;
}

/* On phones the rail would float over the text; plain scrolling is navigation enough. */
@media (max-width: 40rem) {
  .chapters {
    display: none;
  }
}

.site-footer {
  padding: var(--space-4) var(--gutter) var(--space-5);
  background: var(--night);
  color: var(--ink-muted);
  font-size: 0.9rem;
  font-style: italic;
  text-align: center;
}

.site-footer > * + * {
  margin-top: var(--space-1);
}

/* What I'm into lately, linking to Off the Record (written by scripts/off-the-record.mjs). */
.site-footer__lately {
  margin-bottom: var(--space-3);
  color: var(--ink);
  font-size: 1rem;
  font-style: normal;
}

.site-footer__lately cite {
  font-style: italic;
}

.site-footer__lately a {
  color: var(--accent);
  text-underline-offset: 0.3em;
}

/*
 * "Pause animations" switch (WCAG 2.2.2). Checking it stills every scene into a
 * resting composition; JS only persists the choice and stops parallax.
 * With prefers-reduced-motion nothing moves anyway, so the switch is hidden.
 */
.motion-toggle {
  position: fixed;
  left: var(--gutter);
  bottom: max(var(--space-2), env(safe-area-inset-bottom));
  z-index: 10;
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.4rem 0.8rem 0.4rem 0.5rem;
  border: 1px solid rgb(243 234 216 / 0.35);
  border-radius: 999px;
  background: rgb(0 0 0 / 0.55);
  backdrop-filter: blur(4px);
  font-family: var(--font-label);
  font-size: 0.85rem;
  letter-spacing: 0.08em;
  cursor: pointer;
}

.motion-toggle input {
  appearance: none;
  position: relative;
  flex-shrink: 0;
  width: 2.2rem;
  height: 1.25rem;
  margin: 0;
  border: 1px solid currentColor;
  border-radius: 999px;
  cursor: pointer;
}

.motion-toggle input::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 0.2rem;
  width: 0.8rem;
  aspect-ratio: 1;
  border-radius: 50%;
  background: currentColor;
  translate: 0 -50%;
  transition: translate 0.2s var(--ease-out);
}

.motion-toggle input:checked {
  background: var(--accent);
  border-color: var(--accent);
}

.motion-toggle input:checked::before {
  background: var(--night);
  translate: 0.95rem -50%;
}

:root:has(#motion-toggle:checked) {
  & .stage,
  & .stage::after,
  & .layer {
    animation: none;
  }

  /* Rest on a single campfire frame. */
  & .layer[data-role="fire"] + .layer[data-role="fire"] {
    opacity: 0;
  }
}

/* Forced palettes override the knob and fill backgrounds, hiding the switch state;
   draw it with system colours instead. */
@media (forced-colors: active) {
  .motion-toggle input {
    forced-color-adjust: none;
    border-color: ButtonText;
  }

  .motion-toggle input::before {
    background: ButtonText;
  }

  .motion-toggle input:checked {
    background: Highlight;
    border-color: Highlight;
  }

  .motion-toggle input:checked::before {
    background: HighlightText;
  }
}

/* On phones a floating switch would cover the text; park it at the top of the page.
   It stays the first control in tab order either way. */
@media (max-width: 40rem) {
  .motion-toggle {
    position: absolute;
    top: var(--space-2);
    bottom: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  .motion-toggle {
    display: none;
  }
}
