:root {
    --dark-blue: #0a192f;
    --neon-blue: #00d1ff;
    --neon-red: #ff2a6d;
    --neon-purple: #bd00ff;
    --light-gray: #ccd6f6;
    --dark-gray: #1e2a47;
    --metal-gradient: linear-gradient(145deg, #2a3a5c, #0e1a2f);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Noto Sans', 'Orbitron', sans-serif;
    background-color: var(--dark-blue);
    color: var(--light-gray);
    min-height: 100vh;
    padding: 0.5rem;
    /* Changed: Allow scrolling */
    overflow-y: auto;
    touch-action: manipulation;
}

.container {
    width: 100%;
    /* Changed: Removed fixed height, use min-height */
    min-height: 100vh;
    max-height: -webkit-fill-available;
    display: flex;
    flex-direction: column;
    /* Changed: Ensure proper spacing */
    gap: 0.5rem;
}

.game-title {
    font-family: 'Orbitron', sans-serif;
    color: var(--light-gray);
    text-align: center;
    margin: 0.5rem 0;
    font-size: 1.6rem;
    letter-spacing: 2px;
    text-transform: uppercase;
    text-shadow: 0 0 10px rgba(0, 209, 255, 0.5);
}

.game-title span {
    color: var(--neon-red);
    margin: 0 0.3rem;
}

.game-title .version {
    color: var(--neon-blue);
    font-size: 0.9rem;
    vertical-align: super;
    margin-left: 0.5rem;
}

/* Tab Navigation */
.tab-navigation {
    display: flex;
    justify-content: space-between;
    background: var(--metal-gradient);
    border-radius: 8px 8px 0 0;
    padding: 0.5rem 0.5rem 0;
    margin-bottom: 0;
    border-bottom: 2px solid var(--neon-purple);
}

.tab-button {
    background: rgba(30, 42, 71, 0.7);
    color: var(--light-gray);
    border: none;
    padding: 0.5rem;
    border-radius: 5px 5px 0 0;
    font-family: 'Orbitron', sans-serif;
    font-size: 0.9rem;
    flex: 1;
    text-transform: uppercase;
    border-bottom: 2px solid transparent;
    transition: all 0.3s ease;
}

.tab-button.active {
    background: rgba(189, 0, 255, 0.1);
    color: var(--neon-purple);
    border-bottom: 2px solid var(--neon-purple);
    box-shadow: 0 -5px 15px rgba(189, 0, 255, 0.2);
}

/* Tab Content */
.tab-content-container {
    flex: 1;
    position: relative;
    /* Changed: Allow overflow */
    overflow: visible;
    background: var(--metal-gradient);
    border-radius: 0 0 8px 8px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    margin-bottom: 0.5rem;
    /* Changed: Set minimum height */
    min-height: 300px;
}

.tab-content {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    padding: 0.8rem;
    display: none;
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
}

.tab-content.active {
    display: flex;
}

/* Game Area */
.game-area {
    background: rgba(30, 42, 71, 0.7);
    border-radius: 8px;
    box-shadow: inset 0 0 15px rgba(0, 209, 255, 0.2);
    padding: 0.5rem;
    border: 1px solid rgba(0, 209, 255, 0.1);
    position: relative;
    flex: 1;
    overflow: hidden;
}

#battlefield {
    width: 100%;
    height: 100%;
    display: block;
}

/* Panel Title */
.panel-title {
    font-family: 'Orbitron', sans-serif;
    font-size: 1rem;
    margin-bottom: 0.5rem;
    letter-spacing: 1px;
    text-transform: uppercase;
}

.blue-text {
    color: var(--neon-blue);
    text-shadow: 0 0 8px rgba(0, 209, 255, 0.5);
}

.red-text {
    color: var(--neon-red);
    text-shadow: 0 0 8px rgba(255, 42, 109, 0.5);
}

/* Program Area and Block Panel */
.program-area, .block-panel {
    background: rgba(30, 42, 71, 0.7);
    border-radius: 8px;
    padding: 0.8rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    border: 1px solid rgba(0, 209, 255, 0.2);
    box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.3);
    overflow-y: auto;
    flex: 1;
    -webkit-overflow-scrolling: touch;
}

