:root {
  --entry-ink: #211713;
  --entry-light: #3b271f;
  --notebook-paper: #2a221b;
  --warm-air: #9e624c3c;
  --cool-air: #5b707028;
  --project-air: #a55c5d40;
  --plant-air: #81764e40;
  --reference-air: #5375883d;
  --trail-ink: #c7a58a;
}

@property --scene-light {
  syntax: "<color>";
  inherits: false;
  initial-value: #9e624c3c;
}

/* The low light follows the pointer and changes with the chapter. */
.has-ambient {
  isolation: isolate;
}

.archive-background {
  --scene-light: var(--warm-air);
  position: fixed;
  z-index: -1;
  inset: 0;
  background:
    radial-gradient(ellipse 37rem 31rem at var(--warm-x, 72%) var(--warm-y, 22%),
      var(--scene-light), transparent 89%),
    radial-gradient(ellipse 32rem 34rem at 7% 82%, var(--cool-air), transparent 89%);
  transition: --scene-light 480ms ease;
  pointer-events: none;
}

[data-archive-scene="red"] .archive-background {
  --scene-light: var(--project-air);
}

[data-archive-scene="orange"] .archive-background {
  --scene-light: var(--plant-air);
}

[data-archive-scene="blue"] .archive-background {
  --scene-light: var(--reference-air);
}

.chapter {
  position: relative;
  isolation: isolate;
}

.scroll-trail {
  position: absolute;
  z-index: -1;
  inset-block-start: clamp(.3rem, 1.8vw, 1.7rem);
  inset-inline-end: clamp(4rem, 18vw, 19rem);
  inline-size: clamp(3.2rem, 6vw, 5.6rem);
  block-size: clamp(2rem, 3.8vw, 3.2rem);
  color: var(--accent, var(--trail-ink));
  opacity: 0;
  transform: translate3d(0, 9px, 0);
  transition: opacity 680ms ease, transform 530ms cubic-bezier(.2, .75, .22, 1);
  pointer-events: none;
}

.scroll-trail.is-seen {
  opacity: .36;
  transform: translate3d(var(--drift-x, 0), var(--drift-y, 0), 0);
}

.chapter-prose .scroll-trail {
  inset-inline-start: .5rem;
  inset-inline-end: auto;
  inset-block-start: clamp(5.8rem, 7.55vw, 6.8rem);
}

.scroll-trail i,
.entry-content::before,
.entry-content::after {
  position: absolute;
  display: block;
  inline-size: 22%;
  aspect-ratio: 1;
  background: currentColor;
  -webkit-mask: var(--paw-mark) center / contain no-repeat;
  mask: var(--paw-mark) center / contain no-repeat;
}

.scroll-trail i:nth-child(1) {
  inset: 51% auto auto 1%;
  transform: rotate(-22deg);
  opacity: .58;
}

.scroll-trail i:nth-child(2) {
  inset: 9% auto auto 36%;
  transform: rotate(14deg);
}

.scroll-trail i:nth-child(3) {
  inset: 29% 2% auto auto;
  transform: rotate(-12deg);
  opacity: .7;
}

.archive-name .icon {
  transition: transform 200ms ease;
}

.archive-name:hover .icon {
  transform: translateY(-2px) rotate(-14deg);
}

.section-index a::after {
  inset: auto auto .37rem calc(50% - .43rem);
  inline-size: .86rem;
  block-size: .86rem;
  background: var(--accent, var(--accent-red));
  -webkit-mask: var(--paw-mark) center / contain no-repeat;
  mask: var(--paw-mark) center / contain no-repeat;
  transform: translateY(3px) rotate(-13deg);
  transition: opacity 175ms ease, transform 220ms ease;
}

.section-index a:hover::after,
.section-index a[aria-current="location"]::after {
  transform: translateY(0) rotate(-13deg);
}

.search-trigger {
  border-radius: 2rem;
}

.gallery.is-enhanced .is-current {
  position: relative;
  z-index: 1;
}

