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

:root {
    --bg-dark: #1a1a2e;
    --bg-medium: #16213e;
    --bg-light: #0f3460;
    --accent: #e94560;
    --accent-hover: #ff6b6b;
    --text: #eee;
    --text-muted: #888;
    --success: #44ff44;
    --warning: #ffaa00;
    --danger: #ff4444;
}

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--bg-dark);
    color: var(--text);
}

body.game-active {
    position: fixed;
    width: 100%;
    height: 100%;
}

/* Screens */
.screen {
    display: none;
    height: 100%;
    overflow-y: auto;
}

.screen.active {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.container {
    width: 100%;
    max-width: 600px;
    padding: 20px;
}

/* Typography */
h1 {
    font-size: 3rem;
    text-align: center;
    color: var(--accent);
    margin-bottom: 10px;
    text-shadow: 0 0 20px rgba(233, 69, 96, 0.5);
}

h2 {
    font-size: 1.8rem;
    margin-bottom: 20px;
    color: var(--text);
}

h3 {
    font-size: 1.2rem;
    margin-bottom: 10px;
    color: var(--text-muted);
}

h4 {
    font-size: 1rem;
    margin-bottom: 8px;
}

.subtitle {
    text-align: center;
    color: var(--text-muted);
    margin-bottom: 30px;
}

/* Forms */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    color: var(--text-muted);
}

input[type="text"],
input[type="password"] {
    width: 100%;
    padding: 12px 15px;
    border: 2px solid var(--bg-light);
    border-radius: 8px;
    background: var(--bg-medium);
    color: var(--text);
    font-size: 1rem;
    transition: border-color 0.2s;
}

input:focus {
    outline: none;
    border-color: var(--accent);
}

.form-row {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}

.form-row input {
    flex: 1;
}

/* Buttons */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 600;
}

.btn.primary {
    background: var(--accent);
    color: white;
}

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

.btn.secondary {
    background: var(--bg-light);
    color: var(--text);
}

.btn.secondary:hover {
    background: #1a4a7a;
}

.btn.danger {
    background: var(--danger);
    color: white;
}

.btn.danger:hover {
    background: #ff6666;
}

.btn.large {
    padding: 15px 40px;
    font-size: 1.2rem;
}

.btn.small {
    padding: 6px 12px;
    font-size: 0.85rem;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.button-row {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-top: 20px;
}

/* Error messages */
.error {
    color: var(--danger);
    text-align: center;
    margin-top: 10px;
    min-height: 20px;
}

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

.player-name {
    color: var(--accent);
    font-weight: 600;
}

/* Lobby List */
.lobby-list {
    background: var(--bg-medium);
    border-radius: 8px;
    padding: 10px;
    max-height: 300px;
    overflow-y: auto;
    margin-bottom: 20px;
}

.lobby-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px;
    background: var(--bg-light);
    border-radius: 6px;
    margin-bottom: 8px;
}

.lobby-item:last-child {
    margin-bottom: 0;
}

.lobby-item h4 {
    margin: 0 0 4px 0;
    color: var(--text);
}

.lobby-item span {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.lobby-item span.in-game {
    color: var(--warning);
}

.no-lobbies {
    text-align: center;
    color: var(--text-muted);
    padding: 20px;
}

/* Lobby Room */
.lobby-content {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 20px;
}

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

.players-section,
.chat-section {
    background: var(--bg-medium);
    border-radius: 8px;
    padding: 15px;
}

.players-list {
    min-height: 100px;
}

.player-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    background: var(--bg-light);
    border-radius: 6px;
    margin-bottom: 6px;
}

.player-color {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 2px solid rgba(255,255,255,0.3);
}

.bot-controls {
    display: flex;
    gap: 8px;
    margin-top: 10px;
}

/* Chat */
.chat-messages {
    height: 150px;
    overflow-y: auto;
    background: var(--bg-dark);
    border-radius: 6px;
    padding: 10px;
    margin-bottom: 10px;
}

.chat-message {
    margin-bottom: 6px;
    word-wrap: break-word;
}

.chat-message .name {
    color: var(--accent);
    font-weight: 600;
}

.chat-message.system {
    color: var(--text-muted);
    font-style: italic;
}

.chat-input-row {
    display: flex;
    gap: 8px;
}

.chat-input-row input {
    flex: 1;
}

/* Game Screen */
#game-screen.active {
    justify-content: flex-start;
    padding: 0;
}

.game-layout {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
}

/* Race HUD */
#race-hud {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 20px;
    background: rgba(0, 0, 0, 0.8);
    border-bottom: 2px solid var(--accent);
}

.hud-left,
.hud-right {
    display: flex;
    gap: 20px;
}

.hud-item {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.hud-item .label {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
}

.hud-item .value {
    font-size: 1.2rem;
    font-weight: bold;
    color: var(--text);
}

.tire-bar {
    width: 60px;
    height: 12px;
    background: #333;
    border-radius: 6px;
    overflow: hidden;
}

.tire-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--danger) 0%, var(--warning) 50%, var(--success) 100%);
    width: 100%;
    transition: width 0.3s;
}

.countdown {
    font-size: 4rem;
    font-weight: bold;
    color: var(--accent);
    text-shadow: 0 0 30px rgba(233, 69, 96, 0.8);
    animation: pulse 0.5s ease-in-out;
}

@keyframes pulse {
    0% { transform: scale(1.5); opacity: 0; }
    50% { transform: scale(1); opacity: 1; }
    100% { transform: scale(0.9); opacity: 0.8; }
}

