/* ============================================================
   MusicExport Player — Telegram Mini App
   Redesigned: layered frosted-glass dark music player
   ============================================================ */

/* ============================================================
   Telegram theme variable bridge + design tokens
   ============================================================ */

:root {
  /* Telegram theme passthrough */
  --tg-bg:           var(--tg-theme-bg-color, #121212);
  --tg-text:         var(--tg-theme-text-color, #ffffff);
  --tg-hint:         var(--tg-theme-hint-color, #8a8a8e);
  --tg-link:         var(--tg-theme-link-color, #0a84ff);
  --tg-button:       var(--tg-theme-button-color, #0a84ff);
  --tg-button-text:  var(--tg-theme-button-text-color, #ffffff);
  --tg-secondary-bg: var(--tg-theme-secondary-bg-color, #1c1c1e);

  /* Derived surface system */
  --surface-0:  var(--tg-bg);
  --surface-1:  var(--tg-secondary-bg);
  --surface-2:  color-mix(in srgb, var(--tg-secondary-bg) 70%, #ffffff 8%);
  --surface-3:  color-mix(in srgb, var(--tg-secondary-bg) 50%, #ffffff 14%);

  /* Accent */
  --accent:        var(--tg-button);
  --accent-text:   var(--tg-button-text);
  --accent-glow:   color-mix(in srgb, var(--tg-button) 40%, transparent);
  --accent-subtle: color-mix(in srgb, var(--tg-button) 12%, transparent);

  /* Danger */
  --danger: #ff3b30;

  /* Typography scale */
  --font-xs:   11px;
  --font-sm:   13px;
  --font-base: 15px;
  --font-md:   17px;
  --font-lg:   20px;
  --font-xl:   24px;
  --font-2xl:  28px;

  /* Spacing */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;

  /* Radius */
  --r-sm:   8px;
  --r-md:   12px;
  --r-lg:   16px;
  --r-xl:   20px;
  --r-full: 9999px;

  /* Shadows */
  --shadow-sm: 0 1px 4px rgba(0,0,0,0.25);
  --shadow-md: 0 4px 20px rgba(0,0,0,0.4);
  --shadow-lg: 0 12px 48px rgba(0,0,0,0.6);
  --shadow-glow: 0 0 32px var(--accent-glow);

  /* Transitions */
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --dur-fast:   160ms;
  --dur-base:   240ms;
  --dur-slow:   380ms;

  /* Layout */
  --header-h: 52px;
  --bar-h:    64px;
  --max-w:    480px;

  /* Separator */
  --sep: 1px solid rgba(255,255,255,0.06);
}

/* ============================================================
   Reset & base
   ============================================================ */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html {
  height: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  height: 100%;
  width: 100%;
  overflow: hidden;
  background-color: var(--surface-0);
  color: var(--tg-text);
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Helvetica Neue', sans-serif;
  font-size: var(--font-base);
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  max-width: var(--max-w);
  margin: 0 auto;
  position: relative;
}

/* ============================================================
   Utility
   ============================================================ */

.hidden {
  display: none !important;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
}

.truncate {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ============================================================
   Navigation header & tabs
   ============================================================ */

.nav-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  background: var(--surface-0);
  border-bottom: var(--sep);
  max-width: var(--max-w);
  margin: 0 auto;
  /* Subtle frosted glass lift */
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.donate-btn {
  background: none;
  border: none;
  color: var(--tg-theme-link-color, #2481cc);
  font-size: 13px;
  font-weight: 500;
  padding: 6px 12px;
  cursor: pointer;
  white-space: nowrap;
  border-radius: 8px;
  transition: background 0.15s;
  flex-shrink: 0;
}

.donate-btn:active {
  background: var(--tg-theme-secondary-bg-color, rgba(0,0,0,0.05));
}

.tabs {
  display: flex;
  height: var(--header-h);
  position: relative;
}

.tab {
  flex: 1;
  background: none;
  border: none;
  cursor: pointer;
  font-size: var(--font-base);
  font-weight: 500;
  color: var(--tg-hint);
  position: relative;
  padding: 0 var(--sp-4);
  letter-spacing: -0.01em;
  transition: color var(--dur-base) var(--ease-out);
  min-height: 44px;
}

/* Active indicator — animated pill sliding underline */
.tab::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 20%;
  right: 20%;
  height: 2px;
  background: var(--accent);
  border-radius: var(--r-full);
  opacity: 0;
  transform: scaleX(0.4);
  transition:
    opacity var(--dur-base) var(--ease-out),
    transform var(--dur-base) var(--ease-out);
}

.tab.active {
  color: var(--tg-text);
  font-weight: 600;
}

.tab.active::after {
  opacity: 1;
  transform: scaleX(1);
}

.tab:active {
  opacity: 0.6;
}

/* ============================================================
   Main content area
   ============================================================ */

.main-content {
  position: fixed;
  top: var(--header-h);
  left: 0;
  right: 0;
  bottom: 0;
  max-width: var(--max-w);
  margin: 0 auto;
  overflow: hidden;
}

/* ============================================================
   Screens
   Screen visibility is controlled by .hidden class (app.js)
   Default state: flex (visible), hidden state: display:none
   ============================================================ */

.screen {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  /* Bottom padding: bar + safe area + breathing room */
  padding-bottom: calc(var(--bar-h) + env(safe-area-inset-bottom, 0px) + var(--sp-4));
  scroll-behavior: smooth;
}

/* Fade-in when a screen becomes visible */
.screen:not(.hidden) {
  animation: screenFadeIn var(--dur-base) var(--ease-out) both;
}

@keyframes screenFadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ============================================================
   Screen action bars (top of each screen)
   ============================================================ */

.screen-actions {
  display: flex;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  background: var(--surface-0);
  border-bottom: var(--sep);
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 10;
}

/* ============================================================
   Buttons
   ============================================================ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  height: 40px;
  padding: 0 var(--sp-5);
  border-radius: var(--r-full);
  font-size: var(--font-sm);
  font-weight: 600;
  letter-spacing: 0.01em;
  cursor: pointer;
  border: none;
  white-space: nowrap;
  transition:
    transform var(--dur-fast) var(--ease-out),
    opacity var(--dur-fast) ease;
  -webkit-user-select: none;
  user-select: none;
}

.btn:active {
  transform: scale(0.94);
  opacity: 0.82;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-text);
  box-shadow: 0 2px 12px var(--accent-glow);
}

.btn-secondary {
  background: var(--surface-2);
  color: var(--tg-text);
  border: 1px solid rgba(255,255,255,0.08);
}

.btn-danger {
  background: rgba(255, 59, 48, 0.15);
  color: var(--danger);
  border: 1px solid rgba(255, 59, 48, 0.25);
}

.btn-full {
  width: 100%;
}

.btn-icon {
  background: none;
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--tg-text);
  border-radius: 50%;
  transition:
    background-color var(--dur-fast) ease,
    opacity var(--dur-fast) ease,
    transform var(--dur-fast) var(--ease-out);
  min-width: 44px;
  min-height: 44px;
  font-size: 18px;
  line-height: 1;
}

.btn-icon:active {
  opacity: 0.5;
  transform: scale(0.88);
}

.btn-back {
  background: none;
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  padding: var(--sp-2);
  min-width: 44px;
  min-height: 44px;
  border-radius: 50%;
  transition: opacity var(--dur-fast) ease, transform var(--dur-fast) var(--ease-out);
}

.btn-back:active {
  opacity: 0.6;
  transform: scale(0.88) translateX(-2px);
}

/* ============================================================
   Track list
   ============================================================ */

.track-list {
  flex: 1;
}

/* Each track row */
.track-item {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  min-height: 64px;
  padding: var(--sp-3) var(--sp-4);
  gap: var(--sp-3);
  cursor: pointer;
  border-bottom: var(--sep);
  transition: background-color var(--dur-fast) ease;
  -webkit-user-select: none;
  user-select: none;
  position: relative;
}

/* Left ripple accent on active/playing track */
.track-item::before {
  content: '';
  position: absolute;
  left: 0;
  top: 12px;
  bottom: 12px;
  width: 3px;
  border-radius: 0 var(--r-full) var(--r-full) 0;
  background: var(--accent);
  opacity: 0;
  transition: opacity var(--dur-base) var(--ease-out);
}

.track-item:active {
  background-color: var(--surface-1);
}

.track-item.playing {
  background-color: var(--accent-subtle);
}

.track-item.playing::before {
  opacity: 1;
}

.track-item.playing .track-title {
  color: var(--accent);
}

/* Track info column */
.track-info {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.track-title {
  font-size: var(--font-base);
  font-weight: 500;
  color: var(--tg-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: color var(--dur-base) ease;
}

.track-artist {
  font-size: var(--font-sm);
  color: var(--tg-hint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Track meta column (duration + action button) */
.track-meta {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  flex-shrink: 0;
}

.track-duration {
  font-size: var(--font-xs);
  color: var(--tg-hint);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}

/* Download / Play action button on track items */
.track-action-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  line-height: 1;
  background: var(--surface-2);
  color: var(--tg-text);
  transition:
    background-color var(--dur-fast) ease,
    transform var(--dur-fast) var(--ease-out),
    opacity var(--dur-fast) ease;
  flex-shrink: 0;
}

.track-action-btn:active {
  transform: scale(0.86);
  opacity: 0.7;
}

.track-action-btn[disabled] {
  opacity: 0.45;
  cursor: default;
}

/* Remove button (playlist detail) */
.track-remove-btn {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  background: rgba(255,59,48,0.1);
  color: var(--danger);
  transition:
    background-color var(--dur-fast) ease,
    transform var(--dur-fast) var(--ease-out);
  flex-shrink: 0;
}

.track-remove-btn:active {
  transform: scale(0.82);
  background: rgba(255,59,48,0.25);
}

/* ============================================================
   Empty / loading / error states
   ============================================================ */

.empty,
.loading,
.error {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 64px var(--sp-6);
  gap: var(--sp-3);
  text-align: center;
  width: 100%;
}

.empty {
  color: var(--tg-hint);
  font-size: var(--font-md);
  font-weight: 500;
  opacity: 0.6;
}

.loading {
  color: var(--tg-hint);
  font-size: var(--font-base);
}

.loading::after {
  content: '';
  width: 24px;
  height: 24px;
  border: 2px solid var(--surface-2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-top: var(--sp-3);
}

.error {
  color: var(--danger);
  font-size: var(--font-sm);
}

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

/* ============================================================
   Playlist list
   ============================================================ */

.playlist-list {
  flex: 1;
}

.playlist-item {
  display: flex;
  align-items: center;
  min-height: 64px;
  padding: var(--sp-3) var(--sp-4);
  gap: var(--sp-3);
  cursor: pointer;
  border-bottom: var(--sep);
  transition: background-color var(--dur-fast) ease;
  -webkit-user-select: none;
  user-select: none;
}

.playlist-item:active {
  background-color: var(--surface-1);
}

/* Playlist icon box */
.playlist-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--r-md);
  background: linear-gradient(
    135deg,
    var(--surface-2) 0%,
    var(--surface-3) 100%
  );
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--tg-hint);
  font-size: 20px;
  border: 1px solid rgba(255,255,255,0.06);
}

.playlist-item-info {
  flex: 1;
  min-width: 0;
}

.playlist-name {
  font-size: var(--font-base);
  font-weight: 500;
  color: var(--tg-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
}

.playlist-count {
  font-size: var(--font-sm);
  color: var(--tg-hint);
  margin-top: 2px;
  display: block;
}

.playlist-badge {
  display: inline-flex;
  align-items: center;
  font-size: var(--font-xs);
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--accent-text);
  background: var(--accent);
  padding: 1px 6px;
  border-radius: var(--r-full);
  vertical-align: middle;
  margin-left: var(--sp-1);
}

.playlist-meta {
  font-size: var(--font-sm);
  color: var(--tg-hint);
  margin-top: 2px;
  display: block;
}

.playlist-chevron {
  color: var(--tg-hint);
  opacity: 0.4;
  flex-shrink: 0;
}

/* ============================================================
   Playlist detail screen
   ============================================================ */

.playlist-detail-header {
  display: flex;
  align-items: center;
  padding: var(--sp-2) var(--sp-2) var(--sp-2) var(--sp-1);
  border-bottom: var(--sep);
  min-height: 52px;
  gap: var(--sp-1);
  flex-shrink: 0;
  background: var(--surface-0);
  position: sticky;
  top: 0;
  z-index: 10;
}

.playlist-detail-title {
  font-size: var(--font-md);
  font-weight: 700;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: -0.02em;
}

.playlist-detail-actions {
  flex-wrap: wrap;
  justify-content: flex-start;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
}

/* ============================================================
   Now Playing bar
   ============================================================ */

.now-playing-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-width: var(--max-w);
  margin: 0 auto;
  z-index: 200;

  /* Height = bar + safe area */
  height: calc(var(--bar-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);

  /* Frosted glass */
  background: color-mix(in srgb, var(--surface-1) 85%, transparent);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  border-top: var(--sep);
  box-shadow: var(--shadow-md), 0 -1px 0 rgba(255,255,255,0.04);

  display: flex;
  align-items: center;
  padding-left: var(--sp-3);
  padding-right: var(--sp-3);
  gap: var(--sp-3);
  cursor: pointer;

  /* Slide up entrance */
  animation: barSlideUp var(--dur-slow) var(--ease-out) both;
}

@keyframes barSlideUp {
  from { transform: translateY(100%); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

/* Thin progress line along the top edge of the bar */
.now-playing-bar::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  height: 2px;
  width: var(--np-progress, 0%);
  background: var(--accent);
  border-radius: 0 var(--r-full) var(--r-full) 0;
  transition: width 1s linear;
}

/* Artwork thumbnail */
.now-playing-thumb {
  width: 44px;
  height: 44px;
  border-radius: var(--r-sm);
  background: linear-gradient(135deg, var(--surface-2), var(--surface-3));
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--tg-hint);
  font-size: 20px;
  border: 1px solid rgba(255,255,255,0.06);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

/* Track info in bar */
.now-playing-info {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  flex: 1;
  min-width: 0;
}

.now-playing-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  gap: 2px;
}

.np-title {
  font-size: var(--font-sm);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--tg-text);
  letter-spacing: -0.01em;
}

.np-artist {
  font-size: var(--font-xs);
  color: var(--tg-hint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Play/pause in bar */
.np-play-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-text);
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
  box-shadow: 0 2px 12px var(--accent-glow);
  transition:
    transform var(--dur-fast) var(--ease-out),
    opacity var(--dur-fast) ease;
}

.np-play-btn:active {
  transform: scale(0.88);
  opacity: 0.8;
}

/* ============================================================
   Player overlay (full-screen)
   ============================================================ */

.player-overlay {
  position: fixed;
  inset: 0;
  z-index: 300;
  max-width: var(--max-w);
  margin: 0 auto;

  /* Layered background: deep dark with subtle gradient */
  background: linear-gradient(
    180deg,
    color-mix(in srgb, var(--surface-0) 92%, var(--accent) 8%) 0%,
    var(--surface-0) 60%
  );

  /* Closed state — off-screen below */
  transform: translateY(100%);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition:
    transform var(--dur-slow) var(--ease-out),
    opacity var(--dur-slow) var(--ease-out),
    visibility 0s var(--dur-slow);

  display: flex;
  flex-direction: column;
}

/* Open state: slide up */
.player-overlay.active {
  transform: translateY(0);
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transition:
    transform var(--dur-slow) var(--ease-out),
    opacity var(--dur-slow) var(--ease-out),
    visibility 0s;
}

/* While being dragged — disable transition so transform follows finger */
.player-overlay.dragging {
  transition: none !important;
}

.player-overlay-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
  padding: var(--sp-3) var(--sp-6) calc(var(--sp-6) + env(safe-area-inset-bottom, 0px));
  gap: var(--sp-5);
  overflow: hidden;
}

/* Drag handle pill */
.player-drag-handle {
  width: 40px;
  height: 5px;
  border-radius: var(--r-full);
  background: rgba(255,255,255,0.18);
  flex-shrink: 0;
  margin-top: var(--sp-1);
  margin-bottom: var(--sp-2);
}

/* Large album art area */
.player-art {
  width: min(260px, calc(100vw - 80px));
  aspect-ratio: 1;
  border-radius: var(--r-xl);
  background: linear-gradient(
    145deg,
    var(--surface-2) 0%,
    var(--surface-3) 100%
  );
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--tg-hint);
  font-size: 72px;
  border: 1px solid rgba(255,255,255,0.07);
  box-shadow:
    var(--shadow-lg),
    var(--shadow-glow),
    inset 0 1px 0 rgba(255,255,255,0.08);

  /* Breathing pulse when playing */
  transition: transform var(--dur-slow) var(--ease-out);
}

/* Track info block */
.player-info {
  text-align: center;
  width: 100%;
  padding: 0 var(--sp-2);
}

.player-title {
  font-size: var(--font-xl);
  font-weight: 700;
  color: var(--tg-text);
  letter-spacing: -0.03em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
}

.player-artist {
  font-size: var(--font-base);
  color: var(--tg-hint);
  margin-top: var(--sp-1);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Source badge below artist */
.po-source {
  display: inline-block;
  margin-top: var(--sp-2);
  font-size: var(--font-xs);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
  background: var(--accent-subtle);
  padding: 2px 8px;
  border-radius: var(--r-full);
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
}

.po-source:empty {
  display: none;
}

/* ============================================================
   Seek bar
   ============================================================ */

.player-seek {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}

.seek-bar {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: var(--r-full);
  outline: none;
  cursor: pointer;
  /* Progress fill via custom property set in player.js */
  background: linear-gradient(
    to right,
    var(--accent) 0%,
    var(--accent) var(--seek-progress, 0%),
    rgba(255,255,255,0.1) var(--seek-progress, 0%),
    rgba(255,255,255,0.1) 100%
  );
  transition: height var(--dur-fast) ease;
}

.seek-bar:active {
  height: 6px;
}

.seek-bar::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #ffffff;
  cursor: pointer;
  box-shadow: 0 1px 6px rgba(0,0,0,0.5);
  transition: transform var(--dur-fast) var(--ease-spring);
}

.seek-bar:active::-webkit-slider-thumb {
  transform: scale(1.25);
}

.seek-bar::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #ffffff;
  cursor: pointer;
  border: none;
  box-shadow: 0 1px 6px rgba(0,0,0,0.5);
}

.player-time {
  display: flex;
  justify-content: space-between;
}

.player-time span {
  font-size: var(--font-xs);
  color: var(--tg-hint);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
}

/* ============================================================
   Player controls
   ============================================================ */

.player-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 0 var(--sp-2);
}

/* Secondary controls: shuffle, prev, next, repeat */
.ctrl-btn {
  background: none;
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  color: rgba(255,255,255,0.55);
  border-radius: 50%;
  font-size: 22px;
  line-height: 1;
  transition:
    color var(--dur-base) ease,
    transform var(--dur-fast) var(--ease-out),
    opacity var(--dur-fast) ease;
}

.ctrl-btn:active {
  opacity: 0.45;
  transform: scale(0.84);
}

/* Active state for shuffle/repeat */
.ctrl-btn.active {
  color: var(--accent);
}

/* Active dot indicator under shuffle/repeat */
.ctrl-btn.active::after {
  content: '';
  position: absolute;
  bottom: 4px;
  left: 50%;
  transform: translateX(-50%);
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--accent);
}

.ctrl-btn {
  position: relative;
}

/* Prev / Next secondary buttons */
.ctrl-main {
  color: rgba(255,255,255,0.8);
  font-size: 28px;
}

.ctrl-main:active {
  transform: scale(0.82);
}

/* Big play/pause button */
.ctrl-play-pause {
  width: 70px;
  height: 70px;
  border-radius: 50%;
  background: #ffffff;
  color: #000000;
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  line-height: 1;
  box-shadow:
    var(--shadow-md),
    0 0 0 1px rgba(255,255,255,0.1);
  transition:
    transform var(--dur-fast) var(--ease-spring),
    box-shadow var(--dur-base) ease;
}

.ctrl-play-pause:active {
  transform: scale(0.92);
  box-shadow: var(--shadow-sm), 0 0 0 1px rgba(255,255,255,0.1);
}

/* Override btn-icon defaults for these */
.po-shuffle-btn,
.po-repeat-btn {
  min-width: 44px;
  min-height: 44px;
}

/* ============================================================
   Modal (add tracks sheet)
   ============================================================ */

.modal {
  position: fixed;
  inset: 0;
  z-index: 400;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  max-width: var(--max-w);
  margin: 0 auto;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  animation: backdropFadeIn var(--dur-base) ease both;
}

@keyframes backdropFadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.modal-sheet {
  position: relative;
  background: var(--surface-1);
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  max-height: 72vh;
  display: flex;
  flex-direction: column;
  animation: sheetSlideUp var(--dur-slow) var(--ease-out) both;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  border-top: 1px solid rgba(255,255,255,0.08);
  box-shadow: var(--shadow-lg);

  /* Drag handle via pseudo */
  overflow: hidden;
}

.modal-sheet::before {
  content: '';
  display: block;
  width: 40px;
  height: 5px;
  border-radius: var(--r-full);
  background: rgba(255,255,255,0.18);
  margin: 10px auto 0;
  flex-shrink: 0;
}

@keyframes sheetSlideUp {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}

.modal-header {
  display: flex;
  align-items: center;
  padding: var(--sp-3) var(--sp-4) var(--sp-3);
  border-bottom: var(--sep);
  flex-shrink: 0;
  gap: var(--sp-3);
}

.modal-title {
  flex: 1;
  font-size: var(--font-md);
  font-weight: 700;
  letter-spacing: -0.02em;
}

.modal-close {
  color: var(--tg-hint);
  font-size: 18px;
}

.modal-track-list {
  overflow-y: auto;
  flex: 1;
  -webkit-overflow-scrolling: touch;
}

.modal-body {
  padding: var(--sp-4);
}

.modal-input {
  width: 100%;
  padding: var(--sp-3);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  color: var(--tg-text);
  font-size: var(--font-base);
  font-family: inherit;
  outline: none;
  transition: border-color var(--dur-fast) ease;
}

.modal-input::placeholder {
  color: var(--tg-hint);
}

.modal-input:focus {
  border-color: var(--accent);
}

.modal-footer {
  padding: var(--sp-3) var(--sp-4) var(--sp-4);
  border-top: var(--sep);
  flex-shrink: 0;
}

/* Modal track check rows — app.js uses label.modal-track-check with checkbox */
.modal-track-check {
  display: flex;
  align-items: center;
  min-height: 52px;
  padding: var(--sp-3) var(--sp-4);
  gap: var(--sp-3);
  cursor: pointer;
  border-bottom: var(--sep);
  transition: background-color var(--dur-fast) ease;
  -webkit-user-select: none;
  user-select: none;
}

.modal-track-check:active {
  background: var(--surface-2);
}

/* Hide native checkbox, use custom indicator */
.modal-track-check input[type="checkbox"] {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.2);
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  cursor: pointer;
  flex-shrink: 0;
  position: relative;
  transition:
    background-color var(--dur-fast) ease,
    border-color var(--dur-fast) ease;
}

.modal-track-check input[type="checkbox"]:checked {
  background: var(--accent);
  border-color: var(--accent);
}

/* Checkmark via pseudo */
.modal-track-check input[type="checkbox"]:checked::after {
  content: '';
  position: absolute;
  inset: 0;
  background: url("data:image/svg+xml,%3Csvg width='12' height='9' viewBox='0 0 12 9' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 4L4.5 7.5L11 1' stroke='white' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / 12px no-repeat;
}

.modal-track-check span {
  font-size: var(--font-sm);
  color: var(--tg-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}

/* Also style old .modal-track-item if used */
.modal-track-item {
  display: flex;
  align-items: center;
  min-height: 52px;
  padding: var(--sp-2) var(--sp-4);
  gap: var(--sp-3);
  cursor: pointer;
  border-bottom: var(--sep);
  transition: background-color var(--dur-fast) ease;
}

.modal-track-item:active {
  background: var(--surface-2);
}

.modal-track-item.selected {
  background: var(--accent-subtle);
}

.modal-checkbox {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition:
    background-color var(--dur-fast) ease,
    border-color var(--dur-fast) ease;
}

.modal-track-item.selected .modal-checkbox {
  background: var(--accent);
  border-color: var(--accent);
}

/* ============================================================
   Loading skeleton
   ============================================================ */

.skeleton {
  background: linear-gradient(
    90deg,
    var(--surface-1) 25%,
    var(--surface-2) 50%,
    var(--surface-1) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.6s infinite;
  border-radius: var(--r-sm);
}

@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ============================================================
   Scrollbar
   ============================================================ */

::-webkit-scrollbar {
  width: 0;
  height: 0;
}

/* ============================================================
   Responsive adjustments
   ============================================================ */

@media (max-height: 640px) {
  .player-art {
    width: min(180px, calc(100vw - 80px));
  }

  .player-overlay-inner {
    gap: var(--sp-3);
  }

  .player-title {
    font-size: var(--font-lg);
  }

  .ctrl-play-pause {
    width: 60px;
    height: 60px;
    font-size: 22px;
  }
}

@media (max-width: 360px) {
  .player-title {
    font-size: var(--font-lg);
  }

  .player-controls {
    padding: 0;
    gap: var(--sp-1);
  }
}
