:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --border: #e3e6ec;
  --text: #16181d;
  --muted: #6b7280;
  --accent: #4f6df5;
  --accent-ink: #ffffff;
  --chip: #eef1f7;
  --danger: #d33c3c;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 8px 24px rgba(0,0,0,.06);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101216;
    --panel: #181b21;
    --border: #262a33;
    --text: #e8eaf0;
    --muted: #9aa1ad;
    --accent: #7b91ff;
    --accent-ink: #0f1220;
    --chip: #222732;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); text-decoration: none; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

/* ---- shell: a centered, side-padded column ---- */
.app { max-width: 1240px; margin: 0 auto; padding: 0 24px 48px; }
.topbar { display: flex; align-items: baseline; justify-content: space-between; padding: 18px 0 14px; }
.brand { font-weight: 700; font-size: 18px; color: var(--text); letter-spacing: -.01em; }
.topnav a { margin-left: 16px; color: var(--muted); }
.topnav a:hover { color: var(--accent); }

.layout { display: grid; grid-template-columns: 280px minmax(0, 1fr); gap: 20px; align-items: start; }
@media (max-width: 760px) {
  .app { padding: 0 14px 32px; }
  .layout { grid-template-columns: 1fr; }
  .panel { position: static !important; max-height: none !important; }
}

/* ---- left panel ---- */
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); position: sticky; top: 12px; max-height: calc(100vh - 24px); display: flex; flex-direction: column; overflow: hidden; }
.game-switch { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; padding: 10px; border-bottom: 1px solid var(--border); }
.game-switch button { padding: 8px 6px; border-radius: 8px; border: 1px solid var(--border); background: transparent; color: var(--muted); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.game-switch button.active { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.game-switch button:hover:not(.active) { color: var(--text); border-color: var(--muted); }
.set-search { margin: 10px; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); width: calc(100% - 20px); }
.set-search:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.set-list { list-style: none; margin: 0; padding: 0 6px 6px; overflow-y: auto; }
.set-list li { display: flex; align-items: center; gap: 10px; padding: 7px 8px; border-radius: 8px; cursor: pointer; }
.set-list li:hover { background: var(--chip); }
.set-list li.active { background: var(--accent); color: var(--accent-ink); }
.set-list li.active .sub { color: inherit; opacity: .8; }
.set-list .icon { width: 34px; height: 34px; object-fit: contain; flex: none; }
.set-list .icon.blank { display: inline-flex; align-items: center; justify-content: center; border-radius: 8px; background: var(--chip); color: var(--muted); font-size: 11px; font-weight: 700; }
.set-list li.active .icon.blank { background: rgba(255,255,255,.25); color: inherit; }
.set-list .name { font-weight: 600; line-height: 1.25; }
.set-list .sub { font-size: 12px; color: var(--muted); }
.panel-note { padding: 14px 12px; color: var(--muted); font-size: 13px; }

/* ---- content ---- */
.content { min-width: 0; }
.empty { padding: 48px 20px; text-align: center; color: var(--muted); border: 1px dashed var(--border); border-radius: var(--radius); }
.empty h2 { margin: 0 0 6px; color: var(--text); font-size: 18px; }
.set-head { display: flex; align-items: center; gap: 14px; margin: 0 0 12px; }
.set-head img { width: 52px; height: 52px; object-fit: contain; }
.set-head h1 { margin: 0; font-size: 22px; letter-spacing: -.01em; }
.set-head .meta { color: var(--muted); font-size: 13px; }
.set-head .meta a { color: var(--muted); text-decoration: underline; }

/* ---- filters ---- */
.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px; margin-bottom: 14px; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); }
.stmt { display: inline-flex; align-items: center; gap: 6px; padding: 4px 6px 4px 10px; background: var(--chip); border-radius: 999px; border: 1px solid transparent; }
.stmt.invalid { border-color: var(--danger); }
.stmt .label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; font-weight: 700; }
.stmt input { width: 80px; padding: 4px 8px; border-radius: 6px; border: 1px solid var(--border); background: var(--panel); }
.stmt input.wide { width: 170px; }
.stmt input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.stmt .sep { color: var(--muted); }
.stmt .remove { border: 0; background: transparent; color: var(--muted); padding: 2px 6px; border-radius: 999px; font-size: 15px; line-height: 1; }
.stmt .remove:hover { color: var(--danger); background: var(--panel); }
.op { border: 1px solid var(--border); background: var(--panel); color: var(--accent); font-weight: 700; font-size: 12px; padding: 4px 10px; border-radius: 6px; letter-spacing: .06em; }
.op.or { color: #c2410c; }
.add-filter { display: inline-flex; align-items: center; gap: 6px; position: relative; }
.add-filter select { padding: 5px 10px; border-radius: 6px; border: 1px dashed var(--border); background: transparent; color: var(--muted); }
.filters .count { margin-left: auto; color: var(--muted); font-size: 13px; }

/* ---- card grid ---- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; cursor: pointer; text-align: left; padding: 0; display: flex; flex-direction: column; transition: transform .12s ease, box-shadow .12s ease; }
.card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.card .art { aspect-ratio: 717 / 1000; background: var(--chip); display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 12px; }
.card .art img { width: 100%; height: 100%; object-fit: contain; display: block; }
.card .art .noart { color: var(--muted); font-size: 12px; }
.card .body { padding: 8px 10px 10px; display: grid; gap: 2px; }
.card .title { font-weight: 600; line-height: 1.25; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.card .line { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--muted); }
.card .price { font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; }
.card .variants { font-size: 11px; color: var(--accent); }
.grid-empty { grid-column: 1 / -1; }

/* ---- modal ---- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 10; }
.dialog { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; max-width: 980px; width: 100%; max-height: calc(100vh - 40px); overflow: auto; box-shadow: var(--shadow); }
.dialog header { display: flex; align-items: baseline; gap: 12px; padding: 16px 20px 10px; position: sticky; top: 0; background: var(--panel); border-bottom: 1px solid var(--border); }
.dialog header h2 { margin: 0; font-size: 20px; }
.dialog header .muted { color: var(--muted); }
.dialog header .close { margin-left: auto; border: 0; background: var(--chip); border-radius: 999px; width: 32px; height: 32px; font-size: 18px; line-height: 1; }
.variant { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 18px; padding: 18px 20px; border-bottom: 1px solid var(--border); }
.variant:last-child { border-bottom: 0; }
@media (max-width: 640px) { .variant { grid-template-columns: 1fr; } }
.variant img { width: 100%; border-radius: 8px; background: var(--chip); aspect-ratio: 717 / 1000; object-fit: contain; }
.variant .noart { aspect-ratio: 717 / 1000; border-radius: 8px; background: var(--chip); display: flex; align-items: center; justify-content: center; color: var(--muted); }
.variant h3 { margin: 0 0 4px; font-size: 16px; }
.variant .sub { color: var(--muted); font-size: 13px; margin-bottom: 10px; }
.prices { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.prices th, .prices td { text-align: right; padding: 6px 8px; border-bottom: 1px solid var(--border); font-size: 13px; }
.prices th:first-child, .prices td:first-child { text-align: left; }
.prices th { color: var(--muted); font-weight: 600; font-size: 12px; }
.prices td.market { font-weight: 700; }
.prices tr.best td { color: var(--accent); }
.variant .links { margin-top: 10px; font-size: 13px; }
.variant .links a { margin-right: 14px; }
