:root {
  --bg: #121014;
  --bg-elevated: #1c1a20;
  --border: #322e38;
  --text: #f1eef5;
  --text-muted: #a39cae;
  --accent: #e8b923;
  --accent-dark: #7a5e0f;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f7f5f2;
    --bg-elevated: #ffffff;
    --border: #e1dcd4;
    --text: #211f26;
    --text-muted: #6b6675;
    --accent: #b3860a;
    --accent-dark: #f3dfa3;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
}

.topbar h1 {
  font-size: 1.25rem;
  margin: 0;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.count-badge {
  color: var(--text-muted);
  font-size: 0.9rem;
}

@media (max-width: 640px) {
  .topbar {
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
    padding: 0.85rem 1rem;
  }

  .topbar h1 {
    font-size: 1.1rem;
  }

  .topbar-actions {
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .topbar-actions button {
    flex: 1 1 auto;
    font-size: 0.85rem;
    padding: 0.5rem 0.6rem;
  }

  .count-badge,
  .sync-status {
    flex: 1 1 100%;
  }
}

button {
  background: var(--accent);
  color: #1a1400;
  border: none;
  border-radius: 6px;
  padding: 0.5rem 1rem;
  font-weight: 600;
  cursor: pointer;
}

button:hover { filter: brightness(1.08); }
button:disabled { opacity: 0.6; cursor: default; }

.sync-status {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.tabs {
  display: flex;
  gap: 0.5rem;
  padding: 0 1.5rem;
  border-bottom: 1px solid var(--border);
}

.tab-btn {
  background: transparent;
  color: var(--text-muted);
  border-radius: 0;
  padding: 0.75rem 1rem;
  border-bottom: 2px solid transparent;
}

.tab-btn.active {
  color: var(--text);
  border-bottom-color: var(--accent);
}

main { padding: 1.5rem; }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.filters input, .filters select {
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.5rem 0.75rem;
}

.filters input[type="search"] { flex: 1 1 240px; }

.toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  user-select: none;
}

.toggle input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: relative;
  width: 38px;
  height: 22px;
  border-radius: 999px;
  background: var(--border);
  transition: background 0.15s ease;
  flex-shrink: 0;
}

.toggle-slider::before {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--bg-elevated);
  transition: transform 0.15s ease;
}

.toggle input:checked + .toggle-slider {
  background: var(--accent);
}

.toggle input:checked + .toggle-slider::before {
  transform: translateX(16px);
}

.toggle-label {
  font-size: 0.9rem;
  color: var(--text-muted);
}

.view-switch {
  display: flex;
  gap: 0.25rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.2rem;
}

.view-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  color: var(--text-muted);
  border-radius: 4px;
  padding: 0.35rem 0.5rem;
}

.view-btn:hover { filter: none; background: var(--border); }

.view-btn.active {
  background: var(--accent);
  color: #1a1400;
}

.empty-state {
  color: var(--text-muted);
  padding: 2rem;
  text-align: center;
  background: var(--bg-elevated);
  border-radius: 10px;
  border: 1px dashed var(--border);
}

.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 1.25rem;
}

.record-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.15s ease;
}

.record-card:hover { transform: translateY(-3px); }

.record-card img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  background: var(--border);
  display: block;
}

.record-card .info {
  padding: 0.6rem 0.75rem;
}

.record-card .artist {
  font-weight: 600;
  font-size: 0.85rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.record-card .title {
  color: var(--text-muted);
  font-size: 0.8rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.year-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  margin-top: 0.2rem;
}

.record-card .year {
  color: var(--text-muted);
  font-size: 0.75rem;
}

.record-card .original-year {
  color: var(--text-muted);
  font-size: 0.75rem;
}

.condition-price-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  margin-top: 0.2rem;
}

.record-card .condition {
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 600;
}

.record-card .price {
  color: var(--text-muted);
  font-size: 0.75rem;
}

.badge-original {
  display: inline-block;
  margin-top: 0.3rem;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  background: var(--accent-dark);
  color: var(--accent);
  font-size: 0.7rem;
  font-weight: 600;
  width: fit-content;
}

.pressing-tags {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.3rem;
  margin-top: 0.3rem;
  width: fit-content;
}

.badge-tag {
  display: inline-block;
  padding: 0.05rem 0.4rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.68rem;
  font-weight: 600;
}

.pressing-note {
  display: inline-block;
  color: var(--text-muted);
  font-size: 0.75rem;
  width: fit-content;
}

.gallery.list-view .badge-original,
.gallery.list-view .pressing-tags {
  grid-column: 5;
  margin-top: 0;
  max-width: 100%;
}

