/* Music (music.js; Felix's brief "persistent music feature", his notes on the preview, 20 Nov 2026, and from his iPhone,
   21 Nov; CONTRACT.md §19.8): the top bar's control (Loading, then the song's gem, "Music" and a one-tap play / pause),
   and the panel. The house glass (.xp-glass, host.css) at the phones' menu
   values; Funnel Sans for the words, Plex Mono for the state. Spotify's player inside is shown as Spotify ships it (the
   single-song embed, 80 px, its own colours and branding): nothing here crops, covers or repaints it; until it is shown,
   a blank frosted pane holds its place and every Spotify frame is hidden (never covered).
   The panel is ONE element for the life of the page: open / closed and the desktop / phone layouts are CSS on it (an
   iframe moved in the DOM reloads, display: none can drop its layout). Closed, it is hidden, inert and still playing. */

/* without the music config (registry.js `music`) both stay hidden; music.js shows them */
.xp-music-wrap[hidden], .xp-music[hidden] { display: none !important; }

/* ---------- the control in the top bar: a quieter capsule beside the journeys' (ivory hairline; gold while playing) ---------- */
.xp-music-wrap { position: relative; display: flex; align-items: center; min-height: 44px; margin: 0 .6rem 0 auto; border-radius: 22px; }
.xm-tg-glass, .xm-tg-frost { position: absolute; inset: 0; z-index: 0; pointer-events: none; }
.xp-music-wrap > .xp-glass { --glass-radius: 22px; --glass-hair: 238, 235, 227; --glass-hair-a: .16; --glass-shadow: 0 10px 24px -14px rgba(0, 0, 0, .7); }
.xp-music-wrap[data-state="playing"] > .xp-glass, .xp-music-wrap[data-open] > .xp-glass { --glass-hair: 216, 173, 85; --glass-hair-a: .5; }
.xm-tg-frost { opacity: 0; transition: opacity 320ms var(--ease-out); }
.xp-music-wrap:hover .xm-tg-frost, .xp-music-wrap:focus-within .xm-tg-frost, .xp-music-wrap[data-open] .xm-tg-frost { opacity: 1; }
.xp-music-tg { position: relative; z-index: 1; display: inline-flex; align-items: center; min-height: 44px; padding: 0 1.1rem; border-radius: 22px;
  font-size: clamp(.8125rem, .7rem + .2vw, .9375rem); font-weight: 500; letter-spacing: .015em; color: rgba(238, 235, 227, .8); white-space: nowrap; transition: color var(--t-ui) var(--ease-out); }
.xp-music-tg:hover, .xp-music-tg:focus-visible, .xp-music-tg[aria-expanded="true"] { color: var(--ivory); }
.xp-music-tg:focus-visible { outline-offset: -4px; border-radius: 22px; }
/* the gem slot (an empty gem's rim, the gems' own hexagon): Loading, a short gold line travelling the rim (still under
   reduced motion); Spotify unavailable, or a song whose gem is missing, the empty rim alone */
.xm-slot { display: none; flex: none; width: 20px; height: 20px; margin-right: .5rem; }
.xm-slot svg { display: block; width: 20px; height: 20px; overflow: visible; }
.xm-slot path { fill: none; stroke-linejoin: round; stroke-linecap: round; }
.xm-slot-rim { stroke: rgba(238, 235, 227, .3); stroke-width: 1.1; }
.xm-slot-run { stroke: var(--gold); stroke-width: 1.6; stroke-dasharray: 13 47; }
.xp-music-wrap:is([data-ctl="loading"], [data-ctl="off"]) .xm-slot, .xp-music-wrap[data-ctl="ready"]:not([data-mood]) .xm-slot { display: block; }
.xp-music-wrap:not([data-ctl="loading"]) .xm-slot-run { display: none; }
.xp-music-wrap:is([data-ctl="loading"], [data-ctl="off"]) .xp-music-tg .xm-gem { display: none; }
@media (prefers-reduced-motion: no-preference) {
  .xp-music-wrap[data-ctl="loading"] .xm-slot-run { animation: xm-trace 1.6s linear infinite; }
}
@keyframes xm-trace { to { stroke-dashoffset: -60; } }
/* the one-tap play / pause, from Ready on: inside the capsule, after the word (44 px, round) */
.xp-music-wrap[data-quick] .xp-music-tg { padding-right: .3rem; }
.xm-quick { position: relative; z-index: 1; display: grid; place-items: center; flex: none; width: 44px; height: 44px; border-radius: 50%; color: rgba(238, 235, 227, .85);
  transition: color var(--t-ui) var(--ease-out); }
