/*
 * hyd-radio.css - the music deck and its dock button.
 *
 * Styles #sound-deck (source picker, now-playing display, optional audio-file picker and one transport) and
 * #radio-dock-chip, the status-aware Music button. hyd-radio.js builds both and moves them between three hosts as
 * the route changes: the home desktop (deck on #web-desktop, chip in the dock), the player page (deck inside
 * .player-music-shelf, chip among the player actions) and the Places menu (chip beside the shell launcher).
 * The chip carries data-location (dock, player or menu) and data-radio-state; rules below key off both.
 *
 * Loaded after the shared desktop and player sheets, so same-specificity rules here win. Phone width is 620 px,
 * the desktop player layout starts at 621 px, and coarse pointers get 44 px touch targets.
 */

/* One music deck: source, display, file picker and a single transport. */
html[data-theme] #world #sound-deck {
  overflow: hidden;
}

html[data-theme] #world #sound-deck:not([hidden]) {
  display: flex;
  flex-direction: column;
}

html[data-theme] #world #sound-deck .deck-title {
  position: relative;
  flex: none;
  height: 31px;
  min-height: 31px;
  padding: 0 6px;
  box-sizing: border-box;
}

html[data-theme] #world #sound-deck #close-deck {
  flex: none;
  width: 24px;
  min-width: 24px;
  height: 24px;
  min-height: 24px;
  padding: 0;
}

html[data-theme] #world #sound-deck .music-deck-body {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
}

/* Phone and touch: the deck title bar and close button grow to the 44 px touch target. */
@media (max-width: 620px), (any-pointer: coarse) {
  html[data-theme] #world #sound-deck .deck-title {
    height: 44px;
    min-height: 44px;
  }

  html[data-theme] #world #sound-deck #close-deck {
    width: 44px;
    min-width: 44px;
    height: 44px;
    min-height: 44px;
  }
}

/* Source row: a label and the select that chooses a radio station or the own-file source. */
#sound-deck .music-source-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  margin: 10px 6px 6px;
  color: #25313c;
  font:
    12px/1.4 Tahoma,
    sans-serif;
}

#sound-deck .music-source-row select {
  box-sizing: border-box;
  width: 100%;
  height: 34px;
  padding: 5px 8px;
  font:
    12px Tahoma,
    sans-serif;
}

/* Now-playing display and the slot for an embedded player. */
#sound-deck .deck-display {
  margin: 6px;
  min-height: 62px;
}

#sound-deck .radio-player-slot {
  margin: 0 6px;
}

#sound-deck .radio-player-slot iframe {
  display: block;
  width: 100%;
  height: 64px;
  margin: 0;
  border: 0;
  background: #d8dadd;
  border-bottom: 1px solid #89939c;
  border-radius: 0;
}

/* Own audio file picker row. */
#sound-deck .deck-file-row {
  padding: 8px 6px 0;
}

#sound-deck .deck-file-row .audio-picker {
  height: 34px;
  min-height: 34px;
  padding: 5px 9px;
  font:
    12px Tahoma,
    sans-serif;
}

/* Transport row: the play button and the volume slider. */
#sound-deck .deck-controls {
  display: flex;
  gap: 10px;
  align-items: center;
  margin: 0;
  padding: 10px 6px;
  min-height: 54px;
  box-sizing: border-box;
}

#sound-deck .deck-controls > button {
  height: 34px;
  min-height: 34px;
  min-width: 72px;
  padding: 5px 10px;
  font:
    12px Tahoma,
    sans-serif;
}

#sound-deck .deck-controls > label {
  flex: 1;
  min-width: 80px;
  gap: 1px;
}

#sound-deck .deck-controls input[type='range'] {
  width: 100%;
  margin: 2px 0;
}

/* Notes below the transport: provider note, ducking option and footnote. */
#sound-deck .music-provider-note {
  margin: 8px 7px;
  font:
    10px/1.45 Tahoma,
    sans-serif;
  color: #374651;
}

#sound-deck .duck-option {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 6px 6px;
}

#sound-deck .deck-footnote {
  margin: 6px 7px;
}

/* !important so rows hidden by script stay hidden: the display rules above would otherwise override
   the hidden attribute. */
#sound-deck [hidden] {
  display: none !important;
}

