:root {
  --bg: #0f0a1a;
  --bg-card: #1c1430;
  --accent: #d6a4e0;
  --accent-strong: #b565c9;
  --text: #f2ecf7;
  --text-muted: #a698b8;
  --border: #372a4d;
  --win-a: #6ec6a3;
  --win-b: #e0a45e;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: linear-gradient(180deg, var(--bg) 0%, #1a1030 100%);
  color: var(--text);
  min-height: 100vh;
}

.site-header {
  padding: 1.25rem 2rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.theme-form select {
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 0.4rem;
  padding: 0.35rem 0.6rem;
  font-size: 0.8rem;
  cursor: pointer;
}

.logout-form {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.85rem;
}

.btn-link {
  background: none;
  border: none;
  padding: 0;
  color: var(--accent);
  text-decoration: underline;
  cursor: pointer;
  font-size: 0.85rem;
}

.site-title {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  color: var(--accent);
  font-weight: 700;
  font-size: 1.25rem;
  text-decoration: none;
  letter-spacing: 0.02em;
  line-height: 1.2;
}

.site-tagline {
  color: var(--text-muted);
  font-weight: 500;
  font-size: 0.7rem;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

@media (max-width: 420px) {
  .site-title { font-size: 1.05rem; }
  .site-tagline { font-size: 0.62rem; }
}

.site-main {
  max-width: 900px;
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
}

.site-footer {
  text-align: center;
  padding: 1.5rem;
  font-size: 0.8rem;
}

.site-footer a {
  color: var(--text-muted);
  text-decoration: none;
}

.site-footer a:hover { text-decoration: underline; }

.home-card, .compare-page, .results-page {
  animation: fade-in 0.3s ease;
}

@keyframes fade-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

h1 { font-size: 1.75rem; margin-bottom: 0.5rem; }
h2 { font-size: 1.2rem; margin-top: 2.5rem; margin-bottom: 0.75rem; color: var(--accent); }

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

.btn {
  display: inline-block;
  padding: 0.7rem 1.4rem;
  border-radius: 999px;
  font-weight: 600;
  text-decoration: none;
  border: none;
  cursor: pointer;
  font-size: 0.95rem;
}

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

.btn-primary:hover { background: #c47ad6; }

.btn-secondary {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
}

.btn-danger {
  background: transparent;
  color: #e0705e;
  border: 1px solid #e0705e;
}

.btn-danger:hover { background: rgba(224, 112, 94, 0.1); }

.home-actions, .results-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 1.5rem;
  flex-wrap: wrap;
}

.landing-lede {
  font-size: 1.05rem;
  margin-top: 0.5rem;
}

.landing-features {
  margin: 1.5rem 0;
  padding-left: 1.25rem;
}

.landing-features li {
  color: var(--text-muted);
  margin-bottom: 0.5rem;
  line-height: 1.5;
}

.landing-features a {
  color: var(--accent);
}

/* Compare page */
.compare-heading {
  text-align: center;
  margin-bottom: 1.5rem;
}

.progress-wrap { margin-bottom: 2rem; }

.progress-bar {
  height: 8px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent-strong), var(--accent));
  transition: width 0.3s ease;
}

.progress-text {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: center;
  margin-top: 0.5rem;
}

.matchup {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 1rem;
  align-items: stretch;
}

@media (max-width: 640px) {
  .matchup { grid-template-columns: 1fr; }
  .vs-divider { margin: 0.25rem auto; }
}

.song-card-form { display: flex; }