.xm-quick[hidden] { display: none; }
.xm-quick:hover, .xm-quick:focus-visible { color: var(--gold); }
.xm-quick:focus-visible { outline-offset: -6px; border-radius: 50%; }
.xm-quick svg { width: 11px; height: 11px; }

/* play / pause glyphs (the quick control and the panel's): the triangle filled, the pause two strokes */
.xm-i-play { fill: currentColor; }
.xm-i-pause { display: none; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; }
[data-act="pause"] > .xm-i-play { display: none; }
[data-act="pause"] > .xm-i-pause { display: block; }

/* the playing mark: three short gold bars before the word. Absent until Spotify confirms playback; they move only while it
   plays (and never under reduced motion); paused, they hold still in ink */
.xm-bars { display: inline-flex; align-items: flex-end; justify-content: space-between; flex: none; width: 0; height: 11px; margin-right: 0; overflow: hidden; opacity: 0;
  transition: width var(--t-ui) var(--ease-out), margin var(--t-ui) var(--ease-out), opacity var(--t-ui) var(--ease-out); }
.xm-bars i { width: 2px; height: 100%; border-radius: 1px; background: var(--gold); transform-origin: 50% 100%; transform: scaleY(.5); }
.xm-bars i:nth-child(2) { transform: scaleY(.85); }
.xm-bars i:nth-child(3) { transform: scaleY(.65); }
:is([data-state="playing"], [data-state="paused"]) .xm-bars { width: 10px; margin-right: .55rem; opacity: 1; }
[data-state="paused"] .xm-bars i { background: var(--ink-3); }
@media (prefers-reduced-motion: no-preference) {
  [data-state="playing"] .xm-bars i { animation: xm-eq 900ms ease-in-out infinite alternate; }
  [data-state="playing"] .xm-bars i:nth-child(2) { animation-duration: 640ms; animation-delay: -300ms; }
  [data-state="playing"] .xm-bars i:nth-child(3) { animation-duration: 780ms; animation-delay: -520ms; }
}
@keyframes xm-eq { from { transform: scaleY(.3); } to { transform: scaleY(1); } }

/* the song's mood gem (Moodstream's, 96 px copies; decorative: the mood is said in words). In the top bar it takes the
   bars' place: 20 px, still until Spotify confirms playback, a slow breathe while it plays (never under reduced
   motion), quieter while paused. In the panel: 30 px before the mood's word, the state after a small dot. */
.xm-gem { display: block; flex: none; object-fit: contain; }
.xm-gem[hidden], .xm-mood[hidden] { display: none; }
.xp-music-tg .xm-gem { width: 20px; height: 20px; margin-right: .5rem; transition: opacity var(--t-ui) var(--ease-out); }
[data-mood] .xm-bars { display: none; }
.xp-music-wrap[data-state="paused"] .xp-music-tg .xm-gem { opacity: .62; }
@media (prefers-reduced-motion: no-preference) {
  .xp-music-wrap[data-state="playing"] .xp-music-tg .xm-gem { animation: xm-breathe 2.8s ease-in-out infinite; }
}
@keyframes xm-breathe { 0%, 100% { transform: scale(.92); filter: brightness(.94); } 50% { transform: scale(1.06); filter: brightness(1.16); } }
.xm-status .xm-gem { width: 30px; height: 30px; margin: -.45rem .55rem -.45rem -.1rem; }
.xm-mood { display: inline-flex; align-items: center; color: var(--ivory); }
.xm-mood::after { content: ""; width: 3px; height: 3px; margin: 0 .6rem; border-radius: 50%; background: var(--ink-3); }

