/* CSS Variables */
:root {
    --bg-color: #cbd5e1;
    --board-bg: #f8fafc;
    
    --bus-shadow: rgba(0, 0, 0, 0.2);
    --grid-line: rgba(0, 0, 0, 0.05);
}

body {
    margin: 0;
    padding: 0;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #e0e7ff 0%, #c7d2fe 100%);
    color: #1e293b;
    display: flex;
    justify-content: center;
    height: 100vh;
    overflow: hidden;
    touch-action: none;
}

#app-container {
    width: 100%;
    max-width: 500px;
    height: 100%;
    position: relative;
    background-color: #e2e8f0;
    box-shadow: 0 0 20px rgba(0,0,0,0.1);
    overflow: hidden;
}

.screen {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    position: absolute;
    top: 0; left: 0;
    transition: opacity 0.3s ease;
}

.screen.hidden {
    opacity: 0;
    pointer-events: none;
    z-index: -1;
}

#game-container {
    /* Override absolute for standard flow if needed, but it's flex */
    background-color: #e2e8f0;
}

#game-header {
    text-align: center;
    padding: 15px 0 5px 0;
    background-color: #e2e8f0;
    z-index: 10;
}

#game-header h1 {
    margin: 0;
    font-size: 1.5rem;
    color: #0f172a;
}

#game-header p {
    margin: 5px 0 0 0;
    font-size: 0.9rem;
    color: #64748b;
}

#board-container {
    flex: 1 1 auto;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 10px;
    position: relative;
    /* Allow board to take remaining space smoothly */
    min-height: 0; 
}

#passenger-queue {
    display: flex;
    flex-wrap: wrap;
    gap: 10px 6px; /* 10px vertical gap, 6px horizontal */
    justify-content: center;
    align-content: flex-start; /* Pack rows from the top */
    padding: 10px 15px 0 15px; /* No bottom padding */
    height: 90px; /* 10px pad + 35px row1 + 10px gap + 35px row2 = exactly 90px */
    overflow: hidden; /* 3rd row starts at 100px, so it's perfectly hidden */
}

/* Animated Passenger Characters */
.passenger {
    --bus-color: #facc15;
    width: 20px;
    height: 35px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    position: relative;
    z-index: 50;
    animation: idleBounce 2s infinite ease-in-out;
}

.p-head {
    width: 16px;
    height: 16px;
    background: #fcd34d; 
    border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    z-index: 2;
}

.p-torso {
    width: 20px;
    height: 16px;
    background: var(--bus-color);
    border-radius: 8px 8px 4px 4px;
    margin-top: -3px;
    z-index: 1;
    box-shadow: inset 0 -2px 0 rgba(0,0,0,0.15);
}

.p-legs {
    display: flex;
    gap: 4px;
    margin-top: -2px;
}

.p-leg {
    width: 6px;
    height: 8px;
    background: #334155;
    border-radius: 3px;
}

/* Passenger Animations */
@keyframes idleBounce {
    0%, 100% { transform: scaleY(1) translateY(0); }
    50% { transform: scaleY(0.95) translateY(2px); }
}

.passenger.walking {
    animation: walkBounce 0.4s infinite alternate;
}

@keyframes walkBounce {
    0% { transform: translateY(0) rotate(-10deg); }
    100% { transform: translateY(-8px) rotate(10deg); }
}

