/* dialogs.css - Modal windows, overlays, character sheets, shops, and settings screens */

/* --- Overlays & Dialogs --- */
/* Added .dialog-overlay from original styles.css */
#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, .dialog-overlay {
    position: fixed;
    top: 0;
    left: 0 !important;
    right: 0;
    bottom: 0;
    width: 100vw;
    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 */
}

/* Special handling for start-screen to prevent nested scrolling */
#start-screen {
    overflow-y: auto !important; /* Only start-screen should scroll */
    justify-content: flex-start !important; /* Align to top instead of center */
    padding-top: 20px !important;
    background-color: rgba(0, 0, 0, 1) !important; /* Fully opaque to hide game UI */
    z-index: 500 !important; /* Higher than game UI elements */
}

/* Hide game UI elements when on start screen - use body class for proper state management */
body.showing-start-screen .game-wrapper,
body.showing-start-screen #mobile-dpad-container,
body.showing-start-screen #mobile-actions-container,
body.showing-start-screen #settings-button-container {
    visibility: hidden !important;
    pointer-events: none !important;
}

/* Ensure start-screen content doesn't create additional scroll containers */
#main-start-menu {
    width: 100% !important;
    max-width: 800px !important;
    overflow: visible !important; /* Remove any overflow restrictions */
}

/* Fix column layout to prevent internal scrolling */
.main-menu-columns {
    overflow: visible !important;
    min-height: auto !important;
}

.single-player-column,
.multiplayer-column {
    overflow: visible !important;
}

/* Ensure boxes don't create scroll containers */
#start-screen .stats-box,
#start-screen .log-box {
    overflow: visible !important;
    height: auto !important;
    min-height: auto !important;
    max-height: none !important;
}

/* Mobile landscape specific fixes for start screen */
@media screen and (orientation: landscape) and (max-height: 500px) {
    #start-screen {
        padding: 10px !important;
        gap: 10px !important;
    }
    
    #main-start-menu {
        gap: 8px !important;
        padding: 10px !important;
    }
    
    .main-menu-columns {
        gap: 15px !important;
        flex-wrap: wrap !important;
    }
    
    .single-player-column,
    .multiplayer-column {
        min-width: 250px !important;
        max-width: 300px !important;
    }
    
    #start-screen h1 {
        font-size: clamp(1.5rem, 6vw, 2.5rem) !important;
        margin-bottom: 10px !important;
    }
    
    #start-screen h2 {
        font-size: clamp(1rem, 3.5vw, 1.3rem) !important;
        margin-bottom: 6px !important;
    }
}

/* Added #difficulty-selection */
#level-up-dialog, #save-code-dialog, #game-over-screen, #oracle-dialog, #character-sheet-screen, #achievements-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; }

/* Dialog z-index hierarchy - ensure proper layering */
#confirmation-dialog { z-index: 101; background-color: rgba(0,0,0,0.85); }
#achievements-screen { z-index: 102; }
/* All other dialogs use default z-index: 100 from main rule above */

/* Achievements Dialog */
#achievements-screen .dialog-content {
    width: 95vw;
    max-width: 800px;
    height: 90vh;
    max-height: 90vh;
    overflow-x: hidden !important;
    overflow-y: auto;
    padding: 15px;
    box-sizing: border-box;
}

/* Monster Info Screen */
#monster-info-screen .dialog-content {
    width: 90vw;
    max-width: 400px;
    padding: 20px;
    text-align: center;
}

#monster-info-sprite {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 128px;
    margin: 15px 0;
}

#monster-info-sprite canvas {
    border: 2px solid #444;
    border-radius: 8px;
    background: #222;
}

#monster-info-stats {
    margin: 20px 0;
}

#monster-info-stats p:first-child {
    font-weight: bold;
    color: #fff;
}

#monster-info-stats p:nth-child(even) {
    color: #ccc;
}

/* Responsive achievements grid */
@media (max-width: 600px) {
    .achievements-grid {
        grid-template-columns: 1fr !important;
        gap: 8px;
    }
    
    .achievement-item {
        flex-direction: column;
        align-items: flex-start;
        text-align: left;
    }
}

@media (max-width: 400px) {
    .achievements-grid {
        gap: 6px;
    }
    
    .achievement-item {
        padding: 6px;
        font-size: 0.85rem;
    }
}
#add-to-home-screen-dialog { z-index: 105; }
#cutscene-dialog { background-color: #000; z-index: 110; }

/* === PHASE 2: Thematic UI Borders (9-Slice) (Restored) === */
.dialog-content {
    position: relative;
    background-color: var(--dark-ui);
    padding: clamp(8px, 2vw, 20px); /* Reduce padding range */
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.7); /* Updated shadow */
    width: 95%;
    max-width: 600px;
    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;

    /* ACTIVATED: Thematic Border Implementation (Replaced fallback styles) */
    border-radius: 0;
    border-style: solid;
    border-width: 12px; /* Reduce from 20px → 12px = 16px saved */
    border-image-slice: 20 fill;
    border-image-repeat: stretch; /* stretch usually works better than round */
    border-image-source: var(--ui-border-image);
}

