/* ==========================================================================
   Vinter Realm - Modular Seasonal Music Player (v2.5)
   Console Architecture: 2-Column Desktop + Compact Mobile
   Designed with Emil Kowalski & Apple Design principles
   ========================================================================== */

:root {
  --mp-ease: cubic-bezier(0.16, 1, 0.3, 1);
  --mp-spring: cubic-bezier(0.32, 0.72, 0, 1);
  --track-glow: var(--accent-rgb);
}

/* Base Widget Container */
.music-widget {
  position: fixed;
  right: 1.15rem;
  bottom: 1.15rem;
  z-index: 95;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
}

/* Floating Action Button (Glassmorphic Orb) */
.music-btn {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  background: radial-gradient(circle at 32% 28%, rgba(255, 255, 255, 0.28), rgba(18, 13, 31, 0.92) 75%);
  border: 1px solid rgba(var(--accent-rgb), 0.45);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.55), 0 0 16px rgba(var(--accent-rgb), 0.25);
  color: var(--soft);
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  transition: transform 140ms var(--mp-ease), border-color 200ms, box-shadow 200ms;
}

.music-btn:hover {
  transform: scale(1.06);
  border-color: var(--soft);
  box-shadow: 0 0 22px rgba(var(--accent-rgb), 0.55);
}

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

.music-btn.playing {
  border-color: var(--rose);
  box-shadow: 0 0 24px rgba(var(--accent-rgb), 0.65), inset 0 0 12px rgba(255, 255, 255, 0.16);
}

.music-ico {
  width: 22px;
  height: 22px;
  fill: currentColor;
  position: relative;
  z-index: 2;
  transition: transform 160ms var(--mp-ease);
}

.music-btn.playing .music-ico {
  transform: scale(0.92);
}

/* Circular Progress Ring on floating button */
.music-ring-svg {
  position: absolute;
  inset: -1px;
  width: calc(100% + 2px);
  height: calc(100% + 2px);
  transform: rotate(-90deg);
  pointer-events: none;
}

.music-ring-bg {
  fill: none;
  stroke: rgba(255, 255, 255, 0.08);
  stroke-width: 2.5;
}

.music-ring-val {
  fill: none;
  stroke: var(--rose);
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-dasharray: 160;
  stroke-dashoffset: 160;
  transition: stroke-dashoffset 200ms linear;
}

/* Floating Musical Notes Animation */
.music-notes {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: visible;
}

.music-note {
  position: absolute;
  left: 50%;
  top: 10%;
  font-size: 0.95rem;
  color: var(--rose);
  opacity: 0;
  transform: translate(-50%, 0);
  pointer-events: none;
}

.music-btn.playing .music-note:nth-child(1) { animation: flyNote 2.4s ease-out infinite; }
.music-btn.playing .music-note:nth-child(2) { animation: flyNote 2.4s ease-out 0.8s infinite; }
.music-btn.playing .music-note:nth-child(3) { animation: flyNote 2.4s ease-out 1.6s infinite; }

@keyframes flyNote {
  0% { opacity: 0; transform: translate(-50%, 0) scale(0.6); }
  25% { opacity: 0.9; transform: translate(calc(-50% + 8px), -18px) scale(1); }
  65% { opacity: 0.6; transform: translate(calc(-50% - 10px), -40px) scale(0.9); }
  100% { opacity: 0; transform: translate(calc(-50% + 6px), -62px) scale(0.7); }
}

html.lite .music-note, body.reduced-motion .music-note { display: none !important; }

/* ==========================================================================
   CONSOLE DRAWER PANEL (Apple Glass Console)
   ========================================================================== */
