/* ============================================================
   ROOT VARIABLES & RESET
   ============================================================ */
:root {
  --bg-primary:    #121212;
  --bg-secondary:  #1E1E1E;
  --bg-card:       #282828;
  --bg-navbar:     #181818;
  --bg-input:      #2A2A2A;
  --bg-modal:      #1E1E1E;

  --text-primary:  #FFFFFF;
  --text-secondary:#B3B3B3;
  --text-muted:    #6B6B6B;

  --accent:        #A855F7;
  --accent-hover:  #9333EA;
  --accent-glow:   rgba(168, 85, 247, 0.35);

  --danger:        #E53935;
  --danger-hover:  #C62828;
  --danger-glow:   rgba(229, 57, 53, 0.35);

  --error-color:   #FF4444;

  --yt-red:        #FF0000;
  --sp-green:      #1DB954;

  --border:        rgba(255, 255, 255, 0.08);
  --border-input:  rgba(255, 255, 255, 0.12);
  --border-focus:  rgba(168, 85, 247, 0.7);

  --radius-sm:     6px;
  --radius-md:     12px;
  --radius-lg:     20px;

  --shadow-card:   0 4px 24px rgba(0, 0, 0, 0.5);
  --shadow-modal:  0 8px 48px rgba(0, 0, 0, 0.7);
  --transition:    0.2s ease;
}

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

html, body {
  height: 100%;
}

body {
  background-color: var(--bg-primary);
  color: var(--text-primary);
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

/* ============================================================
   PAGES
   ============================================================ */
.page {
  min-height: 100vh;
}

/* ============================================================
   APP TITLE
   ============================================================ */
.app-title {
  font-size: clamp(1.8rem, 5vw, 2.8rem);
  font-weight: 800;
  text-align: center;
  margin-bottom: 2rem;
  letter-spacing: -0.5px;
  background: linear-gradient(135deg, #A855F7 0%, #EC4899 50%, #8B5CF6 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  filter: drop-shadow(0 0 20px rgba(168, 85, 247, 0.4));
  line-height: 1.2;
}

/* ============================================================
   AUTH PAGES (LOGIN & CREATE ACCOUNT)
   ============================================================ */
.auth-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 2rem 1rem;
}

#btn-google-login {
  display: block;
  max-width: 400px;
  width: 100%;
  margin: 0 auto;
}

.auth-form {
  width: 100%;
  max-width: 400px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2.5rem 2rem;
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

/* ============================================================
   INPUTS & SELECTS
   ============================================================ */
.input-field,
.select-field {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border-input);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.95rem;
  padding: 0.75rem 1rem;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
  appearance: none;
  -webkit-appearance: none;
}

.select-field {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23B3B3B3' stroke-width='1.5' stroke-linecap='round' fill='none'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.9rem center;
  padding-right: 2.5rem;
  cursor: pointer;
}

.select-field option {
  background: var(--bg-card);
  color: var(--text-primary);
}

.input-field::placeholder {
  color: var(--text-muted);
}

.input-field:focus,
.select-field:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.875rem;
  font-weight: 600;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  padding: 0.6rem 1.2rem;
  transition: background-color var(--transition), box-shadow var(--transition), transform var(--transition);
  white-space: nowrap;
  text-decoration: none;
  letter-spacing: 0.2px;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none !important;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  box-shadow: 0 0 16px var(--accent-glow);
  transform: translateY(-1px);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-danger:hover:not(:disabled) {
  background: var(--danger-hover);
  box-shadow: 0 0 16px var(--danger-glow);
  transform: translateY(-1px);
}

.btn-full {
  width: 100%;
  padding: 0.8rem 1.2rem;
  font-size: 1rem;
}

.btn-sm {
  font-size: 0.8rem;
  padding: 0.45rem 0.9rem;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.07);
  color: var(--text-primary);
  border: 1px solid var(--border);
}

.btn-sm:hover:not(:disabled) {
  background: rgba(168, 85, 247, 0.2);
  border-color: var(--accent);
  color: var(--accent);
  transform: translateY(-1px);
}

.btn-sm.btn-danger {
  background: rgba(229, 57, 53, 0.12);
  color: var(--danger);
  border: 1px solid rgba(229, 57, 53, 0.3);
}

