/* Google Font for retro pixelated style */
@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap');

/* CSS variables for consistent theming */
:root { --main-gold: #ffd700; --dark-bg: #1a1a1a; --light-text: #f0f0f0; --dark-ui: #262626; --grey-border: #555; }

html, body {
    height: 100%;
    margin: 0;
    overflow: hidden; /* Prevent body scrolling */
}

/* General body styling */
body {
    background-color: var(--dark-bg);
    color: var(--light-text);
    font-family: 'Press Start 2P', cursive;
    display: flex;
    justify-content: center; /* Center the game wrapper */
    align-items: flex-start; /* Align to top */
    padding: 5px;
    box-sizing: border-box;
    -webkit-user-select: none;
    -ms-user-select: none;
    user-select: none;
    touch-action: manipulation; /* Disable double-tap to zoom */
}

.game-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    width: 100%;
    height: 100%;
    max-width: 1200px;
}

/* --- SETTINGS & DEBUG UI --- */
#settings-button-container { position: fixed; top: 15px; right: 15px; z-index: 102; }
#open-settings-button { background-color: rgba(40,40,40,0.8); border: 2px solid var(--grey-border); color: var(--light-text); border-radius: 50%; width: 50px; height: 50px; font-size: 1.8rem; cursor: pointer; display: flex; justify-content: center; align-items: center; }

/* --- Overlays & Dialogs --- */
#start-screen, #level-up-dialog, #save-code-dialog, #game-over-screen, #oracle-dialog, #character-sheet-screen, #full-log-screen, #monster-info-screen, #settings-screen, #shop-screen, #confirmation-dialog, #add-to-home-screen-dialog, #cutscene-dialog, #full-map-screen { 
    position: fixed; 
    top: 0; 
    left: 0; 
    right: 0; 
    bottom: 0; 
    background-color: rgba(0, 0, 0, 0.95); 
    z-index: 100; 
    display: flex; 
    flex-direction: column; 
    justify-content: center; 
    align-items: center; 
    gap: 20px; 
    text-align: center; 
    padding: 20px; 
    box-sizing: border-box; 
    overflow-x: hidden !important; /* Prevent horizontal scrolling */
    overflow-y: auto; /* Allow vertical scrolling */
}
#level-up-dialog, #save-code-dialog, #game-over-screen, #oracle-dialog, #character-sheet-screen, #full-log-screen, #monster-info-screen, #difficulty-selection, #settings-screen, #shop-screen, #confirmation-dialog, #add-to-home-screen-dialog, #cutscene-dialog, #full-map-screen { display: none; }
#confirmation-dialog { z-index: 101; background-color: rgba(0,0,0,0.85); }
#add-to-home-screen-dialog { z-index: 105; }
#cutscene-dialog { background-color: #000; z-index: 110; }

