/* ==========================================
   Mother & Son Dance — Song Picker
   Aesthetic: Editorial luxury, warm & timeless
   ========================================== */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --ivory: #FFFBF5;
  --cream: #F7F1E8;
  --champagne: #E8DDD0;
  --gold: #B8952E;
  --gold-soft: #D4BD7A;
  --gold-bg: #FAF4E6;
  --charcoal: #2A2118;
  --warm-gray: #7A6E62;
  --sage: #6B8F71;
  --sage-bg: #EDF5EE;
  --blush: #C07054;
  --blush-bg: #FDF0EB;
  --sky: #5A7EA6;
  --sky-bg: #EBF1F7;
  --muted: #B5AA9C;
  --card: #FFFFFF;
  --shadow-sm: 0 1px 3px rgba(42,33,24,0.06);
  --shadow-md: 0 4px 12px rgba(42,33,24,0.08);
  --shadow-lg: 0 8px 30px rgba(42,33,24,0.10);
  --radius: 6px;
  --radius-sm: 3px;
  --font-display: 'Cormorant Garamond', Georgia, serif;
  --font-body: 'DM Sans', -apple-system, sans-serif;
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
}

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-body);
  background: var(--ivory);
  color: var(--charcoal);
  line-height: 1.55;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

/* ===== HEADER ===== */
header {
  text-align: center;
  padding: 48px 24px 40px;
  background: var(--charcoal);
  color: var(--cream);
  position: relative;
  overflow: hidden;
}

header::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at 30% 20%, rgba(184,149,46,0.12) 0%, transparent 60%),
    radial-gradient(ellipse at 70% 80%, rgba(184,149,46,0.08) 0%, transparent 50%);
  pointer-events: none;
}

header h1 {
  font-family: var(--font-display);
  font-size: clamp(2.2rem, 8vw, 3.2rem);
  font-weight: 300;
  letter-spacing: 0.06em;
  color: var(--gold-soft);
  position: relative;
}

.header-subtitle {
  font-family: var(--font-display);
  font-size: clamp(1rem, 3.5vw, 1.25rem);
  font-weight: 400;
  font-style: italic;
  color: var(--champagne);
  margin-top: 4px;
  letter-spacing: 0.02em;
}

.header-meta {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 12px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-weight: 300;
}

.header-ornament {
  width: 60px;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--gold-soft), transparent);
  margin: 12px auto;
}

/* ===== NOW PLAYING BAR ===== */
.now-playing {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--charcoal);
  color: var(--cream);
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 100;
  box-shadow: 0 -4px 20px rgba(0,0,0,0.2);
  transform: translateY(0);
  transition: transform 0.4s var(--ease);
  padding-bottom: max(12px, env(safe-area-inset-bottom));
}

.now-playing.hidden {
  transform: translateY(100%);
}

/* Scrubber */
.np-scrubber {
  position: absolute;
  top: -14px;
  left: 0;
  right: 0;
  height: 28px;
  cursor: pointer;
  z-index: 2;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

.np-scrubber-track {
  position: absolute;
  top: 12px;
  left: 0;
  right: 0;
  height: 4px;
  background: rgba(255,255,255,0.15);
  border-radius: 2px;
  overflow: hidden;
}

.np-scrubber-fill {
  height: 100%;
  width: 0%;
  background: var(--gold-soft);
  transition: width 0.3s linear;
  pointer-events: none;
}

.np-scrubber.dragging .np-scrubber-fill {
  transition: none;
}

.np-scrubber-thumb {
  position: absolute;
  top: 6px;
  left: 0%;
  width: 16px;
  height: 16px;
  margin-left: -8px;
  background: var(--gold-soft);
  border: 2px solid var(--cream);
  border-radius: 50%;
  box-shadow: 0 1px 4px rgba(0,0,0,0.3);
  transition: left 0.3s linear, transform 0.15s;
  pointer-events: none;
}

.np-scrubber.dragging .np-scrubber-thumb {
  transition: transform 0.15s;
  transform: scale(1.3);
}

.np-scrubber:active .np-scrubber-thumb {
  transform: scale(1.3);
}

.np-time {
  font-size: 0.65rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.np-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.np-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--gold-soft);
  font-weight: 500;
}

.np-title {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 400;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.np-controls {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.np-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.2);
  background: transparent;
  color: var(--cream);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.1rem;
  transition: all 0.2s var(--ease);
}

.np-btn:hover { background: rgba(255,255,255,0.1); }
.np-btn:active { transform: scale(0.92); }

