/* ==========================================================================
   Dimo Imagine — studio layer (image · video · audio)

   Built on dimo.css tokens (--primary-rgb, --color-*, --border-*), so it
   follows the Imagine accent and the light/dark theme automatically. Classes
   are prefixed `ims-` because the compiled Tailwind build only carries the
   utilities already used elsewhere.

   The one loud element is the video "monitor": a screen that stays dark in
   both themes, framed with viewfinder brackets and a running timecode.
   Everything around it stays quiet.
   ========================================================================== */

.ims {
    --ims-gap: 1.25rem;
    --ims-panel-w: 390px;
    --ims-screen: #0C0E12;
    --ims-screen-line: rgb(255 255 255 / 0.08);
    --ims-danger: 239 68 68;
    max-width: 80rem;
    margin-inline: auto;
}

/* ------------------------------------------------------------ header ---- */

.ims-head {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    gap: 1rem;
    margin-block-end: 1.5rem;
}
.ims-head__sub {
    margin-block-start: 0.5rem;
    font-size: 0.875rem;
    color: var(--color-text-muted);
    line-height: 1.8;
}
.ims-head__actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

/* ------------------------------------------------------------ layout ---- */

.ims-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: var(--ims-gap);
    align-items: start;
}
@media (min-width: 1024px) {
    .ims-layout { grid-template-columns: var(--ims-panel-w) minmax(0, 1fr); }
    .ims-panel {
        position: sticky;
        top: 5.5rem;
        max-height: calc(100vh - 7rem);
        overflow-y: auto;
        scrollbar-width: thin;
    }
}

.ims-panel {
    padding: 0;
    display: flex;
    flex-direction: column;
}
.ims-panel__body {
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 1.35rem;
}
.ims-block { min-width: 0; }
.ims-block__head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.5rem;
    margin-block-end: 0.55rem;
}
.ims-block__head .field-label { margin: 0; }
.ims-hint {
    font-size: 0.6875rem;
    color: var(--color-text-muted);
    line-height: 1.7;
}
.ims-divider {
    height: 1px;
    background: var(--border-subtle);
    margin-inline: -1.25rem;
}

/* Generate button + summary. Sticks to the viewport bottom on small screens
   so the action is always one thumb away while scrolling options. */
.ims-actionbar {
    position: sticky;
    bottom: 0;
    z-index: 5;
    padding: 0.9rem 1.25rem calc(0.9rem + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid var(--border-subtle);
    background: var(--color-surface);
    border-end-start-radius: var(--radius);
    border-end-end-radius: var(--radius);
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
}
@media (max-width: 1023.98px) {
    .ims-actionbar { box-shadow: 0 -12px 28px -18px var(--shadow-color); }
}
.ims-summary {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    font-size: 0.6875rem;
    color: var(--color-text-muted);
}
.ims-summary span {
    padding: 0.15rem 0.5rem;
    border-radius: 99px;
    background: var(--color-bg-dark);
    border: 1px solid var(--border-subtle);
    direction: ltr;
    unicode-bidi: isolate;
}
.ims-summary:empty { display: none; }
.ims-go { width: 100%; min-height: 3rem; font-size: 0.95rem; gap: 0.6rem; }
.ims-go svg { width: 1.15rem; height: 1.15rem; flex-shrink: 0; }
.ims-go kbd {
    font-family: 'Roboto Mono', ui-monospace, monospace;
    font-size: 0.625rem;
    padding: 0.1rem 0.35rem;
    border-radius: 0.3rem;
    border: 1px solid currentColor;
    opacity: 0.55;
}
@media (hover: none) { .ims-go kbd { display: none; } }

.ims-spin {
    width: 1rem;
    height: 1rem;
    border-radius: 50%;
    border: 2px solid currentColor;
    border-inline-end-color: transparent;
    animation: ims-rotate 0.7s linear infinite;
    flex-shrink: 0;
}

/* ------------------------------------------------------ mode switch ----- */

.ims-tabs {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 1fr;
    gap: 0.25rem;
    padding: 0.3rem;
    border-radius: calc(var(--radius) + 0.1rem);
    background: var(--color-bg-dark);
    border: 1px solid var(--border-subtle);
    margin-block-end: 1.25rem;
    max-width: 30rem;
}
.ims-tab {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.65rem 0.75rem;
    border-radius: var(--radius);
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--color-text-muted);
    transition: background-color .2s var(--ease-out), color .2s var(--ease-out);
}
.ims-tab svg { width: 1.05rem; height: 1.05rem; }
.ims-tab:hover { color: var(--color-text-main); }
.ims-tab.is-on {
    background: var(--color-surface);
    color: rgb(var(--primary-ink-rgb));
    box-shadow: 0 1px 0 var(--border-strong), 0 6px 16px -10px var(--shadow-color);
}
.ims-tab:focus-visible { outline: 2px solid rgb(var(--primary-rgb) / .7); outline-offset: 2px; }

/* ------------------------------------------------------- prompt box ----- */

