/* =========================================
   GLOBAL RESET & LAYOUT
   ========================================= */
body,
html {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    /* Prevent scrolling */
    background-color: #87CEEB;
    /* Sky Blue */
    background-image: url('../assets/img/background.jpg');
    background-size: cover;
    background-position: bottom center;
    background-repeat: no-repeat;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    touch-action: none;
    /* Disable default touch actions for game interaction */
}

/* =========================================
   CANVAS CONTAINER
   ========================================= */
#canvas-container {
    position: relative;
    width: 100%;
    height: 100%;
}

canvas {
    display: block;
    /* Removes bottom spacing inherent to inline elements */
}

/* =========================================
   UI OVERLAYS
   ========================================= */

/* Main Game Title */
#main-title {
    position: absolute;
    top: 20px;
    left: 0;
    width: 100%;
    text-align: center;
    z-index: 5;
    font-size: 36px;
    font-weight: 900;
    text-transform: uppercase;
    color: #ff4757;
    text-shadow: 3px 3px 0px #fff, -1px -1px 0 #000;
    pointer-events: none;
    /* Allows clicking through text */
    margin: 0;
    letter-spacing: 2px;
}

/* Online Users Counter */
/* Online Users Counter (Styled like Music Toggle) */
#online-counter {
    position: absolute;
    top: 20px;
    left: 20px;
    /* Moved to left side */
    background: rgba(255, 255, 255, 0.8);
    border: 3px solid #000;
    border-radius: 30px;
    /* Pill shape for wider content */
    height: 40px;
    padding: 0 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-size: 16px;
    font-weight: 800;
    color: #333;
    z-index: 50;
    box-shadow: 4px 4px 0px rgba(0, 0, 0, 0.2);
    user-select: none;
    pointer-events: auto;
}

/* Compact Music Toggle */
#music-toggle {
    position: absolute;
    top: 20px;
    right: 20px;
    background: rgba(255, 255, 255, 0.8);
    border: 3px solid #000;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    cursor: pointer;
    z-index: 50;
    /* Above everything */
    box-shadow: 4px 4px 0px rgba(0, 0, 0, 0.2);
    transition: transform 0.1s;
    user-select: none;
}

#music-toggle:active {
    transform: scale(0.9);
}

/* The Green Ground Bar */
.ground {
    display: none;
    position: absolute;
    bottom: 0;
    width: 100%;
    height: 100px;
    background-color: #4CAF50;
    border-top: 4px solid #000;
    z-index: 0;
    pointer-events: none;
}

/* =========================================
   SETTINGS PANEL (CONTROLS)
   ========================================= */
#controls {
    display: none;
    /* Hidden by default until 'settings' is typed */
    position: absolute;
    top: 20px;
    right: 20px;
    width: 300px;
    background: rgba(255, 255, 255, 0.95);
    border: 3px solid #000;
    border-radius: 12px;
    box-shadow: 8px 8px 0px rgba(0, 0, 0, 0.2);
    z-index: 10;
    overflow: hidden;
    flex-direction: column;
    transition: height 0.3s ease, width 0.3s ease;
}

#controls.visible {
    display: flex;
}

/* Draggable Header */
#controls-header {
    padding: 10px 15px;
    background: #eee;
    border-bottom: 2px solid #000;
    cursor: move;
    display: flex;
    justify-content: space-between;
    align-items: center;
    user-select: none;
}

#controls-title {
    font-weight: 800;
    text-transform: uppercase;
    font-size: 14px;
}

/* Minimize Button */
#minimize-btn {
    background: #ccc;
    border: 2px solid #000;
    width: 24px;
    height: 24px;
    line-height: 20px;
    text-align: center;
    font-weight: bold;
    border-radius: 4px;
    cursor: pointer;
}

#minimize-btn:hover {
    background: #bbb;
}

/* Scrollable Content Area */
#controls-content {
    padding: 15px 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    transition: opacity 0.2s;
    max-height: 80vh;
    overflow-y: auto;
}

/* Minimized State Styles */
#controls.minimized #controls-content {
    display: none;
}

#controls.minimized {
    height: auto;
    width: 180px;
}

/* Control Widget Groups */
.control-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.label-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

label {
    font-weight: 800;
    text-transform: uppercase;
    font-size: 11px;
    color: #333;
}

/* Value Display Box (little number next to slider) */
.val-display {
    font-family: monospace;
    font-size: 11px;
    background: #eee;
    padding: 2px 5px;
    border-radius: 4px;
    border: 1px solid #ccc;
    min-width: 20px;
    text-align: center;
}

/* Custom Range Sliders */
input[type="range"] {
    width: 100%;
    height: 8px;
    -webkit-appearance: none;
    background: #ddd;
    border: 2px solid #000;
    border-radius: 4px;
    outline: none;
    margin-top: 2px;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    background: #ffcc00;
    border: 2px solid #000;
    border-radius: 50%;
    cursor: pointer;
}

/* Action Buttons */
.btn-row {
    display: flex;
    gap: 10px;
    margin-top: 5px;
}

button.action-btn {
    background: #ff4757;
    color: white;
    border: 3px solid #000;
    padding: 10px;
    font-weight: 800;
    font-size: 12px;
    cursor: pointer;
    border-radius: 8px;
    text-transform: uppercase;
    transition: transform 0.1s;
    flex: 1;
}

