/* ── Reset & base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg:        #1a1a22;
    --bg2:       #22222e;
    --bg3:       #2a2a38;
    --border:    #38384a;
    --accent:    #6488d8;
    --accent2:   #4a6abf;
    --text:      #dcdcdc;
    --text2:     #888899;
    --success:   #4caf80;
    --radius:    10px;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: 'Segoe UI', system-ui, sans-serif;
    font-size: 14px;
    min-height: 100vh;
}

/* ── App shell ────────────────────────────────────────────────────────────── */
.app {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    max-width: 1600px;
    margin: 0 auto;
    padding: 0 20px;
}

/* ── Header ──────────────────────────────────────────────────────────────── */
header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 0 16px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 28px;
}

header h1 {
    font-size: 22px;
    font-weight: 600;
    letter-spacing: 0.5px;
    color: var(--text);
}

header h1 span { color: var(--accent); }

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--text2);
    transition: background 0.4s;
}
.status-dot.connected    { background: var(--success); }
.status-dot.disconnected { background: #e05555; }

/* ── Main layout ─────────────────────────────────────────────────────────── */
main {
    display: grid;
    grid-template-columns: 520px 1fr;
    align-items: start;
    gap: 24px;
    flex: 1;
    padding-bottom: 28px;
}

@media (max-width: 680px) {
    main { grid-template-columns: 1fr; }
}

/* ── Panels ──────────────────────────────────────────────────────────────── */
.panel {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* ── Drop zone ───────────────────────────────────────────────────────────── */
.drop-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 40px 20px;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
    position: relative;
}

.drop-zone:hover,
.drop-zone.drag-over {
    border-color: var(--accent);
    background: rgba(100, 136, 216, 0.06);
}

.drop-zone input[type=file] {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
    width: 100%;
    height: 100%;
}

.drop-icon { font-size: 36px; margin-bottom: 12px; }

.drop-zone p {
    color: var(--text);
    line-height: 1.6;
}
.drop-zone p span { color: var(--accent); }

/* ── Preview ─────────────────────────────────────────────────────────────── */
.preview-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.preview-wrap img {
    width: 100%;
    max-height: 200px;
    object-fit: contain;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--bg3);
}

/* ── Geometry tabs ───────────────────────────────────────────────────────── */
.geom-group { display: flex; flex-direction: column; gap: 8px; }

.group-label {
    font-size: 12px;
    color: var(--text);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.geom-tabs {
    display: grid;
    grid-template-columns: repeat(9, 1fr);
    gap: 6px;
}

.geom-tab {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    padding: 10px 2px 8px;
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    cursor: pointer;
    transition: border-color 0.2s, color 0.2s, background 0.2s;
    font-size: 10px;
    text-align: center;
}

.geom-tab svg {
    width: 28px;
    height: 24px;
}

.geom-tab img {
    width: 36px;
    height: 36px;
    object-fit: cover;
    border-radius: 5px;
    opacity: 0.85;
    transition: opacity 0.2s;
}

.geom-tab:hover img,
.geom-tab.active img {
    opacity: 1;
}

.geom-tab:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.geom-tab.active {
    border-color: var(--accent);
    background: rgba(100, 136, 216, 0.12);
    color: var(--accent);
}

/* ── Image shape (radio) ─────────────────────────────────────────────────── */
.shape-group { display: flex; flex-direction: column; gap: 8px; }

.shape-options {
    display: flex;
    gap: 16px;
}

.radio-label {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text);
    font-size: 13px;
    cursor: pointer;
    user-select: none;
}

.radio-label input[type=radio] { display: none; }

.radio-dot {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 1px solid var(--text2);
    background: var(--bg3);
    position: relative;
    flex-shrink: 0;
    transition: border-color 0.2s;
}

.radio-dot::after {
    content: '';
    position: absolute;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent);
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0);
    transition: transform 0.15s;
}

.radio-label input:checked + .radio-dot { border-color: var(--accent); }
.radio-label input:checked + .radio-dot::after { transform: translate(-50%, -50%) scale(1); }
.radio-label:hover .radio-dot { border-color: var(--accent); }

.radio-label:has(input:disabled) {
    color: var(--text2);
    cursor: not-allowed;
}
.radio-label:has(input:disabled) .radio-dot { border-color: var(--border); }
.radio-label:has(input:disabled):hover .radio-dot { border-color: var(--border); }

