/* =========================================================
   Port Q-style glass vinyl — side-dock, half-peek, spin + notes
   z-index 45: above desktop, below modals
   ========================================================= */

.port-music {
  --pm-ease: var(--ease, cubic-bezier(0.22, 1, 0.36, 1));
  --pm-surface: rgba(255, 255, 255, 0.78);
  --pm-surface-strong: rgba(255, 255, 255, 0.92);
  --pm-border: rgba(30, 40, 70, 0.12);
  --pm-text: var(--text, #1a2236);
  --pm-muted: var(--text-muted, rgba(26, 34, 54, 0.58));
  --pm-accent: var(--accent, #3d9b8f);
  --pm-accent-soft: var(--accent-soft, rgba(61, 155, 143, 0.14));
  /* Disc size scales with viewport */
  --pm-disc: clamp(52px, 8.5vmin, 72px);
  --pm-peek: 0.52; /* how much of the disc sticks out when docked */

  position: fixed;
  z-index: 45;
  top: 0;
  left: 0;
  width: 0;
  height: 0;
  pointer-events: none;
  font-family: var(--font-sans, system-ui, sans-serif);
  color: var(--pm-text);
  outline: none;
}

.port-music * {
  box-sizing: border-box;
}

/* Anchor: position set by JS (translate) */
.port-music__anchor {
  position: fixed;
  pointer-events: none;
  width: 0;
  height: 0;
  z-index: 45;
}

/* Smooth edge-snap / panel de-clip when not following the finger */
.port-music:not(.is-dragging) .port-music__anchor {
  transition:
    left 0.35s var(--pm-ease),
    top 0.35s var(--pm-ease);
}

.port-music__cluster {
  position: absolute;
  display: flex;
  align-items: center;
  gap: 10px;
  pointer-events: none;
  /* default right-side: panel left of disc */
  flex-direction: row;
  transform: translate(0, -50%);
}

.port-music[data-side="left"] .port-music__cluster {
  flex-direction: row-reverse;
}

/* ---------- Q glass vinyl ---------- */

.port-music__vinyl {
  pointer-events: auto;
  position: relative;
  flex: 0 0 auto;
  width: var(--pm-disc);
  height: var(--pm-disc);
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
  cursor: grab;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  /* Peek: shift so only ~half+ sits on-screen */
  transition: transform 0.45s var(--pm-ease);
}

.port-music[data-side="right"] .port-music__vinyl {
  /* hide left portion off the right edge → show right half+ */
  transform: translateX(calc(var(--pm-disc) * (1 - var(--pm-peek))));
}

.port-music[data-side="left"] .port-music__vinyl {
  transform: translateX(calc(var(--pm-disc) * (var(--pm-peek) - 1)));
}

/* When expanded or dragging, show full disc */
.port-music.is-expanded .port-music__vinyl,
.port-music.is-dragging .port-music__vinyl {
  transform: translateX(0) !important;
}

.port-music.is-dragging .port-music__vinyl {
  cursor: grabbing;
  transition: none;
}

.port-music__vinyl:focus-visible .port-music__vinyl-disc {
  box-shadow:
    0 0 0 3px rgba(61, 155, 143, 0.4),
    0 12px 28px rgba(40, 60, 100, 0.2),
    0 1px 0 rgba(255, 255, 255, 0.85) inset;
}

/* Soft glass / neumorph disc — thin dark rim so it reads on light wallpapers */
.port-music__vinyl-disc {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background:
    radial-gradient(circle at 32% 28%, rgba(255, 255, 255, 0.75), transparent 42%),
    radial-gradient(circle at 70% 75%, rgba(61, 155, 143, 0.18), transparent 50%),
    linear-gradient(145deg, rgba(255, 255, 255, 0.92), rgba(230, 236, 246, 0.82) 48%, rgba(210, 220, 235, 0.75));
  /* Outer dark hairline + soft white inner edge (not thick) */
  border: 1.5px solid rgba(28, 34, 52, 0.55);
  box-shadow:
    0 0 0 1px rgba(28, 34, 52, 0.22),
    0 10px 26px rgba(40, 60, 100, 0.16),
    0 1px 0 rgba(255, 255, 255, 0.75) inset,
    0 -1px 4px rgba(30, 40, 70, 0.08) inset;
  overflow: hidden;
  will-change: transform;
}

/* Groove rings — subtle */
.port-music__vinyl-groove {
  position: absolute;
  inset: 10%;
  border-radius: 50%;
  background:
    repeating-radial-gradient(
      circle at 50% 50%,
      transparent 0 3px,
      rgba(30, 40, 70, 0.045) 3px 4px
    );
  mask-image: radial-gradient(circle, transparent 22%, #000 24%, #000 92%, transparent 94%);
  -webkit-mask-image: radial-gradient(circle, transparent 22%, #000 24%, #000 92%, transparent 94%);
  pointer-events: none;
}

/* Center hub — pure decorative, no title text */
.port-music__vinyl-hub {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 28%;
  height: 28%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background:
    radial-gradient(circle at 35% 30%, rgba(255, 255, 255, 0.95), transparent 55%),
    linear-gradient(160deg, #6ecfc0, #3d9b8f 60%, #2f7d73);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.55) inset,
    0 3px 8px rgba(30, 50, 80, 0.2);
  pointer-events: none;
}

.port-music__vinyl-hub::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 22%;
  height: 22%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.85);
  box-shadow: 0 0 0 1px rgba(30, 40, 70, 0.08);
}

/* Spin only while playing */
.port-music.is-playing .port-music__vinyl-disc {
  animation: pm-spin 5.2s linear infinite;
}

@keyframes pm-spin {
  to {
    transform: rotate(360deg);
  }
}

/* ---------- Floating notes (playing only) — multi-dir, small, soft colors ---------- */

.port-music__notes {
  position: absolute;
  /* Allow notes toward screen center / down without huge travel */
  inset: -40% -50%;
  pointer-events: none;
  overflow: visible;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.port-music.is-playing .port-music__notes {
  opacity: 1;
}

.port-music__note {
  position: absolute;
  left: 50%;
  top: 50%;
  /* Travel distance: short, relative to disc */
  --nx: 0px;
  --ny: -28px;
  --nrot: 10deg;
  color: rgba(61, 155, 143, 0.72);
  /* Mobile min ~13px; PC up to ~20px */
  font-size: clamp(13px, 3.2vmin, 20px);
  font-weight: 700;
  line-height: 1;
  opacity: 0;
  filter: drop-shadow(0 1px 2px rgba(255, 255, 255, 0.55));
  animation: pm-note-fly 2.6s ease-out infinite;
  animation-play-state: paused;
  will-change: transform, opacity;
}

.port-music.is-playing .port-music__note {
  animation-play-state: running;
}

/* Variants: glyph + palette + direction (short hops) */
.port-music__note--up {
  --nx: 12px;
  --ny: -40px;
  --nrot: -12deg;
  left: 42%;
  top: 40%;
  animation-delay: 0s;
  animation-duration: 2.5s;
  color: rgba(45, 145, 132, 0.78);
  font-size: clamp(14px, 3.4vmin, 21px);
}

.port-music__note--up2 {
  --nx: -10px;
  --ny: -34px;
  --nrot: 14deg;
  left: 58%;
  top: 36%;
  animation-delay: 1.1s;
  animation-duration: 2.8s;
  color: rgba(95, 130, 200, 0.72);
  font-size: clamp(12px, 2.9vmin, 17px);
}

/* Toward screen center (horizontal bias depends on dock side) */
.port-music__note--mid {
  --nx: -38px;
  --ny: -6px;
  --nrot: 8deg;
  left: 48%;
  top: 48%;
  animation-delay: 0.45s;
  animation-duration: 2.4s;
  color: rgba(200, 110, 150, 0.7);
  font-size: clamp(13px, 3.1vmin, 19px);
}

.port-music__note--mid2 {
  --nx: -32px;
  --ny: 12px;
  --nrot: -10deg;
  left: 52%;
  top: 54%;
  animation-delay: 1.55s;
  animation-duration: 2.7s;
  color: rgba(140, 110, 200, 0.68);
  font-size: clamp(12px, 2.8vmin, 17px);
}

/* Soft downward drift */
.port-music__note--down {
  --nx: 14px;
  --ny: 36px;
  --nrot: 16deg;
  left: 40%;
  top: 58%;
  animation-delay: 0.85s;
  animation-duration: 2.6s;
  color: rgba(70, 150, 190, 0.72);
  font-size: clamp(13px, 3vmin, 18px);
}

.port-music__note--down2 {
  --nx: -12px;
  --ny: 32px;
  --nrot: -14deg;
  left: 56%;
  top: 60%;
  animation-delay: 1.9s;
  animation-duration: 2.9s;
  color: rgba(210, 140, 90, 0.68);
  font-size: clamp(12px, 2.9vmin, 17px);
}

/* Right dock: center of screen is to the left → notes drift leftward for "mid" */
.port-music[data-side="right"] .port-music__note--mid {
  --nx: -36px;
}
.port-music[data-side="right"] .port-music__note--mid2 {
  --nx: -30px;
}
.port-music[data-side="right"] .port-music__note--up {
  --nx: -6px;
}
.port-music[data-side="right"] .port-music__note--up2 {
  --nx: -14px;
}
.port-music[data-side="right"] .port-music__note--down {
  --nx: -8px;
}
.port-music[data-side="right"] .port-music__note--down2 {
  --nx: -16px;
}

/* Left dock: center is to the right */
.port-music[data-side="left"] .port-music__note--mid {
  --nx: 36px;
}
.port-music[data-side="left"] .port-music__note--mid2 {
  --nx: 30px;
}
.port-music[data-side="left"] .port-music__note--up {
  --nx: 8px;
}
.port-music[data-side="left"] .port-music__note--up2 {
  --nx: 14px;
}
.port-music[data-side="left"] .port-music__note--down {
  --nx: 10px;
}
.port-music[data-side="left"] .port-music__note--down2 {
  --nx: 16px;
}

@keyframes pm-note-fly {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.72) rotate(calc(var(--nrot) * -0.6));
  }
  14% {
    opacity: 0.92;
  }
  55% {
    opacity: 0.72;
  }
  100% {
    opacity: 0;
    transform: translate(
        calc(-50% + var(--nx)),
        calc(-50% + var(--ny))
      )
      scale(1.08)
      rotate(var(--nrot));
  }
}

/* ---------- Glass playlist panel ---------- */

.port-music__panel {
  pointer-events: none;
  width: min(300px, calc(100vw - 96px));
  max-height: 0;
  opacity: 0;
  transform: scale(0.94) translateY(6px);
  transform-origin: var(--pm-panel-origin, right center);
  overflow: hidden;
  transition:
    max-height 0.4s var(--pm-ease),
    opacity 0.26s var(--pm-ease),
    transform 0.36s var(--pm-ease);
}

.port-music[data-side="right"] {
  --pm-panel-origin: right center;
}

.port-music[data-side="left"] {
  --pm-panel-origin: left center;
}

.port-music.is-expanded .port-music__panel {
  pointer-events: auto;
  max-height: min(420px, calc(100dvh - 120px));
  opacity: 1;
  transform: none;
}

.port-music__panel-card {
  display: flex;
  flex-direction: column;
  min-height: 0;
  max-height: min(420px, calc(100dvh - 120px));
  padding: 12px 12px 10px;
  border-radius: 18px;
  background: var(--pm-surface-strong);
  border: 1px solid var(--pm-border);
  box-shadow:
    0 18px 44px rgba(30, 45, 80, 0.15),
    0 1px 0 rgba(255, 255, 255, 0.9) inset;
  backdrop-filter: blur(22px) saturate(155%);
  -webkit-backdrop-filter: blur(22px) saturate(155%);
}

.port-music__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.port-music__now {
  min-width: 0;
  flex: 1 1 auto;
}

.port-music__now-title {
  font-size: 0.88rem;
  font-weight: 650;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.port-music__now-artist {
  margin-top: 2px;
  font-size: 0.72rem;
  color: var(--pm-muted);
}

.port-music__icon-btn {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  margin: 0;
  padding: 0;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--pm-text);
  cursor: pointer;
  transition: background 0.2s var(--pm-ease), transform 0.15s var(--pm-ease);
}

.port-music__icon-btn:hover {
  background: rgba(30, 40, 70, 0.07);
}

.port-music__icon-btn:focus-visible,
.port-music__track:focus-visible {
  outline: 2px solid var(--pm-accent);
  outline-offset: 2px;
}

.port-music__icon-btn:active {
  transform: scale(0.94);
}

.port-music__icon-btn--play {
  width: 42px;
  height: 42px;
  background: var(--pm-accent-soft);
  color: var(--pm-accent);
}

.port-music__progress-wrap {
  margin-bottom: 8px;
}

.port-music__progress {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  margin: 0;
  border-radius: 999px;
  background: rgba(30, 40, 70, 0.1);
  outline: none;
  cursor: pointer;
}

.port-music__progress::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--pm-accent);
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(30, 50, 80, 0.25);
  cursor: pointer;
}

