/* ============================================================
   Games Music Player — Compact Mode Styles
   Built on ArekUI Brutalist tokens (--ar-*). No Tailwind.
   ============================================================ */

/* --- Root container ------------------------------------------ */

.music-compact {
  --compact-vinyl-size: 128px;
  --compact-expanded-width: 288px;
  --compact-transition: 200ms ease;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  font-family: inherit;
  position: relative;
  z-index: 10;
  overflow: visible;
}

.music-compact *,
.music-compact *::before,
.music-compact *::after {
  box-sizing: border-box;
}

/* --- Vinyl record (default collapsed state) ------------------ */

.music-compact__vinyl-wrap {
  position: relative;
  z-index: 0;
  width: var(--compact-vinyl-size);
  height: var(--compact-vinyl-size);
  transition: height var(--compact-transition), opacity var(--compact-transition);
}

.music-compact:not(.is-expanded) .music-compact__vinyl-wrap {
  height: var(--compact-vinyl-size);
  opacity: 1;
}

.music-compact.is-expanded .music-compact__vinyl-wrap {
  height: 0;
  opacity: 0;
  pointer-events: none;
}

.music-compact__vinyl {
  width: 100%;
  height: 100%;
  border: 4px solid var(--ar-base-content);
  border-radius: 50%;
  box-shadow: 4px 4px 0 var(--ar-base-content);
  animation: compact-spin 1.8s linear infinite;
  background: var(--ar-base-100);
  overflow: hidden;
}

.music-compact:not(.is-playing) .music-compact__vinyl {
  animation-play-state: paused;
}

/* Grooves: dotted ink rings — the paper's dot grid, wrapped around the disc */
.music-compact__groove {
  fill: none;
  stroke: var(--ar-base-content);
  stroke-width: 1;
  stroke-dasharray: 0.5 7;
  stroke-linecap: round;
  opacity: 0.45;
}

/* Center label: the record's identity stamp */
.music-compact__vinyl-center {
  position: absolute;
  top: calc(50% - 21px);
  left: calc(50% - 21px);
  z-index: 10;
  width: 42px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--ar-base-content);
  border-radius: 50%;
}

.music-compact__disc-mark {
  font-size: 15px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.02em;
  color: var(--ar-base-100);
}

.music-compact__disc-mark-accent {
  color: var(--ar-accent);
}

/* The one signal: while a track plays, the label floods orange */
.music-compact.is-playing .music-compact__vinyl-center,
.music-compact.is-playing .music-compact__mini-vinyl-center {
  background: var(--ar-accent);
}

.music-compact.is-playing .music-compact__disc-mark-accent {
  color: var(--ar-base-100);
}

/* Wave: one ink ring breathing out of the grooves toward the rim,
   one pulse per revolution — only while a track plays. */
.music-compact__wave {
  fill: none;
  stroke: var(--ar-base-content);
  stroke-width: 1;
  opacity: 0;
  transform-box: fill-box;
  transform-origin: center;
}

.music-compact.is-playing .music-compact__wave {
  animation: compact-wave 1.8s linear infinite;
}

@keyframes compact-wave {
  0% { opacity: 0.35; transform: scale(0.9); }
  70% { opacity: 0.12; transform: scale(1.9); }
  100% { opacity: 0; transform: scale(2.1); }
}

/* Scope: a real Web Audio waveform drawn by JS across the band, in ink.
   Silence = a flat ruled line sound draws bars above and below. The
   element is never animated by keyframes — the analyser is the truth. */
.music-compact__scope {
  position: absolute;
  left: 12px;
  top: 50%;
  /* Explicit width: a canvas is a replaced element, so an auto width would
     follow the intrinsic (JS-set) attribute and fight the drawing loop. */
  width: calc(100% - 24px);
  height: 18px;
  transform: translateY(-50%);
  pointer-events: none;
}

@keyframes compact-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* --- Expanded panel ------------------------------------------ */

