body {
    background-color: #000;
    color: #FFF;
    font-family: monospace; /* A simple, classic look */
    margin: 0;
    padding: 10px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
}

#app {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
}

/* General UI elements */
button, input[type="text"], textarea, select {
    font-family: monospace;
    color: #FFF;
    background-color: #000;
    border: 1px solid #FFF; /* Subtle border for visibility */
    padding: 8px 12px;
    margin: 5px 0;
    cursor: pointer;
    box-sizing: border-box;
    width: 100%; /* Mobile friendly */
    outline: none;
    touch-action: manipulation; /* Optimize for touch input */
}

button:hover:not(:disabled) {
    background-color: #333; /* Slight visual feedback */
}

button:disabled {
    opacity: 0.5;
    cursor: default;
}

/* Editor Specific Styles */
#editor-container, #player-container {
    padding: 10px 0;
}

#editor-text {
    width: 100%;
    max-width: 100%;
    margin-bottom: 15px;
    box-sizing: border-box;
}

.screen-list button {
    text-align: left;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding: 10px;
}

.button-link-editor {
    display: flex;
    flex-direction: column; /* Stack inputs vertically for better mobile control */
    gap: 0;
    margin-bottom: 15px;
    padding: 10px;
    border: 1px dashed #444; /* Visual grouping */
    position: relative;
}

.button-link-editor h5 {
    margin: 0 0 5px 0;
    border-bottom: 1px solid #444;
    padding-bottom: 5px;
}

.button-link-editor label {
    display: block;
    margin-top: 5px;
    font-size: 0.9em;
    color: #AAA;
}

.button-link-editor input[type="text"], 
.button-link-editor input[type="number"], 
.button-link-editor select {
    width: 100%; 
    margin-top: 2px;
    margin-bottom: 5px;
    padding: 6px;
    box-sizing: border-box;
    /* Reset background/color for specific controls */
    background-color: #000;
    color: #FFF;
    border: 1px solid #FFF;
}

/* Styles for the new Input Field Editor */
.input-field-editor {
    display: flex;
    flex-direction: column; 
    gap: 0;
    margin-bottom: 15px;
    padding: 10px;
    border: 1px dashed #08F; /* Visual grouping for inputs */
    position: relative;
}

/* Make condition list container scrollable on mobile */
#condition-list-container {
    max-height: 40vh; /* Set a maximum height */
    overflow-y: auto; /* Enable vertical scrolling */
    padding: 5px;
    border: 1px solid #333;
    margin-top: 10px;
}

/* Ensure the flex containers inside work well */
.button-link-editor div[data-property] {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    align-items: center;
    margin-bottom: 5px;
    margin-top: 5px;
}

.button-link-editor div[data-property] input,
.button-link-editor div[data-property] select {
    margin: 0; /* Remove vertical margin interference */
    flex-grow: 1;
    min-width: 60px; /* Smallest input size on mobile */
}

.delete-button-editor {
    background-color: transparent !important; /* Make it look less like a main button */
    color: #F00;
    border: 1px solid #F00;
    width: 100%; /* Full width on mobile */
    max-width: 150px;
    align-self: flex-start;
    margin-top: 10px;
    padding: 5px;
}

/* NEW Styles for Image Management (Editor) */
.image-asset-preview {
    max-width: 100%;
    max-height: 150px; /* Keep preview small */
    object-fit: contain;
    border: 1px solid #666;
    margin: 5px 0;
    display: block;
}

.foreground-image-editor {
    display: flex;
    flex-direction: column; 
    gap: 0;
    margin-bottom: 15px;
    padding: 10px;
    border: 1px dashed #F80; /* Visual grouping for images */
    position: relative;
}

.foreground-image-editor select,
.foreground-image-editor input[type="text"] {
    width: 100%;
}

/* NEW Styles for Sound Management (Editor) */
#editor-sound-assets-list {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.sound-asset-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 5px;
    border: 1px solid #333;
    font-size: 0.9em;
}

.sound-asset-item button {
    width: auto;
    padding: 4px 8px;
    font-size: 0.8em;
    margin: 0;
    margin-left: 10px;
}

/* Player Specific Styles */

/* NEW: Player content wrapper for flex ordering */
.player-screen-content-wrapper {
    display: flex;
    flex-direction: column;
    flex-grow: 1;
}

#player-screen-text {
    white-space: pre-wrap;
    padding: 8px 0; /* reduced padding so text doesn't create large empty area */
    line-height: 1.5;
    min-height: 40px; /* reduced from 100px so text only takes necessary space */
    flex-grow: 0;
    overflow-y: auto; /* Retain overflow */
    order: 0; /* Default order */
    position: relative;
}

/* Style for player input form */
#player-input-form input {
    width: 100%;
    margin-top: 5px;
    margin-bottom: 5px;
    padding: 8px 12px;
    font-family: monospace;
    color: #FFF;
    background-color: #000;
    border: 1px solid #FFF;
    box-sizing: border-box;
}

