/* ==========================================================================
   SAYMAWN — Cosmic Control Rail Player Styles (V2)
   Design Specification: STICKY-PLAYER-V2-DESIGN.md
   Replaces the old Player Bar v3 completely.
   ========================================================================== */

/* ---------- CSS Custom Properties (Player-Specific) ---------- */
:root {
  --player-bg: rgba(10, 10, 15, 0.98);
  --player-bg-hover: rgba(26, 26, 37, 0.8);
  --player-bg-active: rgba(107, 33, 168, 0.2);
  --player-border: rgba(255, 255, 255, 0.06);
  --player-border-hover: rgba(255, 255, 255, 0.12);
  --player-border-focus: var(--purple);
  --player-text: var(--text);
  --player-text-secondary: var(--text-secondary);
  --player-text-muted: var(--text-muted);
  --player-accent: var(--pink);
  --player-accent-hover: var(--pink-light);
  --progress-bg: rgba(255, 255, 255, 0.08);
  --progress-buffered: rgba(255, 255, 255, 0.15);
  --progress-fill: linear-gradient(90deg, var(--purple), var(--pink), var(--blue-light));
  --player-padding: 24px;
  --player-gap: 16px;
  --player-gap-sm: 8px;
  --player-gap-xs: 4px;
  --player-radius: 16px;
  --player-radius-sm: 8px;
  --player-radius-lg: 24px;
  --player-transition: 600ms cubic-bezier(0.16, 1, 0.3, 1);
  --player-transition-fast: 150ms cubic-bezier(0.16, 1, 0.3, 1);
  --player-transition-base: 250ms cubic-bezier(0.16, 1, 0.3, 1);
}

/* ---------- Screen Reader Only ---------- */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- Player Root ---------- */
.saymawn-player {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 1002;
  pointer-events: none;
}
.saymawn-player > * {
  pointer-events: auto;
}

/* ---------- Player Bar (Persistent Bottom) ---------- */
.player-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 72px;
  background: var(--player-bg);
  border-top: 1px solid var(--player-border);
  backdrop-filter: blur(20px) saturate(1.2);
  -webkit-backdrop-filter: blur(20px) saturate(1.2);
  transform: translateY(100%);
  transition: transform var(--player-transition);
  will-change: transform;
}
.player-bar.is-visible {
  transform: translateY(0);
}

/* Glow line on top */
.player-bar::before {
  content: '';
  position: absolute;
  top: -1px;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg,
    transparent 0%,
    rgba(147,51,234,0.0) 5%,
    rgba(147,51,234,0.6) 25%,
    rgba(236,72,153,0.7) 45%,
    rgba(6,182,212,0.6) 65%,
    rgba(147,51,234,0.0) 95%,
    transparent 100%);
  opacity: 0;
  transition: opacity 0.6s ease;
  pointer-events: none;
  filter: blur(0.5px);
}
.player-bar.is-visible::before {
  opacity: 1;
}

.player-bar__inner {
  display: flex;
  align-items: center;
  height: 100%;
  max-width: var(--container-max, 1200px);
  margin: 0 auto;
  padding: 0 16px;
  gap: 12px;
  position: relative;
  z-index: 1;
}

/* ---------- Top Section (Artwork + Track Info) ---------- */
.player-bar__top {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
}

/* ---------- Artwork ---------- */
.player-bar__artwork {
  position: relative;
  width: 48px;
  height: 48px;
  border-radius: var(--player-radius-sm);
  overflow: hidden;
  flex-shrink: 0;
  cursor: pointer;
  transition: transform var(--player-transition-fast);
}
.player-bar__artwork:hover {
  transform: scale(1.05);
}
.player-bar__artwork:focus-visible {
  outline: 2px solid var(--player-border-focus);
  outline-offset: 2px;
}
.player-bar__artwork-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.player-bar__artwork-fallback {
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, var(--purple) 0%, var(--pink) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255, 255, 255, 0.8);
}
.player-bar__artwork-fallback[hidden] {
  display: none;
}