.dialog-content { 
    background-color: var(--dark-ui); 
    padding: clamp(15px, 4vw, 40px); 
    border-radius: 12px; 
    border: 3px solid var(--grey-border); 
    box-shadow: 0 0 25px rgba(255, 215, 0, 0.3); 
    width: 95%; 
    max-width: 500px; 
    max-height: 90vh;
    overflow-x: hidden !important; /* Prevent horizontal scrolling */
    overflow-y: auto; /* Allow vertical scrolling */
    box-sizing: border-box;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.game-button { font-family: 'Press Start 2P', cursive; font-size: clamp(0.8rem, 2.5vw, 1rem); padding: 15px 30px; background-color: var(--main-gold); color: var(--dark-bg); border: 2px solid var(--light-text); border-radius: 8px; cursor: pointer; transition: all 0.2s ease; }
.game-button:hover:not(:disabled) { background-color: var(--light-text); transform: translateY(-2px); }
.game-button:disabled { background-color: var(--grey-border); color: #888; cursor: not-allowed; }
.game-button.secondary { background-color: #757575; color: var(--light-text); }
.stat-increase-button { margin: 5px; width: 280px; text-align: left; max-width: 90%; }
h1 { font-size: clamp(2rem, 8vw, 3rem); }
#version-display { position: absolute; bottom: 20px; left: 20px; font-size: 0.7rem; color: #888; }

/* --- PWA & UPDATE STYLES --- */
.pwa-install-button {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    margin-top: 10px;
}

.update-notification {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: #ff9800;
    color: #000;
    padding: 15px;
    z-index: 200;
    text-align: center;
    font-family: 'Press Start 2P', cursive;
}

.notification-content {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 15px;
    flex-wrap: wrap;
}

.notification-content p {
    margin: 0;
    font-size: 0.8rem;
}

.offline {
    filter: grayscale(0.3);
}

/* --- ACHIEVEMENT SYSTEM STYLES --- */
@keyframes damageFloat {
    0% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
    50% { transform: translate(-50%, -80%) scale(1.2); }
    100% { opacity: 0; transform: translate(-50%, -120%) scale(0.8); }
}

.achievement-popup {
    position: fixed;
    top: 50px;
    right: -400px;
    background: linear-gradient(135deg, #ffd700, #ffb300);
    color: #000;
    padding: 15px;
    border-radius: 12px;
    border: 3px solid #fff;
    box-shadow: 0 8px 20px rgba(0,0,0,0.6);
    z-index: 200;
    font-family: 'Press Start 2P', cursive;
    transition: right 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    max-width: 350px;
}

.achievement-popup.show {
    right: 20px;
}

.achievement-content {
    display: flex;
    align-items: center;
    gap: 15px;
}

.achievement-icon {
    font-size: 2rem;
}

.achievement-text h3 {
    margin: 0 0 5px 0;
    font-size: 0.9rem;
}

.achievement-text p {
    margin: 0;
    font-size: 0.7rem;
}

.achievements-section {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 2px solid #555;
}

.achievements-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 10px;
    margin-top: 10px;
}

.achievement-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    border-radius: 5px;
    border: 1px solid #555;
}

.achievement-item.unlocked {
    background-color: rgba(255, 215, 0, 0.1);
    border-color: #ffd700;
}

.achievement-item.locked {
    opacity: 0.5;
}

.achievement-info {
    flex-grow: 1;
}

.achievement-info strong {
    display: block;
    font-size: 0.8rem;
}

.achievement-info small {
    display: block;
    font-size: 0.6rem;
    color: #ccc;
}

/* --- MOBILE GAME FEATURES --- */
.quick-actions {
    position: fixed;
    top: 50%;
    right: 10px;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 45;
}

.quick-action-btn {
    width: 45px;
    height: 45px;
    border-radius: 50%;
    border: 2px solid rgba(255, 215, 0, 0.7);
    background: rgba(0, 0, 0, 0.7);
    color: #ffd700;
    font-size: 1.2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.quick-action-btn:hover, .quick-action-btn:active {
    background: rgba(255, 215, 0, 0.2);
    transform: scale(1.1);
}

.game-toast {
    position: fixed;
    top: 50px;
    left: 50%;
    transform: translateX(-50%) translateY(-20px);
    background: rgba(0, 0, 0, 0.9);
    color: #ffd700;
    padding: 10px 20px;
    border-radius: 20px;
    border: 2px solid #ffd700;
    font-family: 'Press Start 2P', cursive;
    font-size: 0.8rem;
    z-index: 150;
    opacity: 0;
    transition: all 0.3s ease;
}

.game-toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.save-indicator {
    position: fixed;
    top: 20px;
    right: 80px;
    font-size: 1.5rem;
    animation: saveFloat 1s ease-out;
    z-index: 60;
}

@keyframes saveFloat {
    0% { opacity: 0; transform: translateY(10px); }
    50% { opacity: 1; transform: translateY(-5px); }
    100% { opacity: 0; transform: translateY(-15px); }
}

/* --- Cutscene Styles --- */
.video-container {
    position: relative;
    width: 100%;
    max-width: 1120px;
    padding-bottom: 56.25%; /* 16:9 Aspect Ratio */
    height: 0;
}
#cutscene-player {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: 0;
}
#skip-cutscene-button {
    position: absolute;
    bottom: 30px;
}

/* --- Main Game UI --- */
#game-canvas {
    background-color: #000;
    border: 4px solid var(--grey-border);
    border-radius: 8px;
    box-shadow: 0 0 20px rgba(255, 215, 0, 0.3);
    box-sizing: border-box; /* Add for better sizing */
    /* Flex properties for responsive bounding */
    flex-grow: 1;
    width: 100%;
    height: 100%;
    min-height: 0;
    min-width: 0;
}
.ui-container { display: flex; justify-content: space-between; width: 100%; max-width: 800px; flex-wrap: nowrap; gap: 10px; }
.stats-box, .log-box {
    background-color: var(--dark-ui);
    border: 2px solid var(--grey-border);
    border-radius: 8px;
    padding: 10px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.4);
    width: 50%;
    cursor: pointer;
    height: 160px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    justify-content: space-between;
}
.log-box #portrait-message-log, .log-box #landscape-message-log { flex-grow: 1; overflow-y: scroll; scrollbar-width: none; }
#portrait-message-log::-webkit-scrollbar, #landscape-message-log::-webkit-scrollbar { display: none; }
#portrait-message-log, #landscape-message-log, #full-log-content { display: flex; flex-direction: column-reverse; gap: 5px; }

