/* ============================================
   MOBILE-FIRST RESPONSIVE DESIGN
   Base styles: Mobile (≤480px)
   Breakpoints:
   - 481px+  : Large mobile / Small tablet
   - 768px+  : Tablet
   - 992px+  : Desktop
   - 1200px+ : Large desktop
   ============================================ */

/* ============================================
   RESET & BASE STYLES (MOBILE)
   ============================================ */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  /* ========================================
     PRIMARY COLOR - Green Scale
     ======================================== */
  --color-primary-50: #ecfdf5;
  --color-primary-100: #d1fae5;
  --color-primary-200: #a7f3d0;
  --color-primary-300: #6ee7b7;
  --color-primary-400: #34d399;
  --color-primary-500: #1DB954;
  /* Main brand color */
  --color-primary-600: #1ed760;
  /* Hover state */
  --color-primary-700: #059669;
  --color-primary-800: #047857;
  --color-primary-900: #065f46;

  /* Legacy aliases for backward compatibility */
  --color-accent: var(--color-primary-500);
  --color-accent-hover: var(--color-primary-600);

  /* ========================================
     NEUTRAL GRAYS - Background Gradients
     ======================================== */
  --color-gray-50: #f9fafb;
  --color-gray-100: #f3f4f6;
  --color-gray-200: #e5e7eb;
  --color-gray-300: #d1d5db;
  --color-gray-400: #9ca3af;
  --color-gray-500: #6b7280;
  --color-gray-600: #4b5563;
  --color-gray-700: #374151;
  --color-gray-800: #1f2937;
  --color-gray-900: #111827;

  /* ========================================
     SEMANTIC COLORS (Light Mode - Default)
     ======================================== */
  /* Backgrounds */
  --color-bg-app: #f5f7ff;
  /* Light purple-tinted background */
  --color-bg-surface: #ffffff;
  /* Cards, containers */
  --color-bg-element: #f8f9fa;
  /* UI elements */
  --color-bg-hover: #e9ecef;
  /* Hover states */

  /* Text */
  --color-text-primary: #1a1a1a;
  /* Main text */
  --color-text-secondary: #64748b;
  /* Secondary text */
  --color-text-muted: #94a3b8;
  /* Muted text */

  /* Borders */
  --color-border: #e2e8f0;
  /* Subtle borders */
  --color-border-hover: #cbd5e1;
  /* Hover borders */

  /* Status Colors */
  --color-success-bg: #d1fae5;
  --color-success-text: #065f46;
  --color-success-border: #a7f3d0;

  --color-error-bg: #fee2e2;
  --color-error-text: #991b1b;
  --color-error-border: #fecaca;

  /* Overlays */
  --color-overlay: rgba(0, 0, 0, 0.5);

  /* ========================================
     SPACING, RADIUS, TRANSITIONS
     ======================================== */
  --space-xs: 0.5rem;
  --space-sm: 0.75rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;
  --space-2xl: 2.5rem;
  --space-3xl: 3rem;

  --radius-sm: 8px;
  --radius-md: 10px;
  --radius-lg: 15px;
  --radius-xl: 20px;

  --transition-fast: 0.15s ease;
  --transition-base: 0.3s ease;

  --touch-target-min: 44px;
}

/* ========================================
   DARK MODE THEME
   ======================================== */
body[data-theme="dark"] {
  /* Backgrounds */
  --color-bg-app: #0f1419;
  /* Dark app background */
  --color-bg-surface: #1a1f2e;
  /* Cards, containers */
  --color-bg-element: #242938;
  /* UI elements */
  --color-bg-hover: #2d3548;
  /* Hover states */

  /* Text */
  --color-text-primary: #e2e8f0;
  /* Main text */
  --color-text-secondary: #94a3b8;
  /* Secondary text */
  --color-text-muted: #64748b;
  /* Muted text */

  /* Borders */
  --color-border: #334155;
  /* Subtle borders */
  --color-border-hover: #475569;
  /* Hover borders */

  /* Status Colors */
  --color-success-bg: #064e3b;
  --color-success-text: #6ee7b7;
  --color-success-border: #065f46;

  --color-error-bg: #7f1d1d;
  --color-error-text: #fca5a5;
  --color-error-border: #991b1b;

  /* Overlays */
  --color-overlay: rgba(0, 0, 0, 0.7);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  background: linear-gradient(135deg, var(--color-gray-700) 0%, var(--color-gray-900) 100%);
  min-height: 100vh;
  padding: clamp(0.75rem, 3vw, 1.25rem);
  color: var(--color-text-primary);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
  transition: background 0.3s ease, color 0.3s ease;
}

