/* Enhanced Mobile-Optimized Spice Tactics Styles with Functional Panels */
@import url('https://fonts.googleapis.com/css2?family=Orbitron:wght@400;700;900&display=swap');

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

body {
    margin: 0;
    padding: 0;
    background: linear-gradient(135deg, #8B4513 0%, #D2691E 100%);
    font-family: 'Orbitron', monospace;
    color: #D4AF37;
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    touch-action: manipulation;
}

#header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: linear-gradient(90deg, #8B4513, #CD853F, #8B4513);
    border: 3px solid #D4AF37;
    border-bottom: none;
    padding: 8px 15px;
    box-shadow: inset 0 0 20px rgba(212, 175, 55, 0.3);
    height: 50px;
    position: relative;
    z-index: 100;
}

.header-btn {
    background: linear-gradient(145deg, #DAA520, #B8860B);
    border: 2px solid #D4AF37;
    color: #000;
    padding: 8px 12px;
    font-family: 'Orbitron', monospace;
    font-weight: 700;
    font-size: 11px;
    cursor: pointer;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.5);
    transition: all 0.2s ease;
    min-height: 44px;
    min-width: 60px;
    border-radius: 4px;
}

.header-btn:hover,
.header-btn:active {
    background: linear-gradient(145deg, #FFD700, #DAA520);
    box-shadow: 0 0 15px rgba(212, 175, 55, 0.8);
    transform: scale(1.05);
}

#credits {
    font-weight: 900;
    font-size: 16px;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.8);
    letter-spacing: 1px;
}

#house-banner {
    font-weight: 900;
    font-size: 12px;
    color: #4169E1;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.8);
    background: rgba(65, 105, 225, 0.2);
    padding: 6px 10px;
    border: 2px solid #4169E1;
    border-radius: 4px;
}

/* Overlay Panels - Fully Functional */
.overlay-panel {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.8);
    z-index: 1000;
    display: none;
    overflow-y: auto;
    backdrop-filter: blur(5px);
}

.overlay-panel.active {
    display: block;
    animation: panelSlideIn 0.3s ease-out;
}

@keyframes panelSlideIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.panel-header {
    background: linear-gradient(90deg, #8B4513, #CD853F, #8B4513);
    border-bottom: 3px solid #D4AF37;
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 10px rgba(0,0,0,0.5);
}

.panel-header h2 {
    margin: 0;
    font-size: 20px;
    font-weight: 900;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.8);
    letter-spacing: 1px;
}

