/* Mobile first: the base styles are the phone's. Wider screens (≥ 901 px, matching fitFeed in
   app.js) add the desktop layout at the bottom of each section. */
:root {
  --bg: #fff;
  --ink: #000;
  --accent: #ffe600;
  --muted: #555;
  --tint: #fffbd1;
  --pick: #fff6a3;
  --danger: #b00020;
  --good: #0a6b2a;
  --b: 3px solid var(--ink);
  --shadow: 6px 6px 0 var(--ink);
  --shadow-sm: 4px 4px 0 var(--ink);
  --font: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --tabbar: 60px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --dock: calc(var(--tabbar) + var(--safe-b)); /* space the bottom tab bar takes */
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; overflow-x: clip; } /* last resort: nothing may widen the page */
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.35 var(--font);
  display: grid;
  grid-template-rows: auto auto;
  grid-template-columns: minmax(0, 1fr); /* never wider than the screen: see "no page wider than the screen" */
  align-content: start;
  gap: 12px;
  padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) calc(var(--dock) + 16px) max(10px, env(safe-area-inset-left));
  min-height: 100dvh;
}
button, a, label, select, summary { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
h1, h2 { margin: 0; letter-spacing: .02em; }
.box { border: var(--b); box-shadow: var(--shadow); background: var(--bg); }
.sub { color: var(--muted); font-size: 12px; }
.strong { font-weight: 700; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.up { color: var(--good); }
.down { color: var(--danger); }
[hidden] { display: none !important; }

/* No page wider than the screen. A grid or flex child grows to fit its content by default, so
   one long row (the strip of scanned cards, a long name) would widen the whole page, and phones
   zoom out to show it. Columns are allowed to shrink instead; long rows scroll inside themselves. */
.view-scan, .page, #stats-body, #set-detail, #sets-index, #shared-body, .account, .people { grid-template-columns: minmax(0, 1fr); }
body > *, .view-scan > *, .page > *, .layout > *, .panel-box, .session, .strip, .toolbar > *, .dlg-body > * { min-width: 0; }
.session, .strip { max-width: 100%; }

/* ---------- header + navigation ---------- */
.bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.bar h1 { font-size: 17px; background: var(--accent); border: var(--b); padding: 4px 10px; box-shadow: var(--shadow-sm); }
.status { display: none; gap: 8px; flex-wrap: wrap; flex: 1; }
.status span:not(:empty) { border: 2px solid var(--ink); padding: 2px 6px; font-size: 12px; }
.bar-actions { display: flex; gap: 10px; margin-left: auto; }
body:not(.on-scan) .bar-actions { display: none; }

/* phone: a tab bar along the bottom edge, in thumb reach */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(6, 1fr);
  background: var(--bg); border-top: var(--b); padding: 0 env(safe-area-inset-right) var(--safe-b) env(safe-area-inset-left);
}
.tabs a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  min-height: var(--tabbar); color: var(--ink); text-decoration: none; font-weight: 700; font-size: 10px; letter-spacing: .04em;
  border-right: 2px solid var(--ink);
}
.tabs a:last-child { border-right: 0; }
.tabs svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linejoin: miter; }
.tabs a.on { background: var(--ink); color: var(--accent); }
.tabs a:focus-visible { outline: 3px solid var(--accent); outline-offset: -5px; }

/* your account: initials, top right */
.me-btn {
  margin-left: auto; width: 40px; height: 40px; display: grid; place-items: center; flex: none;
  border: var(--b); box-shadow: 3px 3px 0 var(--ink); background: var(--bg); color: var(--ink);
  font-weight: 700; text-decoration: none; font-size: 14px;
}
body.on-account .me-btn { background: var(--ink); color: var(--accent); }
.me-btn + .bar-actions { margin-left: 0; }
body.signed-out .tabs, body.signed-out .bar-actions, body.signed-out .me-btn,
body.standalone .tabs, body.standalone .bar-actions { display: none; }
body.signed-out, body.standalone { --dock: var(--safe-b); }
body:not(.is-admin) .admin-only { display: none !important; }

body.offline::before {
  content: "RECONNECTING TO THE SERVER…"; position: fixed; top: 0; left: 0; right: 0; z-index: 50;
  padding: max(8px, env(safe-area-inset-top)) 12px 8px; background: var(--ink); color: var(--accent);
  font-weight: 700; font-size: 13px; text-align: center; letter-spacing: .05em;
}

