/*
 * Split It - Music Practice Tool
 * Dark Theme Mobile-First CSS
 */

/* ===== CSS Variables ===== */
:root {
  --color-primary: #1db954;
  --color-primary-dark: #1aa34a;
  --color-primary-light: #1ed760;

  --color-vocals: #1db954;
  --color-drums: #4fc3f7;
  --color-bass: #ce93d8;
  --color-other: #ffb74d;

  --color-background: #121212;
  --color-surface: #181818;
  --color-surface-elevated: #282828;
  --color-surface-highlight: #333333;
  --color-text-primary: #ffffff;
  --color-text-secondary: #b3b3b3;
  --color-text-muted: #727272;
  --color-border: #333333;
  --color-error: #e74c3c;
  --color-success: #1db954;

  --spacing-xs: 4px;
  --spacing-sm: 8px;
  --spacing-md: 16px;
  --spacing-lg: 24px;
  --spacing-xl: 32px;
  --spacing-xxl: 32px;

  --font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu,
    Cantarell, sans-serif;
  --font-size-base: 16px;
  --font-size-sm: 14px;
  --font-size-xs: 12px;
  --font-size-lg: 18px;
  --font-size-xl: 24px;
  --font-size-2xl: 32px;

  --touch-target: 44px;

  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 20px rgba(0, 0, 0, 0.5);
}

/* ===== Reset & Base ===== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html {
  font-size: var(--font-size-base);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  height: 100%;
}

body {
  font-family: var(--font-family);
  background-color: var(--color-background);
  color: var(--color-text-primary);
  line-height: 1.6;
  height: 100%;
  overflow: hidden;
  /* Keep content below the status bar at all scroll positions. */
  padding-top: env(safe-area-inset-top, 0px);
}

/* ===== Layout ===== */
.app-container {
  max-width: 768px;
  margin: 0 auto;
  height: 100%;
  display: flex;
  flex-direction: column;
  background-color: var(--color-background);
  overflow: hidden;
}

.main-content {
  flex: 1;
  padding: var(--spacing-md);
  overflow-y: auto;
  overflow-x: hidden;
}

/* ===== Pull-to-refresh ===== */
.pull-to-refresh {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 48px;
  transition: opacity 0.2s;
}

.pull-to-refresh.hidden {
  display: none;
}

.ptr-spinner {
  width: 24px;
  height: 24px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: ptr-spin 0.7s linear infinite;
}

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

/* ===== Header (hidden) ===== */
.app-header {
  display: none;
}

/* ===== Sections ===== */
.section {
  margin-bottom: var(--spacing-xl);
}

.section-title {
  font-size: var(--font-size-xl);
  font-weight: 600;
  margin-bottom: var(--spacing-md);
  color: var(--color-text-primary);
}

/* ===== Upload Section ===== */
.upload-box {
  background-color: var(--color-surface);
  border: 2px dashed var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--spacing-xl);
  text-align: center;
  margin-bottom: var(--spacing-md);
  transition: all 0.2s ease;
  cursor: pointer;
}

.upload-box:hover {
  border-color: var(--color-primary);
  background-color: rgba(29, 185, 84, 0.05);
}

.upload-label {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--spacing-sm);
  cursor: pointer;
}

.upload-icon {
  color: var(--color-primary);
}
.upload-text {
  font-size: var(--font-size-base);
  color: var(--color-text-primary);
  font-weight: 500;
}
.upload-subtext {
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
}
.hidden-input {
  display: none;
}

/* Processing */
.processing-queue {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-sm);
  margin-top: var(--spacing-md);
}

.processing-card {
  background-color: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--spacing-md);
  transition: opacity 0.3s ease;
}

.processing-card-header {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  margin-bottom: var(--spacing-sm);
}

.processing-card-name {
  font-size: var(--font-size-sm);
  font-weight: 600;
  color: var(--color-text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.processing-cancel-btn {
  flex-shrink: 0;
  background: none;
  border: none;
  color: var(--color-text-muted);
  font-size: 12px;
  line-height: 1;
  padding: 2px 4px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: color 0.15s, background 0.15s;
}

.processing-cancel-btn:hover {
  color: var(--color-text-primary);
  background: var(--color-surface-highlight);
}

.progress-bar-container {
  width: 100%;
  height: 4px;
  background-color: var(--color-surface-highlight);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: var(--spacing-sm);
}

.progress-bar {
  height: 100%;
  background: var(--color-primary);
  width: 0%;
  transition: width 0.3s ease;
}

.processing-message {
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
  text-align: center;
}

.processing-card-queued {
  opacity: 0.5;
}

.processing-card-queued .progress-bar {
  background: var(--color-text-muted);
  animation: queued-pulse 1.5s ease-in-out infinite;
}

@keyframes queued-pulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 0.8; }
}

