.app {
    position: relative;
    z-index: 1;
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
}

/* ── Topbar ── */
.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: .65rem 1.35rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    position: sticky;
    top: 0;
    z-index: 20;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(20px) saturate(1.3);
}

.topbar__left,
.topbar__right {
    display: flex;
    align-items: center;
    gap: .75rem;
}

.topbar__title {
    display: none;
}

.topbar__right #api-status {
    display: none;
}

.topbar__right .pill--user {
    font-size: .72rem;
    border-color: transparent;
    background: transparent;
    color: var(--text-subtle);
}

.nav {
    display: flex;
    gap: .15rem;
    margin-left: .5rem;
}

.nav__btn {
    border: none;
    background: transparent;
    color: var(--text-subtle);
    padding: .45rem .9rem;
    border-radius: var(--radius-pill);
    font-size: .84rem;
    font-weight: 500;
    cursor: pointer;
    transition: color .2s var(--ease), background .2s var(--ease);
}

.nav__btn:hover {
    color: var(--text-muted);
}

.nav__btn--active {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text);
}

/* ── Main ── */
.main {
    flex: 1;
    overflow-y: auto;
    padding: 0 1.25rem var(--composer-offset, 280px);
}

.main--no-composer:not(.main--chat) {
    padding-bottom: calc(1.25rem + env(safe-area-inset-bottom, 0px));
}

.main--no-composer.main--chat,
.main--chat {
    overflow: hidden;
}

.main--chat {
    flex: 1;
    min-height: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
}

.main--chat > .view--chat {
    flex: 1;
    min-height: 0;
}

/* ── Studio view ── */
.view--studio {
    width: 100%;
    min-height: calc(100dvh - var(--topbar-height, 52px) - var(--composer-offset, 280px));
}

.studio-stage {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: inherit;
    width: 100%;
    max-width: var(--studio-max);
    margin: 0 auto;
    padding: 1.5rem 0 1rem;
}

.studio-stage--empty .empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.empty-state {
    position: relative;
    text-align: center;
    padding: 2rem 1.5rem;
    max-width: 480px;
    margin: auto;
}

.empty-state__glow {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -55%);
    width: 280px;
    height: 280px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(255, 255, 255, 0.07) 0%, transparent 70%);
    pointer-events: none;
}

.empty-state__title {
    position: relative;
    margin: 0 0 .85rem;
    font-size: clamp(2rem, 6vw, 3rem);
    font-weight: 700;
    letter-spacing: -0.045em;
    line-height: 1.08;
}

.empty-state__sub {
    position: relative;
    margin: 0;
    color: var(--text-muted);
    font-size: .98rem;
    line-height: 1.65;
    max-width: 36ch;
    margin-inline: auto;
}

.progress {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .85rem;
    padding: 3rem 1rem;
    color: var(--text-muted);
    font-size: .9rem;
}

/* ── Studio canvas (single active item) ── */
.studio-canvas {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .75rem;
    padding: 0 .25rem;
}

.studio-hero {
    display: flex;
    flex-direction: column;
    gap: .65rem;
    width: 100%;
}

.studio-hero__media {
    position: relative;
    border-radius: var(--radius-lg);
    overflow: hidden;
    background: #000;
    cursor: zoom-in;
}

.studio-hero__media::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06);
    pointer-events: none;
    z-index: 2;
}

.studio-hero__media img {
    width: 100%;
    max-height: min(68vh, 640px);
    object-fit: contain;
    display: block;
    margin: 0 auto;
    background: #000;
}

.studio-hero__play {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    font-size: 2.75rem;
    color: #fff;
    background: rgba(0, 0, 0, 0.22);
    pointer-events: none;
    z-index: 1;
}

.studio-hero__actions {
    position: absolute;
    top: .65rem;
    right: .65rem;
    z-index: 3;
    display: flex;
    gap: .35rem;
    opacity: 0;
    transform: translateY(-4px);
    transition: opacity .22s var(--ease), transform .22s var(--ease);
}