.close-btn {
    background: transparent;
    border: 2px solid #D4AF37;
    color: #D4AF37;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    font-size: 18px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.close-btn:hover,
.close-btn:active {
    background: #D4AF37;
    color: #000;
    transform: scale(1.1);
}

.panel-content {
    padding: 20px;
    max-width: 800px;
    margin: 0 auto;
    background: linear-gradient(180deg, #654321, #4a2c17);
    min-height: calc(100vh - 80px);
}

/* Mentat Panel Styles */
.mentat-section {
    background: rgba(139, 69, 19, 0.6);
    border: 2px solid #D4AF37;
    border-radius: 8px;
    padding: 15px;
    margin-bottom: 20px;
    box-shadow: inset 0 0 15px rgba(212, 175, 55, 0.2);
}

.mentat-section h3 {
    margin: 0 0 10px 0;
    font-size: 16px;
    font-weight: 700;
    color: #FFD700;
    text-shadow: 1px 1px 3px rgba(0,0,0,0.8);
    border-bottom: 1px solid #D4AF37;
    padding-bottom: 5px;
}

.analysis-content {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
    font-size: 14px;
    line-height: 1.5;
}

.analysis-content p {
    margin: 0;
    padding: 8px 12px;
    background: rgba(0,0,0,0.4);
    border-radius: 4px;
    border-left: 3px solid #4169E1;
}

.analysis-content span {
    color: #FFD700;
    font-weight: 700;
}

.recommendations-list {
    max-height: 200px;
    overflow-y: auto;
}

.recommendation {
    background: rgba(0,0,0,0.3);
    padding: 10px;
    margin-bottom: 8px;
    border-radius: 4px;
    border-left: 3px solid #32CD32;
    font-size: 13px;
    line-height: 1.4;
}

.lore-text {
    background: rgba(0,0,0,0.3);
    padding: 15px;
    border-radius: 6px;
    font-size: 13px;
    line-height: 1.6;
    max-height: 250px;
    overflow-y: auto;
}

.lore-text p {
    margin-bottom: 15px;
}

.lore-text strong {
    color: #FFD700;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 10px;
}

.stat {
    background: rgba(0,0,0,0.4);
    padding: 12px;
    border-radius: 6px;
    text-align: center;
    font-size: 12px;
    border: 1px solid #666;
}

.stat span {
    display: block;
    font-size: 18px;
    font-weight: 700;
    color: #FFD700;
    margin-top: 5px;
}

/* Options Panel Styles */
.options-section {
    background: rgba(139, 69, 19, 0.6);
    border: 2px solid #D4AF37;
    border-radius: 8px;
    padding: 15px;
    margin-bottom: 20px;
    box-shadow: inset 0 0 15px rgba(212, 175, 55, 0.2);
}

.options-section h3 {
    margin: 0 0 15px 0;
    font-size: 16px;
    font-weight: 700;
    color: #FFD700;
    text-shadow: 1px 1px 3px rgba(0,0,0,0.8);
    border-bottom: 1px solid #D4AF37;
    padding-bottom: 5px;
}

.setting-group {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 0;
    border-bottom: 1px solid rgba(212, 175, 55, 0.3);
    gap: 15px;
}

.setting-group:last-child {
    border-bottom: none;
}

.setting-group label {
    font-size: 14px;
    font-weight: 600;
    color: #D4AF37;
    flex: 1;
}

.volume-slider,
.sensitivity-slider {
    flex: 2;
    height: 8px;
    background: #333;
    border-radius: 4px;
    outline: none;
    -webkit-appearance: none;
    box-shadow: inset 0 0 5px rgba(0,0,0,0.5);
}

.volume-slider::-webkit-slider-thumb,
.sensitivity-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    background: linear-gradient(145deg, #DAA520, #B8860B);
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid #D4AF37;
    box-shadow: 0 0 5px rgba(212, 175, 55, 0.5);
}

.volume-slider::-moz-range-thumb,
.sensitivity-slider::-moz-range-thumb {
    width: 20px;
    height: 20px;
    background: linear-gradient(145deg, #DAA520, #B8860B);
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid #D4AF37;
    box-shadow: 0 0 5px rgba(212, 175, 55, 0.5);
}

.setting-checkbox {
    width: 20px;
    height: 20px;
    accent-color: #D4AF37;
    cursor: pointer;
}

.setting-select {
    background: #333;
    color: #D4AF37;
    border: 2px solid #666;
    border-radius: 4px;
    padding: 8px 12px;
    font-family: 'Orbitron', monospace;
    font-size: 12px;
    cursor: pointer;
    min-width: 150px;
}

.setting-select:focus {
    border-color: #D4AF37;
    outline: none;
    box-shadow: 0 0 5px rgba(212, 175, 55, 0.5);
}

.reset-btn {
    width: 100%;
    background: linear-gradient(145deg, #DC143C, #8B0000);
    border: 2px solid #FF6B6B;
    color: #FFF;
    padding: 15px;
    font-family: 'Orbitron', monospace;
    font-weight: 700;
    font-size: 14px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.3s ease;
    text-transform: uppercase;
}

.reset-btn:hover,
.reset-btn:active {
    background: linear-gradient(145deg, #FF6B6B, #DC143C);
    transform: scale(1.02);
    box-shadow: 0 0 15px rgba(220, 20, 60, 0.5);
}

#game-container {
    position: relative;
    display: flex;
    background: #2F2F2F;
    border: 3px solid #D4AF37;
    border-top: none;
    height: calc(100vh - 50px);
    overflow: hidden;
}

#canvas {
    border: none;
    cursor: crosshair;
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
    touch-action: none;
    flex: 1;
}

#command-panel {
    width: 300px;
    background: linear-gradient(180deg, #8B4513, #654321);
    border-left: 3px solid #D4AF37;
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    box-shadow: inset 0 0 20px rgba(0,0,0,0.5);
    transition: transform 0.3s ease;
    position: relative;
    z-index: 50;
}

#command-panel.collapsed {
    transform: translateX(100%);
}

#command-panel.portrait {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 100%;
    height: 250px;
    border-left: none;
    border-top: 3px solid #D4AF37;
    transform: translateY(100%);
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: space-around;
    align-items: flex-start;
}

#command-panel.portrait.collapsed {
    transform: translateY(100%);
}

#command-panel.portrait:not(.collapsed) {
    transform: translateY(0);
}

#command-panel.left-handed {
    border-left: none;
    border-right: 3px solid #D4AF37;
    order: -1;
}

#panel-handle {
    position: absolute;
    left: -20px;
    top: 50%;
    transform: translateY(-50%);
    width: 20px;
    height: 80px;
    background: linear-gradient(90deg, #8B4513, #CD853F);
    border: 2px solid #D4AF37;
    border-right: none;
    border-radius: 10px 0 0 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}

#command-panel.left-handed #panel-handle {
    left: auto;
    right: -20px;
    border-left: none;
    border-right: 2px solid #D4AF37;
    border-radius: 0 10px 10px 0;
}