.music-compact__panel {
  position: relative;
  z-index: 30;
  width: 160px;
  height: 80px;
  margin-top: -8px;
  background: var(--ar-base-100);
  border: 2px solid var(--ar-base-content);
  box-shadow: 4px 4px 0 var(--ar-base-content);
  border-radius: 0;
  overflow: visible;
  transition: width var(--compact-transition), height var(--compact-transition), margin-top var(--compact-transition);
  display: flex;
  flex-direction: column;
}

.music-compact:not(.is-expanded) .music-compact__panel {
  width: 160px;
  height: 80px;
  margin-top: -8px;
}

.music-compact.is-expanded .music-compact__panel {
  width: var(--compact-expanded-width);
  height: 160px;
  margin-top: 0;
}

/* --- Expanded top: mini vinyl + track info ------------------- */

.music-compact__expanded-top {
  display: flex;
  flex-direction: row;
  width: 100%;
  height: 0;
  overflow: hidden;
  transition: height var(--compact-transition);
}

/* Collapsed: the peek band carries track identity instead of buttons */
.music-compact:not(.is-expanded) .music-compact__expanded-top {
  height: 44px;
}

.music-compact:not(.is-expanded) .music-compact__mini-vinyl-wrap {
  display: none;
}

.music-compact.is-expanded .music-compact__expanded-top {
  height: 80px;
}

.music-compact__mini-vinyl-wrap {
  position: relative;
  flex-shrink: 0;
  width: 96px;
  height: 96px;
  margin: -16px 0 0 -16px;
  opacity: 0;
  transform: translate(24px, 24px);
  transition: opacity 100ms var(--compact-transition), transform 100ms var(--compact-transition);
  animation: compact-spin 1.8s linear infinite;
}

.music-compact:not(.is-playing) .music-compact__mini-vinyl-wrap {
  animation-play-state: paused;
}

.music-compact:not(.is-expanded) .music-compact__mini-vinyl-wrap {
  opacity: 0;
  transform: translate(24px, 24px);
}

.music-compact.is-expanded .music-compact__mini-vinyl-wrap {
  opacity: 1;
  transform: translate(0, 0);
}

.music-compact__mini-vinyl {
  width: 100%;
  height: 100%;
  border: 4px solid var(--ar-base-content);
  border-radius: 50%;
  box-shadow: 4px 4px 0 var(--ar-base-content);
  background: var(--ar-base-100);
  overflow: hidden;
}

.music-compact__mini-vinyl-center {
  position: absolute;
  top: calc(50% - 17px);
  left: calc(50% - 17px);
  z-index: 10;
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--ar-base-content);
  border-radius: 50%;
}

.music-compact__disc-mark--mini {
  font-size: 12px;
}

.music-compact__track-info {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding-left: 12px;
  padding-right: 12px;
  margin-left: -36px;
  overflow: hidden;
  white-space: nowrap;
  transition: margin-left var(--compact-transition);
}

.music-compact:not(.is-expanded) .music-compact__track-info {
  margin-left: 0;
}

/* Collapsed: the controls collapse away entirely — a tap on the disc
   expands the panel to reach them. Zero padding keeps the flex-centered
   buttons from peeking through the padding box. */
.music-compact:not(.is-expanded) .music-compact__controls {
  height: 0;
  padding: 0;
  overflow: hidden;
  margin-top: 0;
}

.music-compact.is-expanded .music-compact__track-info {
  margin-left: 0;
}

.music-compact__track-title {
  font-size: 1.25rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--ar-base-content);
  margin: 0;
  text-overflow: ellipsis;
  overflow: hidden;
}

.music-compact__track-artist {
  font-size: 0.875rem;
  color: var(--ar-gray-600);
  margin: 2px 0 0;
  text-overflow: ellipsis;
  overflow: hidden;
}

/* --- Progress bar -------------------------------------------- */

.music-compact__progress {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  margin-top: 12px;
  background: var(--ar-base-200);
  border-radius: 0;
  min-height: 24px;
  transition: margin-top var(--compact-transition);
}

.music-compact:not(.is-expanded) .music-compact__progress {
  margin-top: 12px;
}

.music-compact.is-expanded .music-compact__progress {
  margin-top: 0;
}

.music-compact__time {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--ar-gray-600);
  white-space: nowrap;
  min-width: 3.5ch;
}