/* ===== MAIN ===== */
main {
  max-width: 520px;
  margin: 0 auto;
  padding: 20px 16px 100px;
}

/* ===== STATS ===== */
.stats-row {
  display: flex;
  gap: 2px;
  margin-bottom: 20px;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--champagne);
}

.stat-cell {
  flex: 1;
  text-align: center;
  padding: 14px 8px;
  background: var(--card);
  cursor: pointer;
  transition: all 0.2s var(--ease);
}

.stat-cell:hover { background: var(--cream); }
.stat-cell.active { background: var(--charcoal); }
.stat-cell.active .stat-num { color: var(--gold-soft) !important; }
.stat-cell.active .stat-label { color: var(--cream); }

.stat-cell:first-child { border-radius: var(--radius) 0 0 var(--radius); }
.stat-cell:last-child { border-radius: 0 var(--radius) var(--radius) 0; }

.stat-num {
  font-family: var(--font-display);
  font-size: 1.6rem;
  font-weight: 500;
  line-height: 1;
}

.stat-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--warm-gray);
  margin-top: 4px;
  font-weight: 500;
}

/* ===== CONTROLS ROW ===== */
.controls-row {
  display: flex;
  gap: 10px;
  margin-bottom: 12px;
  align-items: stretch;
}

.controls-row .add-toggle {
  flex: 2;
  margin-bottom: 0;
}

.controls-row .sort-dropdown {
  flex: 1;
}

.sort-dropdown {
  padding: 7px 10px;
  border: 1px solid var(--champagne);
  border-radius: var(--radius-sm);
  background: var(--card);
  font-size: 0.78rem;
  font-family: var(--font-body);
  color: var(--warm-gray);
  cursor: pointer;
  flex-shrink: 0;
}

/* ===== ADD SONG ===== */
.add-toggle {
  width: 100%;
  padding: 14px;
  border: 1.5px dashed var(--champagne);
  border-radius: var(--radius);
  background: transparent;
  font-family: var(--font-body);
  font-size: 0.88rem;
  color: var(--warm-gray);
  cursor: pointer;
  transition: all 0.2s var(--ease);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.add-toggle:hover { border-color: var(--gold-soft); color: var(--gold); }

.add-form {
  margin-bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.add-form.hidden { display: none; }

.add-input {
  padding: 12px 14px;
  border: 1px solid var(--champagne);
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 16px;
  background: var(--card);
  color: var(--charcoal);
  transition: border-color 0.2s;
}

.add-input:focus { outline: none; border-color: var(--gold); }
.add-input::placeholder { color: var(--muted); }

.btn-add {
  padding: 12px;
  background: var(--gold);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s var(--ease);
}

.btn-add:hover { background: #a07d1e; }
.btn-add:active { transform: scale(0.98); }

/* ===== SONG CARDS ===== */
.song-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.song-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  transition: all 0.3s var(--ease);
  position: relative;
  overflow: hidden;
  border: 1px solid transparent;
}

.song-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 3px;
  height: 100%;
  background: var(--champagne);
  transition: background 0.3s var(--ease);
}

.song-card.rated-5::before { background: var(--gold); }
.song-card.rated-4::before { background: var(--sage); }
.song-card.rated-3::before { background: var(--gold-soft); }
.song-card.rated-2::before { background: var(--blush); }
.song-card.rated-1::before { background: var(--muted); }

.song-card.playing {
  border-color: var(--gold-soft);
  box-shadow: var(--shadow-md), 0 0 0 1px var(--gold-soft);
}

.song-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 6px;
}

.song-title {
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 500;
  line-height: 1.2;
  color: var(--charcoal);
}

.song-artist {
  font-size: 0.85rem;
  color: var(--warm-gray);
  margin-bottom: 8px;
}

.song-desc {
  font-size: 0.85rem;
  color: var(--warm-gray);
  line-height: 1.55;
  margin-bottom: 14px;
}

/* Play row */
.play-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  padding: 10px 14px;
  background: var(--cream);
  border-radius: var(--radius-sm);
}

.play-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--charcoal);
  color: var(--cream);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1rem;
  flex-shrink: 0;
  transition: all 0.2s var(--ease);
}

.play-btn:hover { background: var(--gold); }

/* Linking spinner */
.play-row.linking { opacity: 0.7; }
.linking-spinner {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  color: var(--gold);
  flex-shrink: 0;
}
.linking-spinner i { animation: spin 1s linear infinite; }