#command-panel.portrait #panel-handle {
    left: 50%;
    top: -20px;
    transform: translateX(-50%);
    width: 80px;
    height: 20px;
    border-radius: 10px 10px 0 0;
    border-right: 2px solid #D4AF37;
    border-bottom: none;
}

.handle-bar {
    width: 4px;
    height: 40px;
    background: #D4AF37;
    border-radius: 2px;
}

#command-panel.portrait .handle-bar {
    width: 40px;
    height: 4px;
}

#panel-handle:hover,
#panel-handle:active {
    background: linear-gradient(90deg, #CD853F, #DAA520);
    box-shadow: 0 0 10px rgba(212, 175, 55, 0.6);
    transform: translateY(-50%) scale(1.1);
}

#command-panel.portrait #panel-handle:hover {
    transform: translateX(-50%) scale(1.1);
}

#unit-portrait {
    width: 64px;
    height: 64px;
    border: 2px solid #D4AF37;
    background: #1a1a1a;
    align-self: center;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    position: relative;
}

#unit-portrait img {
    width: 60px;
    height: 60px;
    image-rendering: pixelated;
}

#portrait-placeholder {
    font-size: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
}

#unit-info {
    text-align: center;
    min-width: 150px;
}

#unit-name {
    font-weight: 900;
    font-size: 14px;
    margin-bottom: 8px;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.8);
}

#health-bar {
    width: 100%;
    height: 12px;
    background: #333;
    border: 2px solid #666;
    margin-bottom: 8px;
    position: relative;
    overflow: hidden;
    border-radius: 6px;
}

#health-fill {
    height: 100%;
    background: #00FF00;
    width: 100%;
    transition: width 0.3s ease;
    border-radius: 4px;
}

#unit-stats {
    font-size: 11px;
    color: #AAA;
    font-weight: 400;
}

#command-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

#command-panel.portrait #command-buttons {
    grid-template-columns: repeat(4, 1fr);
}

.cmd-btn {
    padding: 15px 10px;
    border: 3px solid #666;
    background: linear-gradient(145deg, #333, #555);
    color: #D4AF37;
    font-family: 'Orbitron', monospace;
    font-weight: 700;
    font-size: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
    min-height: 60px;
    min-width: 60px;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    touch-action: manipulation;
}

.btn-icon {
    font-size: 20px;
    display: block;
}

.cmd-btn:hover,
.cmd-btn:active {
    border-color: #D4AF37;
    background: linear-gradient(145deg, #555, #777);
    box-shadow: 0 0 15px rgba(212, 175, 55, 0.5);
    transform: scale(1.05);
}

.cmd-btn.active {
    border-color: #FFD700;
    background: linear-gradient(145deg, #DAA520, #B8860B);
    color: #000;
    box-shadow: inset 0 0 10px rgba(255, 215, 0, 0.3);
    transform: scale(1.1);
}

.attack-btn:hover { border-color: #FF6B6B; }
.move-btn:hover { border-color: #4ECDC4; }
.guard-btn:hover { border-color: #FFE66D; }
.retreat-btn:hover { border-color: #A8A8A8; }

#status-display {
    background: rgba(0,0,0,0.8);
    border: 2px solid #666;
    padding: 10px;
    font-size: 11px;
    text-align: center;
    color: #D4AF37;
    border-radius: 6px;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.8);
}

#mini-map {
    position: absolute;
    bottom: 15px;
    right: 15px;
    border: 3px solid #D4AF37;
    background: #000;
    box-shadow: 0 0 15px rgba(212, 175, 55, 0.5);
    border-radius: 8px;
    overflow: hidden;
    transition: all 0.3s ease;
}

#mini-map.portrait {
    bottom: 270px;
    right: 15px;
}

#mini-map.expanded {
    transform: scale(1.5);
    z-index: 200;
}

#mini-canvas {
    cursor: pointer;
    image-rendering: pixelated;
    display: block;
}

#mini-map-toggle {
    position: absolute;
    bottom: -25px;
    left: 50%;
    transform: translateX(-50%);
    background: #8B4513;
    color: #D4AF37;
    padding: 4px 8px;
    font-size: 10px;
    font-weight: 700;
    border: 2px solid #D4AF37;
    border-top: none;
    border-radius: 0 0 6px 6px;
    cursor: pointer;
    min-height: 30px;
    display: flex;
    align-items: center;
}

#mini-map-toggle:hover,
#mini-map-toggle:active {
    background: #CD853F;
    box-shadow: 0 0 10px rgba(212, 175, 55, 0.5);
}

#touch-feedback {
    position: absolute;
    background: rgba(255, 215, 0, 0.9);
    color: #000;
    padding: 8px 12px;
    font-size: 12px;
    font-weight: 700;
    border-radius: 6px;
    pointer-events: none;
    z-index: 1000;
    display: none;
    transition: opacity 0.3s ease;
    box-shadow: 0 0 15px rgba(255, 215, 0, 0.7);
}

