:root {
  --bg0: #0c1210;
  --bg1: #14201a;
  --bg2: #1b2a22;
  --ink: #eef3ee;
  --muted: #9aafa3;
  --line: rgba(238, 243, 238, 0.1);
  --amber: #e2b84a;
  --amber-dim: rgba(226, 184, 74, 0.16);
  --mint: #6fd3a3;
  --coral: #ef7d6a;
  --card: rgba(20, 32, 26, 0.82);
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  --radius: 18px;
  --font-display: "Bricolage Grotesque", Georgia, serif;
  --font-body: "Figtree", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  min-height: 100vh;
  color: var(--ink);
  font-family: var(--font-body);
  background: var(--bg0);
  line-height: 1.45;
}

.atmosphere {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(900px 500px at 12% -10%, rgba(226, 184, 74, 0.18), transparent 55%),
    radial-gradient(700px 480px at 90% 8%, rgba(111, 211, 163, 0.12), transparent 50%),
    linear-gradient(165deg, #0c1210 0%, #122019 42%, #0d1411 100%);
}
.atmosphere::after {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.035;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  pointer-events: none;
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0);
  border: 0;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 1.5rem;
  padding: 1.75rem 1.5rem 1rem;
  max-width: 1440px;
  margin: 0 auto;
  animation: rise 0.7s ease both;
}
.topbar-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.75rem;
}
.btn-primary,
.btn-ghost {
  appearance: none;
  border-radius: 12px;
  font: inherit;
  font-weight: 700;
  font-size: 0.88rem;
  padding: 0.65rem 0.95rem;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}
.btn-primary {
  border: 1px solid rgba(226, 184, 74, 0.45);
  background: linear-gradient(120deg, rgba(226,184,74,0.22), rgba(111,211,163,0.14));
  color: var(--ink);
}
.btn-primary:hover { border-color: rgba(226, 184, 74, 0.75); }
.btn-primary:disabled { opacity: 0.55; cursor: wait; }
.btn-ghost {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
}
.btn-ghost:hover { color: var(--ink); border-color: rgba(238,243,238,0.25); }

.identify-box {
  margin-bottom: 1rem;
  padding: 0.85rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255,255,255,0.03);
}
.identify-drop {
  display: grid;
  gap: 0.75rem;
  justify-items: start;
}
.identify-drop.dragover {
  outline: 2px dashed rgba(226, 184, 74, 0.55);
  outline-offset: 4px;
  border-radius: 12px;
}
.identify-copy {
  display: grid;
  gap: 0.2rem;
  cursor: pointer;
}
.identify-copy strong {
  color: var(--ink);
  font-size: 0.95rem;
}
.identify-copy span {
  color: var(--muted);
  font-size: 0.85rem;
}
.identify-preview {
  width: min(180px, 40%);
  aspect-ratio: 63 / 88;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: #0a100d;
}
.identify-preview img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}
.identify-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}
.identify-status {
  margin: 0.65rem 0 0;
  min-height: 1.2em;
  color: var(--mint);
  font-size: 0.85rem;
}
.identify-results {
  margin-top: 0.75rem;
}
.identify-results-label {
  margin: 0 0 0.45rem;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.identify-grid {
  display: grid;
  gap: 0.45rem;
}
.identify-candidate {
  display: grid;
  grid-template-columns: 52px 1fr;
  gap: 0.65rem;
  align-items: center;
  width: 100%;
  text-align: left;
  appearance: none;
  cursor: pointer;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(10, 16, 13, 0.65);
  color: var(--ink);
  padding: 0.45rem 0.55rem;
  font: inherit;
}
.identify-candidate:hover,
.identify-candidate.selected {
  border-color: rgba(111, 211, 163, 0.55);
  background: rgba(111, 211, 163, 0.1);
}
.identify-candidate img {
  width: 52px;
  height: 72px;
  object-fit: contain;
  border-radius: 6px;
  background: #0a100d;
}
.identify-candidate strong {
  display: block;
  font-size: 0.92rem;
}
.identify-candidate span,
.identify-candidate em {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  font-style: normal;
}
.identify-candidate em { opacity: 0.85; }
.add-card-form {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(20, 32, 26, 0.88);
  padding: 1rem 1.1rem 1.1rem;
  box-shadow: var(--shadow);
}
.add-card-head h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.25rem;
  letter-spacing: -0.02em;
}
.add-card-head p {
  margin: 0.35rem 0 0.9rem;
  color: var(--muted);
  font-size: 0.88rem;
}
.add-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.7rem;
}
.add-grid label {
  display: grid;
  gap: 0.35rem;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}