/* ---------- the panel: under the top bar at the right (desktop), a sheet across the top (phones) ---------- */
.xp-music.xp-glass { position: fixed; z-index: 48; top: calc(var(--top) - .3rem); right: var(--margin); width: min(22rem, calc(100vw - 2 * var(--margin)));
  max-height: calc(100svh - var(--top) - 1rem); overflow-y: auto; overscroll-behavior: contain;
  display: grid; grid-template-columns: minmax(0, 1fr); gap: .85rem; padding: .9rem .9rem .85rem; color: var(--ivory); outline: none;
  --glass-radius: 22px; --glass-tint: 11, 12, 11; --glass-alpha: .76; --glass-solid: .96; --glass-blur: 26px; --glass-sat: 1.4; --glass-bright: .7; --glass-hair-a: .34;
  --glass-shadow: 0 24px 48px -20px rgba(0, 0, 0, .9), 0 8px 18px -8px rgba(0, 0, 0, .5);
  visibility: hidden; opacity: 0; transform: translateY(-6px) scale(.985); transform-origin: 100% 0;
  transition: opacity 200ms var(--ease-out), transform 260ms var(--ease-out), visibility 0s linear 260ms; }
.xp-music.xp-glass[data-open="1"] { visibility: visible; opacity: 1; transform: none; transition: opacity 220ms var(--ease-out), transform 300ms var(--ease-out), visibility 0s; }
/* focus moved into the panel on open: its gold edge says where focus is */
.xp-music.xp-glass:focus-visible { --glass-hair-a: .95; }

/* Spotify's single-song embed: 80 px tall, as wide as the panel (≥ 280 px, Spotify's minimum), its corners as Spotify's
   own embed code rounds them (12 px). Every Spotify frame is hidden (visibility, never covered) except the current song's
   once the panel is revealed (data-veil="0"); the next song's waits hidden. Under them, the same size and place: a blank
   frosted pane (the panel's glass already blurs: the pane is a lighter, bevelled sheet, no second backdrop blur). */
.xm-player { position: relative; min-width: 280px; height: 80px; border-radius: 12px; }
.xm-player iframe { position: absolute; inset: 0; z-index: 1; display: block; width: 100%; height: 80px; border: 0; border-radius: 12px; visibility: hidden; }
.xp-music[data-veil="0"] .xm-player iframe.xm-cur { visibility: inherit; }
.xm-ph { position: absolute; inset: 0; z-index: 0; border-radius: 12px;
  background: linear-gradient(115deg, rgba(238, 235, 227, .12) 0%, rgba(238, 235, 227, .055) 38%, rgba(238, 235, 227, .035) 62%, rgba(238, 235, 227, .075) 100%);
  box-shadow: inset 0 0 0 1px rgba(238, 235, 227, .14), inset 0 1px 0 rgba(255, 255, 255, .12), inset 0 -14px 26px -18px rgba(0, 0, 0, .55); }
/* veiled: the pane, Play and the one line; no state, no mood, no Skip */
.xp-music[data-veil="1"] .xm-status { display: none; }

/* under the player: the words (left) and Felix's two controls, Play / Pause and Skip (right) */
.xm-foot { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; column-gap: 1rem; padding: 0 .1rem; }
.xm-text { display: grid; gap: .4rem; min-width: 0; }
.xm-status { margin: 0; display: flex; align-items: center; font-family: var(--f-mono); font-size: var(--instrument); letter-spacing: var(--instrument-track); text-transform: uppercase; color: var(--ink-3); }
.xp-music[data-state="playing"] .xm-word { color: var(--gold); }
.xp-music[data-state="unavailable"] .xm-word { color: var(--ivory); }
.xm-hint { margin: 0; font-size: var(--ui); line-height: 1.45; color: var(--ink-2); }
.xm-hint[hidden] { display: none; }
.xm-open { justify-self: start; display: inline-flex; align-items: center; min-height: 32px; font-size: var(--ui); font-weight: 500; letter-spacing: .015em; color: var(--ink-2); text-decoration: none;
  text-decoration-thickness: 1px; text-underline-offset: .35em; transition: color var(--t-ui) var(--ease-out); }