.ims-prompt {
    position: relative;
    border-radius: 0.6rem;
    border: 1px solid var(--border-subtle);
    background: var(--color-bg-dark);
    transition: border-color .2s var(--ease-out), box-shadow .2s var(--ease-out);
}
.ims-prompt:focus-within {
    border-color: rgb(var(--primary-rgb) / .7);
    box-shadow: 0 0 0 3px rgb(var(--primary-rgb) / .12);
}
.ims-prompt textarea {
    display: block;
    width: 100%;
    min-height: 7.5rem;
    padding: 0.85rem 0.95rem 0.4rem;
    border: 0;
    background: transparent;
    color: var(--color-text-main);
    font-size: 0.9rem;
    line-height: 1.85;
    resize: vertical;
}
.ims-prompt textarea:focus { outline: none; }
.ims-prompt textarea::placeholder { color: rgb(var(--color-text-muted-rgb) / .6); }
.ims-prompt__foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.35rem 0.6rem 0.5rem;
}
.ims-count {
    font-family: 'Roboto Mono', ui-monospace, monospace;
    font-size: 0.625rem;
    color: var(--color-text-muted);
    direction: ltr;
}
.ims-count.is-near { color: rgb(var(--primary-ink-rgb)); }
.ims-iconbtn {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.3rem 0.5rem;
    border-radius: 0.4rem;
    font-size: 0.6875rem;
    color: var(--color-text-muted);
    transition: color .15s, background-color .15s;
}
.ims-iconbtn svg { width: 0.9rem; height: 0.9rem; }
.ims-iconbtn:hover { color: rgb(var(--primary-ink-rgb)); background: var(--color-hover-subtle); }
.ims-iconbtn:focus-visible { outline: 2px solid rgb(var(--primary-rgb) / .7); }

/* Quick-add chips (camera moves, styles). Horizontal scroll on phones. */
.ims-chips {
    display: flex;
    gap: 0.35rem;
    overflow-x: auto;
    padding-block-end: 0.2rem;
    scrollbar-width: none;
    -webkit-mask-image: linear-gradient(to left, #000 88%, transparent);
            mask-image: linear-gradient(to left, #000 88%, transparent);
}
.ims-chips::-webkit-scrollbar { display: none; }
@media (min-width: 1024px) {
    .ims-chips { flex-wrap: wrap; overflow: visible; -webkit-mask-image: none; mask-image: none; }
}
.ims-chip {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.3rem 0.65rem;
    border-radius: 99px;
    border: 1px dashed var(--border-strong);
    font-size: 0.6875rem;
    color: var(--color-text-muted);
    white-space: nowrap;
    transition: all .15s var(--ease-out);
}
.ims-chip::before { content: '+'; font-weight: 700; opacity: .6; }
.ims-chip:hover, .ims-chip:focus-visible {
    border-style: solid;
    border-color: rgb(var(--primary-rgb) / .6);
    color: rgb(var(--primary-ink-rgb));
    outline: none;
}
.ims-chip.is-added { border-style: solid; border-color: rgb(var(--primary-rgb) / .5); color: rgb(var(--primary-ink-rgb)); background: rgb(var(--primary-rgb) / .08); }
.ims-chip.is-added::before { content: '✓'; }

/* ------------------------------------------------------ segmented ------- */

.ims-seg {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}
.ims-seg--scroll {
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    padding-block-end: 0.15rem;
}
.ims-seg--scroll::-webkit-scrollbar { display: none; }
@media (min-width: 1024px) { .ims-seg--scroll { flex-wrap: wrap; } }

.ims-opt {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    min-height: 2.25rem;
    padding: 0.4rem 0.75rem;
    border-radius: 0.5rem;
    border: 1px solid var(--border-subtle);
    background: var(--color-bg-dark);
    color: var(--color-text-muted);
    font-size: 0.75rem;
    font-weight: 600;
    direction: ltr;
    transition: border-color .15s var(--ease-out), color .15s var(--ease-out), background-color .15s var(--ease-out);
}
.ims-opt:hover { border-color: rgb(var(--primary-rgb) / .5); color: var(--color-text-main); }
.ims-opt:focus-visible { outline: 2px solid rgb(var(--primary-rgb) / .7); outline-offset: 1px; }
.ims-opt[aria-checked="true"] {
    border-color: rgb(var(--primary-rgb));
    background: rgb(var(--primary-rgb) / .12);
    color: rgb(var(--primary-ink-rgb));
}
.ims-opt small { font-weight: 500; opacity: .7; font-size: 0.625rem; }

/* Aspect-ratio tiles: the icon IS the label; the ratio sits under it. */
.ims-seg--ratio { display: grid; grid-template-columns: repeat(auto-fill, minmax(3.9rem, 1fr)); }
.ims-opt--ratio {
    flex-direction: column;
    gap: 0.35rem;
    padding: 0.6rem 0.3rem 0.45rem;
    min-height: 4.1rem;
}
.ims-opt--ratio span:last-child { font-size: 0.6875rem; }
.ims-ratio-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 1.6rem;
    height: 1.6rem;
}
.ims-ratio-icon i {
    display: block;
    border: 1.5px solid currentColor;
    border-radius: 3px;
    transition: background-color .15s;
}
.ims-opt[aria-checked="true"] .ims-ratio-icon i { background: rgb(var(--primary-rgb) / .25); }
.ims-ratio-icon i.is-auto { border-style: dashed; }

.ims-empty-opt { font-size: 0.6875rem; color: var(--color-text-muted); }

/* ------------------------------------------------------- toggles -------- */

.ims-switch {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.7rem 0.85rem;
    border-radius: 0.6rem;
    border: 1px solid var(--border-subtle);
    background: var(--color-bg-dark);
    cursor: pointer;
}
.ims-switch__text { display: flex; flex-direction: column; gap: 0.1rem; font-size: 0.8125rem; color: var(--color-text-main); }
.ims-switch__text small { font-size: 0.6875rem; color: var(--color-text-muted); }
.ims-switch input { position: absolute; opacity: 0; pointer-events: none; }
.ims-switch__track {
    position: relative;
    width: 2.4rem;
    height: 1.35rem;
    flex-shrink: 0;
    border-radius: 99px;
    background: var(--border-strong);
    transition: background-color .2s var(--ease-out);
}
.ims-switch__track::after {
    content: '';
    position: absolute;
    top: 0.175rem;
    inset-inline-start: 0.175rem;
    width: 1rem;
    height: 1rem;
    border-radius: 50%;
    background: #fff;
    transition: transform .2s var(--ease-out);
}
.ims-switch input:checked + .ims-switch__track { background: rgb(var(--primary-rgb)); }
[dir="rtl"] .ims-switch input:checked + .ims-switch__track::after,
.ims-switch input:checked + .ims-switch__track::after { transform: translateX(-1.05rem); }
[dir="ltr"] .ims-switch input:checked + .ims-switch__track::after { transform: translateX(1.05rem); }
.ims-switch input:focus-visible + .ims-switch__track { outline: 2px solid rgb(var(--primary-rgb) / .7); outline-offset: 2px; }

/* Advanced options drawer */
.ims-adv { border-radius: 0.6rem; border: 1px solid var(--border-subtle); }
.ims-adv > summary {
    list-style: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 0.85rem;
    cursor: pointer;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--color-text-main);
}
.ims-adv > summary::-webkit-details-marker { display: none; }
.ims-adv > summary svg { width: 1rem; height: 1rem; color: var(--color-text-muted); transition: transform .2s var(--ease-out); }
.ims-adv[open] > summary svg { transform: rotate(180deg); }
.ims-adv > summary:focus-visible { outline: 2px solid rgb(var(--primary-rgb) / .7); border-radius: 0.6rem; }
.ims-adv__body { padding: 0.25rem 0.85rem 0.95rem; display: grid; gap: 0.9rem; }
.ims-grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.75rem; }

