:root {
    --bg-color: #050505;
    --grid-color: #1a1a1a;
    --text-color: #ffffff;
    --p1-color: #00ff88;
    --p2-color: #00ccff;
    --food-color: #ff0055;
    --font-main: 'Outfit', sans-serif;
}

/* GLOBAL UTILITY - MUST BE TOP LEVEL */
.hidden {
    display: none !important;
    opacity: 0 !important;
    pointer-events: none !important;
    visibility: hidden !important;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    user-select: none;
    /* touch-action: none; REMOVED from generic wildcard */
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: var(--font-main);
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    touch-action: none;
    /* Block scrolling/zooming globally on body */
}

.main-wrapper {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100dvh;
    /* Fill screen exactly */
    overflow: hidden;
    align-items: center;
    /* Center horizontally (because flex-dir is column) */
}

.game-container {
    position: relative;
    border-radius: 4px;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    background: #050505;
    /* Border Restored to Container for guaranteed visibility */
    border: 2px solid #00ff88;
    box-shadow: 0 0 20px rgba(0, 255, 136, 0.2);
    box-sizing: border-box;
    /* Ensure border acts correctly */
    width: 100vw;
    /* Flexible Height for PC/Mobile Layout consistency */
    height: auto;
    flex: 1;
    /* width: 100% implicitly from flex parent? */

    /* FIX: Respect mobile browser bars */
    padding: 0;
    margin: 0;
    touch-action: none;
    /* Ensure game touches don't scroll */
}

canvas {
    display: block;
    box-sizing: border-box;
    /* Border removed from canvas, handled by container */
    border: none;
    box-shadow: none;
    /* Centering handled by flex parent */
    touch-action: none;
}

/* NUCLEAR SCROLL FIX v3 */
#high-score-screen,
#high-score-screen * {
    touch-action: pan-y !important;
}

#high-score-list {
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
    pointer-events: auto !important;
    height: 60vh !important;
    /* Enforce height */
    display: block !important;
    /* Ensure block layout for scrolling */
}

/* BLIND EFFECT */
.game-container.blinded {
    filter: brightness(0);
    /* Pitch black */
    animation: flashBlind 0.2s ease-out;
}

@keyframes flashBlind {

    /* Flash white first */
    100% {
        filter: brightness(0);
    }
}



canvas {
    display: block;
    width: 100%;
    height: 100%;
}

#ui-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 100;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.neon-title {
    text-align: center;
    width: 100%;
    font-size: 2.5rem;
    margin-bottom: 10px;
    letter-spacing: 4px;
    text-shadow: 0 0 10px var(--p1-color), 0 0 20px var(--p2-color);
}

#score-board {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    width: 98vw;
    margin: 0 auto 10px auto;
    padding: 0 10px;
    font-size: 1.2rem;
    font-weight: bold;
    white-space: nowrap;
}

.score-box {
    color: #fff;
    display: flex;
    gap: 10px;
    align-items: center;
}

.score-box.p1 {
    color: var(--p1-color);
    justify-self: start;
}

.score-box.p2 {
    color: var(--p2-color);
    justify-self: end;
}

.dynamic-legend-bar {
    justify-self: center;
    margin-bottom: 0;
    height: 30px;
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    gap: 15px;
    align-items: center;
    justify-content: center;
    min-width: 200px;
}

.legend-timers {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-left: 15px;
    font-weight: bold;
    color: #fff;
    text-shadow: 0 0 5px currentColor;
    background: rgba(0, 0, 0, 0.5);
    padding: 2px 8px;
    border-radius: 4px;
    border: 1px solid #444;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 0.85rem;
    color: #ccc;
    background: rgba(255, 255, 255, 0.05);
    padding: 2px 6px;
    border-radius: 4px;
}

.menu-screen {
    position: relative;
    max-width: 95%;
    width: 900px;
    background: rgba(10, 10, 10, 0.95);
    backdrop-filter: blur(10px);
    padding: 40px 60px;

    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.5);
    pointer-events: auto;
    transition: opacity 0.3s ease;
    z-index: 200;
    /* FIX: Allow scrolling on menu even with global touch-action: none */
    touch-action: auto !important;
}