/* One open notebook holds all the existing prose. */
.chapter-prose:has(> .is-notebook) {
  grid-template-columns: clamp(13.5rem, 16vw, 17rem) minmax(0, 54rem) 1fr;
}

.chapter-prose>.is-notebook {
  min-inline-size: 0;
}

.notebook-tabs {
  display: flex;
  flex: 1 1 auto;
  min-inline-size: 0;
  align-items: stretch;
  gap: .35rem;
  max-inline-size: 100%;
  font-size: 1rem;
  overflow-x: auto;
  scrollbar-width: thin;
}

.notebook-tab {
  flex: 0 0 auto;
  min-block-size: 2.85rem;
  max-inline-size: min(22rem, 90%);
  padding: .5rem .86rem;
  overflow-wrap: anywhere;
  border-radius: .72rem .72rem 0 0;
  background: var(--surface);
  color: var(--text-muted);
  line-height: 1.3;
  text-align: start;
  font-weight: 620;
  transition: color 180ms ease, background-color 180ms ease;
}

.notebook-tab:hover {
  color: var(--text);
  background: var(--surface-raised);
}

.notebook-tab[aria-selected="true"] {
  background: var(--notebook-paper);
  color: var(--accent-orange);
  box-shadow: inset 0 2px var(--accent-orange);
}

.notebook-tab:focus-visible {
  outline-offset: -4px;
}

.notebook-sheets {
  position: relative;
  min-inline-size: 0;
  min-block-size: 14rem;
  padding: clamp(1.15rem, 2.85vw, 2.45rem);
  border-radius: 0rem 1.05rem 1.05rem 1.05rem;
  background: var(--notebook-paper);
}

.notebook-sheets::after {
  position: absolute;
  inset: 0 0 auto auto;
  inline-size: 1.15rem;
  aspect-ratio: 1;
  border-start-end-radius: inherit;
  background: linear-gradient(225deg, var(--surface) 50%, var(--surface-hover) 50%);
  pointer-events: none;
  content: "";
}

.notebook-sheet {
  min-inline-size: 0;
}

.notebook-sheet> :first-child {
  margin-block-start: 0;
}

.notebook-sheet> :last-child {
  margin-block-end: 0;
}

.code-sample {
  min-inline-size: 0;
  margin-block: 0 1.15em;
  border-radius: .5rem;
  background: var(--surface);
}

.code-sample pre {
  margin: 0;
  border-radius: inherit;
}

.code-tools {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: .35rem .7rem;
  padding: .2rem .75rem 0;
}

.code-feedback,
.code-copy {
  display: inline-flex;
  align-items: center;
  gap: .36rem;
  font-size: .85rem;
  line-height: 1.3;
}

.code-copy {
  min-block-size: var(--control-size);
  padding-inline: .5rem;
  border-radius: .36rem;
  color: var(--text-secondary);
}

.code-copy:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.code-feedback {
  color: var(--accent-orange);
}

.code-feedback:empty {
  position: absolute;
}

.code-feedback:has(svg) {
  animation: copy-pop 280ms ease-out;
}

@keyframes copy-pop {
  from {
    transform: translateY(3px) scale(.89);
    opacity: 0;
  }

  to {
    transform: none;
    opacity: 1;
  }
}

.code-sample .copy-fallback {
  padding-block-start: 0;
}

/* A separate top-layer veil leaves an opening over the live page. */
dialog.entry-dialog {
  position: fixed;
  display: grid;
  place-items: safe center;
  inset: 0;
  inline-size: 100vw;
  block-size: 100dvh;
  max-inline-size: none;
  max-block-size: none;
  margin: 0;
  padding: clamp(1.1rem, 4vw, 2.4rem);
  border-radius: 0;
  background: transparent;
  color: var(--text);
  overflow: auto;
}

dialog.entry-dialog:not([open]) {
  display: none;
}

.entry-dialog::backdrop {
  background: transparent;
}

