:root {
  --bg: #f4f5f9;
  --panel: #ffffff;
  --text: #1c1f2a;
  --muted: #6b7083;
  --line: #e2e4ec;
  --accent: #d93a2b;
  --accent-ink: #ffffff;
  --accent-soft: #fdecea;
  --good: #1f8a4c;
  --t-common: #8a8f9c;
  --t-uncommon: #3f8f5a;
  --t-reverse: #1b9aaa;
  --t-holo: #3a6fd8;
  --t-ex: #8a4fd6;
  --t-ir: #d9822b;
  --t-sir: #d63a7a;
  --t-chase: #c99a06;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121419;
    --panel: #1c1f27;
    --text: #e9eaf0;
    --muted: #9a9fb2;
    --line: #2d3140;
    --accent: #ff6b5b;
    --accent-ink: #1a0b09;
    --accent-soft: #3a2220;
    --good: #4fd08a;
    --t-common: #9aa0ad;
    --t-uncommon: #5cc27e;
    --t-reverse: #3cc4d4;
    --t-holo: #6b9bff;
    --t-ex: #b388ff;
    --t-ir: #ffa552;
    --t-sir: #ff6ba6;
    --t-chase: #ffd43b;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: env(safe-area-inset-bottom);
}
a { color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.sr { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; pointer-events: none; }
.fatal { background: var(--accent-soft); color: var(--accent); padding: 12px 16px; margin: 0; }

.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.top h1 { margin: 0; font-size: 19px; }
nav { display: flex; gap: 4px; align-items: center; }
.tab { border: 0; background: none; padding: 7px 11px; border-radius: 999px; font: inherit; color: var(--muted); cursor: pointer; }
.tab.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.icon { border: 0; background: none; font-size: 18px; padding: 6px 8px; cursor: pointer; color: var(--text); }

main { max-width: 720px; margin: 0 auto; padding: 12px 16px 40px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 600; color: var(--text); background: var(--panel);
  border: 1px solid var(--line); border-radius: 12px; padding: 11px 14px; cursor: pointer;
  position: relative; user-select: none; -webkit-user-select: none;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--accent); }
.btn.big { font-size: 17px; padding: 16px; }
.btn:active { transform: scale(0.98); }

