:root {
  --bg: #0b0d12;
  --panel: #141821;
  --panel-2: #1b2030;
  --line: #2a3142;
  --text: #e8eaf0;
  --muted: #8b93a7;
  --accent: #f3e600;
  --accent-ink: #0b0d12;
  --cyan: #3de0e8;
  --danger: #ff4d5e;
  --ok: #3ddc84;
  --warn: #ffb347;
  --red: #e5484d;
  --blue: #3b82f6;
  --green: #22c55e;
  --yellow: #eab308;
  --radius: 6px;
  --nav-h: 60px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
}
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
img { max-width: 100%; }
[hidden] { display: none !important; }

/* ---------- chrome ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 10px;
  background: rgba(11, 13, 18, .92); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 800; letter-spacing: .12em; text-decoration: none; font-size: 15px; }
.brand span { color: var(--accent); }
.sync {
  display: inline-flex; align-items: center; gap: 6px;
  background: none; border: 1px solid var(--line); border-radius: 999px;
  padding: 4px 10px; font-size: 12px; color: var(--muted); cursor: pointer;
}
.sync::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.sync[data-state="ok"]::before { background: var(--ok); }
.sync[data-state="syncing"]::before { background: var(--cyan); animation: pulse 1s infinite; }
.sync[data-state="pending"]::before { background: var(--warn); }
.sync[data-state="error"]::before { background: var(--danger); }
@keyframes pulse { 50% { opacity: .3; } }

.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--panel); border-top: 1px solid var(--line);
}
.nav a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  text-decoration: none; color: var(--muted); font-size: 11px;
}
.nav svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; }
.nav a.active { color: var(--accent); }

.view { max-width: 1280px; margin: 0 auto; padding: 16px; }

@media (min-width: 900px) {
  body { padding-bottom: 0; padding-left: 88px; }
  .nav {
    top: 0; right: auto; width: 88px; height: auto;
    grid-template-columns: 1fr; grid-auto-rows: 72px; align-content: start;
    padding-top: 64px; border-top: 0; border-right: 1px solid var(--line);
  }
  .topbar { margin-left: -88px; padding-left: 104px; }
  .view { padding: 24px; }
}

/* ---------- basics ---------- */
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); margin: 24px 0 10px; }
.muted { color: var(--muted); }
.pad { padding: 16px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.spread { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; }
.badge {
  display: inline-block; padding: 1px 6px; border-radius: 4px; font-size: 11px; font-weight: 700;
  letter-spacing: .04em; background: var(--panel-2); border: 1px solid var(--line); color: var(--muted);
}
.btn {
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  padding: 8px 14px; border-radius: var(--radius); border: 1px solid var(--line);
  background: var(--panel-2); cursor: pointer; text-decoration: none; font-size: 14px;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 700; }
.btn.danger { color: var(--danger); border-color: rgba(255,77,94,.5); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  padding: 5px 12px; border-radius: 999px; border: 1px solid var(--line); background: none;
  cursor: pointer; font-size: 13px; color: var(--muted);
}
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 700; }
input[type="search"], input[type="text"], select, textarea {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 8px 10px; min-width: 0;
}
textarea { width: 100%; min-height: 120px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.progress { height: 6px; background: var(--panel-2); border-radius: 3px; overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); }
.progress.done > div { background: var(--ok); }
.empty { padding: 32px 16px; text-align: center; color: var(--muted); }
.back { display: inline-block; margin-bottom: 8px; color: var(--muted); text-decoration: none; font-size: 14px; }

.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; vertical-align: middle; }
.c-Red { background: var(--red); } .c-Blue { background: var(--blue); }
.c-Green { background: var(--green); } .c-Yellow { background: var(--yellow); }

/* ---------- sets list ---------- */
.set-list { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.set-tile {
  display: grid; gap: 8px; padding: 14px; text-decoration: none;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
}
.set-tile:hover { border-color: var(--accent); }
.set-tile .name { font-weight: 600; }
.set-tile .nums { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); }
.set-tile .nums b { color: var(--text); }

/* ---------- set page ---------- */
.set-head { display: grid; gap: 12px; margin-bottom: 16px; }
.stats { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; }
.stat .v { font-size: 22px; font-weight: 700; }
.stat .l { font-size: 12px; color: var(--muted); }
.rarity-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.rarity-table td { padding: 4px 6px; border-bottom: 1px solid var(--line); }
.rarity-table td:last-child { text-align: right; color: var(--muted); }
details.panel > summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 12px 0; }
.toolbar input[type="search"] { flex: 1 1 180px; }

