/* ═══════════════════════════════════════════════════════════════════
   YGO DB Stats — design system (2026-07 redesign)
   Dark charcoal + gold accent, Space Grotesk / Inter, token-driven.
   ═══════════════════════════════════════════════════════════════════ */

:root {
    /* Surfaces */
    --bg: #0a0c10;
    --surface: #101319;
    --surface-2: #161a22;
    --surface-3: #1d232e;
    --border: #232a36;
    --border-strong: #2f3948;

    /* Text */
    --text: #e8ebf0;
    --text-dim: #98a2b3;
    --text-faint: #667085;

    /* Accent */
    --gold: #e3b455;
    --gold-bright: #f0ca79;
    --gold-dim: rgba(227, 180, 85, 0.13);
    --gold-ink: #191307;

    /* Win-rate scale (chip text colors, tuned for >=4.5:1 on tinted chips) */
    --wr-pos-strong: #6ee7a2;
    --wr-pos: #8fd6a8;
    --wr-neutral: #c3cad6;
    --wr-neg: #f0a9a9;
    --wr-neg-strong: #f87d7d;
    --wr-pos-bg: rgba(46, 204, 113, 0.13);
    --wr-pos-bg-soft: rgba(46, 204, 113, 0.07);
    --wr-neutral-bg: rgba(255, 255, 255, 0.05);
    --wr-neg-bg-soft: rgba(240, 82, 82, 0.08);
    --wr-neg-bg: rgba(240, 82, 82, 0.14);

    /* Semantic */
    --green-btn: #237a49;
    --red-btn: #c53838;

    /* Shape & type */
    --radius-lg: 14px;
    --radius: 10px;
    --radius-sm: 7px;
    --font-display: "Space Grotesk", "Inter", system-ui, sans-serif;
    --font-body: "Inter", -apple-system, "Segoe UI", Roboto, sans-serif;

    /* Layout */
    --nav-h: 53px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scrollbar-color: var(--surface-3) var(--bg);
}

body {
    font-family: var(--font-body);
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

::selection {
    background: var(--gold-dim);
    color: var(--gold-bright);
}

:focus-visible {
    outline: 2px solid var(--gold);
    outline-offset: 2px;
    border-radius: 4px;
}

button {
    font-family: inherit;
    cursor: pointer;
}

input,
select {
    font-family: inherit;
}

/* ─── Scrollbars (WebKit) ─── */
::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--surface-3);
    border-radius: 6px;
    border: 2px solid var(--bg);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--border-strong);
}

/* ═══ Topbar ═══ */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    padding: 20px 32px;
    background: linear-gradient(180deg, #0e1117 0%, var(--bg) 100%);
}

.brand {
    display: flex;
    align-items: center;
    gap: 14px;
    min-width: 0;
}

.brand-mark {
    width: 38px;
    height: 38px;
    flex: none;
    color: var(--gold);
}

.brand-text h1 {
    font-family: var(--font-display);
    font-size: 20px;
    font-weight: 700;
    letter-spacing: 0.3px;
    line-height: 1.2;
    color: var(--text);
}

.brand-text h1 .brand-accent {
    color: var(--gold);
}

.subtitle {
    color: var(--text-faint);
    font-size: 12.5px;
    margin-top: 1px;
}