h2 { text-align: center; color: var(--main-gold); text-shadow: 2px 2px 4px #000; margin-top: 0; margin-bottom: 5px; font-size: clamp(13px, 2.6vmin, 1.1rem); }
.stats-box p, #portrait-message-log p, #landscape-message-log p { font-size: clamp(9px, 2.0vmin, 0.95rem); margin: 2px 0; word-wrap: break-word; }

.stat-bar-line { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 2px; }
.stat-bar-line p { margin: 0; white-space: nowrap; flex-shrink: 0; }
.hp-bar, .xp-bar { background-color: #444; border-radius: 5px; height: 10px; width: 100%; border: 1px solid #777; overflow: hidden; flex-grow: 1; }
.hp-fill { background-color: #d32f2f; height: 100%; transition: width 0.3s ease; }
.xp-fill { background-color: #42a5f5; height: 100%; transition: width 0.3s ease; }
.core-stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 10px; }
.stat-bars-container { margin-top: auto; padding-top: 4px; }

/* Hide the new actions box by default */
.actions-box {
    display: none;
}

/* --- NEW MOBILE CONTROLS --- */
#mobile-dpad-container, #mobile-actions-container {
    position: fixed;
    bottom: 15px;
    z-index: 50;
    opacity: 0.8;
    transition: opacity 0.2s ease-in-out;
}
#mobile-dpad-container {
    left: 15px;
}
#mobile-actions-container {
    right: 15px;
}
#mobile-dpad-container:hover, #mobile-actions-container:hover {
    opacity: 1.0;
}
.mobile-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}
.mobile-dpad {
    display: grid;
    grid-template-columns: repeat(3, 50px);
    grid-template-rows: repeat(3, 50px);
    gap: 5px;
}
.mobile-btn, .mobile-dpad-btn {
    font-family: 'Press Start 2P', cursive;
    background-color: rgba(40, 40, 40, 0.8);
    border: 2px solid var(--grey-border);
    color: var(--main-gold);
    border-radius: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
    -webkit-tap-highlight-color: transparent;
}
.mobile-btn {
    font-size: 0.7rem;
    padding: 10px 5px;
}
#mobile-action-map {
    font-size: 1.2rem;
}
.mobile-dpad-btn {
    font-size: 1.5rem;
}
#mobile-dpad-up { grid-area: 1 / 2 / 2 / 3; }
#mobile-dpad-left { grid-area: 2 / 1 / 3 / 2; }
#mobile-dpad-center { grid-area: 2 / 2 / 3 / 3; }
#mobile-dpad-right { grid-area: 2 / 3 / 3 / 4; }
#mobile-dpad-down { grid-area: 3 / 2 / 4 / 3; }

/* --- NEW FULL SCREEN MAP --- */
#full-map-screen {
    background-color: #000;
}
#full-map-canvas {
    background-color: #000;
    border: 4px solid var(--grey-border);
    max-width: 95vw;
    max-height: 80vh;
}
#close-full-map-button {
    margin-top: 15px;
}

