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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: #2a2a2a;
    min-height: 100vh;
    padding: 20px;
    color: #FFFFFF;
}

/* Prevent FOUC - ensure tables and containers are visible from the start */
.scrollable-table-container,
.runs-table,
.leaderboard-table,
.stat-card,
.chart-container {
    visibility: visible !important;
    opacity: 1 !important;
}

/* Smooth transitions when loading completes */
body:not(.loading) .container {
    transition: filter 0.3s ease;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    background: #3a3a3a;
    border-radius: 8px;
    padding: 30px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 2px solid #5D5D5D;
}

h1 {
    color: #FA9549;
    font-size: 2.5em;
    font-weight: 600;
}

h2 {
    color: #FA9549;
    margin: 30px 0 20px 0;
    font-size: 1.8em;
    font-weight: 600;
}

.search-section {
    margin: 30px 0;
}

.search-bar {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}

.search-bar input {
    flex: 1;
    padding: 12px 16px;
    background: #2a2a2a;
    color: #FFFFFF;
    border: 1px solid #5D5D5D;
    border-radius: 4px;
    font-size: 1em;
    transition: all 0.2s ease;
}

.search-bar input:focus {
    outline: none;
    border-color: #FA9549;
}

.search-bar button {
    padding: 12px 24px;
    background: #FA9549;
    color: #FFFFFF;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1em;
    font-weight: 500;
    transition: all 0.2s ease;
}

.search-bar button:hover {
    background: #e8844a;
}

.suggestions-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: auto;
    width: calc(100% - 100px);
    background: #2a2a2a;
    border: 1px solid #5D5D5D;
    border-top: none;
    border-radius: 0 0 4px 4px;
    max-height: 300px;
    overflow-y: auto;
    z-index: 1000;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
    margin-top: -1px;
}

.suggestion-item {
    padding: 12px 16px;
    cursor: pointer;
    border-bottom: 1px solid #5D5D5D;
    transition: background 0.2s ease;
}

.suggestion-item:last-child {
    border-bottom: none;
}

.suggestion-item:hover {
    background: #4a4a4a;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin: 20px 0;
}

.stat-card {
    background: #2a2a2a;
    border: 1px solid #5D5D5D;
    color: #FFFFFF;
    padding: 24px;
    border-radius: 4px;
    text-align: center;
    transition: border-color 0.2s ease;
}

.stat-card:hover {
    border-color: #FA9549;
}

.stat-card h3 {
    font-size: 1.1em;
    margin-bottom: 12px;
    color: #FA9549;
    font-weight: 500;
}

.stat-number {
    font-size: 2.5em;
    font-weight: 600;
}

.chart-section {
    margin: 30px 0;
}

.chart-container {
    background: #2a2a2a;
    border: 1px solid #5D5D5D;
    border-radius: 4px;
    padding: 24px;
    margin: 20px 0;
    overflow-x: auto;
    position: relative;
}

.chart-description {
    text-align: center;
    margin-top: 10px;
    color: #FFFFFF;
    opacity: 0.7;
    font-size: 0.85em;
    position: sticky;
    left: 0;
    right: 0;
    background: #2a2a2a;
    padding: 5px 0;
    z-index: 1;
}

.chart-bars {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    height: 400px;
    gap: 5px;
    padding: 20px 20px 20px 0;
}

.chart-bar-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    height: 100%;
    min-width: 30px;
    cursor: pointer;
    transition: opacity 0.2s ease;
}

.chart-bar-container:hover {
    opacity: 0.8;
}

.chart-bar {
    width: 100%;
    min-height: 2px;
    background: #FA9549;
    border-radius: 2px 2px 0 0;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding-top: 5px;
    transition: all 0.2s ease;
    position: relative;
}

.chart-bar:hover {
    background: #5F668C;
}

.chart-bar-value {
    color: #FFFFFF;
    font-weight: 600;
    font-size: 0.85em;
}

.chart-bar-label {
    margin-top: 8px;
    font-size: 0.85em;
    font-weight: 500;
    color: #FFFFFF;
    text-align: center;
}

.floor-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 15px;
    margin: 20px 0;
}

.floor-card {
    background: #2a2a2a;
    border: 1px solid #5D5D5D;
    padding: 15px;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: center;
}

