/* ── Export — transform wrapper (panel + tab slide together) ──────────────────── */
/* Backdrop-filter lives on the panel and tab individually so the blur area
   is confined to each element's own footprint — no ghost blur when closed.    */

#export-wrapper {
    position: fixed;
    top: 0;
    left: 0;
    width: calc(var(--panel-width) + var(--tab-width) - 1px);
    height: 100%;
    z-index: var(--z-panel);
    transition: transform var(--ease-panel);
    pointer-events: none;        /* children opt back in individually */
    user-select: none;
    transform: translateX(calc(-1 * var(--panel-width))); /* closed by default */
}
#export-wrapper.open {
    transform: translateX(0);
}

/* ── Panel ───────────────────────────────────────────────────────────────────── */
#export-panel {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--panel-width);
    background: var(--panel-bg);
    backdrop-filter: blur(var(--panel-blur));
    -webkit-backdrop-filter: blur(var(--panel-blur));
    border-right: var(--border-panel);
    display: flex;
    flex-direction: column;
    font-family: var(--font-main);
    font-size: var(--font-size-base);
    color: var(--text-primary);
    pointer-events: auto;
}

/* ── Tab — floats off the right edge of the panel ────────────────────────────── */
#export-tab {
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    width: var(--tab-width);
    height: var(--tab-height);
    background: var(--panel-bg);
    backdrop-filter: blur(var(--panel-blur));
    -webkit-backdrop-filter: blur(var(--panel-blur));
    border: var(--border-panel);
    border-left: none;
    border-radius: 0 var(--radius-1) var(--radius-1) 0;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    pointer-events: auto;
    transition: background var(--ease-hover);
}
#export-tab:hover {
    background: var(--panel-bg-hover);
}

#export-wrapper.open #export-tab .tab-arrow-icon { transform: rotate(180deg); }

/* ── Header ──────────────────────────────────────────────────────────────────── */
#export-header {
    padding: var(--pad-header) var(--pad-outer) var(--pad-inner);
    border-bottom: var(--border-panel);
    flex-shrink: 0;
    display: flex;
    align-items: center;
}
#export-title {   /* s1 — heading: export panel title */
    font-size: var(--font-size-base);
    font-weight: var(--font-weight-bold);
    letter-spacing: var(--letter-spacing-ui);
    text-transform: uppercase;
    color: var(--t-sidebar-title-color);
}

/* ── Scrollable body ─────────────────────────────────────────────────────────── */
#export-body {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0;
    scrollbar-width: none;
    -ms-overflow-style: none;
    display: flex;
    flex-direction: column;
}

/* ── Save-target row (above groups, own padding) ─────────────────────────────── */
.exp-save-target {
    padding: var(--pad-inner) var(--pad-outer);
    border-bottom: var(--border-sub);
}
#export-body::-webkit-scrollbar { display: none; }

/* ── Rows ────────────────────────────────────────────────────────────────────── */
.exp-row {
    display: flex;
    align-items: center;
    gap: var(--gap-row);
    min-height: var(--row-height);
}
.exp-row label {
    width: var(--label-width-exp);
    flex-shrink: 0;
    font-size: var(--font-size-base);
    color: var(--text-secondary);
    white-space: nowrap;
}

/* ── Dropdowns ───────────────────────────────────────────────────────────────── */
.exp-row select {
    flex: 1;
    background: var(--surface-input);
    border: var(--border-input);
    border-radius: var(--radius-2);
    color: var(--text-primary);
    font-size: var(--font-size-base);
    font-family: inherit;
    padding: 3px 20px 3px 6px;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='rgba(255,255,255,0.4)'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 6px center;
}
.exp-row select:hover { border-color: var(--border-color-hover); }
/* Ensure the native popup options are readable on dark-themed pages */
.exp-row select option {
    background: var(--select-option-bg);
    color: var(--text-hover);
}

