/* Ensure the game fills the WebView viewport on mobile */
html, body {
    margin: 0;
    padding: 0;
    width: 100vw;
    height: 100vh;
    overflow: hidden;
    background: #000;
}

/* On mobile, scale to fit the screen */
@media (max-width: 900px) and (orientation: landscape) {
    .container {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        transform: none !important;
        width: 100vw;
        height: 100vh;
        overflow: hidden;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
    }
    
    /* Scale the game canvas and UI proportionally - fit to viewport height */
    .game-wrapper {
        transform: scale(0.75);
        transform-origin: center center;
        margin: 0;
    }
    
    h1 {
        font-size: 14px !important;
        margin: 5px 0 !important;
    }
}

@media (max-width: 900px) and (orientation: portrait) {
    .container {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        transform: none !important;
        width: 100vw;
        height: 100vh;
        overflow: hidden;
    }
    
    .game-wrapper {
        transform: scale(0.5);
        transform-origin: top center;
    }
    
    h1 {
        font-size: 12px !important;
        margin: 5px 0 !important;
    }
}

body { position: relative; }

@media (hover: none) and (pointer: coarse) {
    /* Reduce chrome above the canvas on mobile */
    .container > h1 { display: none; }
    #instructionsBtn { display: none; }
}
body {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100vh;
    background-color: #000;
    color: #fff;
    font-family: 'Courier New', Courier, monospace;
    margin: 0;
}

h1 {
    font-family: 'Press Start 2P', monospace;
    font-size: 1.8rem;
    color: gold;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
    margin-bottom: 10px;
    text-align: center;
    animation: glow 2s infinite alternate;
}

@keyframes glow {
    from {
        text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
    }
    to {
        text-shadow: 0 0 10px gold, 0 0 20px gold;
    }
}

canvas {
    border: 2px solid #fff;
    background: #000;
    margin: 0 auto;
    display: block;
    /* disable responsive scaling */
    max-width: none;
}

#gameCanvas {
    /* ensure full-size in multiplayer */
    width: 720px;
    height: 480px;
}

.container {
    text-align: center;
    max-width: 800px; /* Increased from 500px to fit larger canvas */
    margin: 0 auto;
    position: relative;
}

/* Enable transform scaling from JS fitToScreen() */
.container { will-change: transform; }

/* --- New styles --- */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.start-content {
    text-align: center;
    background: #111;
    padding: 20px 30px;
    border: 2px solid #fff;
}

.start-content h2 {
    font-family: 'Press Start 2P', monospace;
    color: #fff;
    margin-bottom: 15px;
}

.start-content input {
    padding: 8px 12px;
    font-size: 16px;
    margin-bottom: 10px;
}

.start-content button {
    padding: 10px 20px;
    font-size: 16px;
    cursor: pointer;
}

.game-wrapper {
    position: relative; /* For absolute positioning of mobile controls */
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: flex-start;
    gap: 20px;
}

#sidebar {
    width: 180px;
    background: #111;
    border: 2px solid #fff;
    color: #fff;
    padding: 10px;
}

#sidebar h2 {
    font-size: 18px;
    margin-top: 0;
    text-align: center;
}

#usersList {
    list-style: none;
    padding: 0;
    margin: 0;
}

#usersList li {
    padding: 6px 4px;
    border-bottom: 1px solid #333;
}

.scoreboard {
    width: 160px;
    background: #111;
    border: 2px solid #fff;
    color: #fff;
    padding: 10px;
    font-family: 'Press Start 2P', monospace;
    font-size: 12px;
}

.scoreboard table {
    width: 100%;
    border-collapse: collapse;
}

.scoreboard td {
    padding: 4px;
}

.scoreboard h2 {
    font-size: 14px;
    margin: 0 0 8px 0;
    text-align: center;
}

.scoreboard canvas {
    display: block;
    margin: 0 auto 30px;
    background-color: #111;
    border: none;
    border-radius: 50%;
}

.player-icon {
    vertical-align: middle;
    margin-right: 8px;
    filter: brightness(0) invert(1);
}

.p2-icon {
    /* tint P2 icon differently, e.g. yellow */
    filter: brightness(0) sepia(1) hue-rotate(60deg) saturate(5);
}

/* Info Button */
.info-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 2px solid #fff;
    background: #333;
    color: #fff;
    font-family: 'Press Start 2P', monospace;
    font-size: 16px;
    text-align: center;
    line-height: 32px;
    cursor: pointer;
}

/* Remove bullets from instructions lists */
.instructions-text ul {
    list-style: none;
    margin: 0;
    padding: 0;
}
.instructions-text li {
    margin: 4px 0;
    padding-left: 0;
}

/* Larger titles in instructions overlay */
#instructionOverlay .start-content h2 {
    font-size: 26px;
}
#instructionOverlay .instructions-text h3 {
    font-size: 18px;
}

/* Two-column instructions layout */
#instructionOverlay .start-content .instructions-text {
    display: flex;
    gap: 20px;
}
#instructionOverlay .instructions-left,
#instructionOverlay .instructions-right {
    flex: 1;
}
#instructionOverlay .start-content {
    max-height: 80vh;
    overflow-y: auto;
    padding: 20px;
}

/* Controls table styling in instructions */
#instructionOverlay .controls-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 16px;
}
#instructionOverlay .controls-table th,
#instructionOverlay .controls-table td {
    border: 1px solid #fff;
    padding: 4px 8px;
}
#instructionOverlay .controls-table th {
    background: rgba(255,255,255,0.2);
}

