/*
 * School Escape - Action Arcade Game
 * Copyright (c) 2025 Ilja Livenson and Mark Livenson
 * All rights reserved.
 */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    overflow: hidden;
}

#game-container {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    width: 100%;
    height: 100vh;
    max-width: 100vw;
    overflow: hidden;
}

#game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    max-width: 800px;
    padding: 10px 20px;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 10px;
    color: white;
}

#score-display {
    font-size: 24px;
    font-weight: bold;
    color: #ffd700;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}

#combo-display {
    font-size: 18px;
    color: #ff6b6b;
    transition: transform 0.1s;
}

#combo-display.pulse {
    transform: scale(1.3);
    color: #ff0000;
}

#lives-display {
    display: flex;
    gap: 5px;
}

.life-icon {
    width: 25px;
    height: 25px;
    background: #ff6b6b;
    border-radius: 50%;
    border: 2px solid white;
}

.life-icon.lost {
    background: #333;
    opacity: 0.5;
}

#powerup-display {
    display: flex;
    gap: 10px;
}

.powerup-slot {
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
}

.powerup-slot.active {
    border-color: #ffd700;
    box-shadow: 0 0 10px #ffd700;
    animation: glow 0.5s ease-in-out infinite alternate;
}

@keyframes glow {
    from { box-shadow: 0 0 10px #ffd700; }
    to { box-shadow: 0 0 20px #ffd700; }
}

#game-canvas {
    border: 4px solid #4a4a6a;
    border-radius: 10px;
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.5), inset 0 0 50px rgba(0, 0, 0, 0.3);
    background: #2a2a4a;
    /* Responsive scaling - CSS handles display size, JS handles internal resolution */
    max-width: calc(100vw - 20px);
    max-height: calc(100vh - 140px);
    width: auto;
    height: auto;
    object-fit: contain;
}

#game-footer {
    display: flex;
    justify-content: center;
    gap: 20px;
    color: white;
    font-size: 14px;
    opacity: 0.8;
}

.key-hint {
    display: flex;
    align-items: center;
    gap: 5px;
}

.key {
    background: rgba(255, 255, 255, 0.2);
    padding: 5px 10px;
    border-radius: 5px;
    font-weight: bold;
}

/* Menu Screens */
.menu-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 100;
    color: white;
    overflow-y: auto;
    padding: 20px 10px;
    box-sizing: border-box;
}

.menu-screen.hidden {
    display: none;
}

#main-menu h1 {
    font-size: 48px;
    color: #ffd700;
    text-shadow: 3px 3px 6px rgba(0, 0, 0, 0.8);
    margin-bottom: 10px;
}

#main-menu h2 {
    font-size: 24px;
    color: #ff6b6b;
    margin-bottom: 40px;
}

.menu-button {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    padding: 15px 40px;
    font-size: 20px;
    color: white;
    border-radius: 30px;
    cursor: pointer;
    margin: 10px;
    transition: transform 0.2s, box-shadow 0.2s;
    font-weight: bold;
}

.menu-button:hover {
    transform: scale(1.1);
    box-shadow: 0 0 20px rgba(102, 126, 234, 0.5);
}

.sound-btn {
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.3);
    padding: 8px 16px;
    font-size: 14px;
    color: white;
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.2s;
}

.sound-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.5);
}

.settings-panel {
    background: rgba(255, 255, 255, 0.1);
    padding: 20px;
    border-radius: 15px;
    margin: 20px 0;
}

.setting-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 15px 0;
    min-width: 300px;
}

.setting-row label {
    font-size: 16px;
}

.setting-row select, .setting-row input {
    padding: 8px 15px;
    border-radius: 5px;
    border: none;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    font-size: 14px;
}

.setting-row input[type="range"] {
    width: 150px;
}

/* Game Over / Win Screen */
#game-over-screen h2 {
    font-size: 48px;
    margin-bottom: 20px;
}

#game-over-screen.win h2 {
    color: #4ade80;
}

#game-over-screen.lose h2 {
    color: #ff6b6b;
}

#final-score {
    font-size: 36px;
    color: #ffd700;
    margin-bottom: 30px;
}

/* Level indicator */
#level-display {
    font-size: 18px;
    color: #4ade80;
}

/* Items remaining */
#items-display {
    font-size: 16px;
    color: #60a5fa;
}

/* Pause Screen */
#pause-screen {
    background: rgba(0, 0, 0, 0.8);
}

#pause-screen h2 {
    font-size: 48px;
    color: #ffd700;
    margin-bottom: 30px;
}

/* How to Play screen - ensure scrollable on mobile */
#how-to-play-screen {
    justify-content: flex-start;
    padding-top: 40px;
    padding-bottom: 40px;
}

