:root {
    --bg: #0a0c11;
    --bg-deep: #06080c;
    --panel: #11141b;
    --panel-2: #161a23;
    --line: #1d2230;
    --line-2: #2a3142;
    --text: #e7ecf3;
    --muted: #6c7689;
    --dim: #3d4555;
    --hot: #ff2d7a;
    --amber: #ffb000;
    --cyan: #00d4ff;
    --lime: #bfff00;
    --danger: #ff3344;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: "Barlow Condensed", Helvetica, Arial, sans-serif;
    font-weight: 500;
    letter-spacing: .02em;
}

body {
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#app {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    width: 100%;
}

.mono { font-family: "JetBrains Mono", ui-monospace, Consolas, monospace; font-weight: 500; }
.muted { color: var(--muted); }
.dim { color: var(--dim); }
.hot { color: var(--hot); }

/* HEADER */
header.app {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 18px;
    border-bottom: 1px solid var(--line-2);
    background: linear-gradient(180deg, #0d1018 0, #0a0c11 100%);
    z-index: 30;
}

.brand { display: flex; align-items: center; gap: 18px; }
.brand .glyph {
    width: 22px;
    height: 22px;
    background-image: url("../favicon.svg");
    background-repeat: no-repeat;
    background-position: center;
    background-size: contain;
}
.brand h1 {
    font-size: 18px;
    margin: 0;
    text-transform: uppercase;
    letter-spacing: .22em;
    font-weight: 700;
}
.brand .sub {
    font-size: 11px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .32em;
}

.file-tag {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: 18px;
    padding-left: 18px;
    border-left: 1px solid var(--line-2);
    cursor: pointer;
    transition: color .12s ease;
}
.file-tag:hover .ft-name { color: var(--hot); }
.file-tag .ft-name { font-size: 12px; color: var(--muted); letter-spacing: .06em; }
.file-tag .ft-dirty { color: var(--amber); font-size: 14px; line-height: 1; display: none; }
.file-tag.dirty .ft-dirty { display: inline; }
.file-tag.dirty .ft-name { color: var(--text); }

.header-actions { display: flex; gap: 8px; align-items: center; }

.header-quality {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0 6px;
    border-left: 1px solid var(--line);
    border-right: 1px solid var(--line);
}
.header-quality input[type=range] {
    width: 90px;
    accent-color: var(--hot);
}
.header-quality.hidden { display: none; }

.header-label {
    font-size: 10px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .18em;
}

.header-select {
    background: var(--panel-2);
    color: var(--text);
    border: 1px solid var(--line-2);
    font-family: "Barlow Condensed", sans-serif;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .12em;
    padding: 5px 8px;
}

/* BUTTONS */
.btn {
    font-family: "Barlow Condensed", sans-serif;
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .2em;
    background: transparent;
    color: var(--text);
    border: 1px solid var(--line-2);
    padding: 7px 14px;
    cursor: pointer;
    white-space: nowrap;
    transition: all .12s ease;
}
.btn:hover { border-color: var(--hot); color: var(--hot); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn:disabled:hover { border-color: var(--line-2); color: var(--text); }
.btn.primary { background: var(--hot); border-color: var(--hot); color: #0a0c11; }
.btn.primary:hover { background: #ff5c95; border-color: #ff5c95; color: #0a0c11; }
.btn.ghost { border-color: var(--line); }
.btn.danger { border-color: var(--danger); color: var(--danger); }
.btn.danger:hover { background: var(--danger); color: #0a0c11; }
.btn.lime { border-color: var(--lime); color: var(--lime); }
.btn.lime:hover { background: var(--lime); color: #0a0c11; }
.btn.cyan { border-color: var(--cyan); color: var(--cyan); }
.btn.cyan:hover { background: var(--cyan); color: #0a0c11; }
.btn.tiny { padding: 3px 7px; font-size: 10px; letter-spacing: .16em; }
.btn.icon {
    padding: 6px 8px;
    line-height: 1;
    font-size: 14px;
    letter-spacing: 0;
}
.btn.is-active { background: var(--hot); border-color: var(--hot); color: #0a0c11; }
.btn.is-active:hover { background: #ff5c95; border-color: #ff5c95; color: #0a0c11; }
.btn .btn-icon {
    display: inline-block;
    font-size: 14px;
    line-height: 1;
    margin-right: 6px;
    letter-spacing: 0;
    vertical-align: -1px;
}

/* TABS */
.tabs {
    display: flex;
    align-items: stretch;
    background: var(--bg-deep);
    border-bottom: 1px solid var(--line-2);
    z-index: 25;
}
.tabs .tab {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 20px;
    cursor: pointer;
    border-right: 1px solid var(--line);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .22em;
    color: var(--muted);
    transition: color .35s ease, background .35s ease, border-color .35s ease, opacity .35s ease;
    position: relative;
}
.tabs .tab.disabled { cursor: not-allowed; }

/* Shimmer sweep applied once when a disabled tab becomes enabled. Travels
   diagonally from the top-left corner to the bottom-right corner with a
   cool metallic-grey highlight band. */
.tabs .tab.shimmer {
    position: relative;
    overflow: hidden;
}
.tabs .tab.shimmer::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(
        135deg,
        transparent 25%,
        rgba(180, 195, 215, .15) 42%,
        rgba(231, 236, 243, .55) 50%,
        rgba(180, 195, 215, .15) 58%,
        transparent 75%
    );
    transform: translate(-100%, -100%);
    animation: tab-shimmer 1.1s ease-out forwards;
    pointer-events: none;
}
@keyframes tab-shimmer {
    to { transform: translate(100%, 100%); }
}
.tabs .tab.disabled .tnum,
.tabs .tab.disabled .tname,
.tabs .tab.disabled .tcount {
    color: var(--dim);
    opacity: .45;
}
.tabs .tab.disabled .tcount { border-color: var(--line); }
.tabs .tab.disabled:hover { background: transparent; }
.tabs .tab.disabled:hover .tnum,
.tabs .tab.disabled:hover .tname,
.tabs .tab.disabled:hover .tcount { color: var(--dim); opacity: .45; }
.tabs .tab .tnum { font-size: 10px; color: var(--dim); letter-spacing: .06em; }
.tabs .tab .tname { font-weight: 600; }
.tabs .tab .tcount {
    font-size: 10px;
    color: var(--dim);
    letter-spacing: .06em;
    border: 1px solid var(--line);
    padding: 1px 6px;
}
.tabs .tab:hover { color: var(--text); background: rgba(255, 255, 255, .02); }
.tabs .tab:hover .tnum { color: var(--muted); }
.tabs .tab.active {
    color: var(--hot);
    background: var(--bg);
    border-bottom: 1px solid var(--bg);
    margin-bottom: -1px;
}
.tabs .tab.active::before {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    height: 2px;
    background: var(--hot);
}
.tabs .tab.active .tnum { color: var(--hot); opacity: .6; }
.tabs .tab.active .tcount { border-color: var(--hot); color: var(--hot); }
.tab-grow { flex: 1; border-bottom: 1px solid var(--line-2); }

/* MAIN + PREVIEW */
main {
    flex: 1;
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr);
    min-height: 0;
    position: relative;
    overflow: hidden;
}
main.with-stack {
    grid-template-columns: 1fr 320px;
}

.preview {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    background:
        repeating-conic-gradient(#0c0e15 0% 25%, #0a0c11 0% 50%) 0 / 24px 24px;
    overflow: hidden;
}
/* OVERLAY HANDLES (drag-to-position over the preview) */
.overlay-handles {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 10;
    opacity: 1;
    transition: opacity .15s ease;
}
.overlay-handles.is-hidden { opacity: 0; pointer-events: none; }
.overlay-handles.is-hidden .overlay-handle { pointer-events: none; }
.overlay-handle {
    position: absolute;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--hot);
    border: 2px solid var(--text);
    box-shadow: 0 0 0 1px rgba(0, 0, 0, .8), 0 2px 8px rgba(0, 0, 0, .6);
    transform: translate(-50%, -50%);
    cursor: grab;
    pointer-events: auto;
    transition: transform .12s ease, background .12s ease;
    touch-action: none;
}
.overlay-handle:hover {
    transform: translate(-50%, -50%) scale(1.25);
    background: #ff5c95;
}
.overlay-handle.is-dragging {
    cursor: grabbing;
    transform: translate(-50%, -50%) scale(1.35);
    background: var(--cyan);
}

.preview canvas {
    max-width: 100%;
    max-height: 100%;
    box-shadow: 0 0 0 1px var(--line-2), 0 24px 80px rgba(0, 0, 0, .6);
    display: block;
}
.preview .empty {
    color: var(--muted);
    text-align: center;
    padding: 32px 44px;
    border: 1px dashed var(--line-2);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .22em;
    cursor: pointer;
    transition: color .12s ease, border-color .12s ease, background .12s ease;
}
.preview .empty:hover {
    color: var(--hot);
    border-color: var(--hot);
    background: rgba(255, 45, 122, .04);
}
.preview.drag-over::after {
    content: "DROP IMAGE";
    position: absolute;
    inset: 12px;
    border: 2px dashed var(--hot);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--hot);
    font-size: 14px;
    letter-spacing: .3em;
    pointer-events: none;
    background: rgba(255, 45, 122, .04);
}

/* STACK PANEL (always visible, right column of <main>) */
.stack-panel {
    background: var(--panel);
    border-left: 1px solid var(--line-2);
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}
.stack-panel-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--line-2);
    background: var(--panel-2);
}
.stack-panel-chevron {
    background: transparent;
    color: var(--muted);
    border: 1px solid var(--line-2);
    width: 22px;
    height: 22px;
    line-height: 1;
    font-family: inherit;
    font-size: 11px;
    cursor: pointer;
    padding: 0;
    transition: color .12s ease, border-color .12s ease;
}
.stack-panel-chevron::before { content: "▾"; }
.stack-panel.all-collapsed .stack-panel-chevron::before { content: "▸"; }
.stack-panel-chevron:hover { color: var(--cyan); border-color: var(--cyan); }
.stack-panel-title {
    flex: 1;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .28em;
    color: var(--hot);
    font-weight: 700;
}
.stack-panel-count {
    font-size: 10px;
    color: var(--dim);
    border: 1px solid var(--line);
    padding: 1px 6px;
    letter-spacing: .06em;
}
.stack-panel-body {
    flex: 1;
    overflow-y: auto;
    padding: 14px 16px;
}

/* SCROLLBAR — applied to every internal scroll container so they match the
   chrome instead of using the OS-default look. Firefox uses the standard
   `scrollbar-*` properties; WebKit/Chromium uses the ::-webkit pseudo classes. */
.stack-panel-body,
.tray-body,
.modal .mb,
.catalog,
.presets {
    scrollbar-width: thin;
    scrollbar-color: var(--hot) var(--bg-deep);
}
.stack-panel-body::-webkit-scrollbar,
.tray-body::-webkit-scrollbar,
.modal .mb::-webkit-scrollbar,
.catalog::-webkit-scrollbar,
.presets::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
.stack-panel-body::-webkit-scrollbar-track,
.tray-body::-webkit-scrollbar-track,
.modal .mb::-webkit-scrollbar-track,
.catalog::-webkit-scrollbar-track,
.presets::-webkit-scrollbar-track {
    background: var(--bg-deep);
}
.stack-panel-body::-webkit-scrollbar-thumb,
.tray-body::-webkit-scrollbar-thumb,
.modal .mb::-webkit-scrollbar-thumb,
.catalog::-webkit-scrollbar-thumb,
.presets::-webkit-scrollbar-thumb {
    background: var(--hot);
    border: 1px solid var(--bg-deep);
}
.stack-panel-body::-webkit-scrollbar-thumb:hover,
.tray-body::-webkit-scrollbar-thumb:hover,
.modal .mb::-webkit-scrollbar-thumb:hover,
.catalog::-webkit-scrollbar-thumb:hover,
.presets::-webkit-scrollbar-thumb:hover {
    background: #ff5c95;
}

/* TRAY (Effects / Presets dropdown overlay over the preview) */
.tray-backdrop {
    position: absolute;
    inset: 0;
    grid-column: 1 / 2;
    background: rgba(4, 6, 10, .35);
    opacity: 0;
    pointer-events: none;
    transition: opacity .18s ease;
    z-index: 14;
}
.tray-backdrop.open { opacity: 1; pointer-events: auto; }

.tray {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    grid-column: 1 / 2;
    max-height: 60%;
    background: var(--panel);
    border-bottom: 1px solid var(--hot);
    box-shadow: 0 12px 30px rgba(0, 0, 0, .5);
    overflow: hidden;
    transform: translateY(-100%);
    transition: transform .22s ease;
    z-index: 16;
    display: flex;
    flex-direction: column;
}
main.with-stack .tray,
main.with-stack .tray-backdrop {
    /* Keep the tray inside the preview column so the stack stays interactive. */
    right: 320px;
}
.tray.open { transform: translateY(0); }
.tray-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px 22px;
}

/* CATALOG */
.catalog-quick-actions {
    margin-top: 14px;
    padding-top: 14px;
    border-top: 1px solid var(--line-2);
}
.catalog-randomize {
    width: 100%;
    padding: 10px 14px;
    font-size: 13px;
    letter-spacing: .22em;
}

.catalog-group { margin-bottom: 14px; }
.catalog-group:last-child { margin-bottom: 0; }
.catalog-group-label {
    font-size: 10px;
    color: var(--dim);
    text-transform: uppercase;
    letter-spacing: .22em;
    margin-bottom: 6px;
}
.catalog-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
.catalog-item {
    background: var(--panel-2);
    color: var(--text);
    border: 1px solid var(--line-2);
    padding: 5px 10px;
    font-family: "Barlow Condensed", sans-serif;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .12em;
    cursor: pointer;
    transition: all .12s ease;
}
.catalog-item:hover { border-color: var(--hot); color: var(--hot); }

/* PRESETS */
.preset-group { margin-bottom: 14px; }
.preset-group:last-child { margin-bottom: 0; }
.preset-group-label {
    font-size: 10px;
    color: var(--dim);
    text-transform: uppercase;
    letter-spacing: .22em;
    margin-bottom: 6px;
}
.preset-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
.preset-item {
    background: var(--panel-2);
    color: var(--text);
    border: 1px solid var(--line-2);
    padding: 5px 10px;
    font-family: "Barlow Condensed", sans-serif;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .12em;
    cursor: pointer;
}
.preset-item:hover { border-color: var(--hot); color: var(--hot); }

/* STACK */
.stack { display: flex; flex-direction: column; gap: 8px; }
.stack-empty {
    color: var(--dim);
    font-size: 11px;
    font-style: normal;
    text-transform: uppercase;
    letter-spacing: .18em;
    padding: 16px 0;
    text-align: center;
}
.stack-item {
    background: var(--panel-2);
    border: 1px solid var(--line-2);
    padding: 8px 10px;
}
.stack-header {
    display: flex;
    align-items: center;
    gap: 8px;
}
.stack-reorder {
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.stack-move {
    background: transparent;
    color: var(--muted);
    border: 1px solid var(--line);
    width: 18px;
    height: 14px;
    padding: 0;
    line-height: 1;
    font-size: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}
.stack-move:hover:not(:disabled) {
    border-color: var(--hot);
    color: var(--hot);
}
.stack-move:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}
.stack-toggle { margin: 0; accent-color: var(--hot); }
.stack-label {
    flex: 1;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .14em;
    color: var(--cyan);
    cursor: grab;
    user-select: none;
}
.stack-label:active { cursor: grabbing; }
.stack-item.is-dragging { opacity: 0.4; }
.stack-item.is-drop-target {
    border-color: var(--hot);
    box-shadow: inset 0 0 0 1px var(--hot);
}
.stack-chevron {
    background: transparent;
    color: var(--muted);
    border: 1px solid var(--line-2);
    width: 22px;
    height: 22px;
    line-height: 1;
    font-family: inherit;
    font-size: 11px;
    cursor: pointer;
    padding: 0;
    transition: color .12s ease, border-color .12s ease;
}
.stack-chevron::before { content: "▾"; }
.stack-item.is-collapsed .stack-chevron::before { content: "▸"; }
.stack-chevron:hover { color: var(--cyan); border-color: var(--cyan); }
.stack-item.is-collapsed .params { display: none; }

.stack-dup {
    background: transparent;
    color: var(--muted);
    border: 1px solid var(--line-2);
    width: 22px;
    height: 22px;
    line-height: 1;
    font-family: inherit;
    font-size: 12px;
    cursor: pointer;
    padding: 0;
    transition: color .12s ease, border-color .12s ease;
}
.stack-dup:hover { color: var(--lime); border-color: var(--lime); }

.stack-remove {
    background: transparent;
    color: var(--danger);
    border: 1px solid var(--danger);
    width: 22px;
    height: 22px;
    line-height: 1;
    font-family: inherit;
    font-size: 14px;
    cursor: pointer;
    padding: 0;
    transition: background .12s ease, color .12s ease;
}
.stack-remove:hover { background: var(--danger); color: var(--bg); }

/* PARAMS */
.params {
    margin-top: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.param-row { display: grid; grid-template-columns: 1fr; gap: 4px; }
.param-row.is-disabled {
    opacity: 0.35;
    pointer-events: none;
}
.param-label {
    font-size: 10px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .14em;
}
.param-slider { width: 100%; accent-color: var(--hot); }
.param-number {
    background: var(--bg-deep);
    color: var(--text);
    border: 1px solid var(--line-2);
    padding: 3px 6px;
    font-family: "JetBrains Mono", monospace;
    font-size: 11px;
    width: 90px;
}
.param-select {
    background: var(--bg-deep);
    color: var(--text);
    border: 1px solid var(--line-2);
    padding: 4px 6px;
    font-family: "Barlow Condensed", sans-serif;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .12em;
    width: 100%;
}
.param-text {
    background: var(--bg-deep);
    color: var(--text);
    border: 1px solid var(--line-2);
    padding: 4px 8px;
    font-family: "JetBrains Mono", monospace;
    font-size: 12px;
    width: 100%;
}
.param-color {
    width: 100%;
    height: 30px;
    background: var(--bg-deep);
    border: 1px solid var(--line-2);
    padding: 2px;
    cursor: pointer;
}

/* TEXT + SHAPES TABS (share the same template-grid layout) */
.text-templates,
.shapes-templates {
    display: flex;
    flex-direction: column;
    gap: 14px;
}
.text-intro,
.shapes-intro {
    color: var(--muted);
    font-size: 12px;
    letter-spacing: .06em;
    line-height: 1.5;
}
.text-template-grid,
.shapes-template-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}
.text-template,
.shapes-template {
    background: var(--panel-2);
    color: var(--text);
    border: 1px solid var(--line-2);
    padding: 10px 12px;
    cursor: pointer;
    text-align: left;
    display: flex;
    flex-direction: column;
    gap: 4px;
    transition: all .12s ease;
    font-family: "Barlow Condensed", sans-serif;
}
.text-template:hover,
.shapes-template:hover {
    border-color: var(--hot);
    color: var(--hot);
}
.text-template-label,
.shapes-template-label {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .16em;
    font-weight: 700;
}
.text-template-desc,
.shapes-template-desc {
    font-size: 10px;
    color: var(--muted);
    letter-spacing: .04em;
}
.text-template:hover .text-template-desc,
.shapes-template:hover .shapes-template-desc {
    color: var(--text);
}

/* FOOTER */
footer.app {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    padding: 9px 18px;
    border-top: 1px solid var(--line-2);
    background: var(--bg-deep);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .22em;
    color: var(--muted);
}
footer .reg {
    font-family: "JetBrains Mono", monospace;
    letter-spacing: .04em;
    color: var(--dim);
    font-size: 10px;
}
footer .license-link {
    cursor: pointer;
    color: var(--muted);
    text-decoration: none;
    transition: color .12s ease;
}
footer .license-link:hover { color: var(--hot); }
footer a.license-link:visited { color: var(--muted); }
footer a.license-link:visited:hover { color: var(--hot); }

.license-body {
    font-family: "JetBrains Mono", monospace;
    font-size: 11px;
    line-height: 1.55;
    color: var(--muted);
    white-space: pre-wrap;
    margin: 0;
    text-transform: none;
    letter-spacing: 0;
}
.license-body-link {
    color: var(--cyan);
    text-decoration: underline;
    transition: color .12s ease;
}
.license-body-link:hover { color: var(--hot); }
.license-body-link:visited { color: var(--cyan); }

.help-body { display: grid; gap: 14px; }
.help-section { display: grid; gap: 6px; }
.help-heading {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .28em;
    color: var(--cyan);
}
.help-list {
    margin: 0;
    padding: 0 0 0 16px;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.45;
}
.help-list li { margin-bottom: 4px; }
.help-list li:last-child { margin-bottom: 0; }

/* MODAL */
.modal-back {
    position: fixed;
    inset: 0;
    background: rgba(4, 6, 10, .72);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 50;
}
.modal-back.open { display: flex; }
.modal {
    width: 620px;
    max-width: calc(100vw - 32px);
    background: var(--panel);
    border: 1px solid var(--cyan);
    box-shadow: 0 0 0 1px rgba(0, 212, 255, .18), 0 24px 80px rgba(0, 0, 0, .55);
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 80px);
}
.modal.lime { border-color: var(--lime); box-shadow: 0 0 0 1px rgba(191, 255, 0, .18), 0 24px 80px rgba(0, 0, 0, .55); }
.modal.danger { border-color: var(--danger); box-shadow: 0 0 0 1px rgba(255, 51, 68, .22), 0 24px 80px rgba(0, 0, 0, .55); }
.modal.hot { border-color: var(--hot); box-shadow: 0 0 0 1px rgba(255, 45, 122, .22), 0 24px 80px rgba(0, 0, 0, .55); }
.modal .mh { padding: 12px 16px; border-bottom: 1px solid var(--line-2); display: flex; align-items: center; justify-content: space-between; }
.modal .mh .mh-main { min-width: 0; display: grid; gap: 4px; }
.modal .mh .t { font-size: 13px; text-transform: uppercase; letter-spacing: .28em; color: var(--cyan); }
.modal.lime .mh .t { color: var(--lime); }
.modal.danger .mh .t { color: var(--danger); }
.modal.hot .mh .t { color: var(--hot); }
/* When a subtitle is set, the header switches to the Aleph Null Media
   disclaimer pattern (matches the chords app's #licenseModal styling) —
   bold uppercase title with wide letter-spacing, muted subtitle stacked
   underneath with even wider letter-spacing. */
.modal .mh.has-subtitle { align-items: flex-start; padding-bottom: 10px; }
.modal .mh.has-subtitle .t {
    font-size: 18px;
    font-weight: 800;
    line-height: 1;
    letter-spacing: .2em;
    color: var(--text);
}
.modal.lime .mh.has-subtitle .t,
.modal.danger .mh.has-subtitle .t,
.modal.hot .mh.has-subtitle .t { color: var(--text); }
.modal .mh .st {
    font-size: 10px;
    color: var(--muted);
    letter-spacing: .22em;
    text-transform: uppercase;
}
/* Close button — compact bordered glyph matching the chords-app disclaimer
   modal. Hover fills with the modal's variant accent. */
.modal .mh .x {
    cursor: pointer;
    flex: 0 0 auto;
    color: var(--text);
    background: var(--bg-deep);
    border: 1px solid var(--line-2);
    border-radius: 3px;
    font-size: 14px;
    line-height: 1;
    padding: 5px 9px;
    transition: color .12s ease, border-color .12s ease, background .12s ease;
}
.modal .mh .x:hover         { background: var(--cyan);   border-color: var(--cyan);   color: var(--bg); }
.modal.lime .mh .x:hover    { background: var(--lime);   border-color: var(--lime);   color: var(--bg); }
.modal.danger .mh .x:hover  { background: var(--danger); border-color: var(--danger); color: var(--bg); }
.modal.hot .mh .x:hover     { background: var(--hot);    border-color: var(--hot);    color: var(--bg); }
.modal .mb { padding: 14px 16px; display: grid; gap: 10px; overflow-y: auto; min-height: 0; }
/* Match the scrollbar to the variant's accent color so the Help / License
   modals don't snap back to default OS chrome inside an otherwise themed
   container. Firefox uses scrollbar-color; WebKit gets explicit pseudos. */
.modal.cyan .mb { scrollbar-color: var(--cyan) var(--panel-2); scrollbar-width: thin; }
.modal.cyan .mb::-webkit-scrollbar { width: 10px; }
.modal.cyan .mb::-webkit-scrollbar-track { background: var(--panel-2); }
.modal.cyan .mb::-webkit-scrollbar-thumb { background: var(--cyan); border: 2px solid var(--panel-2); }
.modal.cyan .mb::-webkit-scrollbar-thumb:hover { background: #66e3ff; }
.modal .mf { padding: 12px 16px; border-top: 1px solid var(--line-2); display: flex; justify-content: flex-end; gap: 8px; }
.modal .summary-block {
    background: var(--bg-deep);
    border: 1px solid var(--line);
    padding: 10px 12px;
    font-family: "Barlow Condensed", sans-serif;
    font-size: 12px;
    color: var(--muted);
    display: grid;
    gap: 6px;
}
.modal .summary-block b { color: var(--text); font-weight: 500; }
.modal .settings-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 0;
    border-top: 1px solid var(--line);
}
.modal .settings-row:first-of-type { border-top: none; padding-top: 4px; }

.modal .settings-row-download {
    align-items: flex-start;
}
.modal .sm-format-row {
    margin-top: 6px;
}
.modal .sm-download-controls {
    display: flex;
    flex-direction: column;
    gap: 6px;
    align-items: flex-end;
}
.modal .sm-inline-row {
    display: flex;
    align-items: center;
    gap: 8px;
}
.modal .sm-inline-row.hidden { display: none; }
.modal .sm-inline-label {
    font-size: 10px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .18em;
    min-width: 56px;
    text-align: right;
}
.modal .sm-quality {
    width: 140px;
    accent-color: var(--hot);
}
.modal .sm-download-row {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-top: 10px;
}
.modal .sm-quality-group {
    display: flex;
    align-items: center;
    gap: 8px;
}
.modal .sm-quality-group.hidden { display: none; }
.modal .sm-quality-group .sm-inline-label {
    min-width: 0;
    text-align: left;
}
.modal .settings-row .sr-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.modal .settings-row .sr-title {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .18em;
    color: var(--text);
    font-weight: 600;
}
.modal .settings-row .sr-desc {
    font-size: 11px;
    color: var(--muted);
    letter-spacing: .06em;
}

/* TOAST */
#toastHost {
    position: fixed;
    right: 18px;
    bottom: 42px;
    z-index: 60;
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: flex-end;
}
.toast {
    background: var(--panel);
    border: 1px solid var(--hot);
    color: var(--text);
    font-size: 12px;
    letter-spacing: .08em;
    text-transform: uppercase;
    padding: 10px 14px;
    min-width: 240px;
    max-width: 420px;
    box-shadow: 0 0 0 1px rgba(255, 45, 122, .18), 0 12px 30px rgba(0, 0, 0, .5);
    transform: translateX(20px);
    opacity: 0;
    transition: transform .22s ease, opacity .22s ease;
}
.toast.in { transform: translateX(0); opacity: 1; }
.toast.danger { border-color: var(--danger); box-shadow: 0 0 0 1px rgba(255, 51, 68, .18), 0 12px 30px rgba(0, 0, 0, .5); }

/* DESKTOP: Stack tab is redundant since the stack is permanently visible. */
.tabs .tab[data-tab="stack"] { display: none; }

/* MOBILE BREAKPOINT */
@media (max-width: 900px) {
    /* Show the Stack tab and use it to toggle the off-canvas drawer. */
    .tabs .tab[data-tab="stack"] { display: flex; }

    /* Collapse the side column; preview takes full width. */
    main.with-stack { grid-template-columns: 1fr; }

    /* Stack drops down from the top like the Effects / Presets tray, so the
       lower portion of the preview stays visible while the user adjusts
       params. 40% max-height keeps more of the image in view than the tray. */
    .stack-panel {
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: auto;
        max-height: 40%;
        border-left: none;
        border-bottom: 1px solid var(--hot);
        box-shadow: 0 12px 30px rgba(0, 0, 0, .5);
        transform: translateY(-100%);
        transition: transform .22s ease;
        z-index: 18;
    }
    main.stack-open .stack-panel { transform: translateY(0); }

    /* Tray overlay now spans the full width since the stack is off-canvas. */
    main.with-stack .tray,
    main.with-stack .tray-backdrop {
        right: 0;
    }

    /* Header on small screens: brand condenses, actions wrap a row. */
    header.app {
        flex-wrap: wrap;
        gap: 8px;
        padding: 10px 12px;
    }
    .brand .sub { display: none; }
    .file-tag { margin-left: 10px; padding-left: 10px; }
    .header-quality { display: none; }
    .header-actions {
        flex-wrap: wrap;
        gap: 6px;
        margin-left: auto;            /* push the cluster to the right edge */
        justify-content: flex-end;     /* and right-align the wrapped buttons */
    }
    /* Undo / Redo collapse to icon-only on small screens to save header room. */
    .header-actions .btn .btn-text { display: none; }
    .header-actions .btn .btn-icon { margin-right: 0; font-size: 16px; }


    /* Tabs become more compact. */
    .tabs .tab { padding: 8px 12px; }
    .tabs .tab .tname { letter-spacing: .16em; }
}

/* Phone-only: footer becomes a 3-column grid so copyright / site / license
   stay visually balanced. Desktop and tablets keep the inline footer. */
@media (max-width: 600px) {
    footer.app {
        display: grid;
        grid-template-columns: 1fr 1fr 1fr;
        gap: 6px;
        padding: 9px 12px;
    }
    footer.app .fcol-sep { display: none; }
    footer.app .fcol-copy { text-align: left; }
    footer.app .fcol-site { text-align: center; }
    footer.app .fcol-license { text-align: right; }
}
