@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&family=Orbitron:wght@600;800&family=Exo+2:wght@400;600&display=swap');

:root {
    --primary: #00ccff;
    /* Neon Blue */
    --accent: #0088ff;
    /* Deep Blue */
    --bg-dark: #050510;
    /* Darker Blue-Black */
    --glass: rgba(10, 20, 40, 0.85);
    /* Blueish Glass */
}

body {
    margin: 0;
    padding: 0;
    overflow: hidden;
    overflow: hidden;
    /* Northern Lights Theme */
    background: linear-gradient(135deg, #0f2027 0%, #203a43 50%, #2c5364 100%);
    background-size: 100% 100%;
    font-family: 'Exo 2', sans-serif;
    color: white;
}

/* Stars Effect */
body::before,
body::after {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: 2px;
    height: 2px;
    border-radius: 50%;
    box-shadow:
        10vw 10vh #fff, 20vw 80vh #fff, 80vw 10vh #fff, 90vw 90vh #fff,
        30vw 30vh #fff, 50vw 50vh #fff, 70vw 70vh #fff, 40vw 20vh #fff,
        60vw 80vh #fff, 10vw 90vh #fff, 90vw 20vh #fff, 50vw 10vh #fff,
        25vw 45vh #fff, 75vw 55vh #fff, 15vw 65vh #fff, 85vw 35vh #fff,
        5vw 5vh #fff, 95vw 95vh #fff, 35vw 75vh #fff, 65vw 25vh #fff,
        45vw 15vh #fff, 55vw 85vh #fff, 20vw 60vh #fff, 80vw 40vh #fff,
        10vw 50vh #fff, 90vw 50vh #fff, 50vw 90vh #fff, 50vw 20vh #fff;
    animation: twinkle 5s linear infinite;
    opacity: 0.8;
    z-index: -1;
}

body::after {
    width: 3px;
    height: 3px;
    box-shadow:
        15vw 15vh #fff, 85vw 85vh #fff, 35vw 65vh #fff, 65vw 35vh #fff,
        25vw 75vh #fff, 75vw 25vh #fff, 45vw 45vh #fff, 55vw 55vh #fff,
        10vw 30vh #aaa, 90vw 70vh #aaa, 30vw 90vh #aaa, 70vw 10vh #aaa;
    animation: twinkle 7s linear infinite reverse;
    opacity: 0.6;
}

@keyframes twinkle {
    0% {
        opacity: 0.4;
    }

    50% {
        opacity: 1;
    }

    100% {
        opacity: 0.4;
    }
}

/* Header */
#game-header {
    height: 70px;
    background: #111;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 40px;
    border-bottom: 2px solid #333;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.5);
    z-index: 1000;
    position: relative;
}

.brand {
    font-family: 'Orbitron', sans-serif;
    font-size: 24px;
    font-weight: 800;
    color: var(--primary);
    display: flex;
    align-items: center;
    gap: 10px;
    text-shadow: 0 0 10px rgba(0, 204, 255, 0.5);
}

.game-tabs {
    display: flex;
    gap: 20px;
}

.tab-btn {
    background: transparent;
    border: none;
    color: #888;
    font-family: 'Orbitron', sans-serif;
    font-size: 16px;
    cursor: pointer;
    padding: 10px 20px;
    border-radius: 8px;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 8px;
}

.tab-btn:hover {
    color: white;
    background: rgba(255, 255, 255, 0.05);
}

.tab-btn.active {
    background: var(--primary);
    color: white;
    box-shadow: 0 0 15px var(--primary);
}

/* Game Containers */
/* Game Containers */
.game-wrapper {
    position: absolute;
    top: 70px;
    left: 0;
    width: 100%;
    height: calc(100vh - 70px);
    background: #000;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    padding: 20px;
    box-sizing: border-box;
}

.game-wrapper.hidden {
    display: none;
}

canvas {
    display: block;
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    aspect-ratio: 4/3;
    background: #222;
    border: 2px solid #444;
    border-radius: 4px;
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.5);
    /* Ensure UI layers match canvas size by making canvas the reference */
}

/* 
   We need a specific container for UI overlays to match the Canvas Size exactly.
   But currently UI is relative to .game-wrapper (full screen).
   Since changing HTML is expensive, we can use a trick:
   The UI overlays are ALREADY siblings to canvas.
   If we set .game-wrapper to display grid, we can stack them?
   NO. The best way without changing HTML is forcing UI to conform to the aspect ratio 
   within the center.
*/

/* Helper to center content */
.game-wrapper {
    /* ... existing ... */
}