.studio-hero__media:hover .studio-hero__actions,
.studio-hero__actions:focus-within {
    opacity: 1;
    transform: none;
}

.studio-hero__action {
    width: 34px;
    height: 34px;
    border: none;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.72);
    backdrop-filter: blur(10px);
    color: #fff;
    cursor: pointer;
    display: grid;
    place-items: center;
    transition: background .2s var(--ease), transform .15s var(--ease);
}

.studio-hero__action svg {
    width: 16px;
    height: 16px;
}

.studio-hero__action:hover {
    background: rgba(255, 255, 255, 0.92);
    color: #000;
}

.studio-hero__action--primary {
    background: rgba(255, 255, 255, 0.92);
    color: #000;
}

.studio-hero__action--primary:hover {
    background: #fff;
}

.studio-hero__meta {
    text-align: center;
    padding: 0 1rem;
    max-width: 52ch;
    margin: 0 auto;
}

.studio-hero__prompt {
    margin: 0;
    font-size: .84rem;
    line-height: 1.55;
    color: var(--text-muted);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.studio-hero__meta-skeleton {
    height: 12px;
    width: 55%;
    margin: .2rem auto 0;
    border-radius: 999px;
    background: var(--surface-2);
    position: relative;
    overflow: hidden;
}

.studio-hero__meta-skeleton::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,.06), transparent);
    animation: skeleton-shimmer 1.6s ease-in-out infinite;
}

.studio-hero--placeholder {
    pointer-events: none;
}

.studio-hero--placeholder .studio-hero__media {
    cursor: default;
    min-height: 220px;
}

/* ── Edit thread strip (Grok-style) ── */
.studio-thread {
    width: 100%;
    display: flex;
    justify-content: center;
    padding: .15rem 0 0;
}

.studio-thread__strip {
    display: flex;
    gap: .4rem;
    overflow-x: auto;
    padding: .2rem .15rem;
    max-width: 100%;
    scrollbar-width: none;
}

.studio-thread__strip::-webkit-scrollbar {
    display: none;
}

.studio-thread__item {
    position: relative;
    flex: 0 0 52px;
    width: 52px;
    height: 52px;
    border-radius: 10px;
    overflow: hidden;
    border: 2px solid transparent;
    background: #111;
    cursor: pointer;
    padding: 0;
    opacity: .72;
    transition: border-color .2s var(--ease), opacity .2s var(--ease), transform .2s var(--ease);
}

.studio-thread__item:hover {
    opacity: 1;
    transform: translateY(-1px);
}

.studio-thread__item--active {
    border-color: var(--accent);
    opacity: 1;
}

.studio-thread__item--new {
    border-color: rgba(255, 255, 255, 0.55);
    opacity: 1;
}

.studio-thread__item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.recent-card {
    border: none;
    border-radius: var(--radius-lg);
    overflow: hidden;
    cursor: pointer;
    background: transparent;
    transition: transform .25s var(--ease);
}

.recent-card:hover {
    transform: translateY(-3px);
}

.recent-card__thumb {
    position: relative;
    background: var(--bg-elevated);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.45);
}

.recent-card__thumb::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06);
    pointer-events: none;
}

.recent-card__thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform .4s var(--ease);
}

.recent-card:hover .recent-card__thumb img {
    transform: scale(1.04);
}

.recent-card__thumb span {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    font-size: 1.75rem;
    background: rgba(0, 0, 0, 0.35);
    color: #fff;
    backdrop-filter: blur(2px);
}

