/* 8-bit/NES-inspired styling */
@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap');

:root {
    --bg-color: #1a1a2e;
    --text-color: #e6e6e6;
    --primary-color: #4d4dff;
    --secondary-color: #8080ff;
    --accent-color: #ff4d4d;
    --border-color: #33334d;
    --disabled-color: #555;
    --disabled-text-color: #999;
    --objectives-panel-bg: rgba(20, 20, 40, 0.85);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Press Start 2P', monospace;
    background-color: var(--bg-color);
    color: var(--text-color);
    font-size: 12px; /* ADDED: Base font size for the document */
    line-height: 1.6;
    padding: 10px;
    overflow-y: hidden; /* Prevent body scroll, internal areas will scroll */
    height: 100vh; /* Full viewport height */
    display: flex; /* For centering and controlling main layout children */
    flex-direction: column; /* Stack main layout and spotify player */
    /* ADD TOP PADDING TO ACCOUNT FOR FIXED MENU, if menu is always visible or to reserve space */
    /* padding-top: 50px; /* Adjust this based on final menu height */
}

/* Top Menu Styles */
#top-menu-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    background-color: var(--bg-color); /* Darker background for the menu bar itself */
    border-bottom: 2px solid var(--border-color);
    z-index: 1001; /* Above debug menu, above game content */
    padding: 5px 10px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
    display: flex; /* Added for layout of title and button */
    align-items: center; /* Vertically align title and button */
    justify-content: space-between; /* Push button to right, title to left */
}

#top-menu-title {
    font-size: 1.2em; /* Slightly larger than button */
    color: var(--primary-color);
    text-shadow: 2px 2px 0px #000;
    margin-right: auto; /* Pushes button to the right, if not using space-between */
    padding-left: 5px; /* Some padding from the edge */
}

#top-menu-toggle-button {
    background-color: var(--primary-color);
    color: var(--text-color);
    border: 1px solid var(--border-color);
    padding: 8px 12px;
    font-family: 'Press Start 2P', monospace;
    font-size: 0.9em;
    cursor: pointer;
    border-radius: 4px;
}

#top-menu-toggle-button:hover {
    background-color: var(--secondary-color);
}

#top-menu-content-wrapper {
    display: none; /* Initially hidden */
    flex-direction: row;
    justify-content: space-around;
    align-items: stretch; /* Make sections take full height of this container */
    background-color: rgba(30, 30, 50, 0.9); /* Slightly lighter than menu bar, but still dark */
    padding: 15px;
    /* margin-top: 5px; /* Space between button and content */
    border-radius: 0 0 8px 8px;
    border: 1px solid var(--border-color);
    border-top: none; /* As top border is from container */
    max-height: calc(100vh - 45px); /* Max height, increased from -60px */
    overflow-y: auto; /* Scroll if content exceeds max height */
    gap: 10px; /* Add gap between sections */
    /* Position this below the button/title bar */
    position: absolute; /* Take it out of flex flow of container */
    top: 100%; /* Position below the parent's bottom edge */
    left: 0;
    right: 0;
    width: auto; /* Let padding and parent define effective width */
    margin-left: 10px; /* Match container padding */
    margin-right: 10px; /* Match container padding */
    box-sizing: border-box; /* Ensure padding is included in width calculations */
}

#top-menu-container.open #top-menu-content-wrapper {
    display: flex;
}

.top-menu-section {
    padding: 10px;
    /* flex-basis: 30%; /* Distribute space, adjust as needed */
    /* min-width: 250px; /* Minimum width for each section */
    display: flex;
    flex-direction: column;
    border: 1px solid var(--primary-color); /* Clear border delimitations */
    background-color: rgba(20, 20, 35, 0.95); /* Darker than #top-menu-content-wrapper */
    border-radius: 4px;
    /* Remove generic flex-basis and min-width, apply them specifically below */
}

#top-menu-spotify-section {
    flex-basis: 25%;
    min-width: 500px; /* Adjusted min-width, consider Spotify embed needs */
}

#top-menu-objectives-section {
    flex-basis: 50%;
    min-width: 300px; /* Adjusted min-width */
}

#top-menu-main-controls-section {
    flex-basis: 25%;
    min-width: 180px; /* Adjusted min-width */
    align-items: center; /* Center button and status */
    justify-content: center; /* Center content vertically if needed, or use padding/margins */
}

.top-menu-section h4 {
    font-size: 1em;
    color: var(--primary-color);
    margin-bottom: 10px;
    text-align: center;
}

