:root {
  --bg: #0f1117;
  --bg2: #161922;
  --panel: #1b1f2a;
  --panel2: #222736;
  --line: #2c3243;
  --text: #e8e9ee;
  --muted: #9198ab;
  --gold: #d4a94a;
  --gold2: #f0cf7e;
  --accent: #7c8cff;
  --good: #3fbf7f;
  --bad: #e5606a;
  --radius: 12px;
  --shadow: 0 10px 40px rgba(0, 0, 0, .45);
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 14px/1.5 Inter, system-ui, -apple-system, Segoe UI, sans-serif; min-height: 100vh; }
a { color: var(--gold2); text-decoration: none; }
a:hover { text-decoration: underline; }
img { display: block; }
h1, h2, h3 { margin: 0; font-weight: 700; }
h1 { font-size: 26px; letter-spacing: -.01em; }
h2 { font-size: 18px; }
.muted { color: var(--muted); }
.boot, .loading { padding: 80px 20px; text-align: center; color: var(--muted); }
.loading::before {
  content: ''; display: block; width: 28px; height: 28px; margin: 0 auto 14px;
  border: 3px solid var(--line); border-top-color: var(--gold); border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- controls ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  padding: 9px 14px; border-radius: 9px; border: 1px solid var(--line);
  background: var(--panel2); color: var(--text); font: inherit; font-weight: 600; cursor: pointer;
  transition: background .15s, border-color .15s, transform .05s; white-space: nowrap;
}
.btn:hover { background: #2a3042; border-color: #3a4258; text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: linear-gradient(180deg, var(--gold2), var(--gold)); color: #1a1408; border-color: transparent; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--bad); }
.btn.danger:hover { background: rgba(229, 96, 106, .12); border-color: var(--bad); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 6px 10px; font-size: 13px; }
.btn.block { width: 100%; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--bg2); border: 1px solid var(--line);
  border-radius: 9px; padding: 9px 11px; outline: none; min-width: 0;
}
input:focus, select:focus, textarea:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(212, 169, 74, .18); }
label { display: grid; gap: 6px; font-weight: 500; color: var(--muted); font-size: 13px; }
label.check, label.radio { display: inline-flex; align-items: center; gap: 8px; color: var(--text); font-size: 14px; cursor: pointer; }
label.check input, label.radio input { width: 16px; height: 16px; accent-color: var(--gold); }
.err { color: var(--bad); min-height: 20px; font-size: 13px; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 24px;
  padding: 12px 24px; background: rgba(15, 17, 23, .85); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { font-family: Cinzel, serif; font-size: 20px; font-weight: 700; color: var(--gold2); display: flex; align-items: center; gap: 8px; letter-spacing: .02em; }
.brand:hover { text-decoration: none; }
.brand svg { width: 22px; height: 22px; }
.topbar nav { display: flex; gap: 4px; }
.topbar nav a { padding: 7px 12px; border-radius: 8px; color: var(--muted); font-weight: 600; }
.topbar nav a:hover { color: var(--text); background: var(--panel); text-decoration: none; }
.topbar nav a.active { color: var(--text); background: var(--panel2); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.market { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.market select { padding: 6px 10px; }
.user-chip { color: var(--muted); font-weight: 600; }
main { max-width: 1500px; margin: 0 auto; padding: 24px; }

/* ---------- page header / toolbar ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.stats { display: flex; gap: 10px; flex-wrap: wrap; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px 14px; min-width: 96px; }
.stat b { display: block; font-size: 18px; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }
.stat.gold b { color: var(--gold2); }
.toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 18px;
  padding: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
}
.toolbar input[type=search] { flex: 1 1 240px; }
.chips { display: flex; gap: 4px; }
.chip {
  width: 32px; height: 32px; border-radius: 50%; border: 2px solid transparent; background: var(--bg2);
  display: grid; place-items: center; cursor: pointer; padding: 0; opacity: .45; transition: opacity .15s, border-color .15s;
}
.chip img { width: 22px; height: 22px; }
.chip.on { opacity: 1; border-color: var(--gold); }
.chip:hover { opacity: .85; }
.chip .multi { width: 22px; height: 22px; border-radius: 50%; background: conic-gradient(#f8f6d8, #c1d7e9, #bab1ab, #e49977, #a3c095, #f8f6d8); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.seg button { background: var(--bg2); color: var(--muted); border: 0; padding: 8px 12px; font: inherit; font-weight: 600; cursor: pointer; }
.seg button.on { background: var(--panel2); color: var(--text); }
.spacer { flex: 1; }

/* ---------- card grid ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 18px 14px; }
.tile { cursor: pointer; position: relative; }
.tile .img-wrap { transition: transform .15s ease, box-shadow .15s; }
.tile:hover .img-wrap { transform: translateY(-4px) scale(1.02); box-shadow: 0 14px 30px rgba(0, 0, 0, .55); }
.img-wrap { position: relative; border-radius: 4.75% / 3.4%; overflow: hidden; background: var(--panel2); aspect-ratio: 488 / 680; }
.img-wrap img { width: 100%; height: 100%; object-fit: cover; }
.img-wrap .ph { position: absolute; inset: 0; display: grid; place-items: center; padding: 10px; text-align: center; color: var(--muted); font-weight: 600; }
.foil::after {
  content: ''; position: absolute; inset: 0; pointer-events: none; mix-blend-mode: color-dodge; opacity: .55;
  background: linear-gradient(115deg, transparent 20%, rgba(255, 0, 170, .35) 32%, rgba(255, 230, 0, .3) 42%,
    rgba(0, 255, 200, .35) 52%, rgba(80, 120, 255, .35) 62%, transparent 75%);
  background-size: 250% 250%; animation: shimmer 6s ease-in-out infinite;
}
@keyframes shimmer { 0%, 100% { background-position: 0% 0%; } 50% { background-position: 100% 100%; } }
.tile-meta { display: flex; justify-content: space-between; align-items: center; margin-top: 7px; font-size: 13px; padding: 0 2px; }
.tile-meta .price { color: var(--gold2); font-weight: 600; font-variant-numeric: tabular-nums; }
.badge {
  position: absolute; top: 8px; right: 8px; z-index: 2; background: rgba(10, 12, 18, .85); color: #fff;
  font-weight: 700; font-size: 12px; padding: 2px 8px; border-radius: 99px; border: 1px solid rgba(255, 255, 255, .15);
}
.badge.left { left: 8px; right: auto; }
.badge.foilb { background: linear-gradient(90deg, #ff4fc3, #ffd84f, #4fffd6, #6b8cff); color: #111; border: 0; }
.badge.missing { background: var(--bad); border: 0; }
.tag { display: inline-block; font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 99px; background: var(--panel2); color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.tag.foil-tag { background: linear-gradient(90deg, #ff4fc3, #ffd84f, #4fffd6, #6b8cff); color: #111; }
.sentinel { height: 1px; }
.empty { text-align: center; padding: 70px 20px; background: var(--panel); border: 1px dashed var(--line); border-radius: var(--radius); }
.empty h2 { margin-bottom: 8px; }
.empty p { color: var(--muted); margin: 0 0 18px; }

/* ---------- list/table ---------- */
table.list { width: 100%; border-collapse: collapse; background: var(--panel); border-radius: var(--radius); overflow: hidden; }
table.list th, table.list td { padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--line); }
table.list th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; background: var(--bg2); font-weight: 600; }
table.list tr.row { cursor: pointer; }
table.list tr.row:hover td { background: var(--panel2); }
table.list td.num, table.list th.num { text-align: right; font-variant-numeric: tabular-nums; }
.ms { display: inline-block; width: 15px; height: 15px; vertical-align: -2px; margin: 0 1px; }
.cost { white-space: nowrap; }

/* ---------- decks ---------- */
.deck-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.deck-card {
  position: relative; display: block; border-radius: var(--radius); overflow: hidden; min-height: 170px;
  background: var(--panel2) center 25% / cover no-repeat; border: 1px solid var(--line); color: var(--text);
  transition: transform .15s, box-shadow .15s;
}
.deck-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); text-decoration: none; }
.deck-card .shade { position: absolute; inset: 0; background: linear-gradient(180deg, rgba(10, 12, 18, .1) 0%, rgba(10, 12, 18, .92) 75%); }
.deck-card .body { position: relative; padding: 16px; display: flex; flex-direction: column; justify-content: flex-end; height: 100%; min-height: 170px; }
.deck-card h3 { font-size: 18px; }
.deck-card .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.deck-card .meta { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; }
.pips { display: inline-flex; gap: 2px; }
.pips .ms { width: 17px; height: 17px; }

