:root {
    --bg-color: #0f172a;
    --card-bg: #1e293b;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --success: #10b981;
    --danger: #ef4444;
}

* { box-sizing: border-box; margin: 0; padding: 0; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; touch-action: manipulation; }

.new-game-wrapper {
    background-color: var(--bg-color); color: var(--text-main);
    display: flex; justify-content: center; align-items: center;
    min-height: 100vh; overflow: hidden;
}

#game-container {
    width: 100%; max-width: 500px; background-color: var(--card-bg);
    border-radius: 16px; padding: 16px; box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.5);
    position: relative;
    min-height: 600px;
    display: flex; flex-direction: column;
}

.screen { display: none; flex-direction: column; align-items: center; text-align: center; animation: fadeIn 0.3s; flex: 1; justify-content: center; }
.screen.active { display: flex; }

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

.game-title { font-size: 2.2rem; font-weight: 800; margin-bottom: 16px; color: #93c5fd; }
.instructions { color: var(--text-muted); margin-bottom: 32px; line-height: 1.6; padding: 0 20px; }
.final-score { font-size: 1.5rem; font-weight: 700; color: #93c5fd; margin-bottom: 24px; }

.btn {
    border: none; padding: 12px 24px; border-radius: 8px; font-size: 1rem; font-weight: 700;
    color: white; cursor: pointer; transition: all 0.2s; width: 100%; max-width: 250px;
}
.btn:active { transform: scale(0.95); }
.btn.primary { background-color: var(--primary); }
.btn.primary:hover { background-color: var(--primary-hover); }

.header { display: flex; justify-content: space-between; width: 100%; margin-bottom: 16px; padding-bottom: 12px; border-bottom: 1px solid #334155; font-weight: 700; font-size: 1.1rem; color: #93c5fd; }

.game-area { width: 100%; display: flex; flex-direction: column; align-items: center; flex: 1; justify-content: center; }

.intersection {
    width: 300px; height: 300px;
    background: #475569;
    border-radius: 8px;
    position: relative;
    overflow: hidden;
}

.road {
    position: absolute;
    background: #1e293b;
}
.road.vertical {
    width: 60px; height: 100%;
    left: 120px; top: 0;
    border-left: 2px dashed #64748b;
    border-right: 2px dashed #64748b;
}
.road.horizontal {
    width: 100%; height: 60px;
    left: 0; top: 120px;
    border-top: 2px dashed #64748b;
    border-bottom: 2px dashed #64748b;
}

/* 
Center box: 
x: 120 to 180
y: 120 to 180
*/

.light {
    position: absolute;
    width: 24px; height: 24px;
    border-radius: 50%;
    cursor: pointer;
    z-index: 20;
    border: 3px solid #0f172a;
    transition: background 0.1s;
    box-shadow: 0 0 10px rgba(0,0,0,0.5);
}
.light.red { background: var(--danger); box-shadow: 0 0 10px var(--danger); }
.light.green { background: var(--success); box-shadow: 0 0 10px var(--success); }

/* Positioning lights at entry points of intersection */
#light-n { top: 90px; left: 125px; } /* Controls Northbound traffic (coming from bottom, going North... wait, let's simplify) */
/* Let's define dir as "origin". N means starting at North (top), going South */
#light-n { top: 90px; left: 125px; } /* Traffic from North, entering intersection at y=120 */
#light-s { top: 185px; left: 155px; } /* Traffic from South */
#light-w { top: 155px; left: 90px; } /* Traffic from West */
#light-e { top: 125px; left: 185px; } /* Traffic from East */

.car {
    position: absolute;
    width: 24px; height: 30px;
    display: flex; justify-content: center; align-items: center;
    font-size: 20px;
    z-index: 10;
    transform-origin: center;
}
.car.crashed {
    filter: drop-shadow(0 0 10px red);
    animation: shake 0.3s infinite;
}

@keyframes shake {
    0% { transform: translate(1px, 1px) rotate(0deg); }
    50% { transform: translate(-1px, -2px) rotate(-5deg); }
    100% { transform: translate(1px, -1px) rotate(5deg); }
}