/* Removed .menu-emoji styles as emojis are removed from HTML */
/* .top-menu-section .menu-emoji {
    margin-right: 8px;
} */

/* Adjustments for moved elements inside the top menu */
#top-menu-spotify-section #embed-iframe {
    width: 100%;
    min-width: 280px; /* Ensure Spotify play button doesn't get squished */
    height: 80px; /* Default height for Spotify embed in this context */
    border: none;
    border-radius: 4px;
}

#top-menu-objectives-section #objectives-list {
    list-style: none;
    padding: 0;
    margin: 0;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    padding: 5px;
    border-radius: 4px;
    background-color: rgba(0,0,0,0.2);
    flex-grow: 1; /* Allow the list to grow and take available vertical space */
    height: 0; /* Works with flex-grow: 1 in a column flex container to fill space */
}

#top-menu-objectives-section #objectives-list li {
    font-size: 0.8em;
    margin-bottom: 6px;
    padding: 5px 8px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    display: flex; /* Ensure flex display */
    align-items: center; /* Vertically center marker with text */
    gap: 12px; /* Increased gap for more space between marker and text */
}
/* Styles for pending/completed objectives in the new menu are inherited if specific enough,
   or can be re-scoped if they were too tied to the old .objectives-panel */

#top-menu-main-controls-section #save-pdf-button {
    margin-top: 0; /* Reset margin if any from original context */
    margin-bottom: 10px; /* Space between button and status */
    width: auto; /* Allow button to size to content or be styled explicitly */
    padding: 8px 15px;
    /* Ensure hover doesn't change height - border was 2px, ensure it stays consistent or isn't added on hover only */
    border: 2px solid var(--border-color); /* Keep border consistent */
}

#top-menu-main-controls-section #save-pdf-button:hover {
    background-color: var(--primary-color); /* From .action-button:hover */
    /* Explicitly ensure border doesn't change on hover if it was the cause */
    border-color: var(--primary-color); /* Optional: match border to hover background */
}

#top-menu-main-controls-section #connection-status {
    width: 100%; /* Take full width for text-align center */
    text-align: center; /* Ensure text is centered */
    margin-top: 0;
    padding-bottom: 0; /* Reset padding */
    position: static; /* Reset positioning */
    background-color: transparent; /* No special background */
    font-size: 0.9em;
    align-self: center; /* Center button within the panel */
}

.main-layout-container {
    display: flex;
    flex-direction: row; /* Story content and objectives side-by-side */
    width: 100%;
    height: calc(100vh - 125px); /* 100vh - spotify_height - body_padding */
    flex-grow: 1; /* Allow this container to grow to fill space */
    /* ADD MARGIN TOP TO ACCOUNT FOR THE FIXED MENU BAR */
    margin-top: 20px; /* Adjust based on #top-menu-container's actual height */
}

.game-content-area {
    display: flex;
    flex-direction: column;
    flex-grow: 1; /* MODIFIED: Takes up remaining space */
    /* width: 70%; /* Example, adjust as needed */
    overflow: hidden; /* Prevent its own scrollbars, children will scroll */
    height: 100%; /* Full height of parent */
    /* border: 1px solid var(--border-color); /* REMOVED border */
    /* background-color: rgba(0,0,0,0.1); /* REMOVED background-color */
    padding-top: 25px; /* Add padding here if h1 is inside game-content-area but outside history-log */
}

.game-content-area h1 {
    margin-bottom: 10px; /* Adjusted margin */
    font-size: 1.2em; /* This will now be 1.2 * 12px = 14.4px */
    color: var(--primary-color);
    text-shadow: 2px 2px 0px #000;
    flex-shrink: 0;
    padding-left: 15px; /* Add padding here if h1 is inside game-content-area but outside history-log */
    padding-right: 15px;
    padding-top: 15px; /* Add padding here if h1 is inside game-content-area but outside history-log */
}

.history-log {
    width: 100%;
    display: flex;
    flex-direction: row;
    overflow-x: auto;   /* Horizontal scroll for turns */
    overflow-y: hidden; /* Individual turns will handle their vertical scroll if needed */
    flex-wrap: nowrap;
    /* padding: 10px; /* Padding can be on game-content-area or here */
    margin-bottom: 10px;
    flex-grow: 1; /* Allows history log to take available vertical space */
    align-items: stretch; /* Stretch turn containers vertically */
    border: 1px solid var(--border-color); /* Can be removed if game-content-area has border */
    background-color: rgba(0,0,0,0.55); /* Made EVEN DARKER */
    padding: 15px; /* ADDED padding here */
}