/* Meta chips (right side of topbar) */
.meta-chips {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.meta-chip {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 1px;
    padding: 7px 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.meta-chip .meta-label {
    font-size: 10.5px;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-faint);
}

.meta-chip .meta-value {
    font-size: 14px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    color: var(--text);
    white-space: nowrap;
}

.meta-chip .meta-value.accent {
    color: var(--gold);
}

/* ═══ Nav ═══ */
.tabs {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 0 24px;
    background: rgba(10, 12, 16, 0.88);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
}

.tab {
    position: relative;
    background: none;
    border: none;
    color: var(--text-dim);
    padding: 16px 16px;
    font-size: 14px;
    font-weight: 500;
    transition: color 0.15s ease-out;
}

.tab:hover {
    color: var(--text);
}

.tab.active {
    color: var(--gold);
}

.tab.active::after {
    content: "";
    position: absolute;
    left: 12px;
    right: 12px;
    bottom: -1px;
    height: 2px;
    border-radius: 2px;
    background: var(--gold);
}

/* Period picker in nav */
.date-filter {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 0;
}

/* ═══ Controls (selects, inputs, search) ═══ */
.control {
    height: 36px;
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0 10px;
    font-size: 13px;
    transition: border-color 0.15s ease-out, background 0.15s ease-out;
}

.control:hover {
    border-color: var(--border-strong);
}

.control:focus {
    border-color: var(--gold);
    outline: none;
}

select.control {
    padding-right: 28px;
    appearance: none;
    background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2398a2b3' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
}

.date-filter select.control {
    max-width: 240px;
}

.date-filter input.control {
    width: 170px;
    text-align: center;
}

/* Search box with inline icon */
.search-box {
    position: relative;
    display: flex;
    align-items: center;
}

.search-box svg {
    position: absolute;
    left: 11px;
    width: 15px;
    height: 15px;
    color: var(--text-faint);
    pointer-events: none;
}

.search-box input {
    padding-left: 34px;
    width: 230px;
}

.search-box input::placeholder {
    color: var(--text-faint);
}

/* ═══ Main layout ═══ */
main {
    max-width: 1240px;
    margin: 0 auto;
    padding: 24px 32px 56px;
}

.site-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-top: 28px;
    padding: 18px 2px 0;
    border-top: 1px solid var(--border);
    color: var(--text-faint);
    font-size: 12px;
}

.site-footer-links {
    display: flex;
    gap: 16px;
}

.site-footer a {
    color: var(--text-dim);
    text-decoration: none;
}

.site-footer a:hover {
    color: var(--gold-bright);
    text-decoration: underline;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* ═══ Panel (table card) ═══ */
/* NB: no overflow on .panel — a clipping ancestor breaks the sticky thead
   (Chromium paints sticky th offset by `top` inside overflow:clip). Corners
   are rounded per-element instead. */
.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
}

.panel > .table-filters {
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

/* Panels whose table sits at the very top (no toolbar above it) */
.panel > table thead th:first-child,
.panel > .dataTables_wrapper:first-child thead th:first-child {
    border-top-left-radius: var(--radius-lg);
}

.panel > table thead th:last-child,
.panel > .dataTables_wrapper:first-child thead th:last-child {
    border-top-right-radius: var(--radius-lg);
}

/* Toolbar row above a table */
.table-filters {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    padding: 13px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}

.filters-left {
    display: flex;
    align-items: center;
    gap: 18px;
    color: var(--text-dim);
    font-size: 13px;
}

.filters-left label {
    display: flex;
    align-items: center;
    gap: 7px;
    white-space: nowrap;
}

.filter-input-sm {
    width: 72px;
}

.filters-note {
    color: var(--text-faint);
    font-variant-numeric: tabular-nums;
}

/* Toggle switch (checkbox styled as a track+thumb; the input stays in the
   accessibility tree, only visually replaced, so keyboard/SR behaviour is
   the native checkbox one). */
.switch {
    cursor: pointer;
    user-select: none;
}

/* 1px rather than 0: a zero-sized control is dropped from the a11y tree by
   some screen readers, which would make the toggle unreachable. */
.switch input {
    position: absolute;
    opacity: 0;
    width: 1px;
    height: 1px;
}

.switch-track {
    position: relative;
    flex: none;
    width: 32px;
    height: 18px;
    border-radius: 9px;
    background: var(--surface-3);
    border: 1px solid var(--border-strong);
    transition: background 0.15s, border-color 0.15s;
}

.switch-track::after {
    content: "";
    position: absolute;
    top: 2px;
    left: 2px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--text-faint);
    transition: transform 0.15s, background 0.15s;
}

.switch input:checked + .switch-track {
    background: var(--gold-dim);
    border-color: var(--gold);
}