/* 
   Ideally, we should wrap canvas + ui in a div. 
   But since we can't easily, let's make the .game-wrapper constrained?
   No, wrapper is full screen.
   
   Wait, if `canvas` is centered and scaled, the `absolute` UI will be top-left of wrapper (0,0) which is CORNER OF SCREEN.
   Canvas will be in MIDDLE.
   UI will NOT OVERLAY CANVAS.
   
   CRITICAL FIX: 
   We MUST wrap standard game elements in a container OR make `.game-wrapper` ITSELF the centered box.
   
   If `.game-wrapper` IS the centered box:
   - It needs `margin: auto`.
   - It needs `position: relative` (for UI).
   - It needs `width: 100%` / `height: 100%` max but aspectRatio 4/3.
   
   Let's try that approach on `.game-wrapper` directly.
   BUT `.game-wrapper` is currently the full screen container in `index.html`.
   "Game Containers" section.
*/

/* REVISED STRATEGY: */
/* 
   We will keep `.game-wrapper` as the full screen background.
   We will treat the `canvas` as the key layout element.
   BUT UI IS ABSOLUTE.
   
   We CANNOT fix this purely in CSS without a container relative to the canvas size, UNLESS:
   1. We use grid:
      .game-wrapper { display: grid; place-items: center; }
      canvas { grid-area: 1/1; }
      #runner-ui { grid-area: 1/1; position: relative; width: 100%; height: 100%; }
      
      This stacks them!
      If `#runner-ui` is `width:100%; height:100%` of the grid item, it matches canvas!
      
      Let's verify:
      Canvas has intrinsic size.
      UI has no intrinsic size (div).
      If we stack them in grid, the grid cell takes size of Canvas.
      The UI (width 100%) takes size of Grid Cell.
      This works!
*/

.game-wrapper {
    position: absolute;
    top: 70px;
    left: 0;
    width: 100%;
    height: calc(100vh - 70px);
    background: #000;

    display: grid;
    place-items: center;
}

canvas {
    grid-area: 1 / 1;
    display: block;
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    aspect-ratio: 4/3;
    background: #222;
    border: 2px solid #444;
    border-radius: 4px;
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.5);
    z-index: 1;
}

/* Update UI Overlays to stack in the same grid cell */
#runner-ui,
#snake-ui,
#blast-ui,
#xox-ui,
#memory-ui,
#merge-ui {
    grid-area: 1 / 1;
    position: relative;
    /* Change from absolute to relative to grid area */
    top: auto;
    left: auto;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 2;
    /* Above canvas */
}

/* UI Overlays generic override removed (handled above specifically) */
/* Keeping this for safety but ensuring specificity isn't an issue */

/* Common Screen Styles */
.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(5px);
    display: flex;
    justify-content: center;
    align-items: center;
    pointer-events: auto;
    z-index: 10;
}

.screen.hidden {
    display: none;
}

.card {
    background: var(--glass);
    padding: 40px 60px;
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    text-align: center;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    max-width: 600px;
    width: 80%;
}

.card h1 {
    font-family: 'Orbitron', sans-serif;
    font-size: 48px;
    margin: 0 0 20px;
    color: white;
    text-shadow: 0 0 20px rgba(255, 255, 255, 0.2);
}

.card h1.danger {
    color: #ff3333;
}

.card h1.victory {
    color: #ffd700;
}

.action-btn {
    background: var(--primary);
    color: white;
    border: none;
    padding: 15px 40px;
    font-family: 'Orbitron', sans-serif;
    font-size: 20px;
    border-radius: 5px;
    cursor: pointer;
    margin: 10px;
    transition: transform 0.2s, background 0.2s;
}

.action-btn:hover {
    transform: scale(1.05);
    background: #ff4d88;
}

.action-btn.secondary {
    background: transparent;
    border: 2px solid var(--accent);
    color: var(--accent);
}

.action-btn.secondary:hover {
    background: var(--accent);
    color: #000;
}

/* Runner UI */
#runner-score-board,
#snake-score-board,
#blast-score-board,
#xox-score-board,
#memory-score-board {
    position: absolute;
    top: 30px;
    left: calc(50% - 400px + 20px);
    /* Align with canvas */
    display: flex;
    gap: 20px;
}

.score-box {
    background: rgba(0, 0, 0, 0.8);
    padding: 10px 20px;
    border-radius: 8px;
    border: 1px solid #444;
}

.score-box .label {
    display: block;
    font-size: 12px;
    color: #888;
    margin-bottom: 5px;
}

.score-box .value {
    font-family: 'Orbitron', sans-serif;
    font-size: 24px;
    color: var(--accent);
}

.score-box .unit {
    font-size: 14px;
    color: #666;
}

.keys {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-top: 30px;
}

.key {
    background: #333;
    padding: 10px 20px;
    border-radius: 5px;
    border: 1px solid #555;
}

.stats p {
    font-size: 24px;
    margin: 10px 0;
}

.highlight {
    color: white;
    font-weight: bold;
}

.highlight.gold {
    color: #ffd700;
}