.recent-card__meta {
    padding: .55rem .15rem .2rem;
    font-size: .76rem;
    color: var(--text-subtle);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.recent-card__actions {
    position: absolute;
    top: .45rem;
    right: .45rem;
    z-index: 2;
    display: flex;
    gap: .3rem;
    opacity: 0;
    transition: opacity .2s var(--ease);
}

.recent-card:hover .recent-card__actions,
.recent-card__actions:focus-within {
    opacity: 1;
}

.recent-card__action {
    width: 30px;
    height: 30px;
    border: none;
    border-radius: var(--radius-sm);
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(8px);
    color: #fff;
    font-size: .75rem;
    cursor: pointer;
    transition: background .2s var(--ease), color .2s var(--ease);
}

.recent-card__action:hover {
    background: var(--accent);
    color: #000;
}

/* ── Composer ── */
.composer {
    position: fixed;
    left: 50%;
    transform: translateX(-50%);
    bottom: 0;
    z-index: 30;
    width: min(var(--composer-max), calc(100% - 2.5rem));
    display: flex;
    flex-direction: column;
    padding: 0 0 calc(1.5rem + env(safe-area-inset-bottom, 0px));
    pointer-events: none;
}

.composer--float .composer__drawer {
    margin-bottom: .55rem;
    border-radius: var(--radius-xl);
    background: rgba(10, 10, 10, 0.88);
    border: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: 0 -12px 48px rgba(0, 0, 0, 0.55);
}

.composer > * {
    pointer-events: auto;
}

.composer__prompt-shell {
    order: 2;
    flex-shrink: 0;
}

.composer__drawer {
    order: 1;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    margin-bottom: .65rem;
    padding: .85rem 1rem;
    border-radius: var(--radius-xl);
    background: rgba(12, 12, 12, 0.92);
    backdrop-filter: blur(20px);
    border: 1px solid var(--border);
    box-shadow: 0 -8px 40px rgba(0, 0, 0, 0.5);
}

.composer__drawer-btn {
    display: none;
}

.bottom-nav {
    display: none;
}

@media (min-width: 769px) {
    .composer__drawer {
        display: block;
    }
}

/* Mode tabs */
.modes {
    display: flex;
    justify-content: center;
    gap: .15rem;
    margin-bottom: .7rem;
    padding: .18rem;
    background: rgba(255, 255, 255, 0.04);
    border-radius: var(--radius-pill);
    border: 1px solid rgba(255, 255, 255, 0.06);
}

.modes--grok {
    flex-wrap: wrap;
}

.mode {
    border: none;
    background: transparent;
    color: var(--text-subtle);
    padding: .38rem .82rem;
    border-radius: var(--radius-pill);
    font-size: .76rem;
    font-weight: 500;
    cursor: pointer;
    transition: all .2s var(--ease);
    white-space: nowrap;
}

.mode:hover {
    color: var(--text);
}

.mode--active {
    background: rgba(255, 255, 255, 0.12);
    color: var(--text);
    font-weight: 600;
}

/* Style bar */
.style-bar,
.upload-bar,
.edit-options-bar {
    max-width: 100%;
    margin-inline: auto;
}

.style-bar,
.upload-bar {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: .35rem;
    margin-bottom: .65rem;
}

.style-chip {
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-muted);
    padding: .32rem .75rem;
    border-radius: var(--radius-pill);
    font-size: .76rem;
    font-weight: 500;
    cursor: pointer;
    transition: all .2s var(--ease);
}

.style-chip:hover {
    border-color: var(--border-strong);
    color: var(--text);
}

.style-chip--active {
    background: var(--accent);
    color: #000;
    border-color: var(--accent);
    font-weight: 600;
}

/* Edit options */
.edit-options-bar {
    margin-bottom: .65rem;
    padding: .65rem .85rem .75rem;
    border: 1px solid rgba(251, 146, 60, 0.2);
    border-radius: var(--radius-lg);
    background: rgba(251, 146, 60, 0.05);
    display: flex;
    flex-direction: column;
    gap: .5rem;
}

.edit-options-bar--collapsed {
    padding-bottom: .5rem;
}

.edit-options-bar__toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .5rem;
    width: 100%;
    margin: 0;
    padding: .15rem 0;
    border: none;
    background: transparent;
    color: var(--text);
    font-size: .78rem;
    font-weight: 600;
    cursor: pointer;
}

.edit-options-bar__toggle:hover { color: var(--spicy); }

.edit-options-bar__chevron {
    font-size: .8rem;
    color: var(--text-muted);
    transition: transform .15s;
}

.edit-options-bar__toggle--collapsed .edit-options-bar__chevron {
    transform: rotate(-90deg);
}