.turn-container {
    display: flex;
    flex-direction: column;
    min-width: 340px; 
    max-width: 480px; 
    flex-shrink: 0;
    gap: 10px;
    padding: 15px;
    margin-right: 15px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    background-color: var(--objectives-panel-bg); 
    overflow-y: auto; /* This enables vertical scroll for the turn container */
    height: 100%; 
}

.objectives-panel {
    /* display: none; /* Hide the old panel if not removed from HTML, or just remove its styles */
    /* Most styles here are now irrelevant or moved/adapted to .top-menu-section */
    /* width: 256px; */
    /* min-height: 512px; */
    /* background-color: var(--objectives-panel-bg); */
    /* border: 2px solid var(--border-color); */
    /* border-radius: 8px; */
    /* padding: 15px; */
    /* margin-left: 15px; */
    /* margin-top: 55px; */
    /* margin-bottom: 30px; */
    /* position: relative; */
    /* display: flex; */
    /* flex-direction: column; */
}

/* .objectives-panel h2 { ... } */ /* Title is now in .top-menu-section h4 */

/* #objectives-list related styles are now scoped to #top-menu-objectives-section #objectives-list */
/* #objectives-list { ... } */
/* #objectives-list li { ... } */

.objective-text-container {
    display: inline; /* Allow text parts to flow on the same line */
    /* flex-grow: 1; /* If needed to push against a fixed-width pseudo-element */
}

.objective-count {
    /* Styles for the (1/3) count, if any specific needed */
    /* e.g., color: var(--secondary-color); */
    margin-left: 4px; /* Space before the count */
}

#objectives-list li .partial-progress {
    font-size: 0.9em; 
    color: #aaa;
    /* display: block; /* Changed: Now part of the inline flow or can be span */
    display: inline; /* Keep it inline */
    margin-left: 4px; /* Space before partial progress text */
}

.status-container {
    flex-shrink: 0;
    padding-top: 10px;
    /* margin-bottom: 10px; /* Removed to allow button to be part of this block */
    text-align: center;
    display: flex; /* To arrange status and button */
    flex-direction: column; /* Stack them */
    align-items: center; /* Center button */
    gap: 10px; /* Space between status and button */
    /* NOTE: This container might be empty now as its children (button, status) moved. */
    /* Consider removing or repurposing .status-container if it's no longer needed. */
}

/* .action-button styles are general, but #save-pdf-button is now in #top-menu-main-controls-section */
/* #save-pdf-button specific adjustments are made under #top-menu-main-controls-section */
.action-button {
    background-color: var(--secondary-color);
    color: var(--text-color);
    border: none;
    padding: 8px 15px;
    font-family: 'Press Start 2P', monospace;
    font-size: 0.8em; 
    cursor: pointer;
    border: 2px solid var(--border-color);
    border-radius: 4px;
    transition: background-color 0.2s;
    margin-top: 15px; /* ADDED: Space above the button */
    margin-bottom: 10px; /* ADDED: Space below the button before connection status */
    width: calc(100% - 30px); /* Make it take panel width minus padding */
    align-self: center; /* Center button within the panel */
}

.action-button:hover {
    background-color: var(--primary-color);
    max-width: 600px; /* Max width for spotify */
    margin: 0 auto; /* Center it */
    flex-shrink: 0;
}

#embed-iframe { /* Spotify player */
    border-top: 3px solid var(--border-color);
    padding-top: 15px;
    width: 100%; 
    max-width: 600px; /* Max width for spotify */
    margin: 0 auto; /* Center it */
    flex-shrink: 0; 
    height: 105px; /* Fixed height for player */
}

/* Removed .debug-menu and related styles */
/*
.debug-menu {
    position: fixed;
    bottom: 20px;
    left: 20px;
    background-color: rgba(26, 26, 46, 0.95);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    padding: 15px;
    color: var(--text-color);
    font-family: 'Press Start 2P', monospace;
    z-index: 1000;
    display: none;
    min-width: 500px;
    min-height: 300px;
    max-width: 900px;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
    margin-bottom: 15px; 
}

.debug-menu h3 {
    font-size: 1.15em; 
    margin-bottom: 10px;
    color: var(--primary-color);
}

.debug-menu h4 {
    font-size: 1em; 
    margin-bottom: 8px;
    color: var(--secondary-color);
}

.debug-section {
    margin-bottom: 15px;
}
*/

#objectives-list li.completed {
    background-color: rgba(77, 255, 77, 0.1);
    border-color: #4dff4d;
}

#objectives-list li.completed::before {
    content: "✓";
    color: #4dff4d;
}

