/* ── Moments (templates/moments.html, static/inv-moments.js) ──────────
   One moment a screen, the page snapping from one to the next. The
   page's own scroll does it (not a box inside the page), so a phone's
   address bar folds away as on any page, and Page Down, the space bar and
   a remote's arrows move a whole moment. Each card is dark whatever the
   theme (.dark-surface): it is a screen for the work. Mobile first; wider
   screens give the label a column of its own. */

:root:has(#moments-feed:not([hidden])) {
  scroll-snap-type: y mandatory;
  scroll-padding-top: var(--moments-top, 64px);
}
/* The feed goes on as long as anyone scrolls, so a footer would never be
   reached; its links are in the header and the menu. */
:root:has(#moments-feed:not([hidden])) .footer { display: none; }

.moments { position: relative; }

.moment {
  position: relative;
  height: calc(100dvh - var(--moments-top, 64px));
  min-height: 22rem;
  scroll-snap-align: start;
  scroll-snap-stop: always;
  display: grid;
  grid-template: "stage" minmax(0, 1fr) / minmax(0, 1fr);
  overflow: hidden;
  background: var(--media-bg);
  color: var(--on-media);
  contain: layout paint;
}
.moment:focus-visible { outline: 3px solid var(--focus-ring); outline-offset: -3px; }

.moment-stage {
  grid-area: stage;
  position: relative;
  display: grid;
  place-items: center;
  min-height: 0;
  overflow: hidden;
}
.moment-still {
  grid-area: 1 / 1;
  /* Positioned, so it paints over the glow (positioned too) behind it. */
  position: relative;
  width: 100%;
  height: 100%;
  object-fit: contain;
}
/* The same picture, blurred and dim, fills the bars around it. */
.moment-glow {
  position: absolute;
  inset: -10%;
  width: 120%;
  height: 120%;
  object-fit: cover;
  filter: blur(40px) brightness(0.45);
  pointer-events: none;
}
.moment-player { position: absolute; inset: 0; }
.moment .inv-player { width: 100%; height: 100%; max-height: none; aspect-ratio: auto; }

/* Sound: a square of the work's art, or its initial where it has none. */
.moment-cover {
  position: relative;
  width: min(68vw, 46dvh, 22rem);
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: var(--radius-lg);
  box-shadow: 0 24px 60px oklch(0 0 0 / 0.55);
}
.moment-initial {
  display: grid;
  place-items: center;
  font-family: var(--font-serif);
  font-size: clamp(3rem, 14vw, 7rem);
  background: linear-gradient(135deg, oklch(0.42 0.12 var(--hue, 277)), oklch(0.24 0.06 var(--hue, 277)));
  color: var(--on-media);
}

/* Art: a detail. Where the museum served the region, it is the picture;
   otherwise the whole picture is framed on it (the frame has the
   region's shape, the picture is sized and moved so the region fills it). */
.moment-frame {
  position: relative;
  overflow: hidden;
  max-width: 100%;
  max-height: 100%;
  width: 100%;
  aspect-ratio: var(--shape, 3 / 4);
}
@supports (width: 1cqw) {
  .moment-stage { container-type: size; }
  .moment-frame { width: min(100cqw, calc(100cqh * var(--shape-n, 0.75))); }
}
.moment-frame img {
  position: absolute;
  width: calc(100% / var(--rw, 1));
  height: auto;
  left: calc(-100% * var(--rx, 0) / var(--rw, 1));
  top: calc(-100% * var(--ry, 0) / var(--rh, 1));
  max-width: none;
}
.moment-frame--cropped img { position: static; width: 100%; height: 100%; object-fit: cover; }
@media (prefers-reduced-motion: no-preference) {
  .moment.is-active .moment-frame { animation: moment-drift var(--d, 20s) var(--ease-in-out-smooth) infinite alternate both; }
}
@keyframes moment-drift {
  from { transform: scale(1); }
  to { transform: scale(1.07) translate(-1.2%, -0.8%); }
}

/* A book: its passage, to read. The label sits under it, not over it. */
.moment--text { grid-template: "stage" minmax(0, 1fr) "info" auto / minmax(0, 1fr); }
/* (Its first lines start below the sound button.) */
.moment--text .moment-stage { place-items: start center; overflow-y: auto; padding: calc(3.75rem + 2vh) var(--gutter) 0; }
.moment--text .moment-stage:focus-visible { outline: 3px solid var(--focus-ring); outline-offset: -3px; }
.moment-passage {
  max-width: 34rem;
  font-family: var(--font-serif);
  font-size: var(--step-1);
  line-height: 1.6;
  color: var(--on-media);
}
.moment-passage p { margin: 0 0 1em; }
.moment-passage-from { font-family: var(--font-display); font-size: var(--step--1); color: var(--on-media-muted); margin-bottom: 0.75rem; }
.moment--text .moment-info { grid-area: info; background: none; padding-top: 0.5rem; }

/* What the moment is, over the foot of the picture. */
.moment-info {
  grid-area: stage;
  align-self: end;
  position: relative;
  z-index: 2;
  padding: 3rem var(--gutter) max(1.1rem, env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--scrim-strong) 55%, transparent);
  pointer-events: none;
}
.moment-info > * { max-width: 40rem; pointer-events: auto; }
.moment-kicker { margin: 0; font-size: var(--step--1); color: var(--on-media-muted); }
.moment-title { margin: 0.15rem 0 0.1rem; font-family: var(--font-display); font-size: var(--step-3); line-height: 1.12; font-weight: 700; }
.moment-part, .moment-by { margin: 0.05rem 0; color: var(--on-media-muted); font-size: var(--step-0); }
/* Some archives' statements run to a paragraph: three lines here, the
   whole of it on the work's own page. */