.edit-options-bar__body {
    display: flex;
    flex-direction: column;
    gap: .65rem;
}

.edit-options-bar__label {
    margin: 0;
    font-size: .72rem;
    font-weight: 600;
    color: var(--text-muted);
}

.edit-options-bar__hint {
    font-weight: 400;
    opacity: .75;
}

.spicy-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: .35rem;
}

.spicy-suggestion {
    border: 1px solid rgba(251, 146, 60, 0.3);
    background: rgba(251, 146, 60, 0.07);
    color: var(--text-muted);
    padding: .38rem .7rem;
    border-radius: var(--radius-pill);
    font-size: .74rem;
    cursor: pointer;
    transition: all .2s var(--ease);
    text-align: left;
    max-width: 100%;
    line-height: 1.35;
}

.spicy-suggestion:hover {
    border-color: var(--spicy);
    color: var(--text);
    background: rgba(251, 146, 60, 0.14);
}

.spicy-suggestion--active {
    border-color: var(--spicy);
    background: rgba(251, 146, 60, 0.2);
    color: #fff;
}

/* Attachments */
.attachment-bar {
    margin-bottom: .65rem;
    padding: .7rem .85rem;
    border: 1px solid rgba(74, 222, 128, 0.2);
    border-radius: var(--radius-lg);
    background: rgba(74, 222, 128, 0.04);
}

.attachment-bar--refs {
    border-color: var(--border);
    background: var(--surface);
}

.attachment-bar__header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: .75rem;
    margin-bottom: .55rem;
}

.attachment-status {
    font-size: .8rem;
    font-weight: 600;
}

.attachment-hint {
    font-size: .7rem;
    color: var(--text-subtle);
}

.attachment-thumbs {
    display: flex;
    gap: .5rem;
    flex-wrap: wrap;
    align-items: center;
}

.ref-slot {
    position: relative;
    width: 88px;
    height: 88px;
    border-radius: var(--radius-md);
    overflow: hidden;
    flex-shrink: 0;
}

.ref-slot--filled {
    border: 2px solid var(--accent);
    background: #000;
}

.ref-slot--filled img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.ref-slot__badge {
    position: absolute;
    left: .3rem;
    bottom: .3rem;
    padding: .1rem .35rem;
    border-radius: 5px;
    background: rgba(0, 0, 0, 0.75);
    color: #fff;
    font-size: .6rem;
    font-weight: 700;
}

.ref-slot__clear {
    position: absolute;
    top: .25rem;
    right: .25rem;
    width: 20px;
    height: 20px;
    border: none;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.75);
    color: #fff;
    cursor: pointer;
    font-size: .7rem;
    line-height: 1;
}

.ref-slot--empty {
    border: 1px dashed var(--border);
    background: var(--surface);
    cursor: pointer;
    display: grid;
    place-items: center;
    transition: border-color .2s;
}

.ref-slot--empty:hover {
    border-color: var(--border-strong);
}

.ref-slot__add {
    font-size: 1.4rem;
    color: var(--text-subtle);
}

.attachment-thumb {
    position: relative;
    width: 60px;
    height: 60px;
    border-radius: var(--radius-sm);
    overflow: hidden;
    border: 1px solid var(--border);
}

.attachment-thumb img,
.attachment-thumb video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.attachment-thumb__label {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    font-size: .58rem;
    text-align: center;
    background: rgba(0, 0, 0, 0.75);
    padding: .1rem;
}

.upload-slots {
    display: flex;
    gap: .45rem;
    justify-content: center;
}

.upload-slot {
    width: 68px;
    height: 68px;
    border: 1px dashed var(--border);
    border-radius: var(--radius-md);
    display: grid;
    place-items: center;
    cursor: pointer;
    overflow: hidden;
    position: relative;
}

.upload-slot img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.upload-slot__clear {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 18px;
    height: 18px;
    border: none;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.75);
    color: #fff;
    cursor: pointer;
    font-size: .65rem;
}

.upload-hint {
    width: 100%;
    text-align: center;
    font-size: .72rem;
    color: var(--text-subtle);
    margin: .35rem 0 0;
}

