/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: "Helvetica", "Arial", "Liberation Sans", sans-serif;
}

html, body {
    height: 100%;
    background-color: #333;
    color: white;
}

/* Main Layout Container */
.container {
    display: flex;
    height: 100vh;
    width: 100vw;
    position: relative;
    overflow: hidden; /* Hide overflow for desktop */
}

/* --- NEW: Mobile Header Styles --- */
.mobile-header {
    display: none; /* Hidden on desktop */
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 50px; /* Standard header height */
    background-color: #222;
    border-bottom: 1px solid #444;
    z-index: 1001; /* Below hamburger button if it were separate, above content */
    padding: 0 10px;
    align-items: center; /* Vertically center items */
}
.mobile-header .hamburger-button {
    position: static; /* Override fixed position from original rule */
    display: block; /* Ensure it's visible */
    background: none;
    border: none;
    font-size: 1.8em;
    padding: 5px;
    margin-right: 10px;
    color: white; /* Ensure color */
    cursor: pointer;
    line-height: 1;
}
.mobile-header .mobile-title {
    font-size: 1.1em;
    font-weight: bold;
    color: #eee;
    line-height: 50px; /* Match header height */
    margin: 0;
    white-space: nowrap; /* Prevent wrapping */
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Sidebar (Controls) - DESKTOP STYLES */
.sidebar {
    width: 320px;
    flex-shrink: 0;
    background-color: #222;
    display: flex; /* Use flex for vertical distribution */
    flex-direction: column;
    height: 100%;
    z-index: 10;
    position: relative;
    transition: transform 0.3s ease-in-out;
    overflow: hidden; /* Prevent scrollbar on sidebar itself */
}
.desktop-title { /* Show desktop title, hide mobile */
    display: block;
    text-align: center;
    margin-bottom: 0.5em;
}
.mobile-title { /* Hide mobile title on desktop */
    display: none;
}


.tool-header {
    margin-bottom: 1em;
    flex-shrink: 0;
    padding: 1em 1em 0 1em; /* Add padding here */
}
.mode-selector {
    display: flex;
    justify-content: space-around;
    margin-bottom: 1em;
}
.mode-button {
    flex-grow: 1;
    padding: 0.5em;
    border: 1px solid #555;
    background-color: #444;
    color: #ccc;
    cursor: pointer;
    text-align: center;
    border-radius: 3px;
    margin: 0 0.25em;
    transition: background-color 0.2s ease, color 0.2s ease;
    font-size: 0.9em;
}
.mode-button:hover { background-color: #555; }
.mode-button.active { background-color: #54afff; color: white; border-color: #54afff; font-weight: bold; }

/* Control Panels */
.controls-panel {
    display: none;
    flex-grow: 1; /* Allow panel to take up space */
    flex-direction: column; /* Stack options container and button wrap */
    min-height: 0; /* Required for flex children scrolling */
    overflow: hidden; /* Hide overflow for the panel itself */
}
.controls-panel.active { display: flex; }

.optionscontainer {
    overflow-y: auto; /* Scroll options */
    flex-grow: 1; /* Take available space */
    padding: 0 1em 1em 1em; /* Adjust padding */
    min-height: 0; /* Required for scrolling */
}

/* Options Styling */
.option { position: relative; margin-top: 1em; padding-bottom: 0.5em; border-bottom: 1px solid #444; }
.option:last-child { border-bottom: none; padding-bottom: 0; }
.optiontitle { font-weight: bold; margin-bottom: 0.3em; display: block; font-size: 0.95em; }
.option small { color: #bbb; font-size: 0.8em; display: block; margin-top: 0.2em; line-height: 1.3; }

/* Input field styling */
.sidebar input[type="file"],
.sidebar input[type="number"],
.sidebar input[type="color"],
.sidebar select,
.sidebar button { padding: 0.4em; background-color: #333; color: white; border: 1px solid #555; border-radius: 3px; margin-top: 0.2em; font-size: 0.9em; vertical-align: middle; }
.sidebar input[type="file"],
.sidebar input[type="number"],
.sidebar select { width: 100%; }
.sidebar input[type="checkbox"] { width: auto; height: 1.2em; width: 1.2em; vertical-align: middle; margin-left: 0.5em; flex-shrink: 0; }
.sidebar input[type="range"] { width: 100%; margin: 0.5em 0; vertical-align: middle; }
.sidebar input[type="color"].color-input { width: calc(100% - 3.5em); padding: 0.3em; height: 2.2em; }
.sidebar label { display: inline-block; vertical-align: middle; padding-right: 0.5em; }

.option.single { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; }
.option.single .optiontitle, .option.single label { margin-bottom: 0; }
.option.single .optionbox { margin-left: auto; flex-shrink: 0; }
.option.single input[type="number"].optionbox { width: 4.5em; text-align: right; }
.option.multiple .optionbox { width: 100%; }

.rangeFlex { display: flex; align-items: center; justify-content: space-between; gap: 0.5em; }
.rangeFlex > input[type=range] { flex-grow: 1; margin: 0; }
.rangeFlex small { flex-shrink: 0; color: #aaa; font-size: 0.8em; }

.reset-btn, .zoom-button { cursor: pointer; display: inline-block; margin-left: 0.5em; font-weight: bold; color: #aaa; user-select: none; background: none; border: none; padding: 0; font-size: 1em; vertical-align: middle; }
.reset-btn:hover, .zoom-button:hover { color: #fff; }

.extrasContainer { display: flex; align-items: center; gap: 0.5em; }
.extrasContainer > select { flex-grow: 1; }
.extrasContainer > button.extra-run-btn { width: 2.5em; height: 2.5em; padding: 0.3em; border: 1px solid white; color: white; background-color: #444; flex-shrink: 0; }
.extrasContainer > button.extra-run-btn:hover { background-color: #555; }
.color-picker-btn { padding: 0.4em 0.6em; border: 1px solid white; margin-left: 0.5em; color: white; background-color: #444; cursor: pointer; height: 2.2em; }
.color-picker-btn:hover { background-color: #555; }

/* --- UPDATED: Button Wrap for Persistent Bottom Position --- */
.buttonwrap {
    padding: 1em; /* Padding around buttons */
    flex-shrink: 0; /* Prevent shrinking */
    border-top: 1px solid #444; /* Separator */
    background-color: #222; /* Ensure background */
}
.action-button { width: 100%; padding: 0.8em; font-size: 1em; font-weight: bold; border: 1px solid #54afff; border-radius: 3px; color: white; background-color: #54afff; cursor: pointer; transition: background-color 0.2s ease; margin-bottom: 0.5em; display: block; }
.action-button:last-child { margin-bottom: 0; }
.action-button:hover { background-color: #4aa0ef; }
.action-button.secondary { background-color: #555; border-color: #777; }
.action-button.secondary:hover { background-color: #666; }

.bottombuttons { display: flex; gap: 0.5em; }
.bottombuttons .action-button { width: 50%; margin-bottom: 0; }
#confirm { text-align: center; }
#confirm .optiontitle { margin-bottom: 0.5em; }
#confirm .action-button { width: calc(50% - 0.25em); display: inline-block; margin: 0 0.125em; }

/* --- UPDATED: Zoom Indicator --- */
.zoomindicator {
    padding: 1em;
    border-top: 1px solid #444;
    flex-shrink: 0; /* Prevent shrinking */
    background-color: #222; /* Ensure background */
    font-size: 0.9em;
    color: #ccc;
    user-select: none;
    position: relative; /* For positioning the toggle */
    line-height: 1.5; /* Better spacing */
}
.zoomindicator #zoom { font-weight: bold; color: white; display: inline-block; min-width: 2.5em; text-align: right; }
.zoom-button { font-size: 1.2em; padding: 0 0.3em; line-height: 1; }
.zoom-pixelated-toggle { position: absolute; right: 1em; /* Use padding */ top: 0.8em; display: inline-flex; align-items: center; }
.zoom-pixelated-toggle input[type="checkbox"] { margin: 0 0.3em 0 0; height: 1em; width: 1em; }
.zoom-pixelated-toggle label { vertical-align: middle; font-size: 0.9em; cursor: pointer; color: #ccc; }
.zoom-pixelated-toggle label:hover { color: white; }

/* Main Content Area (Image Display) */
.main-content { flex-grow: 1; height: 100%; overflow: auto; position: relative; padding: 1em; background-color: #3a3a3a; min-width: 0; }
#imageContainer { position: relative; margin: 0; width: max-content; height: max-content; border: 1px dashed #555; }
#imageContainer > img, #imageContainer > canvas { position: absolute; top: 0; left: 0; display: block; max-width: none !important; }
.pixelated { image-rendering: -webkit-optimize-contrast; image-rendering: -moz-crisp-edges; image-rendering: crisp-edges; image-rendering: pixelated; }
#window { /* Styles defined inline in HTML */ }
#windowSize { /* Styles defined inline in HTML */ }

/* Hamburger Button Styles - Original fixed button is hidden */
.hamburger-button { display: none; }

/* Overlay Styles */
.sidebar-overlay { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.5); z-index: 999; }
.sidebar-overlay.active { display: block; }

/* --- NEW: Mobile Action Bar Styles --- */
.mobile-action-bar {
    display: none; /* Hidden on desktop */
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    background-color: #222;
    border-top: 1px solid #444;
    padding: 0.5em;
    z-index: 998; /* Below overlay/sidebar */
    text-align: center; /* Center single buttons */
}
.mobile-action-bar .action-button {
    margin: 0.25em; /* Space around buttons */
    width: auto; /* Allow buttons to size naturally */
    min-width: 100px; /* Ensure minimum tap target */
    display: inline-block; /* Allow side-by-side */
    padding: 0.6em 1em; /* Adjust padding */
}
/* Style for mobile confirm buttons */
#mobile-confirm-buttons {
    display: flex; /* Use flex for side-by-side */
    justify-content: space-around;
    width: 100%;
}
#mobile-confirm-buttons .action-button {
    width: 45%; /* Adjust width */
    margin: 0;
}


/* --- Mobile Responsiveness --- */
@media (max-width: 768px) {
    html, body { overflow-y: auto; height: auto; }

    .container {
        display: block;
        height: auto;
        min-height: 100vh;
        padding-top: 50px; /* Add padding for fixed mobile header */
        padding-bottom: 60px; /* Add padding for fixed mobile action bar (adjust height as needed) */
        overflow: visible; /* Allow content to scroll */
    }

    .mobile-header { display: flex; }
    .desktop-title { display: none; }
    .mobile-title { display: block; } /* Show mobile title */

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        width: 280px; max-width: 85%;
        transform: translateX(-100%);
        z-index: 1000;
        overflow-y: auto;
        box-shadow: 3px 0px 15px rgba(0,0,0,0.3);
        /* --- ADDED PADDING TOP --- */
        padding: 50px 0 0 0; /* Add top padding equal to mobile header height, remove others */
        background-color: #222; /* Ensure background */
        transition: transform 0.3s ease-in-out;
        display: flex;
        flex-direction: column;
    }
    .sidebar.sidebar-open { transform: translateX(0); }

    /* --- Adjust padding for children within mobile sidebar --- */
    .tool-header {
         padding: 1em; /* Re-apply side/bottom padding */
         margin-bottom: 0; /* Reduce bottom margin if needed */
         border-bottom: 1px solid #444; /* Optional: add separator */
    }
    .optionscontainer {
        padding: 0 1em 1em 1em; /* Keep side/bottom padding */
    }
     .buttonwrap {
        padding: 1em; /* Keep padding */
    }
     .zoomindicator {
        padding: 1em; /* Keep padding */
    }


    .main-content {
        width: 100%;
        height: auto; /* Auto height */
        min-height: calc(100vh - 50px - 60px); /* Adjust min height */
        padding: 0.5em;
        margin-left: 0;
        overflow: visible; /* Let container handle scrolling */
    }

    .mobile-action-bar { display: block; }

    /* --- Mobile adjustments for controls inside sidebar --- */
    .option.single { flex-direction: column; align-items: flex-start; }
    .option.single .optiontitle, .option.single label { margin-bottom: 0.3em; padding-right: 0; }
    .option.single .optionbox { margin-left: 0; width: auto; }
    .option.single input[type="number"].optionbox { width: 6em; }
    .option.single input[type="checkbox"].optionbox { margin-left: 0; }

    .rangeFlex { flex-direction: column; align-items: stretch; }
    .rangeFlex input[type=range] { order: 2; margin: 0.5em 0; }
    .rangeFlex small { order: 1; text-align: center; width: 100%; }
    .rangeFlex small:first-of-type { display: none; }
    .rangeFlex small:last-of-type { display: none; }
}