/* ── Cube side-image slots ───────────────────────────────────────────────── */
.cube-faces-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

@media (max-width: 480px) {
    .cube-faces-grid { grid-template-columns: repeat(2, 1fr); }
}

.cube-face-slot { display: flex; flex-direction: column; }

.drop-zone-sm {
    padding: 14px 6px;
}
.drop-zone-sm .drop-icon { font-size: 20px; margin-bottom: 6px; }
.drop-zone-sm p { font-size: 11px; line-height: 1.4; }

.cube-face-preview { gap: 6px; }
.cube-face-preview img {
    max-height: 80px;
}
.cube-face-preview .btn-ghost {
    padding: 6px;
    font-size: 11px;
}

.bottom-text-wrap {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 4px;
}

.text-input {
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 13px;
    padding: 8px 10px;
    outline: none;
    transition: border-color 0.2s;
}

.text-input:focus { border-color: var(--accent); }

.rp-profile-listbox {
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 13px;
    padding: 4px;
    outline: none;
    width: 100%;
    transition: border-color 0.2s;
}

.rp-profile-listbox:focus { border-color: var(--accent); }

.rp-profile-listbox option {
    padding: 4px 6px;
    border-radius: 4px;
}

/* ── Parameters ──────────────────────────────────────────────────────────── */
.params {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.params label,
.param-row label {
    display: flex;
    align-items: baseline;
    color: var(--text);
    font-size: 13px;
    margin-bottom: 6px;
}

.val { color: var(--accent); font-weight: 600; margin-left: 6px; }

.range-max {
    text-align: right;
    font-size: 11px;
    color: var(--text2);
    margin-top: 4px;
}

input[type=range] {
    -webkit-appearance: none;
    width: 100%;
    height: 4px;
    border-radius: 2px;
    background: var(--bg3);
    outline: none;
    cursor: pointer;
}

input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    transition: background 0.2s;
}

input[type=range]::-webkit-slider-thumb:hover { background: var(--accent2); }

/* Toggle switch */
.toggle-label {
    display: flex !important;
    align-items: center;
    cursor: pointer;
    user-select: none;
}

.toggle-label input[type=checkbox] { display: none; }

.toggle {
    width: 38px;
    height: 20px;
    background: var(--bg3);
    border-radius: 10px;
    position: relative;
    transition: background 0.2s;
    border: 1px solid var(--border);
    flex-shrink: 0;
}

.toggle::after {
    content: '';
    position: absolute;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--text2);
    top: 2px;
    left: 2px;
    transition: left 0.2s, background 0.2s;
}

.toggle-label input:checked + .toggle { background: var(--accent2); }
.toggle-label input:checked + .toggle::after {
    left: 20px;
    background: #fff;
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn-primary {
    display: block;
    width: 100%;
    padding: 12px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    text-align: center;
    text-decoration: none;
    transition: background 0.2s, opacity 0.2s;
}

.btn-primary:hover:not(:disabled) { background: var(--accent2); }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-ghost {
    display: block;
    width: 100%;
    padding: 10px;
    background: transparent;
    color: var(--text2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 13px;
    cursor: pointer;
    text-align: center;
    transition: border-color 0.2s, color 0.2s;
}
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }
.btn-ghost:disabled,
.btn-ghost:disabled:hover {
    opacity: 0.4;
    cursor: not-allowed;
    border-color: var(--border);
    color: var(--text2);
}

.btn-icon {
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text2);
    font-size: 16px;
    width: 30px;
    height: 30px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: border-color 0.2s, color 0.2s;
}
.btn-icon:hover { border-color: var(--accent); color: var(--accent); }
.btn-icon:disabled,
.btn-icon:disabled:hover {
    opacity: 0.35;
    cursor: not-allowed;
    border-color: var(--border);
    color: var(--text2);
}
.btn-icon img {
    width: 32px;
    height: 32px;
    object-fit: contain;
    pointer-events: none;
    opacity: 0.85;
    transition: opacity 0.2s;
}
.btn-icon:hover img { opacity: 1; }
.btn-icon:disabled img { opacity: 0.35; }
.if-toolbar .btn-icon:disabled img { opacity: 0.35; }
.if-toolbar .btn-icon {
    width: 44px;
    height: 44px;
}

