/* ==========================================================================
   FCM Studio - premium tool UI
   ========================================================================== */

:root {
    --fcm-bg: #0b0b0c;
    --fcm-bg-elev: #11100f;
    --fcm-panel: rgba(24, 23, 21, 0.94);
    --fcm-panel-solid: #181715;
    --fcm-panel-soft: rgba(255, 255, 255, 0.045);
    --fcm-panel-raised: #201e1a;
    --fcm-stage: #070707;
    --fcm-border: rgba(247, 238, 220, 0.12);
    --fcm-border-strong: rgba(247, 238, 220, 0.22);
    --fcm-text: #f4efe7;
    --fcm-muted: #b3aa9b;
    --fcm-faint: #81786d;
    --fcm-gold: #d7a84c;
    --fcm-gold-2: #f5d991;
    --fcm-green: #38b981;
    --fcm-blue: #5e93f3;
    --fcm-red: #e05f55;
    --fcm-amber: #e7b14b;
    --fcm-radius: 8px;
    --fcm-radius-sm: 6px;
    --fcm-shadow: 0 18px 45px rgba(0, 0, 0, 0.34);
    --fcm-font: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
}

:root[data-bs-theme="light"] {
    --fcm-bg: #f4f1ea;
    --fcm-bg-elev: #ebe6dc;
    --fcm-panel: rgba(255, 255, 255, 0.94);
    --fcm-panel-solid: #ffffff;
    --fcm-panel-soft: rgba(16, 18, 20, 0.045);
    --fcm-panel-raised: #f8f5ef;
    --fcm-stage: #f8f5ef;
    --fcm-border: rgba(30, 30, 28, 0.12);
    --fcm-border-strong: rgba(30, 30, 28, 0.22);
    --fcm-text: #1b1a18;
    --fcm-muted: #625d54;
    --fcm-faint: #8b8174;
    --fcm-shadow: 0 18px 45px rgba(43, 36, 26, 0.12);
}

* { box-sizing: border-box; }

html {
    min-width: 320px;
    max-width: 100%;
    overflow-x: hidden;
}

body {
    margin: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    font-family: var(--fcm-font);
    color: var(--fcm-text);
    background:
        linear-gradient(180deg, var(--fcm-bg-elev) 0, var(--fcm-bg) 420px),
        var(--fcm-bg);
    max-width: 100%;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    text-rendering: geometricPrecision;
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    background-image:
        linear-gradient(rgba(255, 255, 255, 0.025) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.018) 1px, transparent 1px);
    background-size: 48px 48px;
    mask-image: linear-gradient(180deg, rgba(0, 0, 0, 0.75), transparent 65%);
}

:root[data-bs-theme="light"] body::before {
    background-image:
        linear-gradient(rgba(12, 15, 18, 0.028) 1px, transparent 1px),
        linear-gradient(90deg, rgba(12, 15, 18, 0.02) 1px, transparent 1px);
}

.d-none { display: none !important; }
.mb-0 { margin-bottom: 0 !important; }
.mt-2 { margin-top: 0.5rem !important; }
.mt-3 { margin-top: 0.9rem !important; }
.mb-2 { margin-bottom: 0.5rem !important; }
.fcm-muted { color: var(--fcm-muted); font-weight: 400; }

.fcm-container {
    width: 100%;
    max-width: 1480px;
    margin: 0 auto;
    padding: 0 22px;
}

.fcm-main {
    position: relative;
    z-index: 1;
    flex: 1 0 auto;
    padding-top: 20px;
    padding-bottom: 34px;
}

/* --------------------------------------------------------------- topbar */
.fcm-topbar {
    position: sticky;
    top: 0;
    z-index: 40;
    border-bottom: 1px solid var(--fcm-border);
    background: rgba(9, 9, 10, 0.88);
    backdrop-filter: blur(16px);
}

:root[data-bs-theme="light"] .fcm-topbar {
    background: rgba(250, 247, 241, 0.88);
}

.fcm-topbar-inner {
    height: 66px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
}

.fcm-brand {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
    color: var(--fcm-text);
    text-decoration: none;
}

.fcm-logo-img {
    width: auto;
    height: 40px;
    display: block;
    border-radius: var(--fcm-radius-sm);
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.32);
}

.fcm-brand-copy {
    display: flex;
    flex-direction: column;
    min-width: 0;
    line-height: 1.08;
}

.fcm-brand-name {
    font-size: 0.98rem;
    font-weight: 750;
}

.fcm-brand-tag {
    margin-top: 3px;
    color: var(--fcm-muted);
    font-size: 0.72rem;
}

.fcm-topbar-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    min-width: 0;
}

.fcm-badge-soft {
    display: inline-flex;
    align-items: center;
    min-height: 32px;
    padding: 0 11px;
    border: 1px solid var(--fcm-border);
    border-radius: 999px;
    color: var(--fcm-muted);
    background: var(--fcm-panel-soft);
    font-size: 0.75rem;
    white-space: nowrap;
}

