:root {
    --primary-color: #ff6b6b;
    --primary-dark: #c0392b;
    --text-light: #ffffff;
    --bg-overlay: rgba(0, 0, 0, 0.6);
    --glass-bg: rgba(255, 255, 255, 0.1);
    --glass-border: rgba(255, 255, 255, 0.2);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Cairo', sans-serif;
    user-select: none;
}

body {
    background-color: #0f172a; /* Flat deep slate for outer desktop */
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    width: 100vw;
    color: #f8fafc;
    overflow: hidden;
    /* Removed touch-action: none from body so modal panels can scroll freely */
}

#app-container {
    background-color: #1e293b; /* Fallback dark */
    position: relative;
    width: 100%;
    height: 100%;
    max-width: 500px; /* Slightly wider modern width */
    /* Removed max-height limit to stretch fully on tall mobile screens */
    box-shadow: 0 10px 40px rgba(0,0,0,0.5); /* Deep material ambient shadow */
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* Screens */
.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: none;
    flex-direction: column;
    justify-content: flex-start; /* Start from top instead of center */
    align-items: center;
    z-index: 10;
    overflow-y: auto; /* Enable native vertical scrolling */
    overflow-x: hidden;
    padding: 2rem 1.5rem;
    padding-bottom: 5rem; /* Breathing room */
}

.screen.active {
    display: flex;
}

#registration-screen, #game-over-screen {
    background: rgba(15, 23, 42, 0.98); /* Solid dark material surface */
}

/* Material Card Panel (Replacing Glassmorphism) */
.glass-panel {
    background: #1e293b;
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 16px;
    padding: 2.5rem 2rem;
    width: 100%;
    max-width: 450px;
    text-align: center;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    animation: slideUpFade 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);
    color: #f8fafc; /* Bright text */
    margin-top: 10vh; /* Push downwards slightly */
}

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

.glass-panel h1 {
    font-size: 2rem;
    color: var(--primary-color);
    margin-bottom: 0.5rem;
    text-shadow: none; /* Flat Solid */
    font-weight: 800;
}

.glass-panel p {
    font-size: 1rem;
    margin-bottom: 2rem;
    color: #94a3b8;
}

/* Forms */
.input-group {
    margin-bottom: 1.5rem;
    text-align: start; /* Automatic LTR/RTL support */
}

.input-group label {
    display: block;
    margin-bottom: 0.6rem;
    font-weight: 700;
    color: #cbd5e1;
    font-size: 0.9rem;
}

.input-group input {
    width: 100%;
    padding: 14px 16px;
    border-radius: 10px;
    border: 2px solid transparent;
    background: #334155;
    color: #f8fafc;
    font-size: 1.05rem;
    font-weight: 600;
    outline: none;
    transition: all 0.2s;
}

.input-group input:focus {
    background: #1e293b;
    border-color: var(--primary-color);
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

/* Material Buttons */
.btn-primary {
    width: 100%;
    padding: 16px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 1.15rem;
    font-weight: 800;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 4px 14px rgba(0,0,0,0.3); /* Clean elevation */
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.btn-primary:active {
    transform: scale(0.97) translateY(2px);
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.btn-primary:hover {
    box-shadow: 0 6px 20px rgba(0,0,0,0.4);
    filter: brightness(1.1); /* Clean hover */
    transform: translateY(-2px);
}

.btn-secondary {
    width: 100%;
    padding: 12px;
    border: 2px solid #475569;
    border-radius: 10px;
    background: transparent;
    color: #e2e8f0;
    font-size: 1.05rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-secondary:hover {
    background: #334155;
    border-color: #64748b;
    color: #ffffff;
}

.lang-toggle-btn {
    position: fixed;
    top: 20px;
    left: 20px;
    z-index: 999;
    background: rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(15px);
    border: 1px solid rgba(255, 255, 255, 0.4);
    color: #fff;
    padding: 10px 18px;
    border-radius: 30px;
    cursor: pointer;
    font-weight: bold;
    font-family: inherit;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    text-shadow: 0 2px 4px rgba(0,0,0,0.5);
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}
.lang-toggle-btn:hover {
    background: rgba(255, 255, 255, 0.35);
    transform: translateY(-3px) scale(1.05);
    box-shadow: 0 12px 45px rgba(0, 0, 0, 0.4);
}
.lang-toggle-btn:active {
    transform: translateY(1px) scale(0.95);
}

/* End Modals */

/* How to play */
.how-to-play {
    margin-top: 20px;
    background: #0f172a;
    padding: 15px;
    border-radius: 12px;
    text-align: start;
    border: 1px dashed #334155;
}
.how-to-play h3 {
    margin-top: 0;
    font-size: 1rem;
    color: var(--primary-color);
    text-align: center;
    font-weight: 800;
}
.how-to-play ul {
    list-style: none;
    padding: 0;
    margin: 0;
    font-size: 0.85rem;
    color: #cbd5e1;
}
.how-to-play li {
    margin-bottom: 5px;
    display: flex;
    align-items: center;
}
.how-to-play .icon {
    font-size: 1.2rem;
    margin-left: 10px;
}

/* Floating HUD Pill Overhaul */
#top-bar {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    width: calc(100% - 40px);
    max-width: 440px;
    padding: 10px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(30, 41, 59, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    border-radius: 40px;
    z-index: 20;
}

.hud-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    flex: 1;
}
.hud-item i {
    font-size: 1.1rem;
    margin-bottom: 2px;
}

#hearts-display {
    font-size: 1.1rem;
    letter-spacing: 1px;
    filter: drop-shadow(0 0 5px rgba(239, 68, 68, 0.5));
}
#score-display {
    font-size: 1.8rem;
    font-weight: 800;
    color: #f8fafc;
    line-height: 1;
    text-shadow: 0 0 10px rgba(245, 158, 11, 0.5);
}
#time-left {
    font-size: 1.4rem;
    font-weight: 800;
    color: #f8fafc;
    line-height: 1;
}