.switch input:checked + .switch-track::after {
    transform: translateX(14px);
    background: var(--gold);
}

.switch input:focus-visible + .switch-track {
    outline: 2px solid var(--gold);
    outline-offset: 2px;
}

/* Rows shown only because the toggle is on: below 1100 right now. Dimmed to
   --text-dim (not --text-faint, which drops under 4.5:1 on --surface) so the
   current 1100+ block still reads first without failing contrast. */
.player-former td {
    color: var(--text-dim);
}

.rating-peak {
    color: var(--text-faint);
    font-size: 11px;
    margin-left: 5px;
}

/* ═══ Tables ═══ */
.dataTables_wrapper {
    padding: 0 0 6px;
}

/* border-collapse: separate is required for the sticky thead — collapsed
   borders don't travel with sticky cells and trigger Chromium paint bugs. */
table.dataTable {
    border-collapse: separate;
    border-spacing: 0;
    width: 100% !important;
}

/* The selector list must match the CDN's `th.sorting*` specificity — DataTables
   sets those to position:relative, which would turn our `top` into a plain
   53px downward shift on every sortable column. */
table.dataTable thead > tr > th.sorting,
table.dataTable thead > tr > th.sorting_asc,
table.dataTable thead > tr > th.sorting_desc,
table.dataTable thead th {
    position: sticky;
    top: var(--nav-h);
    z-index: 10;
    background: var(--surface-2);
    color: var(--text-dim);
    border-bottom: 1px solid var(--border-strong);
    padding: 11px 16px;
    font-weight: 600;
    font-size: 11.5px;
    text-transform: uppercase;
    letter-spacing: 0.7px;
    text-align: left;
    white-space: nowrap;
}

table.dataTable tbody td {
    background: transparent;
    border-bottom: 1px solid var(--border);
    padding: 10px 16px;
    font-size: 14px;
    font-variant-numeric: tabular-nums;
}

table.dataTable tbody tr:last-child td {
    border-bottom: none;
}

table.dataTable tbody tr:hover td {
    background: var(--surface-2);
}

table.dataTable td.dataTables_empty {
    text-align: center;
    color: var(--text-faint);
    padding: 40px 16px;
}

/* Numeric columns right-aligned, win-rate chip columns centered.
   The `thead > tr > th` form is required, not decoration: the sticky-header
   rule above carries (0,2,4) via its `th.sorting` list entry, and DataTables
   puts `.sorting` on every sortable header — a plain `th.num` (0,2,2) loses to
   it and every header silently stayed left-aligned over right-aligned values.
   These match at (0,2,4) and win on source order. */
table.dataTable thead > tr > th.num,
table.dataTable th.num,
table.dataTable td.num {
    text-align: right;
}

table.dataTable thead > tr > th.wr,
table.dataTable th.wr,
table.dataTable td.wr {
    text-align: center;
}

/* Kill the CDN's sorted-column shading (inset box-shadow overlay) */
table.dataTable.display tbody tr > .sorting_1,
table.dataTable.display tbody tr > .sorting_2,
table.dataTable.display tbody tr > .sorting_3,
table.dataTable.order-column tbody tr > .sorting_1 {
    box-shadow: none;
}

/* Sorting indicators (override DataTables defaults) */
table.dataTable thead .sorting:before,
table.dataTable thead .sorting:after,
table.dataTable thead .sorting_asc:before,
table.dataTable thead .sorting_asc:after,
table.dataTable thead .sorting_desc:before,
table.dataTable thead .sorting_desc:after {
    color: var(--text-faint);
    opacity: 0.5;
}

table.dataTable thead .sorting_asc:before,
table.dataTable thead .sorting_desc:after {
    color: var(--gold);
    opacity: 1;
}

table.dataTable thead th.sorting,
table.dataTable thead th.sorting_asc,
table.dataTable thead th.sorting_desc {
    cursor: pointer;
}

table.dataTable thead th.sorting:hover,
table.dataTable thead th.sorting_asc:hover,
table.dataTable thead th.sorting_desc:hover {
    color: var(--text);
}