/* ============================================
   CONTAINER (MOBILE-FIRST)
   ============================================ */
.container {
  width: 100%;
  margin: 0 auto;
  background: var(--color-bg-surface);
  border-radius: var(--radius-lg);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
  padding: clamp(1rem, 4vw, 2.5rem);
  /* Add bottom padding to prevent content from being hidden behind fixed player */
  padding-bottom: 280px;
  transition: background 0.3s ease, color 0.3s ease;
}

/* ============================================
   HEADER (MOBILE-FIRST)
   ============================================ */
header {
  position: relative;
  text-align: center;
  margin-bottom: clamp(1.5rem, 5vw, 2.5rem);
  padding-bottom: var(--space-md);
  border-bottom: 2px solid var(--color-border);
  display: flex;
  align-items: flex-start;
  gap: var(--space-sm);
}

.header-content {
  flex: 1;
  text-align: center;
}

/* Theme toggle button */
.theme-toggle-btn {
  width: 50px;
  min-height: 50px;
  padding: 0;
  background: var(--color-accent);
  color: white;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-base);
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.theme-toggle-btn:hover {
  background: var(--color-accent-hover);
  transform: translateY(-2px);
}

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

.theme-toggle-btn .icon {
  font-size: 1.5rem;
  line-height: 1;
}

header h1 {
  /* Fluid typography: scales from 1.75rem (28px) to 3rem (48px) */
  font-size: clamp(1.75rem, 5vw + 0.5rem, 3rem);
  color: var(--color-accent);
  margin-bottom: var(--space-xs);
  line-height: 1.2;
  word-wrap: break-word;
}

.tagline {
  color: var(--color-text-secondary);
  /* Fluid typography: scales from 0.9rem to 1.2rem */
  font-size: clamp(0.9rem, 2.5vw + 0.3rem, 1.2rem);
  line-height: 1.4;
  padding: 0 var(--space-sm);
}

/* ============================================
   CONTROLS (MOBILE-FIRST: STACKED)
   ============================================ */
.controls {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
  margin-bottom: clamp(1.5rem, 4vw, 2rem);
}

.search-box {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  width: 100%;
}

/* ============================================
   FORM INPUTS (MOBILE-OPTIMIZED)
   ============================================ */
#searchInput {
  width: 100%;
  /* Minimum touch target height */
  min-height: var(--touch-target-min);
  padding: var(--space-sm) var(--space-md);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-full);
  font-size: 16px;
  /* Prevents iOS zoom on focus */
  transition: border-color var(--transition-base);
  background: white;
}

#searchInput:focus {
  outline: none;
  border-color: var(--color-accent);
}

#searchInput::placeholder {
  color: var(--color-text-muted);
  opacity: 0.8;
}

/* ============================================
   BUTTONS (MOBILE-OPTIMIZED TOUCH TARGETS)
   ============================================ */
button {
  /* Minimum touch target height */
  min-height: var(--touch-target-min);
  width: 100%;
  padding: var(--space-sm) var(--space-lg);
  background: var(--color-accent);
  color: white;
  border: none;
  border-radius: var(--radius-full);
  cursor: pointer;
  font-size: 1rem;
  font-weight: 600;
  transition: background var(--transition-base), transform var(--transition-fast);
  /* Prevents text selection on double-tap */
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

button:hover {
  background: var(--color-accent-hover);
  transform: translateY(-2px);
}

button:active {
  transform: translateY(0);
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.secondary-btn {
  background: transparent;
  color: var(--color-primary-500);
  border: 2px solid var(--color-primary-500);
}

.secondary-btn:hover {
  background: var(--color-primary-50);
  color: var(--color-primary-700);
  border-color: var(--color-primary-700);
}

/* ============================================
   STATUS MESSAGES
   ============================================ */
.status {
  padding: var(--space-md);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-lg);
  font-weight: 500;
  font-size: 0.9rem;
  line-height: 1.5;
}

.status.success {
  background: var(--success-bg);
  color: var(--success-text);
  border: 1px solid var(--success-border);
}

.status.error {
  background: var(--error-bg);
  color: var(--error-text);
  border: 1px solid var(--error-border);
}

.status.hidden {
  display: none;
}

/* ============================================
   AUDIO PLAYER (FIXED AT BOTTOM)
   ============================================ */
.player-container {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  width: 100%;
  background: linear-gradient(135deg, var(--color-gray-700) 0%, var(--color-gray-900) 100%);
  padding: var(--space-md) var(--space-lg);
  color: white;
  z-index: 100;
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.3);
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
  max-height: 50vh;
  overflow-y: auto;
}

