/**
 * jukebox — music picker.
 * Quick pick: popover anchored to the speaker button (bottom sheet below 576px).
 * Full view: <dialog> with a now-playing deck, track cards and the per-area mix.
 */

/* Speaker button: blue dot while one track is pinned for every area. */
.cq-bgm-toggle {
  position: relative;
}

.cq-bgm-toggle.has-pin::after {
  content: "";
  position: absolute;
  top: 8px;
  right: 8px;
  width: 8px;
  height: 8px;
  background: var(--arcane);
  box-shadow: 0 0 0 2px var(--panel);
}

/* ── Quick pick (popover) ── */
.cq-jukebox {
  inset: auto;
  width: min(408px, calc(100vw - 32px));
  max-height: var(--jb-max, calc(100vh - 32px));
  margin: 0;
  padding: 0;
  border: 0;
  flex-direction: column;
  overflow: hidden;
  color: var(--text-main);
  background: var(--panel);
  box-shadow:
    0 -2px 0 0 var(--border-light), 0 2px 0 0 var(--border-light),
    -2px 0 0 0 var(--border-light), 2px 0 0 0 var(--border-light),
    0 12px 0 rgba(0, 0, 0, 0.35);
}

.cq-jukebox:popover-open {
  display: flex;
}

/* Browsers without the Popover API keep the old click-to-cycle speaker button. */
@supports not selector(:popover-open) {
  .cq-jukebox {
    display: none;
  }
}

@media (min-width: 576px) {
  .cq-jukebox {
    top: var(--jb-top, 72px);
    bottom: var(--jb-bottom, auto);
    left: var(--jb-left, auto);
  }

  .cq-jukebox::backdrop {
    background: transparent;
  }
}

.cq-jukebox__grab {
  display: none;
}

.cq-jukebox__head {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: 0.35rem 0.35rem 0.35rem 1.1rem;
  border-bottom: 2px solid var(--border);
}

.cq-jukebox__head > .fa-music {
  color: var(--btn-gold);
}

.cq-jukebox__heading {
  flex: 1;
  margin: 0;
  font-size: 1.25rem;
}

.cq-jukebox__now {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 0.9rem 1rem 0;
  padding: 0.75rem;
  background: var(--sunken);
  box-shadow: var(--pixel-shadow-inset);
}

.cq-jukebox__now-text {
  flex: 1;
  min-width: 0;
}

.cq-jukebox__now-text p,
.cq-jukebox-full__deck p {
  margin: 0;
}

.cq-jukebox__now-title {
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1.25;
}

.cq-jukebox__now-sub {
  font-size: var(--font-size-sm);
  color: var(--text-muted);
}

[data-jb-now-label].is-preview {
  color: var(--arcane);
}

.cq-jukebox__cover {
  display: grid;
  place-items: center;
  flex: none;
  width: 40px;
  height: 40px;
  background: var(--sunken);
  box-shadow: var(--pixel-shadow-inset);
}

.cq-jukebox__cover img {
  width: 28px;
  height: 28px;
  image-rendering: pixelated;
}

.cq-jukebox__now .cq-jukebox__cover {
  width: 52px;
  height: 52px;
}

.cq-jukebox__now .cq-jukebox__cover img {
  width: 32px;
  height: 32px;
}

.cq-jukebox__cover--areas {
  font-size: 1.1rem;
  color: var(--arcane);
  background: #1C2433;
}

/* Equalizer: steps, not smooth — it should feel like a sprite. */
.cq-jukebox__eq {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 20px;
  opacity: 0.35;
}

.cq-jukebox__eq span {
  width: 4px;
  height: 100%;
  background: var(--btn-gold);
  transform: scaleY(0.4);
  transform-origin: bottom;
}

.is-playing .cq-jukebox__eq {
  opacity: 1;
}

.is-playing .cq-jukebox__eq span {
  animation: cq-jukebox-eq 700ms steps(3) infinite alternate;
}

.is-playing .cq-jukebox__eq span:nth-child(2) {
  animation-duration: 900ms;
  animation-delay: -300ms;
}

.is-playing .cq-jukebox__eq span:nth-child(3) {
  animation-duration: 600ms;
  animation-delay: -150ms;
}

.is-playing .cq-jukebox__eq span:nth-child(4) {
  animation-duration: 800ms;
  animation-delay: -450ms;
}