.menu-screen.active {
    opacity: 1;
    z-index: 220;
    /* Ensure active screen is always on top */
    display: flex;
    /* Kept for child layout stability */
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    /* Changed from center to allow scrolling */
    text-align: center;
    overflow-y: auto;
    /* Allow scrolling if content is too tall */
    max-height: 95vh;
    padding-bottom: 50px !important;
    /* Extra space for bottom buttons (v7.02) */
}

/* HIGH SCORE LIST SCROLL FIX (v6.68) */
#high-score-list {
    width: 100%;
    overflow-y: auto;
    /* Use minimal height but allow growth */
    flex-grow: 1;
    /* Important for touch scrolling */
    touch-action: pan-y;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 10px;
    background: transparent;
    border-radius: 8px;
    padding: 10px;
}

/* Game Over Title Fix */
#winner-text {
    width: 100%;
    text-align: center;
    display: block;
    margin: 0 0 20px 0;
    font-size: 2.5rem;
    text-shadow: 0 0 10px rgba(255, 255, 255, 0.5);
}

.menu-options {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
}

/* FORCE CENTER OVERRIDE removed v7.02 due to syntax errors */

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeOutUp {
    from {
        opacity: 1;
        transform: translate(-50%, -50%);
    }

    to {
        opacity: 0;
        transform: translate(-50%, -150%);
    }
}

.instruction {
    margin-bottom: 30px;
    color: #888;
    font-size: 0.9rem;
    letter-spacing: 1px;
    text-transform: uppercase;
}

h2 {
    font-size: 2rem;
    margin-bottom: 20px;
    text-transform: uppercase;
    letter-spacing: 2px;
    text-align: center;
    width: 100%;
    display: block;
}

.btn,
.neon-btn {
    background: transparent;
    border: 2px solid var(--text-color);
    color: var(--text-color);
    padding: 12px 30px;
    font-size: 1rem;
    font-family: var(--font-main);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 2px;
    cursor: pointer;
    transition: all 0.2s ease;
    border-radius: 4px;
    margin: 10px;
    min-width: 200px;
}

.neon-btn:hover {
    background: var(--p1-color);
    color: #000;
    box-shadow: 0 0 20px var(--p1-color);
    border-color: var(--p1-color);
}

.btn.secondary,
.neon-btn.secondary {
    border-color: #666;
    color: #aaa;
}

.btn.secondary:hover,
.neon-btn.secondary:hover {
    background: #666;
    color: #fff;
    box-shadow: 0 0 20px rgba(100, 100, 100, 0.4);
}

#high-scores {
    margin-top: 20px;
    width: 100%;
    text-align: center !important;
    display: flex;
    flex-direction: column;
    align-items: center !important;
}

#high-scores h2 {
    text-align: center !important;
    width: 100%;
    margin-bottom: 15px;
    display: block !important;
}

#high-score-list {
    list-style: none;
    padding: 0;
    margin: 0 auto;
    /* Center it */
    width: 100%;
    max-width: 500px;
    /* Prevent being too narrow or too wide */

    /* Limit height on desktop */
    max-height: 60vh;
    /* Space for scrollbar */
    padding-right: 10px;

    /* Scrollbar Styling */
    scrollbar-width: thin;
    scrollbar-color: var(--p1-color) rgba(255, 255, 255, 0.05);
}

/* Webkit Scrollbar */
#high-score-list::-webkit-scrollbar {
    width: 6px;
}

#high-score-list::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
}

#high-score-list::-webkit-scrollbar-thumb {
    background-color: var(--p1-color);
    border-radius: 3px;
}

#high-score-list li {
    background: rgba(255, 255, 255, 0.05);
    padding: 10px 20px;
    margin-bottom: 5px;
    display: flex;
    justify-content: space-between;
    border-radius: 4px;
    font-size: 1.1rem;
    color: var(--p1-color);
    border: 1px solid transparent;
    /* Prepare for border highlight */
}

#high-score-list li.highlight {
    background: rgba(0, 255, 136, 0.2);
    border-color: var(--p1-color);
    box-shadow: 0 0 15px rgba(0, 255, 136, 0.3);
    font-weight: bold;
    color: #fff;
    animation: pulseHighlight 2s infinite;
}

@keyframes pulseHighlight {
    0% {
        box-shadow: 0 0 15px rgba(0, 255, 136, 0.3);
    }

    50% {
        box-shadow: 0 0 25px rgba(0, 255, 136, 0.6);
    }

    100% {
        box-shadow: 0 0 15px rgba(0, 255, 136, 0.3);
    }
}