.fcm-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 34px;
    padding: 0 12px;
    border: 1px solid var(--fcm-border);
    border-radius: 999px;
    color: var(--fcm-text);
    background: var(--fcm-panel-soft);
    font: inherit;
    font-size: 0.78rem;
    font-weight: 650;
    cursor: pointer;
    transition: border-color 0.16s ease, background 0.16s ease, transform 0.12s ease;
}

.fcm-icon-btn:hover {
    border-color: var(--fcm-gold);
    background: rgba(215, 168, 76, 0.12);
}

.fcm-icon-btn:active { transform: translateY(1px); }

.fcm-theme-dot {
    width: 13px;
    height: 13px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--fcm-gold), var(--fcm-blue));
    box-shadow: 0 0 0 3px rgba(215, 168, 76, 0.12);
}

/* --------------------------------------------------------------- workbench */
.fcm-workbench-head {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(360px, 540px);
    gap: 20px;
    align-items: end;
    margin-bottom: 18px;
}

.fcm-workbench-head > *,
.fcm-grid > *,
.fcm-col,
.fcm-card,
.fcm-flow {
    min-width: 0;
}

.fcm-kicker {
    margin: 0 0 6px;
    color: var(--fcm-gold-2);
    font-size: 0.72rem;
    font-weight: 750;
    text-transform: uppercase;
    letter-spacing: 0;
}

.fcm-workbench-title {
    margin: 0;
    font-size: 1.72rem;
    line-height: 1.08;
    font-weight: 780;
}

.fcm-workbench-sub {
    max-width: 620px;
    margin: 8px 0 0;
    color: var(--fcm-muted);
    font-size: 0.92rem;
    line-height: 1.45;
}

.fcm-flow {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
    padding: 7px;
    border: 1px solid var(--fcm-border);
    border-radius: var(--fcm-radius);
    background: var(--fcm-panel);
    box-shadow: var(--fcm-shadow);
}

.fcm-flow-step {
    position: relative;
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 42px;
    min-width: 0;
    padding: 8px 10px;
    border: 1px solid transparent;
    border-radius: var(--fcm-radius-sm);
    color: var(--fcm-muted);
    background: transparent;
    font-size: 0.78rem;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.fcm-flow-step::before {
    content: "";
    width: 8px;
    height: 8px;
    flex: 0 0 8px;
    border-radius: 50%;
    background: var(--fcm-faint);
}

.fcm-flow-step.is-active {
    color: var(--fcm-text);
    border-color: rgba(215, 168, 76, 0.36);
    background: rgba(215, 168, 76, 0.12);
}

.fcm-flow-step.is-active::before { background: var(--fcm-gold); }
.fcm-flow-step.is-done::before { background: var(--fcm-green); }

/* --------------------------------------------------------------- layout */
.fcm-grid {
    display: grid;
    grid-template-columns: minmax(285px, 330px) minmax(0, 1fr) minmax(300px, 360px);
    gap: 16px;
    align-items: start;
}

body:not([data-workflow="complete"]) .fcm-grid {
    grid-template-columns: minmax(285px, 330px) minmax(0, 1fr);
}

body:not([data-workflow="complete"]) .fcm-col-right {
    display: none;
}

.fcm-col {
    display: flex;
    flex-direction: column;
    gap: 14px;
    min-width: 0;
}

/* The centre stage flows normally (no internal clipping) so the result image is
   always fully visible — never cut off by a sticky/overflow container. */
.fcm-col-preview { align-self: start; }

/* --------------------------------------------------------------- cards */
.fcm-card {
    position: relative;
    border: 1px solid var(--fcm-border);
    border-radius: var(--fcm-radius);
    background: var(--fcm-panel);
    box-shadow: var(--fcm-shadow);
    padding: 16px;
}

.fcm-card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

.fcm-card-title,
.fcm-step-title {
    margin: 0;
    color: var(--fcm-text);
    font-size: 0.98rem;
    line-height: 1.2;
    font-weight: 750;
    letter-spacing: 0;
}

.fcm-card-title { margin-bottom: 12px; }
.fcm-card-head .fcm-card-title { margin-bottom: 0; }

.fcm-head-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

/* Generic collapse: any card with a .fcm-collapse-btn in its head can be
   hidden/shown. When collapsed we keep only the header row and hide the body. */
.fcm-collapse-btn { flex: 0 0 auto; }
.fcm-card.is-collapsed { padding-bottom: 12px; }
.fcm-card.is-collapsed > *:not(.fcm-card-head) { display: none !important; }
.fcm-card.is-collapsed > .fcm-card-head { margin-bottom: 0; }

.fcm-step-head {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 14px;
}

.fcm-step-num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    flex: 0 0 26px;
    border-radius: var(--fcm-radius-sm);
    color: #14110b;
    background: var(--fcm-gold);
    font-size: 0.78rem;
    font-weight: 800;
}

.fcm-group-label {
    margin: 16px 0 8px;
    color: var(--fcm-faint);
    font-size: 0.72rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0;
}

.fcm-divider {
    height: 1px;
    margin: 16px 0;
    background: var(--fcm-border);
}