.floor-card:hover {
    border-color: #FA9549;
}

.floor-header {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.floor-number {
    font-weight: 600;
    color: #FA9549;
}

.floor-count {
    color: #FFFFFF;
}

.leaderboard-table, .recent-table, .runs-table {
    width: 100%;
    border-collapse: collapse;
    margin: 0;
    background: #2a2a2a;
    border: none;
}

.leaderboard-table thead,
.recent-table thead,
.runs-table thead {
    background: #5F668C;
    color: #FFFFFF;
}

.leaderboard-table th,
.leaderboard-table td,
.recent-table th,
.recent-table td,
.runs-table th,
.runs-table td {
    padding: 12px 16px;
    text-align: left;
}

.leaderboard-table tbody tr,
.recent-table tbody tr,
.runs-table tbody tr {
    border-bottom: 1px solid #5D5D5D;
    cursor: pointer;
    transition: background 0.2s ease;
}

.leaderboard-table tbody tr:hover,
.recent-table tbody tr:hover,
.runs-table tbody tr:hover {
    background: #4a4a4a;
}

.player-card {
    background: #2a2a2a;
    border: 1px solid #5D5D5D;
    border-radius: 4px;
    padding: 24px;
    margin: 20px 0;
}

.player-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.player-card h3 {
    color: #FA9549;
    font-size: 2em;
    margin: 0;
    font-weight: 600;
}

.close-player-btn {
    background: #5D5D5D;
    color: #FFFFFF;
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 4px;
    font-size: 1.2em;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.close-player-btn:hover {
    background: #FA9549;
}

.player-card h4 {
    color: #FA9549;
    margin: 20px 0 10px 0;
    font-weight: 600;
}

.player-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    margin: 20px 0;
}

.player-stat {
    background: #3a3a3a;
    padding: 15px;
    border-radius: 4px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border: 1px solid #5D5D5D;
    flex: 1 1 200px;
}

/* Removed max-width constraint - cards now fill space evenly */

.player-stat .label {
    font-weight: 500;
    color: #FFFFFF;
}

.player-stat .value {
    font-size: 1.5em;
    font-weight: 600;
    color: #FA9549;
}

.error {
    background: #5D5D5D;
    color: #FFFFFF;
    padding: 15px;
    border-radius: 4px;
    margin: 20px 0;
    border: 1px solid #FA9549;
}

.modal {
    display: flex;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    align-items: center;
    justify-content: center;
}

.modal-content {
    background: #3a3a3a;
    padding: 30px;
    border-radius: 4px;
    max-width: 1100px;
    max-height: 80vh;
    overflow: hidden;
    position: relative;
    border: 1px solid #5D5D5D;
    color: #FFFFFF;
}

.modal-content h2 {
    margin-top: 0;
    margin-bottom: 20px;
}

.close {
    position: absolute;
    right: 20px;
    top: 20px;
    font-size: 2em;
    cursor: pointer;
    color: #5D5D5D;
    transition: color 0.2s ease;
}

.close:hover {
    color: #FA9549;
}

.completed-badge {
    background: #5F668C;
    color: #FFFFFF;
    padding: 4px 10px;
    border-radius: 3px;
    font-size: 0.85em;
    font-weight: 500;
}

.incomplete-badge {
    background: #5D5D5D;
    color: #FFFFFF;
    padding: 4px 10px;
    border-radius: 3px;
    font-size: 0.85em;
    font-weight: 500;
}

/* Custom scrollbar styling for dark theme */
::-webkit-scrollbar {
    width: 12px;
    height: 12px;
}

::-webkit-scrollbar-track {
    background: #2a2a2a;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: #5D5D5D;
    border-radius: 4px;
    border: 2px solid #2a2a2a;
}

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

::-webkit-scrollbar-corner {
    background: #2a2a2a;
}

/* Scrollable table container */
.scrollable-table-container {
    border: 1px solid #5D5D5D;
    border-radius: 4px;
    background: #2a2a2a;
    overflow-x: auto;
    overflow-y: hidden;
}

.scrollable-table-container .leaderboard-table {
    display: block;
    max-height: 80vh;
    min-width: 970px;
}

.scrollable-table-container .runs-table {
    display: block;
    max-height: 50vh;
    min-width: 970px;
}

.scrollable-table-container .leaderboard-table thead,
.scrollable-table-container .runs-table thead {
    display: table;
    width: 100%;
    table-layout: fixed;
    position: sticky;
    top: 0;
    z-index: 10;
}

/* Extend header background over scrollbar area - only shown when scrollbar present */
.scrollable-table-container .leaderboard-table thead.has-scrollbar::after,
.scrollable-table-container .runs-table thead.has-scrollbar::after {
    content: '';
    position: absolute;
    top: 0;
    right: -12px;
    width: 12px;
    height: 100%;
    background: #5F668C;
    pointer-events: none;
}

/* Adjust header width when scrollbar is present */
.scrollable-table-container .leaderboard-table thead.has-scrollbar,
.scrollable-table-container .runs-table thead.has-scrollbar {
    width: calc(100% - 12px);
}

.scrollable-table-container .leaderboard-table tbody {
    display: block;
    max-height: calc(80vh - 48px);
    overflow-y: auto;
    overflow-x: hidden;
}

.scrollable-table-container .runs-table tbody {
    display: block;
    max-height: calc(50vh - 48px);
    overflow-y: auto;
    overflow-x: hidden;
}

.scrollable-table-container .leaderboard-table tr,
.scrollable-table-container .runs-table tr {
    display: table;
    width: 100%;
    table-layout: fixed;
}

/* Sticky table headers for scrollable containers */
.scrollable-table-container thead th {
    position: sticky;
    top: 0;
    z-index: 10;
    background: #5F668C;
    box-shadow: 0 1px 0 #5D5D5D;
}

/* Remove hover effect from non-clickable rows */
.runs-table tbody tr[style*="cursor: default"]:hover {
    background: transparent;
    cursor: default;
}

/* Modern loading state with spinner */
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

body.loading::before {
    content: '';
    position: fixed;
    top: 50%;
    left: 50%;
    width: 60px;
    height: 60px;
    margin: -50px 0 0 -30px;
    border: 4px solid rgba(250, 149, 73, 0.2);
    border-top-color: #FA9549;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    z-index: 9999;
}

body.loading::after {
    content: 'Loading data..';
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, 28px);
    color: #FFFFFF;
    font-size: 1.1em;
    font-weight: 600;
    letter-spacing: 0.5px;
    animation: pulse 1.5s ease-in-out infinite;
    z-index: 9999;
    text-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
}

