:root {
    color-scheme: only dark;
    --panel-bg: rgba(11, 4, 16, 0.85);
    --panel-border: #ff0055;
    --accent: #00f3ff;
    --accent-strong: #ff00aa;
    --glow: rgba(255, 0, 85, 0.6);
    --button-bg: linear-gradient(135deg, rgba(255, 0, 85, 0.8), rgba(20, 0, 40, 0.9));
    --button-border: #ff0055;
    --font-heading: 'Orbitron', sans-serif;
    --font-body: 'Rajdhani', sans-serif;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100dvh;
    font-family: var(--font-body);
    background: #0b0410;
    color: #e0d0ff;
    overflow: hidden;
}

#page {
    position: relative;
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: clamp(12px, 3vw, 32px);
    background: radial-gradient(circle at 50% 120%, rgba(255, 0, 85, 0.15), transparent 60%), #0b0410;
}

/* Perspective Grid Background */
#page::before {
    content: '';
    position: absolute;
    inset: 0;
    background-image: linear-gradient(rgba(255, 0, 85, 0.2) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 0, 85, 0.2) 1px, transparent 1px);
    background-size: 40px 40px;
    transform: perspective(500px) rotateX(60deg) translateY(100px) translateZ(-200px);
    opacity: 0.6;
    pointer-events: none;
}

#layout {
    position: relative;
    z-index: 1;
    width: min(1200px, 96vw);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: clamp(12px, 3vw, 26px);
}

#game-container {
    position: relative;
    flex: 1;
    max-width: 880px;
    width: min(70vw, 880px);
    height: clamp(320px, 70vh, 680px);
    border-radius: 8px;
    /* Sharper corners */
    background: rgba(5, 2, 8, 0.8);
    border: 2px solid var(--panel-border);
    box-shadow: 0 0 20px var(--glow), inset 0 0 30px rgba(255, 0, 85, 0.2);
    overflow: hidden;
    clip-path: polygon(0 20px, 20px 0, 100% 0, 100% calc(100% - 20px), calc(100% - 20px) 100%, 0 100%);
}

#game-container::before {
    content: '';
    position: absolute;
    inset: 4px;
    border: 1px dashed rgba(0, 243, 255, 0.4);
    pointer-events: none;
    z-index: 5;
}

canvas {
    background: transparent;
    display: block;
    width: 100%;
    height: 100%;
}

#ui-container {
    position: absolute;
    top: 12px;
    left: 16px;
    right: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    font-family: var(--font-heading);
    font-size: clamp(12px, 2vw, 18px);
    color: var(--accent);
    text-shadow: 0 0 10px var(--accent);
    pointer-events: none;
    z-index: 10;
}

#score-level {
    display: flex;
    gap: 18px;
    padding: 6px 14px;
    background: rgba(11, 4, 16, 0.8);
    border: 1px solid var(--accent);
    box-shadow: inset 0 0 10px rgba(0, 243, 255, 0.3), 0 0 10px rgba(0, 243, 255, 0.3);
    clip-path: polygon(10px 0, 100% 0, calc(100% - 10px) 100%, 0 100%);
}

#score-level div {
    white-space: nowrap;
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

#lives {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 10px;
    background: rgba(11, 4, 16, 0.8);
    border: 1px solid var(--accent);
    box-shadow: inset 0 0 10px rgba(0, 243, 255, 0.3), 0 0 10px rgba(0, 243, 255, 0.3);
    clip-path: polygon(0 0, calc(100% - 10px) 0, 100% 10px, 100% 100%, 0 100%);
}

.life-ship {
    width: 16px;
    height: 16px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath d='M10 0 L15 20 L5 20 Z' fill='%2300f3ff'/%3E%3C/svg%3E");
    background-size: contain;
    background-repeat: no-repeat;
    filter: drop-shadow(0 0 5px #00f3ff);
}

.game-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background: rgba(5, 2, 10, 0.85);
    backdrop-filter: blur(4px);
    text-align: center;
    gap: 20px;
    z-index: 20;
}

.game-overlay h1,
.title-top {
    font-family: var(--font-heading);
    color: var(--accent);
    text-shadow: 0 0 15px var(--accent), 0 0 30px var(--accent);
    margin: 0;
    letter-spacing: 0.15em;
    text-transform: uppercase;
}

.title-top {
    font-size: clamp(20px, 3vw, 36px);
}

.title-bottom {
    font-family: var(--font-heading);
    font-size: clamp(42px, 7vw, 76px);
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--panel-border);
    text-shadow: 0 0 20px var(--glow), 0 0 40px var(--glow);
    font-style: italic;
}

.title-block {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    margin-bottom: 20px;
}

.game-overlay p {
    font-size: clamp(14px, 2vw, 18px);
    margin: 0;
    color: #e0d0ff;
    letter-spacing: 0.05em;
    text-shadow: 0 0 5px rgba(224, 208, 255, 0.5);
}

.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.menu-buttons.horizontal {
    flex-direction: row;
    justify-content: center;
    flex-wrap: wrap;
}

.game-button {
    padding: 14px 40px;
    font-size: clamp(14px, 2vw, 18px);
    font-family: var(--font-heading);
    font-weight: 800;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    background: var(--button-bg);
    color: #fff;
    border: 2px solid var(--button-border);
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 0 15px var(--glow), inset 0 0 10px rgba(255, 0, 85, 0.4);
    clip-path: polygon(10px 0, 100% 0, 100% calc(100% - 10px), calc(100% - 10px) 100%, 0 100%, 0 10px);
    position: relative;
    pointer-events: auto;
}

