body {
    background-color: #000;
    color: #fff;
    font-family: "Noto Sans", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
    margin: 0;
    padding: 16px;
    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: "Noto Sans", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
    color: #12202b;
    background-color: #f6f8fa;
    border: 1px solid #e3e7ea;
    padding: 10px 12px;
    margin: 6px 0;
    cursor: pointer;
    box-sizing: border-box;
    border-radius: 8px;
    width: auto;
    outline: none;
    transition: background-color .12s ease, transform .06s ease;
}

button:hover:not(:disabled) { background-color: #eef3f6; transform: translateY(0); }
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.6; 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;
}

/* Responsive adjustments */
@media (max-width: 900px) {
    body { padding: 12px; }
    #editor-container { padding: 10px; }
    #game-submenus { flex-direction: row; gap: 6px; }
    #game-submenus button { flex: 1 1 40%; font-size: 0.95rem; padding: 10px; }
    .button-link-editor, .input-field-editor, .foreground-image-editor { padding: 10px; border-radius: 10px; }
    #player-container { padding: 10px; }
}

/* Accessibility & contrast tweaks for small screens */
@media (max-width: 420px) {
    button { padding: 12px 10px; font-size: 1rem; border-radius: 10px; }
    .player-input-save-btn { width: 86px; font-size: 0.95rem; }
    #player-screen-text { font-size: 1rem; line-height: 1.5; }
}

/* NEW: Design presets used by the player/editor runtime */
.design-layout-stack .player-screen-content-wrapper { flex-direction: column; }
.design-layout-split .player-screen-content-wrapper { flex-direction: row; gap: 16px; align-items:flex-start; }
.design-layout-split #player-screen-text { flex:1; order:0; }
.design-layout-split #player-buttons { flex:0 0 260px; order:1; }

.design-layout-centered { display:flex; justify-content:center; align-items:flex-start; }
.design-layout-centered .player-screen-content-wrapper { max-width:720px; margin:0 auto; }

.design-layout-columns .player-screen-content-wrapper { display:grid; grid-template-columns: 1fr 1fr; gap:12px; align-items:start; }

/* Button style presets */
.btnstyle-rounded .player-button { border-radius: 14px; padding: 12px 14px; background:#0044cc; color:#fff; border: none; }
.btnstyle-flat .player-button { border-radius:6px; background:transparent; border:1px solid #ccc; color:inherit; padding:10px; }
.btnstyle-outline .player-button { background:transparent; border:2px solid currentColor; padding:10px; border-radius:8px; }
.btnstyle-glass .player-button { background: rgba(255,255,255,0.06); border:1px solid rgba(255,255,255,0.08); backdrop-filter: blur(4px); padding:10px; border-radius:12px; }

/* Variable primary color usage (applied inline via style attribute by JS) */
.player-button[data-primary] { color: white; }

/* Numbered choice mode small input */
.player-choice-number-wrapper { display:flex; gap:8px; align-items:center; margin:8px 0; }
.player-choice-number-wrapper input[type="number"] { width:72px; padding:8px; border-radius:8px; border:1px solid #ccc; }

/* Ensure presets are mobile-friendly */
@media (max-width: 700px) {
    .design-layout-split .player-screen-content-wrapper,
    .design-layout-columns .player-screen-content-wrapper { grid-template-columns: 1fr; flex-direction: column; }
}