.btn-sm.btn-danger:hover:not(:disabled) {
  background: rgba(229, 57, 53, 0.25);
  border-color: var(--danger);
  transform: translateY(-1px);
  box-shadow: none;
}

/* ============================================================
   ERROR MESSAGES
   ============================================================ */
.error-msg {
  color: var(--error-color);
  font-size: 0.875rem;
  font-weight: 500;
  padding: 0.5rem 0.75rem;
  background: rgba(255, 68, 68, 0.1);
  border: 1px solid rgba(255, 68, 68, 0.25);
  border-radius: var(--radius-sm);
  line-height: 1.4;
}

.modal-error {
  color: var(--error-color);
  font-size: 0.875rem;
  font-weight: 500;
  padding: 0.5rem 0.75rem;
  background: rgba(255, 68, 68, 0.1);
  border: 1px solid rgba(255, 68, 68, 0.25);
  border-radius: var(--radius-sm);
  margin-bottom: 0.25rem;
}

/* ============================================================
   AUTH LINKS
   ============================================================ */
.auth-switch {
  font-size: 0.875rem;
  color: var(--text-secondary);
  text-align: center;
}

.text-link {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
  transition: color var(--transition), text-shadow var(--transition);
}

.text-link:hover {
  color: var(--accent-hover);
  text-shadow: 0 0 8px var(--accent-glow);
}

.back-link {
  font-size: 0.875rem;
}

/* ============================================================
   NAVBAR
   ============================================================ */
.navbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  height: 64px;
  background: var(--bg-navbar);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  gap: 1rem;
  box-shadow: 0 2px 16px rgba(0, 0, 0, 0.4);
}

.navbar-brand {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: 0.3px;
  white-space: nowrap;
}

.navbar-actions {
  display: flex;
  align-items: center;
}

/* ============================================================
   ACTION MENU DROPDOWN
   ============================================================ */
.action-menu {
  position: relative;
}

.action-menu-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  user-select: none;
}

.action-menu-caret {
  font-size: 0.6rem;
  transition: transform var(--transition);
}

.action-menu-toggle[aria-expanded="true"] .action-menu-caret {
  transform: rotate(180deg);
}

.action-menu-list {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 200px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-modal);
  padding: 0.4rem 0;
  list-style: none;
  z-index: 150;
  animation: slideUpModal 0.15s ease;
}

.action-menu-list.open {
  display: block;
}

.menu-item {
  display: block;
  width: 100%;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 0.9rem;
  font-weight: 500;
  text-align: left;
  padding: 0.65rem 1.1rem;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  white-space: nowrap;
}

.menu-item:hover,
.menu-item:focus {
  background: rgba(168, 85, 247, 0.12);
  color: var(--accent);
  outline: none;
}

.menu-item-danger {
  color: var(--danger);
}

.menu-item-danger:hover,
.menu-item-danger:focus {
  background: rgba(229, 57, 53, 0.12);
  color: var(--danger);
}

.menu-separator {
  height: 1px;
  background: var(--border);
  margin: 0.4rem 0;
}

/* ============================================================
   DASHBOARD MAIN
   ============================================================ */
.dashboard-main {
  margin-top: 64px;
  padding: 2rem 1.5rem;
  min-height: calc(100vh - 64px);
}

/* ============================================================
   PLAYLIST GRID
   ============================================================ */
.playlist-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1.25rem;
}

.playlist-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1.75rem 1.25rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.85rem;
  text-align: center;
  cursor: pointer;
  transition: transform var(--transition), box-shadow var(--transition), border-color var(--transition);
}

.playlist-card:hover {
  transform: translateY(-4px) scale(1.025);
  box-shadow: 0 8px 32px rgba(168, 85, 247, 0.2);
  border-color: rgba(168, 85, 247, 0.4);
}

.playlist-card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-color: rgba(168, 85, 247, 0.4);
}

.platform-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 56px;
}

.platform-icon.emoji-icon {
  font-size: 2.75rem;
  line-height: 1;
  filter: drop-shadow(0 0 8px rgba(168, 85, 247, 0.5));
}

.platform-icon svg {
  display: block;
}