/* Dock chip (#radio-dock-chip): the status-aware Music button. hyd-radio.js sets data-location to
   dock (home), player or menu (any other page, such as Places), and data-radio-state to the
   playback state. */
/* A fixed dock slot: the state label cannot shift another shortcut. */
html[data-theme] #world :is(#home, #cinema, .shell) #radio-dock-chip {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  flex: 0 0 44px;
  width: 44px;
  min-width: 44px;
  max-width: 44px;
  height: 44px;
  min-height: 44px;
  box-sizing: border-box;
  padding: 2px;
  margin: 0;
  border: 1px solid transparent;
  border-radius: 2px;
  background: transparent;
  color: var(--metal-ink,#262626);
  font: 10px/12px var(--desktop-font);
  white-space: nowrap;
  touch-action: manipulation;
}

html[data-theme] #world :is(#home, #cinema, .shell) #radio-dock-chip .radio-chip-icon {
  display: block;
  flex: none;
  width: 24px;
  height: 24px;
  margin: 0;
  filter: none;
}

html[data-theme] #world :is(#home, #cinema, .shell) #radio-dock-chip .radio-chip-face {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  width: auto;
  height: 12px;
  min-height: 12px;
  flex: none;
  margin: 0;
  font: 10px/12px var(--desktop-font);
}

/* Status dot: dim while idle, solid while playing, hollow when the stream failed or needs a tap. */
#radio-dock-chip .radio-chip-dot {
  display: block;
  width: 5px;
  height: 5px;
  flex: none;
  border: 1px solid currentColor;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.4;
}

#radio-dock-chip[data-radio-state='playing'] .radio-chip-dot {
  opacity: 1;
}

#radio-dock-chip[data-radio-state='error'] .radio-chip-dot,
#radio-dock-chip[data-radio-state='ready-to-play'] .radio-chip-dot {
  background: transparent;
  opacity: 1;
}

/* !important group: children hidden by script stay hidden despite the display rules above, and the
   player-only text label stays off here (the player layout below turns it back on). */
#radio-dock-chip [hidden],
#radio-dock-chip .radio-chip-player-label {
  display: none !important;
}

/* Legacy Music launchers draw a playing dot; this button already has one. */
html[data-theme] #world #radio-dock-chip::before {
  content: none !important;
}

/* Chip states: hover, keyboard focus or open deck tint it; pressing bevels it inward; focus-visible
   draws a ring. */
html[data-theme]
  #world
  :is(#home, #cinema, .shell)
  #radio-dock-chip:is(:hover, :focus-visible, [aria-expanded='true']) {
  background: #e5e5e8;
  border-color: #8595a4;
}

html[data-theme] #world :is(#home, #cinema, .shell) #radio-dock-chip:active {
  border-style: inset;
}

html[data-theme] #world :is(#home, #cinema, .shell) #radio-dock-chip:focus-visible {
  outline: 2px solid #285f94;
  outline-offset: 1px;
}

html[data-theme]
  #world
  :is(#home, #cinema, .shell)
  #radio-dock-chip:not([data-location='dock'])
  .radio-chip-icon {
  display: none;
}

/* On the shell menu (Places and other pages) the chip sits beside the existing Music launcher. */
html[data-theme] #world .shell #radio-dock-chip {
  order: 0;
  margin-left: -6px;
}

/* Keep the Places deck title below its revealed menu, even on short screens. */
html[data-theme] #world.places-menu-reveal > .sound-deck {
  max-height: max(48px,calc(100dvh - var(--dock-overlay-bottom,78px) - var(--menu-height,51px) - 8px));
}

/* Four matching player actions; radio status lives inside Music. */
html[data-theme] #world #cinema .player-music-controls {
  display: contents;
}

html[data-theme] #world #cinema .player-music-controls > [hidden] {
  display: none !important;
}

html[data-theme] #world #cinema #radio-dock-chip {
  flex-direction: row;
  gap: 7px;
  flex: 0 0 136px;
  width: 136px;
  max-width: none;
  min-width: 0;
  height: 44px;
  min-height: 44px;
  padding: 0 9px;
  border: 1px solid #7d838a;
  border-radius: 3px;
  background: linear-gradient(#fafafa, #d2d4d7);
  color: #20262b;
  box-shadow: inset 0 1px #fff;
  font: 12px/1 var(--desktop-font);
}

