:root {
  --bg: #f5f4f1;
  --surface: #ffffff;
  --surface-2: #f0eeea;
  --ink: #1c1917;
  --muted: #6b6560;
  --line: #e2dfda;
  --accent: #dc2626;
  --accent-ink: #ffffff;
  --accent-soft: #fde8e8;
  --ok: #15803d;
  --ok-soft: #e3f4e8;
  --focus: #2563eb;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.06), 0 4px 14px rgb(0 0 0 / 0.06);
  --radius: 14px;
  color-scheme: light;
}

:root[data-theme="dark"] {
    --bg: #141312;
    --surface: #1e1c1b;
    --surface-2: #282624;
    --ink: #f3f1ee;
    --muted: #a39d97;
    --line: #34312e;
    --accent: #ef4444;
    --accent-soft: #3a1a1a;
    --ok: #4ade80;
    --ok-soft: #173322;
    --focus: #60a5fa;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.4), 0 6px 18px rgb(0 0 0 / 0.35);
    color-scheme: dark;
  }
@media (prefers-color-scheme: dark) {
  :root[data-theme="system"] {
    --bg: #141312;
    --surface: #1e1c1b;
    --surface-2: #282624;
    --ink: #f3f1ee;
    --muted: #a39d97;
    --line: #34312e;
    --accent: #ef4444;
    --accent-soft: #3a1a1a;
    --ok: #4ade80;
    --ok-soft: #173322;
    --focus: #60a5fa;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.4), 0 6px 18px rgb(0 0 0 / 0.35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

img { max-width: 100%; display: block; }
a { color: inherit; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 0.35em; }
h1 { font-size: 1.75rem; letter-spacing: -0.01em; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 0.6em; }
.muted { color: var(--muted); }
[hidden] { display: none !important; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px max(16px, calc((100vw - 1200px) / 2));
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: 0 2px 10px rgb(0 0 0 / 0.15);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 1.15rem;
  text-decoration: none;
  letter-spacing: 0.01em;
}

.pokeball {
  --size: 26px;
  width: var(--size);
  height: var(--size);
  border-radius: 50%;
  border: calc(var(--size) * 0.1) solid #111;
  background:
    radial-gradient(circle at 50% 50%, #fff 0 16%, #111 16% 25%, transparent 25%),
    linear-gradient(#dc2626 0 45%, #111 45% 55%, #fff 55%);
  flex: none;
}

.nav { display: flex; gap: 4px; }
.nav a {
  padding: 7px 12px;
  border-radius: 999px;
  text-decoration: none;
  font-weight: 600;
  color: rgb(255 255 255 / 0.85);
}
.nav a:hover { color: #fff; background: rgb(255 255 255 / 0.12); }
.nav a.active { color: var(--accent); background: #fff; }
.nav .nav-add { border: 1.5px solid rgb(255 255 255 / 0.6); }

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

.container { max-width: 1200px; margin: 0 auto; padding: 24px 16px 120px; }

.page-head { margin-bottom: 18px; }
.page-head.row { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }

.stats { display: flex; gap: 16px; color: var(--muted); flex-wrap: wrap; }
.stats strong { color: var(--ink); font-size: 1.05rem; }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.step { display: flex; align-items: center; gap: 10px; }
.step-num {
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 0.85rem;
}
.optional { font-weight: 400; font-size: 0.9rem; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 14px;
}
.toolbar .search { flex: 1 1 260px; }
.result-count { display: block; margin: -4px 0 10px; font-size: 0.9rem; }

/* ---------- Controls ---------- */

input, select, textarea {
  font: inherit;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 11px;
  min-width: 0;
  width: 100%;
}
.toolbar select { width: auto; max-width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--focus); outline-offset: -1px; border-color: transparent; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font: inherit;
  font-weight: 600;
  padding: 9px 16px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { background: #b91c1c; border-color: #b91c1c; color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.small { padding: 5px 10px; font-size: 0.85rem; }
.btn.link { background: none; border: none; padding: 6px 0; color: var(--accent); }
.danger-text { color: #b91c1c; }
:root[data-theme="dark"] .danger-text { color: #f87171; }
@media (prefers-color-scheme: dark) {
  :root[data-theme="system"] .danger-text { color: #f87171; }
}

.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--surface); }
.segmented button { font: inherit; font-weight: 600; font-size: 0.9rem; border: 0; background: none; color: var(--muted); padding: 8px 12px; cursor: pointer; }
.segmented button.active { background: var(--ink); color: var(--bg); }

.field { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 0; }
.field > span { font-size: 0.8rem; font-weight: 600; color: var(--muted); }
.field-row { display: flex; gap: 10px; flex-wrap: wrap; }
.field-row > .field { flex: 1 1 140px; }
.card-fields > :first-child { flex: 2 1 180px; }
.card-fields > .code, .card-fields > .field:nth-child(2) { flex: 0 1 100px; }
.card-fields > .num, .card-fields > .field:nth-child(3) { flex: 0 1 120px; }

.chip {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  font-size: 0.78rem;
  color: var(--muted);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badge {
  position: absolute;
  top: 8px;
  left: 8px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  background: linear-gradient(120deg, #fde68a, #a7f3d0, #bfdbfe, #fbcfe8);
  color: #1c1917;
}

.actions { display: flex; gap: 8px; justify-content: flex-end; align-items: center; flex-wrap: wrap; margin-top: 14px; }
.actions.left { justify-content: flex-start; }
.back { display: inline-block; margin-bottom: 12px; color: var(--muted); text-decoration: none; }

/* ---------- Desktop update banner ---------- */

.update-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 8px 16px;
  background: var(--ok-soft);
  color: var(--ink);
  font-size: 0.9rem;
  border-bottom: 1px solid var(--line);
}
.update-banner[hidden] { display: none; }

/* ---------- Card grid ---------- */

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

.card-tile {
  display: flex;
  flex-direction: column;
  text-align: left;
  font: inherit;
  color: inherit;
  padding: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.card-tile:hover { transform: translateY(-2px); box-shadow: 0 6px 22px rgb(0 0 0 / 0.12); }

.card-img { position: relative; aspect-ratio: 63 / 88; background: var(--surface-2); padding: 8px; }
.card-img > img:first-child { width: 100%; height: 100%; object-fit: contain; border-radius: 6px; }
.card-noimg { height: 100%; display: grid; place-items: center; text-align: center; color: var(--muted); font-weight: 600; }
.card-inset {
  position: absolute;
  right: 6px;
  bottom: 6px;
  width: 30%;
  aspect-ratio: 63 / 88;
  object-fit: cover;
  border-radius: 4px;
  border: 2px solid var(--surface);
  box-shadow: 0 2px 6px rgb(0 0 0 / 0.25);
}

.card-info { flex: 1; display: flex; flex-direction: column; gap: 3px; padding: 10px 12px 11px; min-width: 0; }
.card-name {
  font-size: 0.97rem;
  line-height: 1.25;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: anywhere;
}
.card-set { display: flex; align-items: center; gap: 6px; font-size: 0.8rem; color: var(--muted); font-variant-numeric: tabular-nums; min-width: 0; white-space: nowrap; }
.card-set > span:last-child { overflow: hidden; text-overflow: ellipsis; }
.lang-tag { padding: 0 5px; border-radius: 4px; background: #1e293b; color: #fff; font-size: 0.66rem; font-weight: 800; letter-spacing: 0.06em; line-height: 1.5; }
.set-tag {
  padding: 0 5px;
  border-radius: 4px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  line-height: 1.5;
}
/* Pinned to the bottom so rarity, price and the footer line up across a row of tiles. */
.card-meta { margin-top: auto; padding-top: 8px; display: flex; flex-direction: column; gap: 7px; }
.card-unmatched { font-size: 0.75rem; color: var(--muted); font-style: italic; }
.card-foot {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding-top: 7px;
  border-top: 1px solid var(--line);
  font-size: 0.74rem;
  color: var(--muted);
  white-space: nowrap;
}
.card-info .chip { align-self: flex-start; }
.card-setname { font-size: 0.76rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- Packs ---------- */

.pack-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
.pack-tile {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  text-decoration: none;
  box-shadow: var(--shadow);
}
.pack-tile:hover { box-shadow: 0 6px 22px rgb(0 0 0 / 0.12); }
.pack-img { aspect-ratio: 4 / 3; background: var(--surface-2); display: grid; place-items: center; }
.pack-img img { width: 100%; height: 100%; object-fit: cover; }
.placeholder { font-size: 2.6rem; opacity: 0.6; }
.pack-info { display: flex; flex-direction: column; gap: 2px; padding: 12px; }
.pack-meta { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 6px; font-size: 0.8rem; }

.pack-hero { display: flex; gap: 20px; margin-bottom: 20px; flex-wrap: wrap; }
.pack-hero-img {
  width: 220px;
  max-width: 100%;
  aspect-ratio: 4 / 3;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface-2);
  display: grid;
  place-items: center;
  flex: none;
}
.pack-hero-img img { width: 100%; height: 100%; object-fit: cover; }
.pack-hero-info { flex: 1 1 280px; }
.eyebrow { text-transform: uppercase; letter-spacing: 0.08em; font-size: 0.75rem; font-weight: 700; color: var(--accent); }
.notes { white-space: pre-wrap; }

/* ---------- Upload ---------- */

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 26px 16px;
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  text-align: center;
  background: var(--bg);
  transition: border-color 0.15s, background 0.15s;
}
.dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.dropzone-icon { font-size: 1.8rem; color: var(--accent); line-height: 1; }
.dropzone-actions { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; justify-content: center; }

.new-packs { margin-top: 14px; }
.pack-items { display: flex; flex-direction: column; gap: 10px; }
.pack-item, .card-item {
  display: flex;
  gap: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  align-items: flex-start;
}
.pack-thumb { width: 84px; aspect-ratio: 1; border-radius: 8px; overflow: hidden; background: var(--surface-2); display: grid; place-items: center; flex: none; }
.pack-thumb img { width: 100%; height: 100%; object-fit: cover; }
.pack-thumb .placeholder { font-size: 1.8rem; }
.pack-fields { flex: 1; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.item-actions { display: flex; flex-direction: column; gap: 6px; align-items: stretch; }

.sources { display: flex; flex-direction: column; gap: 18px; margin-top: 16px; }
.source { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.source-head { display: flex; align-items: center; gap: 12px; padding: 10px 12px; background: var(--surface-2); }
.source-thumb { width: 56px; height: 56px; object-fit: cover; border-radius: 8px; }
.source-info { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.source-info strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.source-head .item-actions { flex-direction: row; }
.source-cards { display: flex; flex-direction: column; gap: 10px; padding: 12px; }

.card-item.matched { border-color: color-mix(in srgb, var(--ok) 45%, var(--line)); }
.card-item-photo { width: 110px; flex: none; }
.card-item-photo img { width: 100%; aspect-ratio: 63 / 88; object-fit: contain; }
.card-item-body { flex: 1; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.match-note { color: var(--ok); font-weight: 600; font-size: 0.88rem; }
.match-note:empty { display: none; }

.lookup-status { font-size: 0.85rem; margin: 0; }
.lookup-results { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; margin-top: 6px; }
.lookup-results:empty { display: none; }
.lookup-result {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 5px;
  font: inherit;
  text-align: left;
  color: inherit;
  background: var(--surface);
  border: 2px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
}
.lookup-result img, .lookup-noimg { width: 100%; aspect-ratio: 63 / 88; object-fit: contain; border-radius: 5px; background: var(--surface-2); }
.lookup-noimg { display: grid; place-items: center; font-size: 0.75rem; color: var(--muted); }
.lookup-result.selected { border-color: var(--ok); background: var(--ok-soft); }
.lookup-name { font-size: 0.78rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lookup-meta { font-size: 0.72rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.save-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 5;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 14px;
  padding: 12px max(16px, calc((100vw - 1200px) / 2));
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--line);
}

/* ---------- Modals ---------- */

.modal {
  border: none;
  border-radius: 18px;
  padding: 24px;
  width: min(480px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 20px 60px rgb(0 0 0 / 0.35);
}
.modal.wide { width: min(1040px, calc(100vw - 24px)); }
.modal::backdrop { background: rgb(15 10 10 / 0.55); backdrop-filter: blur(2px); }
.modal-close {
  position: absolute;
  top: 10px;
  right: 12px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: var(--surface-2);
  color: var(--ink);
  font-size: 1.3rem;
  cursor: pointer;
  z-index: 2;
}
.confirm p { margin-right: 30px; }
.check { display: flex; gap: 8px; align-items: flex-start; font-size: 0.92rem; }
.check input { width: auto; margin-top: 4px; }
.form { display: flex; flex-direction: column; gap: 12px; }

.card-detail { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 24px; }
.detail-images { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; align-content: start; }
.detail-img { margin: 0; }
.detail-img img, .detail-noimg { width: 100%; aspect-ratio: 63 / 88; object-fit: contain; border-radius: 10px; background: var(--surface-2); }
.detail-noimg { display: grid; place-items: center; padding: 12px; text-align: center; color: var(--muted); font-size: 0.85rem; }
.detail-img figcaption { text-align: center; font-size: 0.8rem; font-weight: 600; color: var(--muted); margin-top: 6px; }
.detail-info h2 { font-size: 1.5rem; margin-right: 36px; }
.details { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 12px 0 0; }
.details dt { color: var(--muted); font-size: 0.88rem; }
.details dd { margin: 0; font-weight: 500; }
.find-official { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; }

/* ---------- Crop editor ---------- */

.crop-editor h2 { margin-right: 36px; }
.crop-toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.crop-grid { display: inline-flex; align-items: center; gap: 6px; font-size: 0.9rem; color: var(--muted); }
.crop-grid input { width: 58px; padding: 6px 8px; }
.crop-stage { position: relative; width: fit-content; max-width: 100%; margin: 0 auto; user-select: none; touch-action: none; }
.crop-stage img { max-height: 62vh; width: auto; max-width: 100%; border-radius: 8px; }
.crop-layer { position: absolute; inset: 0; width: 100%; height: 100%; cursor: crosshair; overflow: visible; }
.crop-shape { fill: rgb(34 197 94 / 0.14); stroke: #22c55e; stroke-width: 3px; vector-effect: non-scaling-stroke; cursor: move; }
.crop-handle { fill: #fff; stroke: #16a34a; stroke-width: 2px; vector-effect: non-scaling-stroke; cursor: grab; }
.crop-label { fill: #052e12; font-weight: 800; paint-order: stroke; stroke: #22c55e; stroke-width: 6px; pointer-events: none; }
.crop-delete { cursor: pointer; }
.crop-delete circle { fill: rgb(0 0 0 / 0.65); }
.crop-delete text { fill: #fff; font-weight: 700; }
.crop-status { font-size: 0.88rem; }
.crop-count { margin-right: auto; font-weight: 600; }

/* ---------- Empty states & toasts ---------- */

.empty { text-align: center; padding: 56px 16px; color: var(--muted); }
.empty h2 { color: var(--ink); }
.empty .btn { margin-top: 10px; }
.empty-art { display: grid; place-items: center; margin-bottom: 14px; }
.empty-art .pokeball { --size: 64px; opacity: 0.85; }

.toasts { position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 100; pointer-events: none; width: max-content; max-width: calc(100vw - 32px); }
.toast { background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); font-weight: 500; transition: opacity 0.3s, transform 0.3s; }
.toast.success { background: var(--ok); color: #fff; }
.toast.error { background: #b91c1c; color: #fff; }
.toast.leaving { opacity: 0; transform: translateY(6px); }

/* ---------- Small screens ---------- */

@media (max-width: 720px) {
  h1 { font-size: 1.45rem; }
  .brand span:last-child { display: none; }
  .card-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
  .card-detail { grid-template-columns: 1fr; }
  .card-item, .pack-item { flex-wrap: wrap; }
  .card-item-photo { width: 84px; }
  .card-item > .item-actions, .pack-item > .item-actions { flex-direction: row; width: 100%; justify-content: flex-end; }
  .source-head { flex-wrap: wrap; }
  .modal { padding: 18px 14px; }
  .toolbar select { flex: 1 1 140px; }
}

/* ---------- Rarity, pull chance, price ---------- */

.rarity {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 1px 8px 1px 6px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 700;
  white-space: nowrap;
  border: 1px solid transparent;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}
.rarity-symbol { font-size: 0.7rem; letter-spacing: -0.05em; }
.rarity.tier-grey { background: #ececec; color: #4b4b4b; }
.rarity.tier-green { background: #dcf3e3; color: #166534; }
.rarity.tier-blue { background: #dbe8fd; color: #1e40af; }
.rarity.tier-purple { background: #ede4fd; color: #5b21b6; }
.rarity.tier-silver { background: linear-gradient(120deg, #f1f5f9, #cbd5e1, #f8fafc); color: #1e293b; border-color: #cbd5e1; }
.rarity.tier-gold { background: linear-gradient(120deg, #fef3c7, #fcd34d, #fde68a); color: #713f12; border-color: #f59e0b; }
.rarity.tier-pink { background: #fce7f3; color: #9d174d; }
:root[data-theme="dark"] .rarity.tier-grey { background: #333; color: #d4d4d4; }
:root[data-theme="dark"] .rarity.tier-green { background: #14361f; color: #86efac; }
:root[data-theme="dark"] .rarity.tier-blue { background: #172a4d; color: #93c5fd; }
:root[data-theme="dark"] .rarity.tier-purple { background: #2e1a52; color: #c4b5fd; }
:root[data-theme="dark"] .rarity.tier-pink { background: #4a1530; color: #f9a8d4; }
@media (prefers-color-scheme: dark) {
  :root[data-theme="system"] .rarity.tier-grey { background: #333; color: #d4d4d4; }
  :root[data-theme="system"] .rarity.tier-green { background: #14361f; color: #86efac; }
  :root[data-theme="system"] .rarity.tier-blue { background: #172a4d; color: #93c5fd; }
  :root[data-theme="system"] .rarity.tier-purple { background: #2e1a52; color: #c4b5fd; }
  :root[data-theme="system"] .rarity.tier-pink { background: #4a1530; color: #f9a8d4; }
}

.card-market { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 4px 6px; min-width: 0; min-height: 22px; }
.card-market .price { margin-left: auto; }
.price { font-weight: 800; font-size: 0.95rem; color: var(--ok); white-space: nowrap; font-variant-numeric: tabular-nums; }

.market {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 12px 0 4px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
}
.market .btn { align-self: flex-start; }
.market-row { display: grid; grid-template-columns: 110px 1fr; gap: 10px; align-items: baseline; }
.market-label { color: var(--muted); font-size: 0.88rem; }
.price-big { font-size: 1.25rem; color: var(--ok); }
.block { display: block; margin-top: 2px; }
.small { font-size: 0.85rem; }

.badge.owned { left: auto; right: 8px; background: var(--ok); color: #fff; }
.chip.owned { background: var(--ok-soft); color: var(--ok); font-weight: 700; }

.detail-images.single { grid-template-columns: 1fr; max-width: 340px; width: 100%; justify-self: center; }
.search-form { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.search-form .card-fields { flex: 1 1 420px; }
.search-status { margin: 10px 0 0; }
.add-to-collection { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 10px; }
.add-to-collection .btn { align-self: flex-start; }

@media (max-width: 720px) {
  .market-row { grid-template-columns: 1fr; gap: 2px; }
  .nav a { padding: 7px 9px; }
}

/* ---------- Reading cards from photos ---------- */

.variant-hint:empty { display: none; }
.variant-hint { margin: -2px 0 8px; padding: 8px 10px; border-radius: 10px; background: var(--surface-2); font-size: 0.86rem; }
.variant-suggestion { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 10px; }
.variant-reasons { margin: 4px 0 0; padding-left: 18px; color: var(--muted); font-size: 0.8rem; }
.variant-reasons:empty { display: none; }
.variant-hint p { margin: 4px 0 0; }
.read-note { font-size: 0.85rem; font-weight: 600; }
.read-note:empty { display: none; }
.read-note.busy { color: var(--muted); }
.read-note.busy::before { content: ''; display: inline-block; width: 10px; height: 10px; margin-right: 6px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin 0.8s linear infinite; vertical-align: -1px; }
.read-note.high { color: var(--ok); }
.read-note.medium { color: #b45309; }
.read-note.low { color: var(--muted); }
/* A weak photo of a card (blurry, glare, too small): suggest taking it again. */
.retake-note { margin: 0 0 8px; padding: 8px 10px; border-radius: 10px; border-left: 3px solid #b45309; background: var(--surface-2); color: #92400e; font-size: 0.86rem; font-weight: 600; }
:root[data-theme="dark"] .retake-note { color: #fbbf24; border-left-color: #fbbf24; }
@media (prefers-color-scheme: dark) { :root[data-theme="system"] .retake-note { color: #fbbf24; border-left-color: #fbbf24; } }
:root[data-theme="dark"] .read-note.medium { color: #fbbf24; }
@media (prefers-color-scheme: dark) {
  :root[data-theme="system"] .read-note.medium { color: #fbbf24; }
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- eBay sold prices ---------- */

.ebay {
  grid-column: 1 / -1;
  border-top: 1px solid var(--line);
  padding-top: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}
.ebay h3 { margin: 0; font-size: 1.15rem; }
.ebay-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.ebay-head h3 { margin-right: auto; }
.ebay-head select { width: auto; }
.ebay-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.stat { display: flex; flex-direction: column; gap: 2px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); min-width: 0; }
.stat-label { font-size: 0.78rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.stat-big { font-size: 1.5rem; color: var(--ok); }
.trend-word.up { color: #16a34a; }
.trend-word.down { color: #dc2626; }
.trend-word.flat { color: #ca8a04; }
.chart-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.legend { display: flex; gap: 12px; font-size: 0.82rem; font-weight: 700; }
.key.up { color: #16a34a; }
.key.down { color: #dc2626; }
.key.flat { color: #ca8a04; }
.trend-chart { width: 100%; height: auto; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; }
.trend-chart .grid { stroke: var(--line); stroke-width: 1; }
.trend-chart .axis { fill: var(--muted); font-size: 11px; }
.trend-chart .trend-segment { stroke-width: 3.5; stroke-linecap: round; }
.trend-chart .trend-point { stroke: var(--surface); stroke-width: 2; }
.ebay-listings { overflow-x: auto; }
.ebay-listings table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.ebay-listings th { text-align: left; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); padding: 6px 8px; border-bottom: 1px solid var(--line); }
.ebay-listings td { padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.ebay-listings td a { color: var(--ink); }
.ebay-listings .num { text-align: right; font-weight: 700; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.chip.grade { background: #ede4fd; color: #5b21b6; font-weight: 700; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.paste-help { border: 1px dashed var(--line); border-radius: 12px; padding: 10px 14px; background: var(--bg); }
.paste-help summary { cursor: pointer; font-weight: 700; }
.paste-help ol { margin: 8px 0; padding-left: 20px; }
.paste-box {
  min-height: 64px;
  max-height: 120px;
  overflow: hidden;
  border: 2px dashed var(--accent);
  border-radius: 10px;
  padding: 12px;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.9rem;
}
.paste-box:empty::before { content: attr(data-placeholder); }
.paste-box:focus { outline: 2px solid var(--focus); }

/* ---------- Price history & graded sales ---------- */

.price-history {
  grid-column: 1 / -1;
  border-top: 1px solid var(--line);
  padding-top: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}
.price-history h3 { margin: 0; font-size: 1.15rem; }
.price-history .chart-head select { width: auto; max-width: 100%; }
.history-block { display: flex; flex-direction: column; gap: 10px; }
.tracker { display: flex; flex-direction: column; gap: 10px; }
.tracker-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.population { margin: 0; }
.tracker-setup { border: 1px dashed var(--line); border-radius: 12px; padding: 10px 14px; background: var(--bg); }
.tracker-setup summary { cursor: pointer; font-weight: 700; }
.tracker-setup ol { margin: 8px 0 0; padding-left: 20px; }
.tracker-setup code { font-size: 0.85em; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }

/* ---------- Profiles and signing in ---------- */

body.signed-out .nav, body.signed-out .account { display: none; }
.auth-page { min-height: calc(100vh - 200px); display: grid; place-items: center; }
.auth-card { width: min(420px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 28px; box-shadow: var(--shadow); }
.auth-switch { margin: 14px 0 0; text-align: center; color: var(--muted); font-size: 0.92rem; }
.auth-switch .link { background: none; border: 0; padding: 0; color: var(--accent, #2563eb); font: inherit; font-weight: 600; cursor: pointer; text-decoration: underline; }
.auth-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; font-weight: 800; color: var(--accent); }
.auth-card .form { display: flex; flex-direction: column; gap: 12px; margin-top: 10px; }
.btn.block { width: 100%; }
.form-error { color: #b91c1c; font-weight: 600; font-size: 0.9rem; margin: 0; }
.form-error:empty { display: none; }
.account { position: relative; flex: none; }
.account-button { display: flex; align-items: center; gap: 8px; font: inherit; font-weight: 600; color: #fff; background: rgb(255 255 255 / 0.12); border: 0; border-radius: 999px; padding: 4px 12px 4px 4px; cursor: pointer; }
.account-button:hover { background: rgb(255 255 255 / 0.22); }
.avatar { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: #fff; color: var(--accent); font-weight: 800; }
.account-menu { position: absolute; right: 0; top: calc(100% + 8px); min-width: 200px; display: flex; flex-direction: column; padding: 6px; background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); z-index: 20; }
.account-menu a, .account-menu button { font: inherit; text-align: left; padding: 8px 10px; border-radius: 8px; border: 0; background: none; color: inherit; text-decoration: none; cursor: pointer; }
.account-menu a:hover, .account-menu button:hover { background: var(--surface-2); }
.inline-form { margin-top: 16px; display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.inline-form .field-row { width: 100%; }
.form { display: flex; flex-direction: column; gap: 12px; align-items: stretch; }
.form > .btn:not(.block) { align-self: flex-start; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 0.9rem; cursor: pointer; white-space: nowrap; }
/* A sentence-long setting in a panel (Profile) wraps instead of running off a phone screen. */
section.panel > .check { white-space: normal; align-items: flex-start; }
section.panel > .check input { margin-top: 3px; }
.check input { width: auto; margin: 0; accent-color: var(--accent); }
@media (max-width: 720px) { .account-name { display: none; } .account-button { padding: 4px; } }

/* ---------- Tables ---------- */

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.simple-table, .collection-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.simple-table th, .collection-table th { text-align: left; font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); background: var(--surface-2); white-space: nowrap; }
.simple-table td, .collection-table td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.simple-table tr:last-child td, .collection-table tr:last-child td { border-bottom: 0; }
.simple-table .num, .collection-table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.collection-table tbody tr { cursor: pointer; }
.collection-table tbody tr:hover, .simple-table tbody tr[class]:not(.current):hover { background: var(--surface-2); }
.collection-table tr.selected, .simple-table tr.current { background: var(--accent-soft); }
.collection-table td.num:last-child { font-weight: 800; color: var(--ok); }
.name-cell { display: flex; align-items: center; gap: 10px; font-weight: 600; min-width: 180px; }
.table-thumb { width: 30px; aspect-ratio: 63 / 88; object-fit: contain; border-radius: 3px; background: var(--surface-2); flex: none; }
.sort-button { font: inherit; text-transform: inherit; letter-spacing: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; font-weight: 700; }
.sort-button.active { color: var(--ink); }

/* ---------- Gallery: views, density, badges, selection ---------- */

.view-bar { justify-content: space-between; }
.view-bar .result-count { margin: 0; }
.view-controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.btn.active, .chip-button.active { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.chip-button { font: inherit; font-size: 0.85rem; font-weight: 600; padding: 5px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer; }
.chip-button:hover { background: var(--surface-2); }

.card-grid.density-compact { grid-template-columns: repeat(auto-fill, minmax(128px, 1fr)); gap: 10px; }
.card-grid.density-comfortable { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 16px; }
.card-grid.density-large { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 20px; }
.density-compact .card-img { padding: 5px; }
.density-compact .card-info { padding: 7px 8px 8px; }
.density-compact .card-name { font-size: 0.86rem; }
.density-large .card-name { font-size: 1.05rem; }
.card-tile.compact .card-info { gap: 2px; }
.card-tile.compact .card-meta { padding-top: 4px; }
.card-tile.compact .rarity { font-size: 0.68rem; }

.badge.qty { left: auto; right: 8px; background: var(--ink); color: var(--bg); font-variant-numeric: tabular-nums; }
.card-img .badge.variant ~ .badge.qty, .card-img .badge.qty { top: 8px; }
.card-chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip.status { background: #fef3c7; color: #92400e; font-weight: 700; }
:root[data-theme="dark"] .chip.status { background: #3b2a0a; color: #fcd34d; }
:root[data-theme="dark"] .chip.grade { background: #2e1a52; color: #c4b5fd; }
@media (prefers-color-scheme: dark) {
  :root[data-theme="system"] .chip.status { background: #3b2a0a; color: #fcd34d; }
  :root[data-theme="system"] .chip.grade { background: #2e1a52; color: #c4b5fd; }
}
.card-tile .tick { position: absolute; left: 8px; bottom: 8px; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; background: var(--surface); border: 2px solid var(--line); font-weight: 800; color: #fff; }
.card-tile.selected { outline: 3px solid var(--accent); outline-offset: -1px; }
.card-tile.selected .tick { background: var(--accent); border-color: var(--accent); }

.filter-panel { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin-bottom: 14px; display: flex; flex-direction: column; gap: 10px; }
.filter-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 8px; }
.filter-grid .range { display: flex; align-items: center; gap: 6px; grid-column: span 1; }
.filter-checks { display: flex; flex-wrap: wrap; gap: 8px 18px; align-items: center; }
.filter-checks .btn { margin-left: auto; }

.bulk-bar { position: sticky; top: 64px; z-index: 5; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 10px 12px; margin-bottom: 14px; background: var(--surface); border: 2px solid var(--accent); border-radius: 12px; box-shadow: var(--shadow); }
.bulk-bar select { width: auto; padding: 5px 8px; font-size: 0.85rem; }
.bulk-bar strong { margin-right: 6px; }
.load-more { display: flex; justify-content: center; padding: 18px 0; }
.toast.info { background: var(--ink); color: var(--bg); }
.toast-action { pointer-events: auto; margin-left: 10px; font: inherit; font-weight: 800; background: none; border: 1.5px solid currentColor; color: inherit; border-radius: 8px; padding: 2px 10px; cursor: pointer; }
.toasts > .toast:has(.toast-action) { pointer-events: auto; }

/* ---------- Card page: inventory ---------- */

.inventory { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px 12px; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.inventory legend { font-size: 0.8rem; font-weight: 700; color: var(--muted); padding: 0 6px; }
.copies { margin-top: 16px; display: flex; flex-direction: column; gap: 8px; }
.copies h3 { margin: 0; }

/* ---------- Adding cards: recognition ---------- */

.read-status { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 0.76rem; font-weight: 700; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.read-status:empty { display: none; }
.read-status.recognized, .read-status.confirmed { background: var(--ok-soft); color: var(--ok); }
.read-status.review { background: #fef3c7; color: #92400e; }
.read-status.unrecognized { background: var(--accent-soft); color: var(--accent); }
.read-status.reading::before { content: ''; display: inline-block; width: 8px; height: 8px; margin-right: 5px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin 0.8s linear infinite; vertical-align: -1px; }
:root[data-theme="dark"] .read-status.review { background: #3b2a0a; color: #fcd34d; }
@media (prefers-color-scheme: dark) { :root[data-theme="system"] .read-status.review { background: #3b2a0a; color: #fcd34d; } }
.card-item.status-review { border-color: #f59e0b; }
.card-item.status-unrecognized { border-color: var(--accent); }
.card-item.duplicate { box-shadow: 0 0 0 3px #f59e0b; }
.item-actions { align-items: center; }
.read-progress { display: flex; align-items: center; gap: 12px; margin: 12px 0; font-weight: 600; font-size: 0.9rem; }
.read-progress progress { flex: 1; height: 8px; accent-color: var(--accent); }
.batch-summary { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; margin: 12px 0; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); }
.batch-summary .actions { margin: 0; }
.summary-counts { display: flex; flex-wrap: wrap; gap: 6px; }
.sources.review-only .card-item:not(.status-review):not(.status-unrecognized) { display: none; }
.sources.review-only .source:not(:has(.status-review, .status-unrecognized)) { display: none; }
.duplicate-check h2 { margin-bottom: 10px; }
.duplicate-list { list-style: none; margin: 0 0 12px; padding: 0; display: flex; flex-direction: column; gap: 8px; max-height: 50vh; overflow-y: auto; }
.duplicate-list li { display: flex; align-items: center; gap: 10px; }
.duplicate-list img { width: 40px; aspect-ratio: 63 / 88; object-fit: contain; border-radius: 4px; background: var(--surface-2); flex: none; }

/* ---------- Sets ---------- */

.progress { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.progress > span { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), #f59e0b); border-radius: inherit; }
.set-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; margin-bottom: 18px; }
.set-tile { display: flex; flex-direction: column; gap: 8px; padding: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); text-decoration: none; transition: transform 0.12s ease; }
a.set-tile[href]:hover { transform: translateY(-2px); }
.set-tile-head { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.set-tile-foot { display: flex; justify-content: space-between; font-size: 0.88rem; font-variant-numeric: tabular-nums; }
.set-metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin-bottom: 12px; }
.metric { display: flex; flex-direction: column; gap: 2px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); }
.metric-label { font-size: 0.74rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.metric-value { font-size: 1.35rem; font-variant-numeric: tabular-nums; }
.check-tile.missing .card-img img { filter: grayscale(1); opacity: 0.38; }
.check-tile.missing .card-info { opacity: 0.65; }
.badge.missing-badge { background: var(--surface); color: var(--muted); border: 1px solid var(--line); }

/* Phones: the nav gets its own scrollable row under the logo and the profile button. */
@media (max-width: 720px) {
  .topbar { flex-wrap: wrap; row-gap: 6px; }
  .topbar .nav { order: 3; width: 100%; overflow-x: auto; scrollbar-width: none; }
  .topbar .nav a { white-space: nowrap; }
  .view-controls .segmented button { padding: 7px 9px; }
}

/* ---------- Scanner tests (owner) ---------- */
.scan-tests { display: grid; gap: 10px; }
.scan-test { display: grid; grid-template-columns: 96px 1fr auto; gap: 12px; align-items: center; }
.scan-test img { width: 96px; height: 72px; object-fit: cover; border-radius: 8px; background: var(--surface-2); }
.scan-test-cards { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); margin-bottom: 12px; }
.scan-test-card { display: grid; grid-template-columns: 72px 1fr; gap: 10px; align-items: start; }
.scan-test-card img { width: 72px; border-radius: 6px; }

/* ---------- Card dioramas (card page) ---------- */
.diorama-section { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin: 12px 0; }
.diorama-section > strong { width: 100%; }
.diorama-thumb { width: 160px; max-width: 45%; border-radius: 10px; background: var(--surface-2); }

.printing-fields { flex-wrap: wrap; }
.printing-fields .field { min-width: 130px; }
.stamp-options { padding: 9px 12px; border: 1px solid var(--line); border-radius: 8px; }
.stamp-choice { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.stamp-choice input[type=checkbox] { width: auto; }

.card-printing { display: block; color: var(--muted); font-size: .75rem; margin-top: 4px; overflow-wrap: anywhere; }