.song-card {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 220px;
  padding: 2rem 1.25rem;
  border-radius: 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  cursor: pointer;
  text-align: center;
  transition: transform 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.song-card:hover {
  transform: translateY(-3px);
  border-color: var(--accent);
  background: #241a3d;
}

.song-card:active { transform: translateY(0); }

.song-title { font-size: 1.15rem; font-weight: 700; }
.song-album { font-size: 0.85rem; color: var(--text-muted); }
.song-era { font-size: 0.75rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }

.song-badge {
  margin-top: 0.25rem;
  font-size: 0.7rem;
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  background: rgba(214, 164, 224, 0.15);
  color: var(--accent);
}

.song-art {
  width: 72px;
  height: 72px;
  border-radius: 0.6rem;
  object-fit: cover;
  margin-bottom: 0.25rem;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
}

.song-card-wrap {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  flex: 1;
}

.song-card-wrap .song-card-form { flex: 1; }

.song-preview {
  width: 100%;
  height: 32px;
}

.vs-divider {
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.matchup-footer {
  text-align: center;
  margin-top: 1.5rem;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.6rem;
}

.matchup-footer a {
  color: var(--text-muted);
  font-size: 0.85rem;
  text-decoration: underline;
}

.undo-form {
  display: inline;
}

.matchup-footer .btn-link {
  font-size: 0.85rem;
}

/* Results page */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
  margin: 1.5rem 0;
}

.stat-tile {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.stat-value { font-size: 1.5rem; font-weight: 700; color: var(--accent); }
.stat-label { font-size: 0.75rem; color: var(--text-muted); }

.tier-row {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--border);
}

.tier-label {
  flex-shrink: 0;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 0.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1.1rem;
}

.tier-s .tier-label { background: #d4af37; color: #1a1030; }
.tier-a .tier-label { background: var(--win-a); color: #1a1030; }
.tier-b .tier-label { background: var(--accent); color: #1a1030; }
.tier-c .tier-label { background: var(--win-b); color: #1a1030; }
.tier-f .tier-label { background: #c0392b; color: #fff; }

.tier-songs { display: flex; flex-wrap: wrap; gap: 0.4rem; }

.tier-song-chip {
  font-size: 0.75rem;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  background: var(--bg-card);
  border: 1px solid var(--border);
}

.ranked-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.ranked-table th, .ranked-table td {
  text-align: left;
  padding: 0.4rem 0.6rem;
  border-bottom: 1px solid var(--border);
}

.ranked-table th { color: var(--text-muted); font-weight: 600; font-size: 0.75rem; text-transform: uppercase; }

.album-list { padding-left: 1.25rem; }
.album-list li { margin-bottom: 0.35rem; }

.comparison-list { list-style: none; padding: 0; }
.comparison-list li {
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

/* Auth pages */
.auth-card {
  max-width: 360px;
  margin: 2rem auto 0;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-top: 1.25rem;
}

.auth-form label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.auth-form input {
  padding: 0.65rem 0.8rem;
  border-radius: 0.5rem;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-size: 1rem;
}

.auth-form input:focus {
  outline: none;
  border-color: var(--accent);
}

.auth-error {
  background: rgba(224, 164, 94, 0.15);
  border: 1px solid var(--win-b);
  color: var(--win-b);
  padding: 0.6rem 0.9rem;
  border-radius: 0.5rem;
  font-size: 0.85rem;
}

.auth-message {
  background: rgba(110, 198, 163, 0.15);
  border: 1px solid var(--win-a);
  color: var(--win-a);
  padding: 0.6rem 0.9rem;
  border-radius: 0.5rem;
  font-size: 0.85rem;
}

.auth-card h2 {
  font-size: 1rem;
  margin-top: 2rem;
}

/* Past sessions */
.past-sessions {
  margin-top: 2.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

.past-session-list {
  list-style: none;
  padding: 0;
}

.past-session-list li {
  padding: 0.5rem 0;
}

.past-session-list a {
  color: var(--accent);
  text-decoration: none;
}

.past-session-list a:hover { text-decoration: underline; }

.session-meta {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.1rem;
}

.new-session-form {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin: 1.25rem 0;
}

.new-session-form input[type="text"] {
  flex: 1;
  min-width: 220px;
  padding: 0.65rem 0.8rem;
  border-radius: 0.5rem;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-size: 0.95rem;
}

.new-session-form input[type="text"]:focus {
  outline: none;
  border-color: var(--accent);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #faf6fd;
    --bg-card: #ffffff;
    --accent: #9b4fae;
    --accent-strong: #7d3a90;
    --text: #241832;
    --text-muted: #6b5c7a;
    --border: #e3d8ec;
  }
  body { background: linear-gradient(180deg, #faf6fd 0%, #f2e9f8 100%); }
}

/* Era themes -- derived from each album's cover-art palette. Selector
   specificity (html[attr]) intentionally beats :root and the light-mode
   media query above, so an era choice is a full override regardless of
   system light/dark preference. */
html[data-theme-era="debut"]      { --bg: #142523; --bg-card: #17322a; --accent: #1baec6; --accent-strong: #15889a; --text: #f4efe8; --text-muted: #9d9b91; --border: #363226; }
html[data-theme-era="fearless"]   { --bg: #33241a; --bg-card: #442f1e; --accent: #caa462; --accent-strong: #9e804c; --text: #f7efd8; --text-muted: #ad9b77; --border: #715632; }
html[data-theme-era="speak-now"]  { --bg: #1a0e1e; --bg-card: #200f23; --accent: #4a2454; --accent-strong: #3a1c42; --text: #d0bbd2; --text-muted: #6b486e; --border: #341a3c; }
html[data-theme-era="red"]        { --bg: #24070b; --bg-card: #2e0508; --accent: #c0392b; --accent-strong: #902b20; --text: #e6e5de; --text-muted: #8e827a; --border: #4f1007; }
html[data-theme-era="1989"]       { --bg: #28394e; --bg-card: #334e69; --accent: #8bb5d2; --accent-strong: #6c8da4; --text: #f3f1eb; --text-muted: #a2a5a5; --border: #496f8a; }
html[data-theme-era="reputation"] { --bg: #1b191e; --bg-card: #212023; --accent: #a91e47; --accent-strong: #7f1635; --text: #e0e0e0; --text-muted: #828183; --border: #39383a; }
html[data-theme-era="lover"]      { --bg: #5a1f3a; --bg-card: #7c294c; --accent: #76bae0; --accent-strong: #5c91af; --text: #fffae8; --text-muted: #c5aa99; --border: #753952; }
html[data-theme-era="folklore"]   { --bg: #232126; --bg-card: #2d2c2f; --accent: #b08968; --accent-strong: #84674e; --text: #f6f6f6; --text-muted: #a5a4a6; --border: #3e3d3f; }
html[data-theme-era="evermore"]   { --bg: #110c11; --bg-card: #130d11; --accent: #d37f55; --accent-strong: #a56342; --text: #f1eeed; --text-muted: #989192; --border: #2c1615; }
html[data-theme-era="midnights"]  { --bg: #0f131b; --bg-card: #101620; --accent: #85a7ba; --accent-strong: #688291; --text: #d9d3de; --text-muted: #746d80; --border: #384059; }
html[data-theme-era="ttpd"]       { --bg: #140f11; --bg-card: #171210; --accent: #3f3824; --accent-strong: #312c1c; --text: #fbfaf8; --text-muted: #a7a4a2; --border: #2c261b; }
html[data-theme-era="showgirl"]   { --bg: #232f23; --bg-card: #2d3f2b; --accent: #c44615; --accent-strong: #993710; --text: #f8e8ce; --text-muted: #a8966b; --border: #7c3c1b; }