/* Match passenger colors */
.passenger.red { --bus-color: #ef4444; }
.passenger.blue { --bus-color: #3b82f6; }
.passenger.green { --bus-color: #22c55e; }
.passenger.yellow { --bus-color: #facc15; }
.passenger.purple { --bus-color: #a855f7; }
.passenger.orange { --bus-color: #f97316; }

#bus-stops {
    display: flex;
    justify-content: center;
    gap: 8px;
    padding: 10px;
    background: rgba(255,255,255,0.2);
    border-radius: 8px;
    margin: 5px 15px;
}

.bus-slot {
    width: 60px;
    height: 100px;
    border: 2px dashed #94a3b8;
    border-radius: 8px;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.3s ease;
}

.placeholder-p {
    font-size: 2.5rem;
    font-weight: 900;
    color: rgba(148, 163, 184, 0.4);
    pointer-events: none;
    user-select: none;
}

.bus-slot.locked {
    background: rgba(148, 163, 184, 0.3);
    border: 2px solid #64748b;
    cursor: pointer;
    text-align: center;
    font-size: 1.2rem;
    color: #475569;
}
.bus-slot.locked:hover {
    background: rgba(148, 163, 184, 0.5);
}

#coin-display {
    font-weight: bold;
    font-size: 1.1rem;
    color: #ca8a04;
    background: #fef08a;
    padding: 5px 10px;
    border-radius: 20px;
    margin-right: 10px;
}

/* Hint Glow */
.bus.hint-glow {
    animation: hintPulse 1s infinite alternate;
    box-shadow: 0 0 15px 5px #facc15;
    z-index: 100;
}

@keyframes hintPulse {
    0% { filter: brightness(1); transform: scale(1); }
    100% { filter: brightness(1.3); transform: scale(1.05); }
}

/* Toast Notifications */
.toast {
    position: absolute;
    top: 20%;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(15, 23, 42, 0.9);
    color: white;
    padding: 10px 20px;
    border-radius: 8px;
    font-weight: bold;
    z-index: 2000;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

.toast.hidden {
    opacity: 0;
}

/* Passenger boarding transition state */
.passenger.boarding {
    transform: scale(0.5);
    opacity: 0;
}

#game-board {
    width: 100%;
    max-height: 100%;
    aspect-ratio: 10 / 15;
    background-color: #64748b; /* Asphalt color */
    border-radius: 12px;
    position: relative;
    box-shadow: inset 0 4px 15px rgba(0,0,0,0.2);
    border: 4px solid #475569;
    background-image: 
        linear-gradient(to right, rgba(255, 255, 255, 0.25) 2px, transparent 2px),
        linear-gradient(to bottom, rgba(255, 255, 255, 0.25) 2px, transparent 2px);
    background-size: 10% 6.6666%;
    background-position: -1px -1px;
}

#top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 10px 10px 10px;
}

#level-display {
    font-weight: bold;
    font-size: 1.1rem;
    color: #334155;
}

.icon-btn {
    padding: 8px;
    border: none;
    border-radius: 50%;
    background: #cbd5e1;
    font-size: 1.2rem;
    cursor: pointer;
    margin-right: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    transition: transform 0.1s;
}

.icon-btn:active {
    transform: scale(0.9);
}

.btn {
    padding: 8px 16px;
    border: none;
    border-radius: 20px;
    font-weight: bold;
    cursor: pointer;
    background: #cbd5e1;
    color: #334155;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    transition: transform 0.1s, background 0.2s;
}

.btn:active {
    transform: scale(0.95);
}

.btn.primary {
    background: #3b82f6;
    color: white;
    font-size: 1.1rem;
    padding: 12px 24px;
    margin-top: 15px;
}

/* Highlight Restart Button when Stuck */
.btn.pulse {
    animation: highlightPulse 1.5s infinite;
    background: #ef4444;
    color: white;
}

@keyframes highlightPulse {
    0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7); }
    50% { transform: scale(1.05); box-shadow: 0 0 0 10px rgba(239, 68, 68, 0); }
    100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

/* Modals */
#modal-overlay {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(255, 255, 255, 0.4);
    backdrop-filter: blur(8px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    transition: opacity 0.3s ease;
}

#modal-overlay.hidden {
    display: none;
    opacity: 0;
}

.modal {
    background: rgba(255, 255, 255, 0.9);
    padding: 30px;
    border-radius: 20px;
    box-shadow: 0 20px 40px rgba(0,0,0,0.2), inset 0 2px 0 rgba(255,255,255,0.8);
    text-align: center;
    max-width: 80%;
    transform: scale(1);
    animation: bounceIn 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes bounceIn {
    0% { transform: scale(0.5); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

.modal.hidden {
    display: none;
}

.modal h2 {
    margin-bottom: 15px;
    color: #0f172a;
    font-size: 1.8rem;
}

#confetti-canvas {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    pointer-events: none;
    z-index: 900;
}

#game-footer {
    flex: 0 0 60px;
}

/* Real Bus Design */
.bus {
    position: absolute;
    --bus-color: #facc15;
    --bus-color-dark: #ca8a04;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: transform 0.2s ease, opacity 0.3s ease;
    cursor: pointer;
    z-index: 10;
}

.bus-body {
    position: absolute;
    width: 100%;
    height: 100%;
    background: linear-gradient(to bottom, var(--bus-color) 20%, var(--bus-color-dark) 100%);
    border-radius: 8px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.3), inset 0 2px 5px rgba(255,255,255,0.4), inset 0 -4px 0 var(--bus-color-dark);
    display: flex;
    flex-direction: column;
    align-items: center;
    overflow: hidden;
}

/* Menu Styles */
#main-menu {
    justify-content: center;
    align-items: center;
    background: linear-gradient(135deg, #e0e7ff 0%, #c7d2fe 100%);
    text-align: center;
}