/* ===== Song Library ===== */
.song-list {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-sm);
}

.song-item {
  background-color: var(--color-surface);
  border: none;
  border-radius: var(--radius-md);
  padding: var(--spacing-md);
  cursor: pointer;
  transition: all 0.2s ease;
  min-height: var(--touch-target);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.song-item:hover {
  background-color: var(--color-surface-elevated);
}
.song-item:active {
  transform: scale(0.99);
}

.song-info {
  flex: 1;
  min-width: 0;
  overflow: hidden;
}
.song-title {
  font-size: var(--font-size-base);
  font-weight: 600;
  color: var(--color-text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.song-upgrading {
  font-size: 11px;
  color: var(--color-accent, #7c6af7);
  opacity: 0.8;
  margin-top: 2px;
  display: flex;
  align-items: center;
  gap: 5px;
}
.song-upgrading::before {
  content: '';
  display: inline-block;
  width: 8px;
  height: 8px;
  border: 1.5px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}
.song-meta {
  display: none;
}

.song-delete {
  flex-shrink: 0;
  min-width: var(--touch-target);
  min-height: var(--touch-target);
  background: none;
  border: none;
  color: var(--color-text-muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.song-delete:hover {
  color: var(--color-error);
  background-color: rgba(231, 76, 60, 0.1);
}

.empty-state {
  text-align: center;
  color: var(--color-text-secondary);
  padding: var(--spacing-xl);
  font-size: var(--font-size-base);
}

/* ===== Player Modal (Bottom-Up) ===== */
.player-section {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--color-background);
  z-index: 100;
  display: flex;
  flex-direction: column;
  padding: 0;
  animation: slideUpModal 0.3s ease;
  overflow-y: auto;
}

.player-section.hidden {
  display: none !important;
}

.player-section.closing {
  animation: slideDownModal 0.3s ease forwards;
}

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

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

/* Player Header */
.player-header {
  display: flex;
  align-items: center;
  padding: var(--spacing-md);
  padding-top: calc(var(--spacing-md) + env(safe-area-inset-top, 0px));
  gap: var(--spacing-md);
}

.back-button {
  min-width: var(--touch-target);
  min-height: var(--touch-target);
  background: none;
  border: none;
  color: var(--color-text-primary);
  cursor: pointer;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.back-button:hover {
  color: var(--color-primary);
}

/* Marquee title */
.player-title {
  font-size: var(--font-size-lg);
  font-weight: 600;
  color: var(--color-text-primary);
  flex: 1;
  overflow: hidden;
  white-space: nowrap;
  margin: 0;
  position: relative;
}

.player-title .title-text {
  display: inline-block;
  white-space: nowrap;
}

.player-title.marquee .title-text {
  animation: marqueeScroll 10s ease-in-out infinite;
}

@keyframes marqueeScroll {
  0%,
  15% {
    transform: translateX(0);
  }
  40%,
  60% {
    transform: translateX(var(--marquee-distance, 0));
  }
  85%,
  100% {
    transform: translateX(0);
  }
}

.player-artist {
  display: none;
}
.close-button {
  display: none;
}

/* Player body */
.player-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 0 var(--spacing-md) var(--spacing-md);
}

/* Loading */
.player-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--spacing-xl) var(--spacing-md);
  flex: 1;
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--color-surface-highlight);
  border-top: 4px solid var(--color-primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-bottom: var(--spacing-md);
}

@keyframes spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

.loading-text {
  font-size: var(--font-size-base);
  color: var(--color-text-secondary);
  margin: 0;
}

/* ===== Stem Controls ===== */
.stem-controls {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-xxl);
  margin-bottom: var(--spacing-md);
  flex: 1;
  justify-content: center;
}

.stem-control {
  display: flex;
  align-items: center;
  gap: var(--spacing-md);
}

.stem-header {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  flex-shrink: 0;
  min-width: 60px;
}

.stem-icon {
  width: 24px;
  height: 24px;
  color: var(--color-text-secondary);
  flex-shrink: 0;
  cursor: pointer;
  border-radius: 50%;
  padding: 5px;
  margin: -5px;
  box-sizing: content-box;
  transition: background-color 0.15s;
}
.stem-icon:hover {
  background-color: rgba(255, 255, 255, 0.08);
}

.stem-control[data-stem="vocals"] .stem-icon {
  color: var(--color-vocals);
}
.stem-control[data-stem="drums"] .stem-icon {
  color: var(--color-drums);
}
.stem-control[data-stem="bass"] .stem-icon {
  color: var(--color-bass);
}
.stem-control[data-stem="other"] .stem-icon {
  color: var(--color-other);
}

.stem-label {
  display: none;
}

.mute-button {
  min-width: 36px;
  min-height: 36px;
  background: none;
  border: none;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-secondary);
  padding: 0;
}

.mute-button:hover {
  background-color: var(--color-surface-highlight);
}
.mute-button.muted {
  color: var(--color-error);
}

/* Volume slider (colored fill via JS background) */
.volume-control {
  display: flex;
  align-items: center;
  flex: 1;
}

.volume-down,
.volume-up {
  display: none;
}
.volume-value {
  display: none;
}

.volume-slider {
  flex: 1;
  height: var(--touch-target);
  -webkit-appearance: none;
  appearance: none;
  background: linear-gradient(
      to right,
      var(--color-surface-highlight) 0%,
      var(--color-surface-highlight) 100%
    )
    center/100% 4px no-repeat;
  cursor: pointer;
  border-radius: 0;
}

.volume-slider::-webkit-slider-runnable-track {
  height: 4px;
  background: transparent;
  border-radius: 2px;
}

.volume-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  background: var(--color-text-primary);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  margin-top: -6px;
}

