:root {
    --bg: #0f1117;
    --surface: #1a1d27;
    --surface-hover: #1f2333;
    --border: #2a2d3a;
    --text: #e1e4ed;
    --text-dim: #8b8fa3;
    --accent: #6c8cff;
    --accent-glow: rgba(108, 140, 255, 0.12);
    --accent2: #ff6c8c;
    --green: #4ade80;
    --orange: #fb923c;
    --radius: 10px;
    --transition: 200ms ease-out;
}

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

body {
    font-family: 'Fira Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    padding: 20px 24px;
    max-width: 1400px;
    margin: 0 auto;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* ── Header ── */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    flex-wrap: wrap;
    gap: 12px;
}

.header-logo { height: 28px; }
header h1 { font-size: 1.5rem; font-weight: 600; letter-spacing: -0.02em; }

.controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.controls input[type="date"] {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 0.85rem;
    font-family: inherit;
    transition: border-color var(--transition);
}

.controls input[type="date"]:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-glow);
}

.controls button {
    background: var(--accent);
    color: #fff;
    border: none;
    padding: 6px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    font-family: inherit;
    font-weight: 500;
    transition: opacity var(--transition), transform var(--transition);
}

.controls button:hover { opacity: 0.85; }
.controls button:active { transform: scale(0.97); }
.meta { font-size: 0.75rem; color: var(--text-dim); }

/* ── Tabs ── */
.tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 0;
}

.tab {
    background: none;
    border: none;
    color: var(--text-dim);
    font-family: inherit;
    font-size: 0.9rem;
    padding: 10px 20px;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: color var(--transition), border-color var(--transition);
}

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

.tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
    font-weight: 600;
}

.tab-content { display: none; animation: fadeIn 0.25s ease-out; }
.tab-content.active { display: block; }

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ── Tab Toolbar ── */
.tab-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.date-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.date-controls input[type="date"] {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 0.82rem;
    font-family: inherit;
    transition: border-color var(--transition);
}

.date-controls input[type="date"]:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-glow);
}

.date-controls span { color: var(--text-dim); font-size: 0.82rem; }

.btn-sm {
    background: var(--accent);
    color: #fff;
    border: none;
    padding: 6px 14px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.82rem;
    font-family: inherit;
    font-weight: 500;
    transition: opacity var(--transition);
}
.btn-sm:hover { opacity: 0.85; }

/* ── Status Bar ── */
.status-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 0;
    font-size: 0.82rem;
    color: var(--text-dim);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--orange);
    flex-shrink: 0;
}

.status-dot.ok { background: var(--green); box-shadow: 0 0 6px rgba(74, 222, 128, 0.4); }
.status-dot.warn { background: var(--orange); box-shadow: 0 0 6px rgba(251, 146, 60, 0.4); }
.status-dot.error { background: var(--accent2); box-shadow: 0 0 6px rgba(255, 108, 140, 0.4); }

/* ── Cards ── */
.summary-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
    margin-bottom: 24px;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    transition: border-color var(--transition), box-shadow var(--transition);
}

.card:hover {
    border-color: rgba(108, 140, 255, 0.3);
    box-shadow: 0 2px 12px var(--accent-glow);
}

.card-label { font-size: 0.8rem; color: var(--text-dim); margin-bottom: 4px; }
.card-value { font-size: 1.8rem; font-weight: 700; letter-spacing: -0.02em; }

/* ── Charts ── */
.charts-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 24px;
}

.chart-container {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
}

.chart-container.full { grid-column: 1 / -1; }

.chart-container.full canvas { max-height: 240px; }
.chart-container canvas.doughnut { max-height: 260px; }

.chart-container h3 {
    font-size: 0.9rem;
    font-weight: 500;
    margin-bottom: 12px;
    color: var(--text-dim);
}

/* ── Tables ── */
.table-section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
}

.table-section h3 {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-dim);
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 12px;
}

#user-search {
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 0.8rem;
    font-family: inherit;
    width: 200px;
    transition: border-color var(--transition);
}

#user-search:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-glow);
}

/* ── Group Legend ── */
.group-legend {
    display: inline-flex;
    gap: 12px;
    margin-left: 8px;
    font-weight: 400;
}