.game-button::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 50%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.4), transparent);
    transform: skewX(-20deg);
    transition: 0.5s;
}

.game-button:hover::before {
    left: 150%;
}

.game-button:hover {
    transform: scale(1.05);
    box-shadow: 0 0 25px var(--glow), inset 0 0 15px rgba(255, 0, 85, 0.6);
    background: linear-gradient(135deg, rgba(255, 50, 115, 0.9), rgba(40, 0, 80, 0.9));
}

.popup-exit {
    padding: 6px 14px;
    font-size: 16px;
    letter-spacing: normal;
    background: rgba(255, 0, 85, 0.4);
    box-shadow: 0 0 8px rgba(255, 0, 85, 0.5);
    clip-path: polygon(6px 0, 100% 0, 100% calc(100% - 6px), calc(100% - 6px) 100%, 0 100%, 0 6px);
    margin-left: auto;
    /* Push to the right edge */
}

.popup-exit:hover {
    transform: scale(1.1);
    background: rgba(255, 0, 85, 0.8);
    box-shadow: 0 0 15px rgba(255, 0, 85, 0.8);
}

.game-button.secondary {
    background: linear-gradient(135deg, rgba(0, 243, 255, 0.2), rgba(10, 0, 30, 0.8));
    border-color: var(--accent);
    box-shadow: 0 0 10px rgba(0, 243, 255, 0.4);
}

.game-button.secondary:hover {
    box-shadow: 0 0 20px rgba(0, 243, 255, 0.6);
    background: linear-gradient(135deg, rgba(0, 243, 255, 0.4), rgba(20, 0, 50, 0.9));
}

#mobile-controls {
    display: none;
    /* Hidden by default, shown on mobile */
    position: fixed;
    /* Fixed to the viewport */
    bottom: 20px;
    left: 10px;
    right: 10px;
    justify-content: space-between;
    align-items: flex-end;
    z-index: 9999;
    pointer-events: none;
    /* Allow clicks to pass through unless on a button */
}

.control-cluster {
    display: flex;
    gap: 10px;
    pointer-events: auto;
    /* Re-enable pointer events for buttons */
}

.mobile-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: rgba(11, 4, 16, 0.7);
    border: 2px solid var(--accent);
    color: var(--accent);
    font-size: 24px;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 0 15px rgba(0, 243, 255, 0.3), inset 0 0 10px rgba(0, 243, 255, 0.2);
    cursor: pointer;
    user-select: none;
    touch-action: manipulation;
    /* Improve touch responsiveness */
    -webkit-tap-highlight-color: transparent;
    /* Remove tap highlight on iOS */
}

.mobile-btn:active,
.mobile-btn:hover {
    background: rgba(0, 243, 255, 0.3);
    box-shadow: 0 0 20px rgba(0, 243, 255, 0.6);
}

.action-btn {
    width: 70px;
    height: 70px;
    font-family: var(--font-heading);
    font-weight: bold;
    font-size: 16px;
    color: #fff;
    border-color: var(--accent-strong);
    background: rgba(255, 0, 85, 0.4);
    box-shadow: 0 0 15px rgba(255, 0, 85, 0.4), inset 0 0 10px rgba(255, 0, 85, 0.3);
}

.action-btn:active,
.action-btn:hover {
    background: rgba(255, 0, 85, 0.7);
    box-shadow: 0 0 25px rgba(255, 0, 85, 0.7);
}


#start-screen {
    display: flex;
}

#game-over-screen {
    display: none;
}

#final-score {
    font-size: clamp(20px, 3vw, 30px);
    color: var(--accent);
    text-shadow: 0 0 10px var(--accent);
    font-weight: bold;
    letter-spacing: 0.1em;
}

@media (max-width: 900px) {
    #page {
        padding: 0;
    }

    #layout {
        width: 100vw;
        height: 100dvh;
        gap: 0;
    }

    #game-container {
        width: 100vw;
        height: 100dvh;
        max-height: 100dvh;
        max-width: 100vw;
        border: none;
        border-radius: 0;
        box-shadow: none;
        clip-path: none;
    }

    #game-container::before {
        display: none;
    }

    #ui-container {
        top: 15px;
        left: 15px;
        right: 15px;
    }

    .title-top {
        font-size: clamp(20px, 4vw, 30px);
    }

    .title-bottom {
        font-size: clamp(40px, 12vw, 65px);
    }

    .game-overlay p {
        padding: 0 20px;
        text-align: center;
        line-height: 1.5;
    }
}

@media (max-width: 600px) {
    #ui-container {
        flex-direction: column;
        align-items: stretch;
    }

    .left-stats {
        width: 100%;
        justify-content: flex-start;
    }

    #score-level,
    #lives {
        width: fit-content;
        clip-path: none;
        border-radius: 4px;
        transform: scale(0.85);
        transform-origin: left top;
    }

    .popup-exit {
        margin-left: 0;
        margin-top: 10px;
        width: fit-content;
    }

    .menu-buttons {
        width: 100%;
    }

    .game-button {
        width: min(240px, 85vw);
    }

    #mobile-controls {
        display: flex;
        bottom: 25px;
        left: 15px;
        right: 15px;
    }

    .control-cluster {
        gap: 12px;
    }

    .mobile-btn {
        width: 55px;
        height: 55px;
        font-size: 20px;
    }

    .action-btn {
        width: 65px;
        height: 65px;
        font-size: 14px;
    }
}