.volume-slider::-moz-range-track {
  height: 4px;
  background: transparent;
  border-radius: 2px;
  border: none;
}

.volume-slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  background: var(--color-text-primary);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
}

.volume-slider:focus {
  outline: none;
}

/* ===== Playback Controls ===== */
.playback-controls {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-sm);
  padding: var(--spacing-sm) 0;
}

/* Tempo (above sound bar) */
.tempo-selector {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  padding: var(--spacing-xs) 0;
}

.tempo-label {
  font-size: var(--font-size-sm);
  font-weight: 500;
  color: var(--color-text-secondary);
  flex-shrink: 0;
}

.tempo-slider-container {
  flex: 1;
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
}

.tempo-slider {
  flex: 1;
  height: var(--touch-target);
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  cursor: pointer;
}

.tempo-slider::-webkit-slider-runnable-track {
  height: 4px;
  background: var(--color-surface-highlight);
  border-radius: 2px;
}

.tempo-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  background: var(--color-primary);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  margin-top: -6px;
}

.tempo-slider::-moz-range-track {
  height: 4px;
  background: var(--color-surface-highlight);
  border-radius: 2px;
}

.tempo-slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  background: var(--color-primary);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
}

.tempo-slider:focus {
  outline: none;
}
.tempo-slider:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.tempo-value {
  min-width: 40px;
  font-size: var(--font-size-sm);
  font-weight: 600;
  color: var(--color-primary);
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.tempo-reset {
  min-width: 32px;
  min-height: 32px;
  overflow: hidden;
  background: var(--color-surface-elevated);
  border: none;
  border-radius: 20px;
  color: var(--color-text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  flex-shrink: 0;
  font-size: var(--font-size-xs);
  padding: 0 var(--spacing-sm);
}

.tempo-reset:hover {
  background: var(--color-surface-highlight);
  color: var(--color-text-primary);
}

/* Time display (left = current, right = total, no slash) */
.time-display {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
  font-variant-numeric: tabular-nums;
  padding: 0 2px;
}

.time-separator {
  display: none;
}

/* Sound Bar (thin progress bar) */
.sound-bar-container {
  width: 100%;
  padding: 0;
}

.sound-bar {
  position: relative;
  height: 32px;
  background-color: transparent;
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
}

.sound-bar-track {
  position: absolute;
  left: 0;
  right: 0;
  height: 4px;
  background-color: var(--color-surface-highlight);
  border-radius: 2px;
  top: 50%;
  transform: translateY(-50%);
}

.sound-progress {
  height: 4px;
  background: var(--color-primary);
  border-radius: 2px;
  width: 0%;
  transition: width 0.1s ease;
  pointer-events: none;
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
}

.sound-handle {
  position: absolute;
  width: 14px;
  height: 14px;
  background: var(--color-text-primary);
  border-radius: 50%;
  left: 0%;
  top: 50%;
  transform: translate(-50%, -50%);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform 0.1s ease;
  z-index: 1;
}

.sound-handle:hover {
  transform: translate(-50%, -50%) scale(1.2);
}
.sound-bar:active .sound-handle {
  transform: translate(-50%, -50%) scale(1.3);
}

/* Preview overlay: shades the portion of the soundbar not yet available */
.preview-overlay {
  position: absolute;
  right: 0;
  top: 0;
  height: 100%;
  background: rgba(255, 255, 255, 0.12);
  border-left: 1px solid rgba(255, 255, 255, 0.25);
  pointer-events: none;
  border-radius: 0 3px 3px 0;
  transition: width 0.3s ease;
}

/* Shimmer on ::after so it doesn't conflict with the bump animation on the main element */
@keyframes previewShimmer {
  0%   { background-position: 150% center; }
  100% { background-position: -150% center; }
}

.preview-overlay.loading::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 0 3px 3px 0;
  background: linear-gradient(
    90deg,
    transparent 20%,
    rgba(255, 255, 255, 0.22) 50%,
    transparent 80%
  );
  background-size: 200% 100%;
  animation: previewShimmer 1.6s ease-in-out infinite;
}

/* Flash on click past the preview boundary */
@keyframes previewBump {
  0%   { background: rgba(255, 255, 255, 0.12); }
  40%  { background: rgba(255, 255, 255, 0.45); }
  100% { background: rgba(255, 255, 255, 0.12); }
}

.preview-overlay.bump {
  animation: previewBump 0.4s ease-out;
}

/* A-B loop controls */
.ab-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 4px;
}
.ab-btn {
  width: 32px;
  height: 32px;
  border-radius: 20px;
  border: 1px solid var(--color-border);
  background: transparent;
  color: var(--color-text-primary);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.ab-btn.active {
  background: #E8832A;
  border-color: #E8832A;
  color: #fff;
}
.ab-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}
.ab-reset {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: none;
  background: var(--color-text-muted);
  color: var(--color-background);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  opacity: 0.7;
  transition: opacity 0.15s;
}
.ab-reset:hover { opacity: 1; }