/* NEW: Input group structure for inline save button */
.player-input-button-wrapper {
    display: flex;
    gap: 5px; /* Space between input and button */
    align-items: center;
    margin-bottom: 10px;
}

/* Ensure the input element takes most of the space within the flex group */
.player-input-button-wrapper input[type="text"],
.player-input-button-wrapper input[type="number"] {
    flex-grow: 1;
    width: auto; /* Override 100% width default */
    margin: 0; /* Remove vertical margin interference */
}

/* Style the save button */
.player-input-save-btn {
    flex-shrink: 0;
    width: 80px; /* Fixed width for SAVE button on mobile */
    margin: 0;
    padding: 8px 5px;
    font-size: 0.8em;
    background-color: #040;
    border-color: #0F0;
}

.player-input-save-btn:hover:not(:disabled) {
    background-color: #080 !important;
}

#player-variables {
    border: 1px solid #444;
    padding: 10px;
    margin-bottom: 10px;
}

#player-variables h4 {
    color: #0F0; /* Green highlight for variables */
    margin: 0;
}

#player-variables ul {
    margin: 5px 0 0 0;
    padding: 0;
}

#player-variables li {
    font-size: 0.9em;
    line-height: 1.2;
    color: #AAA;
}

#player-container {
    /* Ensure player-status can contain floated elements */
    overflow: hidden; 
    
    /* NEW: Fullscreen attempt for player mode */
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    padding: 10px;
    background-color: #000;
    z-index: 1000; /* Ensure it covers everything */
    box-sizing: border-box;
    /* Ensure children are column stacked (status, variables, content wrapper) */
    flex-direction: column;
}

#player-status {
    /* Ensure status text and button are on one line */
    display: flex; 
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    padding-bottom: 5px;
    border-bottom: 1px dashed #444;
}

/* HIDE SCREEN ID in player mode as requested by user */
#player-current-screen-id {
    display: none; 
}

#player-status span {
    flex-grow: 1;
}

#player-stats-menu-btn {
    width: auto; /* Override 100% width rule for buttons */
    margin-left: 10px;
    padding: 5px 10px;
    font-size: 0.8em;
}

/* NEW: Styles for image rendering in Player mode */
.player-image-container {
    max-width: 100%;
    height: auto;
    margin: 10px 0;
    text-align: center;
}

.player-image-container img {
    max-width: 100%;
    height: auto;
}

/* Use flex order properties for above/below placement within player-content-wrapper */
.placement-above {
    order: -1; 
}

.placement-below {
    order: 1; 
}

/* Ensure player text comes before below images and buttons */
#player-screen-text {
    order: 0;
}

/* Force buttons to render after below-images */
#player-buttons {
    order: 2;
}

/* Background image style applied to the player container */
.has-background-image {
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    background-attachment: fixed; /* Optional: Makes BG look better when scrolling content */
}

.player-button {
    text-align: left;
    margin-bottom: 10px;
}

/* --- Dialog and Toast Styles (NEW) --- */

#toast-container {
    position: fixed;
    top: 10px;
    right: 10px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 3000; /* Above modal overlay */
    max-width: 90%; /* Mobile friendly */
}

.toast {
    background-color: #333;
    color: #FFF;
    padding: 10px 15px;
    border-radius: 5px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    opacity: 0;
    transform: translateY(-10px);
    transition: opacity 0.3s ease, transform 0.3s ease;
    min-width: 200px;
    font-size: 0.9em;
    border-left: 5px solid;
}

.toast.error {
    background-color: #800;
    border-color: #F00;
}

.toast.success {
    background-color: #040;
    border-color: #0F0;
}

.toast.warning {
    background-color: #880;
    border-color: #FF0;
    color: #000;
}

/* Custom Modal/Dialog Styles */

.custom-dialog-box {
    background-color: #111;
    border: 2px solid #FFF;
    padding: 20px;
    max-width: 90%;
    max-height: 90vh; /* Max height for modal */
    overflow-y: auto; /* Allow scrolling inside the modal */
    width: 90%;
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
}

.custom-dialog-box p {
    margin-top: 0;
    margin-bottom: 15px;
    line-height: 1.4;
}

.custom-dialog-box input[type="text"] {
    width: 100%;
    margin-bottom: 0; /* Handled by button wrapper gap */
}

.custom-dialog-box button {
    width: auto; /* Allow buttons to size based on content */
    flex-grow: 1;
}

.custom-dialog-box .confirm-btn {
    background-color: #040;
    border-color: #0F0;
}

.custom-dialog-box .cancel-btn {
    background-color: #400;
    border-color: #F00;
}

/* New placement classes for clarity */
.placement-below-text {
    order: 1; /* sits after the text (text is order:0) and before buttons (buttons order:2) */
    margin-top: 8px;
}

.placement-below-buttons {
    order: 3; /* sits after buttons which use order:2 */
    margin-top: 8px;
}