.combo-text {
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    color: #f59e0b;
    font-size: 0.9rem;
    white-space: nowrap;
    animation: pulseCombo 0.5s infinite alternate;
    display: none;
    background: rgba(0,0,0,0.6);
    padding: 3px 10px;
    border-radius: 12px;
    margin-top: 5px;
}
@keyframes pulseCombo {
    from { transform: translateX(-50%) scale(1); text-shadow: 0 0 5px #f59e0b; }
    to { transform: translateX(-50%) scale(1.1); text-shadow: 0 0 15px #f59e0b; }
}

.timer-bar-wrapper {
    width: 100%;
    height: 8px;
    background: rgba(255,255,255,0.2);
    border-radius: 4px;
    overflow: hidden;
    box-shadow: inset 0 0 5px rgba(0,0,0,0.5);
}

#timer-bar {
    height: 100%;
    width: 100%;
    background: linear-gradient(90deg, #f1c40f, #e74c3c);
    box-shadow: 0 0 10px #e74c3c;
    transition: width 1s linear, background 0.5s;
}

/* Ambient Background Bubbles */
.bubbles {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    z-index: 1;
    pointer-events: none;
    overflow: hidden;
}
.bubble {
    position: absolute;
    bottom: -50px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    box-shadow: inset 0 0 10px rgba(255,255,255,0.3);
    animation: rise infinite ease-in;
}

.bubble:nth-child(1) { width: 40px; height: 40px; left: 10%; animation-duration: 8s; }
.bubble:nth-child(2) { width: 20px; height: 20px; left: 20%; animation-duration: 5s; animation-delay: 1s; }
.bubble:nth-child(3) { width: 50px; height: 50px; left: 35%; animation-duration: 7s; animation-delay: 2s; }
.bubble:nth-child(4) { width: 30px; height: 30px; left: 50%; animation-duration: 11s; animation-delay: 0s; }
.bubble:nth-child(5) { width: 20px; height: 20px; left: 65%; animation-duration: 6s; animation-delay: 3s; }
.bubble:nth-child(6) { width: 45px; height: 45px; left: 80%; animation-duration: 9s; animation-delay: 1s; }
.bubble:nth-child(7) { width: 15px; height: 15px; left: 90%; animation-duration: 4s; animation-delay: 2s; }
.bubble:nth-child(8) { width: 25px; height: 25px; left: 25%; animation-duration: 10s; animation-delay: 4s; }
.bubble:nth-child(9) { width: 35px; height: 35px; left: 70%; animation-duration: 7s; animation-delay: 0.5s; }

@keyframes rise {
    0% { transform: translateY(0) scale(1); opacity: 0; }
    10% { opacity: 1; }
    90% { opacity: 1; transform: translateY(-800px) scale(1.1); }
    100% { transform: translateY(-1000px) scale(1); opacity: 0; }
}

/* Screen Shake Effect */
.shake {
    animation: shakeAnim 0.3s cubic-bezier(.36,.07,.19,.97) both;
}

@keyframes shakeAnim {
    10%, 90% { transform: translate3d(-2px, 0, 0); }
    20%, 80% { transform: translate3d(4px, 0, 0); }
    30%, 50%, 70% { transform: translate3d(-6px, 0, 0); }
    40%, 60% { transform: translate3d(6px, 0, 0); }
}

/* Canvas */
#game-canvas {
    display: block;
    width: 100%;
    height: 100%;
    flex: 1;
    touch-action: none; /* Re-applying canvas touch lock to restrict game surface */
}

/* Game Over Screen */
.final-score-box {
    margin: 1.5rem 0;
    padding: 1.5rem;
    background: #0f172a;
    border-radius: 15px;
    border: 1px solid #334155;
}

.final-score-box p {
    margin-bottom: 0.5rem;
    font-size: 1.2rem;
    color: #94a3b8;
    font-weight: 700;
}

#final-score {
    font-size: 3.5rem;
    font-weight: 800;
    color: var(--primary-color);
    text-shadow: 0 0 20px rgba(0,0,0,0.5);
    line-height: 1;
}

.leaderboard-section {
    margin-bottom: 1.5rem;
    text-align: start;
}

.leaderboard-section h3 {
    text-align: center;
    color: #e2e8f0;
    margin-bottom: 1rem;
    font-weight: 800;
}

#leaderboard-list {
    list-style: none;
    padding: 0;
}

#leaderboard-list li {
    background: #1e293b;
    color: #f8fafc;
    padding: 12px 15px;
    margin-bottom: 8px;
    border-radius: 10px;
    display: flex;
    justify-content: space-between;
    font-weight: bold;
    border: 1px solid #334155;
    box-shadow: 0 4px 10px rgba(0,0,0,0.2);
}