/* ---------- Track Info ---------- */
.player-bar__track-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.player-bar__title {
  font-family: var(--font);
  font-size: 14px;
  font-weight: 600;
  color: var(--player-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
  margin: 0;
}
.player-bar__artist {
  font-family: var(--font);
  font-size: 12px;
  font-weight: 400;
  color: var(--player-text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.4;
  margin: 0;
}
.player-bar__album {
  font-family: var(--font);
  font-size: 11px;
  font-weight: 400;
  color: var(--player-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.4;
  margin: 0;
}

/* ---------- Timeline (hidden on mobile) ---------- */
.player-bar__timeline {
  display: none;
}
.player-bar__time {
  font-family: 'SF Mono', 'Cascadia Code', 'Consolas', monospace;
  font-size: 12px;
  color: var(--player-text-muted);
  letter-spacing: 0.1em;
  min-width: 40px;
  text-align: center;
  user-select: none;
}

/* ---------- Progress Track ---------- */
.progress-track {
  flex: 1;
  height: 4px;
  background: var(--progress-bg);
  border-radius: 9999px;
  cursor: pointer;
  position: relative;
  overflow: visible;
  transition: height var(--player-transition-fast);
}
.progress-track:hover {
  height: 6px;
  margin-top: -1px;
}
.progress-track:focus-visible {
  outline: 2px solid var(--player-border-focus);
  outline-offset: 4px;
}
.progress-buffered {
  position: absolute;
  height: 100%;
  background: var(--progress-buffered);
  border-radius: 9999px;
  pointer-events: none;
}
.progress-fill {
  position: absolute;
  height: 100%;
  background: var(--progress-fill);
  border-radius: 9999px;
  transition: width 100ms linear;
  pointer-events: none;
  box-shadow: 0 0 8px rgba(147,51,234,0.3);
}
.progress-thumb {
  position: absolute;
  width: 12px;
  height: 12px;
  background: var(--white);
  border-radius: 50%;
  top: 50%;
  transform: translate(-50%, -50%) scale(0);
  transition: transform var(--player-transition-fast);
  pointer-events: none;
  box-shadow: 0 2px 8px rgba(147,51,234,0.5);
}
.progress-track:hover .progress-thumb,
.progress-track:focus-visible .progress-thumb,
.progress-track.is-seeking .progress-thumb {
  transform: translate(-50%, -50%) scale(1);
}

/* ---------- Controls ---------- */
.player-bar__controls {
  display: none;
}
.player-bar__controls--primary {
  display: flex;
  align-items: center;
  gap: 8px;
}
.player-bar__controls--secondary {
  display: none;
}

/* ---------- Buttons ---------- */
.player-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--player-text-secondary);
  cursor: pointer;
  padding: 8px;
  border-radius: 9999px;
  transition: all var(--player-transition-fast);
  min-width: 44px;
  min-height: 44px;
  position: relative;
}
.player-btn:hover {
  color: var(--player-text);
  background: var(--player-bg-hover);
}
.player-btn:focus-visible {
  outline: 2px solid var(--player-border-focus);
  outline-offset: 2px;
}
.player-btn:active {
  transform: scale(0.95);
}
.player-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}
.player-btn svg {
  width: 18px;
  height: 18px;
}

/* Play Button (Special) */
.player-btn--play {
  background: var(--player-accent);
  color: var(--white);
  width: 44px;
  height: 44px;
}
.player-btn--play:hover {
  background: var(--player-accent-hover);
  transform: scale(1.05);
}
.player-btn--play:active {
  transform: scale(0.95);
}
.player-btn--play svg {
  width: 22px;
  height: 22px;
}

/* Button States */
.player-btn.is-active {
  color: var(--player-accent);
}
.player-btn[aria-pressed="true"] {
  color: var(--player-accent);
}

/* ---------- Right Section (Mobile) ---------- */
.player-bar__right {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ---------- Volume (Hidden on Mobile) ---------- */
.player-bar__volume {
  display: none;
}
.volume-slider {
  width: 80px;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--progress-bg);
  border-radius: 9999px;
  cursor: pointer;
  outline: none;
}
.volume-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--white);
  cursor: pointer;
  transition: transform var(--player-transition-fast);
}
.volume-slider::-webkit-slider-thumb:hover {
  transform: scale(1.2);
}
.volume-slider::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--white);
  border: none;
  cursor: pointer;
}
.volume-slider:focus-visible {
  outline: 2px solid var(--player-border-focus);
  outline-offset: 4px;
}

/* ---------- Mobile Progress Bar ---------- */
.player-bar__progress-mobile {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--progress-bg);
  pointer-events: none;
}
.progress-fill-mobile {
  height: 100%;
  background: var(--progress-fill);
  transition: width 100ms linear;
  pointer-events: none;
}

/* ---------- Expanded Player ---------- */
.player-expanded {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: all var(--player-transition);
  pointer-events: none;
}
.player-expanded.is-visible {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}
.player-expanded__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(10, 10, 15, 0.98);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}
.player-expanded__content {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 24px;
  max-width: 400px;
  width: 100%;
}
.player-expanded__close {
  position: absolute;
  top: 24px;
  left: 24px;
  background: none;
  border: none;
  color: var(--player-text-secondary);
  cursor: pointer;
  padding: 8px;
  border-radius: 9999px;
  transition: all var(--player-transition-fast);
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.player-expanded__close:hover {
  color: var(--player-text);
  background: var(--player-bg-hover);
}
.player-expanded__close:focus-visible {
  outline: 2px solid var(--player-border-focus);
  outline-offset: 2px;
}

/* ---------- Expanded Artwork ---------- */
.player-expanded__artwork {
  width: 280px;
  height: 280px;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
  position: relative;
}
.player-expanded__artwork-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.player-expanded__artwork-fallback {
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, var(--purple) 0%, var(--pink) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255, 255, 255, 0.8);
}
.player-expanded__artwork-fallback[hidden] {
  display: none;
}