.gallery.list-view .badge-original {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.record-card .offers {
  margin-top: 0.35rem;
  padding-top: 0.35rem;
  border-top: 1px solid var(--border);
  font-size: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.record-card .offers span {
  color: var(--text);
  font-weight: 600;
}

.record-card .offers-link {
  color: var(--accent);
  text-decoration: none;
}

.record-card .offers-link:hover { text-decoration: underline; }

.gallery.list-view .record-card .offers {
  grid-column: 8;
  flex-direction: row;
  align-items: center;
  gap: 0.75rem;
  border-top: none;
  margin-top: 0;
  padding-top: 0;
  white-space: nowrap;
}

.gallery.list-view {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.gallery.list-view .record-card {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr) 150px 50px 160px 70px 90px auto;
  align-items: center;
  gap: 1rem;
  padding: 0.4rem 0.75rem;
}

.gallery.list-view .record-card:hover { transform: none; background: var(--border); }

.gallery.list-view .record-card img {
  grid-column: 1;
  width: 64px;
  height: 64px;
  aspect-ratio: unset;
  border-radius: 6px;
  flex-shrink: 0;
}

.gallery.list-view .record-card .info {
  grid-column: 2;
  padding: 0;
  min-width: 0;
}

.gallery.list-view .record-card .artist,
.gallery.list-view .record-card .title {
  display: inline;
  white-space: nowrap;
}

.gallery.list-view .record-card .artist::after {
  content: " — ";
  color: var(--text-muted);
}

.gallery.list-view .list-body {
  display: contents;
}

.gallery.list-view .list-meta-row {
  display: contents;
}

.gallery.list-view .list-meta {
  grid-column: 3;
  color: var(--text-muted);
  font-size: 0.8rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.gallery.list-view .list-year {
  grid-column: 4;
  color: var(--text-muted);
  font-size: 0.85rem;
  text-align: right;
}

.gallery.list-view .list-condition {
  grid-column: 6;
  color: var(--text-muted);
  font-size: 0.8rem;
  text-align: right;
}

.gallery.list-view .list-price {
  grid-column: 7;
  font-size: 0.85rem;
  font-weight: 600;
  text-align: right;
}

@media (max-width: 720px) {
  .gallery.list-view .list-meta { display: none; }
}

@media (max-width: 640px) {
  .gallery.list-view .record-card {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
  }

  .gallery.list-view .list-body {
    display: flex;
    flex-direction: column;
    flex: 1 1 0;
    min-width: 0;
    gap: 0.25rem;
  }

  .gallery.list-view .record-card .artist,
  .gallery.list-view .record-card .title {
    display: block;
    white-space: normal;
    overflow-wrap: break-word;
  }

  .gallery.list-view .record-card .artist::after {
    content: "";
  }

  .gallery.list-view .list-meta-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.4rem;
  }

  .gallery.list-view .list-year,
  .gallery.list-view .list-condition,
  .gallery.list-view .list-price {
    flex: 0 0 auto;
    text-align: left;
  }
}

.valuation-row {
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
  margin-bottom: 0.75rem;
}

.valuation-figure {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.valuation-label {
  color: var(--text-muted);
  font-size: 0.8rem;
}

.valuation-value {
  font-size: 1.4rem;
  font-weight: 700;
}

.valuation-figure.highlight .valuation-value {
  color: var(--accent);
}

.valuation-note {
  color: var(--text-muted);
  font-size: 0.8rem;
  margin: 0;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 1.25rem;
}

.chart-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem;
}

.chart-card.wide { grid-column: 1 / -1; }

.chart-card h2 {
  font-size: 0.95rem;
  margin: 0 0 0.75rem;
  color: var(--text-muted);
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.modal[hidden] { display: none; }

.modal-content {
  background: var(--bg-elevated);
  border-radius: 12px;
  border: 1px solid var(--border);
  max-width: 640px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  padding: 1.5rem;
  position: relative;
}

.modal-close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  background: transparent;
  color: var(--text-muted);
  font-size: 1.25rem;
  padding: 0.25rem 0.6rem;
}

.detail-header {
  display: flex;
  gap: 1rem;
  margin-bottom: 1rem;
}

.detail-header img {
  width: 140px;
  height: 140px;
  object-fit: cover;
  border-radius: 8px;
  background: var(--border);
}

.detail-meta { color: var(--text-muted); font-size: 0.9rem; }
.detail-meta div { margin-bottom: 0.25rem; }

.original-year-editor {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.75rem;
  margin-bottom: 1rem;
}

.original-year-editor label {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.original-year-editor input {
  width: 90px;
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.3rem 0.5rem;
}

.original-year-status {
  color: var(--text-muted);
  font-size: 0.8rem;
}

.tracklist { list-style: none; padding: 0; margin: 0; }
.tracklist li {
  display: flex;
  justify-content: space-between;
  padding: 0.35rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}
