/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --secondary-color: #8b5cf6;
    --danger-color: #ef4444;
    --success-color: #10b981;
    --warning-color: #f59e0b;
    
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --border-color: #475569;
    
    --shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.4);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
}

/* Container */
.container {
    max-width: 900px;
    margin: 0 auto;
    padding: 2rem 1rem;
}

.container-fluid {
    max-width: 1400px;
    margin: 0 auto;
    padding: 1rem;
}

/* Screen Management */
.screen {
    display: none;
    min-height: 100vh;
    animation: fadeIn 0.3s ease;
}

.screen.active {
    display: block;
}

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

/* Game Header */
.game-header {
    text-align: center;
    margin-bottom: 3rem;
}

.game-title {
    font-size: 3.5rem;
    font-weight: 800;
    background: linear-gradient(135deg, #3b82f6, #8b5cf6, #ec4899);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 0.5rem;
}

.game-subtitle {
    font-size: 1.25rem;
    color: var(--text-secondary);
}

/* Lobby Options */
.lobby-options {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 2rem;
    margin-bottom: 2rem;
}

.option-card {
    background: var(--bg-secondary);
    border: 2px solid var(--border-color);
    border-radius: 1rem;
    padding: 2rem;
    text-align: center;
    transition: all 0.3s ease;
}

.option-card:hover {
    transform: translateY(-4px);
    border-color: var(--primary-color);
    box-shadow: var(--shadow-lg);
}

.option-card h2 {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.option-card p {
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
}

/* Buttons */
.btn {
    padding: 0.875rem 2rem;
    font-size: 1rem;
    font-weight: 600;
    border: none;
    border-radius: 0.75rem;
    cursor: pointer;
    transition: all 0.3s ease;
    width: 100%;
    max-width: 300px;
}

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

.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

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

.btn-secondary:hover:not(:disabled) {
    background: #7c3aed;
    transform: translateY(-2px);
}

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

.btn-danger:hover:not(:disabled) {
    background: #dc2626;
}

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

/* Input Fields */
input[type="text"] {
    width: 100%;
    max-width: 400px;
    padding: 0.875rem 1rem;
    font-size: 1rem;
    background: var(--bg-tertiary);
    border: 2px solid var(--border-color);
    border-radius: 0.75rem;
    color: var(--text-primary);
    margin-bottom: 1rem;
    transition: all 0.3s ease;
}

input[type="text"]:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2);
}

.name-input-container {
    text-align: center;
    margin-top: 2rem;
}

.name-input-container label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--text-secondary);
}

/* Room Info */
.room-info {
    background: var(--bg-secondary);
    border: 2px solid var(--border-color);
    border-radius: 1rem;
    padding: 1.5rem;
    margin-top: 1rem;
}

.room-code {
    font-size: 2rem;
    font-weight: 800;
    color: var(--primary-color);
    letter-spacing: 0.2em;
    font-family: 'Courier New', monospace;
}

.share-text {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-top: 0.5rem;
}

/* Waiting Room */
.waiting-container {
    background: var(--bg-secondary);
    border: 2px solid var(--border-color);
    border-radius: 1rem;
    padding: 2rem;
}

.waiting-container h3 {
    text-align: center;
    margin-bottom: 1.5rem;
    color: var(--text-primary);
}

.players-list {
    display: grid;
    gap: 1rem;
    margin-bottom: 2rem;
    min-height: 200px;
}