/* ── Rotation Profile modal ──────────────────────────────────────────────── */
.rotation-profile-summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
#rotationProfileStatus {
    color: var(--text);
    font-size: 13px;
}
.rotation-profile-summary .btn-ghost {
    width: auto;
    padding: 8px 14px;
    white-space: nowrap;
    color: var(--text);
    border-color: var(--text2);
}

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-window {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    width: min(920px, 94vw);
    max-height: 92vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

.modal-titlebar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
}

.modal-close {
    background: transparent;
    border: none;
    color: var(--text2);
    font-size: 16px;
    cursor: pointer;
    line-height: 1;
    padding: 4px;
}
.modal-close:hover { color: var(--text); }

.modal-body {
    display: flex;
    gap: 20px;
    padding: 18px;
    overflow-y: auto;
}

.rp-main {
    display: flex;
    flex-direction: column;
    gap: 12px;
    flex: 1;
    min-width: 0;
}

.rp-posrow {
    display: flex;
    align-items: center;
    gap: 8px;
}
.rp-pos-input {
    width: 70px;
    text-align: center;
}
.rp-unit { color: var(--text2); font-size: 12px; }

.rp-canvas-wrap {
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg3);
    overflow: hidden;
    align-self: flex-start;
    max-width: 100%;
}
#rpCanvas {
    display: block;
    width: 100%;
    max-width: 640px;
    height: auto;
    aspect-ratio: 1 / 1;
    cursor: crosshair;
    touch-action: none;
}

.rp-toolbar {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}
.rp-toolbar .btn-icon {
    width: 48px;
    height: 48px;
    font-size: 26px;
}
.rp-toolbar .btn-icon.active {
    border-color: var(--accent);
    color: var(--accent);
    background: rgba(100, 136, 216, 0.12);
}
.rp-toolbar .btn-icon.rp-icon-bright {
    color: var(--text);
    border-color: var(--text2);
}
.rp-toolbar .btn-icon.rp-icon-bright:hover {
    border-color: var(--accent);
    color: var(--accent);
}
.rp-plus { font-size: 12px; margin-left: -4px; }

.rp-hint {
    color: var(--text);
    font-size: 12px;
    margin: 0;
}

.rp-delete-profile-btn {
    width: 100%;
    padding: 6px 10px;
    font-size: 12px;
    margin-top: 6px;
    color: var(--text);
    border-color: var(--text2);
}

.rp-side {
    display: flex;
    flex-direction: column;
    gap: 14px;
    width: 180px;
    flex-shrink: 0;
}
.rp-side .group-label,
.rp-side .rp-unit,
.rp-side .radio-label,
.rp-side .rp-checkbox {
    color: var(--text);
}

.rp-field-row { display: flex; align-items: center; gap: 8px; }
.rp-grid-input { width: 70px; }

.rp-checkbox { font-size: 13px; }
.rp-check-dot { border-radius: 4px; }
.rp-check-dot::after { border-radius: 2px; width: 8px; height: 8px; }

.rp-move-pad {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 6px 0;
}
.rp-move-mid { display: flex; align-items: center; gap: 4px; }
.rp-move-center { width: 30px; height: 30px; }
.rp-move-btn { width: 30px; height: 30px; font-size: 14px; }

.rp-gridtype-group {
    flex-direction: column;
    gap: 10px;
}

#rpCancelBtn, #rpOkBtn { margin-top: auto; }
#rpOkBtn { margin-top: 4px; }

@media (max-width: 720px) {
    .modal-body { flex-direction: column; }
    .rp-side { width: 100%; flex-direction: row; flex-wrap: wrap; align-items: flex-end; }
    .rp-gridtype-group { flex-direction: row; }
    #rpCancelBtn, #rpOkBtn { margin-top: 0; }
}

/* ── Image Filtration modal ──────────────────────────────────────────────── */
.preview-btn-row { display: flex; gap: 8px; }
.preview-btn-row .btn-ghost { flex: 1; color: var(--text); }

.btn-loading {
    position: relative;
    color: transparent !important;
    pointer-events: none;
}
.btn-loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 14px;
    height: 14px;
    margin: -7px 0 0 -7px;
    border: 2px solid var(--text2);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: btn-loading-spin 0.7s linear infinite;
}
@keyframes btn-loading-spin {
    to { transform: rotate(360deg); }
}

/* ── Create / Edit Image Border modal ────────────────────────────────────── */
.cb-window { width: min(1100px, 96vw); }
.cb-body { align-items: flex-start; }

