/* ============================================================================
 * image-studio.css — live image generation + the AI editing panel.
 *
 * Two surfaces, one visual language:
 *
 *   .dimg-*  the live generation card in the chat transcript
 *   .dst-*   the AI editing panel inside the image viewer
 *   .dlx-*   additions to the existing viewer (studio layout, markers, live stage)
 *
 * Loads AFTER ui-polish.css because it deliberately restructures the viewer's
 * flex layout: the stage and the controls are now wrapped in .dlx-body/.dlx-main
 * so a sidebar can sit beside them.
 *
 * THE BLUR IS THE POINT. Both surfaces receive a progressive ladder of the real
 * image, smallest rung first, and animate `filter: blur()` down as better pixels
 * arrive. The transition duration is what makes it read as a picture developing
 * rather than three images flickering past — the rungs themselves are encoded
 * server-side in ~200ms.
 * ========================================================================== */

:root {
    --dst-w: 360px;
    --dimg-radius: 16px;
}

/* ═══════════════════════════════════════════════════════════════════════════
   1. CHAT — live generation card
   ═══════════════════════════════════════════════════════════════════════════ */

.dimg {
    display: block;
    width: clamp(200px, 46vw, 300px);
    margin: 10px 0 4px;
}

.dimg-frame {
    position: relative;
    width: 100%;
    aspect-ratio: 1 / 1;
    border-radius: var(--dimg-radius);
    overflow: hidden;
    background: var(--secondary-color, #1c1f23);
    border: 1px solid var(--border-color, rgba(255, 255, 255, 0.08));
}

.dimg-img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0;
    /* Scale eases in with the sharpening so the picture feels like it settles
       into place rather than snapping to its final size. */
    transform: scale(1.04);
    transition: filter 620ms cubic-bezier(0.22, 0.61, 0.36, 1),
        opacity 380ms ease,
        transform 720ms cubic-bezier(0.22, 0.61, 0.36, 1);
    will-change: filter, opacity, transform;
}

.dimg.is-painting .dimg-img {
    opacity: 1;
    transform: scale(1);
}