/* ---------- Expanded Track Info ---------- */
.player-expanded__track-info {
  text-align: center;
  width: 100%;
}
.player-expanded__title {
  font-family: var(--font);
  font-size: 24px;
  font-weight: 600;
  color: var(--player-text);
  margin: 0 0 4px 0;
  line-height: 1.1;
}
.player-expanded__artist {
  font-family: var(--font);
  font-size: 16px;
  font-weight: 400;
  color: var(--player-text-secondary);
  margin: 0;
  line-height: 1.4;
}
.player-expanded__album {
  font-family: var(--font);
  font-size: 14px;
  font-weight: 400;
  color: var(--player-text-muted);
  margin: 0;
  line-height: 1.4;
}

/* ---------- Expanded Timeline ---------- */
.player-expanded__timeline {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  max-width: 350px;
}
.player-expanded__time {
  font-family: 'SF Mono', 'Cascadia Code', 'Consolas', monospace;
  font-size: 12px;
  color: var(--player-text-muted);
  letter-spacing: 0.1em;
  min-width: 40px;
  text-align: center;
  user-select: none;
}
.progress-track--expanded {
  height: 6px;
}
.progress-track--expanded:hover {
  height: 8px;
}
.progress-track--expanded .progress-thumb {
  width: 16px;
  height: 16px;
}

/* ---------- Expanded Controls ---------- */
.player-expanded__controls {
  display: flex;
  align-items: center;
  gap: 16px;
}
.player-expanded__controls--primary {
  gap: 16px;
}
.player-expanded__controls--secondary {
  gap: 16px;
}
.player-expanded__controls .player-btn--play {
  width: 64px;
  height: 64px;
}
.player-expanded__controls .player-btn--play svg {
  width: 32px;
  height: 32px;
}
.player-expanded__controls .player-btn svg {
  width: 24px;
  height: 24px;
}

/* ---------- Expanded Volume ---------- */
.player-expanded__volume {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  max-width: 300px;
}
.volume-slider--expanded {
  width: 100%;
}

/* ---------- Expanded Extras ---------- */
.player-expanded__extras {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-top: 16px;
}

/* ---------- Queue Panel ---------- */
.player-queue {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 320px;
  max-width: 90vw;
  background: var(--player-bg);
  border-left: 1px solid var(--player-border);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  z-index: 1001;
  transform: translateX(100%);
  transition: transform var(--player-transition);
  display: flex;
  flex-direction: column;
  pointer-events: auto;
}
.player-queue.is-visible {
  transform: translateX(0);
}
.player-queue__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid var(--player-border);
}
.player-queue__title {
  font-family: var(--font);
  font-size: 18px;
  font-weight: 600;
  color: var(--player-text);
  margin: 0;
}
.player-queue__header .player-btn {
  color: rgba(255, 255, 255, 0.6);
  min-width: 36px;
  min-height: 36px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 8px;
}
.player-queue__header .player-btn:hover {
  color: rgba(255, 255, 255, 0.95);
  background: rgba(255, 255, 255, 0.12);
}
.player-queue__list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