.entry-veil {
  position: fixed;
  inset: 0;
  inline-size: 100%;
  block-size: 100%;
  pointer-events: none;
}

.entry-glow {
  stop-color: var(--entry-light);
}

.entry-shade {
  stop-color: var(--entry-ink);
}

.entry-mask-paper {
  fill: white;
}

.entry-mask-hole {
  fill: black;
}

.entry-content {
  position: relative;
  display: grid;
  justify-items: center;
  inline-size: min(100%, 30rem);
  gap: .7rem;
  text-align: center;
  transition: opacity 115ms ease, transform 220ms ease;
}

.entry-content::before,
.entry-content::after {
  inline-size: clamp(1rem, 3.8vw, 2.15rem);
  color: var(--accent-red);
  pointer-events: none;
  content: "";
}

.entry-content::before {
  inset: 11% auto auto 8%;
  transform: rotate(-21deg);
  opacity: .33;
}

.entry-content::after {
  inset: 2% 11% auto auto;
  transform: rotate(17deg);
  opacity: .24;
}

.entry-content h2 {
  font-size: clamp(2.3rem, 1.65rem + 4vw, 4.55rem);
  font-weight: 765;
  letter-spacing: -.055em;
  line-height: 1;
}

.entry-content p {
  color: var(--text-secondary);
  font-size: .9rem;
}

.entry-art {
  inline-size: min(86%, clamp(13rem, 26vw, 20.3rem));
  aspect-ratio: 680 / 306;
  margin-block-end: .36rem;
  background: var(--puppy-study) center / contain no-repeat;
  transition: transform 350ms cubic-bezier(.22, .74, .28, 1);
}

.entry-content:has(.entry-button:hover) .entry-art {
  transform: translateY(-3px) rotate(-2deg);
}

.entry-button {
  display: inline-flex;
  align-items: center;
  gap: .6rem;
  min-block-size: 3.1rem;
  margin-block-start: .43rem;
  padding-inline: 1.25rem;
  border-radius: 2rem;
  background: var(--accent-red);
  color: var(--selection-text);
  font-weight: 700;
  transition: background-color 160ms ease, transform 170ms ease;
}

.entry-button:hover {
  background: var(--selection-bg);
  transform: translateY(-2px);
}

.entry-button:active {
  transform: translateY(1px);
}

.entry-quiet {
  min-block-size: var(--control-size);
  padding-inline: .6rem;
  color: var(--text-muted);
  font-size: .87rem;
  text-underline-offset: .2em;
}

.entry-quiet:hover {
  color: var(--text);
  text-decoration: underline;
}

.entry-dialog.is-opening .entry-content {
  opacity: 0;
  transform: scale(.975);
  pointer-events: none;
}

#content:focus {
  outline: none;
}

/* Music is a small, persistent control the listener can reach immediately. */
.music-dock {
  position: fixed;
  z-index: 4;
  inset-block-end: calc(.8rem + env(safe-area-inset-bottom, 0px));
  inset-inline-end: max(1rem, calc(var(--page-inset) * .7));
  display: flex;
  align-items: center;
  gap: .52rem;
  max-inline-size: calc(100% - 2rem);
  padding: .24rem .35rem;
  border-radius: 2rem;
  background: var(--dialog-background);
  box-shadow: 0 2px 14px var(--backdrop);
}

.music-play,
.music-mute {
  display: inline-grid;
  place-items: center;
  min-block-size: var(--control-size);
  padding-inline: .66rem;
  border-radius: 2rem;
  color: var(--text);
  line-height: 1;
  transition: background-color 160ms ease;
}

.music-play {
  min-inline-size: var(--control-size);
  padding-inline: .25rem;
  background: var(--surface-hover);
}

.music-play:hover,
.music-mute:hover {
  background: var(--surface-hover);
}

.music-mute[aria-pressed="true"] {
  background: var(--surface-raised);
  color: var(--accent-red);
}

.music-mute,
.music-title {
  font-size: .84rem;
  font-weight: 595;
}