/* Player chip: its own text label is shown and the dock status label is hidden. !important lets the
   pair win over the dock rules above, which toggle the same children with !important. */
html[data-theme] #world #cinema #radio-dock-chip .radio-chip-player-label {
  display: block !important;
  width: auto;
  height: auto;
  flex: none;
  font: inherit;
}

html[data-theme] #world #cinema #radio-dock-chip [data-radio-label] {
  display: none !important;
}

html[data-theme]
  #world
  #cinema
  #radio-dock-chip:is(:hover, :focus-visible, [aria-expanded='true']) {
  background: linear-gradient(#fff, #dce2e8);
  border-color: #617186;
}

@media (min-width: 901px) {
  html[data-theme] #world #cinema .player-extras {
    padding-block: 4px;
  }
}

/* Phone: the chip spans the full width of the player action grid. */
@media (max-width: 620px) {
  html[data-theme] #world #cinema #radio-dock-chip {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    grid-column: 1;
    grid-row: auto;
  }
}

/* In the player, the open music deck keeps its own supporting row. */
#cinema .player-music-shelf {
  grid-column: 1/-1;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
  width: 100%;
  box-sizing: border-box;
  padding: 0 12px;
}

#cinema .player-music-shelf:has(> .sound-deck[hidden]) {
  display: none;
}

#world #cinema .player-music-shelf > .sound-deck {
  position: relative;
  inset: auto;
  translate: none;
  transform: none;
  margin: 0;
  box-sizing: border-box;
  width: 100%;
  max-width: 560px;
  max-height: none;
  overflow: visible;
  align-self: center;
  z-index: auto;
}

/* Home music shares the desktop stacking context below Riyal. */
#world #web-desktop > .sound-deck {
  z-index: 125;
  bottom: var(--dock-overlay-bottom,78px);
  max-height: max(48px,calc(100dvh - var(--dock-overlay-bottom,78px) - 8px));
}

/* Inside the shelf the deck body sizes to its content instead of scrolling on its own. */
html[data-theme] #world #cinema .player-music-shelf .music-deck-body {
  flex: none;
  overflow: visible;
}

/* Desktop player: a compact deck (source; now playing; play beside volume). The help text and the ducking option fold
   behind the title toggle, which no other host shows. The shelf lives in the location column (hyd-world.js): under the
   location card when that column is on the right, directly under the footer otherwise. A full right column scrolls
   itself, so opening music never grows the page. */
#sound-deck .deck-more-toggle {
  display: none;
}

