/* The <slide-deck> element's stylesheet. The host links it in its head, so a deck is drawn in the
   page's first paint, with or without the script. Every length on a slide is a multiple of --u,
   a 1920th of the slide's width, so a slide keeps its layout at any size: on the page, where the
   slides stack at the column's width; on a phone, where they reflow into cards (below); and when
   presenting, where one slide fills the screen. Colors and faces come from the --slide-deck-*
   tokens, which the host sets; the fallbacks are a light page's. */

slide-deck {
  --u: calc(100cqi / 1920);
  container: slide-deck / inline-size;
  counter-reset: slide-deck;
  display: grid;
  gap: clamp(1rem, 2.5vw, 1.75rem);
  color: var(--slide-deck-text, #25241f);
}

/* Corners in the host's shape. A box of corner radius r, its padding beside its content, sets
   border-radius: calc(r * var(--slide-deck-corner-scale, 1)), so the host maps a shape and the
   scale it draws r at together; with neither, a circle of radius r. A capsule stays round. */
slide-deck *,
slide-deck *::before,
slide-deck *::after {
  corner-shape: var(--slide-deck-corner-shape, round);
}

/* A slide: 16:9 at any width, its bottom band kept clear for the progress bar. Slides count
   themselves in the `slide-deck` counter, which a deck shows wherever it likes. Its corner's
   radius is its least padding. */
slide-deck > .slide {
  --slide-inset: calc(84 * var(--u));
  box-sizing: border-box;
  position: relative;
  display: flex;
  flex-direction: column;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  padding: var(--slide-inset) calc(120 * var(--u));
  border: 1px solid var(--slide-deck-line, #dedbd1);
  border-radius: calc(var(--slide-inset) * var(--slide-deck-corner-scale, 1));
  background: var(--slide-deck-page, #faf9f6);
  font-size: calc(30 * var(--u));
  line-height: 1.42;
  counter-increment: slide-deck;
  scroll-margin-top: 4rem;
}

/* The host's prose rules stay out of slides: a deck sets its own headings, measure, and spacing. */
slide-deck > .slide :where(h1, h2, h3, h4, h5, h6) {
  margin: 0;
  font: inherit;
  letter-spacing: normal;
}

slide-deck > .slide :where(p, ol, ul, li, pre, figure, blockquote) {
  max-width: none;
  margin: 0;
}

slide-deck > .slide :where(ol, ul) {
  padding-left: 1.3em;
}

slide-deck > .slide :where(p, li) {
  text-wrap: pretty;
}

/* Narrow screens: slides become cards that grow with their text, set at the host's body size. A
   deck reflows through two hooks: grids that repeat var(--slide-columns, N) columns collapse to
   one, and display type multiplied by var(--slide-display-scale, 1) shrinks. */
@container slide-deck (max-width: 760px) {
  slide-deck:not([presenting]) > .slide {
    --u: calc(1rem / 30);
    --slide-columns: 1;
    --slide-display-scale: 0.66;
    --slide-inset: 1rem;
    aspect-ratio: auto;
    padding: 1.4rem 1.2rem var(--slide-inset);
  }
}

/* The toolbar above the slides, which the script adds; it stays in reach while the slides scroll. */
slide-deck > .slide-deck-toolbar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1rem;
  padding-block: 0.6rem;
  background: var(--slide-deck-page, #faf9f6);
}

slide-deck .slide-deck-icon {
  width: 1em;
  height: 1em;
  flex: none;
}

slide-deck .slide-deck-present {
  --present-inset: 0.6em;
  display: inline-flex;
  align-items: center;
  gap: 0.45em;
  padding: 0.2em 0.75em 0.25em var(--present-inset);
  border: 0;
  border-radius: calc(var(--present-inset) * var(--slide-deck-corner-scale, 1));
  background: var(--slide-deck-accent, #9b3d20);
  color: var(--slide-deck-surface, #ffffff);
  font: inherit;
  font-size: 1.05rem;
  line-height: 1.4;
  cursor: pointer;
}

slide-deck .slide-deck-present .slide-deck-icon {
  width: 0.8em;
  height: 0.8em;
}

slide-deck .slide-deck-hint {
  max-width: none;
  margin: 0;
  color: var(--slide-deck-muted, #6f6d66);
  font-size: 0.85rem;
  line-height: 1.4;
}

slide-deck :is(.slide-deck-present, .slide-deck-control):focus-visible {
  outline: 3px solid var(--slide-deck-accent, #9b3d20);
  outline-offset: 2px;
}

/* Presenting: one slide at a time, as large as the screen allows, the rest kept in place unseen
   so they still count. */
html:has(slide-deck[presenting]) {
  overflow: hidden;
}

slide-deck[presenting] {
  --u: calc(min(100vw, 100dvh * 16 / 9) / 1920);
  position: fixed;
  inset: 0;
  z-index: 1000;
  place-items: center;
  max-width: none;
  margin: 0;
  background: var(--slide-deck-page, #faf9f6);
}

slide-deck[presenting]:focus {
  outline: none;
}

slide-deck[presenting] > .slide-deck-toolbar {
  display: none;
}

/* A presenting slide is the screen, not a box on it: its corners stay square,
   whatever sets a box's corner, the host's lesson engine included. */
slide-deck[presenting] > .slide {
  grid-area: 1 / 1;
  width: calc(1920 * var(--u));
  border: 0;
  border-radius: 0 !important;
  visibility: hidden;
}

slide-deck[presenting] > .slide[data-current] {
  visibility: visible;
}

/* The controls, at the top right while presenting: they appear when the pointer moves and fade
   when it rests, and stay while the pointer is on them or the keyboard is in them. */
slide-deck > .slide-deck-controls,
slide-deck > .slide-deck-progress {
  display: none;
}

slide-deck[presenting] > .slide-deck-controls {
  position: absolute;
  top: 1rem;
  right: 1rem;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 0.15rem;
  padding: 0.2rem;
  border: 1px solid var(--slide-deck-line, #dedbd1);
  border-radius: 999px;
  corner-shape: round;
  background: color-mix(in srgb, var(--slide-deck-surface, #ffffff) 88%, transparent);
  color: var(--slide-deck-text, #25241f);
  font-family: var(--slide-deck-sans, ui-sans-serif, system-ui, sans-serif);
  font-size: 0.8rem;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s, visibility 0s linear 0.3s;
}

slide-deck[awake] > .slide-deck-controls,
slide-deck[presenting] > .slide-deck-controls:is(:hover, :has(:focus-visible)) {
  opacity: 1;
  visibility: visible;
  transition: opacity 0.15s;
}

slide-deck .slide-deck-control {
  display: grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: 0;
  border-radius: 999px;
  corner-shape: round;
  background: transparent;
  color: inherit;
  cursor: pointer;
}

slide-deck .slide-deck-control:hover {
  background: color-mix(in srgb, var(--slide-deck-accent, #9b3d20) 14%, transparent);
}

slide-deck .slide-deck-count {
  min-width: 4.5em;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* The progress bar, in the band every slide keeps clear: a segment per section, sized by its
   slides and filled up to the current one. It names the current section; hovering over the bar,
   and only that, names them all and thickens it, and both linger half a second after the pointer
   leaves. One number, the reveal, drives both. A click on a segment opens its section. */
@property --slide-deck-reveal {
  syntax: "<number>";
  inherits: true;
  initial-value: 0;
}

slide-deck .slide-deck-progress {
  --slide-deck-reveal: 0;
  transition: --slide-deck-reveal 0.3s ease 0.5s;
}

slide-deck .slide-deck-progress:hover {
  --slide-deck-reveal: 1;
  transition: --slide-deck-reveal 0.3s;
}

slide-deck[presenting] > .slide-deck-progress {
  position: absolute;
  bottom: calc(50% - 512 * var(--u));
  left: calc(50% - 840 * var(--u));
  z-index: 1;
  display: flex;
  align-items: flex-end;
  gap: calc(6 * var(--u));
  width: calc(1680 * var(--u));
}

slide-deck .slide-deck-section {
  display: grid;
  flex: 1 1 0;
  gap: calc(8 * var(--u));
  min-width: max-content;
  padding: 0;
  border: 0;
  background: none;
  color: var(--slide-deck-muted, #6f6d66);
  font-family: var(--slide-deck-sans, ui-sans-serif, system-ui, sans-serif);
  font-size: max(10px, calc(17 * var(--u)));
  font-weight: var(--slide-deck-sans-weight, 600);
  line-height: 1.3;
  text-align: left;
  cursor: pointer;
}

slide-deck .slide-deck-section:is(:hover, :focus-visible) {
  color: var(--slide-deck-text, #25241f);
}

slide-deck .slide-deck-section:focus-visible {
  outline: 2px solid var(--slide-deck-accent, #9b3d20);
  outline-offset: calc(6 * var(--u));
}

slide-deck .slide-deck-section-name {
  padding-right: 0.7em;
  white-space: nowrap;
  opacity: var(--slide-deck-reveal);
}

slide-deck .slide-deck-section[aria-current] .slide-deck-section-name {
  color: var(--slide-deck-accent, #9b3d20);
  opacity: 1;
}

slide-deck .slide-deck-section-track {
  position: relative;
  height: calc(max(2px, calc(4 * var(--u))) + var(--slide-deck-reveal) * max(1px, calc(3 * var(--u))));
  overflow: hidden;
  border-radius: 999px;
  corner-shape: round;
  background: color-mix(in srgb, var(--slide-deck-text, #25241f) 16%, transparent);
}

/* The script times each fill's transition, so the fill sweeps as one front across the segments. */
slide-deck .slide-deck-section-fill {
  position: absolute;
  inset: 0;
  background: var(--slide-deck-accent, #9b3d20);
  transform: scaleX(var(--slide-deck-fill, 0));
  transform-origin: left;
}

/* Where the names do not all fit side by side, the script drops them and the segments stand alone. */
slide-deck .slide-deck-progress[data-compact] .slide-deck-section {
  min-width: 0;
}

slide-deck .slide-deck-progress[data-compact] .slide-deck-section-name {
  display: none;
}

@media (max-width: 640px) {
  slide-deck .slide-deck-hint {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  slide-deck :is(.slide-deck-controls, .slide-deck-progress) {
    transition: none;
  }
}

@media print {
  slide-deck > :is(.slide-deck-toolbar, .slide-deck-controls, .slide-deck-progress) {
    display: none;
  }

  slide-deck > .slide {
    break-inside: avoid;
  }
}