.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
@media (min-width: 900px) { .grid { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); } }
.tile { display: grid; gap: 6px; }
.tile .img {
  position: relative; display: block; aspect-ratio: 733 / 1024; border-radius: 4.5%/3.2%;
  overflow: hidden; background: var(--panel-2);
}
.tile .img img { width: 100%; height: 100%; object-fit: cover; display: block; transition: filter .15s, opacity .15s; }
.tile.missing .img img { filter: grayscale(1) brightness(.55); }
.tile .img .count {
  position: absolute; top: 6px; right: 6px; min-width: 26px; padding: 2px 6px; text-align: center;
  background: var(--accent); color: var(--accent-ink); font-weight: 800; border-radius: 999px; font-size: 13px;
}
.tile.missing .img .count { display: none; }
.tile .meta { display: flex; justify-content: space-between; gap: 6px; font-size: 12px; color: var(--muted); }
.tile .title { font-size: 13px; line-height: 1.25; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.stepper { display: grid; grid-template-columns: 36px 1fr 36px; align-items: center; height: 34px; }
.stepper button {
  height: 100%; border: 1px solid var(--line); background: var(--panel-2); cursor: pointer; font-size: 18px; line-height: 1;
}
.stepper button:first-child { border-radius: var(--radius) 0 0 var(--radius); }
.stepper button:last-child { border-radius: 0 var(--radius) var(--radius) 0; }
.stepper .n {
  height: 100%; border: 1px solid var(--line); border-left: 0; border-right: 0; background: var(--panel);
  text-align: center; font-weight: 700; cursor: pointer;
}
.stepper button:active { background: var(--accent); color: var(--accent-ink); }

/* ---------- card page ---------- */
.card-page { display: grid; gap: 20px; }
@media (min-width: 800px) { .card-page { grid-template-columns: minmax(260px, 380px) 1fr; align-items: start; } }
.card-page .big { width: 100%; height: auto; aspect-ratio: 733 / 1024; object-fit: contain; max-width: 260px; margin: 0 auto; border-radius: 4.5%/3.2%; display: block; }
@media (min-width: 800px) { .card-page .big { max-width: none; } }
.card-stats { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.card-stats .stat { padding: 6px 10px; }
.card-stats .stat .v { font-size: 17px; }
.rules { white-space: normal; background: var(--panel); border-left: 3px solid var(--accent); padding: 10px 12px; border-radius: 0 var(--radius) var(--radius) 0; }
.kw { color: var(--accent); font-weight: 700; }

/* ---------- decks ---------- */
.deck-list { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.deck-tile { display: grid; gap: 6px; padding: 14px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); text-decoration: none; }
.deck-tile:hover { border-color: var(--accent); }
.legal { color: var(--ok); } .illegal { color: var(--danger); }
.deck-editor { display: grid; gap: 16px; }
@media (min-width: 1000px) { .deck-editor { grid-template-columns: 1fr 380px; align-items: start; } .deck-side { position: sticky; top: 70px; } }
.deck-name { font-size: 20px; font-weight: 700; width: 100%; }
.issues { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; font-size: 14px; }
.issues li::before { margin-right: 6px; }
.issues .error { color: var(--danger); } .issues .error::before { content: "✕"; }
.issues .warning { color: var(--warn); } .issues .warning::before { content: "!"; }
.issues .ok { color: var(--ok); } .issues .ok::before { content: "✓"; }
.ram { display: flex; gap: 8px; flex-wrap: wrap; font-size: 13px; }
.ram span { display: inline-flex; gap: 6px; align-items: center; padding: 3px 8px; background: var(--panel-2); border-radius: 999px; }
.deck-lines { display: grid; gap: 4px; }
.deck-line {
  display: grid; grid-template-columns: 104px 14px 1fr auto; gap: 8px; align-items: center;
  padding: 4px 6px; border-radius: var(--radius); background: var(--panel); font-size: 14px;
}
.deck-line.bad { outline: 1px solid var(--danger); }
.deck-line .nm { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer; }
.deck-line .own { font-size: 12px; color: var(--muted); }
.deck-line .own.short { color: var(--warn); }
.deck-line .stepper { height: 28px; grid-template-columns: 30px 1fr 30px; }
.picker-results { display: grid; gap: 4px; max-height: 60vh; overflow: auto; }
.picker-results .deck-line { grid-template-columns: 14px 1fr auto auto; }
.curve { display: flex; align-items: flex-end; gap: 4px; height: 70px; }
.curve div { flex: 1; background: var(--accent); min-height: 2px; position: relative; border-radius: 2px 2px 0 0; }
.curve div span { position: absolute; bottom: -18px; left: 0; right: 0; text-align: center; font-size: 11px; color: var(--muted); }
.curve div b { position: absolute; top: -16px; left: 0; right: 0; text-align: center; font-size: 11px; font-weight: 400; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 50;
  bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom, 0px));
  background: var(--panel-2); border: 1px solid var(--line); padding: 8px 14px; border-radius: var(--radius);
  max-width: calc(100% - 32px);
}
@media (min-width: 900px) { .toast { bottom: 24px; } }