.music-compact__time--end {
  margin-left: auto;
}

.music-compact__seek,
.music-compact__volume-slider {
  flex: 1;
  min-width: 0;
  accent-color: var(--ar-accent);
  height: 16px;
  background: var(--ar-base-300);
  border: 2px solid var(--ar-base-content);
  border-radius: 0;
  appearance: none;
  cursor: pointer;
}

.music-compact__seek::-webkit-slider-thumb,
.music-compact__volume-slider::-webkit-slider-thumb {
  appearance: none;
  width: 14px;
  height: 14px;
  background: var(--ar-base-100);
  border: 2px solid var(--ar-base-content);
  border-radius: 50%;
  box-shadow: 2px 2px 0 var(--ar-base-content);
  cursor: pointer;
  transition: transform 100ms ease;
}

.music-compact__seek::-webkit-slider-thumb:hover,
.music-compact__volume-slider::-webkit-slider-thumb:hover {
  transform: scale(1.15);
}

.music-compact__seek::-moz-range-thumb,
.music-compact__volume-slider::-moz-range-thumb {
  width: 14px;
  height: 14px;
  background: var(--ar-base-100);
  border: 2px solid var(--ar-base-content);
  border-radius: 50%;
  box-shadow: 2px 2px 0 var(--ar-base-content);
  cursor: pointer;
}

/* --- Volume: button in the controls row, flyout slider upward --- */

.music-compact__volume {
  position: relative;
  display: flex;
  align-items: center;
}

.music-compact__volume-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: transparent;
  border: 2px solid var(--ar-base-content);
  border-radius: 0;
  color: var(--ar-gray-600);
  cursor: pointer;
  transition: background 100ms ease, color 100ms ease, border-color 100ms ease;
}

.music-compact__volume-btn:hover {
  background: var(--ar-base-content);
  color: var(--ar-base-100);
}

.music-compact__volume-btn:focus-visible {
  outline: 2px solid var(--ar-base-content);
  outline-offset: 2px;
}

.music-compact__volume-btn[aria-expanded="true"] {
  background: var(--ar-base-200);
  color: var(--ar-base-content);
}

.music-compact__vol-icon {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  fill: none;
}

.music-compact__volume-flyout {
  position: absolute;
  bottom: calc(100% + 10px);
  left: -4px;
  z-index: 40;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: 44px;
  padding: 8px;
  background: var(--ar-base-100);
  border: 2px solid var(--ar-base-content);
  box-shadow: 4px 4px 0 var(--ar-base-content);
}

.music-compact__volume-flyout[hidden] {
  display: none;
}

/* The fader's readout: mono, tabular digits so it doesn't wiggle */
.music-compact__vol-pct {
  font-size: 0.6875rem;
  font-weight: 700;
  line-height: 1;
  color: var(--ar-base-content);
  font-variant-numeric: tabular-nums;
}

/* Vertical fader: min at the bottom, max at the top. The input+class
   selector out-ranks the generic `input[type=range]` sizing the jukebox
   sheet applies on pages where both CSS files load. */
input[type="range"].music-compact__volume-slider {
  writing-mode: vertical-rl;
  direction: rtl;
  width: 24px;
  height: 104px;
  min-width: 0;
  flex: none;
  margin: 0;
}

/* --- Controls row -------------------------------------------- */

.music-compact__controls {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 12px;
  margin-top: 12px;
  transition: margin-top var(--compact-transition);
}

.music-compact.is-expanded .music-compact__controls {
  margin-top: 0;
}

.music-compact__control-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: transparent;
  border: 2px solid var(--ar-base-content);
  border-radius: 0;
  color: var(--ar-base-content);
  cursor: pointer;
  transition: background 100ms ease, color 100ms ease, transform 50ms ease;
}

.music-compact__control-btn:hover {
  background: var(--ar-base-content);
  color: var(--ar-base-100);
}

.music-compact__control-btn:focus-visible {
  outline: 2px solid var(--ar-base-content);
  outline-offset: 2px;
}

.music-compact__control-btn:active {
  transform: scale(0.95);
}

