:root {
    --bg-gradient: linear-gradient(180deg, #000000 0%, #050505 100%);
    --container-bg: rgba(5, 5, 5, 0.98);
    --card-bg: rgba(255, 255, 255, 0.03);
    --text-primary: #ffffff;
    --text-secondary: #a8a8a8;
    --border-color: rgba(255, 255, 255, 0.08);
    --shadow-color: rgba(0, 0, 0, 0.8);
    --chart-canvas-bg: radial-gradient(circle at center, rgba(30, 30, 50, 0.1) 0%, #000 100%);
}

[data-theme="light"] {
    --bg-gradient: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    --container-bg: rgba(255, 255, 255, 0.98);
    --card-bg: rgba(0, 0, 0, 0.03);
    --text-primary: #1a1a1a;
    --text-secondary: #555555;
    --border-color: rgba(0, 0, 0, 0.08);
    --shadow-color: rgba(0, 0, 0, 0.1);
    --chart-canvas-bg: radial-gradient(circle at center, rgba(230, 230, 250, 0.2) 0%, #ffffff 100%);
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-gradient);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 20px 0 0 0;
    overflow: hidden;
}

body::-webkit-scrollbar {
    display: none;
}

.game-container {
    width: 100%;
    max-width: 900px;
    max-height: 90vh;
    background: var(--container-bg);
    border-radius: 24px;
    padding: 0 30px 30px 30px;
    box-shadow: 0 20px 60px var(--shadow-color);
    position: relative;
    overflow-y: auto;
    overflow-x: hidden;
    border: 1px solid var(--border-color);
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.game-container::-webkit-scrollbar {
    display: none;
}

html,
body {
    overflow: hidden;
}

/* Screen Management */
.screen {
    display: none;
    animation: fadeIn 0.4s ease;
}

.screen.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Welcome Screen */
.game-title {
    font-size: 32px;
    font-weight: 700;
    text-align: center;
    margin-top: 0 !important;
    margin-bottom: 5px;
    background: linear-gradient(135deg, #ff1e1e 0%, #ff8c00 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.game-subtitle {
    text-align: center;
    color: var(--text-secondary);
    font-size: 14px;
    margin-bottom: 20px;
}

.team-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

.team-card {
    background: var(--card-bg);
    border: 2px solid var(--border-color);
    border-radius: 12px;
    padding: 12px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.team-card:hover {
    transform: translateY(-8px) scale(1.05);
    border-color: var(--border-color);
    box-shadow: 0 15px 40px var(--shadow-color);
}

.team-card.selected {
    border-color: #00ff00;
    background: rgba(0, 255, 0, 0.1);
    box-shadow: 0 0 30px rgba(0, 255, 0, 0.3);
}

.team-color {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.team-logo {
    width: 70%;
    height: 70%;
    object-fit: contain;
}

.team-name {
    font-size: 12px;
    font-weight: 600;
    text-align: center;
    color: var(--text-primary);
}

/* Instructions Screen */
.screen-title {
    font-size: 24px;
    font-weight: 700;
    text-align: center;
    margin-bottom: 20px;
    color: var(--text-primary);
}

.instructions {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 24px;
}

.instruction-item {
    display: flex;
    align-items: center;
    gap: 12px;
    background: rgba(255, 255, 255, 0.05);
    padding: 12px;
    border-radius: 8px;
}

.instruction-number {
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, #ff1e1e 0%, #ff8c00 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: 700;
    flex-shrink: 0;
}

.instruction-item p {
    font-size: 13px;
    color: var(--text-secondary);
}

.selected-team {
    text-align: center;
    font-size: 16px;
    margin-bottom: 20px;
    color: var(--text-secondary);
}

#selected-team-name {
    color: #00ff00;
    font-weight: 700;
}

/* Buttons */
.btn-primary,
.btn-secondary {
    width: 100%;
    padding: 12px 24px;
    font-size: 16px;
    font-weight: 700;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.btn-primary {
    background: linear-gradient(135deg, #ff1e1e 0%, #ff8c00 100%);
    color: white;
    box-shadow: 0 10px 30px rgba(255, 30, 30, 0.3);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 15px 40px rgba(255, 30, 30, 0.4);
}

.btn-secondary {
    background: var(--card-bg);
    color: var(--text-primary);
    border: 2px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--border-color);
    border-color: var(--text-secondary);
}

/* Test Screen */
.traffic-light-container {
    display: flex;
    justify-content: center;
    margin-bottom: 40px;
}

.traffic-light {
    background: #222;
    padding: 15px;
    border-radius: 16px;
    display: flex;
    gap: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.light {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    transition: all 0.3s ease;
}

.light.red.active {
    background: #ff0000;
    box-shadow: 0 0 30px rgba(255, 0, 0, 0.8);
}

.light.green.active {
    background: #00ff00;
    box-shadow: 0 0 30px rgba(0, 255, 0, 0.8);
}

.test-message {
    text-align: center;
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 15px;
}

.click-area {
    width: 100%;
    height: 120px;
    background: rgba(255, 255, 255, 0.05);
    border: 3px dashed rgba(255, 255, 255, 0.2);
    border-radius: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.click-area:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.3);
}

.click-area.ready {
    border-color: #00ff00;
    background: rgba(0, 255, 0, 0.1);
    cursor: pointer;
}

/* Results Screen */
.result-card {
    text-align: center;
    background: rgba(255, 255, 255, 0.05);
    padding: 40px;
    border-radius: 20px;
    margin-bottom: 30px;
}

.result-time {
    font-size: 72px;
    font-weight: 700;
    background: linear-gradient(135deg, #00ff00 0%, #00cc00 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 10px;
}

.result-label {
    font-size: 18px;
    color: var(--text-secondary);
}

.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 30px;
}

.stat-card {
    background: var(--card-bg);
    padding: 24px;
    border-radius: 16px;
    text-align: center;
    border: 1px solid var(--border-color);
}

.stat-value {
    font-size: 36px;
    font-weight: 700;
    color: #00ff00;
    margin-bottom: 8px;
}

.stat-label {
    font-size: 14px;
    color: var(--text-secondary);
}

.result-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

/* ═══ DASHBOARD COMMAND CENTER ═══════════════════════════════ */

.dashboard-title {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-bottom: 20px;
    padding: 12px 0;
}

.dashboard-title h2 {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    background: linear-gradient(135deg, #ff1e1e 0%, #ff8c00 50%, #ffcc00 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.dashboard-icon {
    font-size: 20px;
    animation: iconPulse 2s infinite;
}

@keyframes iconPulse {

    0%,
    100% {
        opacity: 0.6;
        transform: scale(1);
    }

    50% {
        opacity: 1;
        transform: scale(1.2);
    }
}

/* ── Dashboard Grid ─────────────────────────────── */
.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr 2.5fr 1fr;
    gap: 12px;
    margin-bottom: 16px;
}

/* ── KPI Cards ──────────────────────────────────── */
.kpi-column {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.kpi-card {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 14px;
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    position: relative;
    overflow: hidden;
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
}

.kpi-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 3px;
    height: 100%;
    background: linear-gradient(180deg, #ff1e1e, #ff8c00);
    border-radius: 3px 0 0 3px;
    opacity: 0.6;
}

.kpi-card:hover {
    border-color: rgba(255, 140, 0, 0.3);
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(255, 140, 0, 0.1);
}

.kpi-icon {
    font-size: 14px;
    color: #ff8c00;
    opacity: 0.8;
}

.kpi-value {
    font-size: 22px;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1;
}

.kpi-value-sm {
    font-size: 16px;
}

.kpi-label {
    font-size: 11px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 500;
}

.kpi-trend {
    font-size: 10px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 4px;
}

.kpi-trend.positive {
    color: #00ff88;
}

.kpi-trend.neutral {
    color: var(--text-secondary);
}

.kpi-trend.negative {
    color: #ff4444;
}

/* ── Central 3D Chart Card ──────────────────────── */
.central-chart-card {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 16px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    position: relative;
}

.central-chart-card::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 16px;
    padding: 1px;
    background: linear-gradient(135deg, rgba(255, 140, 0, 0.2), transparent, rgba(255, 30, 30, 0.2));
    mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
    mask-composite: xor;
    -webkit-mask-composite: xor;
    pointer-events: none;
}

.central-chart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.central-chart-header h3 {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
}

.chart-badge {
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 1px;
    padding: 3px 8px;
    background: linear-gradient(135deg, #ff1e1e, #ff8c00);
    border-radius: 20px;
    color: white;
    animation: badgePulse 3s infinite;
}

@keyframes badgePulse {

    0%,
    100% {
        box-shadow: 0 0 6px rgba(255, 140, 0, 0.3);
    }

    50% {
        box-shadow: 0 0 15px rgba(255, 140, 0, 0.6);
    }
}

.central-3d {
    flex: 1;
    min-height: 320px;
}

/* ── Color Bar for 3D Surface ──────────────────────────────── */
.graph-colorbar {
    position: absolute;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    z-index: 10;
}

.colorbar-gradient {
    width: 12px;
    height: 100px;
    border-radius: 6px;
    background: linear-gradient(to bottom,
            #ff2600,
            #ffe500,
            #00ff33,
            #00ccff,
            #0000ff);
    box-shadow: 0 0 12px rgba(0, 200, 255, 0.25);
    border: 1px solid rgba(255, 255, 255, 0.15);
}

.colorbar-label {
    font-size: 9px;
    font-weight: 700;
    color: rgba(255, 255, 255, 0.6);
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

[data-theme="light"] .colorbar-label {
    color: rgba(0, 0, 0, 0.7);
}

[data-theme="light"] .colorbar-gradient {
    border: 1px solid rgba(0, 0, 0, 0.2);
    box-shadow: 0 0 8px rgba(0, 0, 0, 0.1);
}

.central-chart-footer {
    padding: 8px 16px;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    text-align: center;
}

.footer-hint {
    font-size: 11px;
    color: var(--text-secondary);
    opacity: 0.6;
}

.footer-hint i {
    margin-right: 4px;
}

/* ── Bottom Row ─────────────────────────────────── */
.dashboard-bottom {
    display: grid;
    grid-template-columns: 1fr 1.2fr 1fr;
    gap: 12px;
    margin-bottom: 20px;
}

.mini-chart-card,
.leaderboard-card {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 14px;
    padding: 14px;
    overflow: hidden;
}

.mini-chart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.mini-chart-header h4 {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
}

.mini-badge {
    font-size: 8px;
    font-weight: 700;
    letter-spacing: 0.8px;
    padding: 2px 6px;
    background: rgba(255, 140, 0, 0.15);
    border: 1px solid rgba(255, 140, 0, 0.3);
    border-radius: 10px;
    color: #ff8c00;
}

.mini-chart-card canvas {
    width: 100% !important;
    height: auto !important;
    display: block;
    border-radius: 8px;
}

/* ── Leaderboard ────────────────────────────────── */
.leaderboard-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.leaderboard-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 10px;
    transition: all 0.2s ease;
    border: 1px solid transparent;
}

.leaderboard-item:hover {
    border-color: rgba(255, 140, 0, 0.2);
    background: rgba(255, 140, 0, 0.05);
}

.leaderboard-rank {
    font-size: 12px;
    font-weight: 700;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    flex-shrink: 0;
}

.leaderboard-rank.gold {
    background: linear-gradient(135deg, #FFD700, #FFA500);
    color: #000;
}

.leaderboard-rank.silver {
    background: linear-gradient(135deg, #C0C0C0, #A0A0A0);
    color: #000;
}

.leaderboard-rank.bronze {
    background: linear-gradient(135deg, #CD7F32, #A0522D);
    color: #fff;
}

.leaderboard-rank.default {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-secondary);
}

.leaderboard-color {
    width: 10px;
    height: 10px;
    border-radius: 3px;
    flex-shrink: 0;
}

.leaderboard-team {
    flex: 1;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-primary);
}

.leaderboard-time {
    font-size: 12px;
    font-weight: 700;
    color: #00ff88;
    font-family: 'Courier New', monospace;
}

/* ── Actions Row ────────────────────────────────── */
.analytics-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

/* ── Tooltip ────────────────────────────────────── */
.f1-chart-tooltip {
    position: absolute;
    pointer-events: none;
    background: var(--container-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 10px 14px;
    font-size: 13px;
    color: var(--text-primary);
    opacity: 0;
    transition: opacity 0.2s;
    z-index: 100;
    white-space: nowrap;
    box-shadow: 0 8px 32px var(--shadow-color);
}

/* ── Chart Container (shared) ───────────────────── */
.chart-container-3d {
    position: relative;
    width: 100%;
    min-height: 280px;
}

.chart-canvas-3d {
    width: 100%;
    height: 100%;
    min-height: 280px;
}

/* ═══ LIGHT THEME ════════════════════════════════════════════ */

[data-theme="light"] .kpi-card {
    background: rgba(0, 0, 0, 0.02);
    border-color: rgba(0, 0, 0, 0.08);
}

[data-theme="light"] .kpi-card:hover {
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.08);
}

[data-theme="light"] .kpi-icon {
    color: #e65100;
}

[data-theme="light"] .kpi-trend.positive {
    color: #00a152;
}

[data-theme="light"] .central-chart-card {
    background: rgba(0, 0, 0, 0.01);
    border-color: rgba(0, 0, 0, 0.08);
}

[data-theme="light"] .central-chart-card::after {
    background: linear-gradient(135deg, rgba(255, 140, 0, 0.15), transparent, rgba(255, 30, 30, 0.15));
}

[data-theme="light"] .central-chart-header {
    border-bottom-color: rgba(0, 0, 0, 0.06);
}

[data-theme="light"] .central-chart-footer {
    border-top-color: rgba(0, 0, 0, 0.06);
}

[data-theme="light"] .mini-chart-card,
[data-theme="light"] .leaderboard-card {
    background: rgba(0, 0, 0, 0.02);
    border-color: rgba(0, 0, 0, 0.08);
}

[data-theme="light"] .leaderboard-item {
    background: rgba(0, 0, 0, 0.02);
}

[data-theme="light"] .leaderboard-item:hover {
    border-color: rgba(255, 140, 0, 0.15);
    background: rgba(255, 140, 0, 0.04);
}

[data-theme="light"] .leaderboard-time {
    color: #00a152;
}

[data-theme="light"] .leaderboard-rank.default {
    background: rgba(0, 0, 0, 0.06);
}

/* ═══ RESPONSIVE ═════════════════════════════════════════════ */

@media (max-width: 600px) {
    .dashboard-grid {
        grid-template-columns: 1fr;
    }

    .kpi-column {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }

    .central-3d {
        min-height: 250px;
    }

    .dashboard-bottom {
        grid-template-columns: 1fr;
    }

    .team-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .result-time {
        font-size: 56px;
    }

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

    .result-actions {
        grid-template-columns: 1fr;
    }
}