:root {
  --bg: #fff;
  --fg: #222;
  --muted: #666;
  --rule: #ddd;
  --panel: #f6f6f6;
  --hover: #e8e8e8;
  --accent: #2a6fdb;
  --viewer: #e9e9ec;     /* behind the media and its text */
  --viewer-fg: #333;
  --viewer-head: #111;
  /* Gallery geometry. gallery.js reads these to choose the layout. */
  --header-h: 48px;
  --sidebar-w: 240px;
  --strip-h: 148px;      /* bottom strip: 160px-wide thumbs plus labels */
  --caption-w: 320px;    /* text column right of the media */
  --caption-h: 224px;    /* text band below the media */
  --pad: 24px;           /* around the media and text */
  --gap: 24px;           /* between media and text */
  --compact-below: 520px; /* viewport height at which the header is dropped */
  --media-aspect-w: 16;
  --media-aspect-h: 9;
  --media-max-w: 1920px; /* never enlarge past the recording's own size */
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111114;
    --fg: #e6e6e6;
    --muted: #999;
    --rule: #2a2a30;
    --panel: #18181c;
    --hover: #24242a;
    --accent: #6ea2ff;
    --viewer: #0b0b0d;
    --viewer-fg: #cfcfd4;
    --viewer-head: #fff;
    color-scheme: dark;
  }
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.6 system-ui, sans-serif;
}
main {
  max-width: 860px;
  margin: 0 auto;
  padding: 1rem 16px 4rem;
}
img, video { max-width: 100%; }
a { color: var(--accent); }
blockquote {
  margin: 1rem 0;
  padding: 0 1rem;
  border-left: 4px solid var(--rule);
  color: var(--muted);
}
table { border-collapse: collapse; margin-bottom: 1.5rem; }
th, td { padding: 4px 16px 4px 0; text-align: left; vertical-align: top; }
th:last-child, td:last-child { padding-right: 0; }
/* --rule nearly vanishes on the light --viewer grey, so tint from the text. */
thead th { border-bottom: 1px solid color-mix(in srgb, currentColor 25%, transparent); }
/* Backtick segments, mostly hotkeys: the body font on a light chip. */
code {
  padding: 0.1em 0.4em;
  border-radius: 4px;
  background: var(--hover);
  font: inherit;
  font-size: 0.9em;
  white-space: nowrap;
}
/* Fenced blocks: monospace, line breaks kept, long lines scroll. */
pre {
  padding: 0.6em 0.8em;
  border-radius: 4px;
  background: var(--hover);
  overflow-x: auto;
}
pre code {
  padding: 0;
  background: none;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre;
}

/* ---- Gallery layout: header across the top, thumbnails in a left column or
   a bottom strip, media with its text beside or below it. gallery.js sets the
   nav-* / cap-* / compact classes and --media-w / --media-h. */

.gallery { height: 100vh; height: 100dvh; overflow: hidden; }

.topbar {
  position: fixed;
  inset: 0 0 auto 0;
  height: var(--header-h);
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--rule);
  z-index: 2;
}
.brand, .nav-brand {
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-weight: 600;
  font-size: 1.15rem;
}
.brand a, .nav-brand a { color: var(--fg); text-decoration: none; }
.crumb { color: var(--muted); }
.crumb .section { color: var(--fg); }
.nav-brand { display: none; }
.repo {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 0.9rem;
  text-decoration: none;
}
.repo:hover { color: var(--fg); }

