:root {
  --font-display: 'Archivo', sans-serif;
  --font-body: 'Space Grotesk', sans-serif;
}

[data-theme="light"] {
  --bg: #ffffff;
  --panel: #ffffff;
  --ink: #111114;
  --ink-2: #555555;
  --ink-3: #999999;
  --line: #111114;
  --line-soft: #e6e6e6;
  --accent: #5e6737;
  --accent-ink: #4b5230;
  --on-accent: #f4f6e8;
  --heart-off: #b8b8bd;
  --heart-on: #5e6737;
  --cover-ring: rgba(0, 0, 0, .15);
  --field-bg: #ffffff;
  --scrim: rgba(17, 17, 20, .45);
}

[data-theme="dark"] {
  --bg: #0e0e10;
  --panel: #111114;
  --ink: #fafafa;
  --ink-2: #a1a1aa;
  --ink-3: #6b6b73;
  --line: #8c9a53;
  --line-soft: #2c2c33;
  --accent: #8c9a53;
  --accent-ink: #a7b56e;
  --on-accent: #14160c;
  --heart-off: #4a4a52;
  --heart-on: #a7b56e;
  --cover-ring: rgba(255, 255, 255, .1);
  --field-bg: #17171b;
  --scrim: rgba(0, 0, 0, .66);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  transition: background .2s, color .2s;
}

.hidden { display: none !important; }
.ink-2 { color: var(--ink-2); }
.error { color: #d64b3f; font-size: 13px; margin: 0; }

.wrap { max-width: 960px; margin: 0 auto; padding: 40px 20px 80px; }

button, input, select, textarea { font: inherit; color: inherit; }

.btn-solid {
  background: var(--accent);
  color: var(--on-accent);
  border: 1px solid var(--accent);
  font: 600 13px var(--font-body);
  letter-spacing: .04em;
  padding: 9px 16px;
  cursor: pointer;
  transition: opacity .15s;
}

.btn-solid:hover { opacity: .88; }

.btn-outline {
  border: 1px solid var(--line);
  background: none;
  color: var(--ink);
  font: 600 12px var(--font-body);
  letter-spacing: .08em;
  text-transform: uppercase;
  padding: 9px 14px;
  cursor: pointer;
  transition: background .15s, color .15s;
}

.btn-outline:hover { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }

.link-btn {
  background: none;
  border: none;
  color: var(--accent-ink);
  font: 600 13px var(--font-body);
  cursor: pointer;
  padding: 4px 0;
}

.link-btn:hover { text-decoration: underline; }

.icon-btn {
  background: none;
  border: none;
  color: var(--ink-3);
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
}

.icon-btn:hover { color: var(--ink); }

/* ── overlay + login ── */
.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: var(--bg);
  z-index: 60;
  padding: 24px;
}

.login-card {
  width: min(360px, 100%);
  display: grid;
  gap: 14px;
  justify-items: start;
}

.login-brand {
  font-family: var(--font-display);
  font-weight: 900;
  font-size: 56px;
  line-height: .86;
  letter-spacing: -.02em;
}

.login-card p { margin: 0; }
.login-card input {
  width: 100%;
  border: 1px solid var(--line-soft);
  background: var(--field-bg);
  padding: 11px 12px;
}
.login-card input:focus { outline: none; border-color: var(--accent); }
.login-card .btn-solid { width: 100%; padding: 12px; }

/* ── masthead ── */
.masthead-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--ink);
  border-bottom: 1px solid var(--line-soft);
  padding-bottom: 10px;
}

.masthead-meta .mid { color: var(--ink-2); }

.masthead h1 {
  font-family: var(--font-display);
  font-weight: 900;
  font-size: clamp(48px, 12vw, 96px);
  line-height: .86;
  letter-spacing: -.02em;
  margin: 18px 0 4px;
}

.filters {
  border-top: 3px solid var(--accent);
  border-bottom: 1px solid var(--line-soft);
  display: flex;
  gap: 22px;
  margin-top: 14px;
  padding: 12px 0;
  font-size: 13px;
  font-weight: 600;
  overflow-x: auto;
}

.filters button {
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  font: inherit;
  color: var(--ink-3);
  white-space: nowrap;
}

.filters button:hover { color: var(--ink); }
.filters button[aria-selected="true"] { color: var(--accent); }

.toolbar {
  display: flex;
  gap: 12px;
  align-items: center;
  margin: 18px 0 4px;
  flex-wrap: wrap;
}

.search {
  flex: 1;
  min-width: 200px;
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line-soft);
  padding: 9px 12px;
  color: var(--ink-3);
}