#how-to-play-screen .settings-panel {
    max-height: none;
    overflow: visible;
    margin-bottom: 20px;
}

#how-to-play-screen .menu-button {
    flex-shrink: 0;
    margin-top: 10px;
    margin-bottom: 20px;
}

/* Message popup - non-intrusive notification at top */
#message-popup {
    position: absolute;
    top: 80px;
    left: 50%;
    transform: translateX(-50%) translateY(-10px);
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 10px 24px;
    border-radius: 20px;
    font-size: 18px;
    font-weight: bold;
    z-index: 50;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s, transform 0.3s;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
    max-width: 80%;
    text-align: center;
}

#message-popup.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* Minimap */
#minimap {
    position: absolute;
    bottom: 60px;
    right: 10px;
    border: 2px solid rgba(255, 255, 255, 0.5);
    border-radius: 5px;
    opacity: 0.8;
}

/* Collapsible settings */
.collapsible-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    padding: 10px 15px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 10px;
    margin-bottom: 0;
    transition: background 0.2s;
}

.collapsible-header:hover {
    background: rgba(255, 255, 255, 0.1);
}

.collapsible-header .header-title {
    font-size: 14px;
    color: #aaa;
}

.collapsible-header .toggle-icon {
    font-size: 12px;
    transition: transform 0.3s;
    color: #aaa;
}

.collapsible-header.expanded .toggle-icon {
    transform: rotate(180deg);
}

.collapsible-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease-out, padding 0.3s ease-out;
    padding: 0 15px;
}

.collapsible-content.expanded {
    max-height: 350px;
    padding: 15px;
}

/* Help Button */
.help-button {
    position: fixed;
    top: 20px;
    right: 20px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
    border: 2px solid #818cf8;
    color: white;
    font-size: 22px;
    font-weight: bold;
    cursor: pointer;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, box-shadow 0.2s;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.4);
}

.help-button:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.6);
}

/* Multiplayer Styles */
.room-code-display {
    font-size: 32px;
    font-family: 'Courier New', monospace;
    letter-spacing: 8px;
    background: rgba(0, 0, 0, 0.5);
    padding: 15px 30px;
    border-radius: 10px;
    color: #ffd700;
    margin: 15px 0;
    user-select: all;
}

.room-code-input {
    font-size: 24px;
    font-family: 'Courier New', monospace;
    letter-spacing: 4px;
    background: rgba(0, 0, 0, 0.5);
    padding: 15px 20px;
    border-radius: 10px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    color: #fff;
    text-align: center;
    width: 200px;
    text-transform: uppercase;
}

.room-code-input:focus {
    outline: none;
    border-color: #4ade80;
}

.player-list {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 10px;
    padding: 15px;
    margin: 15px 0;
    min-width: 300px;
    max-height: 200px;
    overflow-y: auto;
}

.player-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    margin-bottom: 8px;
}

.player-item:last-child {
    margin-bottom: 0;
}

.player-color {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 2px solid white;
}

.player-name {
    flex: 1;
    color: #fff;
    font-size: 16px;
}

.player-host-badge {
    background: #ffd700;
    color: #000;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: bold;
}

.player-you-badge {
    background: #4ade80;
    color: #000;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 12px;
}

.multiplayer-status {
    color: #aaa;
    font-size: 14px;
    margin: 10px 0;
}

.multiplayer-status.connected {
    color: #4ade80;
}

.multiplayer-status.connecting {
    color: #fbbf24;
}

.multiplayer-status.error {
    color: #ef4444;
}

#multiplayer-players-hud {
    position: absolute;
    top: 70px;
    right: 10px;
    background: rgba(0, 0, 0, 0.7);
    border-radius: 8px;
    padding: 10px;
    display: none;
    z-index: 100;
}

.mp-player-hud-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 0;
    font-size: 14px;
    color: #fff;
}

.mp-player-hud-color {
    width: 12px;
    height: 12px;
    border-radius: 50%;
}

.mp-player-hud-lives {
    color: #ff6b6b;
}

/* ============================================
   MOBILE CONTROLS
   ============================================ */

.mobile-controls {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 90;
}

.mobile-controls.hidden {
    display: none;
}

/* Virtual Joystick */
.joystick-container {
    position: absolute;
    bottom: 80px;
    left: 30px;
    pointer-events: auto;
    touch-action: none;
}

.joystick-base {
    width: 120px;
    height: 120px;
    background: rgba(255, 255, 255, 0.15);
    border: 3px solid rgba(255, 255, 255, 0.4);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.3);
}