.sidebar {
  position: fixed;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  z-index: 1;
}
.sidebar-head { flex: none; display: flex; align-items: center; gap: 12px; }
.sidebar-scroll { flex: 1; min-height: 0; }
.filter {
  box-sizing: border-box;
  padding: 6px 10px;
  font: inherit;
  font-size: 0.9rem;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: var(--bg);
  color: var(--fg);
}
.sidebar h2 {
  margin: 0;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
.sidebar ul { list-style: none; margin: 0; padding: 0; }
.thumb {
  --thumb-pad: 6px;
  display: block;
  padding: var(--thumb-pad);
  border-radius: 8px;
  color: var(--fg);
  text-decoration: none;
}
.thumb:hover { background: var(--hover); }
.thumb.active { background: var(--hover); box-shadow: inset 0 0 0 2px var(--accent); }
.thumb img, .thumb .tile {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-radius: 4px;
  background: var(--viewer);
}
.thumb .tile {
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}
/* The icon is a mask, so it takes the tile's text color in either theme. */
.thumb .tile.icon::before {
  content: "";
  width: 40%;
  height: 40%;
  background: currentColor;
  mask: var(--icon) center / contain no-repeat;
}
.thumb .label {
  display: block;
  margin-top: 4px;
  padding: 0 4px;
  border-radius: 4px;
  font-size: 0.85rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.thumb.active .label {
  /* A band across the bottom of the thumb, out to its edges. */
  margin: 0 calc(-1 * var(--thumb-pad)) calc(-1 * var(--thumb-pad));
  padding: 4px calc(var(--thumb-pad) + 4px) var(--thumb-pad);
  border-radius: 0 0 8px 8px;
  background: var(--accent);
  color: var(--bg);
}

/* The filter takes the header's left end, as wide as the left column, in
   either layout; the header runs on to its right. */
.nav-left .topbar, .nav-bottom .topbar { left: var(--sidebar-w); }

/* Left column, full height. */
.nav-left .sidebar {
  top: 0;
  bottom: 0;
  left: 0;
  width: var(--sidebar-w);
  border-right: 1px solid var(--rule);
}
.nav-left .sidebar-head { flex-direction: column; align-items: stretch; gap: 10px; padding: 12px 12px 0; }
.nav-left:not(.compact) .sidebar-head {
  height: var(--header-h);
  box-sizing: border-box;
  justify-content: center;
  padding: 0 12px;
  border-bottom: 1px solid var(--rule);
}
.nav-left .sidebar-scroll { overflow-y: auto; padding: 0 12px 12px; }
.nav-left .filter { width: 100%; }
.nav-left .sidebar h2 { margin: 16px 4px 6px; }

/* Top strip: one scrolling row of thumbnails under the header with group
   names written sideways. The filter sits above the strip's left end. */
.nav-bottom .sidebar {
  top: var(--header-h);
  left: 0;
  right: 0;
  height: var(--strip-h);
  border-bottom: 1px solid var(--rule);
}
.nav-bottom .sidebar-head {
  position: absolute;
  bottom: 100%;
  left: 0;
  width: var(--sidebar-w);
  height: var(--header-h);
  box-sizing: border-box;
  padding: 0 12px;
  background: var(--panel);
  border: 1px solid var(--rule);
  border-width: 0 1px 1px 0;
}
/* With no header, the filter goes on a tab hanging from the strip's left end.
   The tab sits in the viewer's padding and only covers the media when the
   window is tight. */
.compact.nav-bottom .sidebar-head {
  top: 100%; /* over the strip's bottom border, so the tab joins the strip */
  bottom: auto;
  width: auto;
  height: auto;
  padding: 6px 8px;
  border-bottom-right-radius: 8px;
}
.nav-bottom .sidebar-scroll {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 0 12px;
  scrollbar-width: thin;
  scrollbar-color: color-mix(in srgb, var(--muted) 50%, transparent) transparent;
}
/* Safari; Chrome skips these because the standard properties are set. */
.nav-bottom .sidebar-scroll::-webkit-scrollbar { height: 8px; }
.nav-bottom .sidebar-scroll::-webkit-scrollbar-thumb { background: color-mix(in srgb, var(--muted) 50%, transparent); border-radius: 4px; }
.nav-bottom .filter { width: 100%; }
.compact.nav-bottom .filter { width: 200px; }
.nav-bottom .group { display: flex; align-items: center; gap: 4px; }
.nav-bottom .group[hidden] { display: none; }
.nav-bottom .sidebar h2 {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  padding: 0 4px;
  border-left: 1px solid var(--rule);
}
.nav-bottom .sidebar ul { display: flex; gap: 4px; }
.nav-bottom .thumb { --thumb-pad: 4px; width: 160px; }

/* Short screens (a phone on its side): no header; the list carries the title. */
.compact { --header-h: 0px; }
.compact .topbar { display: none; }
.compact .nav-brand { display: block; }
.compact.nav-left .nav-brand { margin: 0 4px; }

.viewer {
  position: fixed;
  top: var(--header-h);
  right: 0;
  bottom: 0;
  left: 0;
  max-width: none;
  margin: 0;
  padding: 0;
  overflow: auto;
  background: var(--viewer);
}
.nav-left .viewer { left: var(--sidebar-w); }
.nav-bottom .viewer { top: calc(var(--header-h) + var(--strip-h)); }

/* The media sits at the left (or top) and the text takes all the room left
   over, scrolling on its own when it runs long. */
.pane { display: none; }
.pane.active {
  display: flex;
  gap: var(--gap);
  height: 100%;
  box-sizing: border-box;
  padding: var(--pad);
}
.cap-right .pane.active { align-items: center; }
.cap-below .pane.active { flex-direction: column; }
.cap-below .media { align-self: center; }

.media { flex: none; width: var(--media-w); height: var(--media-h); }
.media img, .media video {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: var(--viewer);
}
.media img { cursor: zoom-in; }

/* ---- A cycling pane (data-cycle): another section's poster laid over the
   media, with a call to action through to that section. The incoming frame
   fades in on top; the outgoing one waits until it is covered, unless the
   pane's own media is coming back. */
.media { position: relative; }
.frame {
  position: absolute;
  inset: 0;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.6s 0.6s, visibility 0s 1.2s;
}
.media.on-base .frame { transition-delay: 0s, 0.6s; }
.frame.shown {
  z-index: 1;
  opacity: 1;
  visibility: visible;
  transition: opacity 0.6s, visibility 0s;
}
.media .frame img { cursor: pointer; }
.cta {
  position: absolute;
  left: 50%;
  bottom: 80px;
  transform: translateX(-50%);
  padding: 8px 16px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--bg);
  font-weight: 600;
  font-size: 0.95rem;
  box-shadow: 0 2px 12px rgb(0 0 0 / 0.35);
  white-space: nowrap;
}
.cta .go { font-weight: 400; opacity: 0.75; }
.cta::after { content: "→"; display: inline-block; margin-left: 0.5em; transition: transform 0.2s; }
.frame:hover .cta { filter: brightness(1.1); }
.frame:hover .cta::after { transform: translateX(4px); }

/* The step's link: a tint while it's current, and a bar along its bottom
   that fills over the step's time. */
.cycle-link {
  border-radius: 4px;
  padding: 0 0.15em;
  margin: 0 -0.15em;
  background: linear-gradient(var(--accent), var(--accent)) left bottom / 0% 2px no-repeat;
  transition: background-color 0.3s;
}
/* The bar stands in for the underline, which would run alongside it. */
.cycle-link.lit {
  border-radius: 4px 4px 0 0;
  background-color: color-mix(in srgb, var(--accent) 22%, transparent);
  text-decoration: none;
}
.cycle-link.timing { animation: cycle-fill var(--cycle, 5s) linear forwards; }
@keyframes cycle-fill { to { background-size: 100% 2px; } }

@media (prefers-reduced-motion: reduce) {
  .frame, .frame.shown, .cycle-link { transition: none; }
}
:fullscreen { cursor: zoom-out; object-fit: contain; background: #000; }

.caption {
  flex: 1;
  min-width: 0;
  min-height: 0;
  box-sizing: border-box;
  overflow-y: auto;
  color: var(--viewer-fg);
  font-size: 0.95rem;
  line-height: 1.55;
}
.cap-right .caption { align-self: stretch; }
.caption h2 { margin: 1.25rem 0 0.4rem; font-size: 1.05rem; line-height: 1.3; color: var(--viewer-head); }
.caption p { margin: 0 0 0.75rem; }
.caption > :last-child { margin-bottom: 0; }
.caption img { display: block; margin: 0.25rem 0 0.75rem; border-radius: 4px; }
.caption th, .caption td,
.doc th, .doc td { vertical-align: top; }

.pane-doc.active {
  flex-direction: row;
  justify-content: center;
  align-items: flex-start;
  height: auto;
  min-height: 100%;
  background: var(--bg);
}
.doc { width: 100%; max-width: 760px; }

/* Previous/next links under a section's text. Colors come from the text
   around them, so they suit the dark caption and the light or dark doc. */
.pager {
  display: flex;
  gap: 12px;
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid color-mix(in srgb, currentColor 20%, transparent);
}
.pager a {
  display: flex;
  flex-direction: column;
  min-width: 0;
  max-width: calc(50% - 6px);
  padding: 6px 12px;
  border: 1px solid color-mix(in srgb, currentColor 20%, transparent);
  border-radius: 6px;
  color: inherit;
  text-decoration: none;
  line-height: 1.3;
}
.pager a:hover { border-color: var(--accent); }
.pager .next { margin-left: auto; text-align: right; }
.pager .dir { font-size: 0.75rem; opacity: 0.7; }
.pager .prev .dir::before { content: "← "; }
.pager .next .dir::after { content: " →"; }
.pager .name {
  color: var(--accent);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