.music-compact__control-btn svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.music-compact__control-btn--play {
  width: 48px;
  height: 48px;
}

.music-compact__control-btn--play svg {
  width: 28px;
  height: 28px;
}

/* While a track plays, the play/pause button joins the record label:
   the orange field = live. Paused/idle it returns to plain ink. */
.music-compact.is-playing .music-compact__control-btn--play {
  background: var(--ar-accent);
  border-color: var(--ar-accent);
  color: var(--ar-accent-content);
}

/* Repeat/Shuffle toggle */

.music-compact__mode-toggle {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
}

.music-compact__mode-toggle input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.music-compact__mode-toggle svg {
  width: 20px;
  height: 20px;
  stroke: var(--ar-gray-600);
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: stroke 100ms ease;
}

.music-compact__mode-toggle:hover svg {
  stroke: var(--ar-base-content);
}

.music-compact__mode-toggle:focus-visible {
  outline: 2px solid var(--ar-base-content);
  outline-offset: 2px;
  border-radius: 0;
}

/* Mode button (off/repeat/shuffle) */

.music-compact__mode-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: transparent;
  border: 2px solid var(--ar-base-content);
  border-radius: 0;
  color: var(--ar-gray-600);
  cursor: pointer;
  transition: background 100ms ease, color 100ms ease, border-color 100ms ease;
}

.music-compact__mode-btn:hover {
  background: var(--ar-base-200);
  color: var(--ar-base-content);
}

.music-compact__mode-btn[aria-pressed="true"] {
  color: var(--ar-accent);
  border-color: var(--ar-accent);
}

.music-compact__mode-btn[aria-pressed="true"]:hover {
  background: var(--ar-accent);
  color: var(--ar-accent-content);
}

.music-compact__mode-btn:focus-visible {
  outline: 2px solid var(--ar-base-content);
  outline-offset: 2px;
}

.music-compact__mode-btn svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Playlist button */

.music-compact__playlist-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
}

.music-compact__playlist-btn svg {
  width: 20px;
  height: 20px;
  stroke: var(--ar-gray-600);
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.music-compact__playlist-btn:hover svg,
.music-compact__playlist-btn:focus-visible svg {
  stroke: currentColor;
}

/* --- Expansion triggers -------------------------------------- */

/* Hover expansion (desktop) */
.music-compact:hover {
  --hover-expand: true;
}

.music-compact:hover .music-compact__panel,
.music-compact:focus-within .music-compact__panel {
  width: var(--compact-expanded-width);
  height: 160px;
  margin-top: 0;
}

.music-compact:hover .music-compact__expanded-top,
.music-compact:focus-within .music-compact__expanded-top {
  height: 80px;
}

.music-compact:hover .music-compact__mini-vinyl-wrap,
.music-compact:focus-within .music-compact__mini-vinyl-wrap {
  display: block;
  opacity: 1;
  transform: translate(0, 0);
}

.music-compact:hover .music-compact__track-info,
.music-compact:focus-within .music-compact__track-info {
  margin-left: 0;
}

.music-compact:hover .music-compact__progress,
.music-compact:focus-within .music-compact__progress,
.music-compact:hover .music-compact__controls,
.music-compact:focus-within .music-compact__controls {
  margin-top: 0;
}

/* Hover/focus must undo the collapsed band: controls return (some hosts
   keep the widget un-expanded but interactive). */
.music-compact:hover .music-compact__controls,
.music-compact:focus-within .music-compact__controls {
  height: auto;
  padding: 12px;
  overflow: visible;
}

/* Click-locked expansion (JS toggles .is-expanded) */
.music-compact.is-expanded .music-compact__panel,
.music-compact.is-expanded .music-compact__expanded-top,
.music-compact.is-expanded .music-compact__mini-vinyl-wrap,
.music-compact.is-expanded .music-compact__track-info,
.music-compact.is-expanded .music-compact__progress,
.music-compact.is-expanded .music-compact__controls {
  /* JS-controlled state overrides hover */
}

.music-compact__playlist-dropdown {
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  margin-bottom: 8px;
  width: 320px;
  max-height: 400px;
  overflow-y: auto;
  background: var(--ar-base-100);
  border: 2px solid var(--ar-base-content);
  box-shadow: 4px 4px 0 var(--ar-base-content);
  border-radius: 0;
  z-index: 1000;
  animation: compact-dropdown-in 150ms ease-out;
  display: block;
}

.music-compact__playlist-dropdown[hidden] {
  display: none !important;
}

@keyframes compact-dropdown-in {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

.music-compact__playlist-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-bottom: 1px solid var(--ar-base-content);
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ar-base-content);
  flex-shrink: 0;
}