.moment-prov {
  margin: 0.35rem 0 0;
  font-size: var(--step--2);
  color: var(--on-media-muted);
  line-height: 1.45;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  overflow: hidden;
}
.moment-licence {
  display: inline-block;
  margin-right: 0.4rem;
  padding: 0.05rem 0.5rem;
  border: 1px solid var(--glass-border);
  border-radius: 999px;
  background: var(--glass);
  color: var(--on-media);
}
.moment-actions { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 0.5rem; margin-top: 0.75rem; }
/* Why this moment, in a line. */
.moment-why { margin: 0.45rem 0 0; font-size: var(--step--1); color: var(--on-media); }
.moment-go { min-height: 2.75rem; }
.moment-listen {
  min-height: 2.75rem;
  padding: 0.4rem 0.9rem;
  border-radius: 999px;
  border: 1px solid var(--glass-border);
  background: var(--glass);
  color: var(--on-media);
  font: inherit;
  cursor: pointer;
}
.moment-listen:hover { background: var(--glass-hover); }

/* Less of this: the card's tags, each a toggle that mutes it, in every mode. */
.moment-mute > summary { display: inline-flex; align-items: center; list-style: none; }
.moment-mute > summary::-webkit-details-marker { display: none; }
.moment-mute > summary::after { content: "…"; }
.moment-mute[open] > summary { background: var(--glass-hover); }
.moment-tags { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.5rem; }
.moment-tags .moment-listen[aria-pressed="true"] { text-decoration: line-through; background: var(--scrim-strong); }
.moment-tags .moment-listen[aria-pressed="true"]::after { content: " · muted"; text-decoration: none; display: inline-block; margin-inline-start: 0.25em; }

/* How far through the moment, along its top edge. */
.moment-progress {
  position: absolute;
  inset: 0 0 auto;
  height: 3px;
  z-index: 3;
  background: var(--glass);
  pointer-events: none;
}
.moment-progress span {
  display: block;
  height: 100%;
  background: var(--on-media);
  transform: scaleX(var(--p, 0));
  transform-origin: left;
}

/* Before anything plays, and on a moment waiting for a press: Play. */
.moment-start {
  position: absolute;
  z-index: 3;
  inset: 0;
  margin: auto;
  width: max-content;
  height: max-content;
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.8rem 1.4rem;
  border-radius: 999px;
  border: 1px solid var(--glass-border);
  background: var(--scrim);
  backdrop-filter: blur(8px);
  color: var(--on-media);
  font: inherit;
  font-size: var(--step-1);
  font-weight: 600;
  cursor: pointer;
}
.moment-start .icon { width: 1.4em; height: 1.4em; }
.moments.is-flowing:not(.is-waiting) .moment-start, .moment.is-playing .moment-start { display: none; }
.moment-trouble { position: absolute; z-index: 3; inset: auto var(--gutter) 45%; text-align: center; color: var(--on-media); }

/* Sound and the panel, over the feed. */
.moments-bar {
  position: fixed;
  z-index: 50;
  top: calc(var(--moments-top, 64px) + 0.75rem);
  right: var(--gutter);
  display: flex;
  gap: 0.5rem;
  background: none;
}
.moments-sound {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  min-height: 2.75rem;
  padding: 0.4rem 0.9rem;
  border-radius: 999px;
  border: 1px solid var(--glass-border);
  background: var(--scrim);
  backdrop-filter: blur(8px);
  color: var(--on-media);
  font: inherit;
  cursor: pointer;
}
.moments-sound .icon { width: 1.2em; height: 1.2em; }
/* A phone's narrow bar: the panel's button is its icon, named for screen readers. */
@media (max-width: 420px) {
  .moments-tune .moments-sound-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
}
/* Browsers without popovers keep the panel's controls in /settings. */
@supports not selector(:popover-open) { .moments-tune { display: none; } }