.block-panel {
    padding-right: 20px;
    overflow-y: scroll !important;
}

.block-panel::-webkit-scrollbar {
    width: 12px;
    background-color: rgba(30, 42, 71, 0.5);
    border-radius: 6px;
    display: block;
}

.block-panel::-webkit-scrollbar-thumb {
    background-color: var(--dark-blue);
    border-radius: 6px;
    border: 2px solid rgba(0, 209, 255, 0.3);
    box-shadow: 0 0 5px rgba(0, 209, 255, 0.3);
}

.block-panel::-webkit-scrollbar-track {
    background-color: rgba(30, 42, 71, 0.3);
    border-radius: 6px;
}

.block-panel {
    scrollbar-width: auto;
    scrollbar-color: var(--dark-blue) rgba(30, 42, 71, 0.5);
}

/* Block */
.block {
    background: rgba(0, 209, 255, 0.1);
    color: var(--light-gray);
    padding: 0.8rem 0.6rem;
    border-radius: 6px;
    user-select: none;
    font-size: 0.9rem;
    border: 1px solid rgba(0, 209, 255, 0.3);
    transition: all 0.2s ease;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    position: relative;
    display: flex;
    align-items: center;
    touch-action: none; /* Optimize touch operations */
}

/* Mobile block selection state */
.block.selected {
    background: rgba(0, 209, 255, 0.3);
    box-shadow: 0 0 10px rgba(0, 209, 255, 0.5);
    transform: scale(1.02);
}

/* Team-specific block styles */
#program-area-blue .block {
    background: rgba(0, 209, 255, 0.15);
    border: 1px solid rgba(0, 209, 255, 0.4);
}

#program-area-red .block {
    background: rgba(255, 42, 109, 0.15);
    border: 1px solid rgba(255, 42, 109, 0.4);
}

/* Block add/remove buttons */
.block .block-actions {
    position: absolute;
    right: 0.5rem;
    display: flex;
    gap: 0.5rem;
}

.block .add-button {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: rgba(0, 209, 255, 0.2);
    color: var(--light-gray);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.2rem;
    font-weight: bold;
    border: none;
}

.block .remove-button {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: rgba(255, 42, 109, 0.2);
    color: var(--light-gray);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1rem;
    border: none;
}

/* Control Panel */
.control-panel {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    /* Changed: Ensure control panel always visible */
    position: relative;
    z-index: 10;
}

/* Execute Button */
.neon-button {
    background: var(--metal-gradient);
    color: var(--light-gray);
    border: none;
    padding: 1rem;
    font-family: 'Orbitron', sans-serif;
    font-size: 1.1rem;
    border-radius: 8px;
    text-transform: uppercase;
    letter-spacing: 1px;
    position: relative;
    overflow: hidden;
    z-index: 1;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.4),
                inset 0 0 10px rgba(0, 209, 255, 0.2);
    border: 1px solid rgba(0, 209, 255, 0.3);
    transition: all 0.3s ease;
}

.neon-button:active {
    transform: translateY(2px);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.4);
}

/* Turn Indicator */
.turn-indicator {
    font-family: 'Orbitron', sans-serif;
    text-align: center;
    padding: 0.8rem;
    border-radius: 8px;
    background: rgba(30, 42, 71, 0.7);
    border: 1px solid rgba(0, 209, 255, 0.3);
    text-transform: uppercase;
    letter-spacing: 1px;
    font-size: 1rem;
    transition: all 0.3s ease;
}

.turn-indicator.blue-turn {
    color: var(--neon-blue);
    text-shadow: 0 0 8px rgba(0, 209, 255, 0.5);
    box-shadow: 0 0 15px rgba(0, 209, 255, 0.2);
}

.turn-indicator.red-turn {
    color: var(--neon-red);
    text-shadow: 0 0 8px rgba(255, 42, 109, 0.5);
    box-shadow: 0 0 15px rgba(255, 42, 109, 0.2);
}