/* Rank column */
.rank-cell {
    color: var(--text-faint);
    font-weight: 600;
    width: 46px;
}

table.dataTable tbody tr:nth-child(-n + 3) .rank-cell {
    color: var(--gold);
}

/* Clickable rows */
#players-table tbody tr,
#decks-table tbody tr {
    cursor: pointer;
}

/* ─── Deck cell (icon + name) ─── */
.deck-cell {
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 600;
    color: var(--text);
    min-width: 180px;
}

.deck-icon-wrap {
    position: relative;
    width: 36px;
    height: 36px;
    flex: none;
    border-radius: 9px;
    overflow: hidden;
    border: 1px solid var(--border-strong);
    background: var(--surface-3);
}

.deck-monogram {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 15px;
    color: var(--gold);
}

.deck-icon {
    position: relative;
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* ─── Card cell (thumb + name) ─── */
.card-cell {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 200px;
}

.card-thumb {
    width: 30px;
    height: 43px;
    flex: none;
    object-fit: cover;
    border-radius: 4px;
    border: 1px solid var(--border);
    background: var(--surface-3);
}

/* ═══ Win-rate chips ═══ */
.wr-chip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 60px;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    border: 1px solid transparent;
}

.wr-dominant {
    color: var(--wr-pos-strong);
    background: var(--wr-pos-bg);
    border-color: rgba(46, 204, 113, 0.25);
}

.wr-above {
    color: var(--wr-pos);
    background: var(--wr-pos-bg-soft);
}

.wr-even {
    color: var(--wr-neutral);
    background: var(--wr-neutral-bg);
}

.wr-below {
    color: var(--wr-neg);
    background: var(--wr-neg-bg-soft);
}

.wr-struggling {
    color: var(--wr-neg-strong);
    background: var(--wr-neg-bg);
    border-color: rgba(240, 82, 82, 0.25);
}

.wr-na {
    color: var(--text-faint);
    background: var(--wr-neutral-bg);
}

/* Result chips (player replay history) */
.result-chip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 52px;
    padding: 2px 10px;
    border-radius: 999px;
    font-size: 12.5px;
    font-weight: 600;
}

.result-win {
    color: var(--wr-pos-strong);
    background: var(--wr-pos-bg);
}

.result-loss {
    color: var(--wr-neg-strong);
    background: var(--wr-neg-bg);
}

.result-draw {
    color: var(--wr-neutral);
    background: var(--wr-neutral-bg);
}

/* ═══ DataTables chrome (info + pagination) ═══ */
.dataTables_wrapper .dataTables_length {
    display: none;
}

.dataTables_wrapper .dataTables_info,
.dataTables_wrapper .dataTables_paginate {
    color: var(--text-faint);
    font-size: 13px;
    padding: 12px 16px;
}

.dataTables_wrapper .dataTables_paginate .paginate_button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 30px;
    height: 30px;
    padding: 0 9px !important;
    color: var(--text-dim) !important;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin: 0 2px;
    font-size: 13px;
    transition: background 0.15s ease-out, color 0.15s ease-out;
}

.dataTables_wrapper .dataTables_paginate .paginate_button.current,
.dataTables_wrapper .dataTables_paginate .paginate_button.current:hover {
    color: var(--gold-ink) !important;
    background: var(--gold) !important;
    border-color: var(--gold);
    font-weight: 700;
}

.dataTables_wrapper .dataTables_paginate .paginate_button:hover {
    color: var(--text) !important;
    background: var(--surface-3) !important;
    border-color: var(--border-strong);
}

.dataTables_wrapper .dataTables_paginate .paginate_button.disabled,
.dataTables_wrapper .dataTables_paginate .paginate_button.disabled:hover {
    color: var(--text-faint) !important;
    background: transparent !important;
    border-color: var(--border);
    cursor: default;
}

/* ═══ Status tab ═══ */
.status-panel h2 {
    font-family: var(--font-display);
    font-size: 18px;
    margin-bottom: 18px;
}

