@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;700&family=Space+Mono:wght@400;700&display=swap');

:root {
    --neon-blue: #00ffcc;
    --neon-pink: #ff0055;
    --neon-orange: #ff9900;
    --bg-color: #050505;
    --glass-bg: rgba(255, 255, 255, 0.05);
    --glass-border: rgba(255, 255, 255, 0.1);
    --text-main: #ffffff;
    --text-muted: #aaaaaa;
}

body {
    margin: 0;
    overflow: hidden;
    background-color: var(--bg-color);
    touch-action: none;
    font-family: 'Outfit', sans-serif;
    user-select: none;
}

canvas {
    display: block;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 1;
}

/* --- UI Overlay --- */
#ui-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10;
    pointer-events: none;
    /* Let clicks pass through to canvas usually */
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.interactive {
    pointer-events: auto;
}

/* Scanlines */
.scanlines {
    background: linear-gradient(to bottom, rgba(255, 255, 255, 0), rgba(255, 255, 255, 0) 50%, rgba(0, 0, 0, 0.2) 50%, rgba(0, 0, 0, 0.2));
    background-size: 100% 4px;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    z-index: 10;
}

/* --- Top Bar Elements --- */
.top-bar {
    /* logical container only */
    position: absolute;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

/* Menu Corner (Top Left) */
.menu-container {
    position: absolute;
    top: 20px;
    left: 20px;
    pointer-events: none;
    z-index: 20;
}

/* -- Custom Select Styling -- */
.custom-select {
    position: relative;
    font-family: 'Space Mono', monospace;
    font-weight: bold;
    font-size: 14px;
    width: 140px;
    /* Fixed width to fit content */
    pointer-events: auto;
}

.select-selected {
    background-color: rgba(20, 20, 20, 0.8);
    backdrop-filter: blur(10px);
    color: var(--neon-blue);
    padding: 10px 15px;
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    cursor: pointer;
    user-select: none;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.select-selected:after {
    content: "";
    width: 0;
    height: 0;
    border: 5px solid transparent;
    border-color: var(--neon-blue) transparent transparent transparent;
    margin-left: 10px;
    transform: translateY(2px);
}

.select-selected.select-arrow-active:after {
    border-color: transparent transparent var(--neon-blue) transparent;
    transform: translateY(-2px);
}

.select-items {
    position: absolute;
    background-color: rgba(10, 10, 10, 0.95);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    top: 110%;
    left: 0;
    right: 0;
    z-index: 99;
    overflow: hidden;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.5);
}

.select-items div {
    color: #fff;
    padding: 10px 15px;
    cursor: pointer;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    transition: background 0.2s;
}

.select-items div:last-child {
    border-bottom: none;
}

.select-items div:hover,
.same-as-selected {
    background-color: rgba(0, 255, 204, 0.1);
    color: var(--neon-blue);
}

.select-hide {
    display: none;
}

.disabled {
    color: var(--text-muted) !important;
    cursor: not-allowed !important;
    opacity: 0.5;
}

/* Leaderboard Corner (Top Right, Left of Settings) */
.leaderboard-container {
    position: absolute;
    top: 20px;
    right: 80px;
    /* Space for settings button */
    background: var(--glass-bg);
    backdrop-filter: blur(10px);
    padding: 10px 15px;
    border-radius: 12px;
    border: 1px solid var(--glass-border);
    min-width: 120px;
    text-align: right;
    color: white;
    z-index: 20;
    color: white;
    z-index: 20;
    pointer-events: auto;
}

.leaderboard-title {
    font-size: 12px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 5px;
}

.leaderboard-list {
    list-style: none;
    padding: 0;
    margin: 0;
    font-family: 'Space Mono', monospace;
    font-size: 14px;
}

.leaderboard-list li {
    margin-bottom: 2px;
    display: flex;
    justify-content: space-between;
}

.leaderboard-list li span:first-child {
    color: var(--neon-pink);
    margin-right: 10px;
}

/* Score Display (Center Top) */
.score-container {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    text-align: center;
}

.score-label {
    font-size: 12px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 2px;
}

.score-value {
    font-family: 'Space Mono', monospace;
    font-size: 32px;
    color: var(--neon-blue);
    text-shadow: 0 0 15px var(--neon-blue);
}

/* --- Center Screen (Start / Game Over) --- */
.center-screen {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    color: white;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(5px);
    padding: 40px 60px;
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 0 30px rgba(0, 255, 204, 0.1);
    transition: opacity 0.3s;
}

.hidden {
    opacity: 0;
    pointer-events: none;
}

h1.game-title {
    font-size: 60px;
    margin: 0 0 10px 0;
    background: linear-gradient(to right, var(--neon-blue), #fff, var(--neon-pink));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: 0 0 30px rgba(255, 0, 85, 0.3);
    font-weight: 700;
    letter-spacing: -2px;
}

.start-btn {
    background: linear-gradient(45deg, var(--neon-pink), var(--neon-orange));
    border: none;
    padding: 15px 40px;
    color: white;
    font-size: 18px;
    font-weight: bold;
    border-radius: 50px;
    cursor: pointer;
    margin-top: 20px;
    box-shadow: 0 10px 20px rgba(255, 0, 85, 0.3);
    transition: transform 0.1s, box-shadow 0.1s;
    font-family: 'Outfit', sans-serif;
}

.start-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 10px 30px rgba(255, 0, 85, 0.5);
}

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

.instructions {
    margin-top: 20px;
    color: var(--text-muted);
    font-size: 14px;
}

/* --- Settings Panel (Top Right) --- */
.settings-container {
    position: absolute;
    top: 20px;
    right: 20px;
    pointer-events: auto;
    z-index: 30;
}

.settings-btn {
    background: rgba(20, 20, 20, 0.8);
    backdrop-filter: blur(10px);
    border: 1px solid var(--glass-border);
    color: var(--text-muted);
    font-size: 20px;
    width: 40px;
    height: 40px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.settings-btn:hover {
    color: #fff;
    border-color: var(--neon-blue);
    transform: rotate(90deg);
}

.settings-panel {
    position: absolute;
    top: 50px;
    right: 0;
    width: 180px;
    background: rgba(10, 10, 10, 0.95);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 15px;
    backdrop-filter: blur(15px);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    z-index: 100;
}

.settings-title {
    color: var(--text-muted);
    font-size: 10px;
    letter-spacing: 2px;
    text-transform: uppercase;
    margin-bottom: 15px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 5px;
}

.toggle-control {
    display: flex;
    align-items: center;
    margin-bottom: 12px;
    cursor: pointer;
    user-select: none;
}

.toggle-control:last-child {
    margin-bottom: 0;
}

.toggle-control input {
    margin-right: 10px;
    accent-color: var(--neon-pink);
    width: 16px;
    height: 16px;
    cursor: pointer;
}

.control-label {
    color: #fff;
    font-family: 'Space Mono', monospace;
    font-size: 12px;
}

/* --- Story/Terminal Overlay --- */
#story-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.95);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
}

.terminal-window {
    width: 80%;
    max-width: 600px;
    font-family: 'Courier New', monospace;
    color: #00ffcc;
    text-shadow: 0 0 10px #00ffcc;
}

#story-title {
    font-size: 32px;
    border-bottom: 2px solid #00ffcc;
    margin-bottom: 20px;
    padding-bottom: 10px;
    text-transform: uppercase;
}