/* Enriching state */
.song-desc.enriching {
  color: var(--gold);
  font-style: italic;
}
.enriching-icon {
  animation: pulse 1.5s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 1; }
}
.play-btn:active { transform: scale(0.9); }
.play-btn.is-playing { background: var(--gold); }

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

.play-status {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 500;
}

.play-status.active { color: var(--gold); }

.play-yt-link {
  font-size: 0.78rem;
  color: var(--warm-gray);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 4px;
}

.play-yt-link:hover { color: var(--gold); }

/* YouTube URL input row */
.yt-url-row {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
}

.yt-url-input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--champagne);
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-family: var(--font-body);
  background: var(--card);
  color: var(--charcoal);
}

.yt-url-input:focus { outline: none; border-color: var(--gold); }
.yt-url-input::placeholder { color: var(--muted); }

.yt-url-btn {
  padding: 8px 14px;
  border: 1px solid var(--champagne);
  border-radius: var(--radius-sm);
  background: var(--card);
  font-size: 0.78rem;
  font-family: var(--font-body);
  color: var(--warm-gray);
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s var(--ease);
}

.yt-url-btn:hover { border-color: var(--gold); color: var(--gold); }

/* Rating */
.rating-row {
  display: flex;
  gap: 4px;
}

.rate-btn {
  flex: 1;
  padding: 8px 4px;
  border: 1.5px solid var(--champagne);
  background: var(--card);
  border-radius: var(--radius-sm);
  font-size: 0.7rem;
  font-family: var(--font-body);
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s var(--ease);
  text-align: center;
  line-height: 1.2;
  color: var(--warm-gray);
}

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