.moments-status:empty { display: none; }
.moments-status { padding: 2rem var(--gutter); text-align: center; color: var(--text-muted); }
/* Once the cards are there, what the status says is for screen readers. */
#moments-feed[aria-busy="false"] ~ .moments-status { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* Your feed: the aim, the switch, this visit, breadth (inv-taste.js). */
.moments-panel {
  display: none;
  position: fixed;
  inset: calc(var(--moments-top, 64px) + 4.25rem) var(--gutter) auto auto;
  margin: 0;
  width: min(27rem, calc(100vw - 2 * var(--gutter)));
  max-height: calc(100dvh - var(--moments-top, 64px) - 5.5rem);
  overflow-y: auto;
  padding: 1rem 1.2rem 1.2rem;
  border-radius: var(--radius-lg);
  border: 1px solid var(--glass-border);
  background: var(--scrim-strong);
  backdrop-filter: blur(12px);
  color: var(--on-media);
}
.moments-panel:popover-open { display: block; }
.moments-panel-h { margin: 0 0 0.25rem; font-size: var(--step-1); }
.moments-panel a { color: var(--accent-text); }

/* The end of a set: a screen of its own, where the feed stops. */
.moments-end {
  height: calc(100dvh - var(--moments-top, 64px));
  min-height: 22rem;
  scroll-snap-align: start;
  scroll-snap-stop: always;
  display: grid;
  place-items: center;
  padding: 0 var(--gutter);
  background: var(--media-bg);
  color: var(--on-media);
}
.moments-end[hidden] { display: none; }
.moments-end-inner { max-width: 32rem; }
.moments-end-text { margin: 0 0 1rem; font-size: var(--step-1); line-height: 1.45; }
/* This visit, as this browser counted it: three plain figures. */
.moments-end-visit { display: flex; flex-wrap: wrap; gap: 0.5rem 1.75rem; margin: 0 0 0.4rem; }
.moments-end-visit > div { display: flex; flex-direction: column-reverse; }
.moments-end-visit dt { font-size: var(--step--1); color: var(--on-media-muted); }
.moments-end-visit dd { margin: 0; font-size: var(--step-1); font-weight: 600; font-variant-numeric: tabular-nums; }
.moments-end-note { margin: 0 0 1.25rem; font-size: var(--step--1); color: var(--on-media-muted); }
.moments-end-actions { display: flex; flex-wrap: wrap; gap: 0.6rem; }
.moments-end.is-stopped #moments-stop { display: none; }

/* Without script: the moments as a list of links. */
.moments-plain { padding: 1.5rem var(--gutter) 3rem; }
.moments-lede { max-width: 40rem; color: var(--text-muted); }
.moments-list { list-style: none; margin: 1rem 0; padding: 0; display: grid; gap: 1rem; }
.moments-row { display: flex; gap: 1rem; align-items: flex-start; }
.moments-row-art { width: 96px; height: 96px; object-fit: cover; border-radius: var(--radius); flex: none; }
.moments-kicker { margin: 0; font-size: var(--step--1); color: var(--text-muted); }
.moments-row-title { margin: 0.1rem 0; font-size: var(--step-1); }
.moments-row-part, .moments-row-by, .moments-row-prov { margin: 0.1rem 0; color: var(--text-muted); font-size: var(--step--1); }
.moments-row-go { color: var(--accent-text); }

/* A wider screen: the label takes a column beside the picture. */
@media (min-width: 900px) and (min-aspect-ratio: 4 / 3) {
  .moment:not(.moment--text) { grid-template: "stage info" minmax(0, 1fr) / minmax(0, 1fr) minmax(18rem, 26rem); }
  /* Centred while it fits; from the top, below the bar, once it does not
     (a card's mute list open), scrolling if it must. */
  .moment:not(.moment--text) .moment-info {
    grid-area: info;
    align-self: safe center;
    max-height: 100%;
    overflow-y: auto;
    background: none;
    padding: 4.5rem var(--gutter) 2rem 1.5rem;
  }
  :root[data-tv] .moment:not(.moment--text) .moment-info { padding-top: 6rem; }
}

/* TV: read from across the room. */
:root[data-tv] .moment-title { font-size: var(--step-4); }
:root[data-tv] .moment-part, :root[data-tv] .moment-by { font-size: var(--step-1); }
:root[data-tv] .moment-prov { font-size: var(--step--1); }
:root[data-tv] .moment-passage { font-size: var(--step-2); }
:root[data-tv] .moment-why { font-size: var(--step-0); }
:root[data-tv] .moments-end-text { font-size: var(--step-2); }
:root[data-tv] .moments-panel { width: min(34rem, calc(100vw - 2 * var(--gutter))); }