.search input {
  border: none;
  background: none;
  color: var(--ink);
  font: inherit;
  width: 100%;
}

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

.facets {
  display: flex;
  gap: 10px;
  align-items: center;
  margin: 12px 0 0;
  padding: 12px 0 4px;
  border-top: 1px solid var(--line-soft);
  flex-wrap: wrap;
}

.facet {
  border: 1px solid var(--line-soft);
  background: var(--field-bg);
  color: var(--ink);
  font: 600 12px var(--font-body);
  letter-spacing: .02em;
  padding: 7px 10px;
  cursor: pointer;
}

.facet:focus { outline: none; border-color: var(--accent); }
.facet:hover { border-color: var(--ink-3); }

.facet-sep { flex: 1; min-width: 0; }

@media (max-width: 560px) { .facet-sep { display: none; } }

/* ── grid ── */
.grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-left: 1px solid var(--line-soft);
}

@media (max-width: 720px) { .grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 440px) { .grid { grid-template-columns: 1fr; } }

.card {
  padding: 20px;
  border-top: 1px solid var(--line-soft);
  border-right: 1px solid var(--line-soft);
  cursor: pointer;
  transition: background .12s;
}

.card:hover { background: color-mix(in srgb, var(--accent) 7%, transparent); }

.card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  font-family: var(--font-display);
  margin-bottom: 12px;
  min-height: 20px;
}

.num { font-weight: 800; font-size: 13px; color: var(--ink-3); }

.tag-want {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .12em;
  color: var(--accent);
  border: 1px solid var(--accent);
  padding: 2px 6px;
}

.cover {
  width: 100%;
  aspect-ratio: 1;
  display: flex;
  align-items: flex-end;
  padding: 12px;
  box-shadow: inset 0 0 0 1px var(--cover-ring);
  background-size: cover;
  background-position: center;
  overflow: hidden;
}

.cover .mono {
  font-family: var(--font-display);
  font-weight: 900;
  font-size: 34px;
  line-height: .8;
}

.artist {
  font-family: var(--font-display);
  font-weight: 800;
  text-transform: uppercase;
  font-size: 14px;
  color: var(--ink);
  margin-top: 12px;
  line-height: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.title { font-size: 13px; color: var(--ink-2); margin-top: 3px; }

.card-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 8px;
  gap: 8px;
}

.genre {
  font-size: 11px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--ink-3);
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rating {
  font-size: 15px;
  font-weight: 700;
  color: var(--ink);
  background: none;
  border: none;
  cursor: pointer;
  font-family: var(--font-body);
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.rating .heart { color: var(--heart-off); font-size: 16px; transition: color .12s, transform .12s; }
.rating .heart.on { color: var(--heart-on); }
.rating:hover .heart { transform: scale(1.15); }

.empty {
  text-align: center;
  color: var(--ink-3);
  padding: 70px 20px;
  font-size: 15px;
  border-top: 1px solid var(--line-soft);
}

/* ── dialogs ── */
.sheet {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  padding: 0;
  width: min(720px, calc(100vw - 32px));
  font-family: var(--font-body);
}

.sheet::backdrop { background: var(--scrim); }

.detail-body { padding: 26px; display: grid; grid-template-columns: 260px 1fr; gap: 26px; }

.detail-body .art {
  aspect-ratio: 1;
  box-shadow: inset 0 0 0 1px var(--cover-ring);
  background-size: cover;
  background-position: center;
  display: flex;
  align-items: flex-end;
  padding: 14px;
}

.detail-body .art .mono { font-family: var(--font-display); font-weight: 900; font-size: 44px; line-height: .8; }

.detail-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.detail-body h2 {
  font-family: var(--font-display);
  font-weight: 800;
  text-transform: uppercase;
  font-size: 24px;
  line-height: 1;
  margin: 0;
}
.detail-body .sub { color: var(--ink-2); margin: 6px 0 16px; font-size: 14px; }

.facts {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 16px;
  font-size: 13px;
  margin: 0 0 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line-soft);
}

.facts dt { color: var(--ink-3); text-transform: uppercase; letter-spacing: .08em; font-size: 11px; font-weight: 600; }
.facts dd { margin: 0; }

.field-label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--ink-3);
  font-weight: 600;
  margin: 16px 0 7px;
}

.stars { display: inline-flex; gap: 4px; font-size: 26px; line-height: 1; }
.stars button { background: none; border: none; padding: 0; cursor: pointer; color: var(--line-soft); transition: color .12s; }
.stars button:hover { color: var(--accent); }
.stars button.on { color: var(--accent); }