.joystick-knob {
    width: 50px;
    height: 50px;
    background: linear-gradient(145deg, #667eea, #764ba2);
    border: 3px solid rgba(255, 255, 255, 0.6);
    border-radius: 50%;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.4);
    transition: transform 0.05s ease-out;
    position: absolute;
}

.joystick-knob.active {
    background: linear-gradient(145deg, #8b9cf5, #9165c7);
    box-shadow: 0 4px 20px rgba(102, 126, 234, 0.6);
}

/* Action Buttons */
.action-buttons {
    position: absolute;
    bottom: 80px;
    right: 30px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    pointer-events: auto;
}

.mobile-action-btn {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    border: 3px solid rgba(255, 255, 255, 0.5);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    touch-action: manipulation;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
    transition: transform 0.1s, box-shadow 0.1s;
}

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

.mobile-action-btn .btn-icon {
    font-size: 28px;
    line-height: 1;
}

.mobile-action-btn .btn-label {
    font-size: 10px;
    font-weight: bold;
    color: white;
    margin-top: 2px;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
}

/* Dash Button */
.dash-btn {
    background: linear-gradient(145deg, #3b82f6, #2563eb);
}

.dash-btn:active {
    background: linear-gradient(145deg, #60a5fa, #3b82f6);
    box-shadow: 0 0 25px rgba(59, 130, 246, 0.7);
}

.dash-btn.cooldown {
    background: linear-gradient(145deg, #6b7280, #4b5563);
    opacity: 0.6;
}

/* Power-up Button */
.powerup-btn {
    background: linear-gradient(145deg, #f59e0b, #d97706);
}

.powerup-btn:active {
    background: linear-gradient(145deg, #fbbf24, #f59e0b);
    box-shadow: 0 0 25px rgba(245, 158, 11, 0.7);
}

.powerup-btn.has-powerup {
    animation: powerup-glow 1s ease-in-out infinite alternate;
}

.powerup-btn.empty {
    background: linear-gradient(145deg, #6b7280, #4b5563);
    opacity: 0.5;
}

@keyframes powerup-glow {
    from { box-shadow: 0 4px 20px rgba(245, 158, 11, 0.4); }
    to { box-shadow: 0 4px 30px rgba(245, 158, 11, 0.8); }
}

/* Pause Button */
.mobile-pause-btn {
    position: absolute;
    top: 15px;
    right: 70px;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.6);
    border: 2px solid rgba(255, 255, 255, 0.4);
    font-size: 20px;
    cursor: pointer;
    pointer-events: auto;
    touch-action: manipulation;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
    transition: transform 0.1s;
}

.mobile-pause-btn:active {
    transform: scale(0.9);
    background: rgba(0, 0, 0, 0.8);
}

/* Mobile-specific adjustments */
@media (max-width: 900px) and (pointer: coarse) {
    #game-container {
        gap: 5px;
        padding: 5px;
    }

    #game-canvas {
        max-height: calc(100vh - 80px);
        max-width: calc(100vw - 10px);
        flex: 1;
        min-height: 0;
    }

    #message-popup {
        top: 60px;
        font-size: 14px;
        padding: 8px 16px;
    }

    #game-footer {
        display: none;
    }

    #game-header {
        padding: 8px 15px;
        font-size: 14px;
        max-width: 100%;
        flex-shrink: 0;
    }

    #score-display {
        font-size: 18px;
    }

    #powerup-display {
        display: none;
    }

    .powerup-slot {
        width: 32px;
        height: 32px;
        font-size: 16px;
    }

    #minimap {
        /* Position above mobile action buttons */
        bottom: auto;
        top: 70px;
        right: 10px;
        opacity: 0.7;
        transform: scale(0.7);
        transform-origin: top right;
    }
}

/* Landscape mobile adjustments */
@media (max-height: 500px) and (pointer: coarse) {
    .joystick-container {
        bottom: 20px;
        left: 20px;
    }

    .joystick-base {
        width: 100px;
        height: 100px;
    }

    .joystick-knob {
        width: 40px;
        height: 40px;
    }

    .action-buttons {
        bottom: 20px;
        right: 20px;
        flex-direction: row;
    }

    .mobile-action-btn {
        width: 65px;
        height: 65px;
    }

    .mobile-action-btn .btn-icon {
        font-size: 22px;
    }

    .mobile-action-btn .btn-label {
        font-size: 8px;
    }

    .mobile-pause-btn {
        top: 10px;
        right: 60px;
        width: 40px;
        height: 40px;
        font-size: 16px;
    }

    #minimap {
        /* Position at top-right in landscape to avoid controls */
        bottom: auto;
        top: 55px;
        right: 10px;
        transform: scale(0.5);
        transform-origin: top right;
    }
}