.music-title {
  color: var(--text-secondary);
  overflow-wrap: anywhere;
}

html:has(.music-dock:not([hidden])) {
  scroll-padding-block-end: 4.4rem;
}

body:has(.music-dock:not([hidden])) {
  padding-block-end: 3.75rem;
}

@media (max-width: 54rem) {
  .chapter-prose:has(> .is-notebook) {
    grid-template-columns: clamp(13.5rem, 16vw, 17rem) minmax(0, 84rem) 1fr;
  }

  .chapter-prose .scroll-trail {
    inset-block-start: .6rem;
    inset-inline: auto .6rem;
  }
}

@media (max-width: 45rem) {
  .scroll-trail {
    inset-block-start: .6rem;
    inset-inline: auto .6rem;
  }

  .chapter-carousel .scroll-trail {
    inset-block-start: -.4rem;
    inset-inline-end: 4.9rem;
  }

  .music-dock {
    inset-inline-end: .75rem;
  }
}

@media (max-width: 34rem) {
  .notebook-tabs:has(> :last-child:nth-child(-n + 4)) {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(min-content, 1fr);
  }

  .notebook-tabs:has(> :last-child:nth-child(-n + 4)) .notebook-tab {
    max-inline-size: min(22rem, 68vw);
    overflow-wrap: break-word;
  }

  .notebook-tab {
    padding-inline: clamp(.45rem, 1.8vw, .86rem);
    font-size: .86rem;
  }
}

@media (max-height: 28rem) {
  .entry-art {
    inline-size: min(68%, 11rem);
    margin-block-end: 0;
  }

  .entry-content {
    gap: .34rem;
  }
}

@media (prefers-reduced-motion: reduce) {

  .archive-background,
  .scroll-trail,
  .archive-name .icon,
  .section-index a::after,
  .entry-art,
  .entry-button,
  .entry-content,
  .notebook-tab,
  .music-play,
  .music-mute {
    transition: none;
    transform: none;
  }

  .scroll-trail {
    opacity: .22;
  }

  .scroll-trail.is-seen,
  .archive-name:hover .icon,
  .entry-content:has(.entry-button:hover) .entry-art,
  .entry-button:hover {
    transform: none;
  }

  .code-feedback {
    animation: none !important;
  }
}

dialog.entry-dialog {
  cursor: pointer;
}

.entry-content p {
  font-size: .95rem;
  letter-spacing: .04em;
  animation: entry-pulse 2.5s ease-in-out infinite;
}

