:root {
  --bg: #0f1115;
  --bg-elevated: #171a21;
  --bg-card: #1c2029;
  --border: #2a2f3a;
  --text: #e8e9ee;
  --text-dim: #9aa0ae;
  --accent: #d3934a;
  --accent-2: #7c5cff;
  --owned: #4caf7d;
  --missing: #d3934a;
  --danger: #e2596b;
  --radius: 10px;
  --shadow: 0 4px 16px rgba(0,0,0,0.35);
}

[data-theme="light"] {
  --bg: #f4f2ee;
  --bg-elevated: #ffffff;
  --bg-card: #ffffff;
  --border: #e1ddd3;
  --text: #201d1a;
  --text-dim: #6b6459;
  --accent: #b5672a;
  --accent-2: #5c3fd6;
  --owned: #2f8b5e;
  --missing: #b5672a;
  --danger: #c73a4e;
  --shadow: 0 4px 16px rgba(0,0,0,0.08);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

button, select, input {
  font-family: inherit;
}

/* ---------- Top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 24px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  font-size: 28px;
  color: var(--accent);
}

.brand h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.3px;
}

.subtitle {
  margin: 2px 0 0;
  font-size: 12.5px;
  color: var(--text-dim);
}

.profile-area {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.stat-pill {
  background: var(--bg-card);
  border: 1px solid var(--border);
  padding: 7px 14px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
}

select, input[type="search"], input[type="number"], input[type="text"] {
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13.5px;
}

select:focus, input:focus {
  outline: 1.5px solid var(--accent-2);
}

.btn-ghost {
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  cursor: pointer;
  transition: border-color .15s ease;
  text-align: center;
}
.btn-ghost:hover { border-color: var(--accent-2); }

.btn-accent {
  background: linear-gradient(135deg, var(--accent-2), #a06bff);
  color: white;
  border: none;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
}
.btn-accent:hover { filter: brightness(1.08); }

.full { width: 100%; display: block; }

/* ---------- Progress bar ---------- */

.progress-track {
  height: 4px;
  background: var(--border);
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--owned), var(--accent-2));
  transition: width .3s ease;
}

/* ---------- Layout ---------- */

main {
  display: grid;
  grid-template-columns: 250px 1fr;
  gap: 24px;
  padding: 24px;
  align-items: start;
}

@media (max-width: 860px) {
  main { grid-template-columns: 1fr; }
}

.filters {
  position: sticky;
  top: 24px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.filter-block label {
  display: block;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-dim);
  margin-bottom: 6px;
  font-weight: 600;
}

.filter-block input, .filter-block select {
  width: 100%;
}

.year-range {
  display: flex;
  align-items: center;
  gap: 6px;
}
.year-range input { width: 0; flex: 1; }
.year-range span { color: var(--text-dim); }

.view-tabs {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.view-tab {
  flex: 1;
  background: var(--bg-card);
  color: var(--text-dim);
  border: none;
  padding: 8px 6px;
  font-size: 12.5px;
  cursor: pointer;
  border-right: 1px solid var(--border);
}
.view-tab:last-child { border-right: none; }
.view-tab.active {
  background: var(--accent-2);
  color: white;
  font-weight: 600;
}

.genre-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
  max-height: 220px;
  overflow-y: auto;
  padding-right: 4px;
}
.genre-list label {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  text-transform: none;
  letter-spacing: 0;
  font-weight: 400;
  color: var(--text);
  cursor: pointer;
}
.genre-list input { width: auto; accent-color: var(--accent-2); }
.genre-count { color: var(--text-dim); margin-left: auto; font-size: 11px; }

.backup-block { display: flex; flex-direction: column; gap: 8px; }
.file-label { cursor: pointer; }

/* ---------- Results ---------- */

.results-header {
  margin-bottom: 12px;
  color: var(--text-dim);
  font-size: 13px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 18px;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: transform .12s ease, box-shadow .12s ease;
  display: flex;
  flex-direction: column;
}
.card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow);
}