.cb-image-wrap {
    position: relative;
    flex: 1;
    min-width: 0;
    width: 100%;
    max-width: 700px;
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: 6px;
    overflow: hidden;
    /* aspect-ratio is set from JS to match the loaded image's natural
       dimensions exactly, so #cbImage fills the wrap with no letterboxing
       and shape/handle px coordinates map 1:1 to the rendered image. */
}
#cbImage { display: block; width: 100%; height: 100%; object-fit: fill; user-select: none; -webkit-user-drag: none; }

.cb-shape {
    position: absolute;
    box-sizing: border-box;
    border: 2px solid #e0303a;
    background: rgba(224, 48, 58, 0.10);
    cursor: move;
}
.cb-shape.cb-oval { border-radius: 50%; }

.cb-handle {
    position: absolute;
    width: 14px;
    height: 14px;
    background: #fff;
    border: 2px solid #e0303a;
    border-radius: 50%;
    transform: translate(-50%, -50%);
}
.cb-handle-nw { top: 0;   left: 0;   cursor: nwse-resize; }
.cb-handle-ne { top: 0;   left: 100%; cursor: nesw-resize; }
.cb-handle-sw { top: 100%; left: 0;   cursor: nesw-resize; }
.cb-handle-se { top: 100%; left: 100%; cursor: nwse-resize; }

/* Auto-detected "Border polygon" overlay: a closed line through the
   detected points, draggable vertex markers, and (invisible, widened)
   per-edge hit-lines for click-to-insert-a-point. Colors match
   .cb-shape/.cb-handle above. The container itself stays
   pointer-events:none so it never blocks anything underneath; only the
   specific interactive children opt back in. */
.cb-polygon-overlay {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
}
.cb-polygon-shape {
    fill: rgba(224, 48, 58, 0.10);
    stroke: #e0303a;
    stroke-width: 2;
    stroke-linejoin: round;
    pointer-events: none;
}
.cb-polygon-edge-hit {
    fill: none;
    stroke: transparent;
    stroke-width: 14;
    pointer-events: stroke;
    cursor: copy;
}
.cb-polygon-vertex {
    fill: #fff;
    stroke: #e0303a;
    stroke-width: 2;
    pointer-events: all;
    cursor: move;
}

.cb-side {
    display: flex;
    flex-direction: column;
    gap: 14px;
    width: 180px;
    flex-shrink: 0;
}
.cb-side .group-label,
.cb-side .radio-label,
.cb-side .rp-hint { color: var(--text); }
.cb-type-group { flex-direction: column; gap: 10px; }

/* Houses the "Border polygon" radio plus its "Restore border points"
   icon button on the same row, right-aligned. Only this radio gets the
   icon, so it's not part of .cb-type-group's generic row styling. */
.cb-type-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}
.cb-type-row .radio-label { flex: 1; min-width: 0; }
.cb-polygon-restore-btn {
    width: 24px;
    height: 24px;
    font-size: 13px;
    flex-shrink: 0;
    /* Brighter than the default .btn-icon (dim text2, only brightens on
       hover) — always-on, and in the same red as the polygon overlay
       itself so it reads as "act on the polygon" at a glance. */
    color: #e0303a;
    border-color: #e0303a;
}
.cb-polygon-restore-btn:hover {
    background: #e0303a;
    color: #fff;
}

.cb-info {
    border-top: 1px solid var(--border);
    padding-top: 10px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 12px;
    color: var(--text);
}
.cb-info-row { display: flex; justify-content: space-between; gap: 8px; }