/* ── Quality slider (fill style matching controls) ───────────────────────────── */
.exp-row input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    flex: 1;
    height: var(--ctrl-height);
    background: linear-gradient(to right,
        color-mix(in srgb, var(--group-accent, var(--slider-fill)) var(--group-accent-dim), var(--group-dim-base)) 0%,
        color-mix(in srgb, var(--group-accent, var(--slider-fill)) var(--group-accent-dim), var(--group-dim-base)) var(--fill, 92%),
        var(--slider-empty) var(--fill, 92%),
        var(--slider-empty) 100%
    );
    border-radius: var(--radius-2);
    outline: none;
    cursor: pointer;
    padding: 0;
}
.exp-row input[type="range"]::-webkit-slider-runnable-track {
    height: var(--ctrl-height);
    background: transparent;
    border-radius: var(--radius-2);
}
.exp-row input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: var(--slider-thumb-width);
    height: var(--ctrl-height);
    border-radius: 0;
    background: var(--group-accent, var(--slider-thumb-color));
    cursor: pointer;
    transition: width 0.1s;
}
.exp-row input[type="range"]:hover::-webkit-slider-thumb  { width: calc(var(--slider-thumb-width) + 1px); }
.exp-row input[type="range"]:active::-webkit-slider-thumb { width: calc(var(--slider-thumb-width) + 1px); }
.exp-row input[type="range"]::-moz-range-track {
    height: var(--ctrl-height);
    background: var(--slider-empty);
    border-radius: var(--radius-2);
}
.exp-row input[type="range"]::-moz-range-progress {
    height: var(--ctrl-height);
    background: color-mix(in srgb, var(--group-accent, var(--slider-fill)) var(--group-accent-dim), var(--group-dim-base));
    border-radius: var(--radius-2) 0 0 var(--radius-2);
}
.exp-row input[type="range"]::-moz-range-thumb {
    width: var(--slider-thumb-width);
    height: var(--ctrl-height);
    border-radius: 0;
    background: var(--group-accent, var(--slider-thumb-color));
    border: none;
    cursor: pointer;
}

.exp-val {   /* numeric: read-only value display (e.g. quality %, dimensions) */
    width: var(--swatch-width);
    flex-shrink: 0;
    font-size: var(--font-size-base);
    color: var(--t-info-color);
    text-align: right;
    font-family: var(--font-numeric);
}

/* ── Custom W×H number inputs ────────────────────────────────────────────────── */
.exp-num-input {
    flex: 1;
    background: var(--surface-input);
    border: var(--border-input);
    border-radius: var(--radius-2);
    color: var(--text-primary);
    font-size: var(--font-size-base);
    font-family: inherit;
    padding: 3px 6px;
    text-align: center;
    outline: none;
    min-width: 0;
}
.exp-num-input:focus { border-color: var(--border-color-hover); }

.exp-x-sep {
    flex-shrink: 0;
    font-size: var(--font-size-base);
    color: var(--text-dim);
}

/* ── Read-only info line ─────────────────────────────────────────────────────── */
.exp-info {   /* numeric: read-only info line (frame count, resolution) */
    font-size: var(--font-size-base);
    color: var(--t-info-color);
    font-family: var(--font-numeric);
    padding-left: 2px;
}

/* ── Size estimate hint ──────────────────────────────────────────────────────── */
.exp-size-hint {   /* numeric: estimated file size hint */
    font-size: var(--font-size-base);
    font-family: var(--font-numeric);
    color: var(--text-dim);
    opacity: 0.6;
    padding-left: 2px;
}

/* ── Sequence progress detail (frame counter + cancel; the in-button bar shows fill) ── */
#exp-progress-wrap {
    display: none;
    flex-direction: column;
    gap: var(--gap-content);
}
#exp-progress-label {   /* numeric: export progress counter */
    font-size: var(--font-size-base);
    font-family: var(--font-numeric);
    color: var(--text-secondary);
}
#exp-cancel-btn {   /* s3 — button: cancel export */
    font-size: var(--font-size-sm);
    letter-spacing: var(--letter-spacing-sm);
    text-transform: uppercase;
    font-family: inherit;
    background: none;
    border: var(--border-input);
    border-radius: var(--radius-2);
    color: var(--text-muted);
    padding: 4px 0;
    cursor: pointer;
    transition: all var(--ease-hover);
}
#exp-cancel-btn:hover {
    border-color: var(--border-color-hover);
    color: var(--text-primary);
}

