/* --- Google Font Imports (Consistent with Main Story) --- */
@import url('https://fonts.googleapis.com/css2?family=Lora:ital,wght@0,400;0,700;1,400&family=Cinzel+Decorative:wght@400;700&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Cinzel:wght@400;700&family=Lora:ital,wght@0,400;0,700;1,400&display=swap');

/* --- Root Variables for "The Curator's Garden" Theme --- */
:root {
    --bg-color: #d0edf5;
    --book-cover-color: #a3b8c3;
    --accent-color: #e7b2c4;
    --page-color: #f3eade;
    --text-color: #3d352a;
    --ink-color: #6d5b61;
    --choice-bg: rgba(61, 53, 42, 0.05);
    --choice-hover-bg: rgba(61, 53, 42, 0.15);
    --border-subtle: #d1c4b3;
}

/* --- Global Resets & Base Styles --- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--page-color);
    color: var(--text-color);
    font-family: 'Lora', serif;
    font-size: 16px;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* --- Main Scene & Character --- */
#finance-scene {
    position: relative;
    width: 100vw;
    height: 100vh;
    background-image: linear-gradient(to right, rgba(0,0,0,0.05) 0%, transparent 15%, transparent 85%, rgba(0,0,0,0.05) 100%);
    box-shadow: inset 0 0 50px rgba(0,0,0,0.15);
    opacity: 0;
    transition: opacity 1.5s ease-in-out;
    display: flex; 
    align-items: center;
    justify-content: flex-start;
}

#finance-scene.visible {
    opacity: 1;
}

#character-sprite {
    position: fixed;
    bottom: -300px;
    right: 300px;
    height: 80vh;
    max-height: 800px;
    cursor: pointer;
    transition: all 0.3s ease;
    filter: drop-shadow(5px 5px 8px rgba(0,0,0,0.25));
    z-index: 40; 
    transform: scale(3);
}


#character-sprite:hover {
    transform: translateY(-10px) scale(3.02);
}

/* --- Thematic Tools Panel --- */
#tools-panel {
    position: absolute;
    top: 50%;
    left: 60px;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    gap: 20px;
    background-color: var(--choice-bg);
    padding: 25px;
    border: 1px solid var(--border-subtle);
    border-top: 4px solid var(--accent-color);
    border-radius: 8px;
    box-shadow: 0 5px 20px rgba(0,0,0,0.1);
    z-index: 60; 
    transition: opacity 0.3s ease-in-out;
}

.tool-icon {
    width: 220px;
    background-color: transparent;
    border: 1px solid var(--border-subtle);
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    text-align: center;
    padding: 15px 10px;
}

.tool-icon:hover {
    transform: translateY(-5px);
    border-color: var(--accent-color);
    box-shadow: 0 3px 10px rgba(231, 178, 196, 0.5);
}

.tool-icon .icon-text {
    font-family: 'Cinzel', serif;
    font-size: 1.5em;
    font-weight: 700;
    letter-spacing: 1.5px;
    color: var(--ink-color);
    margin-bottom: 8px;
}

.tool-icon .tool-label {
    margin: 0;
    font-size: 0.85em;
    color: var(--text-color);
    opacity: 0.8;
    font-style: italic;
}


/* --- Dialogue System (Thematic) --- */
#story-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(61, 53, 42, 0.6);
    backdrop-filter: blur(4px);
    z-index: 100;
    display: none; /* FIXED: Changed from 'flex' to 'none' to prevent blocking clicks on load */
    align-items: flex-end;
    justify-content: center;
    gap: 20px;
    padding: 0 20px 30px 20px;
    opacity: 0;
    transition: opacity 0.4s ease-out;
}

#dialogue-sprite-container {
    flex-shrink: 0;
    height: 75vh;
    display: flex;
    align-items: flex-end;
    top:-200px;
    opacity: 1;
    transition: opacity 0.3s ease;
}

#dialogue-sprite {
    max-height: 100%;
    width: auto;
    object-fit: contain;
    filter: drop-shadow(2px 2px 10px rgba(0, 0, 0, 0.3));
}

#dialogue-box {
    width: 100%;
    max-width: 800px;
    min-height: 160px;
    background-color: rgba(243, 234, 222, 0.95);
    border: 1px solid var(--border-subtle);
    border-top: 3px solid var(--accent-color);
    border-radius: 10px;
    padding: 25px 30px;
    box-shadow: 0 0 25px rgba(0,0,0,0.15);
    cursor: pointer;
    position: relative;
    flex-grow: 1;
}

