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

:root {
    --primary: #ff4444;
    --secondary: #4444ff;
    --accent: #44ff44;
    --dark: #1a1a2e;
    --darker: #0f0f1a;
    --light: #f0f0f0;
    --gray: #888;
    --card-bg: #252540;
    --border: #333355;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, var(--darker) 0%, var(--dark) 100%);
    color: var(--light);
    min-height: 100vh;
    overflow-x: hidden;
}

.app-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
}

/* Header */
.header {
    text-align: center;
    padding: 30px 0;
    border-bottom: 2px solid var(--border);
    margin-bottom: 20px;
}

.header h1 {
    font-size: 2.5rem;
    background: linear-gradient(45deg, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 10px;
}

.header p {
    color: var(--gray);
    font-size: 1.1rem;
}

/* Navigation */
.nav-tabs {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-bottom: 30px;
    flex-wrap: wrap;
}

.nav-btn {
    padding: 12px 24px;
    border: none;
    background: var(--card-bg);
    color: var(--light);
    border-radius: 8px;
    cursor: pointer;
    font-size: 1rem;
    transition: all 0.3s ease;
    border: 2px solid transparent;
}

.nav-btn:hover {
    background: var(--border);
    transform: translateY(-2px);
}

.nav-btn.active {
    background: var(--primary);
    border-color: var(--primary);
}

/* Tab Content */
.tab-content {
    display: none;
    animation: fadeIn 0.3s ease;
}

.tab-content.active {
    display: block;
}

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

/* Garage */
.garage-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.garage-header h2 {
    font-size: 1.8rem;
}

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

.car-card {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 20px;
    border: 2px solid var(--border);
    transition: all 0.3s ease;
    cursor: pointer;
}

.car-card:hover {
    transform: translateY(-5px);
    border-color: var(--primary);
    box-shadow: 0 10px 30px rgba(255, 68, 68, 0.2);
}

.car-card .car-preview-small {
    height: 120px;
    margin-bottom: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.car-card h3 {
    font-size: 1.2rem;
    margin-bottom: 8px;
}

.car-card .car-type {
    color: var(--gray);
    font-size: 0.9rem;
    margin-bottom: 10px;
}

.car-card .car-stats {
    display: flex;
    gap: 15px;
    font-size: 0.85rem;
}

.car-card .stat {
    display: flex;
    align-items: center;
    gap: 5px;
}

.car-card .actions {
    display: flex;
    gap: 10px;
    margin-top: 15px;
}

/* Builder */
.builder-container {
    display: grid;
    grid-template-columns: 350px 1fr;
    gap: 30px;
}

.builder-sidebar {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 20px;
    border: 2px solid var(--border);
    height: fit-content;
}

.builder-sidebar h3 {
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 2px solid var(--border);
}

.config-section {
    margin-bottom: 20px;
}

.config-section label {
    display: block;
    margin-bottom: 8px;
    color: var(--gray);
    font-size: 0.9rem;
}

.config-section input,
.config-section select {
    width: 100%;
    padding: 10px;
    border: 2px solid var(--border);
    background: var(--darker);
    color: var(--light);
    border-radius: 6px;
    font-size: 1rem;
}

.config-section input:focus,
.config-section select:focus {
    outline: none;
    border-color: var(--primary);
}

.color-picker {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.color-option {
    width: 35px;
    height: 35px;
    border-radius: 50%;
    cursor: pointer;
    border: 3px solid transparent;
    transition: all 0.2s ease;
}

.color-option:hover {
    transform: scale(1.1);
}

.color-option.selected {
    border-color: var(--light);
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.3);
}

.upgrade-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.upgrade-item {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    padding: 8px;
    border-radius: 6px;
    transition: background 0.2s;
}

.upgrade-item:hover {
    background: var(--border);
}

.upgrade-item input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--primary);
}

.stats-preview {
    background: var(--darker);
    padding: 15px;
    border-radius: 8px;
}

.stats-preview h4 {
    margin-bottom: 15px;
    color: var(--primary);
}

.stat-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
    font-size: 0.85rem;
}

.stat-bar span:first-child {
    width: 80px;
    color: var(--gray);
}

.stat-bar .bar {
    flex: 1;
    height: 8px;
    background: var(--border);
    border-radius: 4px;
    overflow: hidden;
}

.stat-bar .bar div {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--secondary));
    border-radius: 4px;
    transition: width 0.3s ease;
}

.builder-preview {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 20px;
    border: 2px solid var(--border);
}