/* Make cutscene dialog content take up more screen space */
#cutscene-dialog .dialog-content {
    width: 95vw;
    max-width: 95vw;
    height: 90vh;
    max-height: 90vh;
    padding: clamp(8px, 2vw, 20px);
    /* Keep the beautiful 9-slice border */
    border-width: 12px;
    border-image-slice: 20 fill;
    border-image-repeat: stretch;
    border-image-source: var(--ui-border-image);
}

/* --- Cutscene Styles --- */
.video-container {
    position: relative;
    width: 100%;
    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;
    right: 30px;
    z-index: 120;
}

/* --- 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;
    /* Added Pixelation Styles */
    image-rendering: pixelated;
    image-rendering: -moz-crisp-edges;
    image-rendering: crisp-edges;
}

#close-full-map-button {
    margin-top: 15px;
}

/* --- DIALOG/INVENTORY/SETTINGS STYLES (Restored missing sections) --- */
/* Character Sheet Dialog */
#character-sheet-screen .dialog-content {
    display: flex;
    flex-direction: column;
    gap: 8px; /* Reduced from 15px */
    width: 95vw;
    max-width: 1000px;
    height: 90vh;
    max-height: 90vh;
    overflow-x: hidden !important;
    overflow-y: hidden; /* Remove nested scrolling */
    padding: 8px; /* Reduced from 10px */
}

.character-sheet-header {
    margin-bottom: 6px; /* Reduced spacing */
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
}

.character-sheet-header h2 {
    margin: 0; /* Remove default margin */
    font-size: 1.3rem; /* Slightly smaller */
    flex: 1; /* Take up available space */
}

.character-sheet-container {
    display: flex;
    flex-direction: column;
    gap: 15px;
    width: 100%;
    flex-grow: 1;
    min-height: 0; /* Allow flex shrinking */
    overflow: hidden;
}

@media (min-width: 768px) {
    .character-sheet-container {
        flex-direction: row;
        gap: 20px;
    }
}

.character-sheet-panel {
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
    overflow-x: hidden;
    overflow-y: auto; /* Each panel scrolls independently */
    text-align: left;
    display: flex;
    flex-direction: column;
    gap: 6px; /* Reduced from 10px */
    border: 2px solid var(--grey-border);
    border-radius: 8px;
    padding: 8px; /* Reduced from 10px */
    background-color: rgba(40, 40, 40, 0.2);
    flex: 1;
    min-height: 0; /* Allow flex shrinking */
}

/* Reduce spacing in character sheet sections */
.character-sheet-panel h2 {
    margin: 0 0 6px 0; /* Reduced margin */
    font-size: 1.1rem; /* Slightly smaller */
}

.character-sheet-panel ul {
    margin: 0;
    padding: 0;
    list-style: none;
}

.character-sheet-panel li {
    margin-bottom: 4px; /* Reduced spacing between items */
    padding: 6px; /* Reduced padding */
}

/* Reduce button spacing */
.transfer-code-section,
.achievements-section {
    flex-shrink: 0; /* Prevent these sections from being compressed */
    margin-top: 8px; /* Reduced spacing instead of auto */
}

.inventory-controls {
    margin-bottom: 6px; /* Reduced margin */
}

.inventory-close-section {
    margin-top: 8px; /* Reduced margin */
}

/* Ensure important sections in stats panel don't get hidden */
.character-sheet-panel.stats-panel {
    min-height: 200px; /* Ensure minimum height for achievements button visibility */
}

/* Shop Dialog */
#shop-screen .dialog-content {
    display: flex;
    flex-direction: column;
    width: 95vw;
    max-width: 1200px; /* Increased from 1000px */
    height: 85vh; /* Reduced from 90vh for better button visibility */
    max-height: 85vh;
    overflow-x: hidden !important;
    overflow-y: auto; /* Allow scrolling when needed */
    padding: 10px;
}

.shop-panels-container {
    display: flex;
    flex-direction: column;
    width: 100%;
    gap: 15px;
    overflow-x: hidden !important;
    overflow-y: hidden; /* Remove scroll from container */
    flex-grow: 1;
    box-sizing: border-box;
    min-height: 0; /* Allow flex shrinking */
}

@media (min-width: 768px) {
    .shop-panels-container {
        flex-direction: row;
        gap: 20px;
    }
}

.shop-panel {
    width: 100%;
    box-sizing: border-box;
    min-width: 0;
    overflow-x: hidden;
    overflow-y: auto; /* Each panel scrolls independently */
    flex: 1;
    text-align: left;
    display: flex;
    flex-direction: column;
    gap: 10px;
    border: 2px solid var(--grey-border);
    border-radius: 8px;
    padding: 10px;
    background-color: rgba(40, 40, 40, 0.3);
    min-height: 0; /* Allow flex shrinking */
}

/* Settings Dialog (Restored) */
#settings-screen .dialog-content {
    width: 95vw;
    max-width: 800px; /* Increased from 700px */
    height: 85vh; /* Added height constraint */
    max-height: 85vh;
    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 (Restored) */
#full-log-screen .dialog-content {
    width: 95vw;
    max-width: 1000px; /* Increased from 700px */
    height: 85vh; /* Increased from 80vh */
    max-height: 85vh;
    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;
    /* Note: Flex properties (column-reverse, gap) are defined in components.css */
}

/* Save Code Display (Restored) */
#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;
}

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