/* Game Container */
.game-container {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    background: #111;
    overflow: hidden;
}

#game-canvas {
    max-width: 100%;
    max-height: 100%;
}

/* Game Sidebar */
.game-sidebar {
    position: fixed;
    right: 10px;
    top: 80px;
    width: 150px;
    background: rgba(0, 0, 0, 0.85);
    border-radius: 8px;
    padding: 10px;
    z-index: 100;
}

.game-sidebar h4 {
    color: var(--accent);
    margin-bottom: 10px;
    text-align: center;
}

#standings-list {
    margin-bottom: 10px;
}

.standing-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px;
    margin-bottom: 4px;
    background: var(--bg-medium);
    border-radius: 4px;
    font-size: 0.85rem;
}

.standing-item.current-player {
    border: 1px solid var(--accent);
}

.standing-item.finished {
    opacity: 0.7;
}

.standing-position {
    font-weight: bold;
    width: 24px;
    text-align: center;
}

.standing-color {
    width: 12px;
    height: 12px;
    border-radius: 50%;
}

.standing-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.standing-lap {
    color: var(--text-muted);
    font-size: 0.75rem;
}

/* Mobile Stats */
.mobile-stats {
    display: none;
    position: fixed;
    bottom: 120px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.8);
    padding: 8px 16px;
    border-radius: 20px;
    z-index: 100;
}

@media (max-width: 800px) {
    .game-sidebar {
        display: none;
    }

    .mobile-stats:not(.hidden) {
        display: flex;
        gap: 15px;
    }
}

/* Touch Controls */
.touch-controls {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 120px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 20px;
    background: rgba(0, 0, 0, 0.7);
    z-index: 200;
}

.touch-controls.hidden {
    display: none;
}

.touch-left,
.touch-right {
    flex: 1;
    display: flex;
    justify-content: center;
}

.touch-pedals {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.touch-btn {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    border: 3px solid rgba(255, 255, 255, 0.5);
    background: rgba(255, 255, 255, 0.1);
    color: white;
    font-size: 1.5rem;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}

.touch-btn.active {
    background: rgba(255, 255, 255, 0.3);
    border-color: var(--accent);
}

.steer-btn {
    width: 70px;
    height: 70px;
}

.accel-btn {
    background: rgba(68, 255, 68, 0.2);
    border-color: var(--success);
    width: 70px;
    height: 45px;
    border-radius: 8px;
    font-size: 0.9rem;
}

.accel-btn.active {
    background: rgba(68, 255, 68, 0.5);
}

.brake-btn {
    background: rgba(255, 68, 68, 0.2);
    border-color: var(--danger);
    width: 70px;
    height: 45px;
    border-radius: 8px;
    font-size: 0.9rem;
}

.brake-btn.active {
    background: rgba(255, 68, 68, 0.5);
}

/* Modals */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 500;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: var(--bg-medium);
    padding: 30px;
    border-radius: 12px;
    max-width: 400px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
}

.modal-content h3 {
    color: var(--accent);
    margin-bottom: 20px;
    text-align: center;
}

/* Settings */
.settings-section {
    margin-bottom: 25px;
}

.settings-section h4 {
    color: var(--text);
    margin-bottom: 15px;
    border-bottom: 1px solid var(--bg-light);
    padding-bottom: 5px;
}

.keybind-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.keybind-btn {
    padding: 8px 16px;
    min-width: 80px;
    background: var(--bg-light);
    border: 2px solid transparent;
    border-radius: 6px;
    color: var(--text);
    cursor: pointer;
    font-family: monospace;
    font-size: 0.9rem;
}

.keybind-btn:hover {
    border-color: var(--accent);
}

.keybind-btn.listening {
    border-color: var(--success);
    animation: blink 0.5s infinite;
}

@keyframes blink {
    50% { opacity: 0.5; }
}

.toggle-label {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
}

.toggle-label input[type="checkbox"] {
    width: 20px;
    height: 20px;
    accent-color: var(--accent);
}

/* Overlay */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 400;
}

.overlay.hidden {
    display: none;
}

.overlay-content {
    text-align: center;
    padding: 40px;
}

.overlay-content h2 {
    font-size: 2.5rem;
    color: var(--accent);
    margin-bottom: 30px;
}

.results-list {
    margin-bottom: 20px;
}

.result-item {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
    padding: 12px 20px;
    margin-bottom: 8px;
    background: var(--bg-medium);
    border-radius: 8px;
    font-size: 1.1rem;
}

.result-item.first {
    background: linear-gradient(135deg, #ffd700 0%, #ffb700 100%);
    color: #000;
    font-weight: bold;
}

.result-item.second {
    background: linear-gradient(135deg, #c0c0c0 0%, #a0a0a0 100%);
    color: #000;
}

.result-item.third {
    background: linear-gradient(135deg, #cd7f32 0%, #a06020 100%);
    color: #fff;
}

.result-position {
    font-weight: bold;
    width: 40px;
}

.result-name {
    flex: 1;
    text-align: left;
}

.result-time {
    font-family: monospace;
}

.return-hint {
    color: var(--text-muted);
    margin-top: 20px;
}

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

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

::-webkit-scrollbar-thumb {
    background: var(--bg-light);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--accent);
}

/* Responsive */
@media (max-width: 600px) {
    h1 {
        font-size: 2rem;
    }

    .container {
        padding: 15px;
    }

    #race-hud {
        padding: 8px 10px;
    }

    .hud-item .value {
        font-size: 1rem;
    }

    .countdown {
        font-size: 3rem;
    }
}