.add-grid label.span-2 { grid-column: span 2; }
.add-grid input,
.add-grid select {
  width: 100%;
  appearance: none;
  border: 1px solid var(--line);
  background: rgba(10, 16, 13, 0.72);
  color: var(--ink);
  border-radius: 10px;
  padding: 0.65rem 0.75rem;
  font: inherit;
  font-size: 0.92rem;
  font-weight: 500;
  text-transform: none;
  letter-spacing: normal;
}
.add-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-top: 0.9rem;
  flex-wrap: wrap;
}
.add-status {
  margin: 0;
  color: var(--mint);
  font-size: 0.85rem;
  min-height: 1.2em;
}
.add-btns { display: flex; gap: 0.5rem; }

.tile-meta-actions {
  display: none;
}
.tile-meta-sub {
  display: flex;
  justify-content: flex-end;
  padding: 0 0.75rem 0.15rem;
}
.remove-btn {
  appearance: none;
  border: 1px solid rgba(239, 125, 106, 0.35);
  background: rgba(239, 125, 106, 0.08);
  color: #f3a79c;
  border-radius: 999px;
  padding: 0.28rem 0.55rem;
  font: inherit;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
}
.remove-btn:hover {
  border-color: rgba(239, 125, 106, 0.65);
  background: rgba(239, 125, 106, 0.16);
}
.badge.badge-custom {
  border-color: rgba(111, 211, 163, 0.4);
  color: #9fe0bf;
}
.card.is-custom {
  border-color: rgba(111, 211, 163, 0.22);
}

.brand {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(2rem, 4.5vw, 3.4rem);
  font-weight: 750;
  letter-spacing: -0.03em;
  line-height: 0.95;
  background: linear-gradient(120deg, #f4e3b0 10%, var(--amber) 45%, #9fe0bf 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.brand-sub {
  margin: 0.45rem 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.top-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  justify-content: flex-end;
}

.stat-pill {
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.03);
  border-radius: 999px;
  padding: 0.4rem 0.75rem;
  font-size: 0.8rem;
  color: var(--muted);
  white-space: nowrap;
}
.stat-pill strong {
  color: var(--ink);
  font-weight: 700;
  margin-right: 0.25rem;
}

.controls {
  max-width: 1440px;
  margin: 0 auto;
  padding: 0.5rem 1.5rem 0.75rem;
  display: grid;
  gap: 0.75rem;
  animation: rise 0.8s ease both;
  animation-delay: 0.08s;
}

.search-wrap input,
.filters select {
  width: 100%;
  appearance: none;
  border: 1px solid var(--line);
  background: rgba(10, 16, 13, 0.72);
  color: var(--ink);
  border-radius: 12px;
  padding: 0.75rem 0.9rem;
  font: inherit;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.search-wrap input:focus,
.filters select:focus {
  border-color: rgba(226, 184, 74, 0.55);
  box-shadow: 0 0 0 3px var(--amber-dim);
}

.filters {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0.6rem;
}

main {
  max-width: 1440px;
  margin: 0 auto;
  padding: 0.5rem 1.5rem 3rem;
}

.meta-line {
  margin: 0 0 1rem;
  color: var(--muted);
  font-size: 0.88rem;
}

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

.card {
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
  transform: translateY(10px);
  opacity: 0;
  animation: rise 0.55s ease forwards;
  transition: transform 0.25s ease, border-color 0.25s ease;
}
.card:hover {
  transform: translateY(-2px);
  border-color: rgba(226, 184, 74, 0.35);
}

.art {
  position: relative;
  aspect-ratio: 63 / 88;
  background:
    linear-gradient(160deg, rgba(226,184,74,0.08), transparent 40%),
    #0a100d;
  overflow: hidden;
}
.art img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  transition: transform 0.35s ease;
}
.card:hover .art img { transform: scale(1.03); }
.art-fallback {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 0.85rem;
  padding: 1rem;
  text-align: center;
}

