:root {
  --glass-bg: rgba(255, 255, 255, 0.08);
  --glass-border: rgba(255, 255, 255, 0.16);
  --text: #f5f6fb;
  --text-dim: rgba(245, 246, 251, 0.62);
  --accent: #ffffff;
  --radius: 20px;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
  --gradient-default: linear-gradient(135deg, #232946, #3a3f66, #5b4b8a, #232946);
  --gradient-active: var(--gradient-default);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--text);
  overflow: hidden;
}

/* --- Animated gradient background (two crossfading layers) --- */
.bg-layer {
  position: fixed;
  inset: 0;
  z-index: -2;
  background-size: 400% 400%;
  animation: gradient-flow 24s ease infinite;
  opacity: 0;
  transition: opacity 1.1s ease;
  will-change: background-position, opacity;
}
.bg-layer.visible { opacity: 1; }
body::after {  /* subtle vignette for legibility */
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background: radial-gradient(120% 120% at 50% 0%, transparent 40%, rgba(0,0,0,0.45) 100%);
  pointer-events: none;
}

@keyframes gradient-flow {
  0%   { background-position: 0% 50%; }
  50%  { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

/* Mood gradient themes. New moods without a theme fall back to default. */
.grad-default        { background-image: var(--gradient-default); }
.grad-happy          { background-image: linear-gradient(135deg, #ff9a3c, #ffcf4b, #ff6b9d, #ff9a3c); animation-duration: 16s; }
.grad-sad            { background-image: linear-gradient(160deg, #1b2a4a, #2c3e6b, #46618f, #1b2a4a); animation-duration: 32s; }
.grad-romantic       { background-image: linear-gradient(135deg, #7b1e3b, #c33764, #ff6a88, #7b1e3b); animation-duration: 22s; }
.grad-driving        { background-image: linear-gradient(120deg, #0f9b8e, #6a3de8, #ff7a3d, #0f9b8e); animation-duration: 12s; }
.grad-long_drive_slow{ background-image: linear-gradient(160deg, #3a1c5a, #7a3f77, #d98a5b, #f0b67f); animation-duration: 30s; }

/* --- Layout --- */
.app {
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: clamp(14px, 2.5vw, 32px);
  max-width: 1200px;
  margin: 0 auto;
  gap: 18px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}
.topbar-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* Connection status indicators */
.status { display: flex; gap: 8px; }
.status-pill {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 6px 12px; border-radius: 999px;
  border: 1px solid var(--glass-border);
  background: rgba(255,255,255,0.06);
  font-size: 0.82rem; color: var(--text-dim);
  cursor: default; white-space: nowrap;
}
.status-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: rgba(255,255,255,0.4);
  box-shadow: 0 0 8px rgba(255,255,255,0.3);
  transition: background .3s ease, box-shadow .3s ease;
  flex-shrink: 0;
}
.status-pill.ok { color: var(--text); }
.status-pill.ok   .status-dot { background: #35d07f; box-shadow: 0 0 10px rgba(53,208,127,0.75); }
.status-pill.fail .status-dot { background: #ff5a6a; box-shadow: 0 0 10px rgba(255,90,106,0.75); }
.status-pill.checking .status-dot { background: #ffcf4b; box-shadow: 0 0 10px rgba(255,207,75,0.75); animation: pulse 1.2s ease-in-out infinite; }
.brand {
  font-weight: 700;
  font-size: 1.25rem;
  letter-spacing: 0.4px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand-dot {
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 16px var(--accent);
  animation: pulse 2.4s ease-in-out infinite;
}
@keyframes pulse { 0%,100%{ transform: scale(1); opacity:.9 } 50%{ transform: scale(1.35); opacity:.5 } }

.glass {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* Moods */
.moods {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.mood-pill {
  border: 1px solid var(--glass-border);
  background: rgba(255,255,255,0.06);
  color: var(--text);
  padding: 10px 20px;
  border-radius: 999px;
  font-size: 0.95rem;
  cursor: pointer;
  transition: transform .15s ease, background .2s ease, box-shadow .2s ease;
  backdrop-filter: blur(8px);
}
.mood-pill:hover { transform: translateY(-2px); background: rgba(255,255,255,0.14); }
.mood-pill.active {
  background: rgba(255,255,255,0.92);
  color: #1a1a2e;
  font-weight: 600;
  box-shadow: 0 6px 24px rgba(0,0,0,0.35);
}

/* Stage: now-playing + queue */
.stage {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1.35fr 1fr;
  gap: 18px;
}

.now-playing {
  padding: clamp(20px, 3vw, 40px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
}
.art-wrap { position: relative; width: min(46vh, 340px); aspect-ratio: 1; }
.art {
  width: 100%; height: 100%;
  object-fit: cover;
  border-radius: 18px;
  box-shadow: 0 24px 60px rgba(0,0,0,0.5);
  background: rgba(255,255,255,0.05);
}
.art-glow {
  position: absolute; inset: 8%;
  border-radius: 50%;
  filter: blur(40px);
  opacity: 0.55;
  z-index: -1;
  background: rgba(255,255,255,0.25);
  transition: background .6s ease;
}
body.playing .art { animation: float 6s ease-in-out infinite; }
@keyframes float { 0%,100%{ transform: translateY(0) } 50%{ transform: translateY(-8px) } }

.track-meta { text-align: center; max-width: 100%; }
.track-title {
  font-size: 1.5rem; font-weight: 700; line-height: 1.2;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 42ch;
}
.track-artist { color: var(--text-dim); margin-top: 4px; font-size: 1.05rem; }

.seek { display: flex; align-items: center; gap: 12px; width: 100%; max-width: 460px; }
.time { font-variant-numeric: tabular-nums; font-size: 0.82rem; color: var(--text-dim); min-width: 38px; text-align: center; }

input[type=range] {
  -webkit-appearance: none; appearance: none;
  height: 6px; border-radius: 3px; flex: 1;
  background: rgba(255,255,255,0.22);
  cursor: pointer;
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 15px; height: 15px; border-radius: 50%;
  background: #fff; box-shadow: 0 2px 8px rgba(0,0,0,0.4);
}
input[type=range]::-moz-range-thumb {
  width: 15px; height: 15px; border: none; border-radius: 50%; background: #fff;
}

.controls { display: flex; align-items: center; gap: 16px; }
.ctrl {
  background: none; border: none; color: var(--text); cursor: pointer;
  width: 46px; height: 46px; display: grid; place-items: center;
  border-radius: 50%; transition: background .2s ease, transform .15s ease;
}
.ctrl:hover { background: rgba(255,255,255,0.14); }
.ctrl:active { transform: scale(0.92); }
.ctrl svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.ctrl.small svg { width: 18px; height: 18px; }
.ctrl.play {
  width: 66px; height: 66px;
  background: #fff; color: #1a1a2e;
  box-shadow: 0 10px 30px rgba(0,0,0,0.4);
}
.ctrl.play:hover { background: #fff; transform: scale(1.05); }
.ctrl.play svg { width: 30px; height: 30px; }
.ctrl.active { color: #ffe38a; }

.volume { display: flex; align-items: center; gap: 8px; margin-left: 6px; width: 120px; }
.vol-icon { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }

/* Queue */
.queue { padding: 20px; display: flex; flex-direction: column; min-height: 0; }
.queue-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 8px; }
.queue-head h2 { margin: 0; font-size: 1.1rem; }
.queue-count { color: var(--text-dim); font-size: 0.85rem; }
.queue-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.queue-item {
  display: flex; align-items: center; gap: 12px;
  padding: 8px; border-radius: 12px; cursor: pointer;
  transition: background .15s ease;
}
.queue-item:hover { background: rgba(255,255,255,0.10); }
.queue-item.playing { background: rgba(255,255,255,0.16); }
.queue-thumb { width: 44px; height: 44px; border-radius: 8px; object-fit: cover; background: rgba(255,255,255,0.08); flex-shrink: 0; }
.queue-info { min-width: 0; }
.queue-song { font-size: 0.92rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.queue-artist { font-size: 0.8rem; color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.queue-empty { color: var(--text-dim); font-size: 0.9rem; padding: 20px 8px; }

/* Buttons */
.ghost-btn {
  border: 1px solid var(--glass-border);
  background: rgba(255,255,255,0.06);
  color: var(--text);
  padding: 9px 16px; border-radius: 999px; cursor: pointer;
  font-size: 0.9rem; transition: background .2s ease;
}
.ghost-btn:hover { background: rgba(255,255,255,0.16); }
.primary-btn {
  border: none; background: #fff; color: #1a1a2e;
  padding: 11px 22px; border-radius: 999px; cursor: pointer;
  font-size: 0.95rem; font-weight: 600;
}
.primary-btn:hover { filter: brightness(0.95); }
.primary-btn:disabled { opacity: 0.55; cursor: default; }

/* Overlay */
.overlay {
  position: fixed; inset: 0; z-index: 10;
  display: grid; place-items: center;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(6px);
}
.overlay-card { padding: 32px; max-width: 460px; width: calc(100% - 40px); text-align: center; }
.overlay-card h2 { margin-top: 0; }
.overlay-card p { color: var(--text-dim); line-height: 1.5; }
.progress-wrap { margin: 20px 0; }
.progress-track { height: 10px; border-radius: 6px; background: rgba(255,255,255,0.16); overflow: hidden; }
.progress-fill { height: 100%; width: 0%; background: #fff; border-radius: 6px; transition: width .4s ease; }
.progress-label { margin-top: 8px; font-size: 0.85rem; color: var(--text-dim); }
.overlay-actions { display: flex; gap: 12px; justify-content: center; }

.hidden { display: none !important; }

/* Scores table modal */
.scores-card {
  max-width: min(1000px, 96vw);
  width: min(1000px, 96vw);
  max-height: 88vh;
  text-align: left;
  display: flex;
  flex-direction: column;
}
.scores-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.scores-head h2 { margin: 0; }
.scores-filter {
  margin: 14px 0; width: 100%;
  padding: 10px 14px; border-radius: 10px;
  border: 1px solid var(--glass-border);
  background: rgba(255,255,255,0.08); color: var(--text);
  font-size: 0.9rem;
}
.scores-table-wrap { overflow: auto; flex: 1; border-radius: 12px; border: 1px solid var(--glass-border); }
.scores-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.scores-table th, .scores-table td {
  padding: 8px 10px; text-align: left;
  border-bottom: 1px solid rgba(255,255,255,0.08); white-space: nowrap;
}
.scores-table th {
  position: sticky; top: 0; z-index: 1;
  background: #262a44;
  cursor: pointer; user-select: none;
}
.scores-table th:hover { background: #2f3452; }
.scores-table th.mood-col, .scores-table td.mood-col { text-align: center; font-variant-numeric: tabular-nums; }
.scores-table td.song { max-width: 240px; overflow: hidden; text-overflow: ellipsis; }
.scores-table td.artist { max-width: 180px; overflow: hidden; text-overflow: ellipsis; }
.scores-table td.mood-col.best { font-weight: 700; color: #fff; }
.scores-table tbody tr:hover { background: rgba(255,255,255,0.06); }
.scores-meta { margin-top: 10px; font-size: 0.8rem; color: var(--text-dim); }

/* Responsive */
@media (max-width: 860px) {
  html, body { overflow: auto; }
  .stage { grid-template-columns: 1fr; }
  .queue { max-height: 42vh; }
  .track-title { font-size: 1.25rem; }
}
