@view-transition {
  navigation: auto;
}

/* Theming (color-scheme, data-theme, inverse) comes from assets/theme.css.
   The deck sets its palette on the shared --tb-* tokens; --deck-* are aliases
   plus deck-only colors. light-dark() resolves per element, so inverse slides work. */
:root {
  --tb-background-color: light-dark(#fafafa, #111418);
  --tb-font-color: light-dark(#1b1f24, #e8eaed);
  --tb-border-color: light-dark(#c9ced6, #3a414b);
  --tb-hover-background: light-dark(#eef0f3, #1d2228);
  --tb-outline-color: light-dark(#2f6fde, #7aa7ff);
  --deck-bg: var(--tb-background-color);
  --deck-fg: var(--tb-font-color);
  --deck-muted: light-dark(#5f6670, #9aa1ab);
  /* Backdrop glows: give the glass surfaces something to frost. */
  --deck-glow-1: light-dark(rgb(47 111 222 / 0.22), rgb(122 167 255 / 0.2));
  --deck-glow-2: light-dark(rgb(177 108 255 / 0.2), rgb(139 92 246 / 0.22));
  --deck-glow-3: light-dark(rgb(0 163 122 / 0.14), rgb(0 255 170 / 0.1));
  --deck-accent: var(--tb-outline-color);
  --deck-code-bg: var(--tb-hover-background);
}

.deck-theme {
  position: fixed;
  top: calc(0.75rem + env(safe-area-inset-top, 0px));
  right: calc(0.75rem + env(safe-area-inset-right, 0px));
  z-index: 1;
  font-size: 0.6em;
  border-radius: 999px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  background:
    radial-gradient(55% 45% at 12% 8%, var(--deck-glow-1), transparent 70%),
    radial-gradient(50% 55% at 92% 88%, var(--deck-glow-2), transparent 70%),
    radial-gradient(40% 40% at 70% 20%, var(--deck-glow-3), transparent 70%),
    var(--deck-bg);
  background-attachment: fixed;
  color: var(--deck-fg);
  font: clamp(1rem, 1.4vw + 0.6rem, 1.75rem) / 1.5 system-ui, sans-serif;
  display: grid;
  grid-template-rows: 1fr auto;
  /* minmax(0, ...): a wide code line scrolls inside its block, it must not widen the page. */
  grid-template-columns: minmax(0, 1fr);
}

.slide {
  view-transition-name: slide;
  align-self: center;
  justify-self: center;
  width: min(100% - 2rem, 60rem);
  /* Top: clear the fixed Home/Map and theme buttons (0.75rem offset + about 1.5em tall,
     they scale with the body font) plus a gap. */
  padding-block: calc(1.5rem + 1.5em + env(safe-area-inset-top, 0px)) 2rem;
}

.slide h1 {
  font-size: 2.2em;
  line-height: 1.15;
  margin-block: 0 0.5em;
}

.slide h2 {
  font-size: 1.5em;
  margin-block: 0 0.5em;
}

.slide a {
  color: var(--deck-accent);
}

.slide code {
  background: var(--deck-code-bg);
  padding: 0.1em 0.3em;
  border-radius: 0.25em;
  font-size: 0.9em;
}

.slide pre {
  background: var(--deck-code-bg);
  padding: 1em;
  border-radius: 0.5em;
  overflow-x: auto;
  max-width: 100%;
  font-size: 0.8em;
  line-height: 1.45;
  tab-size: 2;
}

.slide pre code {
  background: none;
  padding: 0;
  font-size: 1em; /* the pre sets the code size; do not shrink twice */
}

/* Build-time highlighting (Shiki): tokens carry --shiki-light / --shiki-dark.
   light-dark() follows color-scheme, so deck theme, slide theme and inverse all work. */
.slide pre.shiki {
  background: var(--deck-code-bg); /* the deck's own surface, not the Shiki theme's */
}

.slide pre.shiki span {
  color: light-dark(var(--shiki-light), var(--shiki-dark));
}

/* Showcase block for slides: colorful shapes behind glass cards. */
.showcase {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  padding: 1.5rem;
  border-radius: 1rem;
  background:
    radial-gradient(circle at 18% 30%, light-dark(#7aa7ff, #2f6fde) 0 14%, transparent 15%),
    radial-gradient(circle at 62% 70%, light-dark(#c9a4ff, #8b5cf6) 0 18%, transparent 19%),
    radial-gradient(circle at 88% 22%, light-dark(#7fe3c6, #00a37a) 0 11%, transparent 12%),
    color-mix(in srgb, var(--deck-accent) 8%, transparent);
}

.showcase-card {
  flex: 1 1 12rem;
  padding: 1rem 1.25rem;
  font-size: 0.8em;
  line-height: 1.4;
}

.showcase-buttons {
  flex-basis: 100%;
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin: 0;
  font-size: 0.8em;
}

.showcase-buttons button {
  font: inherit;
  padding: 0.4em 1em;
}

.tiles-nav {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  justify-self: center;
  gap: 0.5rem 1.5rem;
  padding: 0.6rem 1.4rem;
  margin: 0 1rem calc(1rem + env(safe-area-inset-bottom, 0px));
  border-radius: 999px;
  font-size: 0.7em;
}

.tile-link {
  color: var(--deck-muted);
  text-decoration: none;
  display: inline-flex;
  gap: 0.4em;
}

.tile-link:hover,
.tile-link:focus-visible {
  color: var(--deck-accent);
}

/* nav: edges. One arrow per side, pointing at that neighbor. */
body[data-nav='edges'] .slide {
  width: min(100% - 2 * 14rem, 60rem);
}

.edge-nav .edge {
  position: fixed;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 0.5em;
  max-width: 12rem;
  padding: 0.5rem 1rem;
  border-radius: 999px;
  font-size: 0.7em;
  white-space: nowrap;
}

.edge-label {
  overflow: hidden;
  text-overflow: ellipsis;
}

.edge-arrow {
  font-size: 1.4em;
  line-height: 1;
}

.edge[data-dir='up'] {
  top: calc(0.75rem + env(safe-area-inset-top, 0px));
  left: 50%;
  translate: -50% 0;
}

.edge[data-dir='down'] {
  bottom: calc(0.75rem + env(safe-area-inset-bottom, 0px));
  left: 50%;
  translate: -50% 0;
}

.edge[data-dir='left'] {
  left: calc(0.5rem + env(safe-area-inset-left, 0px));
  top: 50%;
  translate: 0 -50%;
}

.edge[data-dir='right'] {
  right: calc(0.5rem + env(safe-area-inset-right, 0px));
  top: 50%;
  translate: 0 -50%;
  flex-direction: row-reverse;
}

/* Narrow screens (under 60rem): side arrows keep only the arrow, so they never cover content. */
@media (max-width: 60rem) {
  body[data-nav='edges'] .slide {
    width: min(100% - 2 * 4rem, 60rem);
  }
  .edge[data-dir='left'] .edge-label,
  .edge[data-dir='right'] .edge-label {
    display: none;
  }
}

/* Home and Map buttons (top left), and the deck map they open. */
.deck-controls {
  position: fixed;
  top: calc(0.75rem + env(safe-area-inset-top, 0px));
  left: calc(0.75rem + env(safe-area-inset-left, 0px));
  z-index: 2;
  display: flex;
  gap: 0.5rem;
  font-size: 0.6em;
}

.deck-button {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  padding: 0.45em 1em;
  border: 1px solid var(--tb-border-color);
  border-radius: 999px;
  color: var(--deck-fg);
  font: inherit;
  text-decoration: none;
  cursor: pointer;
}

.deck-button:hover,
.deck-button:focus-visible {
  color: var(--deck-accent);
}

.deck-button:focus-visible,
.map-tile:focus-visible {
  outline: 2px solid var(--tb-outline-color);
  outline-offset: 2px;
}

.deck-map {
  position: fixed;
  inset: auto;
  top: calc(3.5rem + env(safe-area-inset-top, 0px));
  left: calc(0.75rem + env(safe-area-inset-left, 0px));
  margin: 0;
  max-width: calc(100vw - 1.5rem);
  max-height: calc(100vh - 5rem);
  overflow: auto;
  padding: 0.75rem;
  border: 1px solid var(--tb-border-color);
  border-radius: 1rem;
  color: var(--deck-fg);
  font-size: 0.6em;
}

.deck-notes {
  position: fixed;
  inset: auto;
  top: calc(3.5rem + env(safe-area-inset-top, 0px));
  left: calc(0.75rem + env(safe-area-inset-left, 0px));
  margin: 0;
  width: min(28rem, calc(100vw - 1.5rem));
  max-height: calc(100vh - 5rem);
  overflow: auto;
  padding: 0.75rem 1rem;
  border: 1px solid var(--tb-border-color);
  border-radius: 1rem;
  color: var(--deck-fg);
  font-size: 0.6em;
}

.deck-map::backdrop,
.deck-notes::backdrop {
  background: transparent;
}

.map-grid {
  display: grid;
  grid-template-columns: repeat(var(--map-cols), minmax(5.5rem, 8rem));
  gap: 0.4rem;
}

.map-tile {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 3rem;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--tb-border-color);
  border-radius: 0.6rem;
  color: var(--deck-fg);
  text-align: center;
  text-decoration: none;
  line-height: 1.25;
  overflow: hidden;
}

.map-tile span {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.map-tile:hover {
  background: var(--tb-hover-background);
}

.map-tile.is-start::before {
  content: '\2302\00a0';
}

.map-tile.is-current {
  border-color: var(--deck-accent);
  background: color-mix(in srgb, var(--deck-accent) 18%, transparent);
  font-weight: 600;
}

/* Keep the edge arrows and the controls from sharing a corner on small screens. */
@media (max-width: 40rem) {
  .deck-theme {
    font-size: 0.5em;
  }
}

/* Direction-aware transitions (types set in deck.js on pagereveal). */
@keyframes out-left { to { translate: -100vw 0; } }
@keyframes in-left { from { translate: 100vw 0; } }
@keyframes out-right { to { translate: 100vw 0; } }
@keyframes in-right { from { translate: -100vw 0; } }
@keyframes out-up { to { translate: 0 -100vh; } }
@keyframes in-up { from { translate: 0 100vh; } }
@keyframes out-down { to { translate: 0 100vh; } }
@keyframes in-down { from { translate: 0 -100vh; } }

::view-transition-group(slide) {
  animation-duration: 0.45s;
  animation-timing-function: cubic-bezier(0.2, 0.7, 0.2, 1);
}

html:active-view-transition-type(slide-left) {
  &::view-transition-old(slide) { animation: out-left 0.45s ease both; }
  &::view-transition-new(slide) { animation: in-left 0.45s ease both; }
}
html:active-view-transition-type(slide-right) {
  &::view-transition-old(slide) { animation: out-right 0.45s ease both; }
  &::view-transition-new(slide) { animation: in-right 0.45s ease both; }
}
html:active-view-transition-type(slide-up) {
  &::view-transition-old(slide) { animation: out-up 0.45s ease both; }
  &::view-transition-new(slide) { animation: in-up 0.45s ease both; }
}
html:active-view-transition-type(slide-down) {
  &::view-transition-old(slide) { animation: out-down 0.45s ease both; }
  &::view-transition-new(slide) { animation: in-down 0.45s ease both; }
}

@media (prefers-reduced-motion: reduce) {
  ::view-transition-group(*),
  ::view-transition-old(*),
  ::view-transition-new(*) {
    animation: none !important;
  }
}

.tiles-nav[hidden] {
  display: none;
}

.edge[data-dir='up'],
.edge[data-dir='down'] {
  max-width: min(24rem, 100% - 14rem);
}

/* Notes are for the presenter. They never print. */
@media print {
  .deck-notes,
  .deck-notes-button {
    display: none !important;
  }
}

/* print.html: all slides in one page, one per printed page. */
.print-deck {
  display: block;
  height: auto;
}

.print-hint {
  margin: 1rem;
  font-size: 0.6em;
  color: var(--deck-muted);
}

.print-slide {
  view-transition-name: none;
  margin-inline: auto;
  min-height: 60vh;
}

@media print {
  @page {
    size: landscape;
    margin: 12mm;
  }

  .deck-controls,
  .deck-map,
  .tiles-nav,
  .edge-nav,
  .deck-theme,
  .print-hint {
    display: none !important;
  }

  body {
    background: #fff;
    font-size: 16pt;
  }

  .print-slide {
    break-after: page;
    break-inside: avoid;
    min-height: 0;
    width: 100%;
    padding-block: 0;
  }

  .print-slide:last-child {
    break-after: auto;
  }
}

/* Mermaid diagrams are pre-rendered in a light and a dark variant. The theme picks one. */
.mermaid-diagram {
  margin: 1rem 0;
}
.mermaid-diagram svg {
  max-width: 100%;
  height: auto;
}
.mermaid-dark {
  display: none;
}
@container style(--tb-scheme: dark) {
  .mermaid-light {
    display: none;
  }
  .mermaid-dark {
    display: block;
  }
}