.badges {
  display: none;
}
.tile-meta {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.4rem;
  padding: 0.55rem 0.75rem 0.35rem;
  align-items: stretch;
}
.meta-chip,
.badge {
  box-sizing: border-box;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.28rem;
  width: 100%;
  min-height: 2rem;
  margin: 0;
  padding: 0.35rem 0.45rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(8, 12, 10, 0.72);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  line-height: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.meta-chip.lang-japanese,
.badge.lang-japanese { border-color: rgba(111,211,163,0.45); color: #9fe0bf; }
.meta-chip.lang-korean,
.badge.lang-korean { border-color: rgba(226,184,74,0.45); color: #f0d48a; }
.meta-chip.lang-chinese,
.badge.lang-chinese { border-color: rgba(239,125,106,0.45); color: #f3a79c; }
.meta-chip.lang-english { color: var(--ink); }

.meta-chip.grade-raw,
.badge.grade-raw {
  border-color: rgba(154, 175, 163, 0.45);
  color: #c5d5cb;
}
.meta-chip.grade-graded,
.meta-chip.grade-psa,
.meta-chip.grade-cgc,
.meta-chip.grade-bgs,
.meta-chip.grade-sgc,
.badge.grade-graded,
.badge.grade-psa,
.badge.grade-cgc,
.badge.grade-bgs,
.badge.grade-sgc {
  border-color: rgba(226, 184, 74, 0.6);
  color: #f0d48a;
  background: rgba(226, 184, 74, 0.12);
}

button.meta-chip.owned-btn {
  cursor: pointer;
  appearance: none;
  transition: border-color 0.2s ease, background 0.2s ease, color 0.2s ease;
}
button.meta-chip.owned-btn:hover {
  border-color: rgba(111, 211, 163, 0.45);
  color: var(--ink);
}
.owned-btn .owned-check {
  width: 0.85rem;
  height: 0.85rem;
  flex: 0 0 auto;
  border-radius: 50%;
  display: grid;
  place-items: center;
  border: 1px solid rgba(154, 175, 163, 0.55);
  font-size: 0.62rem;
  line-height: 1;
  color: transparent;
}
.owned-btn.on {
  border-color: rgba(111, 211, 163, 0.65);
  background: rgba(111, 211, 163, 0.16);
  color: var(--mint);
}
.owned-btn.on .owned-check {
  border-color: var(--mint);
  background: var(--mint);
  color: #0c1210;
}
button.meta-chip.delete-btn {
  cursor: pointer;
  appearance: none;
  border-color: rgba(239, 125, 106, 0.4);
  color: #f3a79c;
  background: rgba(239, 125, 106, 0.08);
}
button.meta-chip.delete-btn:hover {
  border-color: rgba(239, 125, 106, 0.7);
  background: rgba(239, 125, 106, 0.16);
  color: #ffc2b8;
}

.btn-danger {
  appearance: none;
  border-radius: 12px;
  font: inherit;
  font-weight: 700;
  font-size: 0.88rem;
  padding: 0.65rem 0.95rem;
  cursor: pointer;
  border: 1px solid rgba(239, 125, 106, 0.55);
  background: rgba(239, 125, 106, 0.2);
  color: #ffc2b8;
}
.btn-danger:hover {
  border-color: rgba(239, 125, 106, 0.85);
  background: rgba(239, 125, 106, 0.3);
}

.modal[hidden] { display: none !important; }
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 1rem;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(4, 8, 6, 0.72);
  backdrop-filter: blur(4px);
}
.modal-card {
  position: relative;
  z-index: 1;
  width: min(420px, 100%);
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(20, 32, 26, 0.96);
  box-shadow: var(--shadow);
  padding: 1.15rem 1.2rem 1.2rem;
  animation: rise 0.25s ease both;
}
.modal-card h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.35rem;
  letter-spacing: -0.02em;
}
.modal-card p {
  margin: 0.55rem 0 1.1rem;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.45;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

.card.is-owned {
  border-color: rgba(111, 211, 163, 0.35);
}

.price-row.ebay {
  border-color: rgba(154, 175, 163, 0.18);
}

.body {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  padding: 0.9rem 0.95rem 1rem;
  flex: 1;
}

.id-row {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  color: var(--muted);
  font-size: 0.75rem;
}
.name {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.15;
}
.setline {
  margin: 0.2rem 0 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.prices {
  display: grid;
  gap: 0.45rem;
  margin-top: auto;
}
.price-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.6rem;
  border-radius: 12px;
  background: rgba(255,255,255,0.03);
  border: 1px solid transparent;
}
.price-row.sneak {
  border-color: rgba(111, 211, 163, 0.28);
  background: rgba(111, 211, 163, 0.07);
}
a.price-row.linkish {
  text-decoration: none;
  color: inherit;
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease, transform 0.15s ease;
}
a.price-row.linkish:hover {
  border-color: rgba(111, 211, 163, 0.55);
  background: rgba(111, 211, 163, 0.14);
}
a.price-row.linkish .label,
a.price-row.linkish .value {
  color: var(--mint);
}
a.price-row.linkish .label {
  text-decoration: underline;
  text-underline-offset: 2px;
}
.price-row .label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}
.price-row .value {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  font-size: 0.98rem;
}
.price-row .value.na { color: var(--muted); font-weight: 500; font-size: 0.85rem; }
.price-row .value.warn { color: #f0c27a; }
.price-row a.value {
  color: var(--mint);
  text-decoration: none;
}
.price-row a.value:hover { text-decoration: underline; }

.ceil {
  font-size: 0.75rem;
  color: var(--muted);
}
.ceil strong { color: var(--ink); font-weight: 600; }
.ceil .delta.good,
.ceil .delta.good strong { color: var(--mint); }
.ceil .delta.bad,
.ceil .delta.bad strong { color: var(--coral); }
.ceil .delta.flat strong,
.ceil .delta.na strong { color: var(--muted); font-weight: 600; }

.empty {
  text-align: center;
  color: var(--muted);
  padding: 3rem 1rem;
}

.foot {
  max-width: 1440px;
  margin: 0 auto;
  padding: 0 1.5rem 2.5rem;
  color: var(--muted);
  font-size: 0.8rem;
}
.foot .defs {
  display: grid;
  gap: 0.45rem;
  margin-bottom: 1rem;
  padding: 0.9rem 1rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255,255,255,0.03);
}
.foot .defs p { margin: 0; line-height: 1.4; }
.foot .defs strong { color: var(--ink); font-weight: 700; }

@keyframes rise {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 1100px) {
  .filters { grid-template-columns: 1fr 1fr; }
  .add-grid { grid-template-columns: 1fr 1fr; }
  .add-grid label.span-2 { grid-column: span 2; }
}
@media (max-width: 900px) {
  .topbar { flex-direction: column; align-items: flex-start; }
  .topbar-actions { align-items: flex-start; width: 100%; }
}
@media (max-width: 560px) {
  .filters { grid-template-columns: 1fr; }
  .add-grid { grid-template-columns: 1fr; }
  .add-grid label.span-2 { grid-column: span 1; }
  .topbar, .controls, .add-card-panel, main, .foot { padding-left: 1rem; padding-right: 1rem; }
}