.playlist-name {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.3;
  word-break: break-word;
}

.playlist-date {
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* ============================================================
   EMPTY / LOADING STATES
   ============================================================ */
.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--text-secondary);
  font-size: 1.05rem;
  padding: 4rem 1rem;
}

.loading-state {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--text-muted);
  padding: 4rem 1rem;
  font-size: 0.95rem;
}

.error-center {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--error-color);
  padding: 4rem 1rem;
  font-size: 0.95rem;
}

/* ============================================================
   MODALS
   ============================================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0, 0, 0, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  animation: fadeInOverlay 0.15s ease;
}

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

.modal-card {
  position: relative;
  background: var(--bg-modal);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2rem 1.75rem;
  width: 100%;
  max-width: 440px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-modal);
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  animation: slideUpModal 0.2s ease;
}

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

.modal-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius-sm);
  transition: color var(--transition), background var(--transition);
}

.modal-close:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.08);
}

.modal-title {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 0.25rem;
  padding-right: 2rem;
}

.field-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin-top: 0.25rem;
}

.field-note {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: -0.4rem;
  line-height: 1.4;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  cursor: pointer;
  padding: 0.25rem 0;
}

.checkbox-input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}

.checkbox-text {
  font-size: 0.9rem;
  color: var(--text-secondary);
}

/* ============================================================
   GENERATE WITH AI MODAL
   ============================================================ */
.modal-section {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.ai-status {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.6rem;
  font-size: 0.875rem;
  color: var(--text-secondary);
  padding: 0.6rem 0.75rem;
  background: rgba(168, 85, 247, 0.1);
  border: 1px solid rgba(168, 85, 247, 0.3);
  border-radius: var(--radius-sm);
}

.ai-elapsed {
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.ai-spinner {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  border: 2px solid rgba(168, 85, 247, 0.3);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: aiSpin 0.8s linear infinite;
}

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

@media (prefers-reduced-motion: reduce) {
  .ai-spinner { animation: none; }
}

.ai-result-summary {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-primary);
  outline: none;
  word-break: break-word;
}

.ai-skipped-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.ai-skipped-list li {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.75rem;
  font-size: 0.875rem;
  word-break: break-word;
}

.ai-skipped-song {
  display: block;
  font-weight: 600;
  color: var(--text-primary);
}

.ai-skipped-reason {
  display: block;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

/* ============================================================
   PLAYLIST SONGS MODAL
   ============================================================ */
/* The card itself doesn't scroll; only the song list area does,
   so the title and close button stay put on long playlists. */
.modal-card.tracks-card {
  max-width: 520px;
  max-height: 90vh;
  max-height: 90dvh;
  overflow: hidden;
}

.tracks-card .modal-title {
  outline: none;
  word-break: break-word;
}

.tracks-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  padding-right: 0.25rem;
}

.tracks-body:empty {
  display: none;
}

.tracks-body:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

.tracks-section {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.tracks-heading {
  position: sticky;
  top: 0;
  z-index: 1;
  margin-top: 0;
  padding: 0.25rem 0;
  background: var(--bg-modal);
}

/* Plain block list (not flex) so the numbers keep rendering everywhere. */
.tracks-list {
  padding-left: 2.25rem;
  font-size: 0.9rem;
  color: var(--text-primary);
  line-height: 1.4;
}

.tracks-list li {
  overflow-wrap: anywhere;
}

.tracks-list li + li {
  margin-top: 0.4rem;
}

.tracks-list li::marker {
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.tracks-note {
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.4;
}

@media (max-width: 400px) {
  .modal-card.tracks-card {
    padding: 1.5rem 1.1rem;
  }

  .tracks-list {
    padding-left: 1.75rem;
  }
}

/* ============================================================
   SCROLLBAR STYLING
   ============================================================ */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(168, 85, 247, 0.5);
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 640px) {
  .auth-form {
    padding: 2rem 1.25rem;
  }

  .playlist-grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 1rem;
  }

  .action-menu-list {
    right: 0;
    min-width: 180px;
  }
}

@media (max-width: 400px) {
  .playlist-grid {
    grid-template-columns: 1fr 1fr;
  }
}