/* --- Cooldown Bar Styling --- */
.canvas-container {
    position: relative;
    display: inline-block;
}

.canvas-wrapper {
    position: relative;
    display: inline-block;
    width: 720px;  /* Match canvas width */
    height: 480px; /* Match canvas height */
}

.cooldown-container {
    width: 30px;
    height: 120px; /* 1/4 of 480px canvas */
    background: linear-gradient(180deg, #333, #222);
    border: 3px solid #fff;
    border-radius: 8px;
    box-shadow: 0 0 10px rgba(255,255,255,0.3);
    overflow: hidden;
    display: flex;
    flex-direction: column-reverse;
    position: absolute;
    bottom: 0;
}

.cooldown-bar {
    width: 100%;
    height: 0%;
    transition: height 0.1s linear;
    position: relative;
    overflow: hidden;
}

.cooldown-bar::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: repeating-linear-gradient(
        45deg,
        rgba(255,255,255,0.2),
        rgba(255,255,255,0.2) 10px,
        transparent 10px,
        transparent 20px
    );
    animation: shimmer 2s linear infinite;
}

@keyframes shimmer {
    0% { transform: translateX(0); }
    100% { transform: translateX(28.28px); }
}

#p1CooldownContainer {
    left: -40px; /* 30px width + 10px spacing */
    border-color: blue;
    box-shadow: 0 0 10px rgba(0,0,255,0.5);
}

#p1CooldownContainer .cooldown-bar {
    background: linear-gradient(180deg, #0066ff, #3399ff);
}

#p2CooldownContainer {
    right: -40px;
    border-color: green;
    box-shadow: 0 0 10px rgba(0,255,0,0.5);
}

#p2CooldownContainer .cooldown-bar {
    background: linear-gradient(180deg, #00cc00, #66ff66);
}

/* Left sidebar container: groups scoreboard and mobile buttons */
.left-sidebar-container {
    display: flex;
    flex-direction: column;
    gap: 20px; /* Gap between scoreboard and buttons */
    align-items: center;
}

/* --- Mobile Controls --- */
/* Hidden by default on desktop */
.mobile-controls-left,
.mobile-controls-right {
    display: none;
}

/* Show on touch devices and small screens (mobile browsers and apps) */
@media (hover: none) and (pointer: coarse), (max-width: 1024px) {
    /* Left side: Buttons below scoreboard in same container */
    .mobile-controls-left {
        display: flex;
        flex-direction: column;
        gap: 12px;
        align-items: center;
        justify-content: center;
        width: 160px; /* Match scoreboard width */
    }
    
    /* Right side: Joystick positioned absolutely inside canvas */
    .mobile-controls-right {
        display: flex;
        position: absolute;
        flex-direction: column;
        gap: 12px;
        align-items: center;
        justify-content: center;
    }
    
    /* Hide fullscreen button text on very small screens to save space */
    @media (max-width: 400px) {
        #btnFullscreen {
            font-size: 8px;
        }
    }
}

/* Right side: Joystick at bottom-right corner of the canvas itself */
.mobile-controls-right {
    right: 10px;
    bottom: 10px;
    pointer-events: none; /* Don't block canvas interactions */
}

/* But allow interactions with the joystick itself */
.mobile-controls-right .joystick {
    pointer-events: auto;
}

/* Mobile button styling */
.mobile-btn {
    background: rgba(255,255,255,0.08);
    color: #fff;
    border: 2px solid rgba(255,255,255,0.6);
    border-radius: 10px;
    width: 140px; /* Wider to fill the 160px container */
    height: 52px;
    font-size: 10px;
    font-weight: bold;
    touch-action: manipulation;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding: 0 4px;
    cursor: pointer;
}

.mobile-btn.primary { 
    border-color: #ffcc00; 
    background: rgba(255, 204, 0, 0.15);
    font-size: 10px;
}

/* Joystick styling */
.joystick {
    position: relative;
    width: 60px;
    height: 60px;
}

.joystick-base {
    position: absolute;
    left: 0; top: 0; right: 0; bottom: 0;
    margin: auto;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: radial-gradient(circle at center, rgba(255,255,255,0.12), rgba(255,255,255,0.05));
    border: 2px solid rgba(255,255,255,0.4);
}

.joystick-knob {
    position: absolute;
    left: 50%; top: 50%;
    transform: translate(-50%, -50%);
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: rgba(255,255,255,0.2);
    border: 2px solid rgba(255,255,255,0.8);
    box-shadow: 0 4px 12px rgba(0,0,0,0.4);
    touch-action: none;
}

@media (hover: none) and (pointer: coarse) {
    /* Make overlays and controls friendlier on mobile */
    .start-content { max-width: 90vw; }
    .start-content input {
        font-size: 18px;
        padding: 12px 16px;
        border: 2px solid rgba(255,255,255,0.6);
        border-radius: 8px;
        background: rgba(255,255,255,0.1);
        color: #fff;
        width: 100%;
        box-sizing: border-box;
        -webkit-appearance: none;
        -webkit-border-radius: 8px;
        -webkit-user-select: text;
        -webkit-touch-callout: default;
        -webkit-tap-highlight-color: transparent;
    }
    .start-content input:focus {
        outline: none;
        border-color: #ffcc00;
        background: rgba(255,255,255,0.15);
        -webkit-appearance: none;
    }
    .start-content input::placeholder {
        color: rgba(255,255,255,0.6);
    }
}