@keyframes entry-pulse {

  0%,
  100% {
    opacity: .45;
  }

  50% {
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .entry-content p {
    animation: none;
  }
}

@media (width > 54rem) {
  .chapter-prose:has(> .is-notebook) {
    grid-template-columns:
      clamp(13.5rem, 16vw, 17rem)
      minmax(0, 1fr);
  }

  .chapter-prose > .prose.is-notebook {
    inline-size: max-content;
    min-inline-size: min(100%, 54rem);
    max-inline-size: min(100%, 84rem);
    justify-self: start;
  }

  .notebook-sheets {
    contain: inline-size;
  }
}

.notebook-tabs {
  flex-wrap: wrap;
  overflow: visible;
}

.notebook-tab {
  flex: 0 0 auto;
}

.nav-actions {
  grid-area: search;
  justify-self: end;
  display: flex;
  align-items: center;
  gap: .45rem;
}

.share-dropdown {
  position: relative;
}

.share-trigger {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .45rem;
  min-block-size: var(--control-size);
  padding-inline: .65rem;
  font-weight: 600;
  color: var(--text);
  border-radius: var(--corner);
  cursor: pointer;
  list-style: none;
  user-select: none;
}

.share-trigger::-webkit-details-marker {
  display: none;
}

.share-trigger .icon {
  color: var(--text-secondary);
}

.share-trigger:hover,
.share-dropdown[open] .share-trigger {
  background: var(--surface-hover);
}

.share-options {
  position: absolute;
  inset-inline-end: 0;
  inset-block-start: calc(100% + .5rem);
  z-index: 20;

  display: grid;
  gap: .2rem;
  inline-size: 13.5rem;
  padding: .45rem;

  background: var(--surface);
  border: 1px solid var(--control-line);
  border-radius: .65rem;
  box-shadow: 0 8px 24px #0003;
}

.share-options button {
  padding: .7rem .8rem;
  border-radius: .35rem;
  text-align: start;
  font-size: .9rem;
  cursor: pointer;
}

.share-options button:hover {
  background: var(--surface-hover);
  color: var(--accent-orange);
}

.share-options button[hidden] {
  display: none;
}

.share-status {
  color: var(--accent-orange);
  font-size: .8rem;
  text-align: center;
}

.share-status:empty {
  display: none;
}

@media (width > 45rem) {
  .masthead-inner {
    grid-template-columns:
      minmax(0, 1fr)
      minmax(0, auto)
      minmax(max-content, 1fr);
  }
}

@media (max-width: 45rem) {
  .nav-actions {
    gap: .2rem;
  }

  .share-trigger {
    padding-inline: .45rem;
  }
}

/* Reserve space for the peeking character. */
@media (min-width: 75rem) {
  #about.chapter-prose:has(> .is-notebook) {
    padding-inline-end: 8rem;
  }

  #about .notebook-sheets::before {
    content: "";
    position: absolute;

    inset-inline-start: 100%;
    inset-block-start: 18px;

    block-size: var(--peek-height, 0px);
    inline-size: calc(var(--peek-height, 0px) * .473);

    background-image: url("../assets/theme/peeking.png");
    background-repeat: no-repeat;
    background-size: auto 110.7%;
    background-position: 56% 50%;

    transform: translateX(-10%) scaleX(-1);
    transform-origin: center;

    pointer-events: none;
    z-index: 2;

    transition:
      block-size 350ms cubic-bezier(.22,.74,.28,1),
      inline-size 350ms cubic-bezier(.22,.74,.28,1);
  }
}

@media (prefers-reduced-motion: reduce) {
  #about .notebook-sheets::before {
    transition: none;
  }
}

/* Mobile notebook controls are hidden on desktop. */
.notebook-mobile-nav {
  display: none;
}

@media (max-width: 54rem) {

  /* Give the notebook the entire available width. */
  #about.chapter-prose:has(> .is-notebook) {
    grid-template-columns: minmax(0, 1fr) !important;
    gap: 1rem;
    padding-inline-end: 0;
  }

  #about .chapter-heading {
    grid-column: 1 / -1;
    inline-size: 100%;
  }

  #about .prose.is-notebook {
    grid-column: 1 / -1;
    inline-size: 100%;
    min-inline-size: 0;
    max-inline-size: 100%;
    justify-self: stretch;
  }

  /* Replace desktop tabs with the chapter picker. */
  .notebook-tabs {
    display: none !important;
  }

  .notebook-mobile-nav {
    display: grid;
    grid-template-columns: 2.8rem minmax(0, 1fr) 2.8rem;
    align-items: stretch;
    gap: .4rem;
    margin-block-end: .65rem;
  }

  .notebook-mobile-picker,
  .notebook-mobile-arrow {
    min-inline-size: 0;
    min-block-size: 2.8rem;
    background: var(--notebook-paper);
    color: var(--text);
    border: 1px solid var(--control-line);
    border-radius: .55rem;
    font: inherit;
  }

  .notebook-mobile-picker {
    inline-size: 100%;
    padding: .5rem .75rem;
    font-size: .95rem;
    cursor: pointer;
  }

  .notebook-mobile-arrow {
    display: grid;
    place-items: center;
    font-size: 1.65rem;
    cursor: pointer;
  }

  .notebook-mobile-arrow:active {
    background: var(--surface-raised);
    transform: scale(.95);
  }

  .notebook-mobile-counter {
    grid-column: 1 / -1;
    color: var(--text-muted);
    font-size: .75rem;
    text-align: center;
  }

  .notebook-sheets {
    inline-size: 100%;
    min-inline-size: 0;
    padding: 1.15rem;
    border-radius: .75rem;
    contain: none;
    overflow-wrap: anywhere;
  }

  .notebook-sheet {
    min-inline-size: 0;
  }

  .notebook-sheet img {
    max-inline-size: 100%;
    block-size: auto;
  }

  .notebook-sheet pre {
    max-inline-size: 100%;
    overflow-x: auto;
  }

  /* Hide the peeking character on smaller displays. */
  #about .notebook-sheets::before {
    display: none;
  }
}