.ims-seed { display: flex; gap: 0.4rem; }
.ims-seed .field { direction: ltr; }

/* -------------------------------------------------- model capability ---- */

.ims-caps { display: flex; flex-wrap: wrap; gap: 0.3rem; margin-block-start: 0.6rem; }
.ims-cap {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.2rem 0.5rem;
    border-radius: 0.35rem;
    font-size: 0.625rem;
    font-weight: 600;
    color: var(--color-text-muted);
    background: var(--color-bg-dark);
    border: 1px solid var(--border-subtle);
}
.ims-cap svg { width: 0.75rem; height: 0.75rem; }
.ims-cap.is-yes { color: rgb(var(--primary-ink-rgb)); border-color: rgb(var(--primary-rgb) / .3); }

/* -------------------------------------------------- frame slots --------- */

.ims-frames {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    align-items: center;
    gap: 0.5rem;
}
.ims-frames__arrow { color: var(--color-text-muted); display: flex; }
.ims-frames__arrow svg { width: 1.1rem; height: 1.1rem; }
[dir="rtl"] .ims-frames__arrow svg { transform: scaleX(-1); }

.ims-slot {
    position: relative;
    aspect-ratio: 16 / 10;
    border-radius: 0.6rem;
    border: 1.5px dashed var(--border-strong);
    background: var(--color-bg-dark);
    overflow: hidden;
    transition: border-color .15s var(--ease-out), background-color .15s var(--ease-out);
}
.ims-slot:hover, .ims-slot.is-drag { border-color: rgb(var(--primary-rgb) / .7); background: rgb(var(--primary-rgb) / .05); }
.ims-slot.is-disabled { opacity: .4; pointer-events: none; }
.ims-slot__pick {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
    padding: 0.4rem;
    text-align: center;
    color: var(--color-text-muted);
    font-size: 0.6875rem;
    width: 100%;
}
.ims-slot__pick svg { width: 1.2rem; height: 1.2rem; }
.ims-slot__pick strong { color: var(--color-text-main); font-size: 0.75rem; font-weight: 600; }
.ims-slot__pick:focus-visible { outline: 2px solid rgb(var(--primary-rgb) / .7); outline-offset: -3px; border-radius: 0.5rem; }
.ims-slot img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.ims-slot__tag {
    position: absolute;
    top: 0.35rem;
    inset-inline-start: 0.35rem;
    padding: 0.1rem 0.4rem;
    border-radius: 0.3rem;
    font-size: 0.5625rem;
    font-weight: 700;
    color: #fff;
    background: rgb(0 0 0 / .6);
}
.ims-slot__actions {
    position: absolute;
    bottom: 0.35rem;
    inset-inline-end: 0.35rem;
    display: flex;
    gap: 0.25rem;
}
.ims-slot__actions button {
    width: 1.75rem;
    height: 1.75rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 0.4rem;
    color: #fff;
    background: rgb(0 0 0 / .6);
    border: 1px solid rgb(255 255 255 / .2);
}
.ims-slot__actions button:hover { background: rgb(var(--ims-danger) / .85); }
.ims-slot__actions svg { width: 0.85rem; height: 0.85rem; }
.ims-slot__busy { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: rgb(0 0 0 / .45); color: #fff; }
.ims-frames-note { margin-block-start: 0.5rem; }
.ims-frames-src { display: flex; gap: 0.4rem; margin-block-start: 0.5rem; }

/* Drive picker sheet */
.ims-sheet {
    position: fixed;
    inset: 0;
    z-index: 80;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    background: rgb(0 0 0 / .6);
    backdrop-filter: blur(4px);
}
.ims-sheet[hidden] { display: none; }
.ims-sheet__card {
    width: 100%;
    max-width: 40rem;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    border-radius: 1rem 1rem 0 0;
    background: var(--color-surface);
    border: 1px solid var(--border-subtle);
    animation: ims-sheet-in .28s var(--ease-out);
}
@media (min-width: 640px) {
    .ims-sheet { align-items: center; padding: 1.5rem; }
    .ims-sheet__card { border-radius: 1rem; }
}
.ims-sheet__head { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; padding: 1rem 1.1rem; border-bottom: 1px solid var(--border-subtle); }
.ims-sheet__head h3 { font-size: 0.9rem; font-weight: 700; color: var(--color-text-main); }
.ims-sheet__search { padding: 0.75rem 1.1rem 0; }
.ims-sheet__grid {
    padding: 0.9rem 1.1rem calc(1.1rem + env(safe-area-inset-bottom, 0px));
    overflow-y: auto;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(6.5rem, 1fr));
    gap: 0.6rem;
}
.ims-sheet__item {
    aspect-ratio: 1;
    border-radius: 0.5rem;
    overflow: hidden;
    border: 1px solid var(--border-subtle);
    background: var(--color-bg-dark);
}
.ims-sheet__item img { width: 100%; height: 100%; object-fit: cover; }
.ims-sheet__item:hover, .ims-sheet__item:focus-visible { outline: 2px solid rgb(var(--primary-rgb)); outline-offset: 1px; }