.legend-item {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.75rem;
    color: var(--text-dim);
}

.legend-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
th { text-align: left; color: var(--text-dim); padding: 8px; border-bottom: 1px solid var(--border); font-weight: 500; }
td { padding: 8px; border-bottom: 1px solid var(--border); transition: background var(--transition); }
tr:hover td { background: var(--accent-glow); }

/* ── Pagination ── */
.pager {
    display: flex;
    justify-content: center;
    gap: 4px;
    margin-top: 12px;
}

.page-btn {
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text-dim);
    padding: 4px 10px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.78rem;
    font-family: inherit;
    min-width: 32px;
    transition: all var(--transition);
}

.page-btn:hover:not(:disabled) { border-color: var(--accent); color: var(--text); }
.page-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 600; }
.page-btn:disabled { opacity: 0.3; cursor: default; }

/* ── Ranking ── */
/* Season Header */
.season-header {
    display: flex;
    align-items: baseline;
    gap: 12px;
    margin-bottom: 16px;
}

.season-header h2 {
    font-size: 1.3rem;
    font-weight: 700;
    background: linear-gradient(135deg, #fbbf24, #f59e0b);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: -0.02em;
}

.season-period {
    font-size: 0.82rem;
    color: var(--text-dim);
}

/* Score Explain */
.score-explain {
    display: flex;
    gap: 16px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.score-factor {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 14px;
    font-size: 0.82rem;
    transition: border-color var(--transition);
}

.score-factor:hover { border-color: rgba(108, 140, 255, 0.3); }

.score-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border-radius: 6px;
    font-weight: 800;
    font-size: 0.72rem;
    flex-shrink: 0;
}

.score-factor:nth-child(1) .score-icon { background: var(--accent); color: #fff; }
.score-factor:nth-child(2) .score-icon { background: var(--green); color: #1a1d27; }
.score-factor:nth-child(3) .score-icon { background: var(--orange); color: #1a1d27; }

.score-desc { color: var(--text-dim); font-size: 0.75rem; }

.sub-score { font-size: 0.75rem; font-weight: 600; color: var(--text-dim); text-align: center; }

/* Tier Guide */
.tier-guide {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 18px;
    margin-bottom: 20px;
}

.tier-guide h3 {
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--text-dim);
    margin-bottom: 10px;
}

.tier-list { display: flex; gap: 16px; flex-wrap: wrap; }

.tier-guide-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.78rem;
    color: var(--text-dim);
}

/* Podium */
.podium-section {
    display: flex;
    justify-content: center;
    align-items: flex-end;
    gap: 16px;
    margin-bottom: 28px;
    min-height: 220px;
}

.podium-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 20px 24px;
    text-align: center;
    position: relative;
    transition: transform var(--transition), box-shadow var(--transition);
    width: 200px;
    cursor: default;
}

.podium-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}

.podium-card.gold {
    border-color: #fbbf24;
    box-shadow: 0 0 24px rgba(251, 191, 36, 0.15);
    order: 2;
    padding-bottom: 28px;
}

.podium-card.silver {
    border-color: #94a3b8;
    box-shadow: 0 0 16px rgba(148, 163, 184, 0.1);
    order: 1;
}

.podium-card.bronze {
    border-color: #cd7f32;
    box-shadow: 0 0 16px rgba(205, 127, 50, 0.1);
    order: 3;
}

.podium-medal { font-size: 2rem; margin-bottom: 6px; line-height: 1; }