/* --- LAYOUT MANAGEMENT --- */
#show-pwa-prompt { display: none; }
body.is-mobile #show-pwa-prompt { display: block; }
#landscape-left-sidebar, #landscape-right-sidebar { display: none; }

/* --- LANDSCAPE LAYOUT (Side Bar Panel) --- */
body.layout-landscape {
    padding: 0;
}

body.layout-landscape .game-wrapper {
    flex-direction: row; /* Use a row for side panel layout */
    gap: 5px;
    height: 100vh;
    padding: 5px;
}

/* Repurpose the main UI container as the left-side panel */
body.layout-landscape .ui-container {
    flex-direction: column; /* Stack stats and log vertically */
    width: 280px;
    max-width: 35%; /* Prevent panel from being too wide */
    height: 100%;
    flex-shrink: 0;
    justify-content: flex-start;
    gap: 5px;
}

/* Ensure stats and log boxes fit the new column layout */
body.layout-landscape .stats-box {
    width: 100%;
    height: auto; /* Auto height for stats */
    flex-shrink: 0;
    cursor: default;
}

body.layout-landscape .log-box {
    width: 100%;
    flex-grow: 1; /* Log box takes remaining space */
    min-height: 150px;
    cursor: pointer;
}

/* Hide desktop-only action buttons on mobile */
body.layout-landscape .actions-box {
    display: none;
}

/* Make the canvas fill the rest of the space */
body.layout-landscape #game-canvas {
    border: 4px solid var(--grey-border); /* Restore border */
    border-radius: 8px;
    box-shadow: 0 0 20px rgba(255, 215, 0, 0.3);
}

/* The empty landscape sidebars are not needed with this approach */
body.layout-landscape #landscape-left-sidebar,
body.layout-landscape #landscape-right-sidebar {
    display: none;
}

/* --- Portrait Layout (Default) --- */
body.layout-portrait .game-wrapper {
    padding: 5px;
}

/* --- Safe Area Support for Notched Devices --- */
@supports (padding: max(0px)) {
    body {
        padding-right: max(5px, env(safe-area-inset-right));
        padding-bottom: max(5px, env(safe-area-inset-bottom));
        padding-left: max(5px, env(safe-area-inset-left));
    }
    
    #mobile-actions-container {
        right: max(15px, env(safe-area-inset-right));
        bottom: max(15px, env(safe-area-inset-bottom));
    }
    #mobile-dpad-container {
        left: max(15px, env(safe-area-inset-left));
        bottom: max(15px, env(safe-area-inset-bottom));
    }
}

/* --- Personalization Inputs --- */
.personalization-container {
    display: flex;
    flex-direction: column;
    gap: 15px;
    align-items: center;
    width: 100%;
    margin-top: 20px;
}
.input-row {
    display: flex;
    align-items: center;
    gap: 10px;
}
.input-row label {
    font-size: 0.9rem;
}
#player-name-input, #player-sprite-input {
    font-family: 'Press Start 2P', cursive;
    background-color: #111;
    border: 2px solid var(--grey-border);
    color: var(--light-text);
    border-radius: 5px;
    text-align: center;
    font-size: 1rem;
    padding: 8px;
    max-width: 100%;
    box-sizing: border-box;
    word-wrap: break-word;
}
#player-name-input {
    width: 200px;
}
#player-sprite-input {
    width: 60px;
    font-size: 1.5rem;
}
.sprite-options button {
    background: none;
    border: 2px solid var(--grey-border);
    font-size: 1.5rem;
    padding: 5px;
    border-radius: 5px;
    cursor: pointer;
    transition: background-color 0.2s;
}
.sprite-options button:hover {
    background-color: var(--grey-border);
}

/* --- DIALOG/INVENTORY/SETTINGS STYLES --- */
/* Character Sheet Dialog */
#character-sheet-screen .dialog-content {
    display: flex;
    flex-direction: column;
    gap: 20px;
    width: 95%;
    max-width: 800px;
    height: 85vh;
    max-height: 85vh;
    overflow-x: hidden !important;
    overflow-y: auto;
}