@keyframes cq-jukebox-eq {
  0% { transform: scaleY(0.3); }
  50% { transform: scaleY(1); }
  100% { transform: scaleY(0.55); }
}

.cq-jukebox__play {
  flex: none;
  width: 44px;
  padding: 0;
}

.cq-jukebox__label {
  margin: 1rem 1rem 0.5rem;
}

.cq-jukebox__list {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  gap: 4px;
  min-height: 0;
  max-height: 404px;
  overflow-y: auto;
  padding: 2px 1rem 0.5rem;
}

.cq-jukebox__list .cq-jukebox__label {
  margin: 0.6rem 0 0.25rem;
}

.cq-jukebox__row {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  min-height: 56px;
  padding: 2px 2px 2px 10px;
}

.cq-jukebox__row:has(:checked) {
  background: var(--panel-light);
  box-shadow: 0 0 0 2px var(--btn-gold);
}

.cq-jukebox__pick {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex: 1;
  min-width: 0;
  min-height: 52px;
  cursor: pointer;
}

.cq-jukebox__text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.cq-jukebox__title {
  font-weight: 600;
  line-height: 1.3;
}

.cq-jukebox__sub {
  font-size: var(--font-size-sm);
  color: var(--text-muted);
}

.cq-jukebox__radio {
  appearance: none;
  -webkit-appearance: none;
  flex: none;
  width: 22px;
  height: 22px;
  margin: 0;
  cursor: pointer;
  background: var(--sunken);
  box-shadow: inset 0 0 0 2px var(--border-light);
}

.cq-jukebox__radio:checked {
  background: var(--btn-gold);
  box-shadow: inset 0 0 0 2px var(--btn-gold), inset 0 0 0 6px var(--sunken);
}

.cq-jukebox__radio:focus-visible,
.cq-switch:focus-visible {
  outline: 2px solid var(--btn-gold);
  outline-offset: 2px;
}

.cq-jukebox__preview.is-active {
  color: var(--btn-gold);
}

.cq-jukebox__foot {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 0.5rem 1rem 1rem;
  border-top: 2px solid var(--border);
}

.cq-jukebox__volume,
.cq-jukebox__switch-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-height: 44px;
}

.cq-jukebox__volume label,
.cq-jukebox__switch-row > span {
  font-weight: 600;
}

.cq-jukebox__volume label {
  flex: none;
  width: 7rem;
}

.cq-jukebox__volume input {
  flex: 1;
  min-width: 0;
  height: 44px;
  margin: 0;
  accent-color: var(--btn-gold);
  cursor: pointer;
}

.cq-jukebox__volume output {
  flex: none;
  width: 3rem;
  text-align: right;
  font-family: var(--font-mono);
  font-size: var(--font-size-sm);
  color: var(--text-muted);
}

.cq-jukebox__switch-row > span {
  flex: 1;
}

.cq-jukebox__note,
.cq-jukebox__status {
  margin: 0;
  font-size: var(--font-size-sm);
}

.cq-jukebox__note {
  color: var(--text-faint);
}

.cq-jukebox__status {
  color: var(--btn-red);
}

.cq-jukebox__status:empty {
  display: none;
}

/* Pixel switch: 44px tall hit area around a 52×28 track. */
.cq-switch {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 60px;
  height: 44px;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
}

.cq-switch__track {
  position: relative;
  display: block;
  width: 52px;
  height: 28px;
  background: var(--sunken);
  box-shadow: inset 0 0 0 2px var(--border-light);
}

.cq-switch__track::after {
  content: "";
  position: absolute;
  top: 6px;
  left: 6px;
  width: 16px;
  height: 16px;
  background: var(--text-faint);
  transition: transform var(--transition-fast);
}

.cq-switch[aria-checked="true"] .cq-switch__track {
  background: var(--btn-gold);
  box-shadow: inset 0 0 0 2px var(--btn-gold-dark);
}

.cq-switch[aria-checked="true"] .cq-switch__track::after {
  background: var(--text-dark);
  transform: translateX(24px);
}

