:root {
  color-scheme: light dark;
  --bg: #f3f4f6;
  --surface: #ffffff;
  --surface-2: #eceef2;
  --text: #14161b;
  --muted: #5f6672;
  --border: #dcdfe5;
  --accent: #2f6bed;
  --accent-soft: #e4ecfd;
  --on-accent: #ffffff;
  --good: #16824a;
  --bad: #c53030;
  --warn: #9a6400;
  --pokemon: #c79a00;
  --mtg: #b05f23;
  --riftbound: #13897f;
  --radius: 12px;
  --nav-h: 58px;
  --shadow: 0 1px 2px rgba(15, 20, 30, .06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1014;
    --surface: #171a20;
    --surface-2: #20242c;
    --text: #eceef2;
    --muted: #9ca3af;
    --border: #2a2f39;
    --accent: #6694ff;
    --accent-soft: #1c2a4a;
    --good: #46d18a;
    --bad: #ff7272;
    --warn: #f0b64a;
    --pokemon: #f2c230;
    --mtg: #e08a4c;
    --riftbound: #3cc7b9;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  padding: env(safe-area-inset-top) 0 calc(var(--nav-h) + env(safe-area-inset-bottom) + 12px);
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}
body[data-view="login"] { padding-bottom: 24px; }
a { color: var(--accent); text-decoration: none; }
h1, h2, h3 { margin: 0; font-weight: 650; }
h1.page-title { font-size: 26px; margin: 18px 0 14px; }
h2 { font-size: 17px; }
p { margin: 0; }
[hidden] { display: none !important; }

main { max-width: 720px; margin: 0 auto; padding: 0 16px; }
.boot { padding: 40vh 0; text-align: center; color: var(--muted); }
.muted { color: var(--muted); }
.fine { color: var(--muted); font-size: 13px; margin: 18px 2px 8px; }
.pad { padding: 14px 4px; }
.good { color: var(--good); }
.bad { color: var(--bad); }

/* ---------------------------------------------------------------- bottom navigation */
nav.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--surface); border-top: 1px solid var(--border);
}
nav.tabs a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); font-size: 11.5px; font-weight: 550;
}
nav.tabs a.on { color: var(--accent); }
nav.tabs svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; stroke-linecap: round; }