/* Sound Controls */
.sound-controls-container {
    background: var(--metal-gradient);
    border-radius: 8px;
    padding: 0.5rem;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(189, 0, 255, 0.2);
}

.sound-controls-container summary {
    font-family: 'Orbitron', sans-serif;
    color: var(--light-gray);
    padding: 0.3rem;
    cursor: pointer;
    user-select: none;
    list-style: none;
    display: flex;
    justify-content: center;
    align-items: center;
}

.sound-controls-container summary::after {
    content: "▼";
    margin-left: 0.5rem;
    font-size: 0.7rem;
    transition: transform 0.3s ease;
}

.sound-controls-container[open] summary::after {
    transform: rotate(180deg);
}

.sound-controls {
    margin-top: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.sound-button {
    background: var(--dark-gray);
    color: var(--light-gray);
    border: 1px solid rgba(0, 209, 255, 0.3);
    padding: 0.5rem;
    border-radius: 4px;
    font-family: 'Orbitron', sans-serif;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.sound-button.disabled {
    opacity: 0.5;
    color: rgba(204, 214, 246, 0.5);
    border-color: rgba(0, 209, 255, 0.1);
}

.volume-control {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.volume-control span {
    font-size: 0.8rem;
}

input[type="range"] {
    flex: 1;
    -webkit-appearance: none;
    height: 6px;
    background: rgba(0, 209, 255, 0.2);
    border-radius: 3px;
    outline: none;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 15px;
    height: 15px;
    background: var(--neon-blue);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 0 5px var(--neon-blue);
}

/* Effects */
.effect {
    position: absolute;
    width: 20px;
    height: 20px;
    background: var(--neon-blue);
    border-radius: 50%;
    animation: explode 0.5s forwards;
    box-shadow: 0 0 10px var(--neon-blue);
    z-index: 100;
}

@keyframes explode {
    0% { transform: scale(1); opacity: 1; }
    100% { transform: scale(3); opacity: 0; }
}

/* Menu */
#menuToggle {
    position: fixed;
    top: 15px;
    right: 15px;
    width: 25px;
    height: 20px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    cursor: pointer;
    z-index: 1001;
}

#menuToggle .bar {
    height: 3px;
    background: var(--neon-blue);
    border-radius: 2px;
}

#menuPanel {
    position: fixed;
    top: 50px;
    right: 15px;
    background: var(--metal-gradient);
    border: 1px solid rgba(0, 209, 255, 0.4);
    border-radius: 8px;
    padding: 0.8rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    z-index: 1000;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.6);
}

#menuPanel.hidden {
    display: none;
}

#menuPanel button {
    background: var(--neon-purple);
    color: white;
    border: none;
    padding: 0.7rem 0.8rem;
    font-family: 'Orbitron', sans-serif;
    border-radius: 5px;
    cursor: pointer;
    text-transform: uppercase;
    font-size: 0.8rem;
    white-space: nowrap;
}

#menuPanel button:hover,
#menuPanel button:active {
    background: var(--neon-red);
}

/* Skill Effects */
.skill-effect {
    animation: skillPulse 0.7s forwards !important;
}

@keyframes skillPulse {
    0% { transform: scale(1); opacity: 1; }
    50% { transform: scale(2); opacity: 0.8; }
    100% { transform: scale(4); opacity: 0; }
}

/* Missile */
.missile {
    position: absolute;
    width: 10px;
    height: 10px;
    background: var(--neon-blue);
    border-radius: 50%;
    z-index: 999;
}

/* Modal Window */
.victory-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.victory-content {
    background: var(--metal-gradient);
    padding: 1.5rem;
    border-radius: 12px;
    text-align: center;
    box-shadow: 0 0 30px rgba(0, 209, 255, 0.5),
                inset 0 0 15px rgba(0, 209, 255, 0.3);
    border: 1px solid rgba(0, 209, 255, 0.5);
    width: 85%;
    max-width: 400px;
    transform: scale(0.8);
    transition: transform 0.3s ease;
}

