:root {
    --bg-dark: #02040a;
    --primary-neon: #a855f7;
    --secondary-neon: #4ecdc4;
    --accent-neon: #ff6b9d;
    --glass: rgba(255, 255, 255, 0.05);
    --glass-border: rgba(255, 255, 255, 0.1);
    --spark-gold: #ffd700;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    background: var(--bg-dark);
    color: white;
    font-family: 'Outfit', sans-serif;
    overflow: hidden;
    height: 100vh;
    width: 100vw;
    display: flex;
    justify-content: center;
    align-items: center;
    touch-action: none;
    /* Prevent browser gestures */
    user-select: none;
    -webkit-user-select: none;
}

/* Canvas Fullscreen */
#game-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 100;
    /* Behind UI */
    background: linear-gradient(rgba(0, 0, 0, 0.2), rgba(0, 0, 0, 0.4)), url('assets/background.png') center/cover no-repeat;
    touch-action: none;
    /* Critical for game handling */
}

#ui-layer {
    position: absolute;
    inset: 0;
    z-index: 200;
    pointer-events: none;
    /* Let clicks pass through to canvas */
}

/* Header */
.header {
    position: absolute;
    top: calc(env(safe-area-inset-top) + 50px);
    left: 0;
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0 20px;
    z-index: 300;
    opacity: 0;
    transition: opacity 0.5s;
}

.header.active {
    opacity: 1;
}


.score-container {
    background: var(--glass);
    border: 1px solid var(--glass-border);
    padding: 10px 20px;
    border-radius: 12px;
    backdrop-filter: blur(10px);
}

.score-label {
    font-size: 0.7rem;
    color: var(--secondary-neon);
    font-weight: 700;
}

.score-value {
    font-family: 'Orbitron', sans-serif;
    font-size: 1.5rem;
    font-weight: 900;
    color: white;
}



.lives-container {
    position: absolute;
    right: 20px;
    display: flex;
    gap: 5px;
}

.life-icon {
    font-size: 1.2rem;
    opacity: 0.8;
}

.life-icon.lost {
    opacity: 0.2;
    filter: grayscale(1);
}

/* Start Screen */
#start-screen {
    position: absolute;
    inset: 0;
    background: rgba(2, 4, 10, 0.95);
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    pointer-events: all;
    /* Capture UI clicks */
}

#start-screen.active {
    display: flex;
}

.game-logo {
    text-align: center;
    margin-bottom: 40px;
}

.game-logo h1 {
    font-family: 'Orbitron', sans-serif;
    font-size: 3rem;
    font-weight: 900;
    line-height: 1;
    background: linear-gradient(to right, #a855f7, #4ecdc4);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: 0 0 30px rgba(168, 85, 247, 0.4);
    letter-spacing: 5px;
    transform: skewX(-5deg);
}

.start-btn {
    background: linear-gradient(135deg, var(--primary-neon), #6d28d9);
    border: none;
    color: white;
    padding: 15px 40px;
    border-radius: 30px;
    font-size: 1.2rem;
    font-weight: 900;
    font-family: 'Orbitron', sans-serif;
    cursor: pointer;
    box-shadow: 0 0 20px rgba(168, 85, 247, 0.5);
    position: relative;
    overflow: hidden;
    transition: transform 0.2s;
}

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

.btn-shine {
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.5), transparent);
    animation: shine 3s infinite;
}

@keyframes shine {
    0% {
        left: -100%;
    }

    20% {
        left: 100%;
    }

    100% {
        left: 100%;
    }
}

.mode-selector {
    display: flex;
    gap: 15px;
    margin-bottom: 30px;
}

.mode-btn {
    background: var(--glass);
    border: 1px solid var(--glass-border);
    padding: 15px;
    border-radius: 12px;
    width: 140px;
    cursor: pointer;
    transition: all 0.3s;
    text-align: center;
}

.mode-btn.active {
    border-color: var(--secondary-neon);
    background: rgba(78, 205, 196, 0.1);
    box-shadow: 0 0 15px rgba(78, 205, 196, 0.2);
}

.mode-icon {
    font-size: 1.5rem;
    margin-bottom: 5px;
}

.mode-title {
    font-family: 'Orbitron', sans-serif;
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--secondary-neon);
}

.mode-desc {
    font-size: 0.7rem;
    color: #888;
    line-height: 1.2;
    margin-top: 5px;
}