/* Remove the visible carousel image containers. */
.gallery .media-frame,
.gallery .media-frame:hover {
  background: transparent;
  border: 0;
  box-shadow: none;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
}

/* Preserve natural image proportions. */
.gallery .media-frame img,
.gallery .media-frame video {
  inline-size: auto;
  block-size: auto;
  max-inline-size: 100%;
  max-block-size: 100%;
  min-inline-size: 0;
  min-block-size: 0;

  object-fit: contain;
  border-radius: .5rem;
}

/* Subtly distinguish neighbouring slides. */
.gallery.is-enhanced .slide:not(.is-current) .media-frame {
  opacity: .7;
  transition: opacity 250ms ease;
}

.gallery.is-enhanced .slide:not(.is-current) .media-frame:hover {
  opacity: 1;
}

/* ==============================
   Spacious layout
   ============================== */

:root {
  --chapter-gap: clamp(3.5rem, 6vw, 7rem);
}

/* More separation between sections. */
.chapter {
  padding-block:
    clamp(3rem, 4.5vw, 5rem)
    var(--chapter-gap);
}

/* More space between headings and their content. */
.chapter-heading {
  margin-block-end: clamp(1.75rem, 3vw, 3rem);
}

/* Give the introduction more breathing room. */
.subject {
  padding-block: clamp(3.5rem, 6vw, 7rem);
}

.subject p {
  line-height: 1.8;
  margin-block-start: 1.4rem;
}

/* Notebook spacing. */
.notebook-sheets {
  padding: clamp(1.5rem, 3vw, 3.5rem);
}

/* Improve reading comfort. */
.prose {
  line-height: 1.85;
}

.prose :where(p, ul, ol, blockquote, pre) {
  margin-block-end: 1.25em;
}

.prose :where(h3, h4, h5, h6) {
  margin-block: 1.9em .65em;
}

.prose li + li {
  margin-block-start: .6em;
}

/* Give carousel items more separation. */
.gallery-track {
  gap: 2.5rem clamp(1.5rem, 3vw, 3.5rem);
}

.slide h3,
.gallery.is-enhanced .is-current h3 {
  margin-block-start: 1.15rem;
}

.slide-summary {
  margin-block-start: .65rem;
  line-height: 1.7;
}

/* Information cards. */
.facts {
  gap: 1.5rem clamp(1.5rem, 3vw, 3rem);
}

.fact-face {
  min-block-size: 6.5rem;
  padding-block: 1.25rem;
  gap: .65rem;
}

/* Footer spacing. */
.site-footer {
  padding-block: 2.5rem 4rem;
}

@media (max-width: 54rem) {
  :root {
    --chapter-gap: 3rem;
  }

  .chapter {
    padding-block: 2.5rem var(--chapter-gap);
  }

  .subject {
    padding-block: 2.75rem;
    row-gap: 2rem;
  }

  .chapter-heading {
    margin-block-end: 1.5rem;
  }

  .notebook-sheets {
    padding: 1.25rem;
  }

  .prose {
    line-height: 1.75;
  }

  .gallery-track {
    gap: 1.5rem;
  }

  .facts {
    gap: 1rem;
  }
}

/* ==============================
   Carousel caption styling
   ============================== */

.gallery .slide {
  text-align: center;
}