.card-cover-wrap {
  position: relative;
  aspect-ratio: 1 / 1;
  background: var(--border);
}
.card-cover-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.rank-badge {
  position: absolute;
  top: 6px;
  left: 6px;
  background: rgba(0,0,0,0.65);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 7px;
  border-radius: 6px;
}
.owned-toggle {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1.5px solid rgba(255,255,255,0.7);
  background: rgba(0,0,0,0.5);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 14px;
  transition: background .15s ease, border-color .15s ease;
}
.owned-toggle.owned {
  background: var(--owned);
  border-color: var(--owned);
}

.card-info {
  padding: 10px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}
.card-title {
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1.25;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card-artist {
  font-size: 12px;
  color: var(--text-dim);
}
.card-meta {
  margin-top: 6px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11.5px;
  color: var(--text-dim);
}
.card-rating {
  color: var(--accent);
  font-weight: 700;
}

.empty-state {
  color: var(--text-dim);
  text-align: center;
  padding: 60px 0;
}

/* ---------- Modal ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 50;
}
.modal-backdrop[hidden] {
  display: none;
}
.modal {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 14px;
  max-width: 640px;
  width: 100%;
  max-height: 88vh;
  overflow-y: auto;
  position: relative;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 14px;
  z-index: 2;
}
.modal-body {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 20px;
  padding: 24px;
}
@media (max-width: 560px) {
  .modal-body { grid-template-columns: 1fr; }
}
.modal-body img {
  width: 100%;
  border-radius: 10px;
  border: 1px solid var(--border);
}
.modal-title { font-size: 20px; font-weight: 700; margin: 0 0 4px; }
.modal-artist { color: var(--text-dim); font-size: 15px; margin-bottom: 14px; }
.modal-facts {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 14px;
  font-size: 13.5px;
  margin-bottom: 18px;
}
.modal-facts dt { color: var(--text-dim); }
.modal-facts dd { margin: 0; }
.modal-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.modal-actions a, .modal-actions button {
  text-decoration: none;
}

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 8px;
  box-shadow: var(--shadow);
  font-size: 13.5px;
  z-index: 100;
}

/* ---------- Auth area (topbar) ---------- */

.auth-area {
  display: flex;
  align-items: center;
  gap: 8px;
}
.auth-area .user-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-right: 2px;
}

/* ---------- Auth modal ---------- */

.auth-modal {
  max-width: 380px;
  padding: 28px;
}
.auth-tabs {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 20px;
}
.auth-tab {
  flex: 1;
  background: var(--bg-card);
  color: var(--text-dim);
  border: none;
  padding: 10px 6px;
  font-size: 13.5px;
  cursor: pointer;
  border-right: 1px solid var(--border);
}
.auth-tab:last-child { border-right: none; }
.auth-tab.active {
  background: var(--accent-2);
  color: white;
  font-weight: 600;
}
.auth-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.auth-form[hidden] {
  display: none;
}
.auth-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12.5px;
  color: var(--text-dim);
  font-weight: 600;
}
.auth-form input {
  padding: 10px 11px;
  font-size: 14px;
}
.auth-hint {
  margin: -4px 0 0;
  font-size: 11.5px;
  color: var(--text-dim);
}
.auth-error {
  margin: 0;
  font-size: 12.5px;
  color: var(--danger);
}

/* ---------- Share modal / banner ---------- */

.share-modal {
  max-width: 460px;
  padding: 28px;
}
.share-modal h3 {
  margin: 0 0 8px;
  font-size: 17px;
}
.share-desc {
  color: var(--text-dim);
  font-size: 13px;
  margin: 0 0 16px;
  line-height: 1.5;
}
.share-link-row {
  display: flex;
  gap: 8px;
}
.share-link-row input {
  flex: 1;
  font-size: 13px;
}

.share-banner {
  background: linear-gradient(135deg, rgba(124,92,255,0.18), rgba(211,147,74,0.12));
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  font-size: 13.5px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.share-banner[hidden] {
  display: none;
}
.share-banner strong { color: var(--accent); }
.share-banner .btn-accent { flex-shrink: 0; }
