/* Modern Tank Commander - Mobile-First CSS Grid Layout */

/* CSS Variables for theming */
:root {
    --bg-dark: #1F261F;
    --bg-panel: #2a3a2a;
    --text-light: #ffffff;
    --text-dim: #b0b0b0;
    --accent-green: #4CAF50;
    --accent-blue: #2196F3;
    --accent-red: #f44336;
    --border-color: #4a5a4a;
    --panel-width: 420px;
    --panel-width-mobile: 100%;
}

/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-light);
    overflow: hidden;
    width: 100vw;
    height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Main container - CSS Grid Layout */
#app-container {
    display: grid;
    width: 100%;
    height: 100vh;

    /* Mobile-first: Stack vertically */
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    grid-template-areas:
        "ui"
        "game";
}

/* Desktop/Tablet: Side-by-side layout */
@media (min-width: 768px) {
    #app-container {
        grid-template-columns: 1fr var(--panel-width);
        grid-template-rows: 100vh;
        grid-template-areas: "game ui";
    }
}

/* Game container */
#game-container {
    grid-area: game;
    position: relative;
    background: var(--bg-dark);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

/* Ensure Phaser canvas fits properly */
#game-container canvas {
    display: block;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

/* UI Panel */
#ui-panel {
    grid-area: ui;
    background: var(--bg-panel);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
    border-left: 2px solid var(--border-color);
    position: relative;
}

/* Mobile: No border on top, adjust heights */
@media (max-width: 767px) {
    #app-container {
        grid-template-rows: minmax(300px, 1fr) auto;
    }

    #ui-panel {
        border-left: none;
        border-top: 2px solid var(--border-color);
        max-height: 60vh;
    }

    #game-container {
        min-height: 300px;
    }
}

/* Screen management */
.screen {
    padding: 1.5rem;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.screen.hidden {
    display: none;
}

/* Menu Screen */
#menu-screen h1 {
    font-size: 2rem;
    margin-bottom: 1rem;
    color: var(--accent-green);
    text-align: center;
}

.instructions, .commands {
    margin-bottom: 1rem;
    line-height: 1.6;
    font-size: 0.95rem;
}

.commands {
    background: rgba(0, 0, 0, 0.3);
    padding: 0.75rem;
    border-radius: 4px;
    border-left: 3px solid var(--accent-green);
}

.level-selector {
    margin: 1.5rem 0;
}

.level-selector label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
}

.level-dropdown {
    width: 100%;
    padding: 0.75rem;
    font-size: 1rem;
    background: var(--bg-dark);
    color: var(--text-light);
    border: 2px solid var(--border-color);
    border-radius: 4px;
    margin-bottom: 1rem;
    cursor: pointer;
}

.level-dropdown:focus {
    outline: none;
    border-color: var(--accent-green);
}

.mobile-notice {
    margin-top: auto;
    padding: 0.75rem;
    background: rgba(33, 150, 243, 0.1);
    border-radius: 4px;
    text-align: center;
    font-size: 0.9rem;
    display: none;
}

@media (max-width: 767px) {
    .mobile-notice {
        display: block;
    }
}

/* Game Screen */
.level-info {
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border-color);
}

.level-info h2 {
    font-size: 1.25rem;
    color: var(--accent-blue);
}

.command-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.command-panel h3 {
    margin-bottom: 0.75rem;
    font-size: 1.1rem;
}

.command-textarea {
    flex: 1;
    min-height: 200px;
    padding: 0.75rem;
    font-family: 'Monaco', 'Menlo', 'Consolas', monospace;
    font-size: 0.95rem;
    background: var(--bg-dark);
    color: var(--text-light);
    border: 2px solid var(--border-color);
    border-radius: 4px;
    resize: vertical;
    line-height: 1.5;
}

.command-textarea:focus {
    outline: none;
    border-color: var(--accent-green);
}

.command-textarea::placeholder {
    color: var(--text-dim);
}

/* Mobile: Smaller textarea */
@media (max-width: 767px) {
    .command-textarea {
        min-height: 120px;
        font-size: 16px; /* Prevents zoom on iOS */
    }
}

.button-group {
    display: flex;
    gap: 0.5rem;
    margin-top: 1rem;
    flex-wrap: wrap;
}

/* Buttons */
.btn {
    padding: 0.75rem 1.25rem;
    font-size: 1rem;
    font-weight: 600;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
    flex: 1;
    min-width: 100px;
    white-space: nowrap;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

.btn:active {
    transform: translateY(0);
}

.btn-primary {
    background: var(--accent-green);
    color: white;
}

.btn-primary:hover {
    background: #45a049;
}

.btn-success {
    background: var(--accent-blue);
    color: white;
}

.btn-success:hover {
    background: #1976D2;
}

.btn-secondary {
    background: #555;
    color: white;
}

.btn-secondary:hover {
    background: #666;
}

/* Stats Panel */
.stats-panel {
    margin-top: 1rem;
    padding: 0.75rem;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 4px;
    font-size: 0.85rem;
}

.stat-row {
    display: flex;
    gap: 2rem;
    flex-wrap: wrap;
}

.stat-group {
    flex: 1;
    min-width: 100px;
}

.stat-group strong {
    display: block;
    margin-bottom: 0.25rem;
    color: var(--accent-green);
}

.stat-group div {
    margin: 0.15rem 0;
    color: var(--text-dim);
}

/* Game Over Screen */
.gameover-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
}