#touch-feedback.show {
    opacity: 1;
    animation: feedbackPulse 1s ease-out;
}

@keyframes feedbackPulse {
    0% { transform: scale(0.8); opacity: 0; }
    50% { transform: scale(1.1); opacity: 1; }
    100% { transform: scale(1); opacity: 1; }
}

#controls {
    position: absolute;
    bottom: 10px;
    left: 10px;
    background: rgba(0,0,0,0.8);
    padding: 8px 12px;
    border: 2px solid #666;
    border-radius: 6px;
    font-size: 10px;
    color: #AAA;
    z-index: 100;
}

#gesture-help {
    margin-top: 4px;
    font-size: 9px;
    color: #888;
}

/* Responsive Design */
@media (max-width: 768px) {
    #header {
        padding: 5px 10px;
        height: 45px;
    }
    
    .header-btn {
        padding: 6px 8px;
        font-size: 10px;
        min-width: 50px;
    }
    
    #credits {
        font-size: 14px;
    }
    
    #house-banner {
        font-size: 10px;
        padding: 4px 8px;
    }
    
    #command-panel {
        width: 250px;
        padding: 10px;
    }
    
    .cmd-btn {
        padding: 12px 8px;
        min-height: 50px;
        font-size: 9px;
    }
    
    .btn-icon {
        font-size: 16px;
    }
    
    #mini-canvas {
        width: 100px;
        height: 75px;
    }
    
    .panel-content {
        padding: 15px;
    }
    
    .mentat-section,
    .options-section {
        padding: 12px;
        margin-bottom: 15px;
    }
    
    .setting-group {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }
    
    .setting-group label {
        margin-bottom: 5px;
    }
}

@media (max-height: 600px) {
    #command-panel:not(.portrait) {
        padding: 8px;
        gap: 8px;
    }
    
    #unit-portrait {
        width: 48px;
        height: 48px;
    }
    
    #unit-portrait img,
    #portrait-placeholder {
        width: 44px;
        height: 44px;
        font-size: 24px;
    }
    
    .cmd-btn {
        padding: 8px 6px;
        min-height: 40px;
        font-size: 8px;
    }
    
    .panel-content {
        padding: 10px;
    }
}

/* Portrait orientation specific styles */
@media (orientation: portrait) {
    #game-container {
        flex-direction: column;
    }
    
    #command-panel:not(.portrait) {
        display: none;
    }
    
    #mini-map:not(.portrait) {
        bottom: 15px;
        right: 15px;
    }
}

/* Landscape orientation specific styles */
@media (orientation: landscape) {
    #command-panel.portrait {
        display: none;
    }
    
    #mini-map.portrait {
        display: none;
    }
}

/* Accessibility improvements */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* High contrast mode */
@media (prefers-contrast: high) {
    body {
        background: #000;
    }
    
    #header {
        background: #333;
        border-color: #FFF;
    }
    
    .header-btn {
        background: #FFF;
        color: #000;
        border-color: #FFF;
    }
    
    #command-panel {
        background: #222;
        border-color: #FFF;
    }
    
    .cmd-btn {
        background: #444;
        border-color: #FFF;
        color: #FFF;
    }
    
    .overlay-panel {
        background: rgba(0,0,0,0.95);
    }
    
    .panel-content {
        background: #111;
    }
    
    .mentat-section,
    .options-section {
        background: #222;
        border-color: #FFF;
    }
}

/* Scrollbar styling for panels */
.overlay-panel::-webkit-scrollbar,
.lore-text::-webkit-scrollbar,
.recommendations-list::-webkit-scrollbar {
    width: 8px;
}

.overlay-panel::-webkit-scrollbar-track,
.lore-text::-webkit-scrollbar-track,
.recommendations-list::-webkit-scrollbar-track {
    background: #333;
    border-radius: 4px;
}

.overlay-panel::-webkit-scrollbar-thumb,
.lore-text::-webkit-scrollbar-thumb,
.recommendations-list::-webkit-scrollbar-thumb {
    background: #D4AF37;
    border-radius: 4px;
}

.overlay-panel::-webkit-scrollbar-thumb:hover,
.lore-text::-webkit-scrollbar-thumb:hover,
.recommendations-list::-webkit-scrollbar-thumb:hover {
    background: #FFD700;
}

/* Focus styles for keyboard navigation */
button:focus,
input:focus,
select:focus,
canvas:focus {
    outline: 3px solid #FFD700;
    outline-offset: 2px;
}

/* Loading states for images */
img {
    transition: opacity 0.3s ease;
}

img:not([src]),
img[src=""] {
    opacity: 0;
}