/* ---------- controls ---------- */
.btn {
  font: inherit; font-weight: 700; color: var(--ink); background: var(--bg);
  border: var(--b); border-radius: 0; padding: 10px 16px; min-height: 44px; cursor: pointer;
  box-shadow: var(--shadow-sm); text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: transform .06s, box-shadow .06s;
}
.btn:active { transform: translate(4px, 4px); box-shadow: 0 0 0 var(--ink); }
.btn:focus-visible, select:focus-visible, input:focus-visible, textarea:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.btn.primary { background: var(--accent); }
.btn.small { padding: 6px 12px; min-height: 40px; font-size: 13px; box-shadow: 3px 3px 0 var(--ink); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.on { background: var(--ink); color: var(--accent); }
.btn.armed { background: var(--danger); color: #fff; }
kbd { font: inherit; font-size: 11px; border: 2px solid currentColor; padding: 0 4px; }
.actions kbd { display: none; }
@media (hover: hover) {
  .btn:hover { background: var(--accent); }
  .btn.primary:hover { background: var(--ink); color: var(--accent); }
  .tabs a:not(.on):hover { background: var(--accent); }
}

/* 16 px text in fields: iOS zooms the page into anything smaller */
select, input[type=search], input[type=number], input[type=password], input:not([type]), input[list], textarea {
  font: inherit; font-size: 16px; color: var(--ink); background: #fff; border: var(--b); border-radius: 0;
  padding: 9px 10px; width: 100%; min-height: 44px; appearance: none; -webkit-appearance: none;
}
textarea { resize: vertical; }
select {
  background-image: linear-gradient(45deg, transparent 50%, var(--ink) 50%), linear-gradient(135deg, var(--ink) 50%, transparent 50%);
  background-position: calc(100% - 14px) 52%, calc(100% - 9px) 52%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 26px;
}
input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--ink); margin: 0; }
.link { all: unset; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 2px; }
.link:focus-visible { outline: 3px solid var(--accent); }
@media (hover: hover) { .link:hover { background: var(--accent); } }
.seg { display: inline-flex; gap: 6px; flex-wrap: wrap; }