/* ── Save destination chooser ────────────────────────────────────────────────── */
.exp-save-label {
    font-size: var(--font-size-base);
    color: var(--text-secondary);
    margin-bottom: var(--gap-content);
}
.exp-save-choices {
    display: flex;
    gap: var(--slider-gap);
}
.exp-save-opt {
    flex: 1;
    background: var(--surface-input);
    border: var(--border-input);
    border-radius: var(--radius-2);
    color: var(--text-secondary);
    font-family: inherit;
    font-size: var(--font-size-base);
    padding: 5px 4px;
    cursor: pointer;
    white-space: nowrap;
    transition: all var(--ease-hover);
}
.exp-save-opt:hover:not(:disabled) {
    background: var(--surface-hover);
    border-color: var(--border-color-hover);
    color: var(--text-hover);
}
.exp-save-opt.is-active {
    background: var(--surface-active);
    border-color: var(--border-color-on);
    color: var(--text-hover);
}
.exp-save-opt:disabled {
    opacity: 0.4;
    cursor: default;
}

.exp-save-status {
    font-size: var(--font-size-base);
    font-family: var(--font-numeric);
    color: var(--text-label);
    margin-top: var(--gap-content);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.exp-save-status:empty { display: none; }

.exp-save-hint {
    font-size: var(--font-size-base);
    color: var(--text-dim);
    line-height: 1.35;
    margin: var(--gap-content) 0 0;
}

/* ── Export groups — dimmed + inert until a save destination is chosen ───────── */
.exp-groups {
    display: flex;
    flex-direction: column;
    transition: opacity var(--ease-hover);
}
.exp-groups.is-locked {
    opacity: 0.35;
}

/* ── Group headers mirror the controls sidebar ───────────────────────────────
   Export sits on the left edge, so the header layout is flipped relative to the
   controls panel: collapse +/- on the outer (left) edge, identity glyph toward
   screen centre (right). The shared summary::before / ::after roles are swapped. */
#export-panel .ctrl-group > summary {               /* header stripe, mirrored right (full opacity) */
    box-shadow: inset -3px 0 0 var(--group-accent);
}
#export-panel .ctrl-content {                       /* content stripe, mirrored right (dimmed) */
    box-shadow: inset -3px 0 0 color-mix(in srgb, var(--group-accent) var(--group-accent-dim), var(--group-dim-base));
}
#export-panel .ctrl-group > summary::before {       /* collapse +/- (left) — neutral */
    width: var(--icon-size);
    height: var(--icon-size);
    background-color: currentColor;
    -webkit-mask-image: url('/assets/icons/ui/ui_plus.svg');
    mask-image: url('/assets/icons/ui/ui_plus.svg');
    opacity: 0.6;
}
#export-panel .ctrl-group[open] > summary::before {
    -webkit-mask-image: url('/assets/icons/ui/ui_minus.svg');
    mask-image: url('/assets/icons/ui/ui_minus.svg');
    opacity: 0.8;
}
#export-panel .ctrl-group > summary::after {        /* identity glyph (right) — accent */
    width: var(--ctrl-group-icon-size);
    height: var(--ctrl-group-icon-size);
    margin-left: auto;
    background-color: var(--group-accent, currentColor);
    -webkit-mask-image: var(--group-icon);
    mask-image: var(--group-icon);
    opacity: 1;
}

/* ── Full-width action button (Download Image · Download Sequence · Download HTML) ── */
.exp-full-btn,
#export-download-btn {   /* s3 — button (primary): main action buttons at base size */
    position: relative;
    overflow: hidden;
    width: 100%;
    padding: 8px 0;
    background: var(--surface-input);
    border: var(--border-input);
    border-radius: var(--radius-2);
    color: var(--text-primary);
    font-family: inherit;
    font-size: var(--font-size-base);
    letter-spacing: var(--letter-spacing-sm);
    text-transform: uppercase;
    cursor: pointer;
    transition: all var(--ease-hover);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}