#gameover-title {
    font-size: 2.5rem;
    margin-bottom: 1rem;
    color: var(--accent-green);
}

#gameover-message {
    font-size: 1.25rem;
    margin-bottom: 2rem;
    line-height: 1.6;
}

/* Audio Controls (floating) */
#audio-controls {
    position: fixed;
    top: 1rem;
    left: 1rem;
    display: flex;
    gap: 0.5rem;
    z-index: 1000;
}

.audio-btn {
    width: 56px;
    height: 56px;
    background: rgba(0, 0, 0, 0.7);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    backdrop-filter: blur(10px);
    padding: 4px;
}

.audio-btn:hover {
    background: rgba(0, 0, 0, 0.9);
    transform: scale(1.05);
}

.audio-icon {
    width: 36px;
    height: 36px;
    object-fit: contain;
    transition: opacity 0.2s ease;
    image-rendering: pixelated;
    filter: invert(1);
}

.audio-btn.muted .audio-icon {
    opacity: 0.3;
}

/* Rotate suggestion overlay for mobile portrait */
.rotate-suggestion {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.95);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.rotate-content {
    text-align: center;
    padding: 2rem;
    max-width: 400px;
}

.rotate-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
    animation: rotate-pulse 2s ease-in-out infinite;
}

@keyframes rotate-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

.rotate-content p {
    font-size: 1.1rem;
    margin-bottom: 1.5rem;
    line-height: 1.5;
}

/* Utility classes */
.hidden {
    display: none !important;
}

/* Loading indicator */
@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 1s linear infinite;
}

/* Responsive adjustments */
@media (max-width: 767px) {
    #menu-screen h1 {
        font-size: 1.5rem;
    }

    .instructions, .commands {
        font-size: 0.9rem;
    }

    #gameover-title {
        font-size: 1.75rem;
    }

    #gameover-message {
        font-size: 1rem;
    }

    .btn {
        padding: 0.65rem 1rem;
        font-size: 0.95rem;
    }
}

/* Landscape mobile optimization */
@media (max-width: 767px) and (orientation: landscape) {
    #app-container {
        grid-template-columns: 1fr 300px;
        grid-template-rows: 100vh;
        grid-template-areas: "game ui";
    }

    #ui-panel {
        border-left: 2px solid var(--border-color);
        border-top: none;
        max-height: 100vh;
        font-size: 0.85rem;
    }

    /* Compact the UI elements for landscape */
    .screen {
        padding: 0.75rem;
    }

    #menu-screen h1 {
        font-size: 1.25rem;
        margin-bottom: 0.5rem;
    }

    .instructions, .commands {
        font-size: 0.8rem;
        margin-bottom: 0.5rem;
    }

    .commands {
        padding: 0.5rem;
    }

    .level-selector {
        margin: 0.75rem 0;
    }

    .level-dropdown {
        padding: 0.5rem;
        font-size: 0.9rem;
        margin-bottom: 0.5rem;
    }

    .command-textarea {
        min-height: 150px;
        font-size: 0.85rem;
        padding: 0.5rem;
    }

    .btn {
        padding: 0.5rem 0.75rem;
        font-size: 0.85rem;
        min-width: 70px;
    }

    .stats-panel {
        margin-top: 0.5rem;
        padding: 0.5rem;
        font-size: 0.75rem;
    }

    .level-info {
        margin-bottom: 0.5rem;
        padding-bottom: 0.5rem;
    }

    .level-info h2 {
        font-size: 1rem;
    }

    .command-panel h3 {
        margin-bottom: 0.5rem;
        font-size: 0.95rem;
    }

    #gameover-title {
        font-size: 1.5rem;
        margin-bottom: 0.5rem;
    }

    #gameover-message {
        font-size: 0.9rem;
        margin-bottom: 1rem;
    }

    /* Smaller audio controls in landscape */
    #audio-controls {
        top: 0.5rem;
        left: 0.5rem;
        gap: 0.25rem;
    }

    .audio-btn {
        width: 40px;
        height: 40px;
        border-width: 1px;
    }

    .audio-icon {
        width: 24px;
        height: 24px;
    }
}

/* Tablet optimizations */
@media (min-width: 768px) and (max-width: 1024px) {
    :root {
        --panel-width: 360px;
    }
}

/* Print styles (hide game) */
@media print {
    body {
        display: none;
    }
}