/* ---------- scan: live feed ---------- */
.view-scan { display: grid; gap: 12px; min-height: 0; }
.layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; min-height: 0; }
.feed-wrap { padding: 0; display: flex; align-items: center; justify-content: center; background: var(--ink); overflow: hidden; min-height: 200px; position: relative; }
.lang-switch { position: absolute; top: 8px; left: 8px; z-index: 3; gap: 0; }
.lang-switch .btn { min-height: 36px; padding: 4px 10px; box-shadow: none; border-width: 2px; }
.lang-switch .btn + .btn { border-left: 0; }
.lang-badge { font-size: 10px; font-weight: 700; border: 2px solid var(--ink); background: var(--ink); color: var(--accent); padding: 0 4px; margin-left: 6px; vertical-align: middle; }
.feed { position: relative; width: 100%; max-height: 100%; aspect-ratio: 16 / 9; margin: 0 auto; }
.feed img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: fill; display: block; }
.feed svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.feed video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: fill; display: block; }
.feed polygon { fill: none; stroke-width: 4; vector-effect: non-scaling-stroke; stroke-linejoin: miter; }
.feed polygon.SEARCHING { stroke: #fff; stroke-dasharray: 10 6; }
.feed polygon.FOUND { stroke: var(--accent); }
.feed polygon.NOT { stroke: #fff; }
.label {
  position: absolute; transform: translateY(-100%); font-weight: 700; font-size: 12px; white-space: nowrap;
  padding: 3px 7px; border: 3px solid var(--ink); box-shadow: 3px 3px 0 var(--ink);
}
.label.SEARCHING { background: var(--ink); color: #fff; border-color: #fff; }
.label.FOUND { background: var(--accent); }
.label.NOT { background: #fff; }
.feed-msg { position: absolute; inset: 0; display: grid; place-items: center; color: #fff; font-weight: 700; letter-spacing: .1em; text-align: center; padding: 10px; }
.feed-msg:empty { display: none; }
.phone-start {
  position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 14px;
  padding: 16px; color: #fff; font-weight: 700; letter-spacing: .05em; text-align: center; overflow-wrap: anywhere;
  background: var(--ink); /* covers the last frame from a phone that stopped sending */
}
.phone-start p { margin: 0; max-width: 32ch; }
#phone-qr { position: static; width: min(220px, 60vw); height: auto; justify-self: center; background: #fff; image-rendering: pixelated; }

/* ---------- scan: result panel ---------- */
.panel { padding: 14px; overflow: visible; position: relative; min-height: 0; }
.idle { height: 100%; display: grid; place-content: center; text-align: center; gap: 14px; font-weight: 700; padding: 8px 0; }
.idle-card { width: 84px; height: 118px; margin: auto; border: var(--b); border-style: dashed; animation: float 3.2s ease-in-out infinite; }
.found { display: grid; grid-template-columns: minmax(90px, 30%) minmax(0, 1fr); gap: 4px 14px; align-items: start; }
/* phone: the card and its name side by side, then the pickers and buttons across the full width */
.found .meta { display: contents; }
.found .card-stage { grid-row: 1 / span 4; }
.found .meta > .tag, .found .name, .found .set, .found .price-row { grid-column: 2; }
.found .meta > .tag { justify-self: start; }
.found .selectors, .found .actions, .found .note { grid-column: 1 / -1; }
.found .selectors { grid-template-columns: repeat(2, minmax(0, 1fr)); margin-top: 10px; }
.card-stage { perspective: 900px; }
.card-img { width: 100%; display: block; border: var(--b); box-shadow: var(--shadow); background: #eee; aspect-ratio: 63 / 88; object-fit: cover; }
.card-img.fly { animation: fly-in .55s cubic-bezier(.2, .9, .25, 1.15) both, float 3.4s ease-in-out .55s infinite; }
.tag { display: inline-block; font-weight: 700; font-size: 12px; border: var(--b); padding: 3px 8px; background: var(--accent); box-shadow: 3px 3px 0 var(--ink); }
.tag.ns { background: #fff; }
.tag.searching { background: var(--ink); color: #fff; }
.name { font-size: 19px; margin: 8px 0 4px; line-height: 1.1; overflow-wrap: anywhere; }
.name .link { text-decoration-thickness: 3px; }
.set { color: var(--muted); }
.price-row { margin: 8px 0; display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.price { font-size: 20px; font-weight: 700; background: var(--accent); border: var(--b); padding: 2px 8px; }
.price.none { background: #fff; font-size: 15px; }
.price-date { font-size: 12px; color: var(--muted); }
.selectors { display: grid; grid-template-columns: minmax(0, 1fr); gap: 6px; margin-bottom: 10px; }
.selectors label { display: grid; gap: 4px; font-size: 11px; font-weight: 700; }
.actions { display: flex; gap: 12px; flex-wrap: wrap; }
/* phone: ADD + NEXT and WRONG stay in reach above the tab bar while the result is on screen */
.found .actions {
  position: sticky; bottom: calc(var(--dock) + 8px); z-index: 5; flex-wrap: nowrap;
  background: var(--bg); padding: 8px 0 0; margin-inline: -4px; padding-inline: 4px;
}
.found .actions .add { flex: 1 1 auto; }
.note { margin-top: 12px; font-size: 12px; min-height: 1em; }
.searching-view { height: 100%; display: grid; place-content: center; text-align: center; gap: 16px; padding: 12px 0; }
.searching-view .bars { display: flex; gap: 6px; justify-content: center; }
.searching-view .bars i { width: 12px; height: 36px; background: var(--ink); animation: pulse .9s ease-in-out infinite; }
.searching-view .bars i:nth-child(2) { animation-delay: .15s; }
.searching-view .bars i:nth-child(3) { animation-delay: .3s; }

.cands { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 16px 0; }
.cand { all: unset; cursor: pointer; display: grid; gap: 6px; font-size: 12px; text-align: center; animation: float 3s ease-in-out infinite; }
.cand img, .cand .ph { width: 100%; aspect-ratio: 63 / 88; border: var(--b); box-shadow: var(--shadow-sm); object-fit: cover; background: #eee; }
.cand:nth-child(2) { animation-delay: -1s; }
.cand:nth-child(3) { animation-delay: -2s; }
.cand:focus-visible img { box-shadow: 6px 6px 0 var(--accent), 9px 9px 0 var(--ink); }
.search { display: flex; gap: 10px; }
.results { margin-top: 14px; display: grid; gap: 8px; }
.result { all: unset; cursor: pointer; display: grid; grid-template-columns: 44px 1fr auto; gap: 10px; align-items: center; border: var(--b); padding: 6px; min-height: 44px; }
.result:active, .result:focus-visible { background: var(--accent); }
.result img, .result .ph { width: 44px; aspect-ratio: 63 / 88; object-fit: cover; border: 2px solid var(--ink); background: #eee; }
.result small { color: var(--muted); }
@media (hover: hover) {
  .cand:hover img { box-shadow: 6px 6px 0 var(--accent), 9px 9px 0 var(--ink); }
  .result:hover { background: var(--accent); }
}

/* ---------- scan: session strip ---------- */
.session { padding: 10px 12px 12px; }
.session-head { display: flex; gap: 12px; align-items: baseline; margin-bottom: 8px; }
.session-total { margin-left: auto; font-weight: 700; font-size: 16px; background: var(--accent); border: var(--b); padding: 2px 8px; }
.strip { display: flex; gap: 14px; overflow-x: auto; padding: 8px 8px 10px 2px; min-height: 100px; align-items: flex-end; scroll-snap-type: x proximity; }
.strip:empty::after { content: "ADDED CARDS APPEAR HERE"; color: var(--muted); font-size: 12px; align-self: center; }
button.chip { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; text-align: inherit; }
.chip { position: relative; flex: none; width: 60px; scroll-snap-align: start; animation: drop-in .45s cubic-bezier(.2, .9, .25, 1.2) both, float 3.6s ease-in-out .45s infinite; }
.chip img, .chip .ph { width: 60px; aspect-ratio: 63 / 88; display: block; border: var(--b); box-shadow: var(--shadow-sm); object-fit: cover; background: #eee; }
.chip .qty { position: absolute; top: -8px; right: -10px; background: var(--accent); border: var(--b); font-weight: 700; font-size: 12px; padding: 0 5px; }
.chip .val { font-size: 11px; text-align: center; margin-top: 6px; }

/* ---------- pages ---------- */
.page { display: grid; gap: 14px; align-content: start; min-width: 0; }
.page-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.page-head h2 { font-size: 18px; }
.head-actions { margin-left: auto; display: flex; gap: 10px; align-items: center; }
.kpi-inline { font-weight: 700; font-size: 12px; border: 2px solid var(--ink); padding: 2px 8px; background: var(--accent); order: 5; flex-basis: 100%; }
.kpi-inline:empty { display: none; }
.empty { border: 3px dashed var(--ink); padding: 24px 16px; text-align: center; font-weight: 700; }
.empty p { margin: 6px 0; }

/* floating add button, above the tab bar */
.btn.fab {
  position: fixed; right: max(14px, env(safe-area-inset-right)); bottom: calc(var(--dock) + 14px); z-index: 25;
  width: 58px; height: 58px; padding: 0; font-size: 30px; box-shadow: var(--shadow);
}
.fab .fab-text { display: none; }
.page:has(.bulkbar:not([hidden])) .fab { display: none; }
.page:has(.fab) { padding-bottom: 76px; } /* the last row scrolls clear of the button */

/* "⋯ MORE": export, import, backup */
.more { position: relative; }
.more .menu { display: none; position: absolute; right: 0; top: calc(100% + 8px); z-index: 20; background: var(--bg); border: var(--b); box-shadow: var(--shadow); padding: 10px; gap: 10px; min-width: 190px; }
.more.open .menu { display: grid; }

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.toolbar input[type=search] { flex: 1 1 160px; width: auto; }
.toolbar > select { flex: 1 1 150px; width: auto; }
.filters { display: none; flex-basis: 100%; gap: 8px; }
.filters.open { display: grid; }
.filter-btn.active { background: var(--accent); }

.bulkbar {
  position: fixed; left: 10px; right: 10px; bottom: calc(var(--dock) + 10px); z-index: 25;
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 10px; border: var(--b); background: var(--accent); box-shadow: var(--shadow);
}
.bulkbar strong { flex-basis: 100%; }
.bulkbar input { flex: 1 1 100%; }

/* rows: the phone layout of the collection and the wishlist */
.items { list-style: none; margin: 0; padding: 0; display: grid; border: var(--b); box-shadow: var(--shadow-sm); }
.item {
  display: grid; grid-template-columns: auto 48px minmax(0, 1fr) auto; gap: 6px 10px; align-items: center;
  padding: 10px; border-bottom: 2px solid var(--ink);
}
.item:last-child { border-bottom: 0; }
.item.picked, .item.deal-row { background: var(--pick); }
.item .thumb-btn img, .item .thumb-btn .ph { width: 48px; }
.item-main { min-width: 0; display: grid; gap: 2px; }
.item-main .link { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }
.item-main .sub { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-right { text-align: right; display: grid; gap: 2px; justify-items: end; }
.item-right strong { font-size: 15px; }
.item-actions { grid-column: 3 / -1; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.item-actions .stepper { margin-right: auto; }
.item.no-pick { grid-template-columns: 48px minmax(0, 1fr) auto; }
.item.no-pick .item-actions { grid-column: 2 / -1; }
.item-actions select, .item-actions .cell-input { width: auto !important; flex: 1 1 calc(50% - 4px); min-width: 0; }
.item.no-pick .item-actions .btn:not([aria-label]) { flex: 1 1 auto; } /* GOT IT fills the row beside ✕ */

.chips { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 2px; }
.chips span { font-size: 10px; font-weight: 700; border: 2px solid var(--ink); padding: 0 4px; white-space: nowrap; }

.thumb-btn { all: unset; cursor: pointer; display: block; }
.thumb-btn img, .thumb-btn .ph { width: 40px; aspect-ratio: 63 / 88; object-fit: cover; border: 2px solid var(--ink); background: #eee; display: block; }
.thumb-btn:focus-visible img { outline: 3px solid var(--accent); }
.stepper { display: inline-flex; align-items: center; border: 2px solid var(--ink); }
.stepper b { min-width: 3ch; text-align: center; padding: 0 4px; font-variant-numeric: tabular-nums; }
.step { all: unset; cursor: pointer; width: 40px; height: 40px; display: grid; place-items: center; font-weight: 700; font-size: 18px; }
.step:active, .step:focus-visible { background: var(--accent); }
.step.armed { background: var(--danger); color: #fff; }
.cell-input { padding: 6px 8px !important; }
.pill { font-size: 11px; font-weight: 700; border: 2px solid var(--ink); padding: 1px 6px; white-space: nowrap; }
.pill.deal { background: var(--ink); color: var(--accent); }

/* tables: wide screens only (the collection's TABLE layout) */
.table-scroll { overflow-x: auto; border: var(--b); box-shadow: var(--shadow); }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { text-align: left; padding: 6px 10px; border-bottom: 2px solid var(--ink); }
th { position: sticky; top: 0; background: var(--accent); z-index: 1; }
.grid-table th { white-space: nowrap; font-size: 12px; }
.grid-table td { vertical-align: middle; }
.grid-table tr:last-child td { border-bottom: 0; }
.grid-table tr.picked { background: var(--pick); }
td.thumb { width: 44px; padding: 4px 6px; }
.note-line { max-width: 28ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-actions { white-space: nowrap; }
.row-actions .btn + .btn { margin-left: 6px; }
.grid-table .step { width: 26px; height: 26px; font-size: 14px; }
.grid-table select { padding: 4px 24px 4px 6px; width: auto; min-height: 0; font-size: 13px; }
.wide-only { display: none !important; }

/* card tiles: collection grid and set pages */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 16px 12px; }
.tile { position: relative; display: grid; gap: 3px; align-content: start; min-width: 0; }
.tile-img { all: unset; cursor: pointer; display: block; }
.tile-img img, .tile-img .ph { width: 100%; aspect-ratio: 63 / 88; object-fit: cover; border: var(--b); box-shadow: var(--shadow-sm); background: #eee; display: block; transition: transform .08s; }
.tile-img:focus-visible img { box-shadow: 6px 6px 0 var(--accent), 9px 9px 0 var(--ink); }
.tile.picked .tile-img img { outline: 4px solid var(--accent); }
.tile .qty { position: absolute; top: -8px; right: -8px; background: var(--accent); border: var(--b); font-weight: 700; font-size: 12px; padding: 0 5px; }
.tile .tile-pick { position: absolute; top: 6px; left: 6px; }
.tile .quick { position: absolute; top: 4px; left: 4px; width: 40px; height: 40px; font: inherit; font-weight: 700; font-size: 20px; border: var(--b); background: var(--accent); color: var(--ink); cursor: pointer; padding: 0; }
.tile.missing .tile-img img { filter: grayscale(1) contrast(.7); opacity: .4; }
.tile.missing .tile-img .ph { opacity: .4; }
.tile-name { font-weight: 700; font-size: 12px; margin-top: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile-foot { display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.tile .sub { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (hover: hover) {
  .tile-img:hover img { transform: translate(-2px, -2px); box-shadow: 6px 6px 0 var(--accent), 9px 9px 0 var(--ink); }
  .tile .quick { opacity: 0; transition: opacity .1s; }
  .tile:hover .quick, .tile .quick:focus-visible { opacity: 1; }
}

/* sets */
.sets-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
.set-card { display: grid; gap: 8px; padding: 12px; border: var(--b); box-shadow: var(--shadow-sm); color: var(--ink); text-decoration: none; background: var(--bg); }
.set-card:active, .set-card:focus-visible { background: var(--tint); outline: none; }
.set-name { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.set-foot { display: flex; gap: 10px; font-size: 12px; font-weight: 700; }
.set-foot strong { margin-left: auto; }
.progress { height: 14px; border: 2px solid var(--ink); background: #fff; }
.progress i { display: block; height: 100%; background: var(--ink); }
.set-hero { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; align-items: stretch; }
.set-progress { grid-column: 1 / -1; border: var(--b); box-shadow: var(--shadow-sm); padding: 12px; display: grid; gap: 8px; }
.set-progress .big { font-size: 26px; font-weight: 700; }
.set-progress .progress { height: 22px; }
.set-progress .progress i { background: var(--accent); border-right: 2px solid var(--ink); }
.set-actions { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 10px; }
.set-actions .btn { flex: 1 1 auto; }
@media (hover: hover) { .set-card:hover { background: var(--tint); transform: translate(-2px, -2px); box-shadow: 6px 6px 0 var(--ink); } }

/* stats */
#stats-body, #set-detail, #sets-index { display: grid; gap: 14px; align-content: start; }
.kpis { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.kpi { border: var(--b); box-shadow: var(--shadow-sm); padding: 8px 10px; display: grid; gap: 2px; align-content: start; color: var(--ink); text-decoration: none; min-width: 0; }
.kpi:first-child { background: var(--accent); grid-column: 1 / -1; }
.kpi-label { font-size: 11px; font-weight: 700; letter-spacing: .05em; }
.kpi-value { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.kpi:first-child .kpi-value { font-size: 30px; }
.stats-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; align-items: start; }
.panel-box { border: var(--b); box-shadow: var(--shadow-sm); padding: 12px; display: grid; gap: 10px; min-width: 0; }
.panel-box h3, .cd-info h3, .entry-form h3 { margin: 0; font-size: 13px; letter-spacing: .05em; }
.bars-list { display: grid; gap: 8px; }
.bar-row { display: grid; grid-template-columns: minmax(70px, 36%) 1fr auto 3ch; gap: 8px; align-items: center; font-size: 12px; }
.bar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { height: 12px; }
.bar-track i { display: block; height: 100%; background: var(--ink); border-radius: 0 4px 4px 0; }
.bar-value { font-weight: 700; font-variant-numeric: tabular-nums; }
.bar-n { text-align: right; }
.card-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.card-list li { display: grid; grid-template-columns: 40px minmax(0, 1fr) auto; gap: 10px; align-items: center; }
.card-list li .sub { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.movers { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; font-size: 13px; }
.movers li { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 0 8px; }
.movers li > .sub:last-child { grid-column: 1 / -1; }
.log { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; font-size: 12px; }

/* charts */
.chart { position: relative; width: 100%; touch-action: pan-y; }
.chart svg { display: block; overflow: visible; }
.chart .grid-line { stroke: #ccc; stroke-width: 1; }
.chart .axis { font: 11px var(--font); fill: var(--muted); }
.chart .line { fill: none; stroke: var(--ink); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { fill: var(--accent); opacity: .55; }
.chart .dot { fill: var(--ink); stroke: #fff; stroke-width: 2; }
.chart .cross { stroke: var(--ink); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .tip { position: absolute; top: 0; pointer-events: none; background: #fff; border: 2px solid var(--ink); box-shadow: 3px 3px 0 var(--ink); padding: 3px 8px; display: grid; font-size: 12px; min-width: 100px; }

/* ---------- accounts ---------- */
.auth { display: grid; place-items: start center; padding-top: 4vh; }
.auth-card { width: min(420px, 100%); padding: 16px; display: grid; gap: 12px; }
.auth-tabs { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.auth-note { margin: 0; font-size: 12px; font-weight: 700; }
.auth-error { margin: 0; color: var(--danger); font-weight: 700; font-size: 13px; min-height: 1em; }
.auth-tabs.single { grid-template-columns: minmax(0, 1fr); }
.field-wrap { display: grid; gap: 4px; }
.field small { font-weight: 400; color: var(--muted); margin-left: 6px; }
.field-hint { margin: 0; font-size: 11px; font-weight: 700; color: var(--muted); min-height: 1.2em; }
.field-hint.error { color: var(--danger); }
.field-hint.ok { color: var(--good); }
input[aria-invalid="true"] { border-color: var(--danger); }
.pw-wrap { display: flex; gap: 8px; }
.pw-wrap input { flex: 1; min-width: 0; }
.pw-toggle { flex: none; min-width: 70px; }
.pw-meter { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; height: 8px; }
.pw-meter i { border: 2px solid var(--ink); background: #fff; }
.pw-meter i.on { background: var(--danger); }
.pw-meter[data-score="2"] i.on { background: var(--accent); }
.pw-meter[data-score="3"] i.on, .pw-meter[data-score="4"] i.on { background: var(--good); }
.invite-form { display: grid; gap: 10px; }
.invites .item { grid-template-columns: auto minmax(0, 1fr); }
.invites .item-right { display: none; }
.invites .item.no-pick .item-actions { grid-column: 1 / -1; }
.invite-code { font: 700 18px var(--font); letter-spacing: .08em; background: var(--accent); border: var(--b); padding: 4px 8px; white-space: nowrap; }
.item.inactive .invite-code { background: #eee; color: var(--muted); text-decoration: line-through; }
.chips span.dim { color: var(--muted); border-color: var(--muted); }
.auth-error:empty { display: none; }
.account { display: grid; gap: 14px; max-width: 720px; }
.radios { display: grid; gap: 8px; }
.radio, .check { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; font-weight: 700; }
.radio { border: 2px solid var(--ink); padding: 10px; }
.radio:has(input:checked) { background: var(--accent); }
.radio span { display: grid; gap: 2px; }
.radio small { font-weight: 400; color: var(--muted); font-size: 12px; }
.radio input[type=radio] { width: 22px; height: 22px; margin: 0; accent-color: var(--ink); flex: none; }
.check { align-items: center; font-size: 13px; }
.link-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.link-row input { flex: 1 1 220px; width: auto; min-width: 0; }
.people { display: grid; gap: 14px; }
.list-title { margin: 6px 0 0; font-size: 13px; letter-spacing: .05em; }
.avatar { width: 48px; height: 48px; display: grid; place-items: center; border: var(--b); background: var(--accent); font-weight: 700; }
.note-banner { margin: 0; border: 2px dashed var(--ink); padding: 8px 10px; font-size: 12px; font-weight: 700; }
.trade { display: flex; flex-wrap: wrap; gap: 6px 16px; align-items: baseline; padding: 10px 12px; background: var(--accent); font-size: 13px; font-weight: 700; }
.trade strong { background: var(--ink); color: var(--accent); padding: 1px 6px; }
.tile .pill { justify-self: start; margin-top: 2px; font-size: 10px; }
.tile.match .tile-img img { outline: 4px solid var(--accent); outline-offset: -1px; }
.tile-img:disabled { cursor: default; }

/* ---------- dialogs: full-screen sheets on a phone ---------- */
dialog {
  padding: 0; color: var(--ink); background: var(--bg);
  width: 100%; max-width: 100%; height: 100%; max-height: 100%; margin: 0; border: 0;
}
dialog.box { border: 0; box-shadow: none; }
html:has(dialog[open]) { overflow: hidden; } /* the page behind a sheet stays put */
dialog { overscroll-behavior: contain; }
dialog[open] { animation: sheet-up .2s ease-out; }
dialog::backdrop { background: rgba(255, 255, 255, .7); }
.dlg-head {
  display: flex; gap: 12px; align-items: center; flex-wrap: nowrap; position: sticky; top: 0; z-index: 2; background: var(--bg);
  padding: max(10px, env(safe-area-inset-top)) 14px 10px; border-bottom: var(--b);
}
.dlg-head h2 { margin-right: auto; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.dlg-body { padding: 14px 14px calc(24px + var(--safe-b)); }

.card-detail { display: grid; grid-template-columns: minmax(0, 1fr); gap: 18px; align-items: start; }
.cd-img { width: min(240px, 62vw); justify-self: center; }
.cd-info { display: grid; gap: 10px; min-width: 0; }
.cd-info h3 { margin-top: 8px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.cd-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.cd-actions .btn { flex: 1 1 auto; }
.mini th { position: static; }
.mini td, .mini th { padding: 6px; }
.small-seg .btn { padding: 2px 10px; min-height: 32px; font-size: 11px; box-shadow: 2px 2px 0 var(--ink); }
.copies { display: grid; gap: 6px; }
.copy { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 10px; align-items: center; border: 2px solid var(--ink); padding: 6px 8px; font-size: 13px; }

.entry-form { display: grid; gap: 12px; }
.entry-form.sell { margin-top: 20px; padding-top: 16px; border-top: var(--b); }
.entry-top { display: grid; grid-template-columns: 64px minmax(0, 1fr); gap: 12px; align-items: center; }
.entry-top img, .entry-top .ph { width: 64px; aspect-ratio: 63 / 88; object-fit: cover; border: 2px solid var(--ink); background: #eee; }
.price-line { font-weight: 700; margin-top: 4px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.field { display: grid; gap: 4px; font-size: 11px; font-weight: 700; }
.entry-form .actions .btn { flex: 1 1 auto; }
#add-results { margin-bottom: 4px; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--dock) + 16px); transform: translate(-50%, 220%); z-index: 40;
  background: var(--ink); color: var(--accent); font-weight: 700; padding: 10px 16px; border: 3px solid var(--accent);
  box-shadow: var(--shadow-sm); transition: transform .2s; max-width: calc(100vw - 32px); text-align: center;
}
.toast:not(.on) { visibility: hidden; transition: transform .2s, visibility 0s .2s; }
.toast.on { transform: translate(-50%, 0); }
.toast:empty { display: none; }

/* ================= wider screens ================= */
@media (min-width: 901px) {
  body { grid-template-rows: auto 1fr; align-content: stretch; gap: 16px; padding: 16px; height: 100%; min-height: 100vh; }
  html { height: 100%; }
  .bar { gap: 16px; }
  .bar h1 { font-size: 22px; }
  body.on-scan .status { display: flex; }

  .tabs { position: static; display: flex; border: var(--b); box-shadow: var(--shadow-sm); padding: 0; }
  .tabs a { flex-direction: row; min-height: 0; font-size: 13px; padding: 6px 12px; }
  .tabs svg { display: none; }
  .auth { padding-top: 10vh; }

  .btn { min-height: 0; }
  .btn.small { padding: 5px 10px; min-height: 0; font-size: 12px; }
  .actions kbd { display: inline; }
  select, input[type=search], input[type=number], input[type=password], input:not([type]), input[list], textarea { font-size: 14px; padding: 8px; min-height: 0; }
  select { padding-right: 28px; }
  input[type=checkbox] { width: 18px; height: 18px; }

  .view-scan { grid-template-rows: 1fr auto; gap: 16px; }
  .layout { grid-template-columns: minmax(0, 1.6fr) minmax(320px, 1fr); gap: 16px; }
  .feed-wrap { min-height: 300px; }
  .panel { padding: 20px; overflow: auto; min-height: 420px; }
  .idle-card { width: 120px; height: 168px; }
  .found { grid-template-columns: minmax(150px, 46%) 1fr; gap: 20px; }
  .found .meta { display: block; }
  .found .card-stage, .found .meta > .tag, .found .name, .found .set, .found .price-row, .found .selectors, .found .actions, .found .note { grid-row: auto; grid-column: auto; }
  .found .selectors { margin-top: 0; }
  .name { font-size: 24px; margin-top: 12px; }
  .price-row { margin: 14px 0; }
  .price { font-size: 26px; }
  .price.none { font-size: 16px; }
  .selectors { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 16px; }
  .found .actions { position: static; flex-wrap: wrap; padding: 0; margin: 0; }
  .found .actions .add { flex: 0 0 auto; }
  .cands { gap: 16px; margin: 18px 0; }
  .session { padding: 12px 16px 16px; }
  .session-head { gap: 16px; margin-bottom: 10px; }
  .session-total { font-size: 18px; }
  .strip { gap: 18px; min-height: 120px; padding: 4px 8px 12px 2px; }
  .chip, .chip img, .chip .ph { width: 72px; }

  .page { gap: 16px; }
  .page-head { gap: 12px; }
  .page-head h2 { font-size: 22px; }
  .kpi-inline { order: 0; flex-basis: auto; font-size: 14px; }
  .btn.fab { position: static; width: auto; height: auto; padding: 5px 10px; font-size: 12px; box-shadow: 3px 3px 0 var(--ink); }
  .page:has(.fab) { padding-bottom: 0; }
  .fab .fab-text { display: inline; }
  .fab-plus { font-size: inherit; }
  .more-btn { display: none; }
  .more .menu { display: flex; position: static; border: 0; box-shadow: none; padding: 0; min-width: 0; background: none; }

  .toolbar { gap: 10px; }
  .toolbar input[type=search] { flex: 1 1 240px; }
  .toolbar > select { flex: 0 0 auto; min-width: 170px; }
  .filter-btn { display: none; }
  .filters, .filters.open { display: flex; flex-basis: auto; gap: 10px; }
  .filters select { width: auto; min-width: 150px; }

  .bulkbar { position: static; box-shadow: var(--shadow-sm); padding: 10px; }
  .bulkbar strong { flex-basis: auto; }
  .bulkbar input { flex: 0 1 260px; padding: 5px 8px; }

  .wide-only { display: inline-flex !important; }
  .item { grid-template-columns: auto 48px minmax(0, 1fr) auto auto; padding: 8px 12px; }
  .item-actions { grid-column: auto; flex-wrap: nowrap; }
  .item.no-pick { grid-template-columns: 48px minmax(0, 1fr) auto auto; }
  .item.no-pick .item-actions { grid-column: auto; }
  .item-actions select { flex: 0 0 auto; }
  .item-actions .cell-input { flex: 0 0 11ch; }
  .item.no-pick .item-actions .btn:not([aria-label]) { flex: 0 0 auto; }
  .step { width: 28px; height: 28px; font-size: 15px; }
  .grid-table tbody tr:hover { background: var(--tint); }

  .tiles { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 22px 18px; }
  .set-tiles { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
  .tile .quick { width: 30px; height: 30px; font-size: 18px; }

  .sets-grid { grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 16px; }
  .set-hero { grid-template-columns: minmax(220px, 2fr) repeat(2, minmax(140px, 1fr)) auto; gap: 16px; }
  .set-progress { grid-column: auto; }
  .set-progress .big { font-size: 28px; }
  .set-actions { grid-column: auto; display: grid; align-content: start; }

  .kpis { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; }
  .kpi { padding: 10px 12px; }
  .kpi:first-child { grid-column: auto; }
  .kpi-value, .kpi:first-child .kpi-value { font-size: 24px; }
  .stats-grid { grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 16px; }
  .panel-box { padding: 12px 14px; }
  .bar-row:hover .bar-track i { background: #444; }

  dialog { width: min(640px, 94vw); height: auto; max-height: 88vh; margin: auto; }
  dialog.box { border: var(--b); box-shadow: var(--shadow); }
  dialog.wide { width: min(1000px, 94vw); }
  dialog[open] { animation: none; }
  .dlg-head { padding: 14px; }
  .dlg-head h2 { font-size: 18px; }
  .dlg-body { padding: 16px; }
  .card-detail { grid-template-columns: minmax(200px, 300px) 1fr; gap: 24px; }
  .cd-img { width: auto; }
  .cd-actions .btn, .entry-form .actions .btn { flex: 0 0 auto; }
  .form-grid { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
  .toast { bottom: 20px; }
  .invites .item { grid-template-columns: auto minmax(0, 1fr) auto; }
  .invites .item.no-pick .item-actions { grid-column: auto; }
}

@media (min-width: 901px) and (max-width: 1200px) { .found { grid-template-columns: minmax(0, 1fr); } }

@keyframes fly-in {
  from { opacity: 0; transform: translate(110%, -20%) rotate(18deg) scale(.8); }
  to { opacity: 1; transform: none; }
}
@keyframes float { 0%, 100% { translate: 0 0; } 50% { translate: 0 -7px; } }
@keyframes drop-in { from { opacity: 0; transform: translateY(-60px) rotate(-8deg); } to { opacity: 1; transform: none; } }
@keyframes pulse { 0%, 100% { transform: scaleY(.4); } 50% { transform: scaleY(1); } }
@keyframes sheet-up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* Per-card marketplace and personal purchase history. */
.scan-price-links,.history-controls{display:flex;gap:10px;align-items:end;flex-wrap:wrap}.scan-price-links{margin:10px 0}.history-controls label{flex:1;min-width:160px}.history-body h3{border-top:var(--b);padding-top:14px;margin-top:24px}.history-body .muted{color:var(--muted);font-size:12px}.history-body #price-chart{display:block;width:100%;height:auto;background:#fafafa;border:1px solid #ddd;margin:12px 0}.history-body .chart-label{font:11px var(--font);fill:#555}.history-body .table-scroll{max-height:240px;overflow:auto}.history-body table{border-collapse:collapse;width:100%;text-align:left}.history-body td,.history-body th{padding:8px;border-bottom:1px solid #ddd}.history-body summary{cursor:pointer;margin:12px 0}.history-body fieldset{border:0;margin:0;padding:0;min-width:0}.history-body fieldset:disabled{opacity:.6}.purchase-grid{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:12px;margin:14px 0}.purchase-grid label{display:grid;gap:4px;font-size:11px;font-weight:700}.purchase-grid .wide{grid-column:1/-1}.purchase-grid input,.purchase-grid textarea,.purchase-grid select{width:100%;min-width:0}.purchase-grid textarea{resize:vertical}.purchase-entry{border-top:2px solid #bbb;padding:14px 0}.purchase-entry a{color:var(--ink);display:inline-block;margin-right:12px}.purchase-notes{white-space:pre-wrap;overflow-wrap:anywhere}.purchase-entry .compact{font:inherit;padding:6px 9px;background:white;border:2px solid var(--ink);cursor:pointer}.history-body #history-status,.history-body #purchase-status{overflow-wrap:anywhere}@media(max-width:550px){.purchase-grid{grid-template-columns:1fr 1fr}.history-controls label{flex-basis:100%;min-width:0}}