/* ---------------------------------------------------------- output ----- */

.ims-out { padding: 1.25rem; min-height: 60vh; }
.ims-out__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-block-end: 1rem;
}
.ims-out__head h2 { font-size: 0.875rem; font-weight: 700; color: var(--color-text-main); }

.ims-status { display: inline-flex; align-items: center; gap: 0.4rem; }
.ims-status::before {
    content: '';
    width: 0.45rem;
    height: 0.45rem;
    border-radius: 50%;
    background: var(--color-text-muted);
}
.ims-status.is-busy::before { background: rgb(var(--primary-rgb)); animation: ims-pulse 1.2s ease-in-out infinite; }
.ims-status.is-done::before { background: rgb(var(--primary-rgb)); }
.ims-status.is-bad { color: rgb(var(--ims-danger)); border-color: rgb(var(--ims-danger) / .4); }
.ims-status.is-bad::before { background: rgb(var(--ims-danger)); }

.ims-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: 0.9rem;
    padding: 3.5rem 1rem;
    color: var(--color-text-muted);
}
.ims-empty__icon {
    width: 3.5rem;
    height: 3.5rem;
    border-radius: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgb(var(--primary-ink-rgb));
    background: rgb(var(--primary-rgb) / .1);
    border: 1px solid rgb(var(--primary-rgb) / .25);
}
.ims-empty__icon svg { width: 1.5rem; height: 1.5rem; }
.ims-empty h3 { font-size: 0.95rem; font-weight: 700; color: var(--color-text-main); }
.ims-empty p { font-size: 0.8125rem; max-width: 26rem; line-height: 1.9; }
.ims-empty ol { font-size: 0.75rem; text-align: start; display: grid; gap: 0.35rem; counter-reset: step; }
.ims-empty ol li { display: flex; gap: 0.5rem; align-items: center; counter-increment: step; }
.ims-empty ol li::before {
    content: counter(step);
    width: 1.3rem; height: 1.3rem;
    flex-shrink: 0;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: 50%;
    font-size: 0.625rem; font-weight: 700;
    border: 1px solid var(--border-strong);
}