/* --------------------------------------------------------------- dropzone */
.fcm-dropzone {
    position: relative;
    display: grid;
    grid-template-columns: 58px minmax(0, 1fr);
    align-items: center;
    column-gap: 14px;
    min-height: 132px;
    padding: 16px;
    border: 1px dashed var(--fcm-border-strong);
    border-radius: var(--fcm-radius);
    background:
        linear-gradient(135deg, rgba(215, 168, 76, 0.12), transparent 44%),
        var(--fcm-panel-soft);
    cursor: pointer;
    transition: border-color 0.16s ease, background 0.16s ease, transform 0.12s ease;
}

.fcm-dropzone:hover,
.fcm-dropzone:focus-visible {
    border-color: var(--fcm-gold);
    outline: none;
}

.fcm-dropzone.dragover {
    border-color: var(--fcm-green);
    background: rgba(56, 185, 129, 0.1);
    transform: translateY(-1px);
}

.fcm-dropzone.has-file {
    border-style: solid;
    border-color: rgba(56, 185, 129, 0.48);
}

.fcm-dropzone-icon {
    grid-row: 1 / span 3;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 58px;
    height: 58px;
    color: var(--fcm-gold-2);
    border: 1px solid rgba(215, 168, 76, 0.28);
    border-radius: var(--fcm-radius);
    background: rgba(215, 168, 76, 0.1);
}

.fcm-dropzone-title {
    margin: 0 0 2px;
    color: var(--fcm-text);
    font-size: 0.98rem;
    font-weight: 750;
}

.fcm-dropzone-sub {
    margin: 0 0 12px;
    color: var(--fcm-muted);
    font-size: 0.78rem;
}

.fcm-file-meta {
    display: flex;
    align-items: center;
    gap: 9px;
    min-width: 0;
    margin-top: 10px;
    padding: 10px 11px;
    border: 1px solid rgba(56, 185, 129, 0.34);
    border-radius: var(--fcm-radius-sm);
    background: rgba(56, 185, 129, 0.09);
    font-size: 0.82rem;
}

.fcm-file-dot {
    width: 8px;
    height: 8px;
    flex: 0 0 8px;
    border-radius: 50%;
    background: var(--fcm-green);
}

.fcm-file-name {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 700;
}

.fcm-file-size {
    flex: 0 0 auto;
    margin-left: auto;
    color: var(--fcm-muted);
    white-space: nowrap;
}

/* --------------------------------------------------------------- fields */
.fcm-field { margin-bottom: 13px; }

.fcm-field > label,
.fcm-slider label,
.fcm-brush-size label {
    display: block;
    margin-bottom: 7px;
    color: var(--fcm-text);
    font-size: 0.82rem;
    font-weight: 700;
}

.fcm-hint {
    margin: 6px 0 0;
    color: var(--fcm-muted);
    font-size: 0.75rem;
    line-height: 1.45;
}

.fcm-select,
.fcm-file,
.fcm-textarea,
.fcm-input {
    width: 100%;
    min-height: 40px;
    padding: 0 12px;
    border: 1px solid var(--fcm-border);
    border-radius: var(--fcm-radius-sm);
    color: var(--fcm-text);
    background: var(--fcm-panel-soft);
    font: inherit;
    font-size: 0.86rem;
    transition: border-color 0.16s ease, box-shadow 0.16s ease, background 0.16s ease;
}

.fcm-select {
    appearance: none;
    -webkit-appearance: none;
    padding-right: 34px;
    background-image: linear-gradient(45deg, transparent 50%, var(--fcm-muted) 50%),
        linear-gradient(135deg, var(--fcm-muted) 50%, transparent 50%);
    background-position: calc(100% - 17px) 17px, calc(100% - 12px) 17px;
    background-size: 5px 5px, 5px 5px;
    background-repeat: no-repeat;
}

.fcm-file { padding: 7px 10px; }

.fcm-file::file-selector-button {
    margin-right: 9px;
    padding: 6px 10px;
    border: 1px solid var(--fcm-border);
    border-radius: var(--fcm-radius-sm);
    color: var(--fcm-text);
    background: var(--fcm-panel-raised);
    font: inherit;
    font-size: 0.78rem;
    font-weight: 700;
    cursor: pointer;
}

.fcm-textarea {
    min-height: auto;
    padding: 10px 12px;
    resize: vertical;
}

.fcm-select:focus,
.fcm-file:focus,
.fcm-textarea:focus,
.fcm-input:focus {
    border-color: var(--fcm-gold);
    box-shadow: 0 0 0 3px rgba(215, 168, 76, 0.16);
    outline: none;
}

/* --------------------------------------------------------------- switch */
.fcm-switch {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    gap: 10px;
    min-height: 40px;
    margin: 8px 0;
    cursor: pointer;
    user-select: none;
}

.fcm-switch input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.fcm-switch-track {
    position: relative;
    width: 42px;
    height: 24px;
    border: 1px solid var(--fcm-border-strong);
    border-radius: 999px;
    background: var(--fcm-panel-raised);
    transition: background 0.16s ease, border-color 0.16s ease;
}

.fcm-switch-track::after {
    content: "";
    position: absolute;
    top: 2px;
    left: 2px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--fcm-muted);
    transition: transform 0.16s ease, background 0.16s ease;
}

