:root {
    --bg: #0f1115;
    --panel: #181b22;
    --panel-2: #1f232c;
    --border: #2a2f3a;
    --text: #e7e9ee;
    --muted: #9aa3b2;
    --accent: #ffcb05; /* Pokémon yellow */
    --accent-2: #3b6cff;
    --radius: 12px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

a { color: inherit; text-decoration: none; }

.wrap { max-width: 1200px; margin: 0 auto; padding: 0 20px; }

/* Top bar */
.topbar {
    border-bottom: 1px solid var(--border);
    background: rgba(15, 17, 21, 0.85);
    backdrop-filter: blur(8px);
    position: sticky;
    top: 0;
    z-index: 10;
}
.topbar .wrap { display: flex; align-items: center; gap: 12px; height: 56px; }
.brand { font-weight: 700; font-size: 18px; display: inline-flex; align-items: center; gap: 8px; }
.brand .logo { flex: none; }
.brand-sub { color: var(--muted); font-size: 13px; }
.topbar-nav { margin-left: auto; display: flex; align-items: center; gap: 14px; font-size: 14px; }
.topbar-nav .who { color: var(--muted); }
.topbar-nav a { color: var(--accent); }
.topbar-nav a:hover { text-decoration: underline; }

/* Auth screen. The login page renders without the topbar, so it owns the whole
   viewport: brand up top, card centered, nothing to click but "Sign in". */
.page-auth main.wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px 20px;
}
.auth {
    width: 100%;
    max-width: 360px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 32px 28px;
    box-shadow: 0 24px 60px rgba(0, 0, 0, .45);
    text-align: center;
}
.auth-brand { display: flex; align-items: center; justify-content: center; gap: 10px; }
/* Override the logo's inline 26px — here the coin is the page's hero. */
.auth-brand .logo { width: 44px; height: 44px; }
.auth-name { font-size: 30px; font-weight: 700; letter-spacing: -.01em; }
.auth-tagline { color: var(--muted); font-size: 13px; margin: 8px 0 26px; }
.auth-note { color: var(--muted); font-size: 12px; margin: 20px 0 0; }
.auth-error {
    background: rgba(255, 80, 80, .12);
    border: 1px solid rgba(255, 80, 80, .4);
    color: #ff9b9b;
    border-radius: 8px;
    padding: 10px 12px;
    font-size: 14px;
    margin: 0 0 16px;
    text-align: left;
}
.auth-form { display: flex; flex-direction: column; gap: 6px; text-align: left; }
.auth-form label { font-size: 13px; color: var(--muted); margin-top: 10px; }
.auth-form input {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 12px;
    color: var(--text);
    font-size: 15px;
}
.auth-form input:focus { outline: none; border-color: var(--accent); }
.auth-form button {
    margin-top: 18px;
    background: var(--accent);
    color: #1a1a1a;
    font-weight: 600;
    font-size: 15px;
    border: 0;
    border-radius: 8px;
    padding: 11px;
    cursor: pointer;
}
.auth-form button:hover { filter: brightness(1.05); }

main.wrap { padding-top: 28px; padding-bottom: 64px; }

/* Page heading */
.page-head { margin-bottom: 24px; }
.page-head h1 { margin: 0 0 4px; font-size: 26px; }
.page-head .meta { color: var(--muted); font-size: 14px; }

.crumbs { color: var(--muted); font-size: 13px; margin-bottom: 12px; }
.crumbs a:hover { color: var(--text); }

/* Series sections */
.series { margin-bottom: 40px; }
.series-head {
    display: flex;
    align-items: baseline;
    gap: 12px;
    margin: 0 0 14px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}
.series-head h2 { margin: 0; font-size: 18px; }
.series-head .count { color: var(--muted); font-size: 13px; }

/* Set cards grid */
.set-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
    gap: 14px;
}
.set-card {
    display: block;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    transition: border-color .15s, transform .15s;
}
.set-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.set-card .name { font-weight: 600; font-size: 16px; margin-bottom: 6px; }
.set-card .sub { color: var(--muted); font-size: 13px; display: flex; justify-content: space-between; gap: 8px; }
.pill {
    display: inline-block;
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 2px 10px;
    font-size: 12px;
    color: var(--muted);
}