.cb-clean-group {
    border-top: 1px solid var(--border);
    padding-top: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.cb-clean-slider-row {
    display: flex;
    align-items: center;
    gap: 10px;
}
.cb-clean-slider-row input[type=range] { flex: 1; }
.cb-clean-swatch {
    width: 22px;
    height: 22px;
    border-radius: 4px;
    border: 1px solid var(--border);
    flex-shrink: 0;
    background: #fff;
}

/* Clean outside border + its Undo, side by side — .btn-ghost's own
   width:100%/display:block default is overridden to split the row. */
.cb-clean-btn-row {
    display: flex;
    gap: 8px;
}
.cb-clean-btn-row .btn-ghost {
    width: auto;
    flex: 1;
}

/* Brighter than the default .btn-ghost (which stays dim text2 until
   hover) — accent-colored border/text always on, matching .cb-ok-btn's
   treatment above, with a filled accent hover for extra emphasis.
   .btn-ghost:disabled (higher specificity) takes back over while Undo
   is inactive, so it only looks bright once there's something to undo. */
.cb-clean-btn,
.cb-clean-undo-btn {
    color: var(--accent);
    border-color: var(--accent);
    font-weight: 600;
}
.cb-clean-btn:hover,
.cb-clean-undo-btn:hover:not(:disabled) {
    background: var(--accent);
    color: #fff;
}

.cb-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 14px 18px;
    border-top: 1px solid var(--border);
}
.cb-toolbar-group { display: flex; gap: 8px; }
.cb-ok-btn { color: var(--accent); border-color: var(--accent); font-weight: 700; }
.cb-toolbar .btn-icon.cb-icon-bright {
    color: var(--text);
    border-color: var(--text2);
}
.cb-toolbar .btn-icon.cb-icon-bright:hover {
    border-color: var(--accent);
    color: var(--accent);
}

@media (max-width: 720px) {
    .cb-body { flex-direction: column; }
    .cb-side { width: 100%; }
    .cb-image-wrap { max-width: 100%; }
}

.if-window { width: min(1440px, 96vw); }

.if-body { align-items: stretch; height: 68vh; }

.if-image-wrap {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: 6px;
    overflow: hidden;
    height: 100%;
}
#ifImage { max-width: 100%; max-height: 100%; object-fit: contain; }

.if-controls {
    width: 620px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: 0;
    height: 100%;
}

.if-tabs {
    display: flex;
    gap: 4px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 10px;
    flex-wrap: wrap;
    flex-shrink: 0;
}

.if-tab {
    flex: 1;
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 8px 4px;
    color: var(--text);
    font-size: 11px;
    line-height: 1.3;
    cursor: pointer;
    text-align: center;
    transition: border-color 0.2s, color 0.2s, background 0.2s;
}
.if-tab:hover { border-color: var(--accent); color: var(--accent); }
.if-tab.active {
    border-color: var(--accent);
    background: rgba(100, 136, 216, 0.12);
    color: var(--accent);
}

.if-panel {
    display: flex;
    flex-direction: column;
    gap: 14px;
    overflow-y: auto;
    padding-right: 4px;
    flex: 1;
    min-height: 0;
}

.if-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.if-row-indent { padding-left: 28px; }

.if-radio-label { min-width: 150px; flex-shrink: 0; }

/* .radio-label defaults to a dim text2 color elsewhere in the app (geometry
   pickers, rotation profile editor); brighten it specifically inside the
   filtration tabs without touching those other usages. */
.if-panel .radio-label { color: var(--text); }

.if-sub-input { width: 56px; text-align: center; }
.if-sub-input:disabled { opacity: 0.4; }

.if-slider { flex: 1; min-width: 80px; accent-color: var(--accent); }
.if-slider:disabled { opacity: 0.4; }

.if-unit { color: var(--text); font-size: 12px; white-space: nowrap; }

.if-placeholder { color: var(--text); font-size: 13px; padding: 20px 0; }

.if-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 18px;
    border-top: 1px solid var(--border);
}
.if-toolbar .btn-icon:disabled { opacity: 0.35; cursor: not-allowed; }
.if-status { color: var(--text); font-size: 12px; margin-left: 6px; }

/* Indeterminate busy bar for Apply Filter — there's no real percentage to
   report (the filter/reconstruct call is a single synchronous request), so
   this is honestly just "something is happening", not a progress fraction. */
.if-progress { padding: 0 18px 10px; }
.if-progress-track {
    width: 100%;
    height: 4px;
    background: var(--bg3);
    border-radius: 2px;
    overflow: hidden;
}
.if-progress-fill {
    height: 100%;
    width: 35%;
    background: var(--accent);
    border-radius: 2px;
    animation: if-progress-slide 1.1s ease-in-out infinite;
}
@keyframes if-progress-slide {
    0%   { transform: translateX(-100%); }
    100% { transform: translateX(285%); }
}

@media (max-width: 780px) {
    .if-body { flex-direction: column; height: auto; max-height: 80vh; overflow-y: auto; }
    .if-image-wrap { height: 34vh; flex: none; }
    .if-controls { width: 100%; height: 44vh; }
}

/* ── Result panel placeholders ───────────────────────────────────────────── */
.result-placeholder {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    color: var(--text2);
}

.placeholder-icon { font-size: 48px; opacity: 0.3; }