.fcm-switch input:checked + .fcm-switch-track {
    border-color: rgba(215, 168, 76, 0.56);
    background: rgba(215, 168, 76, 0.36);
}

.fcm-switch input:checked + .fcm-switch-track::after {
    transform: translateX(18px);
    background: #fff7df;
}

.fcm-switch input:focus-visible + .fcm-switch-track {
    box-shadow: 0 0 0 3px rgba(215, 168, 76, 0.18);
}

.fcm-switch-label {
    min-width: 0;
    color: var(--fcm-text);
    font-size: 0.84rem;
    line-height: 1.28;
}

/* --------------------------------------------------------------- sliders */
.fcm-slider { margin-bottom: 13px; }

.fcm-slider label {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
}

.fcm-val {
    flex: 0 0 auto;
    color: var(--fcm-gold-2);
    font-size: 0.78rem;
    font-variant-numeric: tabular-nums;
    font-weight: 800;
}

.fcm-range {
    width: 100%;
    height: 25px;
    appearance: none;
    -webkit-appearance: none;
    background: transparent;
    cursor: pointer;
}

.fcm-range::-webkit-slider-runnable-track {
    height: 6px;
    border: 1px solid var(--fcm-border);
    border-radius: 999px;
    background: linear-gradient(90deg, rgba(215, 168, 76, 0.72), var(--fcm-panel-raised));
}

.fcm-range::-moz-range-track {
    height: 6px;
    border: 1px solid var(--fcm-border);
    border-radius: 999px;
    background: var(--fcm-panel-raised);
}

.fcm-range::-webkit-slider-thumb {
    width: 20px;
    height: 20px;
    margin-top: -8px;
    border: 2px solid var(--fcm-gold);
    border-radius: 50%;
    appearance: none;
    -webkit-appearance: none;
    background: #fff7df;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
    transition: transform 0.1s ease;
}

.fcm-range::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border: 2px solid var(--fcm-gold);
    border-radius: 50%;
    background: #fff7df;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}

.fcm-range:active::-webkit-slider-thumb { transform: scale(1.12); }

.fcm-slider-emph {
    margin: 13px 0;
    padding: 12px;
    border: 1px solid rgba(56, 185, 129, 0.42);
    border-radius: var(--fcm-radius);
    background: rgba(56, 185, 129, 0.08);
}

/* --------------------------------------------------------------- buttons */
.fcm-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 40px;
    max-width: 100%;
    padding: 0 14px;
    border: 1px solid transparent;
    border-radius: var(--fcm-radius-sm);
    font: inherit;
    font-size: 0.86rem;
    font-weight: 800;
    line-height: 1.1;
    text-align: center;
    text-decoration: none;
    white-space: normal;
    cursor: pointer;
    transition: transform 0.1s ease, filter 0.16s ease, border-color 0.16s ease, background 0.16s ease;
}

.fcm-btn:active { transform: translateY(1px); }
.fcm-btn-sm { min-height: 34px; padding: 0 11px; font-size: 0.78rem; }
.fcm-btn-block { width: 100%; margin-top: 10px; }

.fcm-btn-primary {
    color: #14110b;
    background: var(--fcm-gold);
    border-color: var(--fcm-gold);
    box-shadow: 0 12px 22px rgba(215, 168, 76, 0.18);
}

.fcm-btn-success {
    color: #06140d;
    background: var(--fcm-green);
    border-color: var(--fcm-green);
    box-shadow: 0 12px 22px rgba(56, 185, 129, 0.18);
}

.fcm-btn-ghost {
    color: var(--fcm-text);
    background: var(--fcm-panel-soft);
    border-color: var(--fcm-border);
}

.fcm-btn-outline {
    color: var(--fcm-text);
    background: transparent;
    border-color: var(--fcm-border-strong);
}

.fcm-btn:hover { filter: brightness(1.06); }
.fcm-btn-ghost:hover,
.fcm-btn-outline:hover {
    border-color: var(--fcm-gold);
    background: rgba(215, 168, 76, 0.1);
}

.fcm-btn:disabled,
.fcm-disabled {
    opacity: 0.42;
    pointer-events: none;
}

.fcm-actions-stack {
    display: grid;
    gap: 9px;
    margin-top: 14px;
}

.fcm-btn-row {
    display: flex;
    align-items: stretch;
    gap: 8px;
    min-width: 0;
}

.fcm-btn-row .fcm-btn { flex: 1 1 0; }

/* --------------------------------------------------------------- segments */
.fcm-segment {
    display: inline-flex;
    gap: 4px;
    padding: 4px;
    border: 1px solid var(--fcm-border);
    border-radius: var(--fcm-radius);
    background: var(--fcm-panel-raised);
}

.fcm-seg-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 30px;
    padding: 0 10px;
    border: 0;
    border-radius: var(--fcm-radius-sm);
    color: var(--fcm-muted);
    background: transparent;
    font: inherit;
    font-size: 0.76rem;
    font-weight: 800;
    line-height: 1.1;
    cursor: pointer;
    transition: color 0.14s ease, background 0.14s ease;
}

.fcm-seg-btn.is-active {
    color: #14110b;
    background: var(--fcm-gold);
}