#story-text {
    font-size: 18px;
    line-height: 1.5;
    min-height: 100px;
}

.blinking-cursor {
    display: inline-block;
    animation: blink 1s step-end infinite;
}

@keyframes blink {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0;
    }
}

/* --- Mobile Optimization --- */
@media screen and (max-width: 768px) {

    /* Minimize Top Bar */
    .top-bar {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        padding: 10px;
        background: linear-gradient(to bottom, rgba(0, 0, 0, 0.8), transparent);
        z-index: 100;
        pointer-events: none;
    }

    /* Make interactive elements clickable */
    .top-bar>* {
        pointer-events: auto;
    }

    /* Hide Desktop Menus */
    /* Mobile Leaderboard: allow JS to control visibility (remove display: none) */
    /* .leaderboard-container { display: none !important; } <--- Removed */

    /* Show Menu on Mobile (Top Center/Left) */
    .menu-container {
        display: block !important;
        top: 60px;
        /* Below score */
        left: 20px;
    }

    /* Score Display (Top Left instead of center) */
    .score-container {
        position: absolute;
        top: 15px;
        left: 20px;
        transform: none;
        text-align: left;
    }

    .score-label {
        font-size: 10px;
    }

    .score-value {
        font-size: 24px;
    }

    /* Settings in Top Right */
    .settings-container {
        position: absolute;
        top: 15px;
        right: 20px;
    }

    .settings-btn {
        width: 44px;
        height: 44px;
        /* Larger touch target */
        background: rgba(0, 0, 0, 0.6);
    }

    /* Polarity Button (Bottom Right - Thumb Zone) */
    #polarityBtn {
        bottom: 30px;
        right: 30px;
        width: 90px;
        height: 90px;
        opacity: 0.8;
        z-index: 200 !important;
        pointer-events: auto !important;
        font-size: 16px;
        background: rgba(0, 0, 0, 0.7);
        border-width: 3px;
    }

    /* Fix: Ensure hidden class overrides ID specificity on mobile */
    #polarityBtn.hidden {
        display: none !important;
    }

    /* Ensure Canvas Fills */
    canvas {
        width: 100%;
        height: 100%;
    }

    /* Improve Text Readability */
    h1.game-title {
        font-size: 40px;
    }

    .start-btn {
        padding: 15px 50px;
        font-size: 20px;
    }

    /* Hide scrollbars */
    body {
        overflow: hidden;
    }
}