.exp-full-btn::before,
#export-download-btn::before {
    content: '';
    display: block;
    position: relative;   /* sit above the progress fill */
    z-index: 2;
    width: var(--icon-size);
    height: var(--icon-size);
    flex-shrink: 0;
    background-color: currentColor;
    -webkit-mask-image: url('/assets/icons/ui/ui_download.svg');
    -webkit-mask-size: contain;
    -webkit-mask-repeat: no-repeat;
    -webkit-mask-position: center;
    mask-image: url('/assets/icons/ui/ui_download.svg');
    mask-size: contain;
    mask-repeat: no-repeat;
    mask-position: center;
}
.exp-full-btn:hover,
#export-download-btn:hover {
    background: var(--surface-hover);
    border-color: var(--border-color-on);
    color: var(--text-hover);
}
.exp-full-btn:disabled,
#export-download-btn:disabled {
    opacity: 0.40;
    cursor: default;
}

/* ── In-button download progress + support nudge ─────────────────────────────── */
/* Progress fill — the live palette gradient, revealed left→right via clip-path.
   Same gradient the preset bar shows (var(--palette-gradient)), so it reflects the
   user's current colours at the moment of export. */
.exp-btn-label {
    position: relative;
    z-index: 2;
}
.exp-btn-progress {
    position: absolute;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    opacity: 0;
    background: var(--palette-gradient,
        linear-gradient(to right, rgb(0,51,221) 0%, rgb(221,153,0) 50%, rgb(204,17,102) 100%));
    clip-path: inset(0 100% 0 0);
    transition: clip-path 0.12s linear, opacity 0.25s ease;
}
.exp-full-btn.is-downloading .exp-btn-progress,
#export-download-btn.is-downloading .exp-btn-progress {
    opacity: 0.95;
}
/* Keep full opacity while running even though the button is disabled */
.exp-full-btn.is-downloading:disabled,
#export-download-btn.is-downloading:disabled {
    opacity: 1;
}
/* Legible label + icon over the bright gradient */
.exp-full-btn.is-downloading .exp-btn-label,
#export-download-btn.is-downloading .exp-btn-label {
    color: #fff;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.55);
}
.exp-full-btn.is-downloading::before,
#export-download-btn.is-downloading::before {
    background-color: #fff;
}

/* Completion blink — pulses in the group's accent colour */
@keyframes bmc-btn-blink {
    0%, 100% { box-shadow: none; }
    50% {
        box-shadow: 0 0 0 1px var(--group-accent, var(--border-color-on)),
                    0 0 12px 1px color-mix(in srgb, var(--group-accent, #fff) 55%, transparent);
    }
}
.exp-full-btn.is-complete,
#export-download-btn.is-complete {
    animation: bmc-btn-blink 0.28s ease-in-out 2;
    border-color: var(--group-accent, var(--border-color-on));
}

/* Squared bottom corners while a nudge is attached, so the two meet flush */
.exp-full-btn.nudge-attached,
#export-download-btn.nudge-attached {
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
}

/* ── Support nudge — expands below the button on a successful export ──────────── */
.bmc-nudge {
    overflow: hidden;
    max-height: 0;
    opacity: 0;
    padding: 0 10px;
    /* Cancel the .ctrl-content flex row-gap so the nudge sits flush under the button */
    margin-top: calc(-1 * var(--gap-content));
    background: var(--surface-input);
    border: var(--border-input);
    border-top: none;
    border-radius: 0 0 var(--radius-2) var(--radius-2);
    position: relative;
    transition: max-height 0.35s ease, opacity 0.3s ease, padding 0.35s ease;
}
.bmc-nudge.is-open {
    max-height: 200px;
    opacity: 1;
    padding: 10px;
}
.bmc-nudge-close {
    position: absolute;
    top: 3px;
    right: 5px;
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 16px;
    line-height: 1;
    padding: 2px;
    cursor: pointer;
    transition: color var(--ease-hover);
}
.bmc-nudge-close:hover { color: var(--text-primary); }
.bmc-nudge-msg {
    margin: 0 16px 8px 0;
    font-size: var(--font-size-base);
    color: var(--text-secondary);
    line-height: 1.4;
}
.bmc-nudge-link {
    display: block;
    /* The transparent logo art is dark — sit it on the BMC brand-yellow so it reads */
    background: #ffdd00;
    border-radius: var(--radius-2);
    padding: 8px 14px;
    transition: filter var(--ease-hover);
}
.bmc-nudge-link:hover {
    filter: brightness(1.05);
}
.bmc-nudge-img {
    display: block;
    width: 100%;
    height: auto;
}