.fcm-preview-modes {
    width: 100%;
    flex-wrap: wrap;
}

.fcm-preview-modes .fcm-seg-btn { flex: 1 1 auto; }

.fcm-presets {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.fcm-presets .fcm-btn {
    min-height: 36px;
    padding: 0 9px;
}

.fcm-presets .fcm-btn.is-active {
    color: #14110b;
    border-color: var(--fcm-gold);
    background: var(--fcm-gold);
}

/* --------------------------------------------------------------- stage */
/* The result stage shows FIRST in the centre column so it's immediately visible
   after compose; the Source-analysis reference sits below it. */
.fcm-col-preview > #errorBox,
.fcm-col-preview > #warningBox,
.fcm-col-preview > #statusBox { order: 0; }
.fcm-col-preview > .fcm-stage-card { order: 1; }
.fcm-col-preview > #analysisCard { order: 2; }

.fcm-stage-card {
    overflow: hidden;
    padding: 14px;
    border-color: rgba(215, 168, 76, 0.22);
    background:
        linear-gradient(180deg, rgba(215, 168, 76, 0.07), transparent 190px),
        var(--fcm-stage);
}

.fcm-stage-card::before {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    border-top: 2px solid rgba(215, 168, 76, 0.44);
}

.fcm-stage {
    display: grid;
    grid-template-columns: minmax(0, 0.85fr) minmax(0, 1.15fr);
    gap: 12px;
}

#beforeColumn.d-none + div { grid-column: 1 / -1; }

.fcm-two {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.fcm-preview-label {
    margin-bottom: 7px;
    color: var(--fcm-faint);
    font-size: 0.7rem;
    font-weight: 850;
    letter-spacing: 0;
    text-transform: uppercase;
}

.fcm-frame {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    height: clamp(220px, 28vw, 360px);
    min-height: 206px;
    overflow: hidden;
    border: 1px solid var(--fcm-border);
    border-radius: var(--fcm-radius);
    background:
        linear-gradient(rgba(255, 255, 255, 0.025), rgba(0, 0, 0, 0.08)),
        var(--fcm-panel-raised);
}

.fcm-stage-card .fcm-frame {
    height: clamp(300px, 52vh, 560px);
    min-height: 300px;
    background:
        linear-gradient(rgba(255, 255, 255, 0.025), rgba(0, 0, 0, 0.12)),
        var(--fcm-stage);
}

.fcm-stage #beforeColumn:not(.d-none) .fcm-frame,
.fcm-stage #beforeColumn:not(.d-none) + div .fcm-frame {
    height: clamp(240px, 40vh, 400px);
    min-height: 240px;
}

.fcm-img {
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    display: block;
    object-fit: contain;
    object-position: center;
}

.fcm-placeholder {
    position: relative;
    z-index: 1;
    max-width: 240px;
    padding: 11px 13px;
    border: 1px solid var(--fcm-border);
    border-radius: var(--fcm-radius-sm);
    color: var(--fcm-muted);
    background: rgba(8, 8, 8, 0.66);
    font-size: 0.82rem;
    font-weight: 700;
    text-align: center;
}

:root[data-bs-theme="light"] .fcm-placeholder {
    color: var(--fcm-text);
    background: rgba(255, 255, 255, 0.72);
}

.fcm-overlay-wrap {
    position: relative;
    display: inline-block;
    max-width: 100%;
    max-height: 100%;
    height: auto;
    line-height: 0;
}

.fcm-overlay-wrap .fcm-img {
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 100%;
}

.fcm-bbox-canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.fcm-dims {
    margin-top: 12px;
    color: var(--fcm-muted);
    font-size: 0.76rem;
    font-variant-numeric: tabular-nums;
}

/* --------------------------------------------------------------- analysis */
#analysisCard {
    border-color: rgba(94, 147, 243, 0.25);
    background:
        linear-gradient(180deg, rgba(94, 147, 243, 0.08), transparent 160px),
        var(--fcm-panel);
}

.fcm-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
    margin-top: 12px;
}

.fcm-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 28px;
    padding: 0 9px;
    border: 1px solid rgba(94, 147, 243, 0.26);
    border-radius: 999px;
    color: var(--fcm-text);
    background: rgba(94, 147, 243, 0.1);
    font-size: 0.74rem;
}

.fcm-chip strong {
    color: var(--fcm-gold-2);
    font-variant-numeric: tabular-nums;
}

.fcm-chip.fcm-chip-muted {
    border-color: var(--fcm-border);
    color: var(--fcm-muted);
    background: var(--fcm-panel-soft);
}

.fcm-chip.fcm-chip-muted strong { color: var(--fcm-muted); }

/* --------------------------------------------------------------- alerts */
.fcm-alert,
.fcm-status {
    border-radius: var(--fcm-radius);
    padding: 12px 14px;
    font-size: 0.84rem;
    line-height: 1.45;
}

.fcm-alert-error {
    border: 1px solid rgba(224, 95, 85, 0.4);
    color: #ffd2cd;
    background: rgba(224, 95, 85, 0.14);
}

