*,
*::before,
*::after {
    box-sizing: border-box;
}

body,
html {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    overflow: hidden;
    background: #121212;
    color: #e0e0e0;
}

header {
    background-color: #1e1e1e;
    height: 48px;
    padding: 0 12px;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.7);
    user-select: none;
}

header h1 {
    margin: 0;
    font-weight: 600;
    color: #fff;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    white-space: nowrap;
}

header button {
    background: #333;
    color: #fff;
    border: none;
    width: 40px;
    height: 40px;
    font-size: 1.5rem;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.3s ease;
    margin-left: 6px;
    margin-right: 6px;
}

#toggle-slicer-settings {
    margin-left: auto;
    /* This pushes the button to the far right */
    position: static;
    /* Override absolute positioning */
}

header button:hover,
header button:focus {
    background: #555;
    outline: none;
}

.menu-box {
    position: absolute;
    top: 56px;
    left: 12px;
    z-index: 20;
    background: #2a2a2a;
    padding: 12px 14px;
    border-radius: 12px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.6);
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 280px;
    max-width: 90vw;
    transition: opacity 0.3s ease, transform 0.3s ease;
    box-sizing: border-box;
    scrollbar-color: #555 #2a2a2a;
    scrollbar-width: thin;
}

.menu-box.hidden {
    opacity: 0;
    pointer-events: none;
    transform: translateY(-15px);
}

.menu-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    width: 100%;
    box-sizing: border-box;
    margin-bottom: 8px;
    /* extra breathing space between rows */
}

.menu-row label {
    flex: 0 0 120px;
    text-align: left;
    font-size: 0.95rem;
    color: #ccc;
}

.menu-row input[type="number"] {
    flex: 1;
    padding: 6px 8px;
    border-radius: 6px;
    background-color: #444;
    border: none;
    color: white;
    font-size: 0.95rem;
    width: 100%;
    box-sizing: border-box;
}

.menu-row button {
    flex: 1;
    padding: 10px 14px;
    background: #444;
    color: white;
    font-size: 0.95rem;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.menu-row button:hover {
    background-color: #555;
}

.menu-row>label[for="render-cylinders"] {
    flex: 0 0 120px;
    /* label fixed width */
    text-align: left;
    color: #ccc;
}

.menu-row>label[for="render-cylinders"]+.switch-container {
    flex-shrink: 0;
}

.switch-container {
    position: relative;
    width: 50px;
    /* original width */
    height: 26px;
    /* original height */
    flex-shrink: 0;
    /* don’t let flex make it smaller or bigger */
    flex-grow: 0;
    /* prevent growing */
    flex-basis: auto;
    /* use natural width */
}

/* Also, to avoid it stretching inside the flex container */
.menu-row {
    align-items: center;
    gap: 10px;
}

/* Label for the switch */
.menu-row>label {
    flex: 1 0 auto;
    /* Let label take remaining space */
    color: #ccc;
}

/* Make sure the switch container stays its own size */
.menu-row>label+.switch-container {
    flex: 0 0 50px;
}



.switch-container input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #555;
    transition: 0.4s;
    border-radius: 26px;
}

.slider::before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: 0.4s;
    border-radius: 50%;
}

.switch-container input:checked+.slider {
    background-color: #4caf50;
}

.switch-container input:checked+.slider::before {
    transform: translateX(24px);
}


canvas#viewer {
    display: block;
    width: 100vw;
    height: 100vh;
    background-color: #101010;
}

#cutoff-slider-container {
    position: fixed;
    top: 15%;
    right: 12px;
    bottom: 15%;
    width: 60px;
    background: rgba(255, 255, 255, 0.05);
    padding: 10px 0;
    border-radius: 12px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    align-items: center;
    box-sizing: border-box;
    overflow-y: auto;
    pointer-events: auto;
    touch-action: none;
    gap: 10px;
}

#cutoff-height {
    height: 100%;
    width: 8px;
    writing-mode: vertical-lr;
    direction: rtl;
    background: #333;
    border-radius: 4px;
    outline: none;
    cursor: pointer;
}

#cutoff-height::-webkit-slider-thumb,
#cutoff-height::-moz-range-thumb {
    width: 16px;
    height: 16px;
    background: #4caf50;
    border-radius: 50%;
    border: none;
    box-shadow: 0 0 3px #000;
    transition: background 0.2s ease;
}

#cutoff-height:hover {
    background: #444;
}

#cutoff-value-label {
    color: #fff;
    font-size: 0.95rem;
    text-align: center;
}

.hidden {
    display: none;
}

.transform-row button {
    background: #3a3a3a;
    color: #fff;
    border: none;
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.95rem;
    transition: background 0.3s ease;
}

.transform-row button:hover {
    background: #5a5a5a;
}

.upload-btn {
    background-color: #444;
    color: #fff;
    border: none;
    padding: 10px 14px;
    font-size: 1rem;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.3s ease;
    width: 100%;
    text-align: center;
}

.upload-btn:hover {
    background-color: #666;
}