.now-playing {
  margin-bottom: var(--space-sm);
}

.song-info h3 {
  font-size: 1rem;
  margin-bottom: 2px;
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.song-info p {
  opacity: 0.9;
  font-size: 0.85rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#audioPlayer {
  width: 100%;
  min-height: 40px;
  max-height: 50px;
}

/* Player Controls - Single Row Layout */
.player-controls {
  display: flex;
  gap: var(--space-xs);
  justify-content: center;
  align-items: center;
  margin-top: var(--space-md);
  padding-top: var(--space-md);
  border-top: 1px solid rgba(255, 255, 255, 0.2);
  flex-wrap: nowrap;
}

/* Mode Control Buttons (Shuffle, Repeat, Auto-next) */
.control-btn {
  min-height: 40px;
  min-width: 40px;
  width: auto;
  padding: 8px;
  background: rgba(255, 255, 255, 0.1);
  color: white;
  border: 2px solid transparent;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-base);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.control-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: translateY(-2px);
}

.control-btn.active {
  background: var(--color-accent);
  border-color: var(--color-accent-hover);
}

.control-btn.active:hover {
  background: var(--color-accent-hover);
}

.control-btn .icon {
  font-size: 1.1rem;
  line-height: 1;
}

/* Repeat mode states */
.control-btn[data-repeat="one"],
.control-btn[data-repeat="all"] {
  background: var(--color-primary-500);
  border-color: var(--color-primary-600);
}

.control-btn[data-repeat="one"]:hover,
.control-btn[data-repeat="all"]:hover {
  background: var(--color-primary-600);
}

/* Navigation Buttons (Previous, Next) */
.nav-btn {
  min-height: 44px;
  min-width: 44px;
  padding: 10px;
  background: var(--color-accent);
  color: white;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  transition: all var(--transition-base);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  flex-shrink: 0;
}

.nav-btn:hover {
  background: var(--color-accent-hover);
  transform: translateY(-2px) scale(1.05);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.3);
}

.nav-btn:active {
  transform: translateY(0) scale(0.98);
}

.nav-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

.nav-btn .icon {
  font-size: 1.2rem;
  line-height: 1;
}

/* ============================================
   SONG LIST (MOBILE-FIRST)
   ============================================ */
.song-list h2 {
  margin-bottom: var(--space-lg);
  color: var(--color-text-primary);
  font-size: clamp(1.25rem, 3vw + 0.5rem, 1.75rem);
}

.songs {
  display: grid;
  gap: var(--space-md);
  /* Single column on mobile */
  grid-template-columns: 1fr;
}

/* ============================================
   SONG ITEMS (MOBILE: STACKED LAYOUT)
   ============================================ */
.song-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--space-sm);
  padding: var(--space-md);
  background: var(--color-bg-element);
  border-radius: var(--radius-md);
  transition: all var(--transition-base);
  /* Remove cursor pointer on mobile (tap is implicit) */
  /* Ensure song items don't overflow */
  max-width: 100%;
  overflow: hidden;
}

.song-item:active {
  background: var(--color-bg-hover);
  transform: scale(0.98);
}

.song-details {
  width: 100%;
  max-width: 100%;
  /* Prevent overflow from long text */
  overflow: hidden;
}

.song-name {
  font-weight: 600;
  font-size: clamp(1rem, 2.5vw + 0.2rem, 1.1rem);
  color: var(--color-text-primary);
  margin-bottom: var(--space-xs);
  line-height: 1.3;
  word-wrap: break-word;
}

.song-meta {
  color: var(--color-text-secondary);
  font-size: clamp(0.8rem, 2vw + 0.1rem, 0.9rem);
  line-height: 1.4;
}

/* ============================================
   SONG ACTIONS (MOBILE: FULL WIDTH BUTTONS)
   ============================================ */