:root[data-bs-theme="light"] .fcm-alert-error { color: #9c2d25; }

.fcm-alert-warn {
    border: 1px solid rgba(231, 177, 75, 0.42);
    color: #ffe0a5;
    background: rgba(231, 177, 75, 0.14);
}

:root[data-bs-theme="light"] .fcm-alert-warn { color: #80520b; }

.fcm-alert-warn ul {
    margin: 6px 0 0;
    padding-left: 19px;
}

.fcm-status {
    display: flex;
    align-items: center;
    gap: 11px;
    border: 1px solid rgba(94, 147, 243, 0.34);
    color: var(--fcm-text);
    background: rgba(94, 147, 243, 0.12);
    font-weight: 750;
}

.fcm-spinner {
    width: 18px;
    height: 18px;
    flex: 0 0 18px;
    border: 2px solid rgba(255, 255, 255, 0.22);
    border-top-color: var(--fcm-gold);
    border-radius: 50%;
    animation: fcm-spin 0.78s linear infinite;
}

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

/* --------------------------------------------------------------- accordions */
.fcm-acc {
    margin-top: 10px;
    overflow: hidden;
    border: 1px solid var(--fcm-border);
    border-radius: var(--fcm-radius);
    background: var(--fcm-panel-soft);
}

.fcm-acc + .fcm-acc { margin-top: 8px; }

.fcm-acc > summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 40px;
    padding: 0 12px;
    color: var(--fcm-text);
    cursor: pointer;
    list-style: none;
    font-size: 0.82rem;
    font-weight: 800;
}

.fcm-acc > summary::-webkit-details-marker { display: none; }

.fcm-acc > summary::after {
    content: "+";
    color: var(--fcm-gold);
    font-size: 1rem;
    font-weight: 900;
}

.fcm-acc[open] > summary {
    border-bottom: 1px solid var(--fcm-border);
}

.fcm-acc[open] > summary::after { content: "-"; }

.fcm-acc-body { padding: 12px; }

.fcm-acc-sub {
    margin-left: auto;
    color: var(--fcm-faint);
    font-size: 0.72rem;
    font-weight: 700;
}

/* --------------------------------------------------------------- helpers */
.fcm-info {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    margin-left: 5px;
    border: 1px solid var(--fcm-border);
    border-radius: 50%;
    color: var(--fcm-muted);
    background: var(--fcm-panel-soft);
    font-size: 10px;
    font-weight: 900;
    line-height: 1;
    cursor: help;
    vertical-align: middle;
}

.fcm-info:hover,
.fcm-info:focus {
    border-color: var(--fcm-gold);
    color: #14110b;
    background: var(--fcm-gold);
    outline: none;
}

.fcm-info::after {
    content: attr(data-tip);
    position: absolute;
    bottom: calc(100% + 9px);
    left: 50%;
    z-index: 80;
    width: 224px;
    max-width: min(60vw, 260px);
    padding: 9px 10px;
    border: 1px solid var(--fcm-border-strong);
    border-radius: var(--fcm-radius);
    color: var(--fcm-text);
    background: var(--fcm-panel-solid);
    box-shadow: var(--fcm-shadow);
    font-size: 0.74rem;
    font-weight: 600;
    line-height: 1.42;
    text-align: left;
    white-space: normal;
    opacity: 0;
    visibility: hidden;
    transform: translateX(-50%);
    transition: opacity 0.12s ease;
    pointer-events: none;
}

.fcm-info:hover::after,
.fcm-info:focus::after {
    opacity: 1;
    visibility: visible;
}

.fcm-col-left .fcm-info::after {
    left: -6px;
    transform: none;
}

.fcm-col-right .fcm-info::after {
    right: -6px;
    left: auto;
    transform: none;
}

.fcm-env-group { margin-top: 8px; }

.fcm-env-off .fcm-env-group,
.fcm-env-off .fcm-presets,
.fcm-env-off #genControls {
    opacity: 0.44;
    pointer-events: none;
}

.fcm-gen-status {
    margin: 10px 0 12px;
    padding: 10px 11px;
    border: 1px solid var(--fcm-border);
    border-radius: var(--fcm-radius);
    color: var(--fcm-muted);
    background: var(--fcm-panel-soft);
    font-size: 0.78rem;
    line-height: 1.4;
}

.fcm-gen-status.is-ready {
    border-color: rgba(56, 185, 129, 0.42);
    color: var(--fcm-text);
    background: rgba(56, 185, 129, 0.09);
}

.fcm-gen-status.is-off {
    border-color: var(--fcm-border-strong);
}

.fcm-gen-warn {
    padding-left: 10px;
    border-left: 3px solid var(--fcm-amber);
}

.fcm-gen-advanced {
    margin-top: 10px;
}

.fcm-gen-advanced summary {
    color: var(--fcm-muted);
    cursor: pointer;
    font-size: 0.82rem;
    font-weight: 800;
}

/* --------------------------------------------------------------- cleanup */
.fcm-cleanup { margin-top: 14px; }

.fcm-tools {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 10px;
}

.fcm-brush-size {
    flex: 1 1 170px;
    min-width: 150px;
}

.fcm-brush-size label {
    display: flex;
    justify-content: space-between;
    margin-bottom: 3px;
    font-size: 0.78rem;
}