/* Shimmer veil: the only thing on screen until the first pixels land. */
.dimg-veil {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    background:
        linear-gradient(115deg,
            rgba(255, 255, 255, 0) 30%,
            rgba(255, 255, 255, 0.07) 48%,
            rgba(255, 255, 255, 0) 66%),
        var(--secondary-color, #1c1f23);
    background-size: 280% 100%, auto;
    animation: dimg-sweep 1.5s linear infinite;
    transition: opacity 420ms ease;
}

.dimg.is-painting .dimg-veil {
    opacity: 0;
    pointer-events: none;
}

@keyframes dimg-sweep {
    from { background-position: 160% 0, 0 0; }
    to { background-position: -160% 0, 0 0; }
}

.dimg-orb {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: 2.5px solid var(--accent-color, #3b82f6);
    border-top-color: transparent;
    border-right-color: transparent;
    animation: dimg-spin 0.85s linear infinite;
}

@keyframes dimg-spin {
    to { transform: rotate(360deg); }
}

.dimg-track {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 3px;
    background: rgba(255, 255, 255, 0.1);
}

.dimg-fill {
    display: block;
    height: 100%;
    width: 2%;
    border-radius: 0 3px 3px 0;
    background: linear-gradient(90deg, var(--accent-color, #3b82f6), #a78bfa);
    /* Matches the server's 900ms heartbeat, so the bar glides between ticks
       instead of stepping. */
    transition: width 900ms linear;
}

.dimg-foot {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 2px 0;
}

.dimg-state {
    font-size: 12.5px;
    font-weight: 600;
    color: var(--subheading-color, #98a2b3);
}

.dimg-chip {
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    padding: 3px 7px;
    border-radius: 6px;
    color: var(--accent-color, #3b82f6);
    background: color-mix(in srgb, var(--accent-color, #3b82f6) 14%, transparent);
}

.dimg-stop {
    margin-left: auto;
    display: inline-grid;
    place-items: center;
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--subheading-color, #98a2b3);
    cursor: pointer;
    transition: background 0.14s ease, color 0.14s ease;
}

.dimg-stop:hover:not(:disabled) {
    background: rgba(239, 68, 68, 0.14);
    color: #ef4444;
}

.dimg-stop:disabled {
    opacity: 0.45;
    cursor: default;
}

.dimg-stop .material-symbols-rounded {
    font-size: 20px;
}

/* ═══════════════════════════════════════════════════════════════════════════
   2. VIEWER — layout for the studio sidebar
   ═══════════════════════════════════════════════════════════════════════════ */

.dlx-body {
    flex: 1 1 0;
    display: flex;
    min-height: 0;
    min-width: 0;
}

.dlx-main {
    flex: 1 1 0;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
}

.dlx-topactions {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Above the scrim. The sheet's backdrop covers the whole overlay, and without
   this Close and Download would be unreachable while the sheet is open. */
.dlx-topbar {
    position: relative;
    z-index: 6;
}

.dlx-btn.dlx-ai .material-symbols-rounded {
    color: var(--accent-color, #3b82f6);
}

.dlx-btn.dlx-ai.dlx-active {
    background: color-mix(in srgb, var(--accent-color, #3b82f6) 16%, transparent);
    border-color: var(--accent-color, #3b82f6);
}

/* The stage has to give room to the sidebar. Viewport maths rather than
   percentages because the canvas wrap is content-sized, so a percentage
   max-height there resolves against nothing. */
.dlx-overlay .dlx-canvas {
    max-width: min(88vw, 1000px);
    max-height: 62vh;
}

.dlx-overlay.dlx-studio-open .dlx-canvas {
    max-width: min(calc(100vw - var(--dst-w) - 72px), 1000px);
}

/* ── Point markers ── */
.dlx-marks {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.dlx-marks.is-armed {
    pointer-events: auto;
    cursor: crosshair;
    /* Unmistakable that the image is now a target, not a picture. */
    box-shadow: inset 0 0 0 2px var(--accent-color, #3b82f6);
    background: color-mix(in srgb, var(--accent-color, #3b82f6) 7%, transparent);
}

.dlx-mark {
    position: absolute;
    transform: translate(-50%, -50%);
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 2px solid #fff;
    background: #ff2d55;
    color: #fff;
    font-size: 12.5px;
    font-weight: 800;
    line-height: 1;
    display: grid;
    place-items: center;
    cursor: pointer;
    pointer-events: auto;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.45);
    animation: dlx-mark-in 0.24s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.dlx-mark:hover {
    background: #ef4444;
    transform: translate(-50%, -50%) scale(1.12);
}

@keyframes dlx-mark-in {
    from { transform: translate(-50%, -50%) scale(0.3); opacity: 0; }
    to { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

/* ── Live generation surface over the canvas ── */
.dlx-live {
    position: absolute;
    inset: 0;
    background: var(--darker-background, #111113);
    display: flex;
    align-items: flex-end;
    overflow: hidden;
    z-index: 3;
}

/* The `hidden` attribute must actually hide this surface. It has an explicit
   `display: flex` above, and an author `display` rule would otherwise beat the
   UA `[hidden] { display:none }` rule — leaving the "loading / Stop" overlay
   permanently covering the image instead of only showing during a render. */
.dlx-live[hidden] {
    display: none;
}

.dlx-live-img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    opacity: 0;
    transform: scale(1.03);
    transition: filter 620ms cubic-bezier(0.22, 0.61, 0.36, 1),
        opacity 380ms ease,
        transform 720ms cubic-bezier(0.22, 0.61, 0.36, 1);
    will-change: filter, opacity, transform;
}

.dlx-live.is-painting .dlx-live-img {
    opacity: 1;
    transform: scale(1);
}

.dlx-live-veil {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    background:
        linear-gradient(115deg,
            rgba(255, 255, 255, 0) 30%,
            rgba(255, 255, 255, 0.06) 48%,
            rgba(255, 255, 255, 0) 66%),
        var(--primary-color, #17191c);
    background-size: 280% 100%, auto;
    animation: dimg-sweep 1.5s linear infinite;
    transition: opacity 420ms ease;
}

.dlx-live.is-painting .dlx-live-veil {
    opacity: 0;
}

.dlx-live-orb {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 3px solid var(--accent-color, #3b82f6);
    border-top-color: transparent;
    border-right-color: transparent;
    animation: dimg-spin 0.85s linear infinite;
}

.dlx-live-hud {
    position: relative;
    z-index: 2;
    width: 100%;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.72), transparent);
}

.dlx-live-track {
    height: 4px;
    border-radius: 2px;
    background: rgba(255, 255, 255, 0.16);
    overflow: hidden;
}

.dlx-live-fill {
    display: block;
    height: 100%;
    width: 2%;
    background: linear-gradient(90deg, var(--accent-color, #3b82f6), #a78bfa);
    transition: width 900ms linear;
}

.dlx-live-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.dlx-live-state {
    font-size: 13px;
    font-weight: 600;
    color: #fff;
    text-shadow: 0 1px 6px rgba(0, 0, 0, 0.6);
}

.dlx-btn.dlx-live-stop {
    height: 34px;
    padding: 0 12px;
    background: rgba(239, 68, 68, 0.18);
    border-color: rgba(239, 68, 68, 0.5);
    color: #fff;
}

.dlx-btn.dlx-live-stop:hover:not(:disabled) {
    background: rgba(239, 68, 68, 0.3);
    border-color: #ef4444;
}

.dlx-btn.dlx-live-stop:disabled {
    opacity: 0.5;
    cursor: default;
}

/* Editing tools are meaningless mid-render. */
.dlx-overlay.dlx-generating .dlx-controls {
    opacity: 0.4;
    pointer-events: none;
}

/* ── Bottom toolbar — clean, centred pill row (Shadcn/Notion style) ──
   The base file lays this out as a flex-column with stacked sections. We
   flatten it into a single horizontal row: tool buttons centred, with the
   crop actions inline to their right when crop mode is on. Less bulky, more
   app-like. */
.dlx-controls {
    flex-direction: row;
    justify-content: center;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    padding: 10px 16px calc(10px + env(safe-area-inset-bottom, 0px));
    background: color-mix(in srgb, var(--primary-color, #17191c) 86%, transparent);
    backdrop-filter: blur(8px);
}

/* Calmer stage: drop the accent radial glow + the heavy 54px canvas shadow so
   the editor reads flat and modern, not "AI demo". */
.dlx-stage {
    background: var(--darker-background, #111113);
}

.dlx-canvas-wrap {
    border: 1px solid var(--border-color, rgba(255, 255, 255, 0.08));
    background: var(--primary-color, #17191c);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 12px rgba(0, 0, 0, 0.28);
}

.dlx-tools {
    gap: 4px;
    flex-wrap: nowrap;
}

.dlx-tools .dlx-btn {
    height: 34px;
    min-width: 34px;
    padding: 0 10px;
    border-radius: 8px;
    border-color: transparent;
    background: transparent;
    font-size: 12px;
    font-weight: 550;
    color: var(--subheading-color, #98a2b3);
    transition: background 0.13s ease, color 0.13s ease, border-color 0.13s ease, transform 0.12s var(--ui-ease, cubic-bezier(0.22, 0.61, 0.36, 1));
}

.dlx-tools .dlx-btn .material-symbols-rounded {
    font-size: 18px;
}

.dlx-tools .dlx-btn:hover {
    background: var(--secondary-hover-color, rgba(255, 255, 255, 0.06));
    border-color: transparent;
    color: var(--text-color, #e7eaee);
}

.dlx-tools .dlx-btn:active {
    transform: scale(0.95);
}

.dlx-tools .dlx-btn.dlx-active {
    background: color-mix(in srgb, var(--accent-color, #3b82f6) 16%, transparent);
    border-color: color-mix(in srgb, var(--accent-color, #3b82f6) 50%, transparent);
    color: var(--accent-color, #68a5ff);
}

/* The crop actions appear inline to the right of the toolbar when active.
   Hidden attribute is restored above; this just styles the visible state. */
.dlx-crop-actions {
    gap: 6px;
    margin-top: 0;
    padding-left: 8px;
    border-left: 1px solid var(--border-color, rgba(255, 255, 255, 0.08));
}

.dlx-crop-actions .dlx-btn {
    height: 34px;
    padding: 0 12px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 550;
}

.dlx-crop-actions .dlx-btn.dlx-primary {
    background: var(--accent-color, #3b82f6);
    color: #fff;
    border-color: transparent;
}

/* Backdrop behind the mobile sheet. Inert on desktop. */
.dlx-scrim {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 4;
    display: none;
}

/* The crop actions live in the viewer's bottom toolbar and have an explicit
   `display: flex` rule in ui-polish.css. That author rule beats the UA
   `[hidden]` rule, so the Cancel/Apply bar would stay visible forever. This
   override restores the hidden state without touching the shared file. */
.dlx-crop-actions[hidden] {
    display: none;
}

/* ── Crop box (real, resizable, 8 handles) ──
   The base file's `.dlx-crop-box` is move-only. We layer handles on top so the
   region can actually be resized from any edge or corner. */
.dlx-crop-box {
    border-color: color-mix(in srgb, var(--accent-color, #3b82f6) 80%, #fff);
    box-shadow:
        0 0 0 100vmax rgba(0, 0, 0, 0.55),
        inset 0 0 0 1px rgba(255, 255, 255, 0.18);
    background: transparent;
}

/* Thirds guides inside the crop box. */
.dlx-crop-box::before,
.dlx-crop-box::after {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    opacity: 0.5;
}

.dlx-crop-box::before {
    background:
        linear-gradient(to right, transparent 33.33%, rgba(255, 255, 255, 0.22) 33.33%, rgba(255, 255, 255, 0.22) 33.4%, transparent 33.4%, transparent 66.66%, rgba(255, 255, 255, 0.22) 66.66%, rgba(255, 255, 255, 0.22) 66.73%, transparent 66.73%);
}

.dlx-crop-box::after {
    background:
        linear-gradient(to bottom, transparent 33.33%, rgba(255, 255, 255, 0.22) 33.33%, rgba(255, 255, 255, 0.22) 33.4%, transparent 33.4%, transparent 66.66%, rgba(255, 255, 255, 0.22) 66.66%, rgba(255, 255, 255, 0.22) 66.73%, transparent 66.73%);
}

.dlx-crop-h {
    position: absolute;
    width: 10px;
    height: 10px;
    background: #fff;
    border: 1.5px solid var(--accent-color, #3b82f6);
    border-radius: 50%;
    z-index: 2;
    touch-action: none;
}

/* Corner handles — square. */
.dlx-crop-h.h-nw { left: -6px; top: -6px; cursor: nwse-resize; border-radius: 3px; width: 12px; height: 12px; }
.dlx-crop-h.h-ne { right: -6px; top: -6px; cursor: nesw-resize; border-radius: 3px; width: 12px; height: 12px; }
.dlx-crop-h.h-sw { left: -6px; bottom: -6px; cursor: nesw-resize; border-radius: 3px; width: 12px; height: 12px; }
.dlx-crop-h.h-se { right: -6px; bottom: -6px; cursor: nwse-resize; border-radius: 3px; width: 12px; height: 12px; }

/* Edge handles — wider hit area, thin bar. */
.dlx-crop-h.h-n { top: -5px; left: 50%; transform: translateX(-50%); width: 28px; height: 10px; cursor: ns-resize; border-radius: 4px; }
.dlx-crop-h.h-s { bottom: -5px; left: 50%; transform: translateX(-50%); width: 28px; height: 10px; cursor: ns-resize; border-radius: 4px; }
.dlx-crop-h.h-e { right: -5px; top: 50%; transform: translateY(-50%); width: 10px; height: 28px; cursor: ew-resize; border-radius: 4px; }
.dlx-crop-h.h-w { left: -5px; top: 50%; transform: translateY(-50%); width: 10px; height: 28px; cursor: ew-resize; border-radius: 4px; }

/* The interior of the crop box remains draggable to move the region. */
.dlx-crop-move {
    position: absolute;
    inset: 12px;
    cursor: move;
    touch-action: none;
}

/* ═══════════════════════════════════════════════════════════════════════════
   3. THE STUDIO PANEL
   ═══════════════════════════════════════════════════════════════════════════ */

.dlx-side {
    flex: 0 0 var(--dst-w);
    width: var(--dst-w);
    min-width: 0;
    border-left: 1px solid var(--border-color, rgba(255, 255, 255, 0.08));
    /* Flat, calm surface — no gradient glow. Reads like a Shadcn sidebar. */
    background: var(--primary-color, #17191c);
    /* Collapsed by default: margin, not display, so the open/close slide can be
       animated and the panel's scroll position survives a toggle. */
    margin-right: calc(var(--dst-w) * -1);
    opacity: 0;
    pointer-events: none;
    transition: margin-right 0.3s var(--ui-ease, cubic-bezier(0.22, 0.61, 0.36, 1)),
        opacity 0.22s ease;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 5;
}

.dlx-overlay.dlx-studio-open .dlx-side {
    margin-right: 0;
    opacity: 1;
    pointer-events: auto;
}

.dst {
    display: flex;
    flex-direction: column;
    min-height: 0;
    height: 100%;
}

.dst-grip {
    display: none;
}

.dst-head {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 14px 14px 13px 18px;
    border-bottom: 1px solid var(--border-color, rgba(255, 255, 255, 0.06));
    background: transparent;
    flex-shrink: 0;
}

.dst-head h2 {
    margin: 0;
    font-size: 14px;
    font-weight: 650;
    letter-spacing: -0.01em;
    color: var(--text-color, #e7eaee);
    flex: 1;
}

.dst-head-ico {
    font-size: 18px;
    color: var(--accent-color, #68a5ff);
}

.dst-x {
    display: grid;
    place-items: center;
    width: 30px;
    height: 30px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--subheading-color, #98a2b3);
    cursor: pointer;
    transition: background 0.13s ease, color 0.13s ease;
}

.dst-x:hover {
    background: var(--secondary-hover-color, rgba(255, 255, 255, 0.06));
    color: var(--text-color, #e7eaee);
}

.dst-scroll {
    flex: 1 1 0;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 4px 0 calc(18px + env(safe-area-inset-bottom, 0px));
}

.dst-sec {
    padding: 14px 18px;
    border-bottom: 1px solid var(--border-color, rgba(255, 255, 255, 0.05));
}

.dst-sec:last-child {
    border-bottom: none;
}

.dst-lbl {
    display: block;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.01em;
    color: var(--subheading-color, #98a2b3);
    margin-bottom: 8px;
}

.dst-hint {
    margin: 8px 0 0;
    font-size: 11.5px;
    line-height: 1.45;
    color: var(--subheading-color, #98a2b3);
}

/* ── Prompt ── */
.dst-input {
    width: 100%;
    box-sizing: border-box;
    padding: 11px 12px;
    border: 1px solid var(--border-color, rgba(255, 255, 255, 0.12));
    border-radius: 11px;
    background: var(--secondary-color, rgba(255, 255, 255, 0.04));
    color: var(--text-color, #e7eaee);
    font: inherit;
    font-size: 13.5px;
    line-height: 1.5;
    resize: vertical;
    min-height: 74px;
    transition: border-color 0.14s ease, background 0.14s ease;
}

.dst-input:focus {
    outline: none;
    border-color: var(--accent-color, #3b82f6);
    background: var(--secondary-hover-color, rgba(255, 255, 255, 0.06));
}

.dst-input::placeholder {
    color: var(--subheading-color, #98a2b3);
    opacity: 0.7;
}

.dst-markrow {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 10px;
}

.dst-mark-btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    height: 32px;
    padding: 0 11px;
    border: 1px solid var(--border-color, rgba(255, 255, 255, 0.09));
    border-radius: 8px;
    background: transparent;
    color: var(--text-color, #e7eaee);
    font: inherit;
    font-size: 12px;
    font-weight: 550;
    position: relative;
    cursor: pointer;
    transition: background 0.13s ease, border-color 0.13s ease, transform 0.12s var(--ui-ease, cubic-bezier(0.22, 0.61, 0.36, 1));
}

.dst-mark-btn .material-symbols-rounded {
    font-size: 16px;
    line-height: 1;
}

.dst-mark-btn:hover:not(:disabled) {
    background: var(--secondary-hover-color, rgba(255, 255, 255, 0.05));
    border-color: color-mix(in srgb, var(--accent-color, #3b82f6) 45%, transparent);
}

.dst-mark-btn:active:not(:disabled) {
    transform: scale(0.97);
}

.dst-mark-btn.is-on {
    background: color-mix(in srgb, var(--accent-color, #3b82f6) 16%, transparent);
    border-color: var(--accent-color, #3b82f6);
    color: #fff;
}

/* The count badge only appears once at least one marker exists. The `hidden`
   attribute must actually hide it — an author `display` rule would otherwise
   beat the UA `[hidden]` rule, leaving a "0" bubble on the bare button. */
.dst-mark-n[hidden] {
    display: none;
}

.dst-mark-n {
    position: absolute;
    top: -5px;
    right: -5px;
    display: inline-grid;
    place-items: center;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    border-radius: 8px;
    background: #ef4444;
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    line-height: 1;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
    animation: dst-pop 0.22s var(--ui-ease, cubic-bezier(0.34, 1.56, 0.64, 1));
}

@keyframes dst-pop {
    from { transform: scale(0.4); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.dst-mark-clear {
    border: none;
    background: none;
    color: var(--subheading-color, #98a2b3);
    font-size: 12.5px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: underline;
    text-underline-offset: 3px;
    transition: color 0.14s ease;
}

.dst-mark-clear:hover {
    color: var(--text-color, #e7eaee);
}

.dst-go {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    height: 40px;
    margin-top: 12px;
    border: 1px solid color-mix(in srgb, var(--accent-color, #3b82f6) 55%, transparent);
    border-radius: 10px;
    background: color-mix(in srgb, var(--accent-color, #3b82f6) 14%, transparent);
    color: var(--accent-color, #cfe0ff);
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.01em;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    transition: background 0.14s ease, border-color 0.14s ease, color 0.14s ease, transform 0.12s var(--ui-ease, cubic-bezier(0.22, 0.61, 0.36, 1));
}

.dst-go:hover:not(:disabled) {
    background: color-mix(in srgb, var(--accent-color, #3b82f6) 22%, transparent);
    border-color: var(--accent-color, #3b82f6);
    color: #fff;
}

.dst-go:active:not(:disabled) {
    transform: scale(0.985);
}

.dst-go:disabled {
    opacity: 0.5;
    cursor: default;
}

.dst-go .material-symbols-rounded {
    font-size: 18px;
}

/* At rest the magic glyph is just an icon — no ring, no background, nothing
   cheap-looking. While rendering (`.is-busy`) it gains a thin circular ring
   that spins, so the busy state is unmistakable without a perpetual loader. */
.dst-go-ico {
    display: inline-grid;
    place-items: center;
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.dst-go-ico .material-symbols-rounded {
    font-size: 18px;
    line-height: 1;
    color: inherit;
}

.dst-go.is-busy .dst-go-ico {
    border: 1.5px solid color-mix(in srgb, currentColor 30%, transparent);
    border-top-color: currentColor;
    border-radius: 50%;
    animation: dimg-spin 0.8s linear infinite;
}

.dst-go.is-busy .dst-go-ico .material-symbols-rounded {
    visibility: hidden;
}

/* ── Quick actions — compact icon+text chips (Linear/Notion style) ── */
.dst-quicks {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(108px, 1fr));
    gap: 6px;
}

.dst-quick {
    display: inline-flex;
    align-items: center;
    justify-content: flex-start;
    gap: 7px;
    height: 32px;
    padding: 0 10px;
    border: 1px solid var(--border-color, rgba(255, 255, 255, 0.09));
    border-radius: 8px;
    background: transparent;
    color: var(--text-color, #e7eaee);
    font: inherit;
    font-size: 12px;
    font-weight: 550;
    text-align: left;
    cursor: pointer;
    position: relative;
    transition: background 0.13s ease, border-color 0.13s ease, transform 0.13s var(--ui-ease, cubic-bezier(0.22, 0.61, 0.36, 1));
}

.dst-quick .material-symbols-rounded {
    font-size: 16px;
    line-height: 1;
    color: var(--subheading-color, #98a2b3);
    flex-shrink: 0;
    transition: color 0.13s ease;
}

.dst-quick:hover:not(:disabled) {
    background: var(--secondary-hover-color, rgba(255, 255, 255, 0.05));
    border-color: color-mix(in srgb, var(--accent-color, #3b82f6) 45%, transparent);
}

.dst-quick:hover:not(:disabled) .material-symbols-rounded {
    color: var(--accent-color, #68a5ff);
}

.dst-quick:active:not(:disabled) {
    transform: scale(0.97);
}

.dst-quick:disabled {
    opacity: 0.4;
    cursor: default;
}

.dst-quick-txt {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ── Model picker (compact Shadcn-radio rows) ── */
.dst-models {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.dst-model {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 8px 10px;
    border: 1px solid var(--border-color, rgba(255, 255, 255, 0.08));
    border-radius: 9px;
    background: transparent;
    color: var(--text-color, #e7eaee);
    font: inherit;
    text-align: left;
    cursor: pointer;
    position: relative;
    transition: background 0.12s ease, border-color 0.12s ease;
}

.dst-model:hover:not(:disabled) {
    background: var(--secondary-hover-color, rgba(255, 255, 255, 0.04));
}

.dst-model.is-on {
    border-color: color-mix(in srgb, var(--accent-color, #3b82f6) 60%, transparent);
    background: color-mix(in srgb, var(--accent-color, #3b82f6) 10%, transparent);
}

.dst-model.is-spent {
    opacity: 0.5;
    cursor: default;
}

.dst-model-ico {
    font-size: 16px;
    color: var(--subheading-color, #98a2b3);
    flex-shrink: 0;
}

.dst-model.is-on .dst-model-ico {
    color: var(--accent-color, #68a5ff);
}

.dst-model-txt {
    display: flex;
    flex-direction: column;
    gap: 1px;
    min-width: 0;
    flex: 1;
}

.dst-model-top {
    display: flex;
    align-items: baseline;
    gap: 6px;
}

.dst-model-top b {
    font-size: 12.5px;
    font-weight: 600;
}

.dst-model-top em {
    font-style: normal;
    font-size: 9.5px;
    font-weight: 600;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    color: var(--subheading-color, #6b7280);
}

/* Pro locked out on free accounts: dim it and show a lock. */
.dst-model.is-locked .dst-model-ico {
    color: var(--subheading-color, #6b7280);
}

.dst-model.is-locked .dst-model-txt {
    opacity: 0.55;
}

.dst-model.is-locked .dst-model-tag {
    color: var(--subheading-color, #6b7280);
    transform: none;
}

.dst-model-sub {
    font-size: 11px;
    line-height: 1.35;
    color: var(--subheading-color, #98a2b3);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.dst-model-tag {
    position: absolute;
    top: 8px;
    right: 9px;
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: #f59e0b;
}

/* When the tag is a lock icon (Pro locked for free accounts), render it as a
   glyph rather than tiny uppercase text. */
.dst-model-tag.material-symbols-rounded {
    font-size: 14px;
    font-weight: 400;
    letter-spacing: 0;
    text-transform: none;
    line-height: 1;
}

/* ── Size pills ── */
.dst-sec-row {
    display: flex;
    gap: 18px;
}

.dst-col {
    flex: 1;
    min-width: 0;
}

.dst-pills {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.dst-pill {
    height: 32px;
    min-width: 44px;
    padding: 0 12px;
    border: 1px solid var(--border-color, rgba(255, 255, 255, 0.12));
    border-radius: 8px;
    background: var(--secondary-color, rgba(255, 255, 255, 0.04));
    color: var(--text-color, #e7eaee);
    font: inherit;
    font-size: 12.5px;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.14s ease, border-color 0.14s ease;
}

.dst-pill:hover:not(:disabled) {
    background: var(--secondary-hover-color, rgba(255, 255, 255, 0.08));
}

.dst-pill.is-on {
    border-color: var(--accent-color, #3b82f6);
    background: color-mix(in srgb, var(--accent-color, #3b82f6) 18%, transparent);
    color: #fff;
}

/* ── "Watch it draw" toggle ── */
.dst-toggle {
    display: flex;
    align-items: flex-start;
    gap: 11px;
    cursor: pointer;
}

.dst-toggle.is-off {
    opacity: 0.5;
    cursor: default;
}

.dst-toggle input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.dst-toggle-box {
    flex-shrink: 0;
    width: 38px;
    height: 22px;
    margin-top: 1px;
    border-radius: 11px;
    background: var(--secondary-color, rgba(255, 255, 255, 0.12));
    border: 1px solid var(--border-color, rgba(255, 255, 255, 0.12));
    position: relative;
    transition: background 0.18s ease, border-color 0.18s ease;
}

.dst-toggle-box i {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #fff;
    transition: transform 0.18s var(--ui-ease, cubic-bezier(0.22, 0.61, 0.36, 1));
}

.dst-toggle input:checked + .dst-toggle-box {
    background: var(--accent-color, #3b82f6);
    border-color: transparent;
}

.dst-toggle input:checked + .dst-toggle-box i {
    transform: translateX(16px);
}

.dst-toggle input:focus-visible + .dst-toggle-box {
    outline: 2px solid var(--accent-color, #3b82f6);
    outline-offset: 2px;
}

.dst-toggle-txt {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.dst-toggle-txt b {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-color, #e7eaee);
}

.dst-toggle-txt em {
    font-style: normal;
    font-size: 11.5px;
    line-height: 1.4;
    color: var(--subheading-color, #98a2b3);
}

/* ═══════════════════════════════════════════════════════════════════════════
   4. NARROW SCREENS — the sidebar becomes a bottom sheet
   ═══════════════════════════════════════════════════════════════════════════ */

@media screen and (max-width: 900px) {

    /* The sheet overlays the stage instead of taking width from it, so the image
       keeps the full frame and the controls stay reachable with a thumb. */
    .dlx-body {
        position: relative;
    }

    .dlx-side {
        /* Anchor to the overlay (which fills the viewport) rather than the flex
           .dlx-body. On phones the sheet must always rise off the real bottom
           edge, and a definite height keeps the inner .dst-scroll working — so
           its top can never end up pinned/collapsed at the bottom of the screen. */
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        top: auto;
        width: auto;
        flex: none;
        margin-right: 0;
        height: min(84%, 84vh);
        border-left: none;
        border-top: 1px solid var(--border-color, rgba(255, 255, 255, 0.1));
        border-radius: 20px 20px 0 0;
        box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.5);
        transform: translateY(101%);
        opacity: 1;
        transition: transform 0.32s var(--ui-ease, cubic-bezier(0.22, 0.61, 0.36, 1));
    }

    .dlx-overlay.dlx-studio-open .dlx-side {
        transform: translateY(0);
    }

    .dlx-scrim {
        display: none;
    }

    .dlx-overlay.dlx-studio-open .dlx-scrim {
        display: block;
    }

    .dlx-overlay.dlx-studio-open .dlx-canvas {
        max-width: 94vw;
    }

    /* Drag affordance so the sheet reads as a sheet. */
    .dst-grip {
        display: grid;
        place-items: center;
        padding: 9px 0 3px;
        flex-shrink: 0;
        touch-action: none;
    }

    .dst-grip i {
        width: 38px;
        height: 4px;
        border-radius: 2px;
        background: var(--border-color, rgba(255, 255, 255, 0.22));
    }

    .dst-head {
        padding: 6px 12px 12px 18px;
    }

    .dst-quicks {
        /* Icon-only squares: three across on phones. */
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .dst-quick {
        border-radius: 12px;
    }

    /* The label duplicates the icon and costs width the title needs. */
    .dlx-dl-label,
    .dlx-ai-label {
        display: none;
    }

    .dlx-overlay .dlx-canvas {
        max-height: 46vh;
    }
}

@media screen and (max-width: 600px) {
    .dst-sec {
        padding: 14px 16px;
    }

    .dst-model {
        padding: 10px 11px;
    }

    .dst-model-sub {
        /* Two lines of blurb per model is enough on a phone; the full text is
           still available to screen readers. */
        display: -webkit-box;
        -webkit-line-clamp: 2;
        line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }

    .dimg {
        width: min(78vw, 280px);
    }
}

/* Landscape phones: a bottom sheet would leave no image visible at all. */
@media screen and (max-width: 900px) and (orientation: landscape) and (max-height: 520px) {
    .dlx-side {
        left: auto;
        top: 0;
        bottom: 0;
        height: auto;                 /* full-height right panel, not the bottom-sheet height */
        width: min(360px, 62vw);
        max-height: none;
        border-radius: 0;
        border-top: none;
        border-left: 1px solid var(--border-color, rgba(255, 255, 255, 0.1));
        transform: translateX(101%);
    }

    .dlx-overlay.dlx-studio-open .dlx-side {
        transform: translateX(0);
    }

    .dst-grip {
        display: none;
    }

    .dst-quicks {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

/* Respect a reduced-motion preference: keep the progressive sharpening (it is
   information, not decoration) but drop the spinners and sweeps. */
@media (prefers-reduced-motion: reduce) {

    .dimg-veil,
    .dlx-live-veil,
    .dimg-orb,
    .dlx-live-orb,
    .dst-go.is-busy .dst-go-ico {
        animation: none;
    }

    .dlx-side,
    .dimg-img,
    .dlx-live-img,
    .dst-toggle-box i {
        transition-duration: 0.01ms;
    }

    .dlx-mark {
        animation: none;
    }
}

/* ── Creative polish ───────────────────────────────────────────────────────── */
/* The studio stacks a gentle rise-and-fade stagger in as it slides up. */
.dlx-overlay.dlx-studio-open .dst-head,
.dlx-overlay.dlx-studio-open .dst-sec {
    animation: dst-rise 0.34s var(--ui-ease, cubic-bezier(0.22, 0.61, 0.36, 1)) both;
}

.dlx-overlay.dlx-studio-open .dst-head { animation-delay: 0.02s; }
.dlx-overlay.dlx-studio-open .dst-sec:nth-child(1) { animation-delay: 0.05s; }
.dlx-overlay.dlx-studio-open .dst-sec:nth-child(2) { animation-delay: 0.10s; }
.dlx-overlay.dlx-studio-open .dst-sec:nth-child(3) { animation-delay: 0.15s; }
.dlx-overlay.dlx-studio-open .dst-sec:nth-child(4) { animation-delay: 0.20s; }
.dlx-overlay.dlx-studio-open .dst-sec:nth-child(5) { animation-delay: 0.25s; }

@keyframes dst-rise {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Slimmer, theme-aware scrollbar in the sheet. */
.dst-scroll::-webkit-scrollbar { width: 8px; }
.dst-scroll::-webkit-scrollbar-thumb {
    border-radius: 8px;
    background: color-mix(in srgb, var(--subheading-color, #98a2b3) 32%, transparent);
    border: 2px solid transparent;
    background-clip: padding-box;
}

.dst-scroll::-webkit-scrollbar-thumb:hover {
    background: color-mix(in srgb, var(--subheading-color, #98a2b3) 48%, transparent);
    border: 2px solid transparent;
    background-clip: padding-box;
}

/* Reduced-motion users skip the entrance stagger (information stays, motion
   doesn't). Sourced AFTER the creative block so it wins on equal specificity. */
@media (prefers-reduced-motion: reduce) {
    .dlx-overlay.dlx-studio-open .dst-head,
    .dlx-overlay.dlx-studio-open .dst-sec {
        animation: none;
    }
}
