:root {
    --bg: #0c0f17;
    --bg-2: #131826;
    --bg-3: #1b2233;
    --line: #273149;
    --text: #e6ebf5;
    --muted: #8a97b4;
    --accent: #5fd0c4;      /* teal */
    --accent-2: #f0b65c;    /* amber */
    --win: #57c98a;
    --loss: #e06c6c;
    --gold: #f0d27a;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    font-size: 15px;
    line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.wrap { max-width: 1080px; margin: 0 auto; padding: 0 18px 60px; }

/* ── Top bar ─────────────────────────────────────────────────────────── */
.topbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 18px 2px; border-bottom: 1px solid var(--line); margin-bottom: 22px;
}
.brand { font-size: 19px; font-weight: 700; letter-spacing: .3px; color: var(--gold); }
.brand:hover { text-decoration: none; opacity: .85; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.brand-sub { color: var(--muted); font-size: 12.5px; }
.auth-btn {
    background: var(--bg-3); color: var(--muted); border: 1px solid var(--line);
    border-radius: 7px; padding: 5px 11px; font-size: 12.5px; cursor: pointer; font-family: ui-monospace, monospace;
}
.auth-btn:hover { color: var(--text); border-color: var(--accent); }
.auth-btn.authed { color: var(--accent); border-color: var(--accent); }

.foot { margin-top: 34px; color: var(--muted); font-size: 12px; text-align: center; }

/* ── Empty / loading / error ─────────────────────────────────────────── */
.empty, .error-box { text-align: center; color: var(--muted); padding: 60px 20px; }
.empty .glyph { font-size: 34px; color: var(--accent-2); margin-bottom: 10px; }
.error-box { color: var(--loss); }
.spinner {
    width: 22px; height: 22px; border: 3px solid var(--line); border-top-color: var(--accent);
    border-radius: 50%; animation: spin .8s linear infinite; margin: 0 auto 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Filter / control bar ────────────────────────────────────────────── */
.controls {
    display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
    background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px;
    padding: 12px 14px; margin-bottom: 18px;
}
.controls label { color: var(--muted); font-size: 12.5px; margin-right: 2px; }
.controls select, .controls input {
    background: var(--bg-3); color: var(--text); border: 1px solid var(--line);
    border-radius: 7px; padding: 6px 9px; font-size: 13.5px; font-family: inherit;
}
.controls input.search { flex: 1; min-width: 160px; }
.controls .grow { flex: 1; }

/* ── Tables ──────────────────────────────────────────────────────────── */
.tbl-wrap { background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th {
    text-align: left; color: var(--muted); font-weight: 600; font-size: 11.5px;
    text-transform: uppercase; letter-spacing: .4px; padding: 10px 12px;
    border-bottom: 1px solid var(--line); white-space: nowrap; background: var(--bg-3);
}
thead th.num, td.num { text-align: right; font-variant-numeric: tabular-nums; }
thead th.sortable { cursor: pointer; user-select: none; }
thead th.sortable:hover { color: var(--text); }
thead th[data-dir] { color: var(--accent); }
.sort-ind { margin-left: 4px; font-size: 9px; color: var(--accent); vertical-align: middle; }
tbody td { padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--bg-3); }
.rank { color: var(--muted); font-variant-numeric: tabular-nums; width: 36px; }
.pname { font-weight: 600; color: var(--text); }
.pname .anon { color: var(--muted); font-weight: 400; font-style: italic; }

/* deck cell (leader/base combo thumb + names) */
.deck-cell { display: flex; align-items: center; gap: 9px; min-width: 0; }
/* leader/base combo thumb — ported from the main dashboard: leader art framed
   in its aspect colour(s), with a small base-identity badge in the corner
   (aspect icon / Force glyph / LAW wheel / named-base pill) instead of a
   second card image. */
.leader-thumb { position: relative; width: 34px; height: 34px; flex: none; }
.leader-thumb.lg { width: 46px; height: 46px; }
.leader-thumb--framed { padding: 2px; border-radius: 8px; background: #2a3645; }
.leader-thumb__img {
    width: 100%; height: 100%; border-radius: 6px; background-color: #11141b;
    background-size: 162% auto; background-position: 47% 24%; background-repeat: no-repeat;
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .6);
}
.base-badge {
    position: absolute; right: -4px; bottom: -4px; width: 18px; height: 18px;
    display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.base-badge--icon { object-fit: contain; filter: drop-shadow(0 0 1.5px rgba(0, 0, 0, .9)); }
.base-badge--svg { filter: drop-shadow(0 1px 1.5px rgba(0, 0, 0, .7)); }
.base-badge__svg { width: 100%; height: 100%; display: block; }
.deck-names { min-width: 0; line-height: 1.25; }
.deck-names .ld { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.deck-names .bs { color: var(--muted); font-size: 12px; }

/* winrate pill */
.wr { font-weight: 700; font-variant-numeric: tabular-nums; }
.wr.hi { color: var(--win); }
.wr.lo { color: var(--loss); }
.wr.mid { color: var(--text); }
.wl { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 12.5px; }
.elo { font-weight: 700; color: var(--accent-2); font-variant-numeric: tabular-nums; }
.elo-peak { color: var(--muted); font-size: 11.5px; }

/* result chips */
.res { display: inline-block; width: 18px; text-align: center; font-weight: 700; border-radius: 4px; font-size: 11.5px; padding: 1px 0; }
.res.w { background: rgba(87,201,138,.16); color: var(--win); }
.res.l { background: rgba(224,108,108,.16); color: var(--loss); }

/* replay deep-link (recent games → swuquery viewer) */
.replay-link {
    display: inline-flex; align-items: center; gap: 4px; white-space: nowrap;
    color: var(--accent); font-size: 12px; font-weight: 600; border: 1px solid var(--line);
    border-radius: 5px; padding: 2px 8px;
}
.replay-link:hover { text-decoration: none; border-color: var(--accent); background: var(--bg-3); }
.replay-link .tri { font-size: 9px; }

/* ── Player detail ───────────────────────────────────────────────────── */
.back-link { display: inline-block; color: var(--muted); font-size: 13px; margin-bottom: 14px; }
.player-head {
    display: flex; flex-wrap: wrap; align-items: baseline; gap: 14px;
    border-bottom: 1px solid var(--line); padding-bottom: 14px; margin-bottom: 18px;
}
.player-head h1 { margin: 0; font-size: 26px; color: var(--gold); }
.statline { display: flex; flex-wrap: wrap; gap: 20px; margin-bottom: 22px; }
.stat { background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px; padding: 12px 16px; min-width: 110px; }
.stat .k { color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: .4px; }
.stat .v { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 3px; }
.stat .v .sub { font-size: 13px; color: var(--muted); font-weight: 400; }

.section { margin-bottom: 26px; }
.section h2 {
    font-size: 14px; text-transform: uppercase; letter-spacing: .6px; color: var(--accent);
    margin: 0 0 10px; font-weight: 700;
}
.section .hint { color: var(--muted); font-size: 12px; font-weight: 400; text-transform: none; letter-spacing: 0; margin-left: 8px; }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 760px) { .two-col { grid-template-columns: 1fr; } .statline .stat { flex: 1 1 40%; } }

/* small inline deck (matchups / recent opp) */
.mini-deck { display: flex; align-items: center; gap: 7px; }
.mini-deck .leader-thumb { width: 27px; height: 27px; }
.mini-deck .base-badge { width: 14px; height: 14px; right: -3px; bottom: -3px; }
.mini-deck .mn { line-height: 1.15; }
.mini-deck .mn .ld { font-size: 12.5px; }
.mini-deck .mn .bs { font-size: 11px; color: var(--muted); }
/* recent-games "Opponent" cell: "vs name" + their mini-deck side by side */
.opp-cell { display: flex; align-items: center; gap: 8px; white-space: nowrap; }

.bar { height: 5px; border-radius: 3px; background: var(--bg-3); overflow: hidden; margin-top: 4px; }
.bar > span { display: block; height: 100%; background: var(--accent); }

/* ── Buttons ─────────────────────────────────────────────────────────── */
.btn-solid, .btn-ghost {
    border-radius: 7px; padding: 7px 14px; font-size: 13.5px; cursor: pointer; font-family: inherit; border: 1px solid var(--line);
}
.btn-solid { background: var(--accent); color: #06231f; border-color: var(--accent); font-weight: 600; }
.btn-solid:hover { filter: brightness(1.08); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover { color: var(--text); }

/* ── Auth modal ──────────────────────────────────────────────────────── */
.modal-overlay {
    display: none; position: fixed; inset: 0; background: rgba(4, 6, 11, .72);
    align-items: center; justify-content: center; z-index: 50;
}
.modal {
    background: var(--bg-2); border: 1px solid var(--line); border-radius: 12px;
    padding: 22px; width: min(420px, 92vw); box-shadow: 0 20px 60px rgba(0, 0, 0, .5);
}
.modal-title { margin: 0 0 6px; font-size: 16px; }
.modal-note { margin: 0 0 14px; color: var(--muted); font-size: 12.5px; }
.modal-input {
    width: 100%; background: var(--bg-3); color: var(--text); border: 1px solid var(--line);
    border-radius: 8px; padding: 9px 11px; font-size: 14px; font-family: ui-monospace, monospace;
}
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }

/* ── Seen-decklist expandable row (slides out under the deck row) ──────── */
.deck-cards-btn {
    background: var(--bg-3); color: var(--accent); border: 1px solid var(--line);
    border-radius: 6px; padding: 4px 9px; font-size: 12px; cursor: pointer; font-family: inherit; white-space: nowrap;
}
.deck-cards-btn:hover { border-color: var(--accent); }
.decklist-row td { padding: 0; border-bottom: 1px solid var(--line); }
.decklist-panel-wrap {
    max-height: 0; overflow: hidden; transition: max-height .25s ease; background: var(--bg-3);
}
.decklist-panel-wrap.open { max-height: 430px; }
.decklist-panel { padding: 14px 16px; }
.dl-meta { color: var(--muted); font-size: 12px; margin-bottom: 10px; }
.dl-grid-scroll { max-height: 330px; overflow-y: auto; padding-right: 4px; }
.decklist-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 10px;
}
.dl-card-img-wrap {
    position: relative; width: 100%; aspect-ratio: 5 / 7; background: var(--bg);
    border-radius: 8px; overflow: hidden; border: 1px solid var(--line);
}
.dl-card-img-wrap img, .dl-card-fallback { position: absolute; inset: 0; width: 100%; height: 100%; }
.dl-card-img-wrap img { object-fit: cover; z-index: 1; }
.dl-card-fallback {
    display: flex; align-items: center; justify-content: center; text-align: center;
    font-size: 10.5px; color: var(--muted); padding: 6px; word-break: break-word;
}
.dl-card-badge {
    position: absolute; top: 5px; right: 5px; padding: 2px 6px; border-radius: 5px;
    font-size: 10px; font-weight: 800; color: #06231f; z-index: 2; line-height: 1.4;
}
.dl-card-copies {
    position: absolute; bottom: 5px; left: 5px; background: rgba(12, 15, 23, .85);
    border: 1px solid var(--line); color: var(--accent-2); padding: 2px 6px; border-radius: 5px;
    font-size: 10.5px; font-weight: 700; z-index: 2; line-height: 1.4;
}

/* ── Recent-games pagination footer ─────────────────────────────────── */
.recent-foot { text-align: center; padding: 12px 0 0; }

/* ── Top-bar view nav (Leaderboard / Breakouts) ─────────────────────── */
.topbar-left { display: flex; align-items: baseline; gap: 18px; }
.viewnav { display: flex; gap: 14px; }
.viewnav a { color: var(--muted); font-size: 13.5px; font-weight: 600; padding: 2px 1px; border-bottom: 2px solid transparent; }
.viewnav a:hover { color: var(--text); text-decoration: none; }
.viewnav a.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ── Breakouts view ─────────────────────────────────────────────────── */
.bk-title { font-size: 22px; color: var(--gold); margin: 2px 0 4px; }
.bk-sub { color: var(--muted); font-size: 13px; margin: 0 0 14px; max-width: 780px; }
.pname-link { color: var(--text); font-weight: 600; }
.pname-link:hover { color: var(--accent); }
/* "new deck for this player" flag */
.pill-new {
    display: inline-block; margin-left: 6px; padding: 1px 6px; border-radius: 4px;
    font-size: 9.5px; font-weight: 800; letter-spacing: .4px; text-transform: uppercase;
    background: rgba(240, 182, 92, .16); color: var(--accent-2); border: 1px solid rgba(240, 182, 92, .4);
    vertical-align: middle; white-space: nowrap;
}
/* deck-tech tile extras (reuse .dl-card-* from the seen-decklist grid):
   an amber ring on off-meta "tech" cards + a small meta-baseline line. */
.dl-card-img-wrap.tech { border-color: var(--accent-2); box-shadow: inset 0 0 0 1px var(--accent-2), 0 0 9px rgba(240, 182, 92, .28); }
.dl-card-meta-line {
    position: absolute; bottom: 5px; right: 5px; background: rgba(12, 15, 23, .85);
    border: 1px solid var(--line); color: var(--muted); padding: 1px 5px; border-radius: 5px;
    font-size: 9.5px; font-weight: 700; z-index: 2; line-height: 1.35;
}
.dl-card-meta-line.tech { color: var(--accent-2); border-color: rgba(240, 182, 92, .4); }

/* ── Aspect filter chips + client-side search (leaderboard & breakouts) ──── */
/* Ported in spirit from the main dashboard's fx-chip--icon aspect filter, re-
   themed to the console teal/amber palette. Icons dim until hovered/active so the
   selected aspects read at a glance; AND semantics live in js/filters.js. */
.asp-filter { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; flex: 1; min-width: 220px; }
.asp-chips { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.asp-chip {
    background: var(--bg-3); border: 1px solid var(--line); border-radius: 14px;
    padding: 4px 8px; line-height: 0; cursor: pointer; transition: border-color .15s, box-shadow .15s;
}
.asp-chip img { width: 20px; height: 20px; display: block; opacity: .4; transition: opacity .15s; }
.asp-chip:hover { border-color: var(--accent); }
.asp-chip:hover img { opacity: 1; }
.asp-chip.active { border-color: var(--accent); box-shadow: 0 0 10px rgba(95, 208, 196, .22); background: rgba(95, 208, 196, .12); }
.asp-chip.active img { opacity: 1; }
.asp-sep { width: 1px; align-self: stretch; min-height: 20px; background: var(--line); margin: 0 2px; }
.asp-search { flex: 1; min-width: 150px; }
/* No-results row inside a filtered table body. */
.filter-empty { padding: 22px; text-align: center; color: var(--muted); }

/* ── Breakout streak: opponents faced (above the tech card grid) ─────────── */
/* One box per opponent deck: combo thumbnail on top, W-L vs that deck underneath.
   Most-played opponent first — so a hot streak's schedule reads at a glance. */
.decklist-panel-wrap.tall.open { max-height: 660px; }
.streak-opps { margin-bottom: 16px; }
.streak-label { color: var(--muted); font-size: 12px; margin-bottom: 8px; }
.streak-opp-list { display: flex; flex-wrap: wrap; gap: 10px; max-height: 208px; overflow-y: auto; }
.streak-opp {
    display: flex; flex-direction: column; align-items: center; gap: 5px;
    background: var(--bg); border: 1px solid var(--line); border-radius: 9px; padding: 8px 10px;
}
.streak-opp-rec { font-size: 12.5px; font-weight: 700; font-variant-numeric: tabular-nums; }
.unknown-thumb { display: flex; align-items: center; justify-content: center; color: var(--muted); font-weight: 700; font-size: 14px; }
