/* ── CSS Variables (GitHub Dark Theme) ──────────────────────────────────── */
:root {
    --bg-primary: #0e1117;
    --bg-card: #161b22;
    --bg-card-alt: #0e1117;
    --border: #30363d;
    --border-subtle: #21262d;
    --text-primary: #e6edf3;
    --text-secondary: #c9d1d9;
    --text-muted: #8b949e;
    --text-disabled: #484f58;
    --accent-green: #4ade80;
    --accent-blue: #58a6ff;
    --accent-red: #f85149;
    --win-blue: #38bdf8;
    --top10-green: #4ade80;
    --top20-green: #166534;
    --cut-red: #dc2626;
    --wd-purple: #8b5cf6;
    --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* ── Reset ─────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
    background: var(--bg-primary);
    color: var(--text-secondary);
    font-family: var(--font-family);
    font-size: 14px;
    line-height: 1.5;
    min-height: 100vh;
}

/* ── Site Nav ──────────────────────────────────────────────────────────── */
.site-nav {
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    padding: 8px 20px;
    display: flex;
    align-items: center;
    gap: 24px;
    flex-wrap: wrap;
}
.site-nav-brand {
    text-decoration: none;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: -0.3px;
}
.site-nav-divider {
    width: 1px;
    height: 18px;
    background: var(--border);
}
.site-nav-link {
    text-decoration: none;
    font-size: 13px;
    color: var(--text-muted);
    font-weight: 500;
}
.site-nav-link.active { color: var(--accent-green); }
.site-nav-link.disabled { color: var(--text-disabled); cursor: default; }

/* ── Page Nav ──────────────────────────────────────────────────────────── */
.page-nav {
    display: flex;
    gap: 8px;
    padding: 12px 20px;
    flex-wrap: wrap;
}
.page-nav-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    font-family: var(--font-family);
    transition: all 0.15s;
}
.page-nav-btn:hover { border-color: var(--text-muted); }
.page-nav-btn.active {
    background: var(--cut-red);
    border-color: var(--cut-red);
    color: #fff;
}
.refresh-btn { min-width: auto; padding: 8px 12px; }

.divider {
    border: none;
    border-top: 1px solid var(--border);
    margin: 0 20px;
}

/* ── Page Containers ───────────────────────────────────────────────────── */
.page-container {
    display: none;
    padding: 16px 20px;
    max-width: 1400px;
}
.page-container.active { display: block; }

/* ── Typography ────────────────────────────────────────────────────────── */
h1 { font-size: 28px; font-weight: 700; color: var(--text-primary); margin-bottom: 12px; }
h2 { font-size: 22px; font-weight: 700; color: var(--text-primary); margin-bottom: 8px; }
h3 { font-size: 18px; font-weight: 600; color: var(--text-primary); margin-bottom: 6px; }
.caption { font-size: 12px; color: var(--text-muted); margin-bottom: 12px; }

