@font-face {
  font-family: "Qingming Display";
  src: url("fonts/bricolage-grotesque.woff2?v=1") format("woff2");
  font-style: normal;
  font-weight: 200 800;
  font-display: swap;
}

@font-face {
  font-family: "Qingming CJK";
  src: url("fonts/noto-serif-sc-subset-69.woff2?v=1") format("woff2");
  font-style: normal;
  font-weight: 500 700;
  font-display: swap;
}

@font-face {
  font-family: "Qingming Newsreader";
  src: url("fonts/newsreader-latin.woff2") format("woff2");
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
}

/* A dark room with one handscroll unrolled across it. The silk of the scan
   is the only colour; the mounts above and below it are the 裱绫 a scroll is
   backed with, in a dull warm dark so the painting stays the brightest thing. */
.qingming-page {
  --qm-ink: #16120e;
  --qm-mount: #241e17;
  --qm-mount-edge: #3a3128;
  --qm-silk: #cdb98c;
  --qm-paper: #e9dec6;
  --qm-text: #efe6d2;
  --qm-gold: #c9a15a;
  --qm-gutter: clamp(1.25rem, 5vw, 5.5rem);
  --qm-space-1: 0.5rem;
  --qm-space-2: 1rem;
  --wet: 0;
  --qb-chrome-gap: clamp(1rem, 3vw, 2rem);
  --qb-chrome-ink: var(--qm-text);
  --qb-chrome-fill: color-mix(in srgb, var(--qm-ink) 76%, transparent);
  --qb-chrome-fill-hover: color-mix(in srgb, var(--qm-mount-edge) 92%, transparent);
  --qb-chrome-shine: color-mix(in srgb, var(--qm-text) 17%, transparent);
  --qb-chrome-rim: color-mix(in srgb, var(--qm-text) 35%, transparent);
  --qb-chrome-shadow: color-mix(in srgb, #050302 54%, transparent);
  min-width: 20rem;
  margin: 0;
  overflow-x: hidden;
  color: var(--qm-text);
  background: var(--qm-ink);
  color-scheme: dark;
  font-family: "Qingming Display", ui-sans-serif, sans-serif;
  text-rendering: optimizeLegibility;
}

.qingming-page,
.qingming-page * {
  box-sizing: border-box;
}

.qingming-page ::selection {
  color: var(--qm-ink);
  background: var(--qm-paper);
}

.qingming-page a {
  color: inherit;
}

.qingming-page .skip-link {
  position: fixed;
  z-index: 20;
  top: var(--qm-space-2);
  left: var(--qm-space-2);
  padding: var(--qm-space-1) var(--qm-space-2);
  color: var(--qm-ink);
  background: var(--qm-paper);
  font-size: 0.875rem;
  font-weight: 700;
  text-decoration: none;
  transform: translateY(-160%);
}

.skip-link:focus {
  transform: translateY(0);
  outline: 3px solid var(--qm-gold);
  outline-offset: 3px;
}

/* the stage: mount, painting, mount */
.scroll-stage {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-block-size: 100svh;
  block-size: 100svh;
  background: var(--qm-ink);
}

.scroll-mount {
  position: relative;
  z-index: 4;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 0.75rem var(--qm-space-2);
  /* the shared back control sits fixed in the top-left corner, 44px wide: the
     title starts clear of it at every width */
  padding: max(var(--qb-chrome-gap), env(safe-area-inset-top, 0px)) var(--qm-gutter) 0.9rem calc(max(var(--qb-chrome-gap), env(safe-area-inset-left, 0px)) + 44px + 0.9rem);
  background: var(--qm-mount);
  border-block-end: 1px solid var(--qm-mount-edge);
}

.scroll-mount--foot {
  grid-template-columns: minmax(0, 1fr);
  align-items: center;
  padding: 0.75rem var(--qm-gutter) max(0.9rem, env(safe-area-inset-bottom, 0px));
  border-block-end: 0;
  border-block-start: 1px solid var(--qm-mount-edge);
}

.scroll-mount h1 {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.35rem 1rem;
  margin: 0;
  font-family: "Qingming Newsreader", ui-serif, serif;
  font-optical-sizing: auto;
  font-size: clamp(1.75rem, 3.2vw, 2.5rem);
  font-weight: 500;
  letter-spacing: -0.03em;
  line-height: 1.05;
  color: var(--qm-paper);
}

.scroll-mount h1 [lang] {
  font-family: "Qingming CJK", serif;
  font-weight: 600;
  letter-spacing: 0.06em;
  white-space: nowrap;
}

.scene-gloss {
  font-size: clamp(1rem, 1.5vw, 1.25rem);
  font-weight: 400;
  letter-spacing: -0.02em;
  color: var(--qm-silk);
}

.scroll-credit {
  grid-column: 1;
  margin: 0.35rem 0 0;
  max-width: 44rem;
  font-family: "Qingming Newsreader", ui-serif, serif;
  font-size: 0.95rem;
  line-height: 1.4;
  color: color-mix(in srgb, var(--qm-silk) 80%, var(--qm-text));
}

.scroll-credit a {
  text-decoration-color: color-mix(in srgb, var(--qm-gold) 60%, transparent);
  text-underline-offset: 0.15em;
}

/* the painting */
.scroll-room {
  position: relative;
  isolation: isolate;
  min-block-size: 0;
  overflow: hidden;
  background: var(--qm-ink);
}

.scroll-track {
  position: absolute;
  inset: 0;
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
  /* a handscroll opens at its right end, so the track reads right to left:
     with no script at all, the first thing shown is the start of the story */
  direction: rtl;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  touch-action: pan-x pan-y;
}

.scroll-track::-webkit-scrollbar {
  display: none;
}

.scroll-track[data-dragging] {
  cursor: grabbing;
}

.scroll-track:focus-visible {
  outline: 3px solid var(--qm-gold);
  outline-offset: -3px;
}

.scroll-strip {
  display: flex;
  flex-direction: row;
  width: max-content;
  height: 100%;
}

.scroll-strip img {
  display: block;
  flex: none;
  width: auto;
  height: 100%;
  max-width: none;
  pointer-events: none;
  background: var(--qm-silk);
}

/* the wet tone: the silk cools and darkens as the rain builds. A multiply
   layer, never a filter, so the tiles are not re-rendered per frame. */
.scroll-wet {
  position: absolute;
  z-index: 2;
  inset: 0;
  pointer-events: none;
  mix-blend-mode: multiply;
  background: linear-gradient(180deg, #a9b6b8 0%, #b7bcb4 45%, #9ea7a4 100%);
  opacity: calc(var(--wet) * 0.42);
}

/* the mist: two soft veils, only once it is really raining */
.scroll-mist {
  position: absolute;
  z-index: 3;
  inset: -20% -40%;
  pointer-events: none;
  background:
    radial-gradient(60% 40% at 30% 35%, rgba(226, 229, 222, 0.55), transparent 70%),
    radial-gradient(50% 35% at 75% 60%, rgba(226, 229, 222, 0.45), transparent 70%);
  filter: blur(28px);
  opacity: calc(var(--wet) * var(--wet) * 0.32);
}

/* the people: walkers and umbrellas, drawn between the silk and the weather */
.scroll-people {
  position: absolute;
  z-index: 1;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.scroll-rain {
  position: absolute;
  z-index: 4;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* controls, in the mount beside the title */
.scene-controls {
  grid-column: 2;
  grid-row: 1 / span 2;
  display: none;
  align-items: start;
  color: var(--qm-text);
  font-size: 0.78rem;
}

html[data-qingming-ready] .scene-controls {
  display: grid;
  grid-template-columns: auto auto auto;
  justify-items: end;
  gap: 0.5rem;
}

.scene-motion,
.soundscape {
  border: 1px solid color-mix(in srgb, var(--qm-text) 28%, transparent);
  color: inherit;
  background: color-mix(in srgb, var(--qm-ink) 82%, transparent);
  box-shadow:
    inset 0 1px 0 color-mix(in srgb, var(--qm-text) 18%, transparent),
    0 0.35rem 1.2rem color-mix(in srgb, #050302 34%, transparent);
  backdrop-filter: blur(18px) saturate(1.1);
  -webkit-backdrop-filter: blur(18px) saturate(1.1);
}

.scene-motion {
  min-width: 7.5rem;
  min-height: 44px;
  padding: 0.55rem 0.75rem;
  border-radius: 999px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  text-align: center;
}

.scene-motion[aria-pressed="true"] {
  color: var(--qm-ink);
  background: var(--qm-paper);
}

.scene-sound {
  position: relative;
}

.scene-sound summary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-width: 6rem;
  list-style: none;
}

.scene-sound summary::-webkit-details-marker {
  display: none;
}

.scene-sound summary::after {
  width: 0.35rem;
  height: 0.35rem;
  border-right: 1px solid currentColor;
  border-bottom: 1px solid currentColor;
  content: "";
  transform: translateY(-0.1rem) rotate(45deg);
}

.scene-sound[open] summary::after {
  transform: translateY(0.1rem) rotate(225deg);
}

.scene-sound[open] .soundscape {
  position: absolute;
  z-index: 6;
  top: calc(100% + 0.75rem);
  right: 0;
  width: min(18rem, calc(100vw - (var(--qb-chrome-gap) * 2)));
}

.scene-controls > .scene-status {
  grid-column: 1 / -1;
  max-width: min(22rem, calc(100vw - (var(--qb-chrome-gap) * 2)));
}

.soundscape {
  width: 100%;
  margin: 0;
  padding: 1rem;
  border-radius: 0.875rem;
}

.soundscape legend {
  float: left;
  margin: 0 0 0.75rem;
  padding: 0;
  color: var(--qm-paper);
  font-family: "Qingming Newsreader", ui-serif, serif;
  font-size: 1.25rem;
}

.soundscape__modes {
  clear: both;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.3rem;
}

.soundscape button {
  min-width: 44px;
  min-height: 44px;
  padding: 0.45rem 0.55rem;
  border: 0;
  border-radius: 0.55rem;
  color: inherit;
  background: color-mix(in srgb, var(--qm-text) 10%, transparent);
  font: inherit;
  font-weight: 650;
  cursor: pointer;
}

.soundscape button[aria-pressed="true"] {
  color: var(--qm-ink);
  background: var(--qm-paper);
}

.soundscape__volume {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.45rem;
  color: var(--qm-paper);
}

.soundscape__volume input {
  width: 100%;
  height: 44px;
  margin: 0;
  accent-color: var(--qm-gold);
  cursor: pointer;
}

.scene-status {
  min-height: 1em;
  margin: 0.35rem 0 0;
  color: var(--qm-silk);
  line-height: 1.35;
  text-align: right;
}

/* the room's own status keeps its line even when empty: a line appearing
   under the controls would move the mount and rescale the painting */
.scene-controls > .scene-status {
  min-height: 1.35em;
}

.soundscape .scene-status:empty {
  display: none;
}

/* the stations, in the foot of the mount */
.scroll-stations {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.scroll-stations p {
  margin: 0 0.5rem 0 0;
  font-family: "Qingming Newsreader", ui-serif, serif;
  font-size: 0.9rem;
  color: var(--qm-silk);
}

.scroll-stations button {
  min-height: 44px;
  padding: 0.5rem 0.9rem;
  border: 1px solid color-mix(in srgb, var(--qm-text) 28%, transparent);
  border-radius: 999px;
  color: inherit;
  background: color-mix(in srgb, var(--qm-ink) 82%, transparent);
  font: inherit;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
}

.scene-motion:focus-visible,
.soundscape button:focus-visible,
.soundscape__volume input:focus-visible,
.scroll-stations button:focus-visible,
.scroll-credit a:focus-visible {
  outline: 3px solid var(--qm-gold);
  outline-offset: 3px;
}

.qingming-page .qb-chrome__btn:focus-visible {
  outline-color: var(--qm-gold);
}

@media (hover: hover) and (pointer: fine) {
  .scene-motion[aria-pressed="false"]:hover,
  .scroll-stations button:hover {
    background: var(--qm-mount-edge);
  }

  .soundscape button[aria-pressed="false"]:hover {
    background: color-mix(in srgb, var(--qm-text) 20%, var(--qm-ink));
  }
}

@media (prefers-reduced-transparency: reduce) {
  .scene-motion,
  .soundscape,
  .scroll-stations button {
    background: var(--qm-ink);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }
}

@media (prefers-reduced-motion: no-preference) {
  .scroll-wet {
    transition: opacity 400ms linear;
  }

  .scroll-mist {
    animation: scroll-mist-drift 46s linear infinite;
  }

  .skip-link,
  .scene-motion,
  .soundscape button,
  .scroll-stations button {
    transition:
      color 180ms cubic-bezier(.16, 1, .3, 1),
      background-color 180ms cubic-bezier(.16, 1, .3, 1),
      transform 180ms cubic-bezier(.16, 1, .3, 1);
  }
}

@keyframes scroll-mist-drift {
  from {
    transform: translateX(-6%);
  }

  to {
    transform: translateX(6%);
  }
}

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

@media (max-width: 44rem) {
  .qingming-page {
    --qm-gutter: clamp(1.25rem, 6.16vw, 1.5rem);
  }

  .scroll-mount {
    grid-template-columns: minmax(0, 1fr);
  }

  .scene-controls {
    grid-column: 1;
    grid-row: auto;
  }

  /* three controls do not fit one row on a phone: let them wrap */
  html[data-qingming-ready] .scene-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: start;
  }

  .scene-controls > .scene-status {
    flex-basis: 100%;
    max-width: none;
    text-align: left;
  }

  .scene-sound[open] .soundscape {
    right: auto;
    left: 0;
  }

  .scroll-mount {
    gap: 0.5rem;
    padding-bottom: 0.75rem;
  }

  .scroll-credit {
    margin-top: 0.1rem;
    font-size: 0.78rem;
    line-height: 1.35;
  }

  /* the nav is named; on a phone the label would cost the painting a row */
  .scroll-stations p {
    display: none;
  }

  /* four stations do not fit a phone in one row, and a second row would
     cost the painting its height: one row that scrolls sideways instead */
  .scroll-stations {
    flex-wrap: nowrap;
    justify-content: flex-start;
    margin-inline: calc(var(--qm-gutter) * -1);
    padding-inline: var(--qm-gutter);
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  .scroll-stations::-webkit-scrollbar {
    display: none;
  }

  .scroll-stations button {
    flex: none;
    padding: 0.45rem 0.75rem;
    font-size: 0.78rem;
  }

  .scroll-mount--foot {
    padding-top: 0.6rem;
  }
}