/* Prompt row */
.prompt-row {
    display: flex;
    align-items: flex-end;
    gap: .35rem;
    padding: .5rem .55rem .5rem .7rem;
    background: rgba(12, 12, 12, 0.92);
    backdrop-filter: blur(28px) saturate(1.2);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-pill);
    box-shadow:
        0 12px 48px rgba(0, 0, 0, 0.65),
        0 0 0 1px rgba(255, 255, 255, 0.04),
        inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.prompt-row--grok {
    min-height: 52px;
}

#prompt {
    flex: 1;
    border: none;
    background: transparent;
    resize: none;
    padding: .5rem 0;
    max-height: 120px;
    font-size: .95rem;
    line-height: 1.45;
    min-width: 0;
}

#prompt::placeholder {
    color: var(--text-subtle);
}

/* Spicy toggle */
.spicy-toggle {
    display: flex;
    align-items: center;
    gap: .3rem;
    padding: .38rem .65rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    background: var(--surface);
    cursor: pointer;
    flex-shrink: 0;
    transition: all .2s var(--ease);
}

.spicy-toggle--on {
    border-color: var(--spicy);
    background: rgba(251, 146, 60, 0.12);
    box-shadow: 0 0 16px rgba(251, 146, 60, 0.2);
}

.spicy-toggle__icon { font-size: .9rem; }

.spicy-toggle__label {
    font-size: .76rem;
    font-weight: 600;
}

.spicy-toggle--on .spicy-toggle__label { color: var(--spicy); }

/* Settings */
.settings-panel {
    margin-top: .65rem;
    padding: .85rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
}

.settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: .65rem;
}

.setting {
    display: flex;
    flex-direction: column;
    gap: .3rem;
}

.setting span {
    font-size: .7rem;
    font-weight: 500;
    color: var(--text-subtle);
    text-transform: uppercase;
    letter-spacing: .04em;
}

.setting select,
.setting input {
    border: 1px solid var(--border);
    background: var(--bg-elevated);
    border-radius: var(--radius-sm);
    padding: .5rem .65rem;
    font-size: .84rem;
}

.setting select:focus,
.setting input:focus {
    outline: none;
    border-color: var(--border-strong);
}

.setting--aspect {
    grid-column: 1 / -1;
}

.aspect-picker__native {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.aspect-picker {
    display: flex;
    flex-wrap: wrap;
    gap: .4rem;
}

.aspect-option {
    flex: 1 1 calc(16.666% - .35rem);
    min-width: 58px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .35rem;
    padding: .5rem .35rem .45rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--bg-elevated);
    color: var(--text-muted);
    cursor: pointer;
    transition: border-color .2s var(--ease), background .2s var(--ease), color .2s var(--ease), transform .15s var(--ease);
}

.aspect-option:hover {
    border-color: var(--border-strong);
    color: var(--text);
}

.aspect-option--active {
    border-color: rgba(255, 255, 255, 0.28);
    background: rgba(255, 255, 255, 0.1);
    color: var(--text);
}

.aspect-option[hidden] {
    display: none;
}

.aspect-option__preview {
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
}

.aspect-shape {
    display: block;
    border: 1.5px solid currentColor;
    border-radius: 3px;
    opacity: .82;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.04);
}

.aspect-option--active .aspect-shape {
    opacity: 1;
    border-color: #fff;
}

.aspect-shape--auto {
    width: 22px;
    height: 22px;
    border-style: dashed;
    border-radius: 5px;
    opacity: .55;
}

.aspect-shape--1-1 {
    width: 22px;
    height: 22px;
}

.aspect-shape--16-9 {
    width: 30px;
    height: 17px;
}

.aspect-shape--9-16 {
    width: 17px;
    height: 30px;
}

.aspect-shape--4-3 {
    width: 26px;
    height: 20px;
}

.aspect-shape--3-4 {
    width: 20px;
    height: 26px;
}

.aspect-option__label {
    font-size: .68rem;
    font-weight: 600;
    letter-spacing: .01em;
}