.back-btn {
    margin-top: 20px;
    background: transparent;
    border: 1px solid var(--glass-border);
    color: #888;
    padding: 10px 20px;
    border-radius: 20px;
    font-size: 0.8rem;
    cursor: pointer;
}

/* Game Over Screen */
#game-over-screen {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    pointer-events: all;
    backdrop-filter: blur(8px);
    z-index: 300;
}

#game-over-screen.active {
    display: flex;
}

.go-title {
    font-family: 'Orbitron', sans-serif;
    font-size: 2rem;
    color: #ff4444;
    margin-bottom: 20px;
    letter-spacing: 2px;
}

.final-score-box {
    text-align: center;
    margin-bottom: 10px;
}

.fs-label {
    font-size: 0.8rem;
    color: #888;
}

.fs-value {
    font-family: 'Orbitron', sans-serif;
    font-size: 3rem;
    font-weight: 900;
    color: white;
    text-shadow: 0 0 20px rgba(255, 255, 255, 0.3);
}

.restart-btn {
    background: white;
    color: black;
    border: none;
    padding: 15px 40px;
    border-radius: 30px;
    font-size: 1rem;
    font-weight: 800;
    cursor: pointer;
    margin-bottom: 10px;
    box-shadow: 0 0 20px rgba(255, 255, 255, 0.3);
}

.menu-btn {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
    padding: 10px 30px;
    border-radius: 30px;
    cursor: pointer;
}

/* Modal Styles */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.9);
    z-index: 500;
    display: none;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(10px);
}

.modal-content {
    background: linear-gradient(135deg, #1a0b2e, #02040a);
    border: 1px solid var(--glass-border);
    padding: 20px;
    width: 90%;
    max-width: 400px;
    border-radius: 20px;
    box-shadow: 0 0 30px rgba(168, 85, 247, 0.3);
    text-align: center;
    color: white;
}

.modal-title {
    font-family: 'Orbitron', sans-serif;
    color: var(--secondary-neon);
    margin-bottom: 20px;
}

.tabs {
    display: flex;
    margin-bottom: 15px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 10px;
    padding: 5px;
}

.tab {
    flex: 1;
    background: transparent;
    border: none;
    color: #888;
    padding: 8px;
    border-radius: 8px;
    font-weight: 700;
    cursor: pointer;
    font-size: 0.8rem;
    transition: all 0.2s;
}

.tab.active {
    background: var(--primary-neon);
    color: white;
}

.timer-banner {
    font-size: 0.75rem;
    color: var(--spark-gold);
    background: rgba(255, 215, 0, 0.1);
    padding: 5px;
    border-radius: 5px;
    margin-bottom: 10px;
    border: 1px solid rgba(255, 215, 0, 0.2);
}

.lb-list {
    max-height: 250px;
    overflow-y: auto;
    margin-bottom: 20px;
    text-align: left;
}

.lb-row {
    display: flex;
    justify-content: space-between;
    padding: 10px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    font-size: 0.9rem;
}

.lb-rank {
    width: 30px;
    font-weight: 700;
    color: #888;
}

.lb-name {
    flex: 1;
    color: white;
}

.lb-score {
    font-family: 'Orbitron', sans-serif;
    color: var(--secondary-neon);
}

.rank-1 {
    color: #ffd700;
}

.rank-2 {
    color: #c0c0c0;
}

.rank-3 {
    color: #cd7f32;
}

.close-modal-btn {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
    padding: 10px 30px;
    border-radius: 20px;
    cursor: pointer;
    width: 100%;
}

.rules-text {
    text-align: left;
    font-size: 0.85rem;
    color: #ddd;
    line-height: 1.5;
    margin-bottom: 20px;
}

.rules-text p {
    margin-bottom: 10px;
}

.rules-text strong {
    color: var(--primary-neon);
}

/* Icon Button */
.icon-btn {
    background: var(--glass);
    border: 1px solid var(--glass-border);
    color: white;
    padding: 8px 15px;
    border-radius: 15px;
    cursor: pointer;
    font-size: 0.8rem;
    transition: all 0.2s;
}

/* Rotation Support */
/* Rotation Support */
.game-container.rotated {
    width: 100dvh;
    height: 100vw;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) rotate(90deg);
    transform-origin: center;
    overflow: hidden;
    z-index: 0;
    /* Ensure it stays at base level but above body? */
}

/* Force override for rotated state inputs */
.game-container.rotated #game-canvas {
    width: 100%;
    height: 100%;
}