.character-sheet-panel {
    width: 100%;
    min-width: 0; /* Prevent overflow */
    box-sizing: border-box;
    overflow-x: hidden;
    overflow-y: auto;
    text-align: left;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

/* Shop Dialog */
#shop-screen .dialog-content {
    display: flex;
    flex-direction: column;
    width: 95%;
    max-width: 800px;
    height: 80vh;
    max-height: 80vh;
    overflow-x: hidden !important;
    overflow-y: auto;
}

.shop-panels-container {
    display: flex;
    flex-direction: column;
    width: 100%;
    gap: 20px;
    overflow-x: hidden !important;
    overflow-y: auto;
    flex-grow: 1;
    box-sizing: border-box;
}

.shop-panel {
    width: 100%;
    box-sizing: border-box;
    min-width: 0;
    overflow-x: hidden;
    flex: 1;
    text-align: left;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

/* Settings Dialog */
#settings-screen .dialog-content {
    width: 95%;
    max-width: 600px;
    overflow-x: hidden !important;
    overflow-y: auto;
}

.settings-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    font-size: 0.9rem;
    width: 100%;
    box-sizing: border-box;
    min-width: 0;
}

/* Full Log Dialog */
#full-log-screen .dialog-content {
    width: 95%;
    max-width: 700px;
    height: 80vh;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden !important;
    overflow-y: auto;
}

#full-log-content {
    flex-grow: 1;
    overflow-y: auto;
    overflow-x: hidden !important;
    text-align: left;
    background-color: #111;
    padding: 10px;
    border-radius: 5px;
    font-size: 0.8rem;
    word-wrap: break-word;
    box-sizing: border-box;
    display: flex;
    flex-direction: column-reverse;
    gap: 5px;
}

/* Inventory and Equipment Lists */
.inventory-list, .equipment-list, .shop-list {
    list-style: none;
    padding: 0;
    margin: 0;
    max-height: 200px;
    overflow-y: auto;
    overflow-x: hidden !important;
    box-sizing: border-box;
}

.inventory-list li, .equipment-list li, .shop-list li {
    padding: 8px;
    margin-bottom: 5px;
    background-color: #333;
    border-radius: 5px;
    cursor: pointer;
    transition: background-color 0.2s;
    word-wrap: break-word;
    overflow-wrap: break-word;
    white-space: normal;
    box-sizing: border-box;
}

.inventory-list li:hover, .shop-list li:hover:not(.disabled) { background-color: #444; }
.shop-list li.disabled { color: #888; cursor: not-allowed; background-color: #2a2a2a; }

/* Save Code Display */
#save-code-display {
    font-size: 0.9rem;
    background-color: #111;
    border: 2px solid var(--grey-border);
    color: var(--light-text);
    border-radius: 5px;
    word-wrap: break-word;
    overflow-wrap: break-word;
    white-space: pre-wrap;
    min-height: 50px;
    padding: 10px;
    margin-top: 10px;
    overflow-x: hidden !important;
    overflow-y: auto;
    max-height: 200px;
    box-sizing: border-box;
}

/* Slider and Toggle Controls */
.slider { -webkit-appearance: none; width: 50%; height: 8px; background: #555; outline: none; border-radius: 4px; }
.slider::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 20px; height: 20px; background: var(--main-gold); cursor: pointer; border-radius: 50%; }
.switch { position: relative; display: inline-block; width: 50px; height: 24px; }
.switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #555; transition: .4s; border-radius: 24px; }
.toggle-slider:before { position: absolute; content: ""; height: 16px; width: 16px; left: 4px; bottom: 4px; background-color: white; transition: .4s; border-radius: 50%; }
input:checked + .toggle-slider { background-color: var(--main-gold); }
input:checked + .toggle-slider:before { transform: translateX(26px); }

.keybind-input { 
    font-family: 'Press Start 2P', cursive; 
    background-color: #111; 
    border: 2px solid var(--grey-border); 
    color: var(--light-text); 
    border-radius: 5px; 
    width: 120px; 
    text-align: center; 
    font-size: 0.9rem; 
    padding: 5px; 
    cursor: pointer; 
    text-transform: capitalize; 
    box-sizing: border-box;
}
.keybind-input.listening { border-color: var(--main-gold); }

#save-code-input { 
    width: 80%; 
    max-width: 300px; 
    padding: 10px; 
    font-size: 1rem; 
    background-color: #111; 
    border: 2px solid var(--grey-border); 
    color: var(--light-text); 
    border-radius: 5px; 
    max-width: 100%;
    box-sizing: border-box;
    word-wrap: break-word;
}

