:root {
  /* Core Palette */
  --bg-color: #000000;
  --text-primary: #ffffff;
  --text-secondary: rgba(255, 255, 255, 0.7);
  --text-tertiary: rgba(255, 255, 255, 0.45);

  /* Accent Colors */
  --accent: #0a84ff; /* Apple System Blue */
  --accent-glow: rgba(10, 132, 255, 0.4);
  --danger: #ff453a;

  /* Glass Surfaces */
  --glass-surface: rgba(30, 30, 35, 0.65);
  --glass-surface-hover: rgba(45, 45, 50, 0.75);
  --glass-border: rgba(255, 255, 255, 0.12); /* Increased visibility */
  --glass-border-light: rgba(255, 255, 255, 0.25);
  --glass-highlight: rgba(255, 255, 255, 0.05);

  /* Dimensions */
  --nav-width: 280px;
  --header-height: 70px;
  --controls-height: 60px;
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 8px;

  /* Animation */
  --ease-spring: cubic-bezier(0.175, 0.885, 0.32, 1.275);
  --ease-smooth: cubic-bezier(0.4, 0, 0.2, 1);
}

* {
  box-sizing: border-box;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI",
    Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg-color);
  color: var(--text-primary);
  overflow-x: hidden;
  height: 100vh;
}

/* --- Ambient Background --- */
.ambient-background {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  z-index: -1;
  overflow: hidden;
  background: radial-gradient(circle at top left, #1a1a1a, #000000);
}

.blob {
  position: absolute;
  filter: blur(80px);
  opacity: 0.6;
  animation: float 20s infinite ease-in-out;
}

.blob-1 {
  top: -10%;
  left: -10%;
  width: 50vw;
  height: 50vw;
  background: radial-gradient(circle, #2d1b4e 0%, transparent 70%);
  animation-delay: 0s;
}

.blob-2 {
  bottom: -10%;
  right: -10%;
  width: 60vw;
  height: 60vw;
  background: radial-gradient(circle, #003366 0%, transparent 70%);
  animation-delay: -5s;
}

.blob-3 {
  top: 40%;
  left: 40%;
  width: 40vw;
  height: 40vw;
  background: radial-gradient(circle, #3a0ca3 0%, transparent 70%);
  opacity: 0.4;
  animation-delay: -10s;
}

@keyframes float {
  0%,
  100% {
    transform: translate(0, 0);
  }
  50% {
    transform: translate(20px, -20px);
  }
}

/* --- Layout --- */
.app-shell {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* --- Navigation Drawer (Glass Sidebar) --- */
.nav-drawer {
  width: var(--nav-width);
  background: rgba(20, 20, 23, 0.6);
  backdrop-filter: blur(25px);
  -webkit-backdrop-filter: blur(25px);
  border-right: 1px solid var(--glass-border);
  display: flex;
  flex-direction: column;
  padding: 24px 16px;
  z-index: 100;
  transition: transform 0.4s var(--ease-smooth);
  flex-shrink: 0;
}

.nav-drawer-header {
  padding: 0 16px 32px 16px;
}

.nav-brand {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.5px;
  margin: 0;
  background: linear-gradient(135deg, #fff 0%, #a5a5a5 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.nav-drawer-content {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 32px;
}

.nav-heading {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-tertiary);
  margin: 0 0 12px 16px;
  font-weight: 600;
}

.nav-menu {
  list-style: none;
  padding: 0;
  margin: 0;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  color: var(--text-secondary);
  text-decoration: none;
  border-radius: var(--radius-md);
  transition: all 0.2s ease;
  font-weight: 500;
  font-size: 14px;
}

.nav-link:hover {
  background: var(--glass-highlight);
  color: var(--text-primary);
}

.nav-link.is-active {
  background: rgba(10, 132, 255, 0.15);
  color: var(--accent);
}

.nav-footer {
  margin-top: auto;
  padding: 24px 16px 0;
  border-top: 1px solid var(--glass-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.user-badge-text {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 500;
}

.sign-out-btn {
  background: transparent;
  border: none;
  color: var(--text-tertiary);
  cursor: pointer;
  padding: 8px;
  border-radius: var(--radius-sm);
  transition: color 0.2s;
}

.sign-out-btn:hover {
  color: var(--danger);
  background: rgba(255, 69, 58, 0.1);
}

/* --- Main Content Area --- */
.app-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

/* FIX: Updated selector to catch 'view-metrics-songs' etc. 
   This ensures the flex container works and scrolling happens. 
*/
.view-home,
.view-date,
[class*="view-metrics"] {
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* --- Glass Header --- */
.app-header {
  flex-shrink: 0;
  z-index: 50;
  padding: 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: rgba(20, 20, 23, 0.3);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--glass-border);
}

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  height: 40px;
}

.hamburger-button {
  display: none;
  background: transparent;
  border: none;
  color: var(--text-primary);
  padding: 0;
  cursor: pointer;
}

.view-heading-container {
  display: flex;
  align-items: center;
  gap: 12px;
}

.view-title {
  font-size: 24px;
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.5px;
}

.icon-btn {
  background: rgba(255, 255, 255, 0.1);
  border: none;
  color: var(--text-primary);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s;
}
.icon-btn:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* --- Controls Bar --- */
/* FIX: Hidden by default, only shown on view-date */
.controls-bar {
  display: none;
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: none;
}
.view-date .controls-bar {
  display: flex;
}

.controls-bar::-webkit-scrollbar {
  display: none;
}

.select-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

/* FIX: Stronger background and borders for visibility */
select {
  appearance: none;
  background: rgba(255, 255, 255, 0.1); /* More visible background */
  border: 1px solid rgba(255, 255, 255, 0.2); /* More visible border */
  color: var(--text-primary);
  padding: 8px 32px 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  outline: none;
  transition: all 0.2s;
  white-space: nowrap;
}

select:hover {
  background: rgba(255, 255, 255, 0.15);
  border-color: rgba(255, 255, 255, 0.4);
}

select:focus {
  border-color: var(--accent);
  background: rgba(255, 255, 255, 0.2);
  box-shadow: 0 0 0 2px rgba(10, 132, 255, 0.2);
}

select option {
  background: #1e1e1e;
  color: white;
}

/* FIX: Ensure arrow is visible */
.select-wrapper::after {
  content: "▼";
  font-size: 8px;
  color: rgba(255, 255, 255, 0.8); /* Brighter arrow */
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
}

/* --- Main Feed --- */
.app-main {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  /* FIX: Added padding bottom so content isn't cut off */
  padding-bottom: 80px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
}

.app-main::-webkit-scrollbar {
  width: 6px;
}
.app-main::-webkit-scrollbar-thumb {
  background-color: rgba(255, 255, 255, 0.2);
  border-radius: 3px;
}

.feed {
  max-width: 900px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* --- Cards (Glass Items) --- */
.card {
  background: var(--glass-surface);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  padding: 16px;
  display: flex;
  gap: 16px;
  align-items: center;
  transition: transform 0.2s ease, background 0.2s, box-shadow 0.2s;
  position: relative;
  overflow: hidden;
}

.card:hover {
  transform: scale(1.01);
  background: var(--glass-surface-hover);
  border-color: var(--glass-border-light);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.card.fulfilled {
  opacity: 0.6;
  filter: grayscale(100%);
}
.card.fulfilled:hover {
  opacity: 1;
  filter: grayscale(0%);
}

.card-thumb {
  width: 70px;
  height: 70px;
  border-radius: 12px;
  object-fit: cover;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.card-content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.card-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-artist {
  font-size: 14px;
  color: var(--text-secondary);
}

.card-metadata {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-top: 2px;
}

.card-time {
  position: absolute;
  top: 16px;
  right: 16px;
  font-size: 12px;
  color: var(--text-tertiary);
  font-variant-numeric: tabular-nums;
}

.card-actions {
  display: flex;
  gap: 16px;
  margin-top: 8px;
  font-size: 13px;
}

.apple-music-link {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
}
.apple-music-link:hover {
  text-decoration: underline;
}

.delete-link {
  background: none;
  border: none;
  color: var(--danger);
  font-size: 13px;
  padding: 0;
  cursor: pointer;
}
.delete-link:hover {
  text-decoration: underline;
}

/* Custom Checkbox */
.checkbox-container {
  width: 24px;
  height: 24px;
  position: relative;
  cursor: pointer;
  flex-shrink: 0;
}
.checkbox-container input {
  opacity: 0;
  position: absolute;
}
.checkmark {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid var(--text-tertiary);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}
.checkbox-container input:checked ~ .checkmark {
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 0 12px var(--accent-glow);
}
.checkmark::after {
  content: "✔";
  color: white;
  font-size: 14px;
  display: none;
}
.checkbox-container input:checked ~ .checkmark::after {
  display: block;
}

/* --- Date Links (Folder View) --- */
.date-link {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--glass-surface);
  backdrop-filter: blur(15px);
  padding: 20px 24px;
  border-radius: var(--radius-lg);
  text-decoration: none;
  color: var(--text-primary);
  border: 1px solid var(--glass-border);
  transition: all 0.2s;
  font-size: 18px;
  font-weight: 600;
}
.date-link small {
  font-size: 14px;
  color: var(--text-secondary);
  font-weight: 400;
}
.date-link:hover {
  background: var(--glass-surface-hover);
  transform: translateY(-2px);
}

/* --- Metrics View --- */
.metrics-item {
  display: flex;
  align-items: center;
  background: var(--glass-surface);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  gap: 16px;
  border: 1px solid var(--glass-border);
}

.metrics-rank {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-tertiary);
  width: 30px;
  text-align: center;
}

.metrics-thumb {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  background-size: cover;
  background-color: #333;
}

.metrics-info {
  flex: 1;
}
.metrics-label {
  display: block;
  font-weight: 600;
  font-size: 15px;
}
.metrics-sublabel {
  display: block;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.metrics-bar {
  height: 4px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 2px;
  overflow: hidden;
}
.metrics-bar-fill {
  display: block;
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
}

/* --- Bottom Controls --- */
.bottom-controls {
  padding: 16px 24px;
  background: rgba(20, 20, 23, 0.4);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--glass-border);
  display: flex;
  justify-content: center;
  gap: 16px;
}

.glass-btn {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--glass-border-light);
  color: var(--text-primary);
  padding: 10px 20px;
  border-radius: var(--radius-md);
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.2s;
}
.glass-btn:hover {
  background: rgba(255, 255, 255, 0.15);
}

.glass-btn.danger {
  color: #ff6b6b;
  border-color: rgba(255, 107, 107, 0.3);
}
.glass-btn.danger:hover {
  background: rgba(255, 107, 107, 0.1);
}

/* --- Overlays / Modals (Auth & Dialog) --- */
.overlay-container {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(5px);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.glass-card {
  background: rgba(30, 30, 35, 0.85);
  backdrop-filter: blur(30px);
  border: 1px solid var(--glass-border-light);
  padding: 40px;
  border-radius: 24px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
}

.auth-title {
  text-align: center;
  margin-bottom: 32px;
  font-weight: 700;
}

.input-group {
  position: relative;
  margin-bottom: 24px;
}

.input-group input {
  width: 100%;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--glass-border);
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  color: white;
  font-size: 16px;
  outline: none;
}
.input-group input:focus {
  border-color: var(--accent);
  background: rgba(0, 0, 0, 0.4);
}

.input-group label {
  position: absolute;
  left: 16px;
  top: 16px;
  color: var(--text-tertiary);
  pointer-events: none;
  transition: all 0.2s;
  font-size: 16px;
}

.input-group input:focus ~ label,
.input-group input:not(:placeholder-shown) ~ label {
  top: -22px;
  left: 0;
  font-size: 12px;
  color: var(--text-secondary);
}

.primary-btn {
  background: var(--accent);
  color: white;
  border: none;
  padding: 14px;
  border-radius: var(--radius-md);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.2s;
}
.primary-btn:hover {
  box-shadow: 0 0 15px var(--accent-glow);
}
.primary-btn:active {
  transform: scale(0.98);
}
.full-width {
  width: 100%;
}

.text-btn {
  background: none;
  border: none;
  color: var(--accent);
  margin-top: 16px;
  width: 100%;
  cursor: pointer;
  font-size: 14px;
}

.dialog-actions {
  display: flex;
  gap: 12px;
  margin-top: 24px;
}
.dialog-actions button {
  flex: 1;
}

/* --- Mobile Responsiveness --- */
@media (max-width: 1023px) {
  .nav-drawer {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    transform: translateX(-100%);
  }

  .app-shell.nav-mobile-open .nav-drawer {
    transform: translateX(0);
  }

  .nav-overlay {
    display: block; /* Managed by JS hidden attribute */
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 90;
    backdrop-filter: blur(4px);
  }

  .hamburger-button {
    display: flex;
  }

  /* On mobile, use less padding */
  .app-header {
    padding: 12px 16px;
  }
  .app-main {
    padding: 16px;
    padding-bottom: 90px;
  } /* Extra padding for bottom controls on mobile */
  .card {
    padding: 12px;
    gap: 12px;
  }
  .card-thumb {
    width: 56px;
    height: 56px;
  }
  .card-time {
    top: 12px;
    right: 12px;
    font-size: 11px;
  }

  /* Hide specific view controls on home to save space if needed */
  /* .view-home .controls-bar { display: none; } -- Logic now handled by .view-date check */
  .view-home #backButton {
    display: none;
  }
}

@media (min-width: 1024px) {
  .nav-overlay {
    display: none !important;
  }
}

/* Helpers */
[hidden] {
  display: none !important;
}
