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

body {
    font-family: 'Courier New', monospace;
    background: linear-gradient(135deg, #1a1a2e, #16213e);
    color: #e0e0e0;
    min-height: 100vh;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
}

.game-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 10px;
}

.game-header {
    text-align: center;
    margin-bottom: 15px;
    padding: 15px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 10px;
    border: 2px solid #444;
}

.game-header h1 {
    font-size: 2em;
    color: #ffd700;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
    margin-bottom: 8px;
}

.header-stats {
    display: flex;
    justify-content: center;
    gap: 20px;
    font-size: 1.1em;
    color: #ccc;
    flex-wrap: wrap;
}

.game-layout {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

/* Mobile-Optimized Panels */
.mobile-optimized {
    background: rgba(0, 0, 0, 0.4);
    border: 2px solid #444;
    border-radius: 8px;
    overflow: hidden;
}

.panel-toggle {
    width: 100%;
    background: linear-gradient(145deg, #2a2a3a, #1a1a2a);
    border: none;
    border-bottom: 2px solid #444;
    color: #ffd700;
    padding: 12px 15px;
    font-family: inherit;
    font-size: 1.1em;
    font-weight: bold;
    cursor: pointer;
    transition: background 0.2s ease;
    text-align: left;
    min-height: 44px;
}

.panel-toggle:hover {
    background: linear-gradient(145deg, #3a3a4a, #2a2a3a);
}

.panel-toggle:active {
    transform: translateY(1px);
}

.panel-content {
    padding: 15px;
    display: none;
}

/* Stats Panel */
.stat-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    font-size: 1em;
    min-height: 24px;
}

.health-bar {
    background: #333;
    border: 2px solid #666;
    border-radius: 6px;
    width: 100px;
    height: 16px;
    position: relative;
    overflow: hidden;
}

.health-fill {
    background: linear-gradient(90deg, #ff0000, #ffff00, #00ff00);
    height: 100%;
    transition: width 0.3s ease;
}

/* Game Area */
.game-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    order: 1;
}

#game-canvas {
    border: 3px solid #444;
    border-radius: 8px;
    background: #000;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
    touch-action: none;
    max-width: 100%;
    max-height: 60vh;
}

/* Mobile Controls */
.mobile-controls {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    width: 100%;
    max-width: 400px;
}

.virtual-dpad {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    grid-template-rows: 1fr 1fr 1fr;
    gap: 8px;
    width: 200px;
    height: 200px;
}

.dpad-btn {
    background: linear-gradient(145deg, #2a2a3a, #1a1a2a);
    border: 2px solid #444;
    border-radius: 8px;
    color: #e0e0e0;
    font-size: 1.5em;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.1s ease;
    min-height: 44px;
    touch-action: manipulation;
    user-select: none;
}

.dpad-up { grid-column: 2; grid-row: 1; }
.dpad-left { grid-column: 1; grid-row: 2; }
.dpad-center { grid-column: 2; grid-row: 2; background: linear-gradient(145deg, #3a3a4a, #2a2a3a); }
.dpad-right { grid-column: 3; grid-row: 2; }
.dpad-down { grid-column: 2; grid-row: 3; }

.dpad-btn:active {
    background: linear-gradient(145deg, #4a4a5a, #3a3a4a);
    transform: scale(0.95);
}

.action-buttons {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
}

.mobile-action-btn {
    background: linear-gradient(145deg, #2a2a3a, #1a1a2a);
    border: 2px solid #444;
    border-radius: 8px;
    color: #e0e0e0;
    padding: 12px 16px;
    font-family: inherit;
    font-size: 0.9em;
    cursor: pointer;
    transition: all 0.2s ease;
    min-height: 44px;
    min-width: 80px;
    touch-action: manipulation;
}

.mobile-action-btn:hover {
    background: linear-gradient(145deg, #3a3a4a, #2a2a3a);
    border-color: #666;
}

.mobile-action-btn:active {
    transform: translateY(1px);
}

.mobile-action-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.controls-help {
    background: rgba(0, 0, 0, 0.4);
    padding: 8px 15px;
    border-radius: 5px;
    border: 1px solid #444;
    text-align: center;
    color: #bbb;
    font-size: 0.8em;
}

/* Quest Panel */
.quest-text {
    background: rgba(0, 0, 0, 0.3);
    padding: 12px;
    border-radius: 4px;
    font-size: 0.9em;
    line-height: 1.4;
    margin-bottom: 12px;
    min-height: 60px;
    color: #ddd;
}

/* Inventory */
.inventory-grid.mobile-inventory {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    gap: 8px;
}

.inventory-item.mobile-item {
    background: rgba(0, 0, 0, 0.5);
    border: 2px solid #666;
    border-radius: 6px;
    padding: 12px;
    text-align: center;
    font-size: 0.9em;
    color: #ffd700;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Legend */
.legend {
    font-size: 1em;
}

.legend-item {
    display: flex;
    align-items: center;
    margin-bottom: 8px;
    min-height: 32px;
}

.legend-symbol {
    font-weight: bold;
    margin-right: 12px;
    width: 32px;
    height: 32px;
    text-align: center;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 4px;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2em;
    border: 1px solid #444;
}

.legend-symbol.player { color: #ffff00; }
.legend-symbol.wall { background-color: #8b7355; color: #fff; }
.legend-symbol.floor { background-color: #2a2a2a; color: #fff; }
.legend-symbol.door { background-color: #8B4513; color: #fff; }
.legend-symbol.stairs { color: #fff; }
.legend-symbol.goblin { color: #0f0; }
.legend-symbol.potion { color: #f00; }
.legend-symbol.gold { color: #ffd700; }

/* Game Log */
.game-log {
    background: rgba(0, 0, 0, 0.5);
    border: 1px solid #333;
    border-radius: 4px;
    padding: 10px;
    height: 120px;
    overflow-y: auto;
    font-size: 0.85em;
    line-height: 1.3;
}

.game-log div {
    margin-bottom: 4px;
    color: #ccc;
    padding: 2px 0;
}

/* Action Buttons */
.action-btn {
    background: linear-gradient(145deg, #2a2a3a, #1a1a2a);
    border: 2px solid #444;
    border-radius: 6px;
    color: #e0e0e0;
    padding: 10px 14px;
    font-family: inherit;
    font-size: 0.9em;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-bottom: 10px;
    width: 100%;
    min-height: 44px;
    touch-action: manipulation;
}

.action-btn:hover {
    background: linear-gradient(145deg, #3a3a4a, #2a2a3a);
    border-color: #666;
}

.action-btn:active {
    transform: translateY(1px);
}

.action-btn.danger {
    background: linear-gradient(145deg, #4a2a2a, #3a1a1a);
    border-color: #644;
}

.action-btn.danger:hover {
    background: linear-gradient(145deg, #5a3a3a, #4a2a2a);
    border-color: #866;
}

.game-footer {
    text-align: center;
    margin-top: 20px;
    padding: 12px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 8px;
    font-size: 0.85em;
    color: #999;
}

.game-footer a {
    color: #ffd700;
    text-decoration: none;
}

.game-footer a:hover {
    text-decoration: underline;
}

/* Desktop Responsive Design */
@media (min-width: 768px) {
    .game-container {
        padding: 20px;
    }
    
    .game-layout {
        display: grid;
        grid-template-columns: 1fr 2fr 1fr;
        grid-template-areas: 
            "left game right"
            "actions game log";
        gap: 20px;
    }
    
    .game-area {
        grid-area: game;
        order: unset;
    }
    
    .stats-panel { grid-area: left; }
    .quest-panel { grid-area: left; }
    .legend-panel { grid-area: right; }
    .inventory-panel { grid-area: right; }
    .actions-panel { grid-area: actions; }
    .log-panel { grid-area: log; }
    
    /* Hide mobile controls on desktop */
    .mobile-controls {
        display: none;
    }
    
    /* Desktop panels always open */
    .panel-content {
        display: block !important;
    }
    
    .panel-toggle {
        display: none;
    }
    
    #game-canvas {
        max-height: 80vh;
    }
}

@media (min-width: 1200px) {
    .game-layout {
        grid-template-columns: 250px 1fr 250px;
    }
}

/* Tablet Landscape */
@media (min-width: 768px) and (max-width: 1024px) and (orientation: landscape) {
    .game-layout {
        grid-template-columns: 200px 1fr 200px;
    }
    
    .mobile-controls {
        display: flex;
        transform: scale(0.8);
    }
}

/* Mobile Portrait */
@media (max-width: 767px) {
    .header-stats {
        flex-direction: column;
        gap: 8px;
    }
    
    .game-header h1 {
        font-size: 1.6em;
    }
    
    .virtual-dpad {
        width: 180px;
        height: 180px;
    }
    
    .dpad-btn {
        font-size: 1.2em;
    }
    
    .action-buttons {
        width: 100%;
        max-width: 300px;
    }
    
    .mobile-action-btn {
        flex: 1;
        min-width: 70px;
        font-size: 0.8em;
        padding: 10px 8px;
    }
}

/* Small Mobile */
@media (max-width: 480px) {
    .game-container {
        padding: 5px;
    }
    
    .virtual-dpad {
        width: 160px;
        height: 160px;
    }
    
    .dpad-btn {
        font-size: 1em;
    }
    
    .mobile-action-btn {
        font-size: 0.75em;
        padding: 8px 6px;
    }
    
    #game-canvas {
        max-height: 40vh;
    }
}

/* Scrollbar styling */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: #444;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #666;
}

/* Touch feedback */
@media (hover: none) {
    .dpad-btn:hover,
    .mobile-action-btn:hover,
    .action-btn:hover,
    .panel-toggle:hover {
        background: inherit;
    }
}