.ims-error {
    display: flex;
    gap: 0.6rem;
    align-items: flex-start;
    padding: 0.75rem 0.85rem;
    border-radius: 0.55rem;
    border: 1px solid rgb(var(--ims-danger) / .35);
    background: rgb(var(--ims-danger) / .08);
    color: rgb(var(--ims-danger));
    font-size: 0.75rem;
    line-height: 1.8;
}
[data-theme="dark"] .ims-error, :root:not([data-theme="light"]) .ims-error { color: #fca5a5; }
.ims-error svg { width: 1rem; height: 1rem; flex-shrink: 0; margin-top: 0.2rem; }
.ims-error__body { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.ims-error__actions { display: flex; gap: 0.4rem; margin-top: 0.45rem; flex-wrap: wrap; }

.ims-mini {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.35rem 0.6rem;
    border-radius: 0.4rem;
    font-size: 0.6875rem;
    font-weight: 600;
    color: var(--color-text-main);
    background: var(--color-bg-dark);
    border: 1px solid var(--border-subtle);
    white-space: nowrap;
    transition: border-color .15s, color .15s;
}
.ims-mini svg { width: 0.85rem; height: 0.85rem; }
.ims-mini:hover { border-color: rgb(var(--primary-rgb) / .55); color: rgb(var(--primary-ink-rgb)); }
.ims-mini:focus-visible { outline: 2px solid rgb(var(--primary-rgb) / .7); }
.ims-mini:disabled { opacity: .5; pointer-events: none; }

/* --------------------------------------------------- image results ----- */

.ims-gallery {
    display: grid;
    align-items: start;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem;
}
@media (min-width: 768px) { .ims-gallery { grid-template-columns: repeat(3, minmax(0, 1fr)); } }

.ims-tile {
    position: relative;
    border-radius: 0.65rem;
    overflow: hidden;
    border: 1px solid var(--border-subtle);
    background: var(--color-bg-dark);
    animation: ims-reveal .5s var(--ease-out);
}
.ims-tile__media { display: block; width: 100%; position: relative; background: var(--color-bg-dark); cursor: zoom-in; }
.ims-tile__media img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ims-tile__bar {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.5rem;
}
.ims-tile__meta { flex: 1; min-width: 0; font-size: 0.625rem; color: var(--color-text-muted); direction: ltr; text-align: start; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 480px) { .ims-tile__meta { display: none; } .ims-tile__bar { justify-content: flex-end; } }

/* Loading tile: the image "develops" — a grainy field with a light sweep. */
.ims-develop {
    position: relative;
    overflow: hidden;
    background:
        radial-gradient(120% 90% at 30% 20%, rgb(var(--primary-rgb) / .22), transparent 60%),
        radial-gradient(100% 80% at 80% 90%, rgb(var(--primary-rgb) / .12), transparent 55%),
        var(--color-bg-dark);
    animation: ims-breathe 3.2s ease-in-out infinite;
}
.ims-develop::before {
    content: '';
    position: absolute;
    inset: -50%;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='120' height='120' filter='url(%23n)' opacity='.35'/%3E%3C/svg%3E");
    mix-blend-mode: overlay;
    animation: ims-grain 0.6s steps(3) infinite;
}
.ims-develop::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(105deg, transparent 35%, rgb(255 255 255 / .16) 50%, transparent 65%);
    transform: translateX(-100%);
    animation: ims-sweep 1.9s var(--ease-out) infinite;
}
.ims-develop__label {
    position: absolute;
    inset-inline: 0;
    bottom: 0.6rem;
    z-index: 1;
    text-align: center;
    font-size: 0.6875rem;
    color: var(--color-text-main);
    text-shadow: 0 1px 6px rgb(0 0 0 / .5);
}
.ims-develop__label b { font-family: 'Roboto Mono', monospace; font-weight: 500; direction: ltr; display: inline-block; }

/* Lightbox */
.ims-lightbox {
    position: fixed;
    inset: 0;
    z-index: 90;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background: rgb(0 0 0 / .88);
    animation: ims-fade .2s ease-out;
}
.ims-lightbox[hidden] { display: none; }
.ims-lightbox img { max-width: 100%; max-height: 82vh; border-radius: 0.5rem; }
.ims-lightbox__bar { position: absolute; top: calc(0.75rem + env(safe-area-inset-top, 0px)); inset-inline: 0.75rem; display: flex; justify-content: space-between; gap: 0.5rem; }
.ims-lightbox .ims-mini { background: rgb(0 0 0 / .6); color: #fff; border-color: rgb(255 255 255 / .25); }

/* ---------------------------------------------------- video monitor ---- */

.ims-monitor {
    position: relative;
    border-radius: calc(var(--radius) + 0.15rem);
    background: var(--ims-screen);
    border: 1px solid var(--border-subtle);
    overflow: hidden;
    color: #E8E6EE;
    isolation: isolate;
}
.ims-monitor__screen {
    position: relative;
    aspect-ratio: 16 / 9;
    max-height: 70vh;
    margin-inline: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: aspect-ratio .35s var(--ease-out), width .35s var(--ease-out);
}
.ims-monitor__screen video { width: 100%; height: 100%; object-fit: contain; background: #000; display: block; }

/* Viewfinder: four corner brackets + centre cross, sized to the chosen ratio. */
.ims-vf { position: absolute; inset: 0.85rem; pointer-events: none; }
.ims-vf i { position: absolute; width: 1.1rem; height: 1.1rem; border: 0 solid rgb(255 255 255 / .55); }
.ims-vf i:nth-child(1) { top: 0; left: 0; border-top-width: 2px; border-left-width: 2px; }
.ims-vf i:nth-child(2) { top: 0; right: 0; border-top-width: 2px; border-right-width: 2px; }
.ims-vf i:nth-child(3) { bottom: 0; left: 0; border-bottom-width: 2px; border-left-width: 2px; }
.ims-vf i:nth-child(4) { bottom: 0; right: 0; border-bottom-width: 2px; border-right-width: 2px; }

.ims-hud {
    position: absolute;
    top: 1.55rem;
    inset-inline: 2.1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
    font-family: 'Roboto Mono', ui-monospace, monospace;
    font-size: 0.6875rem;
    letter-spacing: 0.04em;
    color: rgb(255 255 255 / .75);
    direction: ltr;
    pointer-events: none;
}
.ims-hud__rec { display: inline-flex; align-items: center; gap: 0.4rem; }
.ims-hud__rec::before {
    content: '';
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 50%;
    background: rgb(255 255 255 / .35);
}
.ims-monitor.is-rendering .ims-hud__rec::before { background: rgb(var(--primary-rgb)); box-shadow: 0 0 10px rgb(var(--primary-rgb)); animation: ims-pulse 1.1s ease-in-out infinite; }

.ims-idle {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.6rem;
    padding: 1rem;
    text-align: center;
    color: rgb(255 255 255 / .6);
    font-size: 0.8125rem;
}
.ims-idle svg { width: 2.4rem; height: 2.4rem; color: rgb(255 255 255 / .35); }
.ims-idle strong { color: #fff; font-size: 0.95rem; }

/* Rendering state: scanlines, a sweeping exposure bar and a film strip. */
.ims-render {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    padding: 2.5rem 1rem;
    text-align: center;
    background:
        radial-gradient(60% 70% at 50% 50%, rgb(var(--primary-rgb) / .18), transparent 70%),
        repeating-linear-gradient(0deg, rgb(255 255 255 / .025) 0 1px, transparent 1px 3px);
    overflow: hidden;
}
.ims-render::after {
    content: '';
    position: absolute;
    inset-inline: 0;
    height: 30%;
    top: -30%;
    background: linear-gradient(180deg, transparent, rgb(var(--primary-rgb) / .14), transparent);
    animation: ims-scan 2.8s linear infinite;
}
.ims-render__tc {
    font-family: 'Roboto Mono', ui-monospace, monospace;
    font-size: clamp(1.6rem, 5vw, 2.6rem);
    font-weight: 500;
    letter-spacing: 0.06em;
    color: #fff;
    direction: ltr;
    font-variant-numeric: tabular-nums;
}
.ims-render__stage { font-size: 0.875rem; font-weight: 600; color: #fff; min-height: 1.4em; }
.ims-render__note { font-size: 0.6875rem; color: rgb(255 255 255 / .55); max-width: 24rem; line-height: 1.8; }

.ims-strip {
    position: relative;
    width: min(20rem, 80%);
    height: 2.4rem;
    overflow: hidden;
    border-radius: 0.3rem;
    background: rgb(255 255 255 / .06);
    -webkit-mask-image: linear-gradient(90deg, transparent, #000 18%, #000 82%, transparent);
            mask-image: linear-gradient(90deg, transparent, #000 18%, #000 82%, transparent);
}
.ims-strip__reel {
    position: absolute;
    inset-block: 0;
    left: 0;
    width: 200%;
    display: flex;
    animation: ims-reel 3s linear infinite;
    direction: ltr;
}
.ims-strip__reel span {
    flex: 0 0 calc(100% / 12);
    margin: 0.45rem 0.12rem;
    border-radius: 2px;
    background: rgb(255 255 255 / .1);
    position: relative;
}
.ims-strip__reel span:nth-child(3n) { background: rgb(var(--primary-rgb) / .35); }
.ims-strip::before, .ims-strip::after {
    content: '';
    position: absolute;
    inset-inline: 0;
    height: 0.2rem;
    z-index: 1;
    background: repeating-linear-gradient(90deg, rgb(255 255 255 / .35) 0 0.3rem, transparent 0.3rem 0.7rem);
}
.ims-strip::before { top: 0.08rem; }
.ims-strip::after  { bottom: 0.08rem; }

.ims-progress {
    width: min(20rem, 80%);
    height: 3px;
    border-radius: 3px;
    background: rgb(255 255 255 / .12);
    overflow: hidden;
}
.ims-progress i {
    display: block;
    height: 100%;
    width: 0;
    background: rgb(var(--primary-rgb));
    border-radius: inherit;
    transition: width .6s var(--ease-out);
}
.ims-progress.is-indeterminate i { width: 35%; animation: ims-indet 1.6s var(--ease-out) infinite; }

.ims-monitor__bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    padding: 0.7rem 0.9rem;
    border-top: 1px solid var(--ims-screen-line);
    background: rgb(255 255 255 / .02);
}
.ims-monitor__bar p { flex: 1 1 12rem; min-width: 0; font-size: 0.75rem; color: rgb(255 255 255 / .75); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ims-monitor__bar .ims-mini { background: rgb(255 255 255 / .06); color: #fff; border-color: rgb(255 255 255 / .14); }
.ims-monitor__bar .ims-mini:hover { border-color: rgb(var(--primary-rgb) / .7); color: #fff; }
.ims-monitor .ims-error { margin: 0.9rem; color: #fca5a5; }

/* Takes: every generation of this session + recent ones. */
.ims-takes-head { display: flex; align-items: center; justify-content: space-between; margin: 1.5rem 0 0.75rem; }
.ims-takes-head h2 { font-size: 0.875rem; font-weight: 700; color: var(--color-text-main); }
.ims-takes {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr));
    gap: 0.75rem;
}
@media (max-width: 480px) { .ims-takes { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.5rem; } }
.ims-take {
    text-align: start;
    border-radius: 0.6rem;
    overflow: hidden;
    border: 1px solid var(--border-subtle);
    background: var(--color-surface);
    transition: border-color .15s var(--ease-out);
    display: flex;
    flex-direction: column;
    min-width: 0;
}
.ims-take:hover { border-color: rgb(var(--primary-rgb) / .5); }
.ims-take.is-active { border-color: rgb(var(--primary-rgb)); box-shadow: 0 0 0 1px rgb(var(--primary-rgb) / .4); }
.ims-take:focus-visible { outline: 2px solid rgb(var(--primary-rgb) / .7); outline-offset: 2px; }
.ims-take__thumb {
    position: relative;
    aspect-ratio: 16 / 9;
    background: var(--ims-screen);
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgb(255 255 255 / .5);
}
.ims-take__thumb video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; pointer-events: none; }
.ims-take__thumb svg { width: 1.4rem; height: 1.4rem; }
.ims-take__badge {
    position: absolute;
    bottom: 0.35rem;
    inset-inline-start: 0.35rem;
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.1rem 0.4rem;
    border-radius: 0.3rem;
    font-size: 0.5625rem;
    font-weight: 700;
    color: #fff;
    background: rgb(0 0 0 / .65);
}
.ims-take__badge.is-busy { color: rgb(var(--primary-rgb)); }
.ims-take__badge.is-bad { color: #fca5a5; }
.ims-take__body { padding: 0.5rem 0.6rem 0.6rem; min-width: 0; }
.ims-take__body p { font-size: 0.6875rem; color: var(--color-text-main); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ims-take__body small { display: block; margin-top: 0.15rem; font-size: 0.5625rem; color: var(--color-text-muted); direction: ltr; text-align: start; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------------------------------------------------- audio results ---- */

.ims-tracks { display: grid; gap: 0.75rem; }
.ims-track {
    border-radius: 0.65rem;
    border: 1px solid var(--border-subtle);
    background: var(--color-bg-dark);
    padding: 0.9rem;
    display: grid;
    gap: 0.6rem;
    animation: ims-reveal .45s var(--ease-out);
}
.ims-track__head { display: flex; align-items: center; gap: 0.65rem; min-width: 0; }
.ims-track__icon {
    width: 2.4rem; height: 2.4rem;
    flex-shrink: 0;
    border-radius: 0.55rem;
    display: flex; align-items: center; justify-content: center;
    color: rgb(var(--primary-ink-rgb));
    background: rgb(var(--primary-rgb) / .12);
}
.ims-track__icon svg { width: 1.1rem; height: 1.1rem; }
.ims-track__title { flex: 1; min-width: 0; }
.ims-track__title p { font-size: 0.8125rem; color: var(--color-text-main); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ims-track__title small { font-size: 0.625rem; color: var(--color-text-muted); direction: ltr; display: block; text-align: start; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ims-track audio { width: 100%; height: 2.5rem; }
.ims-track__actions { display: flex; gap: 0.4rem; flex-wrap: wrap; justify-content: flex-end; }

/* Loading track: an equalizer that never quite settles. */
.ims-eq { display: flex; align-items: flex-end; gap: 3px; height: 2.4rem; direction: ltr; }
.ims-eq span {
    flex: 1;
    min-width: 3px;
    height: 100%;
    border-radius: 2px;
    background: rgb(var(--primary-rgb) / .75);
    animation: ims-eq 1.1s ease-in-out infinite;
    transform-origin: bottom;
}
.ims-track.is-loading { border-style: dashed; border-color: rgb(var(--primary-rgb) / .4); }
.ims-track [data-clock] { font-family: 'Roboto Mono', monospace; direction: ltr; display: inline-block; }

/* Voice grid */
.ims-voices { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.4rem; }
@media (min-width: 480px) and (max-width: 1023.98px) { .ims-voices { grid-template-columns: repeat(5, minmax(0, 1fr)); } }
.ims-voices .ims-opt { text-transform: capitalize; }

/* ------------------------------------------------------- keyframes ----- */

@keyframes ims-rotate { to { transform: rotate(360deg); } }
@keyframes ims-pulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }
@keyframes ims-sweep { to { transform: translateX(100%); } }
@keyframes ims-breathe { 0%, 100% { filter: saturate(1) brightness(1); } 50% { filter: saturate(1.4) brightness(1.15); } }
@keyframes ims-grain { 0% { transform: translate(0, 0); } 33% { transform: translate(-6%, 4%); } 66% { transform: translate(4%, -5%); } }
@keyframes ims-scan { to { top: 100%; } }
@keyframes ims-reel { to { transform: translateX(-50%); } }
@keyframes ims-indet { 0% { transform: translateX(-110%); } 100% { transform: translateX(300%); } }
@keyframes ims-eq { 0%, 100% { transform: scaleY(.2); } 50% { transform: scaleY(1); } }
@keyframes ims-reveal { from { opacity: 0; transform: translateY(6px) scale(.985); } to { opacity: 1; transform: none; } }
@keyframes ims-fade { from { opacity: 0; } }
@keyframes ims-sheet-in { from { transform: translateY(24px); opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
    .ims *, .ims *::before, .ims *::after,
    .ims-sheet__card, .ims-lightbox {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
    }
    .ims-progress.is-indeterminate i { width: 100%; opacity: .5; }
}

/* Small screens: tighter paddings, full-bleed monitor. */
@media (max-width: 639.98px) {
    .ims { --ims-gap: 1rem; }
    .ims-panel__body, .ims-out { padding: 1rem; }
    .ims-actionbar { padding-inline: 1rem; }
    .ims-divider { margin-inline: -1rem; }
    .ims-hud { top: 1.15rem; inset-inline: 1.6rem; font-size: 0.625rem; }
    .ims-vf { inset: 0.6rem; }
    .ims-render { gap: 0.7rem; }
    .ims-render__note { display: none; }
    .ims-head .page-title { font-size: 1.6rem; }
}

/* ------------------------------------------------ late additions ------ */

/* Monitor sized by the chosen ratio without overflowing the viewport. */
.ims-monitor__screen {
    --arw: 16;
    --arh: 9;
    aspect-ratio: var(--arw) / var(--arh);
    width: min(100%, calc(62vh * var(--arw) / var(--arh)));
    max-height: none;
}

.ims-slot__btns { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.25rem; margin-top: 0.15rem; }
.ims-slot__btns button {
    padding: 0.2rem 0.5rem;
    border-radius: 0.35rem;
    font-size: 0.625rem;
    font-weight: 600;
    color: var(--color-text-main);
    background: var(--color-surface);
    border: 1px solid var(--border-subtle);
}
.ims-slot__btns button:hover { border-color: rgb(var(--primary-rgb) / .6); color: rgb(var(--primary-ink-rgb)); }
.ims-slot__btns button:focus-visible { outline: 2px solid rgb(var(--primary-rgb) / .7); }
@media (max-width: 380px) { .ims-slot__pick strong { font-size: 0.6875rem; } .ims-slot__pick > span:first-child { display: none; } }

.ims-sheet__empty { grid-column: 1 / -1; text-align: center; padding: 2rem 0; font-size: 0.8125rem; color: var(--color-text-muted); }
.ims-hidden-input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
[hidden] { display: none !important; }
/* ------------------------------------------------ video edit studio --- */

/* Source clip / character slots reuse .ims-slot; videos fill like images. */
.ims-slot video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.ims-frames--single { grid-template-columns: minmax(0, 1fr); }
.ims-frames--single .ims-slot { aspect-ratio: 16 / 8; }
.ims-slot__meta {
    position: absolute;
    bottom: 0.35rem;
    inset-inline-start: 0.35rem;
    max-width: calc(100% - 3rem);
    padding: 0.1rem 0.4rem;
    border-radius: 0.3rem;
    font-size: 0.5625rem;
    font-weight: 600;
    color: #fff;
    background: rgb(0 0 0 / .6);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    /* Not direction:ltr — that would also flip this badge's logical inset
       onto the remove button. */
    unicode-bidi: plaintext;
}
.ims-sheet__item { position: relative; }
.ims-sheet__item video { width: 100%; height: 100%; object-fit: cover; pointer-events: none; }
.ims-sheet__item > span {
    position: absolute;
    inset-inline: 0;
    bottom: 0;
    padding: 0.15rem 0.3rem;
    font-size: 0.5625rem;
    color: #fff;
    background: linear-gradient(transparent, rgb(0 0 0 / .7));
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.ims-role-note {
    margin-block-start: 0.6rem;
    padding: 0.55rem 0.7rem;
    border-radius: 0.5rem;
    font-size: 0.6875rem;
    line-height: 1.7;
    color: var(--color-text-muted);
    background: var(--color-bg-dark);
    border: 1px solid var(--border-subtle);
}
.ims-role-note:empty { display: none; }
.ims-compare {
    position: absolute;
    top: 2.4rem;
    inset-inline-end: 1.6rem;
    z-index: 3;
    display: inline-flex;
    gap: 0.2rem;
    padding: 0.2rem;
    border-radius: 0.5rem;
    background: rgb(0 0 0 / .55);
    backdrop-filter: blur(6px);
}
.ims-compare button {
    padding: 0.25rem 0.6rem;
    border-radius: 0.35rem;
    font-size: 0.6875rem;
    font-weight: 600;
    color: rgb(255 255 255 / .75);
}
.ims-compare button[aria-pressed="true"] { background: rgb(255 255 255 / .9); color: #111; }
.ims-compare button:focus-visible { outline: 2px solid rgb(var(--primary-rgb)); }