.deck-hero {
  position: relative; border-radius: var(--radius); overflow: hidden; margin-bottom: 18px;
  background: var(--panel2) center 25% / cover no-repeat; border: 1px solid var(--line);
}
.deck-hero .shade { position: absolute; inset: 0; background: linear-gradient(90deg, rgba(10, 12, 18, .95) 0%, rgba(10, 12, 18, .75) 55%, rgba(10, 12, 18, .35) 100%); }
.deck-hero .body { position: relative; padding: 26px; display: flex; gap: 24px; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; }
.deck-hero h1 { font-size: 30px; }
.deck-hero .cmdr { color: var(--gold2); font-weight: 600; margin-top: 4px; }
.deck-hero .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.deck-layout { display: grid; grid-template-columns: 1fr 280px; gap: 18px; align-items: start; }
.deck-cols { columns: 3 280px; column-gap: 18px; }
.section { break-inside: avoid; margin-bottom: 18px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.section h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 10px 14px; background: var(--bg2); border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; }
.drow { display: grid; grid-template-columns: 24px 1fr auto auto; gap: 8px; align-items: center; padding: 6px 14px; cursor: pointer; border-bottom: 1px solid rgba(44, 50, 67, .5); }
.drow:last-child { border-bottom: 0; }
.drow:hover { background: var(--panel2); }
.drow .q { color: var(--muted); font-variant-numeric: tabular-nums; }
.drow .n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drow .p { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; min-width: 52px; text-align: right; }
.own { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-left: 6px; vertical-align: 1px; }
.drow .own { margin: 0 8px 0 0; }
.own.yes { background: var(--good); }
.own.part { background: var(--gold); }
.own.no { background: var(--bad); }
.side { display: grid; gap: 14px; position: sticky; top: 80px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.panel h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 12px; }
.curve { display: flex; align-items: flex-end; gap: 6px; height: 110px; }
.curve .bar { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 4px; font-size: 11px; color: var(--muted); }
.curve .bar i { display: block; width: 100%; background: linear-gradient(180deg, var(--gold2), var(--gold)); border-radius: 4px 4px 0 0; min-height: 2px; }
.curve .bar b { color: var(--text); font-weight: 600; }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 6px 10px; font-size: 13px; }
.kv span:nth-child(odd) { color: var(--muted); }
.kv span:nth-child(even) { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.legend { display: flex; gap: 12px; font-size: 12px; color: var(--muted); margin-top: 10px; flex-wrap: wrap; }

/* ---------- modal ---------- */
.backdrop {
  position: fixed; inset: 0; z-index: 50; background: rgba(5, 6, 10, .75); backdrop-filter: blur(4px);
  display: grid; place-items: center; padding: 20px; animation: fade .15s ease;
}
@keyframes fade { from { opacity: 0; } }
.modal {
  position: relative; width: min(1100px, 100%); max-height: calc(100vh - 40px); overflow: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow);
  animation: pop .18s ease;
}
.modal.small { width: min(480px, 100%); padding: 22px; }
@keyframes pop { from { transform: translateY(10px) scale(.98); opacity: 0; } }
.modal .x {
  position: absolute; top: 12px; right: 12px; z-index: 3; width: 34px; height: 34px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--panel2); color: var(--text); font-size: 20px; line-height: 1; cursor: pointer;
}
.card-view { display: grid; grid-template-columns: minmax(240px, 400px) minmax(0, 1fr); gap: 28px; padding: 26px; }
.card-view .left { display: grid; gap: 12px; align-content: start; }
.card-view .big { cursor: zoom-in; box-shadow: 0 18px 40px rgba(0, 0, 0, .6); border-radius: 4.75% / 3.4%; }
.card-view .right { display: grid; gap: 16px; align-content: start; min-width: 0; }
.cv-title { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding-right: 40px; }
.cv-title h2 { font-size: 24px; }
.cv-type { color: var(--muted); font-weight: 600; }
.oracle { background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; white-space: normal; }
.oracle p { margin: 0 0 8px; }
.oracle p:last-child { margin: 0; }
.oracle .face-name { font-weight: 700; color: var(--gold2); margin-bottom: 4px; }
.oracle .pt { font-weight: 700; text-align: right; }
.oracle hr { border: 0; border-top: 1px solid var(--line); margin: 10px 0; }
.meta-line { display: flex; gap: 12px; flex-wrap: wrap; color: var(--muted); font-size: 13px; align-items: center; }
.meta-line .ss { display: inline-flex; align-items: center; gap: 6px; }
.price-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.price-table th, .price-table td { padding: 6px 10px; text-align: right; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.price-table th:first-child, .price-table td:first-child { text-align: left; }
.price-table th { color: var(--muted); font-weight: 600; font-size: 12px; }
.price-table tr.sel td { color: var(--gold2); font-weight: 700; }
.controls { display: flex; gap: 12px; flex-wrap: wrap; align-items: end; padding: 14px; background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; }
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.stepper button { width: 34px; height: 36px; border: 0; background: var(--panel2); color: var(--text); font-size: 18px; cursor: pointer; }
.stepper button:hover { background: #2a3042; }
.stepper span { min-width: 40px; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }
.links { display: flex; gap: 8px; flex-wrap: wrap; }
.prints-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.prints-head input { flex: 0 1 220px; padding: 6px 10px; }
.prints { display: grid; grid-template-columns: repeat(auto-fill, minmax(106px, 1fr)); gap: 12px; max-height: 420px; overflow: auto; padding: 4px; }
.print { cursor: pointer; font-size: 11px; color: var(--muted); text-align: center; }
.print .img-wrap { border: 2px solid transparent; transition: transform .12s, border-color .12s; }
.print:hover .img-wrap { transform: translateY(-2px); border-color: var(--line); }
.print.cur .img-wrap { border-color: var(--gold); }
.print b { color: var(--text); display: block; margin-top: 4px; font-size: 11px; }
.print .pp { color: var(--gold2); }

.lightbox { position: fixed; inset: 0; z-index: 70; background: rgba(0, 0, 0, .9); display: grid; place-items: center; cursor: zoom-out; animation: fade .15s; padding: 20px; }
.lightbox img { max-height: calc(100vh - 40px); max-width: 100%; border-radius: 4.75% / 3.4%; box-shadow: 0 20px 60px rgba(0, 0, 0, .8); }

#hoverPreview { position: fixed; z-index: 40; width: 250px; border-radius: 12px; pointer-events: none; box-shadow: var(--shadow); }

/* ---------- auth ---------- */
.auth-wrap {
  min-height: 100vh; display: grid; place-items: center; padding: 20px;
  background: radial-gradient(1200px 600px at 20% -10%, rgba(212, 169, 74, .14), transparent 60%),
    radial-gradient(900px 500px at 110% 110%, rgba(124, 140, 255, .14), transparent 60%), var(--bg);
}
.auth-card { width: min(400px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 30px; box-shadow: var(--shadow); }
.auth-card .brand { font-size: 28px; justify-content: center; }
.auth-card .brand svg { width: 28px; height: 28px; }
.auth-card > p { text-align: center; margin: 6px 0 22px; }
.auth-card form { display: grid; gap: 14px; }
.tabs { display: grid; grid-template-columns: 1fr 1fr; background: var(--bg2); border-radius: 10px; padding: 4px; margin-bottom: 18px; }
.tabs button { border: 0; background: transparent; color: var(--muted); font: inherit; font-weight: 600; padding: 8px; border-radius: 7px; cursor: pointer; }
.tabs button.active { background: var(--panel2); color: var(--text); }

/* ---------- import ---------- */
.import-grid { display: grid; grid-template-columns: 1fr 340px; gap: 18px; align-items: start; }
.import-form { display: grid; gap: 14px; }
.drop {
  border: 2px dashed var(--line); border-radius: var(--radius); padding: 30px; text-align: center; cursor: pointer;
  transition: border-color .15s, background .15s; display: grid; gap: 4px;
}
.drop:hover, .drop.over { border-color: var(--gold); background: rgba(212, 169, 74, .06); }
.drop strong { font-size: 16px; }
.drop span { color: var(--muted); }
.drop .fname { color: var(--gold2); font-weight: 600; }
.or { text-align: center; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .1em; }
textarea { width: 100%; min-height: 200px; resize: vertical; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 13px; }
.row { display: flex; gap: 18px; flex-wrap: wrap; align-items: center; }
.help ol { padding-left: 18px; margin: 8px 0; color: var(--muted); }
.help li { margin-bottom: 6px; }
.help code { background: var(--bg2); padding: 1px 5px; border-radius: 4px; font-size: 12px; color: var(--text); }
.progress { height: 8px; background: var(--bg2); border-radius: 99px; overflow: hidden; margin: 10px 0 6px; }
.progress i { display: block; height: 100%; background: linear-gradient(90deg, var(--gold), var(--gold2)); transition: width .3s; }
.result { padding: 14px; border-radius: 10px; background: var(--bg2); border: 1px solid var(--line); }
.result.ok { border-color: rgba(63, 191, 127, .5); }
.result ul { margin: 6px 0 0; padding-left: 18px; max-height: 180px; overflow: auto; font-family: ui-monospace, Consolas, monospace; font-size: 12px; color: var(--muted); }

/* ---------- autocomplete ---------- */
.ac { position: relative; }
.ac input { width: 100%; }
.ac-list { position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 5; background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; box-shadow: var(--shadow); }
.ac-list div { padding: 8px 12px; cursor: pointer; }
.ac-list div:hover, .ac-list div.hi { background: #2e3448; }

/* ---------- toasts ---------- */
#toasts { position: fixed; bottom: 20px; right: 20px; z-index: 90; display: grid; gap: 8px; }
.toast { background: var(--panel2); border: 1px solid var(--line); border-left: 4px solid var(--good); padding: 10px 14px; border-radius: 10px; box-shadow: var(--shadow); animation: pop .2s; max-width: 360px; }
.toast.error { border-left-color: var(--bad); }

/* ---------- responsive ---------- */
@media (max-width: 1000px) {
  .deck-layout, .import-grid { grid-template-columns: 1fr; }
  .side { position: static; }
  .card-view { grid-template-columns: minmax(0, 1fr); }
  .card-view .left { max-width: 380px; margin: 0 auto; width: 100%; }
}
@media (max-width: 720px) {
  .topbar { flex-wrap: wrap; gap: 10px; padding: 10px 16px; }
  .topbar nav { order: 3; width: 100%; }
  .topbar-right { gap: 8px; }
  .market span, .user-chip { display: none; }
  main { padding: 16px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 14px 10px; }
  .card-view { padding: 18px; }
  table.list .hide-sm { display: none; }
  #hoverPreview { display: none; }
}