/* ---------- set codes, rarity symbols, prints gallery ---------- */
.badge.code { color: var(--accent); border-color: rgba(243,230,0,.35); font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-weight: 600; }
.rar { vertical-align: -3px; flex: none; color: #fff; }
.prints { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
.print .img { border: 0; padding: 0; cursor: pointer; width: 100%; outline-offset: 2px; }
.print.selected .img { outline: 2px solid var(--accent); }
.set-link { color: var(--muted); text-decoration: none; font-size: 12px; }
.set-link:hover { color: var(--text); text-decoration: underline; }

/* ---------- collections ---------- */
.topbar-right { display: flex; align-items: center; gap: 8px; min-width: 0; }
#collection-switch { max-width: 44vw; padding: 4px 8px; font-size: 13px; border-color: var(--accent); }
.pstat { font-size: 11px; font-weight: 700; padding: 0 6px; border-radius: 999px; background: var(--panel-2); color: var(--muted); white-space: nowrap; }
.pstat.part { color: var(--warn); }
.pstat.done { background: var(--ok); color: #06210f; }
.tile .meta { align-items: center; }
.own-summary { display: grid; gap: 4px; margin: 10px 0; font-size: 14px; }
.col-rows { display: grid; gap: 8px; }
.col-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr) auto; gap: 8px; align-items: center; }
@media (max-width: 600px) { .col-row { grid-template-columns: minmax(0, 1fr) auto; } .col-row select { grid-column: 1 / -1; grid-row: 2; } }
.check-line {
  display: grid; grid-template-columns: 14px minmax(0, 1fr) auto auto; gap: 8px; align-items: center;
  padding: 8px 10px; border-radius: var(--radius); background: var(--panel); text-decoration: none; font-size: 14px;
}
.check-line .nm { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- scanner ---------- */
.scan-layout { display: grid; gap: 16px; margin-top: 12px; }
@media (min-width: 900px) { .scan-layout { grid-template-columns: minmax(0, 420px) minmax(0, 1fr); align-items: start; } }
.scan-stage { position: relative; aspect-ratio: 3 / 4; max-height: 62vh; width: 100%; background: #000; border-radius: var(--radius); overflow: hidden; margin: 0 auto; }
.scan-stage video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.scan-frame { position: absolute; border: 3px solid var(--accent); border-radius: 4.5%/3.2%; box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .45); transition: border-color .15s; }
.scan-frame.found { border-color: var(--ok); }
.scan-hint { position: absolute; left: 8px; right: 8px; bottom: 8px; text-align: center; font-size: 13px; background: rgba(0, 0, 0, .6); padding: 4px 8px; border-radius: var(--radius); }
.scan-pick { display: grid; grid-template-columns: 120px minmax(0, 1fr); gap: 14px; align-items: start; }
.scan-big { width: 120px; height: auto; border-radius: 4.5%/3.2%; display: block; }
.scan-thumbs { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; }
.scan-thumb { flex: none; width: 76px; background: none; border: 2px solid transparent; border-radius: 6px; padding: 2px; cursor: pointer; display: grid; gap: 2px; font-size: 10px; color: var(--muted); }
.scan-thumb img { width: 100%; height: auto; display: block; border-radius: 3px; }
.scan-thumb span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.scan-thumb.on { border-color: var(--accent); color: var(--text); }
.session-line { display: grid; grid-template-columns: 104px minmax(0, 1fr); gap: 4px 8px; align-items: center; padding: 6px; background: var(--panel); border-radius: var(--radius); font-size: 14px; }
.session-line .nm { text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.session-line .muted { grid-column: 2; }

/* ---------- narrow screens ---------- */
.brand, .sync { white-space: nowrap; }
.brand b { font-weight: inherit; }
.scan-layout > div, .scan-pick > div { min-width: 0; }
@media (max-width: 480px) {
  .topbar { padding-left: 12px; padding-right: 12px; gap: 8px; }
  .brand-long { display: none; }
  .sync { padding: 4px 8px; }
}
.qr { background: #fff; border-radius: var(--radius); width: min(260px, 100%); aspect-ratio: 1; }
.qr svg { width: 100%; height: 100%; display: block; }