/* Phones: the quick pick slides up as a bottom sheet. */
@media (max-width: 575.98px) {
  .cq-jukebox {
    top: auto;
    right: 0;
    bottom: 0;
    left: 0;
    width: 100%;
    max-height: 88vh;
    box-shadow: 0 -2px 0 0 var(--border-light), 0 -10px 0 rgba(0, 0, 0, 0.3);
  }

  .cq-jukebox::backdrop {
    background: rgba(10, 11, 16, 0.72);
  }

  .cq-jukebox__grab {
    display: block;
    align-self: center;
    width: 44px;
    height: 4px;
    margin-top: 10px;
    background: var(--border-light);
  }

  .cq-jukebox__list {
    max-height: none;
  }
}

/* ── Full view (dialog) ── */
.cq-jukebox-full {
  width: min(1040px, calc(100vw - 32px));
  max-width: none;
  max-height: calc(100vh - 48px);
  margin: auto;
  padding: 0;
  border: 0;
  overflow: auto;
  color: var(--text-main);
  background: var(--panel);
  box-shadow:
    0 -2px 0 0 var(--border-light), 0 2px 0 0 var(--border-light),
    -2px 0 0 0 var(--border-light), 2px 0 0 0 var(--border-light),
    0 14px 0 rgba(0, 0, 0, 0.4);
}

.cq-jukebox-full::backdrop {
  background: rgba(10, 11, 16, 0.72);
}

.cq-jukebox-full__head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1.25rem;
  padding: 1rem 0.75rem 0 1.5rem;
  border-bottom: 2px solid var(--border);
}

.cq-jukebox-full__brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex: 1 1 260px;
  min-width: 0;
  padding-bottom: 0.9rem;
}

.cq-jukebox-full__brand .fa-music {
  font-size: 1.5rem;
  color: var(--btn-gold);
}

.cq-jukebox-full__brand h2 {
  margin: 0;
  font-size: 1.6rem;
}

.cq-jukebox-full__brand p {
  margin: 0;
  font-size: var(--font-size-sm);
  color: var(--text-muted);
}

.cq-jukebox-full__tabs {
  display: flex;
  align-self: flex-end;
  gap: 4px;
}

.cq-jukebox-full__tabs button {
  min-height: 48px;
  padding: 0 1.1rem;
  border: 0;
  cursor: pointer;
  font-family: var(--font-pixel);
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-muted);
  background: transparent;
}

.cq-jukebox-full__tabs button:hover {
  color: var(--text-main);
}

.cq-jukebox-full__tabs button[aria-selected="true"] {
  color: var(--text-main);
  background: var(--panel-light);
  box-shadow: inset 0 -3px 0 var(--btn-gold);
}

.cq-jukebox-full__close {
  align-self: flex-start;
  margin: 0;
}

.cq-jukebox-full__body {
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
  padding: 1.5rem;
}

.cq-jukebox-full__deck {
  display: flex;
  flex: 1 1 280px;
  flex-direction: column;
  gap: 1rem;
  max-width: 100%;
}

.cq-jukebox-full__main {
  flex: 999 1 560px;
  min-width: 0;
}

.cq-jukebox-full__cover {
  display: grid;
  place-items: center;
  height: 220px;
  background: var(--sunken);
  box-shadow: var(--pixel-shadow-inset);
}

.cq-jukebox-full__cover img {
  width: 128px;
  height: 128px;
  image-rendering: pixelated;
}

.cq-jukebox-full__title {
  font-family: var(--font-pixel);
  font-size: 1.6rem;
  font-weight: 600;
  line-height: 1.15;
}

.cq-jukebox-full__sub {
  font-size: var(--font-size-sm);
  color: var(--text-muted);
}

.cq-jukebox-full__progress {
  height: 10px;
  background: var(--sunken);
  box-shadow: 0 0 0 2px var(--border);
}

.cq-jukebox-full__progress span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--btn-gold);
}

.cq-jukebox-full__times {
  display: flex;
  justify-content: space-between;
  margin-top: 0.5rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-muted);
}

.cq-jukebox-full__transport {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.9rem;
}

.cq-jukebox-full__transport .pixel-btn {
  padding: 0;
  min-width: 48px;
  min-height: 48px;
}

.cq-jukebox-full__transport .cq-jukebox__play {
  width: 64px;
  min-height: 56px;
}

.cq-jukebox-full__controls {
  padding: 0.75rem 0 0;
}

