/* Pokémon TCG Cards For Sale — buyer picker.
   Dark-first, mobile-first. No framework. */

:root {
  --bg: #0e1116;
  --bg-raised: #161b23;
  --bg-sunken: #0a0d12;
  --border: #262d38;
  --border-strong: #39424f;
  --text: #e7ecf3;
  --text-muted: #97a3b4;
  --accent: #ffcb3d;
  --accent-ink: #2a1f00;
  --accent-soft: rgba(255, 203, 61, 0.14);
  --danger: #ff6b6b;
  --danger-soft: rgba(255, 107, 107, 0.14);
  --ok: #4ade80;
  --radius: 12px;
  --radius-sm: 8px;
  --cart-w: 380px;
  --header-h: 60px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f6fa;
    --bg-raised: #ffffff;
    --bg-sunken: #e9edf4;
    --border: #d9e0ea;
    --border-strong: #b9c4d3;
    --text: #16202e;
    --text-muted: #5c6b7f;
    --accent: #f0a500;
    --accent-ink: #ffffff;
    --accent-soft: rgba(240, 165, 0, 0.15);
    --shadow: 0 10px 30px rgba(20, 32, 48, 0.12);
  }
}

*, *::before, *::after { box-sizing: border-box; }

/* Class-based display rules below outrank the UA rule for [hidden], so make
   the attribute win outright. */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow-x: hidden;
}

body.cart-open { overflow: hidden; }