body.loading {
    overflow: hidden;
    position: fixed;
    width: 100%;
}

body.loading .container {
    filter: blur(3px);
    pointer-events: none;
    transition: filter 0.3s ease;
}

body:not(.loading) .container {
    filter: none;
    pointer-events: auto;
}

/* Mobile optimizations */
@media (max-width: 768px) {
    body {
        padding: 10px;
    }

    .container {
        padding: 15px;
    }

    h1 {
        font-size: 1.8em;
    }

    h2 {
        font-size: 1.4em;
        margin: 20px 0 15px 0;
    }

    .search-bar {
        flex-direction: column;
    }

    .search-bar button {
        width: 100%;
    }

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

    .stat-card h3 {
        font-size: 0.9em;
    }

    .stat-number {
        font-size: 1.5em;
    }

    /* Simplify tables on mobile */
    .leaderboard-table,
    .runs-table {
        font-size: 0.85em;
    }

    .leaderboard-table th,
    .leaderboard-table td,
    .runs-table th,
    .runs-table td {
        padding: 8px 4px;
    }

    /* Reduce chart bar count on mobile */
    .chart-bars {
        gap: 4px;
    }

    .chart-bar-container {
        min-width: 35px;
    }

    .chart-bar-label {
        font-size: 0.7em;
    }

    .chart-bar-value {
        font-size: 0.7em;
    }

    /* Modal adjustments for mobile */
    .modal-content {
        padding: 15px;
        max-width: 95vw;
        max-height: 90vh;
    }

    .modal-content h2 {
        font-size: 1.2em;
    }

    .close {
        font-size: 1.5em;
        right: 10px;
        top: 10px;
    }
}

/* Optimize scrolling performance on iOS */
.scrollable-table-container tbody {
    -webkit-overflow-scrolling: touch;
}

/* Prevent zoom on input focus on iOS */
@media (max-width: 768px) {
    input, select, textarea {
        font-size: 16px;
    }
}