.fcm-canvas-frame {
    min-height: 0;
    background:
        repeating-conic-gradient(rgba(255, 255, 255, 0.06) 0% 25%, transparent 0% 50%) 50% / 22px 22px,
        var(--fcm-panel-soft);
}

.fcm-cleanup-canvas {
    width: 100%;
    height: auto;
    display: block;
    cursor: crosshair;
    touch-action: none;
}

/* --------------------------------------------------------------- footer */
.fcm-footer {
    position: relative;
    z-index: 1;
    flex-shrink: 0;
    padding: 18px 0;
    border-top: 1px solid var(--fcm-border);
    color: var(--fcm-muted);
    text-align: center;
    font-size: 0.78rem;
}

.fcm-footer strong { color: var(--fcm-text); }

/* --------------------------------------------------------------- responsive */
@media (max-width: 1280px) {
    .fcm-container { max-width: 1180px; }
    .fcm-grid {
        grid-template-columns: minmax(265px, 310px) minmax(0, 1fr);
    }
    .fcm-col-right {
        grid-column: 1 / -1;
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        align-items: start;
    }
}

@media (max-width: 1179px) {
    .fcm-workbench-head {
        grid-template-columns: 1fr;
    }

    .fcm-grid,
    body:not([data-workflow="complete"]) .fcm-grid {
        grid-template-columns: 1fr;
    }

    .fcm-col-preview { order: -1; }
    .fcm-col-right {
        display: flex;
        grid-column: auto;
    }
}

@media (max-width: 760px) {
    .fcm-container { padding: 0 14px; }
    .fcm-main { padding-top: 14px; }
    .fcm-topbar-inner { height: auto; min-height: 62px; padding-top: 9px; padding-bottom: 9px; }
    .fcm-brand-copy { display: none; }
    .fcm-badge-soft { display: none; }
    .fcm-workbench-title { font-size: 1.36rem; }
    .fcm-workbench-sub { font-size: 0.84rem; }
    .fcm-flow {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
    .fcm-flow-step {
        min-height: 36px;
        font-size: 0.74rem;
    }
    .fcm-card { padding: 14px; }
    .fcm-dropzone {
        grid-template-columns: 1fr;
        text-align: center;
        justify-items: center;
    }
    .fcm-dropzone-icon { grid-row: auto; }
    .fcm-two,
    .fcm-stage {
        grid-template-columns: 1fr;
    }
    #beforeColumn.d-none + div { grid-column: auto; }
    .fcm-stage-card .fcm-frame,
    .fcm-frame {
        height: clamp(220px, 42vh, 360px);
        min-height: 220px;
    }
    .fcm-head-actions,
    .fcm-btn-row {
        width: 100%;
    }
}

@media (max-width: 460px) {
    .fcm-logo-img { height: 34px; }
    .fcm-icon-btn { width: 38px; padding: 0; }
    .fcm-icon-btn span + span,
    .fcm-icon-btn .fcm-theme-label { display: none; }
    .fcm-presets { grid-template-columns: 1fr; }
}

/* ===========================================================================
   FIXES (v2): images fit reliably, JS tooltips (no clipping), cleanup modal
   =========================================================================== */

/* Any media never overflows its container (kills the "only shows when zoomed
   out" problem). */
.fcm-main img,
.fcm-main canvas { max-width: 100%; }

/* Bulletproof preview image: shrink to fit the frame, keep aspect, never spill. */
.fcm-img {
    width: auto !important;
    height: auto !important;
    max-width: 100% !important;
    max-height: 100% !important;
    object-fit: contain;
    margin: auto;
}

/* Disable the CSS pseudo-tooltip; a JS fixed-position tooltip replaces it so the
   text is never clipped by an ancestor's overflow. */
.fcm-info::after,
.fcm-info::before { content: none !important; display: none !important; }

/* Floating help tooltip (positioned by JS at document level). */
#fcmTip {
    position: fixed;
    z-index: 400;
    max-width: 280px;
    padding: 9px 11px;
    border-radius: 9px;
    background: var(--fcm-panel-solid);
    color: var(--fcm-text);
    border: 1px solid var(--fcm-border-strong);
    box-shadow: var(--fcm-shadow);
    font-size: 12px;
    line-height: 1.5;
    pointer-events: none;
    opacity: 0;
    transform: translateY(3px);
    transition: opacity 0.12s ease, transform 0.12s ease;
}
#fcmTip.is-visible { opacity: 1; transform: translateY(0); }