#oracle-response { font-size: 1rem; color: var(--main-gold); min-height: 80px; text-align: center; line-height: 1.5; }

/* --- Responsive adjustments for very small screens --- */
@media (max-height: 600px) and (orientation: landscape) {
    .game-toast {
        top: 10px;
        font-size: 0.6rem;
        padding: 5px 15px;
    }
    
    .achievement-popup {
        top: 10px;
        right: -300px;
        max-width: 250px;
    }
    
    .quick-actions {
        right: 5px;
        gap: 5px;
    }
    
    .quick-action-btn {
        width: 35px;
        height: 35px;
        font-size: 1rem;
    }
}

/* --- Mobile optimizations --- */
@media (max-width: 480px) {
    .dialog-content {
        padding: 15px;
        width: 95vw;
        max-width: none;
        overflow-x: hidden !important;
    }
    
    .game-button {
        font-size: 0.8rem;
        padding: 12px 20px;
    }
    
    .achievements-grid {
        grid-template-columns: 1fr;
    }
    
    .achievement-item {
        padding: 6px;
    }
    
    .achievement-info strong {
        font-size: 0.7rem;
    }
    
    .achievement-info small {
        font-size: 0.5rem;
    }
    
    #shop-screen .dialog-content {
        width: 95vw;
        height: 85vh;
        max-height: 85vh;
    }
    
    .shop-panels-container {
        gap: 15px;
    }
    
    .shop-list {
        max-height: 150px;
    }
    
    .settings-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
}

/* ========================================= */
/* === DESKTOP OPTIMIZATIONS START HERE === */
/* ========================================= */