/* ── Aspect ratio chip selector ─────────────────────────────────────────────── */
/* Six chips in a 3-column wrap: 16:9 · 4:3 · 1:1 / 9:16 · 21:9 · Custom      */
.exp-aspect-chips {
    display: flex;
    flex-wrap: wrap;
    gap: var(--slider-gap);
}
.exp-aspect-chip {
    flex: 1 0 calc(33.333% - var(--slider-gap));
    background: var(--surface-input);
    border: var(--border-input);
    border-radius: var(--radius-2);
    color: var(--text-secondary);
    font-family: inherit;
    font-size: var(--font-size-base);
    padding: 4px 2px;
    cursor: pointer;
    text-align: center;
    white-space: nowrap;
    transition: all var(--ease-hover);
}
.exp-aspect-chip:hover:not(.is-active) {
    background: var(--surface-hover);
    border-color: var(--border-color-hover);
    color: var(--text-hover);
}
.exp-aspect-chip.is-active {
    background: var(--surface-active);
    border-color: var(--border-color-on);
    color: var(--text-hover);
}

/* ── Export preview thumbnail ────────────────────────────────────────────────── */
/* Dark wrapper acts as letterbox/pillarbox background when the export aspect
   doesn't match the screen — portrait exports show side bars, ultrawide shows
   top & bottom bars, making the crop immediately obvious.                      */
.exp-preview-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.04);  /* neutral letterbox — reads as "outside frame" */
    border: var(--border-input);
    border-radius: var(--radius-2);
    overflow: hidden;
    line-height: 0;   /* prevent phantom gap beneath inline canvas */
}
.exp-preview-thumb {
    display: block;
    max-width: 100%;
    max-height: 150px;
    width: auto;
    height: auto;
    /* Checkerboard shows through transparent WebGL pixels — same pattern as the
       main canvas background, scaled down to 8 px tiles for the small preview. */
    background-color: var(--color-bg);
    background-image:
        linear-gradient(45deg,  var(--checker) 25%, transparent 25%),
        linear-gradient(-45deg, var(--checker) 25%, transparent 25%),
        linear-gradient(45deg,  transparent 75%, var(--checker) 75%),
        linear-gradient(-45deg, transparent 75%, var(--checker) 75%);
    background-size: 8px 8px;
    background-position: 0 0, 0 4px, 4px -4px, -4px 0;
}

/* ── Statistics footer ──────────────────────────────────────────────────────── */
#exp-stats {
    flex-shrink: 0;
    padding: var(--pad-inner) var(--pad-outer);
    border-top: var(--border-sub);
}

.exp-stats-title {
    display: block;
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-bold);
    letter-spacing: var(--letter-spacing-sm);
    text-transform: uppercase;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.exp-stats-grid {
    display: flex;
    flex-direction: column;
    gap: 1px;
}

/* Each row is a flex container; ::before is the proportional fill bar */
.exp-stats-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 1px 4px;
    border-radius: var(--radius-2);
    position: relative;
    overflow: hidden;
}
.exp-stats-row::before {
    content: '';
    position: absolute;
    inset: 0;
    width: var(--stat-bar, 0%);
    background: color-mix(in srgb, var(--stat-accent) 12%, transparent);
    border-radius: inherit;
    transition: width 0.6s ease-out;
    pointer-events: none;
}

.exp-stats-label {
    font-size: var(--font-size-base);
    color: var(--text-dim);
    line-height: 1.7;
    position: relative;
    z-index: 1;
}

.exp-stats-val {
    font-family: var(--font-numeric);
    font-size: var(--font-size-base);
    color: var(--stat-accent, var(--text-secondary));
    text-align: right;
    line-height: 1.7;
    position: relative;
    z-index: 1;
    transition: color var(--ease-hover);
}

@keyframes stat-tick {
    0%   { color: var(--text-hover); }
    100% { color: var(--stat-accent, var(--text-secondary)); }
}
.exp-stats-val.is-ticking {
    animation: stat-tick 0.4s ease-out forwards;
}