.car-preview-container {
    height: 400px;
    background: linear-gradient(180deg, #1a1a3e 0%, #0a0a1a 100%);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
    margin-bottom: 20px;
}

.car-preview-container::before {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 40%;
    background: linear-gradient(180deg, transparent 0%, rgba(255, 68, 68, 0.1) 100%);
}

.preview-controls {
    display: flex;
    justify-content: center;
    gap: 15px;
}

/* Buttons */
.btn-primary {
    padding: 12px 24px;
    background: linear-gradient(45deg, var(--primary), #ff6666);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    transition: all 0.3s ease;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 20px rgba(255, 68, 68, 0.4);
}

.btn-secondary {
    padding: 10px 20px;
    background: var(--border);
    color: var(--light);
    border: 2px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.3s ease;
}

.btn-secondary:hover {
    background: var(--card-bg);
    border-color: var(--primary);
}

.btn-full {
    width: 100%;
    margin-top: 20px;
}

.btn-danger {
    background: linear-gradient(45deg, #ff4444, #ff6666);
    padding: 8px 16px;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
}

/* Test Drive */
.testdrive-container {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.game-area {
    position: relative;
    background: var(--darker);
    border-radius: 12px;
    overflow: hidden;
    border: 2px solid var(--border);
}

#gameCanvas {
    width: 100%;
    height: 500px;
    display: block;
}

.game-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 15, 26, 0.95);
    display: flex;
    align-items: center;
    justify-content: center;
}

.overlay-content {
    text-align: center;
}

.overlay-content h2 {
    margin-bottom: 30px;
    font-size: 1.8rem;
}

.car-select-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 15px;
    max-width: 800px;
    margin: 0 auto;
}

.car-select-item {
    background: var(--card-bg);
    border: 2px solid var(--border);
    border-radius: 10px;
    padding: 15px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.car-select-item:hover {
    border-color: var(--primary);
    transform: scale(1.05);
}

.car-select-item .mini-car {
    height: 60px;
    margin-bottom: 10px;
}

.game-ui {
    position: absolute;
    top: 20px;
    left: 20px;
    right: 20px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    pointer-events: none;
}

.speedometer {
    background: rgba(0, 0, 0, 0.8);
    border-radius: 50%;
    width: 120px;
    height: 120px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border: 4px solid var(--primary);
}

.speed-value {
    font-size: 2.5rem;
    font-weight: bold;
    color: var(--primary);
}

.speed-unit {
    font-size: 0.9rem;
    color: var(--gray);
}

.rpm-gauge {
    background: rgba(0, 0, 0, 0.8);
    padding: 15px 25px;
    border-radius: 8px;
    text-align: center;
}

.rpm-bar {
    width: 150px;
    height: 10px;
    background: var(--border);
    border-radius: 5px;
    margin-bottom: 8px;
    overflow: hidden;
}

.rpm-bar::after {
    content: '';
    display: block;
    height: 100%;
    width: 30%;
    background: linear-gradient(90deg, var(--accent), var(--primary));
    border-radius: 5px;
    transition: width 0.1s;
}

.gear-display {
    background: rgba(0, 0, 0, 0.8);
    width: 60px;
    height: 60px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    font-weight: bold;
    border: 2px solid var(--secondary);
}

.controls-hint {
    background: rgba(0, 0, 0, 0.8);
    padding: 15px;
    border-radius: 8px;
    font-size: 0.85rem;
    color: var(--gray);
}

.controls-hint .key {
    display: inline-block;
    padding: 4px 8px;
    background: var(--card-bg);
    border-radius: 4px;
    margin: 0 3px;
    font-weight: bold;
    color: var(--light);
    border: 1px solid var(--border);
}

.track-info {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 20px;
    border: 2px solid var(--border);
}

.track-info h3 {
    margin-bottom: 15px;
}

.lap-times {
    display: flex;
    gap: 20px;
}

.lap {
    background: var(--darker);
    padding: 10px 20px;
    border-radius: 6px;
    font-family: monospace;
}

/* Stats */
.stats-container h2 {
    margin-bottom: 30px;
}

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

.stat-card {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 25px;
    text-align: center;
    border: 2px solid var(--border);
    transition: all 0.3s ease;
}

.stat-card:hover {
    transform: translateY(-5px);
    border-color: var(--primary);
}

.stat-icon {
    font-size: 2.5rem;
    margin-bottom: 10px;
}

.stat-number {
    font-size: 2rem;
    font-weight: bold;
    color: var(--primary);
    margin-bottom: 5px;
}

.stat-label {
    color: var(--gray);
    font-size: 0.9rem;
}

.charts-section {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 25px;
    border: 2px solid var(--border);
}

.charts-section h3 {
    margin-bottom: 20px;
}

.chart-container {
    height: 200px;
    display: flex;
    align-items: flex-end;
    gap: 20px;
    padding: 20px;
    background: var(--darker);
    border-radius: 8px;
}

/* Car SVG Styles */
.car-svg {
    width: 100%;
    height: 100%;
}

.car-body {
    transition: all 0.3s ease;
}

/* Responsive */
@media (max-width: 900px) {
    .builder-container {
        grid-template-columns: 1fr;
    }
    
    .header h1 {
        font-size: 1.8rem;
    }
    
    .nav-tabs {
        gap: 5px;
    }
    
    .nav-btn {
        padding: 10px 15px;
        font-size: 0.9rem;
    }
}

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--gray);
}

.empty-state h3 {
    margin-bottom: 15px;
    color: var(--light);
}

.empty-state p {
    margin-bottom: 25px;
}