#character-name { font-family: 'Cinzel Decorative', cursive; font-weight: 700; font-size: 1.5em; color: var(--ink-color); margin-bottom: 15px; }
#dialogue-text { color: var(--text-color); font-size: 1.2em; line-height: 1.6;  user-select: none; }
#dialogue-text i, .narrator-text { color: var(--ink-color); font-style: italic;  user-select: none; }
#dialogue-text::selection {
    color: var(--text-color);;
    background-color: var(--page-color)
}
#dialogue-next-indicator { color: var(--accent-color); position: absolute; bottom: 15px; right: 25px; font-size: 1.5em; animation: pulse 1.5s infinite; }
@keyframes pulse { 0% { opacity: 1; } 50% { opacity: 0.4; } 100% { opacity: 1; } }


/* --- Modal Overhaul (Thematic) --- */
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(61, 53, 42, 0.5);
    backdrop-filter: blur(5px);
    z-index: 200; /* Increased z-index to be above tool panel */
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    overflow-y: auto;
}

.modal-content {
    background-color: var(--page-color);
    border: 1px solid var(--border-subtle);
    border-top: 5px solid var(--accent-color);
    border-radius: 8px;
    padding: 25px 35px;
    width: 100%;
    max-width: 500px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
    position: relative;
    color: var(--text-color);
    margin: auto;
}

.modal-content h2 {
    font-family: 'Cinzel Decorative', cursive;
    color: var(--ink-color);
    margin: 0 0 25px 0;
    border-bottom: 1px solid var(--border-subtle);
    padding-bottom: 15px;
    text-align: center;
    font-size: 1.8em;
    font-weight: 400;
}

.close-modal-btn {
    position: absolute;
    top: 15px;
    right: 15px;
    background: none;
    border: none;
    font-size: 2em;
    color: var(--border-subtle);
    cursor: pointer;
    transition: color 0.3s ease, transform 0.3s ease;
    line-height: 1;
}

.close-modal-btn:hover {
    color: var(--accent-color);
    transform: rotate(90deg);
}

.input-group { margin-bottom: 20px; }
.input-group label { display: block; margin-bottom: 8px; font-size: 0.9em; color: var(--text-color); opacity: 0.8; font-family: 'Cinzel', serif; letter-spacing: 0.5px; }
.input-group input {
    width: 100%;
    padding: 12px;
    background-color: white;
    border: 1px solid var(--border-subtle);
    color: var(--text-color);
    border-radius: 4px;
    font-family: 'Lora', serif;
    font-size: 1.1em;
    transition: border-color 0.3s, box-shadow 0.3s;
}

.input-group input::placeholder {
    color: var(--border-subtle);
    font-style: italic;
    opacity: 0.9;
}

.input-group input:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 8px rgba(231, 178, 196, 0.6);
}

.tool-button {
    width: 100%;
    padding: 14px 20px;
    background-color: var(--choice-bg);
    border: 1px solid var(--border-subtle);
    border-left: 3px solid var(--accent-color);
    font-family: 'Cinzel', serif;
    font-weight: bold;
    font-size: 1.1em;
    cursor: pointer;
    border-radius: 5px;
    transition: all 0.3s;
    margin-top: 10px;
    color: var(--text-color);
    text-transform: uppercase;
    letter-spacing: 1px;
}
.tool-button:hover, .tool-button:focus {
    background-color: var(--choice-hover-bg);
    border-color: var(--accent-color);
    transform: translateX(3px);
    outline: none;
}

.result-area {
    margin-top: 25px;
    padding-top: 20px;
    border-top: 1px dashed var(--border-subtle);
    text-align: center;
}
.result-area p { margin: 10px 0; font-size: 1em; color: var(--text-color); opacity: 0.9; }
.result-value { font-weight: bold; color: var(--ink-color); font-size: 1.6em; display: block; margin-top: 5px; font-family: 'Lora', serif; }

#budget-chart-container {
    position: relative;
    width: 100%;
    max-width: 250px;
    margin: 20px auto 0;
}

/* --- FIX: Hide Tool Panel When Modal Is Active --- */
/* This modern CSS rule checks if any modal is visible (using its inline style) and hides the tool panel to prevent overlap. */
body:has(.modal-backdrop[style*="flex"]) #tools-panel {
    opacity: 0;
    pointer-events: none;
}