#transform-menu {
    padding: 12px 14px;
    background: #2a2a2a;
    color: #eee;
    border-radius: 10px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 280px;
    max-width: 90vw;
    box-sizing: border-box;
}

#transform-menu .transform-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    width: 100%;
    box-sizing: border-box;
}

#transform-menu label {
    flex: 0 0 100px;
    /* fixed width for labels */
    text-align: ;
    font-size: 0.95rem;
    color: #ccc;
}

#transform-menu input[type="number"] {
    flex: 1;
    max-width: 120px;
    /* consistent with transform menu */
    padding: 6px 8px;
    border-radius: 6px;
    background-color: #444;
    border: none;
    color: white;
    font-size: 0.95rem;
    box-sizing: border-box;
}

.menu-box,
#transform-menu {
    width: 280px;
    max-width: 90vw;
    padding: 16px 18px;
    background: #2a2a2a;
    color: #eee;
    border-radius: 12px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.6);
    display: flex;
    flex-direction: column;
    gap: 12px;
    box-sizing: border-box;
}

#persistent-action-box {
    position: fixed;
    bottom: 16px;
    right: 16px;
    z-index: 999;
    background: #2a2a2a;
    padding: 16px 18px;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    min-width: 180px;
    width: 280px;
}

#persistent-action-btn {
    width: 100%;
}

.menu-category {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.menu-category-header {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 1rem;
    font-weight: 500;
    padding: 8px 10px;
    background: #333;
    color: #e0e0e0;
    border-radius: 8px;
    cursor: pointer;
    user-select: none;
    transition: background 0.2s ease;
}

.menu-category-header:hover {
    background: #444;
}

.menu-category-header.open {
    background: #555;
}

.menu-category-content {
    display: none;
    flex-direction: column;
    gap: 10px;
    padding-left: 6px;
    border-left: 2px solid #444;
    margin-left: 4px;
}

.triangle {
    font-size: 0.85rem;
    transition: transform 0.2s ease;
}

/* Make menu rows consistent across all menus */
.menu-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    width: 100%;
    box-sizing: border-box;
    margin-bottom: 8px;
}

/* Labels in menus */
.menu-row label {
    flex: 0 0 110px;
    /* consistent fixed width */
    text-align: left;
    font-size: 0.95rem;
    color: #ccc;
}

/* Inputs in menus */
.menu-row input[type="number"],
.menu-row select {
    flex: 1;
    max-width: 90px;
    /* consistent with transform menu */
    padding: 6px 8px;
    border-radius: 6px;
    background-color: #444;
    border: none;
    color: white;
    font-size: 0.95rem;
    box-sizing: border-box;
}

#slicer-settings-menu {
    /* ... existing properties ... */

    /* Add the following lines */
    max-height: 80vh;
    /* This sets the maximum height to 80% of the viewport height. */
    overflow-y: auto;
    /* This enables vertical scrolling when content overflows. */
}

#menu-row-btn {
    margin-bottom: 0;
}

/* Startup popup overlay */
.popup-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    display: none;
    /* hidden until script shows it */
    justify-content: center;
    align-items: center;
    z-index: 2000;
}

/* Popup box */
.popup-box {
    background: #2a2a2a;
    color: #e0e0e0;
    padding: 24px 28px;
    border-radius: 12px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.6);
    max-width: 600px;
    width: 90%;
    text-align: center;
}

.popup-box h2 {
    margin-top: 0;
    color: #fff;
}

.popup-box a {
    color: #4caf50;
    text-decoration: underline;
}

.popup-actions {
    margin-top: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.popup-actions label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.95rem;
}

.popup-actions button {
    background: #4caf50;
    color: #fff;
    border: none;
    padding: 10px 14px;
    font-size: 1rem;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.3s ease;
}

.popup-actions button:disabled {
    background: #666;
    cursor: not-allowed;
}

.popup-actions button:hover:enabled {
    background: #45a047;
}

ul li {
    text-align: left;
}

/* Loading animation for the persistent action button */
#persistent-action-btn.loading .btn-text {
    visibility: hidden;
}

#persistent-action-btn.loading {
    position: relative;
    cursor: wait;
    /* Indicate a busy state */
}

#persistent-action-btn.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin-top: -10px;
    /* Half of height */
    margin-left: -10px;
    /* Half of width */
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Hide cutoff slider when slicer settings menu is visible */
#slicer-settings-menu:not(.hidden)~#cutoff-slider-container {
    display: none !important;
}

/* New style for the popup close button */
.close-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    background: none;
    border: none;
    color: #e0e0e0;
    font-size: 1.5rem;
    font-weight: bold;
    cursor: pointer;
    transition: color 0.2s ease;
    padding: 5px;
}

.close-btn:hover {
    color: #fff;
}

/* Styles for the drag-and-drop overlay */
#drag-drop-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    pointer-events: none;
    /* Important to allow clicks to pass through */
}

#drag-drop-overlay.hidden {
    display: none;
}

.drag-drop-message {
    color: white;
    font-size: 2em;
    padding: 20px 40px;
    border: 2px dashed #fff;
    border-radius: 10px;
    text-align: center;
}