/* ── Metric Cards ──────────────────────────────────────────────────────── */
.metric-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}
.metric-card {
    background: linear-gradient(135deg, #0d1117, var(--bg-card));
    padding: 12px 16px;
    border-radius: 12px;
    border: 1px solid var(--border);
}
.metric-card-label { font-size: 12px; color: var(--text-muted); margin-bottom: 4px; }
.metric-card-value {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ── Select / Input ────────────────────────────────────────────────────── */
.select-wrapper { margin-bottom: 12px; }
.select-wrapper label { display: block; font-size: 12px; color: var(--text-muted); margin-bottom: 4px; font-weight: 600; }
select, .text-input {
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 13px;
    font-family: var(--font-family);
    width: 100%;
    max-width: 500px;
}
select:focus, .text-input:focus { outline: none; border-color: var(--accent-blue); }
.text-input::placeholder { color: var(--text-disabled); }

/* ── Sortable Table ────────────────────────────────────────────────────── */
.table-container {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 16px;
}
.data-table {
    width: 100%;
    min-width: 900px;
    border-collapse: collapse;
    font-size: 11px;
}
.data-table th {
    position: sticky;
    top: 0;
    background: var(--bg-primary);
    color: var(--text-muted);
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    padding: 6px 4px;
    text-align: center;
    cursor: pointer;
    user-select: none;
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
    z-index: 2;
}
.data-table th:hover { color: var(--accent-blue); }
.data-table th .sort-arrow { font-size: 8px; margin-left: 2px; }
.data-table td {
    padding: 4px;
    text-align: center;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-subtle);
    white-space: nowrap;
}
.data-table tr:nth-child(even) { background: var(--bg-card); }
.data-table tr:nth-child(odd) { background: var(--bg-primary); }
.data-table tr:hover { background: #1c2333; }
.data-table tr.selected { background: #1c2333; outline: 1px solid var(--accent-blue); }

/* Sticky columns */
.data-table .col-rank,
.data-table .col-player {
    position: sticky;
    z-index: 1;
}
.data-table .col-rank { left: 0; width: 30px; min-width: 30px; }
.data-table .col-player {
    left: 30px;
    min-width: 100px;
    text-align: left;
    font-weight: 500;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 120px;
    border-right: 1px solid var(--border);
}
.data-table tr:nth-child(even) .col-rank,
.data-table tr:nth-child(even) .col-player { background: var(--bg-card); }
.data-table tr:nth-child(odd) .col-rank,
.data-table tr:nth-child(odd) .col-player { background: var(--bg-primary); }
.data-table tr:hover .col-rank,
.data-table tr:hover .col-player { background: #1c2333; }
.data-table th.col-rank, .data-table th.col-player { background: var(--bg-primary); z-index: 3; }

/* Score coloring */
.score-high { color: #3fb950; }
.score-mid { color: var(--accent-blue); }

/* ── Finish Boxes ──────────────────────────────────────────────────────── */
.finish-boxes {
    display: flex;
    gap: 2px;
    flex-wrap: nowrap;
}
.finish-box {
    width: 36px;
    min-width: 36px;
    height: 26px;
    border-radius: 3px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 9px;
    font-weight: 600;
    cursor: default;
}
.finish-box-empty {
    width: 36px;
    min-width: 36px;
    height: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-disabled);
    font-size: 11px;
}
.finish-box-sm { width: 28px; min-width: 28px; height: 24px; font-size: 9px; }

/* ── Matchup Cards ─────────────────────────────────────────────────────── */
.matchup-header {
    display: flex;
    align-items: center;
    padding: 6px 17px;
    margin-bottom: 4px;
}
.matchup-header-cell {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.matchup-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 12px;
    overflow-x: auto;
}
.matchup-card-inner { min-width: 700px; }
.matchup-row {
    display: flex;
    align-items: center;
    padding: 10px 14px;
}
.matchup-row + .matchup-row { border-top: 1px solid var(--border-subtle); }
.matchup-badge {
    flex: 0 0 30px;
    margin: 0 4px;
    text-align: center;
    font-size: 13px;
    font-weight: 700;
}
.matchup-badge-empty { flex: 0 0 30px; margin: 0 4px; }
.matchup-name {
    flex: 0 0 160px;
}
.matchup-name-text { font-size: 13px; font-weight: 600; color: var(--text-primary); }
.matchup-name-sub { font-size: 11px; color: var(--text-muted); }
.matchup-odds {
    flex: 0 0 80px;
    text-align: center;
    font-size: 14px;
    font-weight: 700;
    color: var(--text-primary);
}
.matchup-boxes {
    flex: 1;
    display: flex;
    gap: 2px;
    flex-wrap: nowrap;
}

/* ── Legend ─────────────────────────────────────────────────────────────── */
.legend {
    display: flex;
    gap: 12px;
    margin-bottom: 8px;
    flex-wrap: wrap;
    align-items: center;
}
.legend-label { font-size: 12px; color: var(--text-muted); }
.legend-item {
    padding: 2px 8px;
    border-radius: 3px;
    font-size: 11px;
    font-weight: 600;
}

/* ── Player Detail Panel ───────────────────────────────────────────────── */
.player-detail {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}
.player-detail h3 { margin-bottom: 12px; }
.detail-metrics {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 8px;
    margin-bottom: 16px;
}
.detail-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
    margin-bottom: 16px;
}
.detail-table th {
    background: var(--bg-card);
    color: var(--text-muted);
    padding: 6px 8px;
    text-align: left;
    font-size: 11px;
    border-bottom: 1px solid var(--border);
}
.detail-table td {
    padding: 5px 8px;
    border-bottom: 1px solid var(--border-subtle);
    color: var(--text-secondary);
}
.chart-container {
    max-width: 600px;
    height: 250px;
    margin-bottom: 16px;
}

/* ── Two Column Layout ─────────────────────────────────────────────────── */
.two-col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
}

/* ── Slider ────────────────────────────────────────────────────────────── */
.slider-wrapper { margin-bottom: 12px; }
.slider-wrapper label { display: block; font-size: 12px; color: var(--text-muted); margin-bottom: 4px; font-weight: 600; }
input[type="range"] {
    width: 100%;
    max-width: 300px;
    accent-color: var(--accent-blue);
}
.slider-value { font-size: 12px; color: var(--text-secondary); margin-left: 8px; }

/* ── Filter Row ────────────────────────────────────────────────────────── */
.filter-row {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    align-items: flex-end;
    margin-bottom: 16px;
}
.filter-row > div { flex: 1; min-width: 150px; }

/* ── Loading ───────────────────────────────────────────────────────────── */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(14, 17, 23, 0.85);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 100;
}
.loading-spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--border);
    border-top-color: var(--accent-blue);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { margin-top: 12px; color: var(--text-muted); font-size: 13px; }

/* ── Info / Empty States ───────────────────────────────────────────────── */
.info-msg {
    padding: 12px 16px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-muted);
    font-size: 13px;
}

/* ── Responsive ────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
    .page-container { padding: 12px 8px; }
    .page-nav { padding: 8px 8px; gap: 4px; }
    .page-nav-btn { padding: 6px 10px; font-size: 11px; }
    .two-col { grid-template-columns: 1fr; }
    .metric-cards { grid-template-columns: 1fr 1fr; }
    .data-table { font-size: 10px; }
    .finish-box { width: 28px; min-width: 28px; height: 22px; font-size: 8px; }
    .matchup-name { flex: 0 0 120px; }
    .matchup-name-text { font-size: 11px; }
    .matchup-odds { flex: 0 0 60px; font-size: 12px; }
    h1 { font-size: 22px; }
    h2 { font-size: 18px; }
}
