:root {
    --bg: #12151a;
    --panel: #1a1f27;
    --panel-2: #222833;
    --border: rgba(255, 255, 255, 0.08);
    --text: #eef1f6;
    --muted: #9aa3b2;
    --accent: #d36142;
    --accent-strong: #b84c30;
    --danger: #ff6b6b;
    --assistant: #243041;
    --user: #1e3a36;
    --radius: 14px;
    --font: "Instrument Sans", sans-serif;
    --mono: "IBM Plex Mono", monospace;
    --top-bar-height: 88px;
    --avatar-size: 96px;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    height: 100%;
    font-family: var(--font);
    color: var(--text);
    background:
        radial-gradient(1200px 600px at 0% 0%, rgba(61, 214, 198, 0.12), transparent 55%),
        radial-gradient(900px 500px at 100% 100%, rgba(80, 120, 255, 0.1), transparent 50%),
        var(--bg);
}

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

.app {
    position: relative;
    display: grid;
    grid-template-columns: minmax(320px, 420px) 1fr;
    height: 100vh;
    gap: 0;
}

.credits-badge {
    position: absolute;
    top: calc(var(--top-bar-height) / 2);
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 30;
    display: inline-flex;
    align-items: baseline;
    gap: 0.4rem;
    padding: 0.45rem 0.85rem;
    border-radius: 999px;
    background: rgba(18, 21, 26, 0.88);
    border: 1px solid rgba(245, 213, 71, 0.35);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
    color: #f5d547;
    font-family: var(--mono);
    font-weight: 500;
    font-size: 0.95rem;
    letter-spacing: 0.02em;
    pointer-events: none;
    white-space: nowrap;
}

.credits-label {
    color: rgba(245, 213, 71, 0.75);
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.account-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    margin-top: 0.85rem;
}

.account-label {
    color: var(--muted);
    font-size: 0.8rem;
    margin-right: 0.15rem;
}

.project-bar {
    display: flex;
    gap: 0.45rem;
    width: 100%;
    margin-top: 0.75rem;
}

.project-select {
    flex: 1;
    min-width: 0;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #151a22;
    color: var(--text);
    padding: 0.45rem 0.65rem;
    font: inherit;
    font-size: 0.85rem;
}

.asset-tray {
    display: flex;
    gap: 0.45rem;
    overflow-x: auto;
    padding: 0.65rem 1.25rem;
    border-top: 1px solid var(--border);
    background: rgba(0, 0, 0, 0.15);
}

.asset-tray[hidden] {
    display: none !important;
}

.asset-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    border: 1px solid var(--border);
    background: #151a22;
    color: var(--text);
    border-radius: 999px;
    padding: 0.25rem 0.65rem 0.25rem 0.25rem;
    font: inherit;
    font-size: 0.75rem;
    cursor: pointer;
    white-space: nowrap;
}

.asset-chip img {
    width: 28px;
    height: 28px;
    object-fit: cover;
    border-radius: 50%;
    background: #000;
}

.composer-left {
    display: flex;
    gap: 0.45rem;
}

.chat-panel,
.preview-panel {
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.chat-panel {
    border-right: 1px solid var(--border);
    background: color-mix(in srgb, var(--panel) 92%, transparent);
    backdrop-filter: blur(10px);
}

.chat-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0 1.25rem 1.15rem;
    border-bottom: 1px solid var(--border);
    text-align: center;
}

.chat-avatar {
    display: flex;
    align-items: flex-end;
    justify-content: center;
    width: calc(100% + 2.5rem);
    height: var(--top-bar-height);
    margin: 0 -1.25rem calc(var(--avatar-size) / 2 + 0.75rem);
    border-bottom: 1px solid var(--border);
    box-sizing: border-box;
}

.chat-logo {
    position: relative;
    z-index: 1;
    display: block;
    width: var(--avatar-size);
    height: var(--avatar-size);
    margin-bottom: calc(var(--avatar-size) / -2);
    object-fit: cover;
    background: var(--panel);
    border-radius: 50%;
    box-shadow: 0 0 0 4px var(--panel);
}

.chat-title {
    margin: 0;
    font-size: 1.2rem;
    font-weight: 700;
    letter-spacing: -0.03em;
}

.chat-tagline {
    margin: 0.45rem 0 0;
    max-width: 34ch;
    color: var(--muted);
    font-size: 0.88rem;
    line-height: 1.45;
}

.preview-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    height: var(--top-bar-height);
    padding: 0 1.25rem;
    border-bottom: 1px solid var(--border);
    box-sizing: border-box;
}

.messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
}

.message {
    display: flex;
    max-width: 95%;
}

.message.user {
    align-self: flex-end;
}

.message.assistant {
    align-self: flex-start;
}

.bubble {
    padding: 0.8rem 0.95rem;
    border-radius: 12px;
    line-height: 1.45;
    font-size: 0.95rem;
    white-space: pre-wrap;
    word-break: break-word;
}