/* ===== Lyrics ===== */
.lyrics-section {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-sm);
  padding: var(--spacing-xs) 0;
}
.lyrics-btn-row {
  display: flex;
  justify-content: center;
}
.lyrics-btn {
  min-width: 80px;
  height: 32px;
  border-radius: 20px;
  border: 1px solid var(--color-border);
  background: transparent;
  color: var(--color-text-primary);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  padding: 0 var(--spacing-sm);
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.lyrics-btn.active {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: #000;
}
.lyrics-btn.loading {
  opacity: 0.6;
  cursor: default;
}
.lyrics-btn.error {
  border-color: var(--color-error);
  color: var(--color-error);
}
.lyrics-panel {
  border-radius: var(--radius-md);
  padding: var(--spacing-sm) var(--spacing-md);
  min-height: 60px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  text-align: center;
}
.lyrics-panel.hidden { display: none; }
.lyrics-line {
  font-size: var(--font-size-sm);
  line-height: 1.5;
  min-height: 1.5em;
}
.lyrics-word {
  color: #888;
  transition: color 0.1s;
  margin-right: 0.25em;
  display: inline-block;
}
.lyrics-word.past  { color: #aaa; }
.lyrics-word.active { color: var(--color-text-primary); font-weight: 600; }
.lyrics-btn-row { gap: 8px; }
.lyrics-phonetic-btn {
  height: 32px;
  padding: 0 10px;
  border-radius: 4px;
  border: 1px solid var(--color-border);
  background: transparent;
  color: var(--color-text-secondary);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.05em;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.lyrics-phonetic-btn.active {
  background: var(--color-surface-elevated);
  border-color: var(--color-text-secondary);
  color: var(--color-text-primary);
}
.lyrics-phonetic-btn.hidden { display: none; }

/* Soundbar markers */
.ab-loop-range {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  height: 4px;
  background: rgba(232, 131, 42, 0.35);
  z-index: 1;
  pointer-events: none;
}
.ab-marker {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 2px;
  height: 12px;
  border-radius: 1px;
  z-index: 3;
  pointer-events: none;
}
.ab-marker-a { background: #E8832A; }
.ab-marker-b { background: #E8832A; }

/* Prev / Play / Next row */
.playback-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--spacing-xl);
  padding: var(--spacing-sm) 0;
  padding-bottom: calc(var(--spacing-sm) + env(safe-area-inset-bottom, 0px));
}

.nav-button {
  min-width: var(--touch-target);
  min-height: var(--touch-target);
  background: none;
  border: none;
  color: var(--color-text-secondary);
  cursor: pointer;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.nav-button:hover {
  color: var(--color-text-primary);
}
.nav-button:active {
  transform: scale(0.9);
}
.nav-button:disabled {
  color: var(--color-text-muted);
  opacity: 0.4;
  cursor: default;
}
.nav-button:disabled:active {
  transform: none;
}

.play-button {
  min-width: 56px;
  min-height: 56px;
  background-color: var(--color-primary);
  color: var(--color-background);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-md);
}

#play-icon {
  transform: translateX(2px); /* optical centering for play triangle */
}

.play-button:hover {
  background-color: var(--color-primary-light);
  transform: scale(1.05);
}
.play-button:active {
  transform: scale(0.95);
}

/* ===== Footer ===== */
.app-footer {
  background-color: var(--color-background);
  border-top: 1px solid var(--color-border);
  padding: var(--spacing-md);
  padding-bottom: calc(var(--spacing-md) + env(safe-area-inset-bottom, 0px));
  text-align: center;
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
  position: relative;
}

.app-footer a {
  color: var(--color-primary);
  text-decoration: none;
}
.app-footer a:hover {
  text-decoration: underline;
}

.discord-link {
  position: absolute;
  right: var(--spacing-md);
  top: 50%;
  transform: translateY(-50%);
  color: #5865F2 !important;
  text-decoration: none !important;
  opacity: 0.85;
  transition: opacity 0.2s;
  line-height: 0;
}
.discord-link:hover {
  opacity: 1;
  text-decoration: none !important;
}
.discord-icon {
  width: 18px;
  height: 18px;
  fill: #5865F2;
  flex-shrink: 0;
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  top: calc(var(--spacing-lg) + env(safe-area-inset-top, 0px));
  left: var(--spacing-md);
  right: var(--spacing-md);
  padding: var(--spacing-md);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--spacing-md);
  z-index: 1000;
  animation: slideDown 0.3s ease;
}

.toast-error {
  background-color: var(--color-error);
  color: white;
}
.toast-success {
  background-color: var(--color-success);
  color: white;
}
.toast-warning {
  background-color: #b45309;
  color: white;
}

.toast-close {
  min-width: var(--touch-target);
  min-height: var(--touch-target);
  background: none;
  border: none;
  color: white;
  font-size: var(--font-size-xl);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
}

.toast-close:hover {
  background-color: rgba(255, 255, 255, 0.2);
}

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

/* ===== Splash Screen ===== */
.splash-screen {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--color-background);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.4s ease;
}