.song-actions {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  width: 100%;
  max-width: 100%;
  /* Ensure no overflow */
  overflow: hidden;
}

.play-btn,
.download-btn {
  width: 100%;
  max-width: 100%;
  min-height: var(--touch-target-min);
  padding: var(--space-sm) var(--space-lg);
  border-radius: var(--radius-xl);
  font-size: 0.95rem;
  font-weight: 600;
  /* Prevent text from causing overflow */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  /* Ensure button content doesn't expand beyond bounds */
  box-sizing: border-box;
}

.download-btn {
  background: transparent;
  color: var(--color-primary-500);
  border: 2px solid var(--color-primary-500);
}

.download-btn:hover {
  background: var(--color-primary-50);
  color: var(--color-primary-700);
  border-color: var(--color-primary-700);
}

/* ============================================
   LOADING STATE
   ============================================ */
.loading {
  text-align: center;
  padding: var(--space-2xl);
  color: var(--color-text-muted);
  font-size: clamp(0.95rem, 2.5vw + 0.2rem, 1.1rem);
}

/* ============================================
   SYNC INFO
   ============================================ */
.sync-info {
  margin-top: clamp(2rem, 5vw, 2.5rem);
  padding-top: clamp(1.5rem, 4vw, 2rem);
  border-top: 2px solid var(--color-border);
}

.sync-info h3 {
  margin-bottom: var(--space-md);
  color: var(--color-text-primary);
  font-size: clamp(1.1rem, 2.5vw + 0.3rem, 1.25rem);
}

.sync-item {
  padding: var(--space-sm) var(--space-md);
  background: var(--color-bg-element);
  border-radius: var(--radius-sm);
  margin-bottom: var(--space-sm);
  font-size: clamp(0.8rem, 2vw + 0.1rem, 0.9rem);
  line-height: 1.5;
}

.sync-item .sync-date {
  font-weight: 600;
  color: var(--color-accent);
  display: block;
  margin-bottom: var(--space-xs);
}

.sync-item .sync-stats {
  color: var(--color-text-muted);
  font-size: 0.85rem;
}

/* ============================================
   HAMBURGER MENU (MOBILE ONLY)
   ============================================ */

/* Hamburger button */
.hamburger-btn {
  position: relative;
  width: 50px;
  min-height: 50px;
  padding: 0;
  background: var(--color-accent);
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  z-index: 998;
  transition: background var(--transition-base), z-index 0s;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

/* Increase z-index when menu is active to stay above everything */
.hamburger-btn.active {
  z-index: 1003;
}

.hamburger-btn:hover {
  background: var(--color-accent-hover);
}

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

/* Hamburger lines */
.hamburger-line {
  width: 28px;
  height: 3px;
  background: white;
  border-radius: 2px;
  transition: all var(--transition-base);
  pointer-events: none;
}

/* Animate to X when active */
.hamburger-btn.active .hamburger-line:nth-child(1) {
  transform: translateY(9px) rotate(45deg);
}

.hamburger-btn.active .hamburger-line:nth-child(2) {
  opacity: 0;
  transform: translateX(-10px);
}

.hamburger-btn.active .hamburger-line:nth-child(3) {
  transform: translateY(-9px) rotate(-45deg);
}

/* Menu overlay */
.menu-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.5);
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--transition-base), visibility var(--transition-base);
  z-index: 999;
  backdrop-filter: blur(2px);
}

.menu-overlay.active {
  opacity: 1;
  visibility: visible;
}

/* Mobile menu */
.mobile-menu {
  position: fixed;
  top: 0;
  left: 0;
  width: 85%;
  max-width: 400px;
  height: 100vh;
  background: var(--color-bg-surface);
  transform: translateX(-100%);
  transition: transform var(--transition-base);
  z-index: 1002;
  overflow-y: auto;
  box-shadow: 4px 0 12px rgba(0, 0, 0, 0.15);
  padding: var(--space-xl) var(--space-lg);
  padding-top: 80px;
}

.mobile-menu.active {
  transform: translateX(0);
}

/* Controls inside the menu */
.mobile-menu .controls {
  margin-bottom: 0;
}

/* ============================================
   RESPONSIVE BREAKPOINTS (MOBILE-FIRST)
   ============================================ */