/* PC HIGH SCORE OPTIMIZATION */
@media (min-width: 1000px) {
    #high-score-list {
        display: grid !important;
        grid-template-columns: 1fr 1fr;
        gap: 10px;
        max-width: 900px !important;
        max-height: 75vh !important;
    }

    #high-score-list li {
        font-size: 1rem;
        padding: 5px 15px;
    }

    /* Side-by-side controls on PC */
    #hs-controls {
        display: flex;
        flex-direction: row;
        gap: 40px;
        justify-content: center;
        margin-bottom: 10px;
    }

    .score-tabs {
        flex: 1;
        max-width: 300px;
    }
}

/* Default HS Controls (Mobile) */
#hs-controls {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-bottom: 20px;
    align-items: center;
}

.score-tabs {
    width: 100%;
    max-width: 400px;
}

.neon-btn.small {
    flex: 1;
    padding: 8px;
    font-size: 0.8rem;
    min-width: auto;
    margin: 0;
    /* Override default btn margin */
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem;
    color: #ccc;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.dot {
    width: 12px;
    height: 12px;
    border-radius: 2px;
    display: inline-block;
    box-shadow: 0 0 5px currentColor;
}

/* Static Instruction Colors */
.dot.normal {
    background-color: #ff0055;
    color: #ff0055;
}

/* Food */
.dot.purple,
.dot.ghost {
    background-color: #8800ff;
    color: #8800ff;
}

.dot.orange,
.dot.speed {
    background-color: #ff6600;
    color: #ff6600;
}

.dot.blue,
.dot.slow {
    background-color: #0000ff;
    color: #0000ff;
}

.dot.red,
.dot.bomb {
    background-color: #b30000;
    color: #b30000;
}

.dot.silver,
.dot.shield {
    background-color: #c0c0c0;
    color: #c0c0c0;
}

.dot.pink,
.dot.magnet {
    background-color: #ff69b4;
    color: #ff69b4;
}

.dot.brown,
.dot.wall {
    background-color: #8b4513;
    color: #8b4513;
}

.dot.white,
.dot.eraser {
    background-color: #ffffff;
    color: #ffffff;
}

.dot.black,
.dot.blind {
    background-color: #333333;
    color: #333333;
    border: 1px solid #555;
}

.dot.cyan,
.dot.ice {
    background-color: #00ffff;
    color: #00ffff;
}

.dot.green,
.dot.switch {
    background-color: #00ff00;
    color: #00ff00;
}

/* Mobile adjustments */
@media (max-width: 768px) {
    .neon-title {
        font-size: 1.2rem;
        /* Smaller title on mobile */
        margin-bottom: 2px;
        /* Reduce gap */
        margin-top: 5px;
        /* Ensure visible at top */
    }

    #score-board {
        font-size: 0.8rem;
        padding: 0 5px;
        margin-bottom: 2px;
        /* Reduce gap to canvas */
    }

    /* HIDE LOCAL MULTIPLAYER ON MOBILE */
    #btn-2p {
        display: none !important;
    }

    .menu-screen {
        padding: 20px;
        width: 95%;
        max-height: 90vh;
        /* Maximize space */
        overflow-y: auto;
    }

    .menu-screen.active {
        /* Fix for content being cut off at top in landscape/small screens */
        justify-content: flex-start !important;
        padding-top: 10px;
    }

    .instructions-split-layout {
        flex-direction: column;
    }

    .instructions-split-layout>div {
        border-left: none !important;
        padding-left: 0 !important;
        border-top: 1px solid #333;
        padding-top: 5px;
        margin-top: 5px;
    }

    #high-score-list {
        max-height: 60dvh !important;
        /* Use dynamic viewport height */
        overflow-y: auto !important;
        touch-action: pan-y !important;
    }
}

#player-name-input {
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid var(--p1-color);
    color: #fff;
    padding: 15px;
    font-size: 1.5rem;
    font-family: var(--font-main);
    text-align: center;
    border-radius: 8px;
    margin-bottom: 20px;
    width: 100%;
    outline: none;
    text-transform: uppercase;
}

#auth-options-container button {
    font-size: 0.8rem;
    padding: 8px 15px;
    min-width: 100px;
}

canvas {
    display: block;
    box-sizing: content-box;
    border: none;
}