.splash-screen.fade-out {
  opacity: 0;
  pointer-events: none;
}

.splash-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--spacing-lg);
}

.splash-logo {
  width: 96px;
  height: 96px;
  border-radius: 20px;
}

.splash-title {
  font-size: var(--font-size-2xl);
  font-weight: 700;
  color: var(--color-text-primary);
  letter-spacing: 2px;
}

/* ===== Fake Progress Bar (stem loading) ===== */
.loading-progress-container {
  width: 200px;
  height: 4px;
  background-color: var(--color-surface-highlight);
  border-radius: 2px;
  overflow: hidden;
  margin-top: var(--spacing-md);
}

.loading-progress-bar {
  height: 100%;
  background: var(--color-primary);
  border-radius: 2px;
  width: 0%;
}

.loading-progress-bar.animating {
  animation: fakeProgress 1s ease-out forwards;
}

@keyframes fakeProgress {
  0% { width: 0%; }
  25% { width: 40%; }
  55% { width: 65%; }
  75% { width: 78%; }
  90% { width: 87%; }
  100% { width: 90%; }
}

/* ===== Download Bottom Sheet ===== */
.download-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 10;
}

.download-sheet {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background-color: var(--color-surface-elevated);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: var(--spacing-sm) var(--spacing-md) calc(var(--spacing-md) + env(safe-area-inset-bottom, 0px));
  z-index: 11;
  animation: slideUpSheet 0.25s ease;
  display: flex;
  flex-direction: column;
  gap: var(--spacing-xs);
}

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