/* Card grid (set detail) */
.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 16px;
}
.tcg-card { display: block; }
.tcg-card .frame {
    position: relative;
    aspect-ratio: 63 / 88;
    border-radius: 10px;
    overflow: hidden;
    background: var(--panel-2);
    border: 1px solid var(--border);
    transition: transform .15s, box-shadow .15s;
}
.tcg-card:hover .frame {
    transform: translateY(-3px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, .5);
}
.tcg-card img { width: 100%; height: 100%; object-fit: contain; display: block; }
.tcg-card .noimg {
    width: 100%; height: 100%;
    display: flex; align-items: center; justify-content: center;
    color: var(--muted); font-size: 12px; text-align: center; padding: 8px;
}
.tcg-card .label { margin-top: 8px; }
.tcg-card .cname { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tcg-card .cmeta { color: var(--muted); font-size: 12px; display: flex; justify-content: space-between; gap: 6px; }
.tcg-card .cprice {
    margin-top: 2px;
    font-size: 13px;
    font-weight: 600;
    color: var(--accent);
    display: flex;
    align-items: baseline;
    gap: 6px;
}
.tcg-card .cprice-holo { color: var(--muted); font-size: 11px; font-weight: 500; }

.empty { color: var(--muted); padding: 40px 0; text-align: center; }
.empty a { color: var(--accent); }
.empty a:hover { text-decoration: underline; }

/* Flash messages */
.flash {
    border-radius: 8px;
    padding: 10px 14px;
    font-size: 14px;
    margin-bottom: 18px;
}
.flash-success {
    background: rgba(80, 200, 120, .12);
    border: 1px solid rgba(80, 200, 120, .4);
    color: #8fe3aa;
}

/* Buttons */
.btn {
    background: var(--panel-2);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 8px;
    padding: 8px 14px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn-primary { background: var(--accent); color: #1a1a1a; border-color: var(--accent); }
.btn-primary:hover { filter: brightness(1.05); }
.btn-ghost { background: transparent; }

/* Update-collection toolbar. The bar reserves the button's height so swapping
   the edit button for the actions row doesn't shift the page. */
.collection-bar { margin-bottom: 18px; min-height: 38px; display: flex; align-items: center; }
.collection-actions {
    display: none;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    width: 100%;
}
.collection.editing [data-collection-edit] { display: none; }
.collection.editing .collection-actions { display: flex; }
.collection-hint { color: var(--muted); font-size: 13px; flex: 1; min-width: 200px; }
.collection-count { color: var(--accent); font-size: 13px; font-weight: 600; }

/* The checkbox is the source of truth; it's never shown directly. */
.tcg-select { position: absolute; opacity: 0; pointer-events: none; }
.card-controls { display: none; }

/* Two full-frame overlays, swapped by mode: link (browse) vs select (edit). */
.frame-link, .frame-select {
    position: absolute;
    inset: 0;
    z-index: 2;
}
.frame-select { display: none; cursor: pointer; }
.collection.editing .frame-link { display: none; }
.collection.editing .frame-select { display: block; }

.owned-badge, .select-tick {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 26px;
    height: 26px;
    border-radius: 999px;
    display: none;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    font-weight: 700;
    z-index: 3;
    pointer-events: none;
}
.owned-badge {
    background: rgba(80, 200, 120, .92);
    color: #0f1115;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .4);
}
.select-tick {
    background: var(--accent);
    color: #1a1a1a;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .4);
}

/* Browse mode: an owned badge marks cards already in the collection. For a
   signed-in collector, cards not yet owned are dimmed (like the edit flow), so
   the set reads at a glance as "what I have". Hovering restores full opacity. */
.tcg-card.is-owned .owned-badge { display: flex; }
.collection.has-owner:not(.editing) .tcg-card:not(.is-owned) .frame { opacity: .5; }
.collection.has-owner:not(.editing) .tcg-card:not(.is-owned):hover .frame { opacity: 1; }

/* Edit mode: selection state is driven purely by the checkbox via :has(). */
.collection.editing .owned-badge { display: none; }
.collection.editing .tcg-card:not(:has(.tcg-select:checked)) .frame { opacity: .55; }
.collection.editing .tcg-card:has(.tcg-select:checked) .frame {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}
.collection.editing .tcg-card:has(.tcg-select:checked) .select-tick { display: flex; }
/* Reserve the control row for every card while editing, so toggling a card's
   selection reveals its controls in place instead of pushing the grid around. */
.collection.editing .card-controls { display: flex; visibility: hidden; }
.collection.editing .tcg-card:has(.tcg-select:checked) .card-controls { visibility: visible; }
.card-controls {
    gap: 6px;
    margin-top: 8px;
}
.cond-select {
    background: var(--panel);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 6px;
    padding: 5px 6px;
    font-size: 12px;
}
.cond-select { flex: 1; min-width: 0; }
.cond-select:focus { outline: none; border-color: var(--accent); }

/* Per-card variant flags, revealed alongside the controls while editing. */
.card-flags { display: none; gap: 10px; margin-top: 6px; }
.collection.editing .card-flags { display: flex; visibility: hidden; }
.collection.editing .tcg-card:has(.tcg-select:checked) .card-flags { visibility: visible; }
.card-flags .flag {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    color: var(--muted);
    cursor: pointer;
}
.card-flags input { accent-color: var(--accent); margin: 0; }

/* Collection page: holdings tables + totals */
.series-head .subtotal { color: var(--accent); font-weight: 600; margin-left: auto; }
.total-value { color: var(--accent); }
.value-note { color: var(--muted); font-size: 12px; }
.holdings { width: 100%; border-collapse: collapse; font-size: 14px; }
.holdings th, .holdings td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--border); }
.holdings thead th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
.holdings td.num, .holdings th.num { text-align: right; font-variant-numeric: tabular-nums; }
.holdings td.muted { color: var(--muted); }
.holdings tbody tr:hover { background: var(--panel); }
.holdings a:hover { color: var(--accent); }
.tag {
    display: inline-block;
    margin-left: 6px;
    padding: 1px 7px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    border: 1px solid var(--border);
    color: var(--muted);
    vertical-align: middle;
}
.tag-rh { color: #c9a8ff; border-color: rgba(160, 120, 255, .4); }
.tag-1st { color: var(--accent); border-color: rgba(255, 203, 5, .4); }

/* Reverse-holo glyph: sits inline in tags and beside the holo price. */
.rh-icon { vertical-align: -0.12em; }
.cprice-holo .rh-icon { color: #c9a8ff; }

/* Per-holding status selector on the collection page. */
.status-form { margin: 0; display: inline-flex; gap: 6px; align-items: center; }
.status-select {
    background: var(--panel);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 6px;
    padding: 4px 6px;
    font-size: 12px;
    font-weight: 600;
}
.status-select:focus { outline: none; border-color: var(--accent); }
.status-select--collected { color: var(--muted); }
.status-select--listed { color: var(--accent-2); border-color: rgba(59, 108, 255, .5); }
.status-select--sold { color: #8fe3aa; border-color: rgba(80, 200, 120, .5); }
.status-go { padding: 4px 8px; font-size: 12px; }

/* A sold copy has left the collection — show it, but visibly retired. */
.holdings tr.is-sold td { opacity: .5; }
.holdings tr.is-sold .status-select { opacity: 1; }
.holdings tr.is-sold td.num { text-decoration: line-through; }
.grand-total {
    margin-top: 28px;
    padding-top: 16px;
    border-top: 2px solid var(--border);
    text-align: right;
    font-size: 16px;
    color: var(--muted);
}
.grand-total strong { color: var(--accent); font-size: 22px; margin-left: 12px; }

/* ---------------------------------------------------------------------------
   Catalogue filters + per-set ownership
   --------------------------------------------------------------------------- */

.filters {
    display: flex;
    align-items: flex-end;
    gap: 20px;
    flex-wrap: wrap;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    margin-bottom: 28px;
}
.filter { display: flex; flex-direction: column; gap: 6px; }
.filter label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
.filter-range { display: flex; align-items: center; gap: 8px; }
.filter-dash { color: var(--muted); }
.filters input[type="number"] {
    width: 84px;
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 7px 10px;
    color: var(--text);
    font-size: 14px;
    font-variant-numeric: tabular-nums;
}
.filters input[type="number"]:focus { outline: none; border-color: var(--accent); }
.filter-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    cursor: pointer;
    padding-bottom: 7px;
}
.filter-toggle input { accent-color: var(--accent); width: 16px; height: 16px; margin: 0; }
.filter-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; padding-bottom: 0; }
.filter-actions .btn-ghost { color: var(--muted); }
.filter-actions .btn-ghost:hover { color: var(--text); }

.meta-owned { color: var(--accent); }

/* Ownership readout on a set card: a progress bar plus the exact count. A set
   you own nothing from is dimmed, so the grid reads as "where am I collecting". */
.owned-row { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.owned-bar {
    flex: 1;
    height: 4px;
    border-radius: 999px;
    background: var(--panel-2);
    overflow: hidden;
}
.owned-bar i {
    display: block;
    height: 100%;
    border-radius: 999px;
    background: var(--accent);
}
/* A single card out of 200 rounds to 0% — keep a visible sliver so "some" never
   looks like "none". */
.set-card.has-owned .owned-bar i { min-width: 4px; }
.pill-owned {
    color: var(--accent);
    border-color: rgba(255, 203, 5, .4);
    font-variant-numeric: tabular-nums;
}
.pill-none { opacity: .7; }
.set-card.no-owned { background: transparent; border-style: dashed; }
.set-card.no-owned .name { color: var(--muted); }
.set-card.no-owned:hover { border-style: solid; }
.set-card.no-owned:hover .name { color: var(--text); }
