/* =============================================================================
   Music Explorer UI
   - Dark/light theme variables
   - Responsive layout for main menu & recommendation cards
   - Styling for rating controls, YouTube preview, and loading overlay
   ============================================================================= */

/* =========================
   Base / Theme Variables
   ========================= */
* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:#0b1220;
  --ink:#e5e7eb;
  --card:#121a2a;
  --muted:#9ca3af;
  --ring:#1f2937;
  --brand-1:#7c83ff;
  --brand-2:#b074ff;
  --accent:#1DB954; /* spotify green */
  --shadow: 0 8px 24px rgba(0,0,0,.25);
}

body.light {
  --bg:#f8fafc;
  --ink:#111827;
  --card:#ffffff;
  --muted:#6b7280;
  --ring:#e5e7eb;
  --brand-1:#4f46e5;
  --brand-2:#9333ea;
  --shadow: 0 6px 18px rgba(15,23,42,.12);
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, "Segoe UI", Roboto, system-ui, sans-serif;
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
}

/* =========================
   Header
   ========================= */
header {
  background: linear-gradient(135deg, var(--brand-1), var(--brand-2));
  color: #fff;
  padding: 1rem 1.25rem;
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
}

header h1 { font-size: 1.4rem; font-weight: 600; }

.header-right { display: flex; gap: .5rem; align-items: center; }

.header-action {
  display: none;
  background: rgba(255,255,255,.16);
  color: #fff;
  border: 1px solid rgba(255,255,255,.3);
  padding: .45rem .8rem;
  border-radius: 6px;
  font-size: .9rem;
  cursor: pointer;
}
.header-action:hover { filter: brightness(1.06); }

.theme-toggle {
  background: rgba(255,255,255,.16);
  color: #fff;
  border: 1px solid rgba(255,255,255,.3);
  border-radius: 999px;
  padding: .5rem .6rem;
  cursor: pointer;
  line-height: 1;
}

/* =========================
   Pages
   ========================= */
.page {
  display: none;
  padding: 1.25rem 0;
  opacity: 0;
  transition: opacity 0.3s ease;
}
.page.active {
  display: block;
  gap: 1rem;
  justify-items: center;
  text-align: center;
  width: min(1000px, 94%);
  margin: 1rem auto 2rem;
  opacity: 1;
}

/* Main menu layout (better on tall/large screens) */
#main-menu.page.active {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  padding-top: 2rem;
}

/* Ensure it hides cleanly when not active */
#main-menu.page { display: none; }

/* =========================
   Main Menu
   ========================= */
.welcome-text {
  max-width: 600px;
  margin: 0 auto 1.5rem auto;
  text-align: center;
  line-height: 1.45;
  opacity: 0.9;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  animation: fadeUp 0.5s ease-out both;
}
body:not(.light) .welcome-text { background: rgba(255,255,255,0.05); }
body.light .welcome-text       { background: rgba(0,0,0,0.05); }

.menu-buttons {
  display: flex;
  gap: .75rem;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 1rem !important;
}
.menu-btn { font-size: .95rem; padding: .55rem 1.2rem; border-radius: 8px; }

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

/* =========================
   Buttons
   ========================= */
button {
  appearance: none;
  border: none;
  outline: none;
  cursor: pointer;
  font: inherit;
  padding: .7rem 1.1rem;
  border-radius: 8px;
  transition: background .2s, filter .2s, opacity .2s, transform .15s ease, box-shadow .2s ease;
}
button:hover:not(:disabled) { transform: translateY(-2px); }

