/* The café jukebox (src/jukebox-ui.js): a small TV in the bottom-left corner
   of the shared café, where Grove's radio usually sits. YouTube needs the
   player visible and at least 200 x 200 pixels, so the screen keeps a 16:9
   frame of at least 200 pixels tall and nothing of ours is drawn over it.

   Look (UX-005 A5): the pixel frame from src/ui-components.css. The card rests
   (.pxf) in the corner and is raised (.pxf--raised) while the line is open; its
   buttons are the Button component ("Add a song" the one primary, × a 44 px icon
   button, Skip / Quiet / Boost pressed toggles). Type: Pixelify 16 / 14, Outfit 14 / 12.
   On a phone with nothing playing the card folds to its header (one 44 px row), so
   the café floor stays in view; "Add a song" opens the line as a full-screen sheet. */
.jukebox {
  position: fixed;
  z-index: 45; /* above side sheets and chat, below the dungeon layer, toasts and true modals */
  left: var(--hud-band-side);
  bottom: var(--hud-edge);
  display: grid;
  gap: var(--ui-s-2);
  box-sizing: border-box;
  --jukebox-w: 384px; /* the card's width, set once (the short-screen scroll padding uses it too) */
  width: var(--jukebox-w);
  max-height: calc(100dvh - 2 * var(--hud-edge));
  /* 16 at the bottom: the last line (the legal one) keeps 12 clear of the frame's drawn edge. */
  padding: var(--ui-s-3) var(--ui-s-3) var(--ui-s-4);
  overflow-y: auto;
  color: var(--ui-ink);
  font-family: var(--ui-font-body);
}
.jukebox[hidden], .jukebox-pill[hidden], .jukebox-more[hidden], .jukebox-results[hidden], .jukebox-note[hidden], .jukebox-resume[hidden], .jukebox-progress[hidden], .jukebox-idle[hidden], .jukebox-skip[hidden], .jukebox-line-toggle[hidden] { display: none; }
body.jukebox-on #music-dock { display: none; }

.jukebox-head { display: flex; align-items: center; gap: var(--ui-s-2); min-height: var(--ui-target); }
.jukebox-glyph { --ico: 28px; color: var(--ui-accent); }
.jukebox-title { display: grid; flex: 1; gap: var(--ui-s-1); min-width: 0; line-height: 1; }
.jukebox-title strong { overflow: hidden; font-family: var(--ui-font-display); font-size: var(--ui-fs-16); font-weight: 600; white-space: nowrap; text-overflow: ellipsis; }
.jukebox-sub { overflow: hidden; color: var(--ui-ink-muted); font-size: var(--ui-fs-12); white-space: nowrap; text-overflow: ellipsis; }
.jukebox-head .btn { flex: none; min-height: var(--ui-target); }
.jukebox-hide { width: var(--ui-target); }
.jukebox-hide .ico { --ico: 14px; }

/* The screen: 16:9, never under 200 pixels tall; a dark cocoa well with a 1 UI px edge. */
.jukebox-screen {
  position: relative;
  width: 100%;
  min-width: 200px;
  aspect-ratio: 16 / 9;
  min-height: 200px;
  overflow: hidden;
  background: var(--ui-line-deep);
  border: 0;
  border-radius: 0;
  box-shadow: var(--ui-frame-edge);
}
.jukebox-screen > .jukebox-player, .jukebox-screen > iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.jukebox-idle { position: absolute; inset: 0; display: grid; place-content: center; gap: var(--ui-s-2); padding: var(--ui-s-4); color: var(--ui-ink-on-dark); text-align: center; font-size: var(--ui-fs-14); line-height: 1.4; }
.jukebox-idle strong { font-family: var(--ui-font-display); font-size: var(--ui-fs-16); font-weight: 600; }
.jukebox.is-idle .jukebox-screen { min-height: 120px; aspect-ratio: auto; }
.jukebox-note { margin: 0; padding: var(--ui-s-2) var(--ui-s-3); background: var(--ui-surface-sunk); font-size: var(--ui-fs-14); line-height: 1.4; }
.jukebox-resume { justify-self: start; }