/* === DESKTOP-SPECIFIC OVERRIDES === */
@media (pointer: fine) and (min-width: 1024px) {
    
    /* === MAIN GAME LAYOUT === */
    body {
        padding: 10px;
        overflow: hidden;
    }
    
    .game-wrapper {
        max-width: none;
        width: 100%;
        height: 100vh;
        gap: 10px;
        flex-direction: row;
        align-items: stretch;
    }
    
    /* === ENHANCED UI CONTAINER === */
    .ui-container {
        flex-direction: column;
        width: 320px;
        max-width: 320px;
        flex-shrink: 0;
        gap: 10px;
        height: 100%;
    }
    
    .stats-box, .log-box {
        width: 100%;
        max-height: none;
    }
    
    .stats-box {
        height: auto;
        flex-grow: 0;
    }
    
    .log-box {
        flex-grow: 1;
        min-height: 200px;
    }
    
    .actions-box {
        display: block;
        width: 100%;
        background-color: var(--dark-ui);
        border: 2px solid var(--grey-border);
        border-radius: 8px;
        padding: 10px;
        box-shadow: 0 4px 8px rgba(0,0,0,0.4);
    }
    
    .action-buttons-grid {
        display: flex;
        flex-direction: column;
        gap: 10px;
        margin-top: 10px;
    }

    .action-btn-desktop {
        width: 100%;
        box-sizing: border-box;
        padding: 12px 10px;
        font-size: 0.9rem;
    }
    
    /* === LARGER GAME CANVAS === */
    #game-canvas {
        max-width: none;
        max-height: none;
        border-radius: 12px;
    }
    
    /* === HIDE MOBILE ELEMENTS === */
    .quick-actions, #mobile-dpad-container, #mobile-actions-container {
        display: none !important;
    }
    
    /* === ENHANCED DIALOGS === */
    .dialog-content {
        max-width: 90vw;
        max-height: 85vh;
        width: auto;
        overflow-y: auto;
        overflow-x: hidden !important;
        padding: 30px;
    }
    
    /* === CHARACTER SHEET OPTIMIZATIONS === */
    #character-sheet-screen .dialog-content {
        width: 95vw;
        max-width: 1200px;
        height: 85vh;
        max-height: 85vh;
        display: flex;
        flex-direction: row;
        gap: 30px;
        overflow-x: hidden !important;
        overflow-y: auto;
    }
    
    .character-sheet-panel {
        flex: 1;
        min-width: 0;
        max-width: 50%;
        overflow-y: auto;
        overflow-x: hidden !important;
        padding-right: 10px;
        box-sizing: border-box;
    }
    
    .character-sheet-panel:first-child {
        border-right: 2px solid var(--grey-border);
        padding-right: 20px;
    }
    
    /* === ACHIEVEMENTS GRID ENHANCEMENT === */
    .achievements-section {
        margin-top: 20px;
        padding-top: 20px;
        border-top: 2px solid #555;
        max-height: 400px;
        overflow-y: auto;
    }
    
    .achievements-grid {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
        margin-top: 15px;
    }
    
    .achievement-item {
        padding: 12px;
        font-size: 0.85rem;
    }
    
    .achievement-info strong {
        font-size: 0.8rem;
    }
    
    .achievement-info small {
        font-size: 0.65rem;
    }
    
    /* === INVENTORY OPTIMIZATIONS === */
    #inventory-list, #equipment-list {
        max-height: 300px;
        overflow-y: auto;
        padding-right: 10px;
    }
    
    /* === SETTINGS DIALOG === */
    #settings-screen .dialog-content {
        width: 600px;
        max-width: 90vw;
    }
    
    .settings-row {
        margin-bottom: 25px;
        font-size: 1rem;
    }
    
    .keybind-input {
        width: 150px;
        font-size: 1rem;
        padding: 8px;
    }
    
    /* === SHOP OPTIMIZATIONS === */
    #shop-screen .dialog-content {
        width: 90vw;
        max-width: 900px;
        height: 75vh;
        max-height: 75vh;
    }
    
    .shop-panels-container {
        display: flex;
        flex-direction: row;
        gap: 30px;
        height: 100%;
        overflow-x: hidden !important;
        overflow-y: auto;
    }
    
    .shop-panel {
        flex: 1;
        min-width: 0;
        max-width: 50%;
    }
    
    .shop-list {
        max-height: 400px;
    }
    
    /* === ENHANCED MESSAGE LOG === */
    #portrait-message-log {
        max-height: none;
        height: 100%;
        font-size: 0.85rem;
    }
    
    /* === FULL LOG SCREEN === */
    #full-log-screen .dialog-content {
        width: 90vw;
        max-width: 1000px;
        height: 80vh;
    }
    
    #full-log-content {
        font-size: 0.9rem;
        line-height: 1.4;
    }
    
    /* === GAME BUTTON ENHANCEMENTS === */
    .game-button {
        font-size: 1rem;
        padding: 15px 25px;
        transition: all 0.2s ease;
    }
    
    .game-button:hover:not(:disabled) {
        transform: translateY(-3px);
        box-shadow: 0 6px 20px rgba(255, 215, 0, 0.3);
    }
    
    /* === STATS DISPLAY IMPROVEMENTS === */
    .core-stats-grid {
        gap: 8px 15px;
        font-size: 1rem;
    }
    
    .stat-bar-line {
        margin-top: 8px;
    }
    
    .stat-bar-line p {
        font-size: 1rem;
    }
    
    /* === ENHANCED SCROLLBARS === */
    .character-sheet-panel::-webkit-scrollbar,
    .achievements-section::-webkit-scrollbar,
    #inventory-list::-webkit-scrollbar,
    #equipment-list::-webkit-scrollbar,
    .shop-list::-webkit-scrollbar,
    #full-log-content::-webkit-scrollbar {
        width: 8px;
    }
    
    .character-sheet-panel::-webkit-scrollbar-track,
    .achievements-section::-webkit-scrollbar-track,
    #inventory-list::-webkit-scrollbar-track,
    #equipment-list::-webkit-scrollbar-track,
    .shop-list::-webkit-scrollbar-track,
    #full-log-content::-webkit-scrollbar-track {
        background: #333;
        border-radius: 4px;
    }
    
    .character-sheet-panel::-webkit-scrollbar-thumb,
    .achievements-section::-webkit-scrollbar-thumb,
    #inventory-list::-webkit-scrollbar-thumb,
    #equipment-list::-webkit-scrollbar-thumb,
    .shop-list::-webkit-scrollbar-thumb,
    #full-log-content::-webkit-scrollbar-thumb {
        background: var(--main-gold);
        border-radius: 4px;
    }
    
    .character-sheet-panel::-webkit-scrollbar-thumb:hover,
    .achievements-section::-webkit-scrollbar-thumb:hover,
    #inventory-list::-webkit-scrollbar-thumb:hover,
    #equipment-list::-webkit-scrollbar-thumb:hover,
    .shop-list::-webkit-scrollbar-thumb:hover,
    #full-log-content::-webkit-scrollbar-thumb:hover {
        background: #ffed4e;
    }
    
    /* === ACHIEVEMENT POPUP POSITIONING === */
    .achievement-popup {
        top: 100px;
        right: -450px;
        max-width: 400px;
        font-size: 0.9rem;
    }
    
    .achievement-popup.show {
        right: 340px;
    }
    
    /* === TOAST POSITIONING === */
    .game-toast {
        top: 100px;
        font-size: 0.9rem;
        padding: 12px 24px;
    }
    
    /* === VERSION DISPLAY === */
    #version-display {
        font-size: 0.8rem;
        bottom: 30px;
        left: 30px;
    }
    
    /* === SETTINGS BUTTON === */
    #settings-button-container {
        top: 20px;
        right: 30px;
    }
    
    #open-settings-button {
        width: 60px;
        height: 60px;
        font-size: 2rem;
    }
    
    #open-settings-button:hover {
        background-color: rgba(255, 215, 0, 0.2);
        transform: scale(1.1);
    }
}