.victory-title {
    font-family: 'Orbitron', sans-serif;
    font-size: 2rem;
    margin-bottom: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 3px;
}

.round-number {
    font-family: 'Orbitron', sans-serif;
    font-size: 1.2rem;
    margin-bottom: 1rem;
    color: var(--neon-purple);
    text-shadow: 0 0 8px rgba(189, 0, 255, 0.8);
    letter-spacing: 2px;
}

.winner-blue {
    color: var(--neon-blue);
    text-shadow: 0 0 10px rgba(0, 209, 255, 0.8);
}

.winner-red {
    color: var(--neon-red);
    text-shadow: 0 0 10px rgba(255, 42, 109, 0.8);
}

.winner-draw {
    color: var(--neon-purple);
    text-shadow: 0 0 10px rgba(189, 0, 255, 0.8);
}

.victory-message {
    font-size: 1.1rem;
    margin-bottom: 1.5rem;
    color: var(--light-gray);
}

.close-button {
    background: var(--metal-gradient);
    color: var(--light-gray);
    border: none;
    padding: 0.8rem 2rem;
    font-family: 'Orbitron', sans-serif;
    font-size: 1rem;
    border-radius: 8px;
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 1px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.4),
                inset 0 0 10px rgba(0, 209, 255, 0.2);
    border: 1px solid rgba(0, 209, 255, 0.3);
    transition: all 0.3s ease;
}

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

.show-modal {
    opacity: 1;
}

.show-modal .victory-content {
    transform: scale(1);
}

/* iOS height support */
@supports (-webkit-touch-callout: none) {
    .container {
        height: -webkit-fill-available;
    }
}

/* Portrait orientation optimization - adjust to display all content */
@media (orientation: portrait) {
    /* Set container height to auto to expand with content */
    .container {
        height: auto;
        min-height: 100vh;
    }
    
    /* Adjust tab content container height to prevent content cutoff */
    .tab-content-container {
        height: 50vh;  /* Half of screen height */
        min-height: 300px;
        max-height: 60vh; /* Limit maximum height */
        margin-bottom: 1rem; /* Ensure spacing with bottom controls */
    }
    
    /* Ensure battlefield maintains height */
    #battlefield {
        height: 100%;
        width: 100%;
        object-fit: contain;
    }
    
    /* Ensure control panel is always visible */
    .control-panel {
        position: relative;
        bottom: 0;
        left: 0;
        width: 100%;
        background: var(--dark-blue);
        padding: 0.5rem 0;
        z-index: 100;
    }
    
    /* Allow overall scrolling to access all elements */
    body {
        overflow-y: auto;
    }
    
    /* Reduce game title size to save space */
    .game-title {
        font-size: 1.3rem;
        margin: 0.3rem 0;
    }
}

/* Landscape orientation adjustments */
@media (orientation: landscape) {
    .game-title {
        font-size: 1.2rem;
        margin: 0.3rem 0;
    }
    
    .tab-navigation {
        padding: 0.3rem 0.3rem 0;
    }
    
    .tab-button {
        padding: 0.3rem;
        font-size: 0.8rem;
    }
    
    /* Arrange control panel horizontally in landscape */
    .control-panel {
        flex-direction: row;
    }
    
    .neon-button {
        flex: 2;
    }
    
    .turn-indicator {
        flex: 1;
    }
    
    .sound-controls-container {
        flex: 1;
    }
    
    /* Set appropriate tab content height */
    .tab-content-container {
        height: calc(100vh - 150px);
        min-height: 200px;
    }
}

/* Utility classes for space saving */
.compact-margin {
    margin: 0.2rem 0;
}

.compact-padding {
    padding: 0.2rem;
}

/* Additional adjustments for small screens */
@media screen and (max-height: 600px) {
    .game-title {
        font-size: 1rem;
        margin: 0.2rem 0;
    }
    
    .control-panel {
        margin-bottom: 0.2rem;
    }
    
    .neon-button {
        padding: 0.7rem;
        font-size: 0.9rem;
    }
    
    .turn-indicator {
        padding: 0.5rem;
        font-size: 0.9rem;
    }
}