#objectives-list li.pending::before {
    content: "○";
    color: var(--accent-color);
    /* line-height: 1; /* May help with precise centering if font size differs greatly */
}

/* ADDED: Styling for the new "Connected" status in objectives panel */
/*
.objectives-connection-status {
    text-align: center;
    margin-bottom: 10px;
    color: var(--primary-color);
    font-size: 0.9em;
} 
*/

.turn-image-container {
    position: relative; 
    width: 360px; /* Changed from 320px */
    height: 360px; /* Changed from 320px */
    margin: 0 auto; /* Center if .turn-container is wider */
    background-color: #000; 
    display: flex; 
    align-items: center;
    justify-content: center;
    border: 2px solid var(--border-color);
    flex-shrink: 0; 
    overflow: hidden; /* Ensure image doesn't break out of fixed size */
}

.turn-image {
    display: block;
    /* Width and height will be constrained by the parent container */
    max-width: 100%;  /* Max width is 100% of container (512px) */
    max-height: 100%; /* Max height is 100% of container (512px) */
    width: auto;      /* Maintain aspect ratio if original is not square */
    height: auto;     /* Maintain aspect ratio if original is not square */
    object-fit: contain; /* Ensures the whole image fits, letterboxing if not square */
    image-rendering: pixelated;
    position: relative;
    z-index: 1;
    /* Ensure image error icon/tooltip is still working relative to this */
}

.turn-content {
    text-align: left;
    width: 360px; /* Changed from 320px */
    flex-grow: 1; /* Allow content to take remaining space and push for scroll */
    overflow-y: auto; /* Fallback scroll for content itself, if needed */
    display: flex; /* Added to manage children better */
    flex-direction: column; /* Stack narration and choices */
}

.turn-narration {
    width: 100%;
    font-size: 0.8em; /* CHANGED from 10px (now 9.6px) */
    letter-spacing: 0.5px;
    line-height: 1.6; /* Adjusted line height for smaller font */
    margin-bottom: 12px; /* Adjusted margin */
    white-space: pre-wrap; 
    overflow-wrap: break-word; 
    /* Ensure cursor styles are not affected or are adjusted */
}

.turn-choices {
    display: flex;
    flex-direction: column;
    gap: 10px; 
    flex-shrink: 0; /* Prevent choices from shrinking excessively */
}

.choice-button {
    background-color: var(--primary-color);
    color: var(--text-color);
    border: none;
    padding: 7px 10px; /* Adjusted padding for smaller font */
    font-family: 'Press Start 2P', monospace;
    font-size: 0.7em; /* CHANGED from 9px (now 8.4px) */
    cursor: pointer;
    border: 2px solid var(--border-color);
    transition: background-color 0.2s;
    text-align: left;
    width: 100%;
    line-height: 1.5; /* Added line-height for button text */
    /* Ensure these styles are sufficient for buttons in their new context if any were choice-specific */
}

.choice-button:hover:not(:disabled) {
    background-color: var(--secondary-color);
}

.choice-button:active:not(:disabled) {
    transform: scale(0.98);
}

.choice-button:disabled {
    background-color: var(--disabled-color);
    color: var(--disabled-text-color);
    cursor: default;
    border-color: #444;
}

/* Highlight selected choice button */
.choice-button.selected {
    background-color: var(--accent-color);
    color: var(--text-color);
    border-color: var(--accent-color);
}

/* .connection-status is now in #top-menu-main-controls-section, adjusted there */
.connection-status {
    /* font-size: 1em; */ /* Styles are now in #top-menu-main-controls-section #connection-status */
    /* color: var(--accent-color); */
    /* text-align: center; */
    /* position: static; */
    /* width: 100%; */
    /* margin-top: auto; */
    /* padding-bottom: 0; */
}

/* Blinking Cursor */
@keyframes blink {
    0% { opacity: 1; }
    50% { opacity: 0; }
    100% { opacity: 1; }
}

.cursor {
    display: inline-block;
    width: 0.7em; /* Adjusted width for smaller font */
    height: 1.1em; /* CHANGED from 13px */
    background-color: var(--text-color);
    animation: blink 1s infinite;
    margin-left: 1px;
    vertical-align: baseline;
}