.summary {
  position: sticky; top: calc(54px + env(safe-area-inset-top)); z-index: 4;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.05);
}
.sum-main { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.total { font-size: 30px; font-weight: 750; color: var(--good); font-variant-numeric: tabular-nums; line-height: 1.1; }
.best { text-align: right; font-size: 13px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip {
  font-size: 12px; padding: 3px 9px; border-radius: 999px; border: 1px solid currentColor;
  font-variant-numeric: tabular-nums;
}

.setpick { display: flex; align-items: center; gap: 8px; margin: 14px 0 10px; color: var(--muted); font-weight: 600; }
select, input[type="search"], input[type="number"] {
  font: inherit; color: var(--text); background: var(--panel);
  border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; min-width: 0;
}
.setpick select { flex: 1; }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.snap { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; }
.hint { color: var(--muted); font-size: 13px; margin: 8px 2px 14px; }

.entries { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.entry {
  display: grid; grid-template-columns: 52px 1fr auto; gap: 10px; align-items: start;
  background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--line);
  border-radius: 12px; padding: 8px;
}
.empty { color: var(--muted); text-align: center; padding: 28px 8px; list-style: none; }
.thumb img { width: 52px; aspect-ratio: 63 / 88; object-fit: cover; border-radius: 5px; background: var(--bg); display: block; }
.body { min-width: 0; }
.n { font-weight: 650; }
.n a { text-decoration: none; }
.body .muted { font-size: 12px; overflow-wrap: anywhere; }
.side { text-align: right; display: flex; flex-direction: column; gap: 6px; align-items: flex-end; }
.price { font-weight: 700; font-variant-numeric: tabular-nums; }
.row-actions { display: flex; gap: 4px; }
.row-actions button {
  font: inherit; font-size: 12px; border: 1px solid var(--line); background: var(--bg); color: var(--text);
  border-radius: 8px; padding: 4px 8px; cursor: pointer;
}
.variants { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.variants.col { flex-direction: column; }
.vchip {
  font: inherit; font-size: 12px; padding: 3px 9px; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--line); background: var(--bg); color: var(--muted);
}
.vchip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.badge {
  display: inline-block; font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 999px;
  color: #fff; background: var(--muted); vertical-align: 1px; margin-left: 4px;
}
.badge.check { background: none; color: var(--t-ir); border: 1px solid currentColor; }
.bar { height: 4px; border-radius: 2px; margin-top: 8px; background: linear-gradient(90deg, var(--line) 0%, var(--accent) 50%, var(--line) 100%); background-size: 200% 100%; animation: slide 1.1s linear infinite; }
@keyframes slide { from { background-position: 100% 0; } to { background-position: -100% 0; } }

/* tier colours */
.tier-common { --tc: var(--t-common); } .tier-uncommon { --tc: var(--t-uncommon); }
.tier-reverse { --tc: var(--t-reverse); } .tier-holo { --tc: var(--t-holo); }
.tier-ex { --tc: var(--t-ex); } .tier-ir { --tc: var(--t-ir); }
.tier-sir { --tc: var(--t-sir); } .tier-chase { --tc: var(--t-chase); }
.chip[class*="tier-"] { color: var(--tc); }
.badge[class*="tier-"] { background: var(--tc); }
.badge.tier-chase { color: #2a2000; }
.entry.t-common { border-left-color: var(--t-common); } .entry.t-uncommon { border-left-color: var(--t-uncommon); }
.entry.t-reverse { border-left-color: var(--t-reverse); } .entry.t-holo { border-left-color: var(--t-holo); }
.entry.t-ex { border-left-color: var(--t-ex); } .entry.t-ir { border-left-color: var(--t-ir); }
.entry.t-sir { border-left-color: var(--t-sir); }
.entry.t-chase { border-left-color: var(--t-chase); box-shadow: 0 0 0 1px var(--t-chase) inset; }

.pack-actions { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-top: 16px; }

/* history */
.lifetime { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 14px; margin-bottom: 12px; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; text-align: center; }
@media (max-width: 480px) { .stats { grid-template-columns: repeat(2, 1fr); } }
.big { font-size: 20px; font-weight: 750; font-variant-numeric: tabular-nums; }
.pack { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin-bottom: 8px; }
.pack summary { display: flex; justify-content: space-between; gap: 10px; align-items: center; cursor: pointer; list-style: none; }
.pack summary::-webkit-details-marker { display: none; }
.total-sm { font-weight: 750; color: var(--good); font-variant-numeric: tabular-nums; }
.mini { list-style: none; padding: 0; margin: 10px 0; }
.mini li { display: flex; gap: 6px; align-items: baseline; padding: 4px 0; border-top: 1px solid var(--line); font-size: 13px; }
.mini .badge { margin: 0; flex: none; }
.mini .nm { flex: 1; min-width: 0; }
.mini .r { font-variant-numeric: tabular-nums; }
.row { display: flex; gap: 8px; }
.backup { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; }

/* dialogs */
dialog {
  border: 1px solid var(--line); border-radius: 16px; background: var(--bg); color: var(--text);
  width: min(720px, calc(100vw - 16px)); max-height: calc(100dvh - 32px); padding: 14px;
}
dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
.dlg-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
#q { width: 100%; }
.inline { display: flex; gap: 6px; align-items: center; color: var(--muted); font-size: 13px; margin-top: 8px; }
.field { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin: 10px 0; }
.field input { width: 90px; }
.results { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px; display: flex; flex-direction: column; gap: 5px; }
.card.top { border-color: var(--accent); }
.card img { width: 100%; aspect-ratio: 63 / 88; object-fit: contain; border-radius: 6px; background: var(--bg); }
.card .name { font-weight: 650; font-size: 14px; }
.variant {
  display: flex; justify-content: space-between; gap: 6px; cursor: pointer; font: inherit; font-size: 13px;
  padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--text);
}
.variant:hover { border-color: var(--accent); background: var(--accent-soft); }
.variant .p { font-weight: 650; color: var(--good); }

.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-weight: 600;
  z-index: 20; max-width: calc(100vw - 32px);
}