/* ---------------------------------------------------------------- panels and hero */
.panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px; margin: 12px 0; box-shadow: var(--shadow);
}
.panel > h2 { margin-bottom: 10px; }
.panel-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.hero {
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  padding: 16px; box-shadow: var(--shadow);
}
.hero-label { color: var(--muted); font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.hero-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 6px; }
.vb-label { color: var(--muted); font-size: 13px; }
.vb-main { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.vb-alt { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.hero-sub { margin-top: 10px; color: var(--muted); font-size: 14px; }
.quick { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 12px 0; }

.game-table { width: 100%; border-collapse: collapse; font-size: 14.5px; }
.game-table td { padding: 8px 0; border-top: 1px solid var(--border); vertical-align: top; }
.game-table tr:first-child td { border-top: 0; }
.game-table td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.game-table .sub { color: var(--muted); font-size: 12.5px; }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 14.5px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------- buttons and inputs */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; cursor: pointer; text-align: center;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.danger { color: var(--bad); }
.btn.small { min-height: 34px; padding: 0 12px; font-size: 14px; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .5; }
.icon-btn {
  width: 40px; height: 40px; border: 0; border-radius: 50%; background: transparent; color: var(--muted);
  font-size: 26px; line-height: 1; cursor: pointer;
}
input, select, textarea {
  font: inherit; font-size: 16px; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; min-height: 44px; padding: 8px 12px; width: 100%;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
input.search { border-radius: 22px; padding-left: 16px; }
label.field { display: block; margin: 12px 0 0; }
label.field > span, .field-label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.row2 { display: grid; grid-template-columns: 1fr 110px; gap: 8px; }
.row3 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.check { display: flex; align-items: center; gap: 10px; margin-top: 14px; font-weight: 600; }
.check input { width: 22px; height: 22px; min-height: 0; margin: 0; accent-color: var(--accent); }
.form-error { color: var(--bad); font-size: 14px; margin-top: 10px; min-height: 1em; }

.pills { display: flex; flex-wrap: wrap; gap: 6px; }
.pill {
  min-height: 36px; padding: 0 13px; border-radius: 18px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-size: 14.5px; font-weight: 550; cursor: pointer;
}
.pill.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.segmented { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--surface-2); border-radius: 10px; padding: 3px; gap: 3px; }
.segmented button {
  border: 0; background: transparent; color: var(--muted); font: inherit; font-size: 14.5px; font-weight: 600;
  min-height: 36px; border-radius: 8px; cursor: pointer;
}
.segmented button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.12); }
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.stepper button { width: 44px; height: 42px; border: 0; background: var(--surface-2); color: var(--text); font-size: 22px; cursor: pointer; }
.stepper output { min-width: 52px; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------- list rows */
.toolbar { position: sticky; top: env(safe-area-inset-top); z-index: 5; background: var(--bg); padding: 10px 0 8px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
.toolbar > * { min-width: 0; }
.toolbar .line { display: flex; gap: 8px; align-items: center; }
.toolbar select { width: auto; min-height: 36px; padding: 4px 10px; font-size: 14px; border-radius: 18px; }
.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; min-width: 0; }
.chips .pills { flex-wrap: nowrap; }
.chips .pill { flex: none; white-space: nowrap; }
.chips::-webkit-scrollbar { display: none; }
.list-info { color: var(--muted); font-size: 13px; padding: 2px 2px 6px; }

.rows { display: grid; gap: 8px; }
.rows.busy { opacity: .55; }
.row {
  display: grid; grid-template-columns: 52px minmax(0, 1fr) auto; gap: 12px; align-items: center;
  padding: 8px 10px 8px 8px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text); box-shadow: var(--shadow); min-height: 84px;
}
.row.compact { grid-template-columns: 52px minmax(0, 1fr) auto auto; gap: 10px; }
.thumb {
  width: 52px; height: 72px; border-radius: 5px; object-fit: cover; background: var(--surface-2);
  display: flex; align-items: center; justify-content: center; color: var(--muted); overflow: hidden;
}
.thumb svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.6; }
.row-main { min-width: 0; }
.row-title { font-weight: 650; line-height: 1.25; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow-wrap: anywhere; }
.row-sub { color: var(--muted); font-size: 13px; line-height: 1.3; margin-top: 2px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.badges { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 5px; }
.badge {
  font-size: 11.5px; font-weight: 650; padding: 1px 7px; border-radius: 9px;
  background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.badge.pokemon { color: var(--pokemon); }
.badge.mtg { color: var(--mtg); }
.badge.riftbound { color: var(--riftbound); }
.badge.accent { background: var(--accent-soft); color: var(--accent); }
.badge.warn { color: var(--warn); }
.row-price { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.p-low { font-weight: 700; }
.p-trend { color: var(--muted); font-size: 12.5px; }
.p-qty { font-size: 12.5px; font-weight: 700; color: var(--accent); margin-top: 2px; }
.add-btn {
  width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--accent); background: var(--accent-soft);
  color: var(--accent); font-size: 24px; line-height: 1; cursor: pointer;
}
.empty { text-align: center; color: var(--muted); padding: 40px 10px; }

/* ---------------------------------------------------------------- item page */
.back { display: inline-block; margin: 14px 0 6px; font-weight: 600; }
.item-head { display: grid; grid-template-columns: 120px 1fr; gap: 14px; align-items: start; }
.item-img { width: 120px; border-radius: 8px; background: var(--surface-2); aspect-ratio: 63 / 88; object-fit: cover; display: flex; align-items: center; justify-content: center; color: var(--muted); }
.item-img svg { width: 40px; height: 40px; fill: none; stroke: currentColor; stroke-width: 1.5; }
.item-title { font-size: 21px; line-height: 1.2; }
.item-sub { color: var(--muted); font-size: 14px; margin-top: 4px; }
.price-grid { display: grid; grid-template-columns: auto 1fr 1fr; gap: 6px 12px; font-variant-numeric: tabular-nums; }
.price-grid .h { color: var(--muted); font-size: 12.5px; font-weight: 600; text-align: right; }
.price-grid .l { color: var(--muted); font-size: 14px; }
.price-grid .v { text-align: right; font-weight: 650; }
.qty-line { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.actions { display: grid; gap: 10px; margin-top: 16px; }

/* ---------------------------------------------------------------- sheet, toast */
dialog.sheet {
  border: 0; padding: 0; margin: auto auto 0; width: 100%; max-width: 640px;
  max-height: 92vh; border-radius: 18px 18px 0 0; background: var(--surface); color: var(--text);
  display: flex; flex-direction: column;
}
dialog.sheet:not([open]) { display: none; }
dialog.sheet::backdrop { background: rgba(0, 0, 0, .45); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 10px 4px 16px; }
.sheet-title { font-weight: 700; font-size: 17px; line-height: 1.25; }
.sheet-body { overflow-y: auto; padding: 0 16px calc(18px + env(safe-area-inset-bottom)); }
.sheet-card { display: grid; grid-template-columns: 52px 1fr; gap: 12px; align-items: center; margin-bottom: 4px; }
.price-line { margin-top: 12px; padding: 10px 12px; border-radius: 10px; background: var(--surface-2); font-size: 14.5px; font-variant-numeric: tabular-nums; }
.toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 14px); z-index: 50;
  transform: translate(-50%, 20px); opacity: 0; transition: .2s; pointer-events: none;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 22px; font-weight: 600; font-size: 14.5px;
  max-width: calc(100vw - 32px); text-align: center;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; }
.toast.bad { background: var(--bad); color: #fff; }

/* ---------------------------------------------------------------- login */
.login { max-width: 420px; margin: 0 auto; padding-top: 8vh; }
.login .logo { width: 72px; height: 72px; border-radius: 18px; display: block; margin-bottom: 14px; }
.login h1 { font-size: 26px; }
.login p.lead { color: var(--muted); margin: 6px 0 18px; }
.code { font: 700 26px/1 ui-monospace, "SF Mono", Menlo, Consolas, monospace; letter-spacing: .12em; }
.offline { text-align: center; padding: 26vh 10px 0; }
.offline h1 { font-size: 22px; margin-bottom: 8px; }
.offline p { color: var(--muted); margin-bottom: 18px; }