/* ── Progress ────────────────────────────────────────────────────────────── */
.progress-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
}

.stage-label {
    color: var(--text2);
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.progress-track {
    width: 100%;
    height: 6px;
    background: var(--bg3);
    border-radius: 3px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    width: 0%;
    background: var(--accent);
    border-radius: 3px;
    transition: width 0.4s ease;
}

/* Applied only while stage is "reconstructing" (see setProgress in app.js) —
   the numeric percentage barely moves during that phase (a 4-10s operation
   squeezed into an 8-10% band, sampled by 2s polling), so this pulse plus
   the elapsed-seconds label are what actually communicate "still working". */
.progress-bar-pulse {
    animation: progress-bar-pulse-anim 1.4s ease-in-out infinite;
}

@keyframes progress-bar-pulse-anim {
    0%, 100% { opacity: 1; }
    50%      { opacity: 0.55; }
}

.progress-pct {
    color: var(--accent);
    font-size: 28px;
    font-weight: 700;
}

/* ── 3D Viewer ───────────────────────────────────────────────────────────── */
.viewer-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: 0;
}

.viewer-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.viewer-title {
    font-size: 13px;
    color: var(--text2);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Groups Reset View + Wireframe together on the right side of the
   toolbar, instead of letting justify-content: space-between spread
   them apart from each other across the row. */
.viewer-toolbar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Text-label sibling to .btn-icon (which is a fixed 30x30 square built
   for a single glyph) — same height/border/colors so the two buttons
   read as a matched pair, but sized to fit "Wireframe: Off/On" without
   the text overlapping or being clipped. */
.btn-viewer-toggle {
    height: 30px;
    padding: 0 10px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text2);
    font-size: 12px;
    white-space: nowrap;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: border-color 0.2s, color 0.2s;
}

/* Brighter resting state for Reset View + Wireframe specifically — they
   sit right over the 3D preview and were easy to miss at --text2's dim
   default. Scoped to this toolbar so other .btn-icon buttons elsewhere
   in the app keep their normal dimmer resting color. Hover/active are
   restated here too (rather than relying on source order against the
   shared .btn-icon:hover / .btn-viewer-toggle.active rules above/below)
   so the accent highlight reliably wins via selector specificity. */
.viewer-toolbar-actions .btn-icon,
.viewer-toolbar-actions .btn-viewer-toggle {
    color: var(--text);
    border-color: #4a4a60;
}
.viewer-toolbar-actions .btn-icon:hover,
.viewer-toolbar-actions .btn-viewer-toggle:hover {
    border-color: var(--accent);
    color: var(--accent);
}
.viewer-toolbar-actions .btn-viewer-toggle.active {
    border-color: var(--accent);
    color: var(--accent);
}

.btn-viewer-toggle:hover { border-color: var(--accent); color: var(--accent); }
.btn-viewer-toggle.active { border-color: var(--accent); color: var(--accent); }

.viewer-canvas-wrap {
    width: 100%;
    aspect-ratio: 1 / 1;
    min-height: 300px;
    position: relative;
    border-radius: 8px;
    overflow: hidden;
    background: var(--bg3);
    border: 1px solid var(--border);
}

#stlViewer {
    width: 100%;
    height: 100%;
}

#stlViewer canvas {
    display: block;
    width: 100% !important;
    height: 100% !important;
}

.viewer-loading-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    background: rgba(26, 26, 34, 0.72);
    backdrop-filter: blur(2px);
}

.viewer-spinner {
    width: 30px;
    height: 30px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: viewer-spin 0.8s linear infinite;
}

@keyframes viewer-spin {
    to { transform: rotate(360deg); }
}

#viewerLoadingText {
    color: var(--text2);
    font-size: 13px;
}

.viewer-hint {
    text-align: center;
    font-size: 11px;
    /* color: var(--text2); */
    /* opacity: 0.85; */
    color: #b0b0b0; /* or try #cccccc for even brighter */
    opacity: 1;
}

.viewer-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.viewer-filesize {
    font-size: 0.85rem;
    /* color: var(--text-muted, #888);*/
    color: var(--accent);
    margin-left: 0.5rem;
}

/* Brighter than the default dim btn-ghost text — these two sit at the
   bottom of the 3D display and are easy to miss at the default --text2. */