.message.assistant .bubble {
    background: var(--assistant);
    border: 1px solid var(--border);
}

.message.user .bubble {
    background: var(--user);
    border: 1px solid rgba(61, 214, 198, 0.25);
}

.message.error .bubble {
    background: rgba(255, 107, 107, 0.12);
    border: 1px solid rgba(255, 107, 107, 0.35);
    color: #ffc9c9;
}

.composer {
    padding: 1rem 1.25rem 1.25rem;
    border-top: 1px solid var(--border);
    background: var(--panel-2);
}

.composer textarea {
    width: 100%;
    resize: none;
    min-height: 84px;
    max-height: 220px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #151a22;
    color: var(--text);
    padding: 0.85rem 0.95rem;
    font: inherit;
    line-height: 1.4;
}

.composer textarea:focus {
    outline: 2px solid rgba(61, 214, 198, 0.35);
    outline-offset: 1px;
    border-color: rgba(61, 214, 198, 0.45);
}

.composer-actions {
    display: flex;
    justify-content: space-between;
    gap: 0.75rem;
    margin-top: 0.75rem;
}

.btn {
    appearance: none;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text);
    border-radius: 10px;
    padding: 0.65rem 1rem;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.btn.small {
    padding: 0.4rem 0.7rem;
    font-size: 0.8rem;
    font-weight: 500;
}

.btn.ghost:hover {
    background: rgba(255, 255, 255, 0.04);
}

.btn.primary {
    background: linear-gradient(180deg, var(--accent), var(--accent-strong));
    color: #fff;
    border-color: transparent;
}

.btn.primary:hover {
    filter: brightness(1.06);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-spinner {
    width: 1rem;
    height: 1rem;
    border: 2px solid rgba(255, 255, 255, 0.35);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.preview-panel {
    background: #0e1116;
}

.preview-label {
    font-family: var(--mono);
    font-size: 0.75rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
}

.preview-actions {
    display: flex;
    gap: 0.5rem;
}

.preview-frame-wrap {
    position: relative;
    flex: 1;
    min-height: 0;
    background: #0c0f14;
}

#preview {
    width: 100%;
    height: 100%;
    border: 0;
    background: #fff;
    display: none;
}

#preview.has-content {
    display: block;
}

.preview-empty {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    color: var(--muted);
    pointer-events: none;
    padding: 2rem;
    text-align: center;
}

.preview-empty[hidden] {
    display: none;
}

.btn.full {
    width: 100%;
}

.modal[hidden] {
    display: none;
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: grid;
    place-items: center;
    padding: 1.25rem;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(6, 8, 12, 0.72);
    backdrop-filter: blur(4px);
}

.modal-card {
    position: relative;
    z-index: 1;
    width: min(420px, 100%);
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 1.4rem 1.35rem 1.25rem;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
}

.modal-close {
    position: absolute;
    top: 0.65rem;
    right: 0.75rem;
    border: 0;
    background: transparent;
    color: var(--muted);
    font-size: 1.4rem;
    line-height: 1;
    cursor: pointer;
}

.modal-card h2 {
    margin: 0 0 0.45rem;
    font-size: 1.2rem;
    letter-spacing: -0.02em;
}

.modal-copy {
    margin: 0 0 1rem;
    color: var(--muted);
    font-size: 0.92rem;
    line-height: 1.45;
}

.modal-note {
    margin: 0.85rem 0 0;
    color: var(--muted);
    font-size: 0.78rem;
    line-height: 1.4;
}

.tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.35rem;
    margin-bottom: 1rem;
    padding: 0.25rem;
    border-radius: 10px;
    background: rgba(0, 0, 0, 0.22);
}

.tab {
    border: 0;
    background: transparent;
    color: var(--muted);
    border-radius: 8px;
    padding: 0.55rem 0.7rem;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}

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

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.auth-form[hidden] {
    display: none !important;
}

.auth-form label {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    font-size: 0.82rem;
    color: var(--muted);
}

.field-hint {
    font-size: 0.75rem;
    color: var(--muted);
}

.field-hint code {
    color: #f5d547;
    font-family: var(--mono);
    font-size: 0.74rem;
}

.auth-form input {
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #151a22;
    color: var(--text);
    padding: 0.7rem 0.8rem;
    font: inherit;
}

.auth-form input:focus {
    outline: 2px solid rgba(211, 97, 66, 0.35);
    border-color: rgba(211, 97, 66, 0.45);
}

.form-error {
    margin: 0.75rem 0 0;
    color: #ffc9c9;
    font-size: 0.85rem;
}

.btn.ghost.full {
    margin-top: 0.5rem;
}

@media (max-width: 900px) {
    .app {
        grid-template-columns: 1fr;
        grid-template-rows: 55vh 45vh;
        height: 100dvh;
    }

    .chat-panel {
        border-right: 0;
        border-bottom: 1px solid var(--border);
    }

    .credits-badge {
        top: 0.75rem;
        transform: translateX(-50%);
    }
}