.jukebox-now { display: grid; gap: var(--ui-s-1); min-width: 0; }
.jukebox-now-title { margin: 0; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; font-family: var(--ui-font-display); font-size: var(--ui-fs-14); font-weight: 600; line-height: 1.25; }
.jukebox-now-meta { margin: 0; overflow: hidden; color: var(--ui-ink-muted); font-size: var(--ui-fs-12); white-space: nowrap; text-overflow: ellipsis; }
/* Progress: a 2 UI px groove, the played part in the accent (no radius). */
.jukebox-progress { height: calc(var(--ui-px) * 2); overflow: hidden; background: var(--ui-surface-sunk); }
.jukebox-progress > span { display: block; width: 0; height: 100%; background: var(--ui-accent); transition: width 1s linear; }

.jukebox-actions { display: flex; align-items: center; gap: var(--ui-s-2); flex-wrap: wrap; }
.jukebox-volume { display: flex; align-items: center; flex: 1 1 88px; min-width: 80px; margin: 0; }
.jukebox-volume input { width: 100%; margin: 0; accent-color: var(--ui-accent); cursor: pointer; }
.jukebox-volume input:focus-visible { outline: var(--ui-focus-ring-w) solid var(--ui-focus-ring); outline-offset: calc(var(--ui-px) * 2); }

/* The line: under a 1 UI px shade rule. */
.jukebox-more { display: grid; gap: var(--ui-s-2); max-height: max(220px, calc(100dvh - 460px)); padding-top: var(--ui-s-3); overflow-y: auto; box-shadow: inset 0 var(--ui-px) 0 0 var(--ui-surface-shade); }
.jukebox-add { display: grid; gap: var(--ui-s-1); }
.jukebox-add-label { margin: 0; color: var(--ui-ink); font-family: var(--ui-font-display); font-size: var(--ui-fs-14); font-weight: 600; }
.jukebox-add-row { display: flex; gap: var(--ui-s-2); }
/* The Input component: a flat frame with the bevel inverted. */
.jukebox #jukebox-input {
  flex: 1;
  box-sizing: border-box;
  width: auto;
  min-width: 0;
  height: 40px;
  margin: 0;
  padding: 0 var(--ui-s-3);
  color: var(--ui-input-ink);
  background: var(--ui-frame-fill);
  border: 0;
  border-radius: 0;
  box-shadow:
    inset var(--ui-px) var(--ui-px) 0 0 var(--ui-surface-shade),
    inset calc(var(--ui-px) * -1) calc(var(--ui-px) * -1) 0 0 var(--ui-surface-hi),
    var(--ui-frame-edge);
  font-family: var(--ui-font-body);
  font-size: var(--ui-fs-16);
  line-height: 1;
}
.jukebox #jukebox-input::placeholder { color: var(--ui-ink-muted); opacity: 1; }
.jukebox #jukebox-input:focus-visible { outline: var(--ui-focus-ring-w) solid var(--ui-focus-ring); outline-offset: calc(var(--ui-px) * 2); }
.jukebox #jukebox-input:disabled { background: var(--ui-disabled-bg); color: var(--ui-disabled-ink); cursor: not-allowed; }
.jukebox-add-row .btn { flex: none; }
.jukebox-add-note { margin: 0; color: var(--ui-ink-muted); font-size: var(--ui-fs-12); line-height: 1.4; }
.jukebox-results, .jukebox-line { display: grid; gap: var(--ui-s-2); margin: 0; padding: 0; list-style: none; }
/* Songs and search results: flat pixel frames; yours edged in the accent, a boosted one in gold. */
.jukebox-result, .jukebox-song { display: flex; align-items: center; gap: var(--ui-s-2); padding: var(--ui-s-2); }
.jukebox-result-copy, .jukebox-song-copy { display: grid; flex: 1; gap: var(--ui-px); min-width: 0; line-height: 1.25; }
.jukebox-result-copy strong, .jukebox-song-copy strong { overflow: hidden; font-size: var(--ui-fs-14); font-weight: 600; white-space: nowrap; text-overflow: ellipsis; }
.jukebox-result-copy small, .jukebox-song-copy small { overflow: hidden; color: var(--ui-ink-muted); font-size: var(--ui-fs-12); white-space: nowrap; text-overflow: ellipsis; }
.jukebox-song.mine { --f-edge: var(--ui-accent); }
.jukebox-song.jumping { --f-edge: var(--ui-coin-deep); }
.jukebox-pos { display: grid; place-items: center; width: var(--ui-s-5); height: var(--ui-s-5); flex: none; background: var(--ui-surface-sunk); box-shadow: 0 0 0 var(--ui-px) var(--ui-line); font-size: var(--ui-fs-12); font-weight: 700; font-variant-numeric: tabular-nums; }
.jukebox-song-tools { display: flex; gap: var(--ui-s-1); flex: none; }
.jukebox-empty { padding: var(--ui-s-2); color: var(--ui-ink-muted); font-size: var(--ui-fs-14); }
.jukebox-line-head { margin: var(--ui-s-1) 0 0; font-family: var(--ui-font-display); font-size: var(--ui-fs-14); font-weight: 600; }
.jukebox-rules { margin: 0; color: var(--ui-ink-muted); font-size: var(--ui-fs-12); line-height: 1.4; }
.jukebox-credits { margin: 0; color: var(--ui-ink-muted); font-size: var(--ui-fs-12); line-height: 1.4; }
.jukebox-credits a { color: inherit; }

