:root {
    --bg-dark: #121212;
    --bg-card: #1e1e1e;
    --text-primary: #e0e0e0;
    --text-secondary: #a0a0a0;
    --accent: #64b5f6;
    --accent-hover: #42a5f5;
    --border: #333;
    --success: #66bb6a;
    --danger: #ef5350;
}

body {
    margin: 0;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-primary);
    overflow: hidden;
    /* App-like feel */
    height: 100vh;
    display: flex;
    flex-direction: column;
}

header {
    background-color: var(--bg-card);
    border-bottom: 1px solid var(--border);
    padding: 1rem 2rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 60px;
    flex-shrink: 0;
}

.logo {
    font-weight: 700;
    font-size: 1.2rem;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.controls {
    display: flex;
    gap: 1rem;
    align-items: center;
}

select {
    background: var(--bg-dark);
    color: var(--text-primary);
    border: 1px solid var(--border);
    padding: 0.5rem 1rem;
    border-radius: 6px;
    font-size: 0.9rem;
    outline: none;
    cursor: pointer;
}

select:focus {
    border-color: var(--accent);
}

.mode-switch {
    display: flex;
    background: var(--bg-dark);
    border-radius: 6px;
    padding: 2px;
    border: 1px solid var(--border);
}

.mode-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 0.4rem 1rem;
    font-size: 0.9rem;
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s;
}

.mode-btn.active {
    background-color: var(--bg-card);
    color: var(--accent);
    font-weight: 600;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

main {
    flex: 1;
    display: flex;
    position: relative;
    overflow: hidden;
}

#chart-container {
    flex: 1;
    position: relative;
    padding: 1rem;
    display: flex;
    flex-direction: column;
}

#main-chart {
    width: 100%;
    height: 100%;
    border-radius: 8px;
    background: var(--bg-card);
    overflow: hidden;
}

#map-container {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 100;
    background: var(--bg-dark);
    display: none;
}

#map-view {
    width: 100%;
    height: 100%;
}



/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-dark);
}

::-webkit-scrollbar-thumb {
    background: #444;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* Mobile Responsive Design */
@media screen and (max-width: 768px) {
    body {
        height: calc(var(--vh, 1vh) * 100);
        /* Use actual viewport height */
        overflow: hidden;
    }

    header {
        padding: 0.3rem 0.5rem;
        height: auto;
        flex-direction: column;
        gap: 0.3rem;
        align-items: stretch;
    }

    .logo {
        display: none !important;
        /* Hide logo on mobile to save space */
    }

    .controls {
        flex-wrap: wrap;
        gap: 0.3rem;
    }

    select {
        flex: 1;
        min-width: 0;
        font-size: 0.75rem;
        padding: 0.35rem 0.5rem;
    }

    .mode-switch {
        width: 100%;
        justify-content: space-between;
    }

    .mode-btn {
        flex: 1;
        font-size: 0.7rem;
        padding: 0.3rem 0.3rem;
    }

    #chart-container {
        padding: 0.25rem;
    }


}

/* Landscape mobile */
@media screen and (max-width: 768px) and (orientation: landscape) {
    header {
        flex-direction: row;
        height: 50px;
        padding: 0.5rem 1rem;
    }

    .logo {
        font-size: 0.9rem;
    }

    .mode-switch {
        width: auto;
    }

    .mode-btn {
        padding: 0.3rem 0.75rem;
        font-size: 0.8rem;
    }
}

/* --- Full History View --- */
#full-history-view {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    overflow-y: auto;
    padding: 1rem;
    background: #121212;
    /* Deeper dark */
    z-index: 5;
    -webkit-overflow-scrolling: touch;
    /* Smooth scroll on iOS */
}

#history-content {
    max-width: 900px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    padding-bottom: 2rem;
}

.comp-card {
    background: #1e1e1e;
    border-radius: 16px;
    border: 1px solid #333;
    overflow: hidden;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    transition: transform 0.2s;
}

.comp-header {
    background: linear-gradient(135deg, #1976d2, #1565c0);
    padding: 1.2rem 1.5rem;
    color: white;
}

.comp-header h3 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 700;
}

.comp-meta {
    font-size: 0.85rem;
    opacity: 0.8;
    margin-top: 0.3rem;
    display: flex;
    gap: 15px;
}

.comp-body {
    padding: 1.2rem;
}

.event-block {
    margin-bottom: 2rem;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 12px;
    padding: 1rem;
}

.event-block:last-child {
    margin-bottom: 0;
}

.event-title-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid #333;
}

.event-label {
    color: #64b5f6;
    font-weight: 800;
    font-size: 1rem;
    display: flex;
    align-items: center;
    gap: 8px;
}

.event-bests {
    font-size: 0.85rem;
    color: #888;
}

.event-bests b {
    color: #fff;
    margin-left: 4px;
}

/* Round Table */
.round-table {
    width: 100%;
    border-collapse: collapse;
}

.round-table tr:hover {
    background: rgba(255, 255, 255, 0.02);
}

.round-table th {
    text-align: left;
    color: #555;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    padding: 0.5rem;
}

.round-table td {
    padding: 0.75rem 0.5rem;
    border-top: 1px solid #2a2a2a;
}

.mobile-solves {
    display: none;
    font-size: 0.75rem;
    color: #888;
    margin-top: 4px;
    font-family: 'Inter', sans-serif;
}

.td-name {
    width: 30%;
    color: #eee;
    font-weight: 500;
}

.td-solves {
    color: #999;
    font-size: 0.85rem;
    font-family: 'Inter', sans-serif;
}

.td-avg {
    text-align: right;
    width: 15%;
    color: #64b5f6;
    font-weight: 700;
}

.td-pos {
    text-align: right;
    width: 10%;
    color: #ffa726;
    font-weight: 800;
    font-size: 1.1rem;
}

/* Mobile responsive */
@media (max-width: 768px) {
    #history-content {
        padding: 0.5rem;
    }

    .comp-meta {
        flex-direction: column;
        gap: 2px;
    }

    .hide-mobile {
        display: none !important;
    }

    .td-solves {
        display: none;
    }

    .mobile-solves {
        display: block;
    }

    .td-name {
        width: 60%;
        /* Take more space for stacked data */
    }

    .td-avg {
        width: 25%;
        text-align: right;
    }

    .td-pos {
        width: 15%;
        text-align: right;
    }

    .event-title-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 5px;
    }
}