/* --- Universal Navigation Menu --- */
#navigation-menu { position: fixed; bottom: 30px; left: 30px; z-index: 1000; pointer-events: none; }
#nav-toggle-btn { width: 60px; height: 60px; background-color: var(--page-color); border: 2px solid var(--border-subtle); border-radius: 50%; box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2); cursor: pointer; display: flex; justify-content: center; align-items: center; font-size: 2em; color: var(--accent-color); transition: transform 0.4s cubic-bezier(0.68, -0.55, 0.27, 1.55), box-shadow 0.3s ease; position: relative; z-index: 1001; pointer-events: auto; }
#nav-toggle-btn:hover { box-shadow: 0 6px 20px rgba(231, 178, 196, 0.8); }
#navigation-menu.is-open #nav-toggle-btn { transform: rotate(135deg); background-color: var(--accent-color); color: white; }
.nav-link { position: absolute; bottom: 5px; left: 5px; width: 50px; height: 50px; background: var(--page-color); border-radius: 50%; box-shadow: 0 2px 8px rgba(0,0,0,0.15); border: 1px solid var(--border-subtle); display: flex; justify-content: center; align-items: center; text-decoration: none; opacity: 0; transform: scale(0.5) translate(0, 0); pointer-events: none; transition: transform 0.3s cubic-bezier(0.68, -0.55, 0.27, 1.55), opacity 0.3s ease; }
#navigation-menu.is-open .nav-link { opacity: 1; pointer-events: auto; }
#navigation-menu.is-open #nav-story { transform: translate(120px, 0); transition-delay: 0.0s; }
#navigation-menu.is-open #nav-library { transform: translate(85px, -85px); transition-delay: 0.1s; }
#navigation-menu.is-open #nav-study { transform: translate(0, -120px); transition-delay: 0.2s; }
.nav-link .nav-text { position: absolute; left: 120%; background: var(--page-color); padding: 5px 12px; border-radius: 5px; color: var(--text-color); font-family: 'Cinzel Decorative', cursive; font-size: 0.9em; white-space: nowrap; opacity: 0; transition: opacity 0.2s ease; pointer-events: none; }
.nav-link:hover .nav-text { opacity: 1; transition-delay: 0.3s; }
.nav-link .nav-icon { font-size: 1.5em; color: var(--text-color); }
.nav-link.active .nav-icon { color: var(--accent-color); }
.nav-link.disabled { opacity: 0.4 !important; cursor: not-allowed; background-color: #e0e0e0; }
.nav-link.disabled:hover .nav-text { opacity: 0 !important; }
.nav-link.disabled:hover::after { content: attr(title); position: absolute; left: 120%; background-color: var(--text-color); color: var(--page-color); padding: 5px 10px; border-radius: 5px; font-size: 0.8em; font-family: 'Lora', serif; white-space: nowrap; z-index: 1001; }

/* --- Responsive Media Queries --- */

/* For Tablet Screens (e.g., iPads) */
@media (max-width: 1024px) {
    #finance-scene {
        justify-content: center;
    }

    #character-sprite {
        display: none;
    }

    #tools-panel {
        position: relative;
        top: auto;
        left: auto;
        transform: none;
        margin: 20px;
    }

    #story-overlay {
        justify-content: center;
        gap: 10px;
        padding: 20px;
    }

    #dialogue-sprite-container {
        height: 50vh;
        flex-shrink: 1;
    }

    #dialogue-box {
        max-width: 600px;
    }

    .modal-content {
        max-width: 90vw;
    }
}


/* For Mobile Screens (e.g., iPhones) */
@media (max-width: 768px) {
    body {
        overflow-y: auto;
    }

    #finance-scene {
        align-items: flex-start;
        padding-top: 5vh;
        height: auto;
        min-height: 100vh;
    }

    #tools-panel {
        width: 90%;
        padding: 20px;
        gap: 15px;
    }

    .tool-icon {
        width: 100%;
        padding: 15px;
    }

    #story-overlay {
        align-items: flex-end;
        padding: 15px;
    }

    #dialogue-sprite-container {
        display: none;
    }

    #dialogue-box {
        max-width: none;
        min-height: 180px;
        padding: 20px 25px;
    }

    #character-name { font-size: 1.3em; }
    #dialogue-text { font-size: 1.1em; }

    .modal-content {
        width: 95%;
        padding: 20px 25px;
    }

    .modal-content h2 {
        font-size: 1.5em;
        padding-bottom: 10px;
        margin-bottom: 20px;
    }

    .result-value {
        font-size: 1.4em;
    }

    #navigation-menu {
        bottom: 15px;
        left: 15px;
    }

    #nav-toggle-btn {
        width: 50px;
        height: 50px;
        font-size: 1.8em;
    }
}