/* Hidden for you: a 44 px HUD card 12 px above the radio brings it back. */
.jukebox-pill {
  position: fixed;
  z-index: var(--z-hud);
  left: var(--hud-band-side);
  bottom: calc(var(--hud-edge) + var(--ui-target) + var(--ui-s-3));
  max-width: min(360px, calc(100vw - 2 * var(--hud-band-side)));
}
.jukebox-pill .ico { color: var(--ui-accent); }
.jukebox-pill-text { min-width: 0; overflow: hidden; font-family: var(--ui-font-display); font-size: var(--ui-fs-14); font-weight: 600; white-space: nowrap; text-overflow: ellipsis; }

@media (prefers-reduced-motion: reduce) {
  .jukebox-progress > span { transition: none; }
}

/* Narrower desktops: the dock reaches the corner, so the screen (and its chip) sits above it. */
@media (max-width: 1240px) and (min-width: 721px) {
  .jukebox { bottom: calc(var(--hud-edge) + var(--dock-h) + var(--ui-s-3)); max-height: calc(100dvh - var(--dock-h) - 3 * var(--hud-edge)); }
  .jukebox-pill { bottom: calc(var(--hud-edge) + var(--dock-h) + var(--ui-s-3)); }
}
/* Taller desktops, where the top band is one row: at its tallest (the line open, a song on)
   the card ends 12 under that row, so it never touches the place card and door; it scrolls
   instead (UX-319). */
@media (min-width: 1241px) and (min-height: 641px) {
  .jukebox { max-height: calc(100dvh - var(--hud-edge) - var(--hud-band-top) - var(--hud-h) - var(--ui-s-3)); }
}
/* Narrower desktops: the room bar sits on the band's second row and reaches left of the
   card's right edge (x 375 < 400 at 1024), so the card ends 12 under both rows. */
@media (max-width: 1240px) and (min-width: 901px) and (min-height: 641px) {
  .jukebox { max-height: calc(100dvh - var(--hud-edge) - var(--dock-h) - var(--ui-s-3) - var(--hud-band-top) - 2 * var(--hud-h) - 2 * var(--ui-s-3)); }
}