.primary { background: var(--brand-1); color: #fff; }
.primary:hover { filter: brightness(1.06); }

.secondary { background: #e5e7eb; color: #111; }
body:not(.light) .secondary { background: #1f2937; color: #e5e7eb; }

button.disabled { opacity: .55; cursor: not-allowed; }

/* =========================
   Mode Toggle
   ========================= */
.mode-toggle {
  display: flex;
  gap: .5rem;
  justify-content: center;
  align-items: center;
  margin: .25rem 0 0.75rem;
  flex-wrap: wrap;
}
.mode-btn {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--ring);
  border-radius: 999px;
  padding: .45rem .9rem;
  font-size: .9rem;
  transition: transform .15s ease, box-shadow .2s ease, background-color .2s ease;
}
.mode-btn:hover:not(.active):not(:disabled) { transform: translateY(-2px); }
.mode-btn.active { background: var(--brand-1); color: #fff; border-color: transparent; }

/* =========================
   Sections
   ========================= */
.song-section { width: 100%; margin: .25rem 0 1rem; }
.section-title { font-size: 1.05rem; margin-bottom: .25rem; opacity: .95; }

/* =========================
   Results Grid
   ========================= */
.results {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}
/* Tablets & phones: always 1 card per row */
@media (max-width: 1024px) {
  .results {
    grid-template-columns: 1fr;
  }
}

/* Phones: slightly bigger cards & text */
@media (max-width: 640px) {
  .results {
    grid-template-columns: 1fr;
  }
  .song-card {
    max-width: 100%;
    min-height: 360px;
    padding: 16px 14px;
  }
  .song-card h3 {
    font-size: 1.1rem;
  }
  .song-card p {
    font-size: 0.95rem;
  }
}

/* Center rows on non-hybrid modes (still responsive) */
.results.center {
  justify-content: center;
  grid-template-columns: repeat(auto-fit, minmax(280px, 320px));
}

/* =========================
   Cards
   ========================= */
.song-card {
  background: var(--card);
  border: 1px solid var(--ring);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  min-height: 240px;
  transform: translateZ(0);
  transition: transform .20s ease, box-shadow .25s ease;
}
.song-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 6px 18px rgba(0,0,0,0.25);
}
.song-card h3 { font-size: 1.05rem; line-height: 1.35; text-align: center; }
.song-card p  { opacity: .9; }

/* (Keep in case some cards still render it) */
.spotify-link {
  display: inline-block;
  text-decoration: none;
  color: #fff;
  background: var(--accent);
  padding: .45rem .7rem;
  border-radius: 6px;
  font-size: .9rem;
}
.spotify-link:hover { filter: brightness(1.06); }

/* =========================
   Rating buttons
   ========================= */
.song-actions { display: grid; gap: .35rem; width: 100%; }
.song-actions button {
  background: transparent;
  border: 1px solid var(--ring);
  color: var(--ink);
  padding: .45rem;
  border-radius: 6px;
  font-size: .9rem;
  transition: transform .15s ease, box-shadow .2s ease, background-color .2s ease;
}
.song-actions button:hover { background: rgba(127,127,255,.08); }
.song-actions button.selected {
  border-color: var(--accent);
  background: linear-gradient(
    135deg,
    rgba(124,131,255,0.18),
    rgba(176,116,255,0.24)
  );
  color: #fff;
  box-shadow:
    0 0 0 2px rgba(124,131,255,0.25),
    0 10px 22px rgba(15,23,42,0.45);
  transform: translateY(-2px) scale(1.02);
}

/* =========================
   Player / Preview
   ========================= */
.player-area { margin-top: 8px; width: 100%; }
.yt-holder { width: 100%; display: flex; justify-content: center; }

.preview-btn {
  margin-top: 6px;
  width: 100%;
  padding: 6px 8px;
  border-radius: 6px;
  background: var(--accent);
  color: white;
  border: none;
  cursor: pointer;
}

.no-preview {
  opacity: 0.7;
  font-size: 0.9rem;
  margin-top: 6px;
}

/* Distinct progress + volume slider rows */
.slider-row {
  display: none;              /* shown via JS when video is ready */
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  margin-top: 6px;
}

.slider-icon {
  font-size: 0.85rem;
  opacity: 0.8;
}

/* Progress bar = purple/brand, Volume = green/accent */
.progress-slider,
.volume-slider {
  width: 100%;
  cursor: pointer;
}

/* Use accent-color so the thumb/track match theme */
.progress-slider {
  accent-color: var(--brand-1);
}

.volume-slider {
  accent-color: var(--accent);
}

/* =========================
   Controls & Footer
   ========================= */
.controls { display: grid; place-items: center; margin: .5rem 0 0; }
footer { text-align: center; color: var(--muted); font-size: .9rem; padding: 1rem; }

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

.song-card.disabled-card {
  opacity: 0.5;
  pointer-events: none;
  filter: grayscale(1);
  position: relative;
}

.no-video-msg {
  color: #ff5555;
  font-style: italic;
  text-align: center;
  margin: 10px 0;
}

/* =========================
   Loading overlay
   ========================= */
.loading-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(circle at top, rgba(255,255,255,0.08), transparent 55%),
    rgba(0,0,0,0.55);
  z-index: 999;
  backdrop-filter: blur(6px);
}

.loading-inner {
  background: var(--card);
  border-radius: 16px;
  padding: 1.5rem 2rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  border: 1px solid var(--ring);
}

.loading-inner p {
  color: var(--muted);
  font-size: 0.95rem;
}

/* Spinner */
.spinner {
  width: 36px;
  height: 36px;
  border-radius: 999px;
  border: 3px solid rgba(255,255,255,0.2);
  border-top-color: var(--brand-1);
  animation: spin 0.75s linear infinite;
}

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

/* While loading: dim + soften rest of UI and visually disable buttons */
body.loading header,
body.loading footer,
body.loading .page {
  filter: blur(1px) brightness(0.9);
  transition: filter 0.2s ease;
}

body.loading button {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Block interaction with underlying UI but still allow overlay to work */
body.loading {
  pointer-events: none;
}

body.loading .loading-overlay {
  pointer-events: auto; /* overlay itself still interactive if you ever need it */
}