.podium-card.gold .podium-medal { color: #fbbf24; text-shadow: 0 0 12px rgba(251, 191, 36, 0.4); }
.podium-card.silver .podium-medal { color: #94a3b8; text-shadow: 0 0 10px rgba(148, 163, 184, 0.3); }
.podium-card.bronze .podium-medal { color: #cd7f32; text-shadow: 0 0 10px rgba(205, 127, 50, 0.3); }

.podium-name { font-size: 1rem; font-weight: 700; margin-bottom: 2px; }
.podium-group { font-size: 0.75rem; color: var(--text-dim); margin-bottom: 8px; }
.podium-value { font-size: 1.6rem; font-weight: 800; color: var(--accent); letter-spacing: -0.02em; }
.podium-card.gold .podium-value { color: #fbbf24; text-shadow: 0 0 10px rgba(251, 191, 36, 0.3); }
.podium-label { font-size: 0.7rem; color: var(--text-dim); margin-top: 4px; }

/* Rank Table */
.rank-table-section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 20px;
}

.rank-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.rank-table th { text-align: left; color: var(--text-dim); padding: 8px; border-bottom: 1px solid var(--border); font-weight: 500; }
.rank-table td { padding: 8px; border-bottom: 1px solid var(--border); transition: background var(--transition); }
.rank-table tr:hover td { background: var(--accent-glow); }
.rank-col { width: 50px; text-align: center; }
.rank-value-col { width: 100px; text-align: center; }

.rank-num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    font-weight: 700;
    font-size: 0.8rem;
}

.rank-num.r1 { background: #fbbf24; color: #1a1d27; box-shadow: 0 0 8px rgba(251, 191, 36, 0.4); }
.rank-num.r2 { background: #94a3b8; color: #1a1d27; }
.rank-num.r3 { background: #cd7f32; color: #1a1d27; }

.tier-badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 10px;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.3px;
}

.tier-badge.grandmaster { background: linear-gradient(135deg, #fbbf24, #f59e0b); color: #1a1d27; }
.tier-badge.master { background: linear-gradient(135deg, #c084fc, #a855f7); color: #1a1d27; }
.tier-badge.diamond { background: linear-gradient(135deg, #22d3ee, #06b6d4); color: #1a1d27; }
.tier-badge.platinum { background: linear-gradient(135deg, #6c8cff, #4f6ddf); color: #fff; }
.tier-badge.gold { background: linear-gradient(135deg, #fbbf24, #d4a017); color: #1a1d27; }
.tier-badge.silver { background: #94a3b8; color: #1a1d27; }
.tier-badge.bronze { background: #cd7f32; color: #1a1d27; }

.rank-name {
    color: var(--accent);
    cursor: pointer;
    text-decoration: none;
    transition: color var(--transition);
}

.rank-name:hover { color: #93adff; text-decoration: underline; }

/* Group Race */
.group-race-section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
}

.group-race-section h3 {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-dim);
    margin-bottom: 14px;
}

.race-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 10px;
}

.race-group-name {
    width: 80px;
    font-size: 0.82rem;
    font-weight: 600;
    text-align: right;
    flex-shrink: 0;
}

.race-bar-wrap {
    flex: 1;
    background: var(--bg);
    border-radius: 6px;
    height: 28px;
    overflow: hidden;
    position: relative;
}

.race-bar-fill {
    height: 100%;
    border-radius: 6px;
    transition: width 0.6s ease-out;
    display: flex;
    align-items: center;
    padding-left: 10px;
    font-size: 0.78rem;
    font-weight: 600;
    color: #fff;
    min-width: fit-content;
}

/* ── Modal ── */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    z-index: 1000;
    justify-content: center;
    align-items: center;
}

.modal-overlay.open { display: flex; animation: fadeIn 0.2s ease-out; }

.modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 24px;
    width: 90%;
    max-width: 700px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.4);
    animation: modalSlide 0.25s ease-out;
}

@keyframes modalSlide {
    from { opacity: 0; transform: translateY(12px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.modal-header h3 { font-size: 1.1rem; font-weight: 600; }

.modal-close {
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 1.5rem;
    cursor: pointer;
    line-height: 1;
    padding: 4px;
    border-radius: 6px;
    transition: color var(--transition), background var(--transition);
}

.modal-close:hover { color: var(--text); background: rgba(255, 255, 255, 0.05); }

.modal-stats {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.modal-stat {
    background: var(--bg);
    border-radius: 8px;
    padding: 10px 16px;
    flex: 1;
    min-width: 120px;
}

.modal-stat-label { font-size: 0.72rem; color: var(--text-dim); margin-bottom: 2px; }
.modal-stat-value { font-size: 1.2rem; font-weight: 700; letter-spacing: -0.02em; }

.modal-chart { margin-top: 8px; }

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

/* ── Live Section ── */
.live-section {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.live-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}

.live-filters {
    display: flex;
    gap: 8px;
    margin-left: auto;
}

.live-filters select,
.live-filters input {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 0.78rem;
    font-family: inherit;
    outline: none;
    transition: border-color 200ms;
}
.live-filters select:focus,
.live-filters input:focus { border-color: var(--accent); }
.live-filters input { width: 140px; }

.live-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
}

.live-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #4ade80;
    box-shadow: 0 0 8px rgba(74, 222, 128, 0.6);
    animation: live-pulse 2s ease-in-out infinite;
}

@keyframes live-pulse {
    0%, 100% { opacity: 1; box-shadow: 0 0 8px rgba(74, 222, 128, 0.6); }
    50% { opacity: 0.5; box-shadow: 0 0 4px rgba(74, 222, 128, 0.3); }
}

.live-label {
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    color: #4ade80;
    text-transform: uppercase;
}

.live-desc {
    font-size: 0.8rem;
    color: var(--text-dim);
}

.refresh-live-btn {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-dim);
    padding: 4px 12px;
    border-radius: 6px;
    font-size: 0.78rem;
    cursor: pointer;
    font-family: inherit;
    transition: all 200ms;
}
.refresh-live-btn:hover { border-color: var(--accent); color: var(--text); }

.live-summary {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
}

.live-stat {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px 16px;
    min-width: 120px;
}
.live-stat-label { font-size: 0.72rem; color: var(--text-dim); margin-bottom: 2px; }
.live-stat-value { font-size: 1.4rem; font-weight: 700; letter-spacing: -0.02em; }

.live-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 10px;
}

.live-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: border-color 200ms, box-shadow 200ms;
    cursor: pointer;
}
.live-card:hover {
    border-color: rgba(108, 140, 255, 0.3);
    box-shadow: 0 2px 12px rgba(108, 140, 255, 0.08);
}

.live-card-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.85rem;
    color: #1a1d27;
    flex-shrink: 0;
}

.live-card-info { flex: 1; min-width: 0; }
.live-card-name {
    font-size: 0.88rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.live-card-group { font-size: 0.72rem; }
.live-card-meta {
    text-align: right;
    flex-shrink: 0;
}
.live-card-msgs {
    font-size: 1rem;
    font-weight: 700;
    color: var(--accent);
}
.live-card-time {
    font-size: 0.68rem;
    color: var(--text-dim);
}

.live-empty {
    text-align: center;
    color: var(--text-dim);
    padding: 48px 0;
    font-size: 0.9rem;
}

/* ── Overview Mini Widgets ── */
.ov-rank-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 0;
    border-bottom: 1px solid var(--border);
}
.ov-rank-row:last-child { border-bottom: none; }

.ov-rank-num {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.72rem;
    flex-shrink: 0;
}
.ov-rank-num.r1 { background: #fbbf24; color: #1a1d27; }
.ov-rank-num.r2 { background: #94a3b8; color: #1a1d27; }
.ov-rank-num.r3 { background: #cd7f32; color: #1a1d27; }

.ov-rank-name { flex: 1; font-size: 0.85rem; font-weight: 500; }
.ov-rank-group { font-size: 0.72rem; margin-right: 8px; }
.ov-rank-score { font-size: 0.9rem; font-weight: 700; color: var(--accent); min-width: 32px; text-align: right; }

.ov-live-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.82rem;
}
.ov-live-item:last-child { border-bottom: none; }

.ov-live-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    flex-shrink: 0;
}
.ov-live-name { flex: 1; font-weight: 500; }
.ov-live-ago { font-size: 0.72rem; color: var(--text-dim); }
.ov-live-msgs { font-weight: 600; color: var(--accent); min-width: 24px; text-align: right; }

.ov-empty { color: var(--text-dim); font-size: 0.82rem; padding: 16px 0; text-align: center; }

/* ── Responsive ── */
@media (max-width: 768px) {
    .charts-row { grid-template-columns: 1fr; }
    .summary-cards { grid-template-columns: repeat(2, 1fr); }
    .tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .podium-section { flex-direction: column; align-items: center; min-height: auto; }
    .podium-card { width: 100%; max-width: 280px; }
    .podium-card.gold, .podium-card.silver, .podium-card.bronze { order: unset; }
    .score-explain { flex-direction: column; }
    .modal { width: 95%; padding: 16px; }
}