h1, h2, h3 { line-height: 1.25; margin: 0 0 .4em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
p { margin: 0 0 .8em; }
img { max-width: 100%; display: block; }

.wrap {
  width: 100%;
  max-width: 1240px;
  margin: 0 auto;
  padding: 0 16px;
}

.visually-hidden {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.skip-link {
  position: absolute; left: -9999px; top: 0; z-index: 100;
  background: var(--accent); color: var(--accent-ink);
  padding: 10px 16px; border-radius: 0 0 var(--radius-sm) 0;
}
.skip-link:focus { left: 0; }

/* ---------- In-app browser block (Facebook / Messenger) ---------- */

body.inapp-blocked { overflow: hidden; }

.inapp-block {
  position: fixed; inset: 0; z-index: 200;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
  padding: 24px;
}
.inapp-block-card {
  max-width: 420px; width: 100%;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 24px;
  text-align: center;
  box-shadow: var(--shadow);
}
.inapp-block-icon { font-size: 2.2rem; margin: 0 0 8px; }
.inapp-block-card h1 { font-size: 1.2rem; margin-bottom: 10px; }
.inapp-block-card p { color: var(--text-muted); font-size: .92rem; }
.inapp-block-field { display: block; margin: 16px 0; }
.inapp-block-field input {
  width: 100%; font: inherit; font-size: .85rem;
  background: var(--bg-sunken); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 10px 12px;
  text-align: center;
}
.inapp-block-actions { display: flex; gap: 8px; margin-top: 6px; }
.inapp-block-actions .btn { flex: 1; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- Header ---------- */

.site-header {
  position: sticky; top: 0; z-index: 30;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  min-height: var(--header-h);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark { font-size: 1.5rem; }
.brand-title { margin: 0; font-weight: 700; font-size: 1rem; letter-spacing: .01em; }
.brand-sub { margin: 0; font-size: .78rem; color: var(--text-muted); }

.cart-toggle {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--accent); color: var(--accent-ink);
  border: 0; border-radius: 999px;
  padding: 9px 16px; font-size: .92rem; font-weight: 700;
  cursor: pointer;
}
.cart-toggle:hover { filter: brightness(1.06); }

.cart-count {
  background: var(--accent-ink); color: var(--accent);
  border-radius: 999px; min-width: 22px; padding: 1px 7px;
  font-size: .78rem; font-weight: 700; text-align: center;
}

/* ---------- Views ---------- */

main { padding-bottom: 96px; }
.view { padding-top: 22px; }

.notice-area:empty { display: none; }
.notice {
  display: flex; gap: 10px; align-items: flex-start;
  background: var(--accent-soft);
  border: 1px solid color-mix(in srgb, var(--accent) 45%, transparent);
  border-radius: var(--radius);
  padding: 10px 14px; margin-top: 16px;
  font-size: .88rem;
}
.notice button {
  margin-left: auto; background: none; border: 0; cursor: pointer;
  color: inherit; font-size: 1rem; line-height: 1; padding: 2px 4px;
}

/* ---------- Guide ---------- */

.guide {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 24px;
}
.guide p:last-child { margin-bottom: 0; }

.guide-steps {
  margin: 0 0 .9em; padding-left: 1.25em;
  display: grid; gap: 4px;
  color: var(--text-muted); font-size: .93rem;
}
.guide-steps strong { color: var(--text); }
.guide-foot { font-size: .86rem; color: var(--text-muted); }

.group-freshness {
  background: var(--accent-soft);
  border: 1px solid color-mix(in srgb, var(--accent) 45%, transparent);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 18px;
}
.group-freshness p { margin: 0 0 10px; font-size: .88rem; }
.group-freshness .btn-small { margin-top: 0; }

/* ---------- Groups grid ---------- */

.groups-grid {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
}

.group-card {
  display: flex; flex-direction: column; gap: 8px;
  text-align: left; width: 100%;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  color: inherit; font: inherit; cursor: pointer;
  transition: transform .12s ease, border-color .12s ease;
}
.group-card:hover:not(:disabled) {
  transform: translateY(-2px);
  border-color: var(--accent);
}
.group-card:disabled { opacity: .5; cursor: not-allowed; }

.group-card-thumb-wrap {
  aspect-ratio: 5 / 3;
  background: var(--bg-sunken);
  border-radius: var(--radius-sm);
  overflow: hidden;
  display: flex; align-items: center; justify-content: center;
}
.group-card-thumb-wrap.is-empty { font-size: 2.2rem; }
.group-card-thumb { width: auto; height: 100%; object-fit: contain; }

.group-card-name { font-weight: 700; font-size: 1.02rem; }
.group-card-desc { font-size: .82rem; color: var(--text-muted); }

.group-card-stock {
  margin-top: auto; padding-top: 4px;
  font-size: .86rem; font-weight: 700; color: var(--accent);
}
.group-card-stock.is-empty { color: var(--text-muted); font-weight: 500; }

.group-card-picked { font-size: .8rem; color: var(--ok); font-weight: 600; }

/* ---------- Group header ---------- */

.group-header { margin-bottom: 18px; }
.back-btn {
  background: none; border: 0; color: var(--text-muted);
  font: inherit; font-size: .9rem; cursor: pointer;
  padding: 4px 0; margin-bottom: 10px;
}
.back-btn:hover { color: var(--text); }

.group-header-main { display: flex; align-items: center; gap: 14px; }
.group-desc { margin: 0 0 2px; font-size: .9rem; color: var(--text-muted); }
.group-meta { margin: 0; font-size: .86rem; color: var(--text-muted); }

/* ---------- Toolbar ---------- */

.toolbar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin-bottom: 16px;
}
.search-field { flex: 1 1 220px; }
.search-field input, .sort-field select {
  width: 100%; font: inherit; font-size: .95rem;
  background: var(--bg-sunken); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 9px 12px;
}
.search-field input::placeholder { color: var(--text-muted); }
.sort-field { flex: 0 1 200px; }
.toolbar-status { margin: 0; font-size: .85rem; color: var(--text-muted); width: 100%; }

/* ---------- Cards grid ---------- */

.cards-grid {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
}

@media (min-width: 720px) {
  .cards-grid { grid-template-columns: repeat(auto-fill, minmax(186px, 1fr)); }
}

.card-tile {
  position: relative;
  display: flex; flex-direction: column; gap: 6px;
  background: var(--bg-raised);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 8px;
}
.card-tile.is-soldout { opacity: .55; }

.card-thumb-wrap {
  position: relative;
  aspect-ratio: 245 / 342;
  background: var(--bg-sunken);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.card-thumb { width: 100%; height: 100%; object-fit: contain; }

.stock-badge {
  position: absolute; inset-inline-start: 6px; inset-block-start: 6px;
  border-radius: 999px; padding: 2px 8px;
  font-size: .68rem; font-weight: 800;
}
.stock-low { background: var(--accent); color: var(--accent-ink); }
.stock-soldout { background: rgba(0, 0, 0, .72); color: #fff; }

.card-num { font-size: .74rem; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.card-name {
  font-size: .84rem; font-weight: 600; line-height: 1.3;
  overflow-wrap: anywhere;
}
.card-badges { display: flex; flex-wrap: wrap; gap: 4px; }

.badge {
  font-size: .68rem; font-weight: 700; letter-spacing: .02em;
  border-radius: 999px; padding: 2px 8px;
  border: 1px solid var(--border-strong); color: var(--text-muted);
}
.badge-variant-normal { border-color: var(--border-strong); }
.badge-variant-reverse-holofoil { border-color: #7c9cff; color: #9db4ff; }
.badge-variant-holofoil { border-color: #d78bff; color: #dda6ff; }
.badge-rarity { border-style: dashed; }
.badge-source { border-color: var(--accent); color: var(--accent); }
.badge-condition { border-color: var(--ok); color: var(--ok); }

.card-price {
  font-size: .98rem; font-weight: 800; font-variant-numeric: tabular-nums;
}
.card-notes {
  font-size: .74rem; color: var(--text-muted); font-style: italic;
  overflow-wrap: anywhere;
}
.card-soldout-label {
  text-align: center; font-size: .8rem; font-weight: 700;
  color: var(--text-muted); padding: 8px 0 2px;
}

.empty-state {
  text-align: center; color: var(--text-muted);
  padding: 28px 12px; font-size: .92rem;
}

/* ---------- Quantity stepper ---------- */

.qty-stepper {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: auto; padding-top: 4px;
  border-radius: var(--radius-sm);
}
.qty-stepper.is-active { background: var(--accent-soft); }
.qty-btn {
  width: 30px; height: 30px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-sunken); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  font: inherit; font-weight: 800; font-size: 1rem; line-height: 1;
  cursor: pointer;
}
.qty-btn:hover:not(:disabled) { border-color: var(--border-strong); }
.qty-btn:disabled { opacity: .4; cursor: not-allowed; }
.qty-count {
  flex: 1; text-align: center;
  font-weight: 800; font-variant-numeric: tabular-nums;
}

/* ---------- Cart ---------- */

.cart-scrim {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(0, 0, 0, .55);
}

.cart {
  position: fixed; z-index: 50;
  top: 0; right: 0;
  height: 100vh; height: 100dvh;
  width: min(var(--cart-w), 100vw);
  display: flex; flex-direction: column;
  background: var(--bg-raised);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow);
  transform: translateX(101%);
  transition: transform .22s ease;
  visibility: hidden;
}
.cart.is-open { transform: none; visibility: visible; }

body.cart-fullpage .cart { width: 100vw; }

@media (prefers-reduced-motion: reduce) {
  .cart { transition: none; }
}

/* Phones are already full-width, so the box-grid layout is forced on
   (cart.js OR's this breakpoint into its full-page check) and the now-moot
   expand/collapse toggle is hidden. */
@media (max-width: 719px) {
  #cart-expand { display: none; }
}

.cart-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.cart-head h2 { margin: 0; }
.cart-head-actions { display: flex; align-items: center; gap: 2px; }

.icon-btn {
  background: none; border: 0; color: var(--text-muted);
  font-size: 1.05rem; cursor: pointer; padding: 6px 8px; border-radius: var(--radius-sm);
}
.icon-btn:hover { color: var(--text); background: var(--bg-sunken); }

.cart-carts {
  position: relative;
  border-bottom: 1px solid var(--border);
}
.cart-carts-toggle {
  display: flex; align-items: center; gap: 6px;
  width: 100%; background: none; border: 0; cursor: pointer;
  font: inherit; text-align: left; color: var(--text-muted);
  padding: 8px 16px; font-size: .82rem; font-weight: 600;
}
.cart-carts-toggle:hover { color: var(--text); background: var(--bg-sunken); }
.cart-carts-toggle span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cart-carts-chevron { transition: transform .15s ease; font-size: .8em; }
#cart-carts[data-open="true"] .cart-carts-chevron { transform: rotate(180deg); }

.cart-carts-menu {
  position: absolute; z-index: 5; left: 8px; right: 8px; top: 100%;
  margin-top: 4px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  padding: 8px;
  max-height: min(360px, 60vh);
  display: flex; flex-direction: column;
}
.cart-carts-list { overflow-y: auto; }
.cart-carts-empty { font-size: .82rem; color: var(--text-muted); padding: 6px 8px; margin: 0; }

.cart-carts-row {
  display: flex; align-items: center; gap: 6px;
  border-radius: var(--radius-sm);
}
.cart-carts-row.is-active { background: var(--accent-soft); }
.cart-carts-switch {
  flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: flex-start;
  background: none; border: 0; cursor: pointer; text-align: left;
  font: inherit; color: var(--text); padding: 7px 8px; border-radius: var(--radius-sm);
}
.cart-carts-switch:hover { background: var(--bg-sunken); }
.cart-carts-row.is-active .cart-carts-switch:hover { background: none; }
.cart-carts-name { font-size: .85rem; font-weight: 600; overflow-wrap: anywhere; }
.cart-carts-count { font-size: .72rem; color: var(--text-muted); }
.cart-carts-save-here {
  background: none; border: 0; color: var(--text-muted); cursor: pointer;
  font-size: .95rem; padding: 6px 8px; border-radius: var(--radius-sm); flex-shrink: 0;
}
.cart-carts-save-here:hover { color: var(--text); background: var(--bg-sunken); }

.cart-carts-actions {
  display: flex; gap: 6px; margin-top: 6px; padding-top: 6px;
  border-top: 1px solid var(--border);
}
.cart-carts-actions .btn { flex: 1; margin-top: 0; white-space: nowrap; }

.cart-body {
  flex: 1; overflow-y: auto;
  padding: 14px 16px;
  -webkit-overflow-scrolling: touch;
}

.cart-guide {
  font-size: .86rem; color: var(--text-muted);
  background: var(--accent-soft);
  border-radius: var(--radius-sm);
  padding: 10px 12px; margin-bottom: 14px;
}
.cart-guide strong { color: var(--text); }

.cart-group { margin-bottom: 18px; }
.cart-group-name {
  display: flex; align-items: center; gap: 6px;
  width: 100%; background: none; border: 0; margin: 0; cursor: pointer;
  font: inherit; text-align: left;
  font-size: .74rem; font-weight: 800; letter-spacing: .07em;
  text-transform: uppercase; color: var(--text-muted);
  padding: 0 0 6px; margin-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.cart-group-name:hover { color: var(--text); }
.cart-group-chevron {
  display: inline-block;
  transition: transform .15s ease;
  font-size: .8em;
}
.cart-group.is-collapsed .cart-group-chevron { transform: rotate(-90deg); }
.cart-group.is-collapsed .cart-item { display: none; }

.cart-item {
  display: grid;
  grid-template-columns: 42px 1fr auto;
  gap: 10px; align-items: start;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.cart-item:last-child { border-bottom: 0; }

.cart-thumb {
  width: 42px; aspect-ratio: 245 / 342; object-fit: contain;
  background: var(--bg-sunken); border-radius: 4px;
}
.cart-item-main { min-width: 0; }
.cart-item-num { font-size: .72rem; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.cart-item-name { font-size: .85rem; font-weight: 600; overflow-wrap: anywhere; }
.cart-item-variant { font-size: .72rem; color: var(--text-muted); }

.cart-item-price-row {
  display: flex; justify-content: space-between; align-items: baseline;
  margin-top: 6px; font-size: .78rem;
}
.cart-item-unit-price { color: var(--text-muted); }
.cart-item-subtotal { font-weight: 800; font-variant-numeric: tabular-nums; }

.cart-item .qty-stepper { margin-top: 6px; max-width: 140px; }

.cart-item-remove {
  background: none; border: 0; color: var(--text-muted);
  cursor: pointer; font-size: 1rem; padding: 4px 6px; border-radius: 6px;
}
.cart-item-remove:hover { color: var(--danger); background: var(--bg-sunken); }

/* Full-page mode: cart items become a grid of boxes, matching the card
   picker's grid footprint instead of the drawer's cramped row list. */
body.cart-fullpage .cart-group {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
}
@media (min-width: 720px) {
  body.cart-fullpage .cart-group { grid-template-columns: repeat(auto-fill, minmax(186px, 1fr)); }
}
body.cart-fullpage .cart-group-name { grid-column: 1 / -1; }

body.cart-fullpage .cart-item {
  display: flex; flex-direction: column; gap: 8px;
  padding: 10px; border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-raised);
  position: relative;
}

body.cart-fullpage .cart-thumb { width: 100%; border-radius: var(--radius-sm); }

body.cart-fullpage .cart-item-remove {
  position: absolute; top: 6px; right: 6px;
  width: 24px; height: 24px;
  display: flex; align-items: center; justify-content: center; padding: 0;
  background: rgba(0, 0, 0, .65); color: #fff; border-radius: 50%;
}
body.cart-fullpage .cart-item-remove:hover { background: rgba(0, 0, 0, .8); color: #fff; }

/* ---------- QR panel ---------- */

.qr-panel {
  padding: 14px 16px; text-align: center;
  border-top: 1px solid var(--border);
}
.qr-panel canvas {
  max-width: 180px; width: 100%; height: auto;
  background: #fff; border-radius: var(--radius-sm);
  padding: 8px; margin: 0 auto 8px;
}
.qr-panel p { margin: 0; font-size: .8rem; color: var(--text-muted); }

.cart-foot {
  border-top: 1px solid var(--border);
  padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
  background: var(--bg-raised);
}
.cart-total {
  display: flex; justify-content: space-between; align-items: baseline;
  margin-bottom: 10px; font-size: .95rem;
}
.cart-total strong { font-size: 1.25rem; font-variant-numeric: tabular-nums; }

.cart-actions { display: contents; }

body.cart-fullpage .cart-actions {
  display: flex; gap: 8px; align-items: stretch; flex-wrap: wrap;
}
body.cart-fullpage .cart-actions .btn {
  flex: 1; width: auto; margin-top: 0;
}

.btn {
  font: inherit; font-weight: 700; cursor: pointer;
  border-radius: var(--radius-sm); border: 1px solid transparent;
  padding: 11px 16px;
}
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover:not(:disabled) { filter: brightness(1.06); }
.btn-primary:disabled { opacity: .45; cursor: not-allowed; }
.btn-ghost {
  background: none; color: var(--text-muted); border-color: var(--border);
}
.btn-ghost:hover { color: var(--text); border-color: var(--border-strong); }
.btn-block { display: block; width: 100%; }
.btn-small { padding: 8px 14px; font-size: .85rem; margin-top: 8px; }

.checkout-output {
  width: 100%; resize: vertical;
  background: var(--bg-sunken); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 12px;
  font: 13px/1.6 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.checkout-actions { display: flex; gap: 8px; margin-top: 12px; }
.checkout-actions .btn { flex: 1; }
.copy-status { margin: 10px 0 0; font-size: .84rem; color: var(--ok); min-height: 1.2em; }

/* ---------- Desktop: cart docks beside content ---------- */

@media (min-width: 1080px) {
  body.cart-open { overflow: auto; }
  body.cart-open .cart-scrim { display: none; }
  body.cart-open main,
  body.cart-open .site-header .wrap { padding-right: calc(var(--cart-w) + 16px); }

  body.cart-open.cart-fullpage main,
  body.cart-open.cart-fullpage .site-header .wrap { padding-right: 0; }
}