@media (min-width: 621px) {
  html[data-theme] #world #cinema .player-music-shelf #sound-deck .deck-more-toggle {
    display: block;
    order: 2;
    padding: 0;
    font-size: 13px;
    line-height: 1;
  }

  /* The body becomes a two-column grid: play beside the volume slider, every other row full width. */
  html[data-theme] #world #cinema .player-music-shelf .music-deck-body {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    align-content: start;
    gap: 6px;
    padding: 6px;
  }

  html[data-theme] #world #cinema .player-music-shelf .music-deck-body > * {
    grid-column: 1/-1;
    margin: 0;
  }

  html[data-theme] #world #cinema .player-music-shelf .music-source-row {
    gap: 6px;
  }

  /* Compact display: no minimum height, and the title stays on one line with an ellipsis. */
  html[data-theme] #world #cinema .player-music-shelf .deck-display {
    min-height: 0;
    padding: 5px 8px;
  }

  html[data-theme] #world #cinema .player-music-shelf .deck-display b {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    overflow-wrap: normal;
  }

  /* Transport in the grid: play in column 1, volume in column 2 and the time right-aligned on its
     own row; when the retry button shows, the volume spans two rows. */
  html[data-theme] #world #cinema .player-music-shelf .deck-controls {
    display: contents;
  }

  html[data-theme] #world #cinema .player-music-shelf #deck-play {
    grid-column: 1;
    min-width: 64px;
  }

  html[data-theme] #world #cinema .player-music-shelf .deck-controls > label {
    grid-column: 2;
    min-width: 0;
  }

  html[data-theme] #world #cinema .player-music-shelf .deck-controls > label > input {
    width: 100%;
    margin: 0;
  }

  html[data-theme] #world #cinema .player-music-shelf .deck-controls > #music-time {
    grid-column: 1/-1;
    justify-self: end;
  }

  html[data-theme] #world #cinema .player-music-shelf .deck-controls > .radio-retry {
    grid-column: 1;
  }

  html[data-theme]
    #world
    #cinema
    .player-music-shelf
    #sound-deck:has(.radio-retry:not([hidden]))
    .deck-controls
    > label {
    grid-row: span 2;
    align-self: center;
  }

  html[data-theme] #world #cinema .player-music-shelf :is(.deck-file-row, .duck-option) {
    padding: 0;
  }

  /* Rows fold away: the file picker shows only for the file source; the ducking option, provider
     note and footnote show only after the more toggle opens them. */
  html[data-theme]
    #world
    #cinema
    .player-music-shelf
    #sound-deck:not([data-music-source='file'])
    .deck-file-row {
    display: none;
  }

  html[data-theme]
    #world
    #cinema
    .player-music-shelf
    #sound-deck:not(.deck-more-open)
    :is(.duck-option, .music-provider-note, .deck-footnote) {
    display: none;
  }

  /* Placement inside #player-location-dock: first by default, last (order 2) when the player is wide. */
  html[data-theme] #world #cinema #player-location-dock > .player-music-shelf {
    order: -1;
    flex: none;
    padding: 0;
    margin: 0 0 10px;
  }

  html[data-theme]
    #world
    #cinema
    #cinema-view.player-wide
    #player-location-dock
    > .player-music-shelf {
    order: 2;
    margin: 10px 0 0;
  }

  html[data-theme]
    #world
    #cinema
    #cinema-view.player-wide
    #player-location-dock
    > .player-music-shelf
    > #sound-deck {
    max-width: none;
  }

  /* While the deck is open in a wide player, the location column becomes a thin-scrollbar scroller
     with a fixed size. */
  html[data-theme]
    #world
    #cinema
    #cinema-view.player-wide
    #player-location-dock:has(> .player-music-shelf > #sound-deck:not([hidden])) {
    align-self: stretch;
    contain: size;
    overflow: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
  }

  /* The location card and map keep their size: the column scrolls rather than squeezing them (their overflow:hidden
    would otherwise let them shrink to nothing). */
  html[data-theme]
    #world
    #cinema
    #cinema-view.player-wide
    #player-location-dock:has(> .player-music-shelf > #sound-deck:not([hidden]))
    > * {
    flex-shrink: 0;
  }

  /* Riyal can sit on the full column's bottom edge: draw his focus ring inside, so no padding can add a 1 px overflow. */
  html[data-theme]
    #world
    #cinema
    #cinema-view.player-wide
    #player-location-dock:has(> .player-music-shelf > #sound-deck:not([hidden]))
    #hyd-cat
    .hyd-cat-pet:focus-visible {
    outline-offset: -2px;
  }
}

/* Mouse and trackpad: a slimmer deck title bar, more toggle and source picker. */
@media (min-width: 621px) and (pointer: fine) {
  html[data-theme] #world #cinema .player-music-shelf #sound-deck .deck-title {
    height: 28px;
    min-height: 28px;
  }

  html[data-theme] #world #cinema .player-music-shelf #sound-deck .deck-more-toggle {
    flex: 0 0 25px;
    width: 24px;
    min-width: 24px;
    height: 24px;
    min-height: 24px;
  }

  html[data-theme] #world #cinema .player-music-shelf #music-source {
    height: 28px;
    padding: 3px 6px;
  }
}

/* A touch laptop (fine primary pointer plus a touchscreen) keeps the stock 34 px source picker. */
@media (min-width: 621px) and (pointer: fine) and (any-pointer: coarse) {
  html[data-theme] #world #cinema .player-music-shelf #music-source {
    height: 34px;
    padding: 5px 8px;
  }
}

/* Any touch input keeps the 44 px title, close button and toggle (a touch laptop has a fine primary pointer too). */
@media (min-width: 621px) and (any-pointer: coarse) {
  html[data-theme] #world #cinema .player-music-shelf #sound-deck .deck-title {
    height: 44px;
    min-height: 44px;
  }

  html[data-theme] #world #cinema .player-music-shelf #sound-deck .deck-more-toggle {
    flex: 0 0 44px;
    width: 44px;
    min-width: 44px;
    height: 44px;
    min-height: 44px;
  }
}