/* Extra Small Screens (very small phones): up to 360px */
@media (max-width: 360px) {

  .play-btn,
  .download-btn {
    /* Reduce padding on very small screens */
    padding: var(--space-sm) var(--space-md);
    font-size: 0.9rem;
  }

  .song-item {
    /* Reduce padding on very small screens */
    padding: var(--space-sm);
  }

  .container {
    /* Reduce container padding on very small screens */
    padding: var(--space-md);
  }
}

/* Large Mobile / Small Tablet: 481px+ */
@media (min-width: 481px) {
  .search-box {
    flex-direction: row;
  }

  #searchInput {
    flex: 1;
  }

  button {
    width: auto;
    min-width: 120px;
  }

  .song-actions {
    flex-direction: row;
    justify-content: flex-start;
  }

  .play-btn,
  .download-btn {
    width: auto;
    min-width: 100px;
  }
}

/* Tablet: 768px+ */
@media (min-width: 768px) {
  body {
    padding: clamp(1.25rem, 3vw, 2rem);
  }

  /* Hide hamburger menu on desktop */
  .hamburger-btn {
    display: none;
  }

  .menu-overlay {
    display: none;
  }

  /* Show controls normally (not in slide-out menu) */
  .mobile-menu {
    position: static;
    width: 100%;
    max-width: none;
    height: auto;
    transform: translateX(0);
    box-shadow: none;
    padding: 0;
    overflow-y: visible;
  }

  .controls {
    flex-direction: row;
    align-items: center;
  }

  .search-box {
    flex: 1;
    max-width: 600px;
  }

  button {
    width: auto;
  }

  .song-item {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-lg);
  }

  /* Hover effects only on non-touch devices */
  .song-item:hover {
    background: var(--color-bg-hover);
    transform: translateX(5px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
  }

  .song-details {
    flex: 1;
    width: auto;
  }

  .song-actions {
    flex-direction: row;
    width: auto;
  }

  /* Reduce bottom padding for tablet screens */
  .container {
    padding-bottom: 250px;
  }

  /* Make player slightly more compact on larger screens */
  .player-container {
    padding: var(--space-md) var(--space-xl);
  }
}

/* Desktop: 992px+ */
@media (min-width: 992px) {
  .container {
    max-width: 1000px;
    padding-bottom: 220px;
  }

  /* Further optimize player spacing for desktop */
  .player-container {
    padding: var(--space-lg) var(--space-2xl);
  }

  .player-controls {
    gap: var(--space-md);
  }

  .songs {
    gap: var(--space-lg);
  }

  header {
    margin-bottom: var(--space-2xl);
  }
}

/* Large Desktop: 1200px+ */
@media (min-width: 1200px) {
  .container {
    max-width: 1200px;
    padding: var(--space-2xl) var(--space-3xl);
    padding-bottom: 200px;
  }

  .songs {
    gap: var(--space-lg);
  }

  /* Optimize player layout for large screens */
  .player-container {
    padding: var(--space-lg) var(--space-3xl);
  }

  .now-playing {
    margin-bottom: var(--space-md);
  }
}

/* ============================================
   ACCESSIBILITY IMPROVEMENTS
   ============================================ */

/* Focus visible for keyboard navigation */
*:focus-visible {
  outline: 3px solid var(--color-accent);
  outline-offset: 2px;
}

/* Reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  .container {
    border: 2px solid var(--color-text-primary);
  }

  button {
    border: 2px solid transparent;
  }

  button:focus {
    border-color: currentColor;
  }
}

/* Dark mode support (optional, can be enabled later) */
@media (prefers-color-scheme: dark) {
  /* Uncomment to enable dark mode */
  /*
  body {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
  }

  .container {
    background: #0f3460;
    color: #e8e8e8;
  }

  header h1,
  .song-name,
  .song-list h2,
  .sync-info h3 {
    color: var(--color-accent);
  }

  .tagline,
  .song-meta,
  .sync-stats {
    color: #b0b0b0;
  }

  .song-item {
    background: #1a1a2e;
  }

  .song-item:hover {
    background: #16213e;
  }
  */
}

/* ============================================
   PRINT STYLES
   ============================================ */
@media print {
  body {
    background: white;
    padding: 0;
  }

  .container {
    box-shadow: none;
    max-width: 100%;
  }

  .controls,
  .player-container,
  .song-actions,
  button {
    display: none;
  }

  .song-item {
    page-break-inside: avoid;
  }
}