/* xTCGx.com — original design, system fonts only (nothing external). Mobile-first; light + dark.
   Palette: black / gray / white with a subtle gold accent. Have/Want/Trade keep their own colors.
   Everything is centered except the data itself (card grids, tables, text pages). */
:root {
  --bg: #f5f5f4; --surface: #fff; --surface-2: #efefed; --text: #18181b; --muted: #64646c; --border: #dcdcd8;
  --accent: #18181b; --on-accent: #fff; --gold: #8a6d26;
  --have: #2f7d4f; --have-soft: #e1f0e6; --want: #3b6fb6; --want-soft: #e3ebf7; --trade: #8a4f91; --trade-soft: #f1e5f2;
  --warn: #a86400; --bad: #c42f2f; --radius: 10px; color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f0f10; --surface: #18181b; --surface-2: #232327; --text: #ececec; --muted: #9a9aa2; --border: #2e2e33;
    --accent: #ececec; --on-accent: #18181b; --gold: #d4b464;
    --have: #5cc28a; --have-soft: #16291e; --want: #7aa6e6; --want-soft: #1a2436; --trade: #c995cf; --trade-soft: #2a1d2c;
    --warn: #f0a83a; --bad: #f07070; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: #f5f5f4; color: #18181b; background: var(--bg); color: var(--text); font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; overflow-x: hidden; }
a { color: var(--gold); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.05rem; }
h3 { font-size: .9rem; margin-top: 12px; }
p { margin: 4px 0; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 1px; }
.muted { color: var(--muted); }
.center { text-align: center; justify-content: center; }
p.center { margin: 10px 0 8px; }
.empty { color: var(--muted); text-align: center; padding: 24px 0; }
.error { color: var(--bad); margin: 0; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }

/* ---------- controls ---------- */
button, input, select, textarea { font: inherit; color: inherit; }
input, select, textarea {
  height: 32px; padding: 0 8px; border: 1px solid var(--border); border-radius: 7px; background: var(--surface); min-width: 0;
}
textarea { height: auto; padding: 6px 8px; resize: vertical; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 4px; height: 30px; padding: 0 10px;
  border: 1px solid var(--border); border-radius: 7px; background: var(--surface); font-weight: 600; font-size: .85rem;
  cursor: pointer; white-space: nowrap; color: var(--text);
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { opacity: .88; background: var(--accent); }
.btn.danger { color: var(--bad); }
.btn.icon { width: 30px; padding: 0; }
.btn:disabled { opacity: .5; cursor: default; }

/* ---------- header: computer = logo left · menu middle · account right; phone = logo middle, menu below ---------- */
.top {
  position: sticky; top: 0; z-index: 10; display: grid; grid-template-columns: 1fr auto 1fr; grid-template-areas: "brand nav acct";
  align-items: center; gap: 4px 12px; padding: 7px 12px; padding: 7px max(12px, calc((100% - 1280px) / 2)); background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { grid-area: brand; justify-self: start; display: flex; flex-direction: column; align-items: center; gap: 1px; color: var(--text); line-height: 1; }
.brand:hover { text-decoration: none; }
.brand img { height: 30px; width: auto; display: block; }
.brand small, .foot [data-version] { color: var(--muted); font-size: .68rem; font-weight: 600; }
.top nav { grid-area: nav; display: flex; justify-content: center; gap: 2px; }
.top nav a { padding: 5px 12px; border-radius: 7px; color: var(--muted); font-weight: 600; }
.top nav a:hover { background: var(--surface-2); text-decoration: none; }
.top nav a.active { background: var(--surface-2); color: var(--text); box-shadow: inset 0 -2px 0 var(--gold); }
.top-right { grid-area: acct; justify-self: end; display: flex; align-items: center; gap: 8px; }
.sync { font-size: .75rem; font-weight: 700; color: var(--have); white-space: nowrap; transition: opacity .6s; }
.sync.saving { color: var(--muted); }
.sync.error { color: var(--bad); }
.sync.fade { opacity: 0; }
main { display: block; max-width: 1280px; margin: 0 auto; padding: 14px 12px 32px; min-height: 70vh; }
.foot { max-width: 1280px; margin: 0 auto; padding: 14px 12px 20px; border-top: 1px solid var(--border); font-size: .75rem; color: var(--muted); text-align: center; }
.wordmark { font-weight: 900; } /* footer text "xTCGx.com" */
.wordmark b { color: var(--gold); }
.head { display: flex; flex-direction: column; align-items: center; gap: 2px; margin-bottom: 10px; text-align: center; }

/* ---------- totals bar under the header (collection pages) ---------- */
.statsbar { background: var(--surface); border-bottom: 1px solid var(--border); }
.stats-in { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); max-width: 1280px; margin: 0 auto; padding: 4px 12px; }
.scell { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: center; gap: 0 6px; padding: 1px 8px; line-height: 1.3; border-left: 1px solid var(--border); min-width: 0; }
.scell:first-child { border-left: 0; }
.slabel { font-size: .62rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.scell.have .slabel { color: var(--have); }
.scell.want .slabel { color: var(--want); }
.scell.trade .slabel { color: var(--trade); }
.snum { font-size: .92rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.scell.owned .snum { color: var(--gold); }
.sval { font-size: .76rem; font-weight: 600; white-space: nowrap; }
.savg { font-size: inherit; font-weight: 400; color: var(--muted); }
.srange { font-size: .66rem; color: var(--muted); white-space: nowrap; }
.bar { height: 6px; border-radius: 9px; background: var(--border); overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--have); }
.statsbar > .bar { height: 2px; border-radius: 0; background: transparent; }
.set-progress { display: grid; justify-items: center; gap: 4px; font-size: .8rem; font-weight: 600; }
.set-progress .bar { width: 220px; max-width: 100%; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Sets | Cards | Spreadsheet switch (also the admin tabs) ---------- */
.seg { display: flex; flex-wrap: wrap; justify-content: center; margin: 12px 0 0; }
.toolbar { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 8px; margin: 10px auto 0; }
.toolbar .seg { margin: 0; }
.toolbar .btn { height: 32px; }
.seg .btn { border-radius: 0; margin-left: -1px; }
.seg .btn:first-child { border-radius: 7px 0 0 7px; margin-left: 0; }
.seg .btn:last-child { border-radius: 0 7px 7px 0; }
.seg .btn.on { background: var(--accent); border-color: var(--accent); color: var(--on-accent); position: relative; }

/* ---------- search (magnifying glass + the box it opens), Filter button and the panel it opens ---------- */
.search-box { display: flex; max-width: 640px; margin: 10px auto 0; }
.search-box input { flex: 1 1 auto; }
.btn.mag-btn { width: 32px; }
.mag-btn.on { background: var(--surface-2); border-color: var(--muted); }
.mag { position: relative; width: 11px; height: 11px; margin: -3px 0 0 -3px; border: 2px solid currentColor; border-radius: 50%; }
.mag::after { content: ""; position: absolute; right: -4px; bottom: -5px; width: 2px; height: 6px; border-radius: 1px; background: currentColor; transform: rotate(-45deg); }
.filter-btn::before { content: ""; width: 12px; height: 10px; margin-right: 2px; background: currentColor; clip-path: polygon(0 0, 100% 0, 62% 50%, 62% 100%, 38% 85%, 38% 50%); }
.filter-btn.active::after { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--gold); }
.filter-btn[aria-expanded="true"] { background: var(--surface-2); }
.filter-panel { display: flex; flex-wrap: wrap; justify-content: center; align-items: end; gap: 8px 12px; max-width: 900px; margin: 8px auto 0; padding: 10px 12px; }
.ctl { display: grid; gap: 2px; font-size: .7rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.ctl select, .ctl input { color: var(--text); font-size: .85rem; font-weight: 400; text-transform: none; letter-spacing: 0; }
.pair { display: flex; gap: 4px; }
.pair input { width: 84px; }
.check { display: flex; align-items: center; gap: 6px; height: 32px; font-size: .8rem; }
.check input { height: auto; }
.tools { flex-basis: 100%; display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 6px; padding-top: 10px; border-top: 1px solid var(--border); }

/* ---------- sets ---------- */
.serie { display: flex; align-items: center; justify-content: center; gap: 10px; margin: 18px 0 0; }
.serie h2 { font-size: 1.1rem; }
.fold { all: unset; cursor: pointer; display: inline-flex; align-items: center; gap: 8px; color: var(--text); }
.fold:hover { color: var(--gold); }
.fold:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.count { font-size: .7rem; font-weight: 600; padding: 1px 7px; border: 1px solid var(--border); border-radius: 9px; background: var(--surface-2); color: var(--muted); }
.chev { display: inline-block; font-size: .75rem; transition: transform .15s; }
.closed .chev { transform: rotate(-90deg); }
.set-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; margin-top: 10px; }
.set-tile { position: relative; padding: 8px; }
.set-tile > a { display: grid; gap: 4px; color: var(--text); }
.set-tile > a:hover { text-decoration: none; }
.set-tile:hover { border-color: var(--muted); }
.set-tile.done { border-color: var(--gold); }
.set-tile.off { border-style: dashed; }
.set-tile.off > a { opacity: .35; filter: grayscale(1); }
.set-logo { height: 52px; display: flex; align-items: center; justify-content: center; }
.set-logo img { max-height: 100%; object-fit: contain; }
.logo-text { font-weight: 800; color: var(--muted); text-align: center; font-size: .85rem; }
.set-name { font-weight: 700; font-size: .85rem; line-height: 1.2; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.set-meta { font-size: .75rem; color: var(--muted); }
.set-head { display: flex; flex-direction: column; align-items: center; gap: 6px; margin-bottom: 10px; text-align: center; }
.set-head .row { justify-content: center; }
.set-head .set-logo { width: 110px; height: 44px; }
.sym { height: 14px; width: auto; max-width: 22px; object-fit: contain; vertical-align: -2px; margin-right: 5px; }
h1 .sym { height: 22px; max-width: 32px; vertical-align: -3px; margin-right: 8px; }
.card-group .sym { height: 18px; max-width: 26px; }

/* on/off switch (admin: count or hide a set / series). Series: always visible; set tiles: on hover */
.switch { position: relative; width: 28px; height: 16px; flex: none; padding: 0; border: 0; border-radius: 9px; background: var(--border); cursor: pointer; opacity: 0; transition: opacity .15s; }
.serie .switch, .set-tile:hover .switch, .set-tile:focus-within .switch { opacity: 1; }
@media (hover: none) { .switch { opacity: 1; } } /* phones/tablets: no hover, so always show */
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 12px; height: 12px; border-radius: 50%; background: var(--surface); transition: transform .15s; }
.switch[aria-checked="true"] { background: var(--gold); }
.switch[aria-checked="true"]::after { transform: translateX(12px); }
.set-tile .switch { position: absolute; top: 6px; right: 6px; }

/* ---------- cards ---------- */
.card-group { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 4px 10px; margin: 20px 0 8px; font-size: 1.05rem; }
.card-group a { color: var(--text); }
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.sentinel { height: 1px; }
.card { display: flex; flex-direction: column; gap: 4px; padding: 6px; content-visibility: auto; contain-intrinsic-size: auto 330px; }
.card.owned { border-color: var(--have); }
.card-img { position: relative; padding: 0; border: 0; background: none; cursor: pointer; aspect-ratio: 245 / 342; }
.card-img img { width: 100%; height: 100%; object-fit: contain; border-radius: 5px; }
.card:not(.owned) .card-img img { opacity: .6; }
.badge { position: absolute; top: 4px; right: 4px; background: var(--have); color: #fff; font-weight: 800; font-size: .75rem; padding: 1px 6px; border-radius: 9px; }
.card-title { padding: 0; border: 0; background: none; text-align: left; font-weight: 700; font-size: .85rem; cursor: pointer; line-height: 1.2; }
.card-title:hover { color: var(--gold); }
.card-meta { display: flex; justify-content: space-between; gap: 4px; font-size: .75rem; color: var(--muted); }
.card-meta span:last-child { color: var(--text); font-weight: 600; }
.chips { display: flex; gap: 3px; margin-top: auto; }
.chip { flex: 1; text-align: center; font-size: .72rem; font-weight: 700; padding: 2px 4px; border-radius: 6px; background: var(--surface-2); color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.chip.nz.have { background: var(--have-soft); color: var(--have); }
.chip.nz.want { background: var(--want-soft); color: var(--want); }
.chip.nz.trade { background: var(--trade-soft); color: var(--trade); }
.steppers { display: grid; gap: 3px; margin-top: auto; }
.stepper { display: grid; grid-template-columns: 40px 24px 1fr 24px; gap: 3px; align-items: center; }
.stepper label { font-size: .68rem; font-weight: 800; text-transform: uppercase; }
.stepper.have label { color: var(--have); }
.stepper.want label { color: var(--want); }
.stepper.trade label { color: var(--trade); }
.stepper button { height: 24px; padding: 0; border: 1px solid var(--border); border-radius: 6px; background: var(--surface-2); cursor: pointer; font-weight: 800; }
input.qty { height: 24px; width: 100%; padding: 0 2px; text-align: center; font-weight: 700; -moz-appearance: textfield; font-variant-numeric: tabular-nums; }
input.qty::-webkit-inner-spin-button, input.qty::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
input.qty.nz.have { background: var(--have-soft); border-color: var(--have); color: var(--have); }
input.qty.nz.want { background: var(--want-soft); border-color: var(--want); color: var(--want); }
input.qty.nz.trade { background: var(--trade-soft); border-color: var(--trade); color: var(--trade); }

/* ---------- spreadsheet + tables ---------- */
.sheet-wrap { overflow-x: auto; }
.sheet { width: 100%; border-collapse: collapse; font-size: .82rem; font-variant-numeric: tabular-nums; }
.sheet th, .sheet td { padding: 3px 6px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
.sheet thead th { background: var(--surface-2); font-size: .7rem; text-transform: uppercase; color: var(--muted); }
.sheet thead button { all: unset; cursor: pointer; }
.sheet [aria-sort="ascending"] button::after { content: " ▲"; }
.sheet [aria-sort="descending"] button::after { content: " ▼"; }
.sheet .r { text-align: right; }
.sheet td.q { width: 50px; padding: 2px 3px; }
.sheet td.q input, .sheet td.q .chip { width: 46px; display: block; }
.sheet td.name button { all: unset; cursor: pointer; }
.sheet td.name button:hover { color: var(--gold); text-decoration: underline; }
.sheet td.name, .sheet td.setc { max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
.sheet tr.owned td.name { font-weight: 700; }
.sheet tbody tr:hover td { background: var(--surface-2); }
.pager { display: flex; gap: 8px; align-items: center; justify-content: center; margin: 10px 0; }

/* ---------- dialogs + forms ---------- */
dialog { padding: 0; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--text); width: min(860px, calc(100vw - 16px)); max-height: calc(100vh - 16px); }
dialog.small { width: min(340px, calc(100vw - 16px)); }
dialog:not([open]) { display: none; }
dialog.modal { position: fixed; top: 8px; left: 50%; transform: translateX(-50%); z-index: 30; overflow: auto; box-shadow: 0 0 0 100vmax rgba(8, 10, 14, .6); } /* browsers without <dialog> */
dialog::backdrop { background: rgba(8, 10, 14, .6); }
.dlg-close { position: absolute; top: 8px; right: 8px; }
.dlg { display: grid; grid-template-columns: minmax(0, 300px) minmax(0, 1fr); gap: 16px; padding: 14px; }
.dlg-img img { width: 100%; border-radius: 8px; }
.dlg h2 { padding-right: 36px; }
.dlg .steppers, .dlg .chips { max-width: 280px; margin: 8px 0; }
dl { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; margin: 8px 0; font-size: .85rem; }
dt { color: var(--muted); }
dd { margin: 0; }
.prices { width: 100%; border-collapse: collapse; font-size: .8rem; }
.prices th, .prices td { padding: 3px 4px; border-bottom: 1px solid var(--border); text-align: right; white-space: nowrap; }
.prices th:first-child, .prices td:first-child { text-align: left; white-space: normal; }
.prices thead th { color: var(--muted); font-size: .7rem; }
.prices tr.sel td { background: var(--surface-2); }
.prices input { height: auto; margin: 0 4px 0 0; vertical-align: middle; }
.form { display: grid; gap: 8px; padding: 14px; }
.form h2 { padding-right: 36px; }
.field-row { display: grid; gap: 2px; }
.field-row label { font-size: .75rem; font-weight: 700; color: var(--muted); }
input.pin { letter-spacing: .25em; }

/* ---------- profile + admin ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; margin: 12px 0; }
.stat { display: grid; gap: 2px; padding: 8px 10px; font-size: .75rem; text-align: center; }
.stat b { font-size: 1.1rem; font-variant-numeric: tabular-nums; }
.profile-form { max-width: 520px; margin: 0 auto; }
.admin-sec { margin-top: 18px; }
.admin-sec > h2 { margin-bottom: 8px; text-align: center; }
.days { display: grid; gap: 4px; padding: 10px 12px; }
.day { display: grid; grid-template-columns: 44px 1fr 170px; gap: 10px; align-items: center; font-size: .78rem; font-variant-numeric: tabular-nums; }
.day .bar { height: 8px; }
.tops { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.tops h3 { margin: 0 0 4px; text-align: center; }
main > .row, .admin-sec .row { justify-content: center; margin-top: 10px; }
.sheet-wrap .sheet td { overflow-wrap: anywhere; }
.diag { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.diag li { display: grid; grid-template-columns: 52px 1fr; gap: 2px 10px; padding: 8px 10px; }
.diag small { grid-column: 2; color: var(--muted); white-space: pre-wrap; overflow-wrap: anywhere; }
.st { font-size: .7rem; text-align: center; border-radius: 5px; padding: 2px 0; background: var(--surface-2); color: var(--muted); }
.st.pass { background: var(--have-soft); color: var(--have); }
.st.warn { color: var(--warn); }
.st.fail { color: var(--bad); }
pre { background: var(--surface-2); padding: 10px; border-radius: 8px; overflow: auto; font-size: .75rem; }

/* ---------- about / terms / privacy ---------- */
.legal { max-width: 720px; margin: 0 auto; line-height: 1.55; }
.legal h1, .legal > .muted:first-of-type { text-align: center; }
.legal .lead { font-size: 1rem; }
.legal h2 { font-size: 1rem; margin: 18px 0 4px; }

/* ---------- simple version (<div id="simple" hidden>): never shown where the app runs; see js/fallback.js ---------- */
.links { list-style: none; max-width: 960px; margin: 8px auto 0; padding: 0; columns: 3 240px; column-gap: 24px; }
.links li { padding: 3px 0; break-inside: avoid; }
.card > picture img { display: block; width: 100%; height: auto; border-radius: 5px; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 14px; transform: translateX(-50%); z-index: 20; display: flex; gap: 10px; align-items: center;
  max-width: calc(100vw - 24px); padding: 8px 12px; border-radius: 9px; background: var(--text); color: var(--bg); font-size: .85rem;
}
.toast button { background: none; border: 1px solid currentColor; color: inherit; border-radius: 6px; padding: 2px 8px; cursor: pointer; }

/* ---------- small screens ---------- */
@media (max-width: 1100px) { .srange { display: none; } } /* Min–High range: wide screens only (always in the tooltip) */
@media (max-width: 640px) {
  .top { grid-template-areas: ". brand acct" "nav nav nav"; padding-top: 8px; }
  .brand { justify-self: center; }
  .dlg { grid-template-columns: 1fr; }
  .dlg-img { max-width: 240px; margin: 0 auto; }
  .card-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 6px; }
  .set-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 6px; }
  .set-logo { height: 40px; }
  .stats-in { padding: 4px 2px; }
  .scell { gap: 0 4px; padding: 0 3px; line-height: 1.25; }
  .slabel { flex-basis: 100%; text-align: center; }
  .snum { font-size: .82rem; }
  .sval { font-size: .7rem; }
  .savg, .scell.owned .sval { display: none; }
  .filter-panel { justify-content: stretch; }
  .filter-panel .ctl { flex: 1 1 140px; }
  .day { grid-template-columns: 40px 1fr; }
  .day span:last-child { grid-column: 2; }
}