/* Queue Item */
.queue-item {
  display: flex;
  flex-direction: row-reverse;
  align-items: center;
  gap: 12px;
  padding: 8px;
  border-radius: 8px;
  cursor: pointer;
  transition: background var(--player-transition-fast);
}
.queue-item:hover {
  background: var(--player-bg-hover);
}
.queue-item.is-active {
  background: var(--player-bg-active);
}
.queue-item__artwork {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  overflow: hidden;
  flex-shrink: 0;
}
.queue-item__artwork img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.queue-item__info {
  flex: 1;
  min-width: 0;
  text-align: right;
}
.queue-item__title {
  font-family: var(--font);
  font-size: 14px;
  font-weight: 600;
  color: var(--player-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
}
.queue-item__artist {
  font-family: var(--font);
  font-size: 12px;
  color: var(--player-text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
}

/* ---------- Artwork Transitions ---------- */
.player-bar__artwork.transitioning,
.player-expanded__artwork.transitioning {
  animation: artwork-change 350ms cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes artwork-change {
  0% { transform: scale(1); opacity: 1; }
  40% { transform: scale(0.95); opacity: 0; }
  60% { transform: scale(0.95); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

/* ---------- Loading State ---------- */
.player-bar__artwork[data-loading="true"],
.player-expanded__artwork[data-loading="true"] {
  animation: artwork-shimmer 1.5s infinite;
}
@keyframes artwork-shimmer {
  0% { opacity: 0.6; }
  50% { opacity: 0.8; }
  100% { opacity: 0.6; }
}

/* ---------- Reduced Motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ==========================================================================
   RESPONSIVE BREAKPOINTS
   ========================================================================== */

/* Tablet: 768px — 1023px */
@media (min-width: 768px) and (max-width: 1023px) {
  .player-bar {
    height: 80px;
  }
  .player-bar__inner {
    padding: 0 24px;
  }
  .player-bar__top {
    flex: 0 1 240px;
  }
  .player-bar__artwork {
    width: 56px;
    height: 56px;
  }
  .player-bar__title {
    font-size: 16px;
  }
  .player-bar__artist {
    font-size: 14px;
  }
  .player-bar__timeline {
    display: flex;
    flex: 1;
    align-items: center;
    gap: 12px;
    max-width: 600px;
  }
  .player-bar__controls--primary {
    display: flex;
  }
  .player-bar__controls--secondary {
    display: flex;
    align-items: center;
    gap: 16px;
  }
  .player-bar__volume {
    display: flex;
    align-items: center;
    gap: 8px;
  }
  .player-bar__right {
    display: none;
  }
  .player-expanded__artwork {
    width: 300px;
    height: 300px;
  }
}

/* Desktop: 1024px+ */
@media (min-width: 1024px) {
  .player-bar {
    height: 80px;
  }
  .player-bar__inner {
    padding: 0 24px;
  }
  .player-bar__top {
    flex: 0 1 280px;
  }
  .player-bar__artwork {
    width: 56px;
    height: 56px;
  }
  .player-bar__title {
    font-size: 15px;
  }
  .player-bar__artist {
    font-size: 13px;
  }
  .player-bar__timeline {
    display: flex;
    flex: 1;
    align-items: center;
    gap: 12px;
    max-width: 700px;
  }
  .player-bar__controls--primary {
    display: flex;
    gap: 8px;
  }
  .player-bar__controls--secondary {
    display: flex;
    align-items: center;
    gap: 12px;
  }
  .player-bar__volume {
    display: flex;
    align-items: center;
    gap: 8px;
  }
  .player-bar__right {
    display: none;
  }
  .player-expanded__artwork {
    width: 300px;
    height: 300px;
  }
}

/* Mobile: < 640px */
@media (max-width: 639px) {
  .player-bar {
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .player-bar__inner {
    padding: 8px 12px;
    gap: 10px;
  }
  .player-bar__artwork {
    width: 42px;
    height: 42px;
    border-radius: 10px;
  }
  .player-bar__title {
    font-size: 0.8rem;
  }
  .player-bar__artist {
    font-size: 0.65rem;
  }
  /* Hide desktop-only elements */
  .player-bar__timeline { display: none; }
  .player-bar__controls--primary { display: none; }
  .player-bar__controls--secondary { display: none; }
  .player-bar__volume { display: none; }
  .player-bar__right { display: none; }
  /* Mobile progress bar */
  .player-bar__progress-mobile {
    display: block;
  }
  /* Mobile controls */
  .player-bar__mobile-controls {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
  }
  /* Mobile play button */
  .player-bar__play-mobile {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    flex-shrink: 0;
    background: linear-gradient(135deg, var(--purple), var(--pink));
    border: none;
    border-radius: 50%;
    color: var(--white);
    cursor: pointer;
    box-shadow: 0 2px 12px rgba(147,51,234,0.3);
  }
  /* Mobile expand button */
  .player-bar__expand-mobile {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    flex-shrink: 0;
    background: rgba(255,255,255,0.06);
    border: none;
    border-radius: 50%;
    color: var(--player-text-secondary);
    cursor: pointer;
  }
  .player-expanded__artwork {
    width: 240px;
    height: 240px;
  }
  .player-expanded__controls {
    gap: 12px;
  }
  .player-queue {
    width: 100%;
    max-width: 100vw;
  }
}

/* Hide mobile elements on desktop */
@media (min-width: 640px) {
  .player-bar__play-mobile { display: none; }
  .player-bar__expand-mobile { display: none; }
  .player-bar__mobile-controls { display: none; }
  .player-bar__progress-mobile-wrap { display: none; }
}

/* Desktop controls hidden on mobile */
@media (max-width: 639px) {
  .player-bar__progress-mobile-wrap {
    display: block;
    width: 100%;
    padding: 0 0 2px;
  }
}
