/* Responsive Design */

/* Large Desktop */
@media (min-width: 1200px) {
    .container {
        display: grid;
        grid-template-columns: var(--panel-width-large) 1fr var(--panel-width-large);
    }
}

/* Medium Desktop */
@media (max-width: 1199px) and (min-width: 768px) {
    .container {
        display: grid;
        grid-template-columns: var(--panel-width-medium) 1fr var(--panel-width-small);
    }
    
    .hud-panel {
        padding: 12px;
        gap: 12px;
    }
}

/* Tablet and Mobile */
@media (max-width: 767px) {
    .container {
        flex-direction: column;
        height: 100vh;
        overflow: hidden;
    }
    .messaging-header {
        display: none;
    }
    .messaging-panel {
        border-right: none;
        border-bottom: 2px solid var(--border-color);
        max-height: 150px;
        min-height: 120px;
        flex-shrink: 0;
    }
    
    .messages-container {
        max-height: 80px;
    }
    
    .game-area {
        flex: 1;
        min-height: 0;
        overflow: hidden;
    }
    
    .scene-container {
        width: calc(100% - 10px);
        height: calc(100% - 10px);
        margin: 5px auto;
        max-width: none;
        max-height: none;
    }
    
    .hud-panel {
        border-left: none;
        border-top: 2px solid var(--border-color);
        flex-direction: row;
        gap: 8px;
        padding: 8px;
        flex-wrap: wrap;
        max-height: 160px;
        overflow-x: auto;
        overflow-y: hidden;
        flex-shrink: 0;
    }
    
    .game-logo {
        max-height: 40px;
    }
    
    .hud-section {
        flex: 1;
        min-width: 100px;
        margin-bottom: 0;
        padding: 6px;
    }
    .history-section {
        min-height: 300px;
    }
    .hud-section h3 {
        margin-bottom: 6px;
        font-size: 10px;
    }
    
    .history-container {
        max-height: 60px;
    }
    
    .history-item {
        padding: 3px;
        margin-bottom: 2px;
    }
}

/* Small Mobile Phones */
@media (max-width: 480px) {
    .messaging-panel {
        max-height: 120px;
        min-height: 100px;
    }

    .message {
        padding: 6px 8px;
    }
    
    .message-sender {
        font-size: 9px;
        margin-bottom: 4px;
    }
    
    .message-content {
        font-size: 11px;
    }
    
    .message-time {
        font-size: 8px;
    }
    
    .hud-panel {
        padding: 6px;
        gap: 6px;
    }
    
    .hud-section {
        min-width: 90px;
        padding: 4px;
    }
    
    .hud-section h3 {
        font-size: 9px;
        margin-bottom: 4px;
    }
    
    .stat-item, .resource-item {
        font-size: 10px;
        padding: 2px 0;
    }
    
    .game-logo {
        max-height: 30px;
    }
    
    .alert {
        width: 30px;
        height: 30px;
        font-size: 10px;
    }
    
    .event-display {
        padding: 15px;
        margin: 10px;
    }
    
    .event-display .event-title {
        font-size: 14px;
    }
    
    .event-display .work-title {
        font-size: 16px;
    }
    
    .event-display .work-description {
        font-size: 12px;
    }
    
    .event-display .decision-buttons {
        flex-direction: column;
        gap: 8px;
    }
    
    .event-display .decision-btn {
        padding: 10px 15px;
        font-size: 12px;
    }
}

/* Ultra Wide Screens */
@media (min-width: 1600px) {
    .container {
        grid-template-columns: 400px 1fr 400px;
    }
    
    .scene-container {
        max-width: 1200px;
        max-height: 960px;
    }
    
    .hud-panel {
        gap: 20px;
        padding: 20px;
    }
    
    .game-logo {
        max-height: 120px;
    }
}

/* High DPI Displays */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .game-logo {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }
    
    .alert {
        border-width: 2px;
    }
    
    .gauge-cursor {
        border-width: 1px;
    }
}

/* Landscape Orientation on Mobile */
@media (max-width: 767px) and (orientation: landscape) {
    .container {
        flex-direction: row;
    }
    
    .messaging-panel {
        border-right: 2px solid var(--border-color);
        border-bottom: none;
        max-height: none;
        min-height: 0;
        max-width: 250px;
        min-width: 200px;
        flex-shrink: 0;
    }
    
    .messages-container {
        max-height: none;
    }
    
    .hud-panel {
        border-top: none;
        border-left: 2px solid var(--border-color);
        flex-direction: column;
        max-height: none;
        max-width: 250px;
        min-width: 200px;
        overflow-y: auto;
        overflow-x: hidden;
    }
    
    .hud-section {
        flex: 0 0 auto;
        min-width: auto;
    }
}

/* Print Styles (for debugging) */
@media print {
    body {
        background: white;
        color: black;
    }
    
    .messaging-panel,
    .hud-panel,
    .stress-overlay,
    .game-over-modal,
    .flashback-modal {
        display: none !important;
    }
    
    .game-area {
        width: 100%;
        height: auto;
    }
    
    .scene-container {
        border: 1px solid black;
        margin: 0;
        width: 100%;
        height: 500px;
    }
}

/* Accessibility Improvements */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    
    .alert {
        animation: none;
    }
    
    .stress-overlay {
        animation: none;
    }
    
    .typing-effect {
        animation: none;
        white-space: normal;
        border-right: none;
    }
}

@media (prefers-color-scheme: light) {
    /* Light mode overrides if needed */
    :root {
        --bg-primary: #f8f9fa;
        --bg-secondary: #e9ecef;
        --bg-tertiary: #dee2e6;
        --text-primary: #212529;
        --text-secondary: #6c757d;
        --border-color: #adb5bd;
        --message-bg: #ffffff;
    }
}

/* High Contrast Mode */
@media (prefers-contrast: high) {
    :root {
        --bg-primary: #000000;
        --bg-secondary: #111111;
        --bg-tertiary: #222222;
        --text-primary: #ffffff;
        --text-secondary: #cccccc;
        --border-color: #ffffff;
        --accent-red: #ff0000;
        --accent-blue: #0099ff;
        --accent-orange: #ff6600;
    }
    
    .message, .hud-section {
        border: 2px solid var(--border-color);
    }
    
    .alert {
        border-width: 4px;
    }
}

/* Touch Device Optimizations */
@media (hover: none) and (pointer: coarse) {
    .alert {
        min-width: 44px;
        min-height: 44px;
    }
    
    .btn, .restart-btn, .flashback-close {
        min-height: 44px;
        padding: 12px 20px;
    }
    
    .history-item {
        min-height: 40px;
        padding: 10px;
    }
    
    .message {
        padding: 12px;
    }
}

/* Foldable Device Support */
@media (spanning: single-fold-vertical) {
    .container {
        grid-template-columns: 1fr;
        grid-template-rows: 1fr 1fr;
    }
    
    .messaging-panel {
        order: 1;
    }
    
    .game-area {
        order: 2;
    }
    
    .hud-panel {
        order: 3;
        flex-direction: row;
        max-height: 200px;
    }
}