#reduceStlBtn,
#newBtn {
    color: var(--text);
    border-color: var(--text2);
}
#reduceStlBtn:hover,
#newBtn:hover {
    border-color: var(--accent);
    color: var(--accent);
}
#reduceStlBtn img {
    width: 15px;
    height: 15px;
    vertical-align: -2px;
    margin-right: 6px;
    object-fit: contain;
}

/* ── Reduce STL File Size Modal ─────────────────────────────────────────── */
.rs-window { width: min(1180px, 96vw); max-height: 94vh; }
.rs-body { align-items: stretch; }
.rs-canvas-wrap {
    flex: 1;
    min-height: 560px;
}
.rs-side { width: 300px; }
#rsViewer {
    width: 100%;
    height: 100%;
}
#rsViewer canvas {
    display: block;
    width: 100% !important;
    height: 100% !important;
}

@media (max-width: 780px) {
    .rs-body { flex-direction: column; }
    .rs-canvas-wrap { height: 34vh; min-height: 220px; }
    .rs-side { width: 100%; }
}

/* ── Program Settings Modal ─────────────────────────────────────────────── */
.settings-window { width: min(420px, 92vw); }
.settings-body { flex-direction: column; align-items: stretch; gap: 12px; }
.settings-face-model-options { flex-direction: column; gap: 12px; }

.rp-ctx-menu {
    position: fixed;
    z-index: 1000;
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 4px 16px rgba(0,0,0,0.4);
    padding: 4px 0;
    min-width: 180px;
    font-size: 13px;
}

.rp-ctx-menu-item {
    padding: 8px 14px;
    color: var(--text);
    cursor: pointer;
    white-space: nowrap;
}

.rp-ctx-menu-item:hover {
        background: var(--accent2);
        color: #fff;
}

/* Cylinder bottom logo preview — shown at half the size of the normal
   preview above; it's a small logo, not the main input photo. */
#cylinderLogoPreviewImg {
    width: 50%;
    max-height: 50px;
}

/* Custom Profile bottom logo preview — mirrors #cylinderLogoPreviewImg above. */
#rotationLogoPreviewImg {
    width: 50%;
    max-height: 50px;
}

#splashScreen {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #1a1a22;
    opacity: 1;
    transition: opacity 0.6s ease;
}

    #splashScreen img {
        max-width: min(90vw, 800px);
        max-height: 90vh;
        width: auto;
        height: auto;
    }

    #splashScreen.fade-out {
        opacity: 0;
        pointer-events: none;
    }

/* ── Image Transform (morphing) modal ───────────────────────────────────── */
.it-window { width: min(1100px, 96vw); }

.it-title-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.xform-main {
    display: flex;
    flex-direction: column;
    gap: 24px;
    width: 100%;
}

.xform-displays {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
}

@media (max-width: 780px) {
    .xform-displays { grid-template-columns: 1fr; }
}

.xform-display-col {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.xform-display {
    aspect-ratio: 3 / 4;
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.xform-display img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.xform-placeholder {
    color: var(--text2);
    font-size: 13px;
}

.xform-frame-label {
    text-align: center;
    color: var(--text2);
    font-size: 12px;
    min-height: 16px;
}

.xform-frame-toolbar {
    display: flex;
    justify-content: center;
    gap: 8px;
}
.xform-frame-toolbar .btn-icon {
    width: 36px;
    height: 36px;
}
.xform-frame-toolbar .btn-icon img {
    width: 24px;
    height: 24px;
}
.xform-frame-toolbar .btn-icon:disabled { opacity: 0.35; cursor: not-allowed; }

.xform-controls {
    max-width: 480px;
}

/* #xformTransferBtn overrides .btn-primary's block/full-width default —
   scoped to this one button by id so nothing else using .btn-primary
   elsewhere in the app is affected. .xform-controls's parent (.panel) is a
   flex column, which stretches children to full width by default
   regardless of their own display/width — align-self is what actually
   shrinks it and lets it sit left instead of centered/stretched. */
#xformTransferBtn {
    align-self: flex-start;
    width: auto;
    padding: 8px 20px;
    font-size: 13px;
}

.xform-status { color: var(--text); font-size: 12px; }

.xform-progress-track {
    width: 100%;
    height: 6px;
    background: var(--bg3);
    border-radius: 3px;
    overflow: hidden;
}

.xform-progress-fill {
    height: 100%;
    width: 0%;
    background: var(--accent);
    border-radius: 3px;
    transition: width 0.15s ease;
}