/* UI Overlays Check */
.pause-overlay-btn {
    position: absolute;
    top: 30px;
    left: calc(50% + 400px - 60px);
    /* Aligned to right side of 800px canvas */
    pointer-events: auto;
    z-index: 5;
    cursor: pointer;
    background: rgba(0, 0, 0, 0.5);
    padding: 5px;
    border-radius: 5px;
    border: 1px solid #444;
}

.pause-overlay-btn img {
    width: 30px;
    height: 30px;
    display: block;
    opacity: 0.8;
    transition: opacity 0.2s;
}

.pause-overlay-btn:hover img {
    opacity: 1;
    transform: scale(1.1);
}

/* Fight UI Removed */

/* --- MAIN MENU STYLES --- */
#main-menu-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    width: 100%;
    overflow-y: auto;
    padding: 20px;
    box-sizing: border-box;
}

.main-title {
    font-family: 'Press Start 2P', cursive;
    color: #ffffff;
    font-size: 40px;
    margin-bottom: 50px;
    text-shadow: 0 0 20px rgba(0, 204, 255, 0.6);
    text-align: center;
}

.game-grid {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 30px;
    max-width: 1200px;
    z-index: 10;
}

.game-card {
    background: rgba(20, 20, 30, 0.8);
    border: 2px solid #333;
    border-radius: 15px;
    width: 250px;
    height: 300px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    /* Bouncy transition */
    cursor: pointer;
    position: relative;
    overflow: hidden;
}

.game-card:hover {
    transform: translateY(-10px) scale(1.02);
    border-color: var(--primary);
    box-shadow: 0 10px 30px rgba(0, 204, 255, 0.3);
    background: rgba(20, 40, 60, 0.95);
}

.game-card .icon {
    font-size: 60px;
    margin-bottom: 20px;
    color: white;
    /* Force white color for text icons like RUN and abc */
    text-shadow: 0 0 10px rgba(255, 255, 255, 0.5);
    /* Enhanced glow */
    filter: drop-shadow(0 0 10px rgba(255, 255, 255, 0.3));
}

.game-card .name {
    font-family: 'Orbitron', sans-serif;
    color: white;
    font-size: 20px;
    font-weight: 800;
    margin-bottom: 15px;
    text-align: center;
}

.game-card .desc {
    font-family: 'Exo 2', sans-serif;
    color: #aaa;
    font-size: 14px;
    text-align: center;
    padding: 0 15px;
}

/* Footer Credit */
.footer-credit {
    position: fixed;
    bottom: 20px;
    right: 20px;
    color: white;
    font-family: 'Orbitron', sans-serif;
    font-size: 14px;
    opacity: 0.8;
    text-shadow: 0 0 5px rgba(255, 255, 255, 0.5);
    z-index: 2000;
    pointer-events: none;
}

/* UNO UI Specifics */
#uno-ui {
    grid-area: 1 / 1;
    position: relative;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 2;
}

#uno-turn-indicator {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.7);
    padding: 10px 20px;
    border-radius: 20px;
    font-size: 18px;
    font-weight: bold;
    border: 2px solid var(--primary);
}

#uno-color-picker {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    pointer-events: auto;
    z-index: 50;
}

#uno-color-picker.hidden {
    display: none;
}

.picker-content {
    background: white;
    padding: 20px;
    border-radius: 10px;
    text-align: center;
}

.picker-content h3 {
    margin-top: 0;
    color: #333;
}

.picker-content .colors {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.color-btn {
    width: 60px;
    height: 60px;
    cursor: pointer;
    border-radius: 5px;
    border: 2px solid #ccc;
    transition: transform 0.1s;
}

.color-btn:active {
    transform: scale(0.9);
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    .main-title {
        font-size: 28px;
        margin-bottom: 30px;
    }

    .game-grid {
        gap: 20px;
    }

    .game-card {
        width: 100%;
        max-width: 320px;
        height: 100px;
        /* Compact horizontal card */
        flex-direction: row;
        padding: 0 20px;
        justify-content: flex-start;
    }

    .game-card .icon {
        font-size: 40px;
        margin-bottom: 0;
        margin-right: 20px;
    }

    .game-card .name {
        font-size: 16px;
        text-align: left;
        margin-bottom: 5px;
    }

    .game-card .desc {
        display: none;
        /* Hide desc on mobile list view for cleaner look, or keep */
        text-align: left;
        padding: 0;
        font-size: 12px;
    }

    /* Ensure canvas fits */
    canvas {
        max-width: 100%;
        height: auto;
    }

    /* Adjust UI overlays */
    .pause-overlay-btn {
        top: 10px;
        right: 10px;
        /* Fixed position relative to screen might be better */
        left: auto;
    }

    #surfer-ui,
    #runner-ui,
    #snake-ui {
        /* Mobile UI adjustments */
    }
}