.music-compact__playlist-close {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 2px solid var(--ar-base-content);
  border-radius: 0;
  color: var(--ar-base-content);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  transition: background 100ms ease, color 100ms ease;
}

.music-compact__playlist-close:hover {
  background: var(--ar-base-content);
  color: var(--ar-base-100);
}

.music-compact__playlist-close:focus-visible {
  outline: 2px solid var(--ar-base-content);
  outline-offset: 2px;
}

.music-compact__playlist-list {
  list-style: none;
  margin: 0;
  padding: 4px 0;
  max-height: 340px;
  overflow-y: auto;
}

.music-compact__playlist-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  cursor: pointer;
  transition: background 100ms ease;
  border-left: 3px solid transparent;
}

.music-compact__playlist-item:hover {
  background: var(--ar-base-200);
}

.music-compact__playlist-item:focus-visible {
  outline: 2px solid var(--ar-base-content);
  outline-offset: -2px;
}

.music-compact__playlist-item.is-current {
  background: var(--ar-accent);
  color: var(--ar-base-100);
  border-left-color: var(--ar-base-content);
}

.music-compact__playlist-item.is-current .music-compact__playlist-artist {
  color: var(--ar-base-100);
}

.music-compact__playlist-index {
  font-size: 0.625rem;
  font-weight: 700;
  color: var(--ar-gray-600);
  min-width: 2em;
}

.music-compact__playlist-item.is-current .music-compact__playlist-index {
  color: var(--ar-base-100);
}

.music-compact__playlist-title {
  flex: 1;
  font-weight: 700;
  text-transform: uppercase;
  font-size: 0.8125rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.music-compact__playlist-artist {
  font-size: 0.6875rem;
  color: var(--ar-gray-600);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 120px;
}

/* Attribution lives wherever the track plays — same rule the Snake
   footer and the modal's track-list credits follow. */
.music-compact__playlist-credits {
  display: block;
  padding: 10px 12px;
  border-top: 1px solid var(--ar-base-content);
  font-size: 0.625rem;
  line-height: 1.6;
  text-align: center;
  color: var(--ar-gray-600);
}

.music-compact__playlist-credits a {
  color: var(--ar-accent);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

.music-compact__playlist-credits a:hover {
  color: var(--ar-base-content);
}

.music-compact__playlist-playing {
  font-size: 0.75rem;
  animation: compact-playing-pulse 1s ease-in-out infinite;
}

@keyframes compact-playing-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .music-compact__vinyl,
  .music-compact__mini-vinyl {
    animation: none;
  }
  .music-compact.is-playing .music-compact__wave {
    animation: none;
    opacity: 0;
  }
  .music-compact__vinyl-wrap,
  .music-compact__panel,
  .music-compact__expanded-top,
  .music-compact__mini-vinyl-wrap,
  .music-compact__track-info,
  .music-compact__progress,
  .music-compact__controls {
    transition: none;
  }
  .music-compact__seek::-webkit-slider-thumb {
    transition: none;
  }
  .music-compact__control-btn {
    transition: none;
  }
}

/* Mobile: collapsed state shows only the disc — the panel (now-playing
   band + progress) costs vertical space the game wants back on small
   screens. Tapping the disc expands to the full panel; desktop keeps
   the collapsed band. Gated on pointer type, NOT width alone: embed
   iframes are 340px wide even on desktop, and media queries inside a
   frame evaluate against the frame's own viewport, so a width check
   alone would hide the band on desktop too. */
@media (max-width: 600px) and (pointer: coarse) {
  .music-compact:not(.is-expanded) .music-compact__panel {
    display: none;
  }
}