.gallery .slide h3,
.gallery.is-enhanced .is-current h3 {
  margin-block: 1.4rem .5rem;
  margin-inline: auto;
  max-inline-size: 36ch;
  line-height: 1.3;
  text-wrap: balance;
}

.gallery .slide-summary {
  max-inline-size: 48ch;
  margin-inline: auto;
  margin-block-start: .65rem;
  line-height: 1.7;
  text-wrap: pretty;
}

/* De-emphasise neighbouring captions. */
.gallery.is-enhanced .slide:not(.is-current) h3 {
  opacity: .65;
}

.gallery.is-enhanced .slide:not(.is-current) .slide-summary {
  opacity: .65;
  font-size: .85rem;
}

/* Keep detailed content readable. */
.gallery .slide-extra {
  max-inline-size: 60ch;
  margin-inline: auto;
  margin-block-start: 1rem;
}

.gallery .slide-details p,
.gallery .slide-extra .notice {
  text-align: start;
}

/* Remove the floating expand button. */
.gallery .media-indicator {
  display: none !important;
}

.gallery .is-current .media-frame {
  cursor: zoom-in;
}

.gallery .slide:not(.is-current) .media-frame {
  cursor: pointer;
}

/* ==============================
   Cinematic lightbox
   ============================== */

dialog.image-dialog {
  background: rgb(17 17 17 / 97%);
  border: 1px solid rgb(255 255 255 / 7%);
  border-radius: 1rem;
  box-shadow: 0 24px 100px rgb(0 0 0 / 40%);
}

.image-dialog::backdrop {
  background: rgb(0 0 0 / 75%);
  backdrop-filter: blur(9px);
}

/* Remove the brown image mat. */
.image-dialog .viewer-frame {
  background: transparent;
  border: 0;
  border-radius: .65rem;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
}

.viewer-frame img,
.viewer-frame video {
  inline-size: auto;
  block-size: auto;
  max-inline-size: 100%;
  max-block-size: 100%;
  object-fit: contain;
  border-radius: .5rem;
}

/* Modal title. */
.image-dialog .dialog-header {
  padding: 1.25rem 1.5rem;
}

.image-dialog .dialog-header h2 {
  font-weight: 600;
  letter-spacing: -.025em;
}

/* Stack the caption and navigation vertically. */
.image-dialog .viewer-meta {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
  padding: 1.25rem 1.5rem 1.75rem;
  text-align: center;
}

.image-dialog .viewer-meta p {
  flex: none;
  max-inline-size: 65ch;
  line-height: 1.7;
}

/* Previous / next navigation. */
.image-dialog [data-viewer-controls] {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 1rem;
  margin-block-start: .5rem;
}

.image-dialog [data-viewer-previous] {
  order: 1;
}

.image-dialog [data-viewer-position] {
  order: 2;
  margin: 0;
}

.image-dialog [data-viewer-next] {
  order: 3;
}

/* Translucent buttons. */
.image-dialog .icon-button {
  background: rgb(255 255 255 / 5%);
  border: 1px solid rgb(255 255 255 / 6%);
  border-radius: 50%;
  transition:
    background 180ms ease,
    border-color 180ms ease;
}

.image-dialog .icon-button:hover:not([aria-disabled="true"]) {
  background: rgb(255 255 255 / 13%);
  border-color: rgb(255 255 255 / 15%);
}

.image-dialog .icon-button[aria-disabled="true"] {
  opacity: .3;
}

@media (max-width: 48rem) {
  dialog.image-dialog {
    inline-size: calc(100% - 1rem);
    border-radius: .85rem;
  }

  .image-dialog .viewer-frame {
    block-size: min(55dvh, 32rem);
    margin-inline: .5rem;
  }

  .image-dialog .dialog-header {
    padding: .85rem 1rem;
  }

  .image-dialog .viewer-meta {
    padding: 1rem 1rem 1.5rem;
    gap: 1rem;
  }

  .gallery .slide h3 {
    margin-block-start: 1rem;
  }

  .gallery .slide-summary {
    max-inline-size: 34ch;
  }
}