.player-item {
    background: var(--bg-tertiary);
    border: 2px solid var(--border-color);
    border-radius: 0.75rem;
    padding: 1rem;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.player-color {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 3px solid white;
}

.player-info {
    flex: 1;
}

.player-name {
    font-weight: 600;
    font-size: 1.1rem;
}

.player-status {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.waiting-controls {
    display: flex;
    gap: 1rem;
    justify-content: center;
    flex-wrap: wrap;
}

/* Countdown */
.countdown-display {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 80vh;
}

.countdown-number {
    font-size: 12rem;
    font-weight: 800;
    background: linear-gradient(135deg, #3b82f6, #8b5cf6);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: countdownPulse 1s ease infinite;
}

.countdown-text {
    font-size: 2rem;
    color: var(--text-secondary);
    margin-top: 1rem;
}

@keyframes countdownPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

/* Race Header */
.race-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-secondary);
    border: 2px solid var(--border-color);
    border-radius: 1rem;
    padding: 1rem 1.5rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.race-stats {
    display: flex;
    gap: 2rem;
    flex-wrap: wrap;
}

.race-stats span {
    font-weight: 600;
    color: var(--text-secondary);
}

/* Race Track */
.race-track {
    background: var(--bg-secondary);
    border: 2px solid var(--border-color);
    border-radius: 1rem;
    padding: 2rem 1rem;
    margin-bottom: 1rem;
    min-height: 400px;
    position: relative;
}

.race-lane {
    position: relative;
    height: 80px;
    margin-bottom: 1rem;
    background: linear-gradient(90deg, 
        var(--bg-tertiary) 0%, 
        var(--bg-tertiary) 2%, 
        transparent 2%, 
        transparent 98%, 
        var(--bg-tertiary) 98%);
    border-radius: 0.5rem;
    border: 2px solid var(--border-color);
}

.race-lane:last-child {
    margin-bottom: 0;
}

.finish-line {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: repeating-linear-gradient(
        45deg,
        #fff,
        #fff 10px,
        #000 10px,
        #000 20px
    );
}

.racer {
    position: absolute;
    top: 50%;
    left: 0;
    transform: translateY(-50%);
    width: 60px;
    height: 40px;
    border-radius: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    transition: left 0.3s ease;
    box-shadow: var(--shadow);
}

.racer-name {
    position: absolute;
    top: -25px;
    left: 0;
    font-size: 0.85rem;
    font-weight: 600;
    white-space: nowrap;
    color: var(--text-primary);
}

.racer-progress {
    position: absolute;
    bottom: -20px;
    left: 0;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.racer.finished {
    animation: bounce 0.5s ease;
}

@keyframes bounce {
    0%, 100% { transform: translateY(-50%); }
    50% { transform: translateY(-60px); }
}

/* Typing Area */
.typing-area {
    background: var(--bg-secondary);
    border: 2px solid var(--border-color);
    border-radius: 1rem;
    padding: 2rem;
    text-align: center;
}

.word-display {
    margin-bottom: 2rem;
}

.current-word {
    font-size: 3rem;
    font-weight: 700;
    color: var(--primary-color);
    font-family: 'Courier New', monospace;
    letter-spacing: 0.1em;
}

.typing-input {
    max-width: 500px;
    font-size: 1.5rem;
    text-align: center;
    padding: 1rem 1.5rem;
}

.typing-feedback {
    margin-top: 1rem;
    min-height: 24px;
    font-size: 0.9rem;
}

.typing-feedback.correct {
    color: var(--success-color);
}

.typing-feedback.incorrect {
    color: var(--danger-color);
}

/* Results */
.results-container {
    background: var(--bg-secondary);
    border: 2px solid var(--border-color);
    border-radius: 1rem;
    padding: 2rem;
}

.results-list {
    margin-bottom: 2rem;
}

.result-item {
    background: var(--bg-tertiary);
    border: 2px solid var(--border-color);
    border-radius: 0.75rem;
    padding: 1.5rem;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.result-position {
    font-size: 2rem;
    font-weight: 800;
    width: 60px;
    text-align: center;
}

.result-position.first {
    color: #fbbf24;
}

.result-position.second {
    color: #d1d5db;
}

.result-position.third {
    color: #cd7f32;
}

.result-player-color {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    border: 3px solid white;
}

.result-details {
    flex: 1;
}

.result-name {
    font-size: 1.25rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
}

.result-stats {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.results-controls {
    display: flex;
    gap: 1rem;
    justify-content: center;
    flex-wrap: wrap;
}

/* Toast Notifications */
.toast {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    background: var(--bg-secondary);
    border: 2px solid var(--border-color);
    border-radius: 0.75rem;
    padding: 1rem 1.5rem;
    box-shadow: var(--shadow-lg);
    transform: translateX(400px);
    transition: transform 0.3s ease;
    z-index: 1000;
    max-width: 300px;
}

.toast.show {
    transform: translateX(0);
}

.toast.error {
    border-color: var(--danger-color);
    background: rgba(239, 68, 68, 0.1);
}

.toast.success {
    border-color: var(--success-color);
    background: rgba(16, 185, 129, 0.1);
}

/* Back Home Link */
.back-home {
    text-align: center;
    margin-top: 3rem;
}

.home-link {
    color: var(--text-secondary);
    text-decoration: none;
    transition: color 0.3s ease;
    font-weight: 500;
}

.home-link:hover {
    color: var(--primary-color);
}

/* Responsive */
@media (max-width: 768px) {
    .game-title {
        font-size: 2.5rem;
    }
    
    .countdown-number {
        font-size: 8rem;
    }
    
    .current-word {
        font-size: 2rem;
    }
    
    .race-track {
        padding: 1rem 0.5rem;
    }
    
    .race-lane {
        height: 60px;
    }
    
    .racer {
        width: 40px;
        height: 30px;
        font-size: 1rem;
    }
    
    .race-stats {
        gap: 1rem;
    }
}