.music-drawer {
  position: absolute;
  bottom: 64px;
  right: 0;
  background: rgba(18, 13, 31, 0.94);
  backdrop-filter: blur(28px) saturate(170%);
  -webkit-backdrop-filter: blur(28px) saturate(170%);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-top: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 24px;
  box-shadow: 0 20px 52px rgba(0, 0, 0, 0.78), 0 0 28px rgba(var(--accent-rgb), 0.22);
  opacity: 0;
  visibility: hidden;
  transform: scale(0.95);
  transform-origin: bottom right;
  transition: transform 220ms var(--mp-spring), opacity 180ms ease-out, visibility 220ms;
  pointer-events: none;
  direction: rtl;
  text-align: right;
  box-sizing: border-box;
  overflow: hidden;
}

.music-widget.open .music-drawer {
  opacity: 1;
  visibility: visible;
  transform: scale(1);
  pointer-events: auto;
}

html.lite .music-drawer {
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
  background: rgba(18, 13, 31, 0.98);
}

/* ==========================================================================
   DESKTOP 2-COLUMN LAYOUT (min-width: 680px)
   ========================================================================== */
@media (min-width: 680px) {
  .music-drawer {
    width: min(630px, 92vw);
    height: min(350px, calc(100dvh - 150px));
    display: flex;
    flex-direction: row;
    padding: 0;
  }

  /* Right Column: Now Playing Stage (~44% width) */
  .music-stage-col {
    width: 44%;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    position: relative;
    padding: 1rem 1.05rem;
    background: linear-gradient(180deg, rgba(var(--track-glow), 0.14) 0%, rgba(255, 255, 255, 0.02) 100%);
    border-left: 1px solid rgba(255, 255, 255, 0.08);
    overflow: hidden;
    box-sizing: border-box;
  }

  /* Left Column: Header, Tabs, Tracklist (~56% width) */
  .music-list-col {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    padding: 1rem 1.05rem;
    box-sizing: border-box;
  }
}

/* Ambient Glow behind cover */
.music-stage-glow {
  position: absolute;
  top: 15%;
  right: 25%;
  width: 140px;
  height: 140px;
  border-radius: 50%;
  background: rgba(var(--track-glow), 0.35);
  filter: blur(34px);
  pointer-events: none;
  opacity: 0.65;
  transition: background 400ms ease, opacity 400ms ease;
  z-index: 0;
}

.music-widget.playing .music-stage-glow {
  opacity: 0.85;
  animation: glowPulse 3s ease-in-out infinite alternate;
}

@keyframes glowPulse {
  0% { transform: scale(0.9); opacity: 0.65; }
  100% { transform: scale(1.15); opacity: 0.95; }
}

html.lite .music-stage-glow, body.reduced-motion .music-stage-glow {
  animation: none !important;
}

/* Stage Cover Top Area */
.music-stage-top {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.music-stage-cover-wrap {
  position: relative;
  width: 104px;
  height: 104px;
  flex-shrink: 0;
  border-radius: 18px;
  overflow: hidden;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.65), 0 0 20px rgba(var(--track-glow), 0.35);
  border: 1px solid rgba(255, 255, 255, 0.18);
  transition: box-shadow 300ms ease, transform 300ms ease;
}

.music-widget.playing .music-stage-cover-wrap {
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.75), 0 0 26px rgba(var(--track-glow), 0.55);
}

.music-stage-cover {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Stage Info Details */
.music-stage-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.music-stage-title {
  font-size: 0.88rem;
  font-weight: 700;
  color: #ffffff;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
}

.music-stage-badge-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.15rem;
}

.music-stage-badge {
  font-size: 0.62rem;
  font-weight: 600;
  padding: 0.12rem 0.45rem;
  border-radius: 999px;
  background: rgba(var(--track-glow), 0.24);
  color: #fff;
  border: 1px solid rgba(var(--track-glow), 0.45);
  white-space: nowrap;
}

.music-stage-sub {
  font-size: 0.72rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Stage Bottom: Progress, Controls, Volume */
.music-stage-bottom {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

/* LTR Seekbar */
.music-prog-container {
  direction: ltr;
  text-align: left;
}

.music-progress-wrap {
  position: relative;
  height: 5px;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 5px;
  cursor: pointer;
  margin-bottom: 0.25rem;
  touch-action: none;
}

.music-progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--violet), var(--rose));
  border-radius: 5px;
  position: relative;
  transition: width 100ms linear;
}