/* ------------------------------------------------------------- cleanup modal */
.fcm-modal {
    position: fixed;
    inset: 0;
    z-index: 300;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 18px;
    background: rgba(0, 0, 0, 0.68);
    backdrop-filter: blur(5px);
}
.fcm-modal.d-none { display: none !important; }
.fcm-modal-card {
    width: min(960px, 96vw);
    max-height: 94vh;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 16px 18px;
    border: 1px solid var(--fcm-border-strong);
    border-radius: 12px;
    background: var(--fcm-panel-solid);
    box-shadow: var(--fcm-shadow);
}
.fcm-modal-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 14px;
}
.fcm-modal-title { margin: 0; font-size: 1.05rem; font-weight: 750; }
.fcm-modal-sub { margin: 3px 0 0; color: var(--fcm-muted); font-size: 0.8rem; }
.fcm-modal-close {
    flex: 0 0 auto;
    width: 34px; height: 34px;
    display: inline-flex; align-items: center; justify-content: center;
    border: 1px solid var(--fcm-border); border-radius: 8px;
    background: var(--fcm-panel-soft); color: var(--fcm-text);
    font-size: 1.2rem; line-height: 1; cursor: pointer;
}
.fcm-modal-close:hover { border-color: var(--fcm-gold); }
.fcm-modal-canvas-wrap {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px;
    border-radius: 10px;
    overflow: auto;
    background:
        repeating-conic-gradient(rgba(255, 255, 255, 0.06) 0% 25%, transparent 0% 50%) 50% / 22px 22px,
        var(--fcm-panel-soft);
}
.fcm-modal .fcm-cleanup-canvas {
    max-width: 100%;
    max-height: 68vh;
    width: auto;
    height: auto;
    display: block;
    cursor: crosshair;
    touch-action: none;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
}
.fcm-modal-tools {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
}
.fcm-modal-tools .fcm-brush-size { flex: 1 1 180px; min-width: 150px; }
@media (max-width: 600px) {
    .fcm-modal-card { padding: 13px; }
    .fcm-modal .fcm-cleanup-canvas { max-height: 56vh; }
}

/* ------------------------------------------------------- sign-in screen */
.fcm-auth-body {
    /* A quiet, even backdrop: the workbench's grid overlay and 420px gradient
       are busy behind a single small card. */
    background: var(--fcm-bg);
}

.fcm-auth-body::before { display: none; }

.fcm-auth-shell {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 24px 16px;
}

.fcm-auth-card {
    width: 100%;
    max-width: 352px;
    padding: 34px 30px 26px;
    border: 1px solid var(--fcm-border);
    border-radius: 12px;
    background: var(--fcm-panel-solid);
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.28);
    text-align: left;
}

:root[data-bs-theme="light"] .fcm-auth-card {
    box-shadow: 0 24px 60px rgba(43, 36, 26, 0.10);
}

/* The wordmark's lower line is navy and would vanish on the dark card, so the
   logo sits on a plate. Keeping it small, warm and softly bordered stops it
   reading as a bright block punched out of the card. */
.fcm-auth-logo {
    width: 104px;
    height: auto;
    margin: 0 0 22px;
    display: block;
    padding: 10px 13px;
    border: 1px solid var(--fcm-border);
    border-radius: 10px;
    background: rgba(242, 238, 230, 0.9);
}

:root[data-bs-theme="light"] .fcm-auth-logo {
    border-color: transparent;
    background: transparent;
    padding: 0;
}

.fcm-auth-title {
    margin: 0 0 5px;
    color: var(--fcm-text);
    font-size: 1.28rem;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.fcm-auth-sub {
    margin: 0 0 24px;
    color: var(--fcm-muted);
    font-size: 0.8rem;
}

.fcm-auth-card .fcm-field { margin-bottom: 15px; }

.fcm-auth-card .fcm-field > label {
    color: var(--fcm-muted);
    font-size: 0.76rem;
    font-weight: 600;
}

.fcm-auth-card .fcm-input {
    background: var(--fcm-panel-soft);
}

/* A calmer submit: the brand gold as a flat fill, without the lifted glow the
   workbench buttons use to compete with a dense UI. */
.fcm-auth-card .fcm-btn-primary {
    margin-top: 20px;
    min-height: 42px;
    border-radius: var(--fcm-radius-sm);
    font-weight: 700;
    box-shadow: none;
}

.fcm-auth-alert {
    margin-bottom: 18px;
    font-size: 0.79rem;
}

.fcm-auth-alert code {
    color: inherit;
    font-size: 0.75rem;
    word-break: break-all;
}

.fcm-auth-foot {
    margin: 22px 0 0;
    padding-top: 16px;
    border-top: 1px solid var(--fcm-border);
    color: var(--fcm-faint);
    font-size: 0.72rem;
    text-align: center;
}

/* ------------------------------------------------------- account chip */
.fcm-user-chip {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    min-height: 32px;
    max-width: 190px;
    padding: 0 11px;
    border: 1px solid var(--fcm-border);
    border-radius: 999px;
    color: var(--fcm-text);
    background: var(--fcm-panel-soft);
    font-size: 0.75rem;
    font-weight: 650;
    white-space: nowrap;
}

.fcm-user-chip span {
    overflow: hidden;
    text-overflow: ellipsis;
}

.fcm-user-dot {
    flex: none;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--fcm-green);
}

@media (max-width: 720px) {
    .fcm-user-chip { max-width: 120px; }
}

.fcm-logout-form { margin: 0; display: inline-flex; }

@media (max-width: 460px) {
    /* The narrow-screen rule collapses icon buttons to a 38px square; the
       sign-out button is text-only, so keep it auto-width and drop the
       username chip instead. */
    .fcm-user-chip { display: none; }
    .fcm-logout-form .fcm-icon-btn { width: auto; padding: 0 11px; }
}