.rate-btn[data-r="1"] { }
.rate-btn[data-r="1"].on { background: var(--muted); color: #fff; border-color: var(--muted); }
.rate-btn[data-r="2"] { }
.rate-btn[data-r="2"].on { background: var(--blush); color: #fff; border-color: var(--blush); }
.rate-btn[data-r="3"] { }
.rate-btn[data-r="3"].on { background: var(--gold-soft); color: #fff; border-color: var(--gold-soft); }
.rate-btn[data-r="4"] { }
.rate-btn[data-r="4"].on { background: var(--sage); color: #fff; border-color: var(--sage); }
.rate-btn[data-r="5"] { }
.rate-btn[data-r="5"].on { background: var(--gold); color: #fff; border-color: var(--gold); }

/* Three-dot menu */
.card-menu {
  position: relative;
  flex-shrink: 0;
}

.menu-btn {
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  border-radius: var(--radius-sm);
  transition: all 0.15s;
}

.menu-btn:hover {
  color: var(--charcoal);
  background: var(--cream);
}

.menu-dropdown {
  position: absolute;
  top: 100%;
  right: 0;
  background: var(--card);
  border: 1px solid var(--champagne);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  z-index: 10;
  min-width: 120px;
  overflow: hidden;
}

.menu-item {
  display: block;
  width: 100%;
  padding: 9px 14px;
  border: none;
  background: transparent;
  text-align: left;
  font-size: 0.82rem;
  font-family: var(--font-body);
  color: var(--warm-gray);
  cursor: pointer;
  transition: all 0.15s;
}

.menu-item:hover {
  background: var(--cream);
  color: var(--blush);
}

/* Sync indicator */
.sync-indicator {
  position: fixed;
  top: 12px;
  right: 12px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(255,255,255,0.9);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--sage);
  font-size: 1rem;
  z-index: 90;
  box-shadow: var(--shadow-sm);
  transition: all 0.3s var(--ease);
}

.sync-indicator.syncing { color: var(--gold); }
.sync-indicator.error { color: var(--blush); }
.sync-indicator.offline { color: var(--muted); }

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

.sync-indicator.syncing i {
  animation: spin 1s linear infinite;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--muted);
}

.empty-state i {
  font-size: 2.5rem;
  margin-bottom: 12px;
  display: block;
  color: var(--champagne);
}

.empty-state p {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-style: italic;
}

/* Footer */
.site-footer {
  text-align: center;
  padding: 32px 16px 24px;
  max-width: 520px;
  margin: 0 auto;
}

.site-footer p {
  font-size: 0.72rem;
  color: var(--muted);
  letter-spacing: 0.04em;
}

.site-footer #footerYear {
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
}

/* ===== "THE ONE" CELEBRATION ===== */
.song-card.the-one-celebration {
  animation: theOneCelebrate 4s ease-out forwards;
  z-index: 50;
  position: relative;
}

.song-card.the-one-celebration::after {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: var(--radius);
  border: 2px solid var(--gold);
  animation: theOnePulse 0.7s ease-out 4;
  pointer-events: none;
}

/* "The One" active mode — fade everything except header + selected card */
body.the-one-active .stats-row,
body.the-one-active .controls-row,
body.the-one-active .add-form,
body.the-one-active .site-footer,
body.the-one-active .sync-indicator {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.8s var(--ease);
}

body.the-one-active .now-playing {
  transform: translateY(100%);
  pointer-events: none;
}

header.the-one-header h1 {
  font-size: clamp(1.4rem, 5.5vw, 2rem);
  font-weight: 300;
  font-style: italic;
  line-height: 1.4;
  letter-spacing: 0.02em;
}

/* Phase 2: collapse space after fade so card moves up flush under header */
body.the-one-collapsed .stats-row,
body.the-one-collapsed .controls-row,
body.the-one-collapsed .add-form {
  display: none;
}

.song-card.the-one-selected {
  border-color: var(--gold-soft);
  box-shadow: 0 0 20px rgba(184,149,46,0.15);
}

@keyframes theOneCelebrate {
  0% {
    transform: scale(1);
    box-shadow: var(--shadow-sm);
  }
  10% {
    transform: scale(1.05);
    box-shadow: 0 0 30px rgba(184,149,46,0.4), 0 0 60px rgba(184,149,46,0.15);
  }
  30% {
    transform: scale(1.05);
    box-shadow: 0 0 40px rgba(184,149,46,0.5), 0 0 80px rgba(184,149,46,0.2);
  }
  70% {
    transform: scale(1.03);
    box-shadow: 0 0 20px rgba(184,149,46,0.25);
  }
  100% {
    transform: scale(1);
    box-shadow: 0 0 15px rgba(184,149,46,0.15);
  }
}

@keyframes theOnePulse {
  0% {
    opacity: 1;
    inset: -4px;
  }
  100% {
    opacity: 0;
    inset: -20px;
  }
}

/* "The One" confirmation dialog */
.the-one-confirm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(42, 33, 24, 0);
  backdrop-filter: blur(0px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  transition: all 0.3s var(--ease);
}

.the-one-confirm-overlay.visible {
  background: rgba(42, 33, 24, 0.55);
  backdrop-filter: blur(4px);
}

.the-one-confirm {
  background: var(--card);
  border-radius: var(--radius);
  padding: 36px 28px 28px;
  text-align: center;
  box-shadow: var(--shadow-lg);
  max-width: 280px;
  width: 90%;
  transform: scale(0.9);
  opacity: 0;
  transition: all 0.3s var(--ease);
}

.the-one-confirm-overlay.visible .the-one-confirm {
  transform: scale(1);
  opacity: 1;
}

.the-one-confirm-text {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 400;
  color: var(--charcoal);
  margin-bottom: 24px;
  line-height: 1.3;
}

.the-one-confirm-text em {
  color: var(--gold);
  font-style: italic;
}

.the-one-confirm-btns {
  display: flex;
  gap: 10px;
}

.the-one-btn {
  flex: 1;
  padding: 12px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s var(--ease);
}

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

.the-one-yes {
  background: var(--gold);
  color: white;
}

.the-one-yes:hover { background: #a07d1e; }

.the-one-no {
  background: transparent;
  color: var(--warm-gray);
  border: 1px solid var(--champagne);
}

.the-one-no:hover { background: var(--cream); }

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

/* Animations */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Animation only on initial page load, disabled during auto-link */

/* Mobile polish */
@media (max-width: 420px) {
  header { padding: 36px 16px 32px; }
  main { padding: 16px 12px 100px; }
  .song-card { padding: 16px; }
  .song-title { font-size: 1.2rem; }
  .rate-btn { padding: 7px 2px; font-size: 0.65rem; }
  .play-row { padding: 8px 10px; }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
  :root {
    --ivory: #1a1714;
    --cream: #242019;
    --champagne: #3a332a;
    --charcoal: #f0ebe4;
    --warm-gray: #a09585;
    --card: #211e19;
    --muted: #6a5f53;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.2);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.3);
  }

  header { background: #0f0d0a; }
  .add-input, .yt-url-input { background: var(--cream); }
  .sort-dropdown { background: var(--cream); color: var(--charcoal); }
}