.status-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 14px;
    margin-bottom: 28px;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 20px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.stat-label {
    color: var(--text-faint);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.9px;
}

.stat-value {
    font-family: var(--font-display);
    color: var(--text);
    font-size: 24px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

/* Scraper controls (live mode only; stripped from the static build) */
.scraper-controls {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
}

.scraper-controls h3 {
    color: var(--text-dim);
    font-size: 14px;
    margin-bottom: 14px;
}

.control-row {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
}

.control-row label {
    color: var(--text-dim);
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.control-row input {
    width: 130px;
}

.btn {
    height: 38px;
    padding: 0 18px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 13.5px;
    font-weight: 600;
    transition: filter 0.15s ease-out;
}

.btn:hover {
    filter: brightness(1.15);
}

.btn-start {
    background: var(--green-btn);
    color: #fff;
}

.btn-stop {
    background: var(--red-btn);
    color: #fff;
}

/* ═══ Modals ═══ */
/* Deck and player details replace the tab body in place rather than floating
   over it: same reading width as the tables they came from, page scroll instead
   of a nested scroll box, and the nav tabs stay reachable above. The inner
   .modal-* classes are kept because the header/tabs/body/pager layout is
   unchanged — only the container behaviour differs. */
.detail-view {
    animation: detail-in 0.18s ease-out;
}

/* The container is focused on open (see openDetail) purely to move the caret
   into the new view; it should never paint a ring of its own. */
.detail-view:focus {
    outline: none;
}

.modal-content {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    display: flex;
    flex-direction: column;
}

@keyframes detail-in {
    from {
        opacity: 0;
        transform: translateY(6px);
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    padding: 18px 24px 14px;
}

.modal-header h2 {
    font-family: var(--font-display);
    font-size: 18px;
    color: var(--text);
    margin: 0;
}

.modal-player-rating {
    margin: 3px 0 0;
    color: var(--text-dim);
    font-size: 13px;
    font-variant-numeric: tabular-nums;
}

.modal-player-rating:empty {
    display: none;
}

.detail-back-btn {
    flex: none;
    width: 34px;
    height: 34px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--surface-3);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    color: var(--text-dim);
    font-size: 13px;
    white-space: nowrap;
    transition: background 0.15s ease-out, color 0.15s ease-out;
}

.detail-back-btn svg {
    width: 15px;
    height: 15px;
}

.detail-back-btn:hover {
    background: var(--border-strong);
    color: var(--text);
}

.modal-header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.copy-ids-btn {
    height: 34px;
    padding: 0 14px;
    background: var(--surface-3);
    border: 1px solid var(--border-strong);
    color: var(--text-dim);
    border-radius: var(--radius-sm);
    font-size: 13px;
    white-space: nowrap;
    transition: background 0.15s ease-out, color 0.15s ease-out;
}

.copy-ids-btn:hover {
    background: var(--border-strong);
    color: var(--text);
}

/* Overall-WR chips in the deck-modal header */
.modal-overall {
    display: flex;
    align-items: center;
    gap: 12px;
}

.overall-stat {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.overall-label {
    font-size: 10.5px;
    text-transform: uppercase;
    letter-spacing: 0.7px;
    color: var(--text-faint);
}

/* Relative chips carry a delta tooltip */
.wr-chip[title] {
    cursor: help;
}

/* Pager below the deck-modal tables (mirrors the DataTables pagination look) */
.modal-pager-wrap {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    padding: 12px 2px 4px;
}

.modal-pager-info {
    color: var(--text-faint);
    font-size: 12.5px;
    font-variant-numeric: tabular-nums;
}

.modal-pager {
    display: flex;
    align-items: center;
    gap: 4px;
}

.pager-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 30px;
    height: 30px;
    padding: 0 9px;
    color: var(--text-dim);
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 13px;
    transition: background 0.15s ease-out, color 0.15s ease-out;
}

.pager-btn:hover:not(:disabled):not(.current) {
    color: var(--text);
    background: var(--surface-3);
    border-color: var(--border-strong);
}

.pager-btn.current {
    color: var(--gold-ink);
    background: var(--gold);
    border-color: var(--gold);
    font-weight: 700;
}

.pager-btn:disabled {
    color: var(--text-faint);
    cursor: default;
}

.pager-ellipsis {
    color: var(--text-faint);
    padding: 0 4px;
}

.modal-filters {
    padding: 0 24px 12px;
}

.modal-filters label {
    color: var(--text-dim);
    font-size: 13px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

/* Modal tabs */
.modal-tabs {
    display: flex;
    gap: 2px;
    border-bottom: 1px solid var(--border);
    padding: 0 24px;
}

.modal-tab {
    position: relative;
    background: none;
    border: none;
    color: var(--text-dim);
    padding: 10px 14px;
    font-size: 13.5px;
    font-weight: 500;
    transition: color 0.15s ease-out;
}

.modal-tab:hover {
    color: var(--text);
}

.modal-tab.active {
    color: var(--gold);
}

.modal-tab.active::after {
    content: "";
    position: absolute;
    left: 10px;
    right: 10px;
    bottom: -1px;
    height: 2px;
    border-radius: 2px;
    background: var(--gold);
}

.modal-tab-content {
    display: none;
}

.modal-tab-content.active {
    display: block;
}

.modal-body {
    /* Inline view: the page scrolls, not a nested box. Only the horizontal
       overflow stays, so wide tables scroll inside their own container instead
       of pushing the page sideways. */
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding: 4px 24px 20px;
}

/* Tables inside modals are plain (never DataTables-initialized), so they
   need the base table look explicitly; no sticky (they scroll in .modal-body) */
.modal-body table {
    width: 100%;
    border-collapse: collapse;
}

.modal-body thead th {
    position: static;
    background: var(--surface-2);
    color: var(--text-dim);
    border-bottom: 1px solid var(--border-strong);
    font-weight: 600;
    font-size: 11.5px;
    text-transform: uppercase;
    letter-spacing: 0.7px;
    text-align: left;
}

.modal-body thead th.num,
.modal-body tbody td.num {
    text-align: right;
}

.modal-body thead th.wr,
.modal-body tbody td.wr {
    text-align: center;
}

.modal-body tbody td {
    border-bottom: 1px solid var(--border);
    font-size: 13.5px;
    font-variant-numeric: tabular-nums;
}

.modal-body tbody tr:hover td {
    background: var(--surface-2);
}

#matchup-table th,
#matchup-table td,
#deck-cards-table th,
#deck-cards-table td,
#player-replays-table th,
#player-replays-table td {
    padding: 9px 14px;
    white-space: nowrap;
}

/* Replay link */
.replay-link {
    color: var(--gold);
    text-decoration: none;
}

.replay-link:hover {
    color: var(--gold-bright);
    text-decoration: underline;
}

/* ═══ Deck-card hover popover ═══ */
.deck-hover {
    cursor: pointer;
    text-decoration: underline dotted rgba(227, 180, 85, 0.45);
    text-underline-offset: 3px;
}

.deck-popover {
    position: absolute;
    z-index: 1100;
    background: var(--surface-2);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    padding: 8px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.6);
    display: grid;
    grid-template-columns: repeat(10, 50px);
    gap: 4px;
    max-width: calc(10 * 50px + 9 * 4px + 16px);
    pointer-events: none;
}

.deck-popover-card {
    position: relative;
    width: 50px;
    height: 72px;
    border-radius: 3px;
    overflow: hidden;
    background: var(--surface-3);
}

.deck-popover-card img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.deck-popover-card .count-badge {
    position: absolute;
    bottom: 2px;
    right: 2px;
    background: rgba(0, 0, 0, 0.82);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    padding: 1px 4px;
    border-radius: 3px;
    line-height: 1.2;
}

.deck-popover-empty {
    grid-column: 1 / -1;
    color: var(--text-faint);
    font-size: 12px;
    padding: 4px 8px;
    text-align: center;
}

/* ═══ Reduced motion ═══ */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ═══ Responsive ═══ */
@media (max-width: 980px) {
    /* Wide tables scroll inside their panel; sticky thead is given up here.
       Same specificity dance as the sticky rule above, and top must be reset
       so the CDN's position:relative can't re-apply it as an offset. */
    .dataTables_wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    table.dataTable thead > tr > th.sorting,
    table.dataTable thead > tr > th.sorting_asc,
    table.dataTable thead > tr > th.sorting_desc,
    table.dataTable thead th {
        position: static;
        top: auto;
    }
}

@media (max-width: 768px) {
    .topbar {
        padding: 14px 16px;
        flex-wrap: wrap;
        gap: 12px;
    }

    .brand-mark {
        width: 32px;
        height: 32px;
    }

    .brand-text h1 {
        font-size: 17px;
    }

    .meta-chips {
        gap: 8px;
    }

    .meta-chip {
        padding: 5px 10px;
    }

    .meta-chip .meta-value {
        font-size: 12.5px;
    }

    .tabs {
        flex-wrap: wrap;
        padding: 0 8px;
    }

    .tab {
        padding: 12px 10px;
        font-size: 13px;
    }

    .date-filter {
        width: 100%;
        margin-left: 0;
        padding: 0 0 10px;
    }

    .date-filter select.control {
        width: 100%;
        max-width: none;
    }

    .date-filter input.control {
        width: 100%;
    }

    main {
        padding: 14px 10px 40px;
    }

    .site-footer {
        align-items: flex-start;
        flex-direction: column;
        gap: 8px;
        margin-top: 20px;
        padding-top: 14px;
    }

    .table-filters {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
        padding: 12px;
    }

    .filters-left {
        gap: 12px;
        flex-wrap: wrap;
    }

    .search-box,
    .search-box input {
        width: 100%;
    }

    table.dataTable thead th {
        padding: 9px 8px;
        font-size: 10.5px;
        letter-spacing: 0.3px;
    }

    table.dataTable tbody td {
        padding: 8px 8px;
        font-size: 12.5px;
    }

    .deck-cell {
        gap: 8px;
        min-width: 140px;
    }

    .deck-icon-wrap {
        width: 28px;
        height: 28px;
        border-radius: 7px;
    }

    .deck-monogram {
        font-size: 12px;
    }

    .card-cell {
        min-width: 150px;
    }

    .card-thumb {
        width: 22px;
        height: 32px;
    }

    .wr-chip {
        min-width: 50px;
        padding: 2px 7px;
        font-size: 12px;
    }

    .status-grid {
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }

    .stat-card {
        padding: 12px 14px;
    }

    .stat-value {
        font-size: 18px;
    }

    .control-row {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }

    .control-row input {
        width: 100%;
    }

    .modal-content {
        width: 96%;
        max-height: 92vh;
    }

    .modal-header {
        padding: 14px 16px 10px;
    }

    .modal-header h2 {
        font-size: 15.5px;
    }

    .modal-tabs,
    .modal-filters {
        padding-left: 16px;
        padding-right: 16px;
    }

    .modal-body {
        padding: 4px 16px 16px;
    }

    #matchup-table th,
    #matchup-table td,
    #deck-cards-table th,
    #deck-cards-table td,
    #player-replays-table th,
    #player-replays-table td {
        padding: 8px 8px;
        font-size: 12px;
    }

    .dataTables_wrapper .dataTables_paginate .paginate_button {
        min-width: 26px;
        height: 26px;
        font-size: 12px;
    }

    .dataTables_wrapper .dataTables_info {
        font-size: 12px;
    }
}

@media (max-width: 480px) {
    .meta-chips {
        display: none;
    }

    .tab {
        padding: 10px 8px;
        font-size: 12.5px;
    }

    .status-grid {
        grid-template-columns: 1fr;
    }

    .modal-header {
        flex-wrap: wrap;
        gap: 8px;
    }
}