.music-progress-thumb {
  position: absolute;
  right: -5px;
  top: 50%;
  transform: translateY(-50%) scale(0);
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 0 6px rgba(0, 0, 0, 0.7);
  transition: transform 140ms var(--mp-ease);
}

.music-progress-wrap:hover .music-progress-thumb {
  transform: translateY(-50%) scale(1);
}

.music-time-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.66rem;
  color: var(--muted);
  font-family: monospace;
  direction: ltr;
}

/* Controls Row */
.music-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  direction: ltr;
}

.music-ctl-btn {
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  padding: 0.35rem;
  border-radius: 50%;
  display: grid;
  place-items: center;
  touch-action: manipulation;
  transition: color 150ms, transform 120ms;
}

.music-ctl-btn svg {
  width: 17px;
  height: 17px;
  fill: currentColor;
}

.music-ctl-btn:hover {
  color: var(--soft);
  transform: scale(1.1);
}

.music-ctl-btn:active {
  transform: scale(0.92);
}

.music-ctl-btn.on {
  color: var(--rose);
}

.music-play-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--violet), var(--rose));
  color: #ffffff;
  box-shadow: 0 4px 16px rgba(var(--accent-rgb), 0.45);
}

.music-play-btn svg {
  width: 19px;
  height: 19px;
  fill: #ffffff;
}

.music-play-btn:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 20px rgba(var(--accent-rgb), 0.65);
}

/* Minimal Volume Row */
.music-vol-row {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  direction: ltr;
  padding: 0 0.15rem;
}

.music-mute-btn {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 2px;
  display: grid;
  place-items: center;
  border-radius: 4px;
  transition: color 150ms;
}

.music-mute-btn:hover {
  color: var(--text);
}

.music-mute-btn svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

.music-vol-row input[type="range"] {
  flex: 1;
  accent-color: var(--soft);
  height: 3.5px;
  cursor: pointer;
  border-radius: 4px;
}

.music-vol-badge {
  font-size: 0.64rem;
  color: var(--muted);
  min-width: 26px;
  text-align: right;
  font-family: monospace;
}

/* ==========================================================================
   LEFT COLUMN: Header, Tabs, Tracklist
   ========================================================================== */
.music-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
  padding: 0 0.2rem;
}

.music-header-title {
  font-size: 0.84rem;
  font-weight: 700;
  color: var(--soft);
}

.music-close-btn {
  background: none;
  border: none;
  color: var(--muted);
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  cursor: pointer;
  padding: 2px;
  transition: color 150ms, background 150ms, transform 120ms;
}

.music-close-btn:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.08);
}

.music-close-btn:active {
  transform: scale(0.92);
}

.music-close-btn svg {
  width: 15px;
  height: 15px;
  fill: currentColor;
}

/* Segmented Control Tabs (Single Row) */
.music-tabs {
  display: flex;
  gap: 0.25rem;
  background: rgba(255, 255, 255, 0.06);
  padding: 0.22rem;
  border-radius: 12px;
  margin-bottom: 0.55rem;
}

.music-tab {
  flex: 1;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 600;
  padding: 0.38rem 0.15rem;
  border-radius: 9px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.2rem;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  white-space: nowrap;
  transition: background 180ms, color 180ms, transform 120ms;
}

.music-tab:hover {
  color: var(--text);
}

.music-tab:active {
  transform: scale(0.96);
}

.music-tab.active {
  background: rgba(var(--accent-rgb), 0.32);
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}

/* Scrollable Tracklist */
.music-tracklist {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  overflow-y: auto;
  padding-left: 2px;
  overscroll-behavior: contain;
}

.music-tracklist::-webkit-scrollbar {
  width: 4px;
}

.music-tracklist::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.16);
  border-radius: 4px;
}