/* Desktop Adjustments */
@media (min-width: 768px) {
    .turn-container {
        max-width: 500px;
    }
    /* Removed .objectives-panel specific media query */
    .turn-narration {
        font-size: 0.8em; /* CHANGED from 12px (now 12px) */
        line-height: 1.7;
    }
    .choice-button {
        font-size: 0.75em; /* CHANGED from 10px (now 9px) */
        padding: 8px 12px; /* Adjusted padding */
        line-height: 1.5; /* Added line-height for button text for larger screens */
    }
    .connection-status {
        font-size: 1.1em; /* CHANGED from 14px (now 13.2px) */
    }
    .cursor {
        width: 0.7em; /* Adjusted width */
        height: 1.1em; /* CHANGED from 14px (Adjusted to match typical desktop narration font) */
    }
    #objectives-list li {
        font-size: 0.8em; /* Base size is 12px, so this is 9.6px. User wanted smaller. */
        padding: 6px 10px; /* Adjusted padding for desktop */
    }
    #objectives-list li .objective-text-container {
        /* No specific style change needed for desktop, inherits from base */
    }
    #objectives-list li .objective-count {
        /* No specific style change needed for desktop */
    }
    #objectives-list li .partial-progress {
        font-size: 0.9em; /* Relative to its parent li's text */
    }

    /* Adjustments for top menu on larger screens */
    #top-menu-content-wrapper {
        /* Could allow more items per row or adjust section widths */
        flex-wrap: nowrap; /* Prevent wrapping if not desired */
    }
    .top-menu-section {
        min-width: 200px; /* Adjust min-width */
        flex-basis: auto; /* Allow natural sizing or more specific flex-grow/shrink */
    }
    #top-menu-spotify-section #embed-iframe {
        height: 80px; /* Consistent height */
    }
    #top-menu-objectives-section #objectives-list {
        /* max-height: 250px; /* Slightly more height for objectives list */ 
        /* flex-grow: 1; and height: 0; should handle this dynamically */
    }
} 

/* Pixel-art loader */
.pixel-loader {
    z-index: 10; /* keep loader on top */
    width: 32px; /* Doubled size */
    height: 32px; /* Doubled size */
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.pixel-loader div {
    width: 8px; /* Doubled size */
    height: 8px; /* Doubled size */
    background: var(--primary-color);
    position: absolute;
    top: 12px;  /* Adjusted for new size: (32-8)/2 */
    left: 12px; /* Adjusted for new size: (32-8)/2 */
    box-shadow: 
        12px  0px 0 var(--primary-color), /* E */
        12px  12px 0 var(--primary-color), /* SE */
        0px   12px 0 var(--primary-color), /* S */
        -12px 12px 0 var(--primary-color), /* SW */
        -12px 0px  0 var(--primary-color), /* W */
        -12px -12px 0 var(--primary-color),/* NW */
        0px   -12px 0 var(--primary-color),/* N */
        12px  -12px 0 var(--primary-color);/* NE */
    animation: spin-pixel 1s linear infinite;
    image-rendering: pixelated;
}

@keyframes spin-pixel {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
} 

/* Markdown bold styling */
.md-bold {
    font-weight: bold;
    color: yellow;
}

/* Style for image loading error indicator */
.image-error-icon {
    position: absolute;
    top: 5px;
    right: 5px;
    font-size: 1.5em;
    cursor: pointer;
    z-index: 20;
    background-color: rgba(0, 0, 0, 0.5); /* Slight background for visibility */
    padding: 2px 4px;
    border-radius: 3px;
}

/* Style for image error tooltip */
.image-error-tooltip {
    position: absolute;
    top: 30px; /* Position below the icon */
    right: 5px;
    background-color: rgba(0, 0, 0, 0.85);
    color: var(--accent-color);
    border: 1px solid var(--border-color);
    padding: 8px;
    border-radius: 4px;
    font-size: 11px; /* Smaller font for tooltip */
    font-family: monospace; /* Use a basic font */
    max-width: 250px;
    z-index: 30;
    display: none; /* Controlled by JS */
    text-align: left;
    line-height: 1.4;
}

/* Game End Message Styling */
.game-end-message {
    color: var(--accent-color); /* Red */
    font-family: 'Press Start 2P', monospace;
    font-size: 1.8em; /* Larger font size */
    text-align: center;
    padding: 20px 0;
    font-weight: bold;
    text-shadow: 2px 2px 0px #000; /* Optional: Add a little shadow like h1 */
}

/* CSS for menu button blink */
@keyframes blink-attention-animation {
    0%, 100% { background-color: var(--primary-color); box-shadow: none; }
    50% { background-color: var(--accent-color); box-shadow: 0 0 8px var(--accent-color); }
}

#top-menu-toggle-button.blink-attention {
    animation: blink-attention-animation 0.3s 2; /* 0.3s per blink, 2 times = 0.6s total */
} 