button.secondary-btn {
    background: #3498db;
}

button.music-btn {
    background: #9b59b6;
}

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

#shoot-btn.cooldown {
    background: #ccc;
    cursor: not-allowed;
    position: relative;
    overflow: hidden;
}

/* Cooldown Progress Bar Overlay */
#shoot-btn.cooldown::after {
    content: "";
    position: absolute;
    bottom: 0;
    left: 0;
    height: 4px;
    /* Thin bar at bottom */
    background: #ff4757;
    width: 0%;
    animation: cooldownBar var(--cooldown-time, 2000ms) linear forwards;
}

@keyframes cooldownBar {
    from {
        width: 100%;
    }

    to {
        width: 0%;
    }
}

.instruction {
    font-size: 10px;
    color: #666;
    text-align: center;
    font-weight: 600;
    margin-top: 5px;
    min-height: 15px;
}

/* =========================================
   WORD SHOOTER (BOTTOM INPUT)
   ========================================= */
#word-shooter {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 8px;
    z-index: 20;
    background: rgba(255, 255, 255, 0.9);
    padding: 8px;
    border-radius: 30px;
    border: 3px solid #000;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
}

#word-input {
    border: 2px solid #333;
    border-radius: 20px;
    padding: 8px 15px;
    font-family: inherit;
    font-weight: bold;
    outline: none;
    width: 200px;
}

#shoot-btn {
    padding: 10px 20px;
    background: #ff4757;
    color: white;
    border: none;
    border-radius: 20px;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.2);
    transition: transform 0.2s, background 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

#shoot-btn:active {
    transform: scale(0.95);
}

#shoot-btn:hover {
    transform: scale(1.05);
    background: #ff6b81;
}

@keyframes input-flash {
    0% {
        background: white;
        transform: scale(1);
    }

    50% {
        background: #dff9fb;
        transform: scale(1.05);
    }

    100% {
        background: white;
        transform: scale(1);
    }
}

.input-fired {
    animation: input-flash 0.3s ease-out;
}

.wobble {
    animation: wobble 0.4s ease-in-out;
}

@keyframes wobble {

    0%,
    100% {
        transform: translateX(0);
    }

    25% {
        transform: translateX(-5px) rotate(-5deg);
    }

    75% {
        transform: translateX(5px) rotate(5deg);
    }
}

@keyframes idle-pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(255, 71, 87, 0.7);
        transform: scale(1);
    }

    70% {
        box-shadow: 0 0 0 10px rgba(255, 71, 87, 0);
        transform: scale(1.05);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(255, 71, 87, 0);
        transform: scale(1);
    }
}

.input-idle {
    animation: idle-pulse 2s infinite;
    border-color: #ff4757 !important;
}

/* =========================================
   MEDIA QUERIES (MOBILE)
   ========================================= */
@media (max-width: 600px) {
    #controls {
        width: calc(100% - 40px);
        top: auto;
        bottom: 80px;
        /* Above the word shooter */
        right: 20px;
    }

    #word-shooter {
        bottom: 10px;
        width: 90%;
        justify-content: center;
    }

    #word-input {
        flex: 1;
    }

    #main-title {
        font-size: 24px;
        top: 10px;
    }

    /* Mobile: Music Toggle Hidden */
    #music-toggle {
        display: none;
    }

    /* Mobile: Online Counter Centered below title */
    #online-counter {
        top: 55px;
        /* Directly below title */
        left: 50%;
        transform: translateX(-50%);
        right: auto;
        min-width: 200px;
        /* Ensure enough space for text */
        white-space: nowrap;
    }
}

/* Stats Modal */
#stats-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: center;
}

.modal-content {
    background: white;
    padding: 20px;
    border-radius: 10px;
    width: 300px;
    position: relative;
    border: 4px solid #000;
    box-shadow: 10px 10px 0 rgba(0, 0, 0, 0.2);
}

.close-btn {
    position: absolute;
    top: 5px;
    right: 10px;
    font-size: 24px;
    cursor: pointer;
    font-weight: bold;
}

#stats-list {
    list-style: none;
    padding: 0;
    margin-top: 10px;
}

#stats-list li {
    background: #eee;
    margin: 5px 0;
    padding: 8px;
    border-radius: 5px;
    font-weight: bold;
    display: flex;
    justify-content: space-between;
}

#stats-list li span {
    color: #ff4757;
}

/* Live Chat Overlay */
/* Live Chat Overlay */
#live-chat {
    position: absolute;
    bottom: 100px;
    /* Clear the input bar */
    left: 0;
    width: 100%;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    align-items: center;
    pointer-events: none;
    height: 200px;
    overflow: visible;
    z-index: 60;
    /* Higher than UI controls */
}

.chat-msg {
    font-weight: 900;
    font-size: 20px;
    color: #fff;
    text-shadow: 2px 2px 0 #000, -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000, 1px 1px 0 #000;
    margin-top: 2px;
    /* Animation: Enter (delay/fade-in) -> Wait -> Exit (fade-out) */
    animation: chatLife 4s ease-in-out forwards;
    opacity: 0;
    /* Start invisible */
}

@keyframes chatLife {
    0% {
        opacity: 0;
        transform: translateY(20px) scale(0.9);
    }

    10% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }

    85% {
        opacity: 1;
        transform: translateY(0);
    }

    100% {
        opacity: 0;
        transform: translateY(-20px);
    }
}