.download-sheet-handle {
  width: 36px;
  height: 4px;
  background: var(--color-border);
  border-radius: 2px;
  margin: var(--spacing-xs) auto var(--spacing-sm);
}

.download-sheet-title {
  font-size: var(--font-size-sm);
  font-weight: 600;
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 0 var(--spacing-xs) var(--spacing-xs);
}

.download-action {
  display: flex;
  align-items: center;
  gap: var(--spacing-md);
  width: 100%;
  background: none;
  border: none;
  color: var(--color-text-primary);
  cursor: pointer;
  padding: var(--spacing-md) var(--spacing-xs);
  border-radius: var(--radius-md);
  text-align: left;
  transition: background-color 0.15s ease;
  min-height: var(--touch-target);
}

.download-action:hover {
  background-color: var(--color-surface-highlight);
}

/* Delete sheet uses position:fixed so it covers the viewport from both
   the library view and the player view (download sheet uses absolute,
   which only works correctly when player-section is visible) */
.delete-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 100;
}

.delete-sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background-color: var(--color-surface-elevated);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: var(--spacing-sm) var(--spacing-md) calc(var(--spacing-md) + env(safe-area-inset-bottom, 0px));
  z-index: 101;
  animation: slideUpSheet 0.25s ease;
  display: flex;
  flex-direction: column;
  gap: var(--spacing-xs);
}

.delete-sheet-name {
  font-size: var(--font-size-base);
  color: var(--color-text-primary);
  padding: 0 var(--spacing-xs) var(--spacing-xs);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.delete-confirm-btn {
  width: 100%;
  padding: var(--spacing-md);
  background: #c0392b;
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  font-size: var(--font-size-base);
  font-weight: 600;
  cursor: pointer;
  min-height: var(--touch-target);
  transition: background-color 0.15s ease;
}

.delete-confirm-btn:hover {
  background: #a93226;
}

.delete-cancel-btn {
  width: 100%;
  padding: var(--spacing-md);
  background: none;
  color: var(--color-text-secondary);
  border: none;
  border-radius: var(--radius-md);
  font-size: var(--font-size-base);
  font-weight: 500;
  cursor: pointer;
  min-height: var(--touch-target);
  text-align: center;
  transition: color 0.15s ease;
}

.delete-cancel-btn:hover {
  color: var(--color-text-primary);
}

.download-action:active {
  background-color: var(--color-surface-highlight);
  transform: scale(0.98);
}

.download-action:disabled {
  opacity: 0.5;
  cursor: default;
}

.download-action svg {
  flex-shrink: 0;
  color: var(--color-primary);
}

.download-action-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.download-action-label {
  font-size: var(--font-size-base);
  font-weight: 500;
  color: var(--color-text-primary);
}

.download-action-sub {
  font-size: var(--font-size-xs);
  color: var(--color-text-secondary);
}

/* ===== Utility ===== */
.hidden {
  display: none !important;
}

/* ===== Small screen: compact stem spacing ===== */
@media (max-height: 700px) {
  .stem-controls {
    gap: var(--spacing-md);
  }
}

/* ===== Responsive ===== */
@media (min-width: 480px) {
  .main-content {
    padding: var(--spacing-lg);
  }
  .upload-box {
    padding: var(--spacing-xl) var(--spacing-lg);
  }
}

@media (min-width: 768px) {
  .toast {
    max-width: 400px;
    left: auto;
    right: var(--spacing-lg);
  }

  .player-section {
    max-width: 100%;
    left: 0;
    right: 0;
    transform: none;
    animation: slideUpModal 0.3s ease;
  }

  .player-section.closing {
    animation: slideDownModal 0.3s ease forwards;
  }
}

/* ===== Touch device: disable hover states that get stuck ===== */
@media (hover: none) {
  .song-delete:hover {
    color: var(--color-text-muted);
    background-color: transparent;
  }
  .upload-box:hover {
    border-color: var(--color-border);
    background-color: transparent;
  }
  .mute-button:hover {
    background-color: transparent;
  }
  .stem-icon:hover {
    background-color: transparent;
  }
}

/* ===== Focus ===== */
*:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}
button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}