.xm-open:hover, .xm-open:focus-visible { color: var(--ivory); text-decoration: underline; text-decoration-color: var(--gold); }
.xm-open[hidden] { display: none; }
.xm-ctl { display: flex; align-items: center; gap: .45rem; }
.xm-btn { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 50%; box-shadow: inset 0 0 0 1px rgba(238, 235, 227, .3); color: var(--ivory);
  transition: box-shadow var(--t-ui) var(--ease-out), background-color var(--t-ui) var(--ease-out), color var(--t-ui) var(--ease-out); }
.xm-btn:hover, .xm-btn:focus-visible { box-shadow: inset 0 0 0 1px rgba(216, 173, 85, .85); background-color: rgba(216, 173, 85, .08); }
.xm-btn:focus-visible { outline-offset: 2px; border-radius: 50%; }
.xm-btn[hidden] { display: none; }
.xm-btn svg { width: 12px; height: 12px; }
.xm-play[aria-pressed="true"] { box-shadow: inset 0 0 0 1px rgba(216, 173, 85, .6); }
.xm-skip .xm-i-tri { fill: currentColor; }
.xm-skip .xm-i-bar { fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; }
.xp-music[data-state="unavailable"] .xm-ctl { display: none; }
@media (pointer: coarse) { .xm-open { min-height: 44px; } }

/* ---------- phones (≤ 640 px, the menu's breakpoint): Music sits left of the journeys' pill; the sheet spans the top,
   under the bar, clear of the bottom bar (chapters · Next); swipes outside it still move the story ---------- */
@media (max-width: 640px) {
  .xp-music-wrap { margin-right: .5rem; }
  .xp-music-tg { padding: 0 1.05rem; font-size: .875rem; color: var(--ivory); }
  .xp-music-wrap[data-quick] .xp-music-tg { padding-right: .15rem; }
  .xp-music.xp-glass { left: var(--margin); right: var(--margin); width: auto; top: calc(var(--top) - .45rem); padding: .85rem .85rem .8rem; gap: .8rem; transform-origin: 50% 0;
    max-height: calc(100svh - var(--top) - 44px - 1.6rem - env(safe-area-inset-bottom)); }
}
/* landscape phones and small tablets (641–919 px): the bar also carries the name and the socials; the control drops its
   word (the gem or the traced rim, then play / pause; its name still says it all: "Music, loading", "Music, Thrill") */
@media (min-width: 641px) and (max-width: 919px) {
  .xp-music-tg { padding: 0 .8rem; }
  .xp-music-wrap[data-quick] .xp-music-tg { padding-right: .1rem; }
  .xp-music-tg .xm-tg-l { display: none; }   /* (the button's name carries it) */
  .xp-music-tg .xm-gem, .xm-slot { margin-right: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .xp-music.xp-glass { transform: none; transition: opacity 120ms linear, visibility 0s linear 120ms; }
  .xp-music.xp-glass[data-open="1"] { transition: opacity 120ms linear, visibility 0s; }
  .xm-tg-frost, .xm-bars, .xm-btn, .xm-quick, .xm-open, .xp-music-tg, .xm-gem { transition: none; }
  .xm-gem, .xm-slot-run { animation: none !important; }
}
@media (forced-colors: active) {
  .xm-bars i { background: CanvasText; forced-color-adjust: none; }
  [data-state="playing"] .xm-bars i { background: Highlight; }
  .xm-btn { border: 1px solid ButtonText; }
  .xm-open { color: LinkText; }
  .xp-music-tg, .xm-quick { color: ButtonText; }
  .xm-mood::after { background: CanvasText; forced-color-adjust: none; }
  .xm-slot-rim { stroke: CanvasText; }
  .xm-slot-run { stroke: Highlight; }
  .xm-ph { border: 1px solid CanvasText; }
}