.port-music__progress::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--pm-accent);
  border: 2px solid #fff;
  cursor: pointer;
}

.port-music__time-row {
  display: flex;
  justify-content: space-between;
  margin-top: 4px;
  font-size: 0.64rem;
  font-variant-numeric: tabular-nums;
  color: var(--pm-muted);
}

.port-music__controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  margin-bottom: 8px;
}

.port-music__volume {
  display: flex;
  align-items: center;
  gap: 5px;
  flex: 1 1 auto;
  min-width: 0;
  max-width: 100px;
  margin-left: 4px;
  color: var(--pm-muted);
}

.port-music__volume-slider {
  -webkit-appearance: none;
  appearance: none;
  flex: 1 1 auto;
  min-width: 0;
  height: 3px;
  border-radius: 999px;
  background: rgba(30, 40, 70, 0.12);
  outline: none;
  cursor: pointer;
}

.port-music__volume-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--pm-text);
  border: 2px solid #fff;
  cursor: pointer;
}

.port-music__list-label {
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--pm-muted);
  letter-spacing: 0.03em;
  padding: 0 4px 6px;
}

.port-music__list {
  list-style: none;
  margin: 0;
  padding: 0 2px 2px;
  overflow-y: auto;
  min-height: 0;
  flex: 1 1 auto;
  max-height: min(200px, 34dvh);
  scrollbar-width: thin;
  scrollbar-color: rgba(30, 40, 70, 0.2) transparent;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.port-music__track {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  margin: 0 0 2px;
  padding: 8px;
  border: none;
  border-radius: 11px;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background 0.18s var(--pm-ease);
}

.port-music__track:hover {
  background: rgba(30, 40, 70, 0.06);
}

.port-music__track.is-active {
  background: var(--pm-accent-soft);
}

.port-music__track-index {
  flex: 0 0 1.2em;
  font-size: 0.7rem;
  color: var(--pm-muted);
  font-variant-numeric: tabular-nums;
}

.port-music__track.is-active .port-music__track-index {
  color: var(--pm-accent);
  font-weight: 700;
}

.port-music__track-info {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.port-music__track-title {
  font-size: 0.78rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.port-music__track.is-active .port-music__track-title {
  font-weight: 650;
  color: var(--pm-accent);
}

.port-music__track-artist {
  font-size: 0.66rem;
  color: var(--pm-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.port-music__empty {
  padding: 12px;
  font-size: 0.76rem;
  color: var(--pm-muted);
  text-align: center;
}

/* ---------- Responsive ---------- */

@media (max-width: 720px) {
  .port-music {
    --pm-disc: clamp(48px, 12vw, 60px);
    --pm-peek: 0.54;
  }

  .port-music__panel {
    width: min(280px, calc(100vw - 80px));
  }
}

@media (max-width: 420px) {
  .port-music {
    --pm-disc: clamp(46px, 13vw, 56px);
    --pm-peek: 0.55;
  }

  .port-music__panel {
    width: min(260px, calc(100vw - 72px));
  }

  .port-music__list {
    max-height: min(160px, 30dvh);
  }

  .port-music__volume {
    max-width: 70px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .port-music__vinyl,
  .port-music__panel,
  .port-music__icon-btn,
  .port-music__track,
  .port-music:not(.is-dragging) .port-music__anchor {
    transition: none;
  }

  .port-music.is-playing .port-music__vinyl-disc {
    animation: none;
  }

  .port-music__note {
    animation: none !important;
    opacity: 0 !important;
  }
}