/* Tracklist Item */
.music-item {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.38rem 0.55rem;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
  cursor: pointer;
  border: 1px solid transparent;
  touch-action: manipulation;
  transition: background 150ms, border-color 150ms, transform 100ms;
}

.music-item:hover {
  background: rgba(255, 255, 255, 0.07);
}

.music-item:active {
  transform: scale(0.98);
}

.music-item.active {
  background: rgba(var(--track-glow, var(--accent-rgb)), 0.22);
  border-color: rgba(var(--track-glow, var(--accent-rgb)), 0.45);
}

.music-item-thumb {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  object-fit: cover;
  flex-shrink: 0;
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

.music-item-text {
  flex: 1;
  min-width: 0;
}

.music-item-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.35rem;
}

.music-item-title {
  font-size: 0.77rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.music-item-badge {
  font-size: 0.58rem;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.07);
  padding: 0.08rem 0.35rem;
  border-radius: 999px;
  flex-shrink: 0;
}

.music-item-desc {
  font-size: 0.67rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 0.1rem;
}

/* Live Equalizer on Active Track */
.music-item-eq {
  display: none;
  align-items: flex-end;
  gap: 2px;
  height: 12px;
  flex-shrink: 0;
}

.music-item-eq i {
  width: 2.2px;
  height: 3px;
  background: var(--rose);
  border-radius: 1px;
}

.music-widget.playing .music-item.active .music-item-eq {
  display: flex;
}

.music-widget.playing .music-item.active .music-item-eq i {
  animation: eqBarMini 0.9s ease-in-out infinite alternate;
}

.music-widget.playing .music-item.active .music-item-eq i:nth-child(2) { animation-delay: 0.22s; }
.music-widget.playing .music-item.active .music-item-eq i:nth-child(3) { animation-delay: 0.44s; }

@keyframes eqBarMini {
  0% { height: 3px; }
  100% { height: 11px; }
}

.music-item-icon {
  width: 14px;
  height: 14px;
  fill: var(--muted);
  flex-shrink: 0;
  display: grid;
  place-items: center;
}

.music-widget.playing .music-item.active .music-item-icon {
  display: none;
}

.music-item.active .music-item-icon {
  fill: var(--rose);
}

/* ==========================================================================
   MOBILE LAYOUT (max-width: 679px)
   ========================================================================== */
@media (max-width: 679px) {
  .music-drawer {
    width: min(350px, calc(100vw - 1.6rem));
    max-height: min(460px, calc(100dvh - 135px));
    display: flex;
    flex-direction: column;
    padding: 0.85rem;
  }

  /* Unbox list column on mobile so its children participate directly in flex ordering */
  .music-list-col {
    display: contents;
  }

  /* 1. Header with Title & Close (x) at the very top */
  .music-header {
    order: 1;
    width: 100%;
    margin-bottom: 0.45rem;
    flex-shrink: 0;
  }

  /* 2. Season Tabs (Single-line segmented control) */
  .music-tabs {
    order: 2;
    width: 100%;
    margin-bottom: 0.5rem;
    flex-shrink: 0;
  }

  /* 3. Now Playing Stage (Cover, Title, Seekbar, Controls, Volume) */
  .music-stage-col {
    order: 3;
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    padding: 0;
    padding-bottom: 0.55rem;
    border-left: none;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    margin-bottom: 0.5rem;
    background: none;
    position: relative;
    overflow: hidden;
    flex-shrink: 0;
  }

  .music-stage-top {
    gap: 0.65rem;
  }

  .music-stage-cover-wrap {
    width: 58px;
    height: 58px;
    border-radius: 14px;
  }

  .music-stage-title {
    font-size: 0.82rem;
    -webkit-line-clamp: 1;
  }

  /* 4. Scrollable Tracklist at the bottom */
  .music-tracklist {
    order: 4;
    flex: 1 1 auto;
    min-height: 0;
    max-height: 165px;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }
}