/* === ULTRA-WIDE SCREEN OPTIMIZATIONS === */
@media (pointer: fine) and (min-width: 1400px) {
    .ui-container {
        width: 380px;
        max-width: 380px;
    }
    
    #game-canvas {
        width: calc(100vw - 440px);
    }
        
    .achievement-popup.show {
        right: 400px;
    }
}

/* === HIGH-DPI SCREEN OPTIMIZATIONS === */
@media (pointer: fine) and (min-width: 1024px) and (-webkit-min-device-pixel-ratio: 2) {
    .core-stats-grid {
        font-size: 1.1rem;
    }
    
    .stat-bar-line p {
        font-size: 1.1rem;
    }
    
    h2 {
        font-size: 1.3rem;
    }
    
    .game-button {
        font-size: 1.1rem;
    }
}

/* Hide quick actions in landscape mode on mobile */
body.layout-landscape .quick-actions {
    display: none;
}

/* Multiplayer UI Styles */
.dialog-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.95);
    z-index: 100;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 20px;
    text-align: center;
    padding: 20px;
    box-sizing: border-box;
    overflow-y: auto;
}

.lobby-player {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px;
    margin: 5px 0;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 5px;
    border: 2px solid #757575;
}

.lobby-player.ready {
    border-color: #4caf50;
}

#multiplayer-turn-indicator {
    position: fixed;
    top: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.9);
    color: #ffd700;
    padding: 10px 20px;
    border-radius: 20px;
    border: 2px solid #ffd700;
    font-family: 'Press Start 2P', cursive;
    font-size: 0.8rem;
    z-index: 60;
    display: none;
}

.loading-spinner {
    font-size: 2rem;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

#room-code-input {
    font-family: 'Press Start 2P', cursive;
    background-color: #111;
    border: 2px solid #555;
    color: #fff;
    border-radius: 5px;
    padding: 10px;
    font-size: 1rem;
    text-align: center;
    margin-right: 10px;
    max-width: 150px;
}

.settings-row select {
    font-family: 'Press Start 2P', cursive;
    background-color: #111;
    border: 2px solid #555;
    color: #fff;
    border-radius: 5px;
    padding: 5px;
    font-size: 0.8rem;
}