.cq-jukebox-full__picks {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.cq-jukebox-full__picks > .cq-eyebrow {
  margin: 0.25rem 0 0;
}

.cq-jukebox-full__grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

/* A card is a label around a visually hidden radio, so arrow keys work natively. */
.cq-jukebox-card {
  position: relative;
  flex: 1 1 190px;
  min-width: 0;
}

.cq-jukebox-card > label {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  height: 100%;
  padding: 0.9rem;
  cursor: pointer;
  background: var(--sunken);
  box-shadow: var(--pixel-shadow-inset);
}

.cq-jukebox-card--wide {
  flex: none;
}

.cq-jukebox-card--wide > label {
  flex-direction: row;
  align-items: center;
  gap: 1rem;
}

.cq-jukebox-card--wide .cq-jukebox__text {
  flex: 1;
}

.cq-jukebox-card input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.cq-jukebox-card:has(:checked) > label {
  background: var(--panel-light);
  box-shadow: 0 0 0 2px var(--btn-gold), 0 0 0 8px rgba(245, 184, 61, 0.08);
}

.cq-jukebox-card:has(:focus-visible) > label {
  outline: 2px solid var(--btn-gold);
  outline-offset: 4px;
}

.cq-jukebox-card .cq-jukebox__cover {
  width: 56px;
  height: 56px;
}

.cq-jukebox-card .cq-jukebox__cover img {
  width: 36px;
  height: 36px;
}

.cq-jukebox-card__name {
  font-weight: 700;
  line-height: 1.3;
}

.cq-jukebox-card--wide .cq-jukebox-card__name {
  font-family: var(--font-pixel);
  font-size: 1.15rem;
  font-weight: 600;
}

.cq-jukebox-card__meta {
  font-size: var(--font-size-sm);
  color: var(--text-muted);
}

.cq-jukebox-card .cq-jukebox__preview {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  background: var(--sunken);
  box-shadow: var(--pixel-shadow-inset);
}

.cq-jukebox-areas {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.cq-jukebox-areas > p {
  margin: 0 0 0.25rem;
  color: var(--text-muted);
}

.cq-jukebox-area {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem 0.9rem;
  padding: 0.6rem 0.75rem;
  background: var(--sunken);
  box-shadow: var(--pixel-shadow-inset);
}

.cq-jukebox-area .cq-jukebox__cover {
  background: var(--panel);
}

.cq-jukebox-area .cq-jukebox__cover img {
  width: 24px;
  height: 24px;
}

.cq-jukebox-area__text {
  display: flex;
  flex: 1 1 160px;
  flex-direction: column;
  min-width: 0;
}

.cq-jukebox-area__text label {
  font-weight: 700;
  line-height: 1.3;
}

.cq-jukebox-area__hint {
  font-size: var(--font-size-sm);
  color: var(--text-muted);
}

.cq-jukebox-area select {
  flex: 1 1 220px;
  min-width: 0;
  height: 44px;
  padding: 0 0.75rem;
  font: inherit;
  color: var(--text-main);
  background: var(--panel);
  border: 2px solid var(--border-light);
  border-radius: 0;
  cursor: pointer;
}

.cq-jukebox-area.is-changed .cq-jukebox-area__hint {
  color: var(--btn-gold);
}

.cq-jukebox-area.is-changed select {
  border-color: var(--btn-gold);
}

.cq-jukebox-areas__reset {
  align-self: flex-end;
  margin-top: 0.25rem;
}

.cq-jukebox-full__foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1rem;
  padding: 0.9rem 1.5rem 1.1rem;
  border-top: 2px solid var(--border);
}

.cq-jukebox-full__foot > p:first-child {
  flex: 1 1 260px;
  margin: 0;
  font-size: var(--font-size-sm);
  color: var(--text-faint);
}

.cq-jukebox-full__foot form {
  margin: 0;
}

/* Phones: the full view takes the whole screen. */
@media (max-width: 575.98px) {
  .cq-jukebox-full {
    width: 100vw;
    height: 100vh;
    max-height: 100vh;
  }

  .cq-jukebox-full__head {
    padding-left: 1rem;
  }

  .cq-jukebox-full__body {
    padding: 1rem;
  }

  .cq-jukebox-full__cover {
    height: 140px;
  }

  .cq-jukebox-full__cover img {
    width: 96px;
    height: 96px;
  }
}