#main-menu h1 {
    font-size: 3rem;
    color: #0f172a;
    margin-bottom: 5px;
}

.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-top: 30px;
}

.btn-diff {
    width: 200px;
}

#level-select {
    background-color: #f8fafc;
}

.header-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px;
    background: #e2e8f0;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.level-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    padding: 20px;
    justify-content: center;
    overflow-y: auto;
    align-content: flex-start;
    flex: 1; /* Fix for 0-height collapse */
}

.lvl-btn {
    width: 60px;
    height: 60px;
    border-radius: 12px;
    border: none;
    background: #3b82f6;
    color: white;
    font-size: 1.2rem;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    transition: transform 0.1s;
}
.lvl-btn:active { transform: scale(0.9); }
.lvl-btn.locked {
    background: #cbd5e1;
    color: #64748b;
    cursor: not-allowed;
    box-shadow: none;
}

.windshield {
    margin-top: 4px;
    width: 80%;
    height: 25%;
    max-height: 15px;
    background: #1e293b;
    border-radius: 4px 4px 2px 2px;
    box-shadow: inset 0 -2px 4px rgba(255,255,255,0.2);
}

.roof {
    margin-top: 5px;
    width: 70%;
    height: 40%;
    background: rgba(255,255,255,0.25);
    border-radius: 4px;
    border: 1px solid rgba(255,255,255,0.4);
}

.bus-wheels {
    position: absolute;
    width: 110%;
    height: 60%;
    display: flex;
    justify-content: space-between;
    z-index: -1;
}

.wheel-group {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    height: 100%;
}

.wheel {
    width: 4px;
    height: 30%;
    background: #0f172a;
    border-radius: 2px;
}

/* Arrow inside bus body */
.bus .arrow {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 0; 
    height: 0; 
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-bottom: 10px solid white;
    z-index: 5;
}

/* Entry Animation */
.bus.entry-anim {
    animation: popIn 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
    opacity: 0;
    transform: scale(0.1);
}

@keyframes popIn {
    to {
        opacity: 1;
    }
}

/* Bus Colors */
.bus.red { --bus-color: #ef4444; --bus-color-dark: #b91c1c; }
.bus.blue { --bus-color: #3b82f6; --bus-color-dark: #1d4ed8; }
.bus.green { --bus-color: #22c55e; --bus-color-dark: #15803d; }
.bus.yellow { --bus-color: #facc15; --bus-color-dark: #ca8a04; }
.bus.purple { --bus-color: #a855f7; --bus-color-dark: #7e22ce; }
.bus.orange { --bus-color: #f97316; --bus-color-dark: #c2410c; }

/* Types of buses */
/* Grid is 10 columns by 15 rows. Cells are perfect squares. */
.bus.small {
    width: calc(10% - 4px);
    aspect-ratio: 1 / 1; 
}

.bus.standard {
    width: calc(10% - 4px);
    aspect-ratio: 1 / 2; 
}

.bus.long {
    width: calc(10% - 4px);
    aspect-ratio: 1 / 3; 
}

/* Custom Animated Logo */
.logo-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 20px;
    animation: floatLogo 3s ease-in-out infinite;
}

.logo-bus {
    font-size: 5rem;
    margin-bottom: -15px;
    z-index: 2;
    text-shadow: 0 10px 20px rgba(0,0,0,0.3);
    animation: busDrive 4s ease-in-out infinite alternate;
}

.animated-logo {
    font-size: 3.5rem;
    font-weight: 900;
    margin: 0;
    letter-spacing: 2px;
    display: flex;
    gap: 10px;
    text-transform: uppercase;
}

.text-bus { color: #facc15; text-shadow: 0 4px 0 #ca8a04, 0 8px 15px rgba(0,0,0,0.2); }
.text-jam { color: #ef4444; text-shadow: 0 4px 0 #b91c1c, 0 8px 15px rgba(0,0,0,0.2); }

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

@keyframes busDrive {
    0% { transform: translateX(-10px) rotate(-5deg); }
    100% { transform: translateX(10px) rotate(5deg); }
}

@media (max-width: 400px) {
    .animated-logo { font-size: 2.8rem; }
    .logo-bus { font-size: 4rem; }
}

/* Button Hover Enhancements */
.btn, .icon-btn {
    transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), filter 0.2s ease, box-shadow 0.2s ease !important;
}

.btn:hover, .icon-btn:hover {
    transform: scale(1.05) translateY(-2px);
    filter: brightness(1.1);
}

.btn:active, .icon-btn:active {
    transform: scale(0.95);
    filter: brightness(0.9);
}