/* Short wide screens (a small laptop, a phone on its side; UX-302): there is no room for the
   card beside the café's room actions, minimap and place card, so it starts folded to a
   compact chip beside the radio (Grove's radio plays while it is folded, so its button
   stays), level with the dock and ending 8 px before it (src/jukebox-ui.js fitChip). With
   a song on, the chip says "Listen · <song>" behind a live dot. Open, the card is the one
   panel (raised): whatever it would half-cover steps aside (the place card and door, the
   quest strip, the room actions, the hint, the arrival card) and the minimap folds out of
   its way (src/minimap.js); × or Escape folds it back. */
@media (min-width: 721px) and (max-height: 640px) {
  body.jukebox-chip .jukebox-pill {
    left: var(--chip-left, calc(var(--hud-band-side) + var(--ui-target) + var(--ui-s-2)));
    bottom: var(--hud-edge);
    max-width: var(--chip-max, min(360px, 50vw));
  }
  body.jukebox-chip .jukebox-pill.is-tight { padding: 0 var(--ui-s-2); }
  body.jukebox-chip .jukebox-pill.is-tight > .ico, body.jukebox-chip .jukebox-pill.is-tight .jukebox-pill-song { display: none; }
  body.jukebox-panel :is(#cafe-shortcuts, .world-guide, .arrival-help) { visibility: hidden; }
  /* The open line doesn't scroll inside the card (UX-308/309): nested in the capped card it
     shrank to a sliver and cut the Add-a-song form, so the card is the one scroller, as on phones. */
  .jukebox.is-expanded .jukebox-more { max-height: none; overflow: visible; }
  /* Scrolled down to Add a song, the YouTube screen stays pinned at the card's top, so the
     song keeps playing (it pauses whenever its screen is out of view) (UX-308 N3). Under it,
     a strip of the card's own fill as deep as the gap below the screen, so what scrolls up
     ends at a straight line instead of showing a half-cut line or a sliver of the progress
     bar (UX-317). At rest the strip lies on the gap, the same fill, so it doesn't show. */
  .jukebox.is-panel.is-expanded .jukebox-screen { position: sticky; top: 0; z-index: 1; box-shadow: var(--ui-frame-edge), 0 var(--ui-s-2) 0 0 var(--f-fill); }
  /* Focus, a scroll into view or a snap lands content below the pinned screen and its strip
     (the card's 12 top padding, the screen at 16:9 of the card's inner width, never under 200,
     and the 8 strip), not under them. */
  .jukebox.is-panel.is-expanded { scroll-padding-top: calc(var(--ui-s-3) + max(200px, (var(--jukebox-w) - 2 * var(--ui-s-3)) * 9 / 16) + var(--ui-s-2)); scroll-snap-type: y mandatory; }
  /* The card rests at its top (header, screen), with the song (title, progress, buttons), with
     its buttons (Skip, Quiet, volume: on a phone on its side the song and buttons don't fit
     under the screen together), or with the line's section ("Add a song" its first line) right
     under that strip, never in between, so no half-cut song line or row of buttons shows under
     the screen (UX-317). Inside the section (taller than the view) it scrolls freely. */
  .jukebox.is-panel.is-expanded > :is(.jukebox-head, .jukebox-now, .jukebox-actions, .jukebox-more) { scroll-snap-align: start; }
}
/* UX-332: 400 tall or less, the pinned screen (200 at least) leaves the song one line under it:
   its title is clamped to one line (as on phones), so a second line is never cut by the screen. */
@media (min-width: 721px) and (max-height: 400px) {
  .jukebox-now-title { -webkit-line-clamp: 1; }
}
/* A small laptop: the open card (it scrolls, the line with it) ends under the top band's
   two rows, so the place card, the quest strip and the room bar stay whole beside it. */
@media (min-width: 721px) and (min-height: 561px) and (max-height: 640px) {
  .jukebox { max-height: calc(100dvh - var(--dock-h) - 3 * var(--hud-edge) - var(--hud-band-top) - 2 * var(--hud-h) - var(--ui-s-3) - var(--ui-s-2)); }
}
/* A phone on its side: the open card reaches the top band, so the place card, door and quest
   strip step aside too (on a small laptop the card ends below them). */
@media (min-width: 721px) and (max-height: 560px) {
  body.jukebox-panel :is(.hud-left, .next-step-bar) { visibility: hidden; }
  /* An open sheet there runs top to bottom and the radio's button and the dock step aside
     (src/shell.css): the chip beside them steps aside too, not left alone in the corner. */
  body.sheet-open.jukebox-chip .jukebox-pill { visibility: hidden; }
}
/* The live dot: an accent square, still (no pulse), so it reads the same with reduced motion. */
.jukebox-live { flex: none; width: var(--ui-s-2); height: var(--ui-s-2); background: var(--ui-success); box-shadow: 0 0 0 var(--ui-px) var(--ui-line); }
.jukebox-live[hidden] { display: none; }

/* Phones: the card spans the 16 px gutters above the dock and everything there moves up;
   it sits under bottom sheets, so opening one pauses the café music for you. */
@media (max-width: 720px) {
  .jukebox { z-index: 35; left: var(--hud-band-side); right: var(--hud-band-side); bottom: calc(var(--hud-edge) + var(--dock-h) + var(--ui-s-2)); width: auto; padding: var(--ui-s-2); }
  .jukebox-now-title { -webkit-line-clamp: 1; }
  /* At rest with nothing playing: only the header row (title, "Add a song", ×). Quiet, the
     volume and the line are in the sheet "Add a song" opens; the header names a quiet room. */
  .jukebox.is-idle:not(.is-expanded) :is(.jukebox-screen, .jukebox-now, .jukebox-actions) { display: none; }
  body.jukebox-on :is(.chat-toggle) { bottom: calc(var(--hud-edge) + var(--dock-h) + var(--ui-s-4) + var(--jukebox-h, 0px)); }
  body.jukebox-on :is(.status-stack, .world-guide) { bottom: calc(var(--hud-edge) + var(--dock-h) + 72px + var(--jukebox-h, 0px)); }
  body.jukebox-on .chat-panel { bottom: calc(var(--hud-edge) + var(--dock-h) + 72px + var(--jukebox-h, 0px)); height: min(420px, calc(100dvh - 260px - var(--jukebox-h, 0px))); }
  body.jukebox-on #touch-controls:not([hidden]) { bottom: calc(var(--hud-edge) + var(--dock-h) + var(--ui-s-4) + var(--jukebox-h, 0px)); }
  .jukebox-pill { bottom: calc(var(--hud-edge) + var(--dock-h) + 64px); }
  /* The line on a phone: the whole screen (a sheet, so no frame), the player pinned at the top. */
  .jukebox.is-expanded { z-index: 46; inset: 0; bottom: 0; max-height: none; padding: var(--ui-s-3) var(--ui-s-4) calc(var(--ui-s-4) + env(safe-area-inset-bottom)); box-shadow: none; align-content: start; }
  .jukebox.is-expanded .jukebox-screen { position: sticky; top: 0; z-index: 1; }
  .jukebox.is-expanded .jukebox-more { max-height: none; overflow: visible; }
  .jukebox .btn--sm { min-height: var(--ui-target); }
}

/* Messages never land on the screen: beside it on wide screens, under the
   pinned player on a phone with the line open. */
@media (min-width: 721px) {
  body.jukebox-on .toast { left: calc(var(--hud-band-side) + 400px + (100vw - var(--hud-band-side) - 400px) / 2); max-width: min(560px, calc(100vw - 400px - 2 * var(--hud-band-side) - 16px)); }
}
@media (max-width: 720px) {
  html body.jukebox-open.jukebox-on .toast { top: auto; bottom: calc(var(--ui-s-3) + env(safe-area-inset-bottom)); }
}