.fav-line { display: flex; align-items: center; gap: 10px; margin-top: 16px; }
.fav-btn {
  background: none;
  border: 1px solid var(--line-soft);
  color: var(--ink);
  cursor: pointer;
  padding: 7px 12px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font: 600 13px var(--font-body);
}
.fav-btn .heart { color: var(--heart-off); font-size: 16px; }
.fav-btn.on { border-color: var(--accent); }
.fav-btn.on .heart { color: var(--heart-on); }

.sheet textarea {
  width: 100%;
  min-height: 84px;
  resize: vertical;
  border: 1px solid var(--line-soft);
  background: var(--field-bg);
  padding: 10px 12px;
}
.sheet textarea:focus { outline: none; border-color: var(--accent); }

.actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 22px; flex-wrap: wrap; }
.actions .left { margin-right: auto; }

.btn-danger {
  background: none;
  border: 1px solid var(--line-soft);
  color: #d64b3f;
  cursor: pointer;
  padding: 9px 14px;
  font: 600 13px var(--font-body);
}
.btn-danger:hover { border-color: #d64b3f; }

.btn-ghost {
  background: none;
  border: 1px solid var(--line-soft);
  color: var(--ink);
  cursor: pointer;
  padding: 9px 14px;
  font: 600 13px var(--font-body);
}
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }

/* ── add dialog ── */
.add-body { padding: 24px; }
.add-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.add-head h2 {
  font-family: var(--font-display);
  font-weight: 800;
  text-transform: uppercase;
  font-size: 20px;
  margin: 0;
}

.search.big { border: 1px solid var(--line); padding: 11px 14px; gap: 10px; }
.search.big input { font-size: 15px; }
.search.big .btn-solid { padding: 7px 14px; }

.add-results { display: grid; gap: 0; margin: 18px 0 4px; max-height: 46vh; overflow-y: auto; }

.result {
  display: flex;
  gap: 14px;
  align-items: center;
  padding: 12px 4px;
  border-top: 1px solid var(--line-soft);
}
.result:first-child { border-top: none; }

.result .thumb {
  width: 54px;
  height: 54px;
  flex: none;
  box-shadow: inset 0 0 0 1px var(--cover-ring);
  background-size: cover;
  background-position: center;
}

.result .info { flex: 1; min-width: 0; }
.result .r-artist { font-family: var(--font-display); font-weight: 800; text-transform: uppercase; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.result .r-title { font-size: 12.5px; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.result .r-saved { font-size: 11px; color: var(--accent); font-weight: 600; margin-top: 2px; letter-spacing: .06em; text-transform: uppercase; }

.result .r-actions { display: flex; gap: 6px; flex: none; }
.result .r-actions button {
  border: 1px solid var(--line-soft);
  background: none;
  color: var(--ink);
  cursor: pointer;
  font: 600 11px var(--font-body);
  letter-spacing: .04em;
  padding: 6px 9px;
  white-space: nowrap;
}
.result .r-actions button:hover { border-color: var(--accent); color: var(--accent); }

#manual-toggle { margin-top: 8px; }

.manual { margin-top: 16px; border-top: 1px solid var(--line-soft); padding-top: 16px; }
.manual-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.manual-fields label {
  display: grid;
  gap: 5px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--ink-3);
  font-weight: 600;
}
.manual-fields input, .manual-fields select {
  border: 1px solid var(--line-soft);
  background: var(--field-bg);
  padding: 9px 11px;
  text-transform: none;
  letter-spacing: 0;
  color: var(--ink);
  font-weight: 400;
}
.manual-fields input:focus, .manual-fields select:focus { outline: none; border-color: var(--accent); }
.manual-actions { display: flex; justify-content: flex-end; margin-top: 14px; }

@media (max-width: 560px) {
  .manual-fields { grid-template-columns: 1fr; }
  .detail-body { grid-template-columns: 1fr; }
  .detail-body .art { max-width: 220px; }
}

/* ── loading ── */
.loading { display: flex; gap: 6px; justify-content: center; padding: 40px; }
.loading span { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); animation: bounce 1s infinite ease-in-out; }
.loading span:nth-child(2) { animation-delay: .15s; }
.loading span:nth-child(3) { animation-delay: .3s; }

@keyframes bounce { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

/* ── toast ── */
.toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--bg);
  padding: 11px 18px;
  z-index: 90;
  font-size: 14px;
  max-width: min(520px, calc(100vw - 32px));
}
.toast.bad { background: #d64b3f; color: #fff; }
