:root {
    --bg: var(--surface-ground);
    --panel: var(--surface-panel-strong);
    --line: var(--gray-2);
    --ink: var(--text-1);
    --muted: var(--text-2);
    --brand: var(--indigo-6);
    --brand-2: var(--indigo-2);
    --user: var(--indigo-6);
    --user-ink: #ffffff;
    --assistant: var(--surface-panel-strong);
    --tool: var(--gray-0);
    --tool-line: #dbe3f1;
    --code: var(--gray-8);
    --code-ink: #e5e7eb;
    --danger: var(--danger-1);
    --danger-bg: var(--danger-soft);
    --ok: var(--ok-1);
    --ok-bg: var(--ok-soft);
    --shadow: var(--shadow-2);
    --radius: var(--radius-3);
    --composer-clearance: 8rem;
}

* {
    box-sizing: border-box;
}

html,
body {
    height: 100%;
}

body {
    margin: 0;
    font-family: var(--app-font-family);
    font-size: 16px;
    line-height: 1.45;
    font-variation-settings: var(--app-font-body-settings);
    color: var(--ink);
    background: var(--bg);
}

a {
    color: var(--brand);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

button,
input,
select,
textarea {
    font: inherit;
}

.app {
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
}

.shell,
.composer-inner {
    width: min(100%, 880px);
    margin: 0 auto;
    padding-left: 1rem;
    padding-right: 1rem;
}

.shell {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    padding-top: 1rem;
    padding-bottom: calc(var(--composer-clearance) + 1rem);
}

.chip-btn,
.send-btn,
.upload-btn,
.secondary-btn,
.suggestion-btn {
    border: 1px solid var(--line);
    background: #fff;
    color: var(--ink);
    border-radius: var(--radius-round);
    padding: 0.58rem 0.9rem;
    cursor: pointer;
    text-decoration: none;
    font-weight: 600;
    box-shadow: none;
}

.chip-btn,
.secondary-btn {
    font-size: 0.92rem;
}

.chip-btn:hover,
.secondary-btn:hover,
.suggestion-btn:hover,
.upload-btn:hover {
    text-decoration: none;
    border-color: #c7d2fe;
    background: #fff;
}

.banner {
    display: none;
    border-radius: var(--radius-3);
    padding: 0.85rem 1rem;
    border: 1px solid transparent;
    background: #fff;
    box-shadow: var(--shadow);
}

.banner.show {
    display: block;
}

.banner.error {
    color: var(--danger);
    background: var(--danger-bg);
    border-color: #fecaca;
}

.banner.ok {
    color: var(--ok);
    background: var(--ok-bg);
    border-color: #bbf7d0;
}

.panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1rem;
}

.panel h1,
.panel h2,
.panel p {
    margin: 0;
}

.panel-stack {
    display: grid;
    gap: 1rem;
}

.signed-out-copy {
    margin-top: 0.55rem !important;
    color: var(--muted);
}

.meta-card {
    display: grid;
    gap: 0.85rem;
}

.site-title {
    font-size: clamp(1.85rem, 4vw, 2.8rem);
    line-height: 0.98;
    letter-spacing: -0.05em;
    font-variation-settings: var(--app-font-heading-settings);
    overflow-wrap: anywhere;
}

.meta-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.meta-actions {
    display: flex;
    gap: 0.55rem;
    align-items: flex-end;
    flex-wrap: nowrap;
    width: 100%;
}

.meta-model {
    flex: 1 1 18rem;
    min-width: 0;
}

.meta-actions .select-input,
.meta-actions .secondary-btn {
    height: 3rem;
}

.meta-actions .secondary-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
}

.meta-actions .select-input {
    min-width: 0;
}

.field-label {
    display: block;
    font-size: 0.84rem;
    color: #374151;
    margin-bottom: 0.35rem;
    font-weight: 600;
}

.select-input,
.text-input {
    width: 100%;
    border: 1px solid var(--line);
    background: #fff;
    color: var(--ink);
    border-radius: 12px;
    padding: 0.75rem 0.85rem;
}

.chat-card {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    min-height: 48vh;
}

.session-activity {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.session-activity .tool-activity {
    width: min(100%, 32rem);
}

.welcome {
    display: grid;
    gap: 1rem;
    justify-items: start;
}

.welcome h1 {
    font-family: var(--app-font-family);
    font-size: 1.6rem;
    line-height: 1.1;
    font-variation-settings: var(--app-font-heading-settings);
    letter-spacing: -0.03em;
}

.welcome p {
    color: var(--muted);
    max-width: 40rem;
}

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

.suggestion-btn {
    font-weight: 500;
    padding: 0.65rem 0.95rem;
}

.messages {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    min-height: 16rem;
}

.message {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    scroll-margin-bottom: calc(var(--composer-clearance) + 0.75rem);
}

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

.message.assistant,
.message.system {
    align-items: flex-start;
}

.message-bubble {
    max-width: min(100%, 46rem);
    border-radius: 18px;
    padding: 0.9rem 1rem;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    box-shadow: var(--shadow);
    line-height: 1.55;
}

.message.user .message-bubble {
    background: var(--user);
    color: var(--user-ink);
    border-bottom-right-radius: 6px;
}

.message.assistant .message-bubble,
.message.system .message-bubble {
    background: var(--assistant);
    border: 1px solid var(--line);
    border-bottom-left-radius: 6px;
}

.message.assistant .message-bubble p,
.message.system .message-bubble p {
    margin: 0 0 0.65rem;
}

.message.assistant .message-bubble p:last-child,
.message.system .message-bubble p:last-child {
    margin-bottom: 0;
}

.message.assistant .message-bubble strong,
.message.system .message-bubble strong {
    font-weight: 700;
}

.message.assistant .message-bubble em,
.message.system .message-bubble em {
    font-style: italic;
}

.message.assistant .message-bubble h1,
.message.assistant .message-bubble h2,
.message.assistant .message-bubble h3,
.message.system .message-bubble h1,
.message.system .message-bubble h2,
.message.system .message-bubble h3 {
    margin: 0.2rem 0 0.55rem;
    line-height: 1.2;
}

.message.assistant .message-bubble h1,
.message.system .message-bubble h1 {
    font-size: 1.22rem;
}

.message.assistant .message-bubble h2,
.message.system .message-bubble h2 {
    font-size: 1.08rem;
}

.message.assistant .message-bubble h3,
.message.system .message-bubble h3 {
    font-size: 1rem;
}

.message.assistant .message-bubble ul,
.message.assistant .message-bubble ol,
.message.system .message-bubble ul,
.message.system .message-bubble ol {
    margin: 0.25rem 0 0.6rem 1.25rem;
}

.message.assistant .message-bubble li,
.message.system .message-bubble li {
    margin: 0.2rem 0;
}

.message.assistant .message-bubble code,
.message.system .message-bubble code {
    background: var(--code);
    color: var(--code-ink);
    border-radius: 6px;
    padding: 0.12rem 0.4rem;
    font-size: 0.9em;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.message.assistant .message-bubble pre,
.message.system .message-bubble pre {
    background: var(--code);
    color: var(--code-ink);
    border-radius: 12px;
    padding: 0.8rem 0.95rem;
    overflow: auto;
    margin: 0.55rem 0;
    font-size: 0.88em;
    line-height: 1.45;
}

.message.assistant .message-bubble pre code,
.message.system .message-bubble pre code {
    background: none;
    padding: 0;
    color: inherit;
}

.tool-activity {
    width: min(100%, 46rem);
    background: var(--tool);
    border: 1px solid var(--tool-line);
    border-radius: 14px;
    padding: 0.7rem 0.9rem;
    box-shadow: none;
    scroll-margin-bottom: calc(var(--composer-clearance) + 0.75rem);
}

.tool-activity.pending {
    opacity: 0.88;
}

.tool-activity summary {
    cursor: pointer;
    font: 600 0.9rem/1.35 system-ui, -apple-system, sans-serif;
    color: #334155;
    user-select: none;
}

.tool-summary-inline {
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
    vertical-align: middle;
}

.tool-summary-thumb {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    border: 1px solid var(--tool-line);
    object-fit: cover;
    background: #fff;
    flex: 0 0 auto;
}

.tool-activity pre {
    margin: 0.7rem 0 0;
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 14rem;
    overflow: auto;
    font: 0.82rem/1.45 ui-monospace, SFMono-Regular, Menlo, monospace;
    color: #475569;
}

.tool-image-preview {
    margin-top: 0.75rem;
    display: grid;
    grid-template-columns: 84px 1fr;
    gap: 0.7rem;
    align-items: center;
}

.tool-image-preview a {
    width: 84px;
    height: 84px;
    display: inline-flex;
    overflow: hidden;
    border-radius: 10px;
    border: 1px solid var(--tool-line);
    background: #fff;
}

.tool-image-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.tool-image-meta {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    color: #64748b;
    font-size: 0.78rem;
    overflow-wrap: anywhere;
}

.thinking {
    width: min(100%, 46rem);
    display: flex;
    align-items: center;
    gap: 0.55rem;
    color: var(--muted);
    padding: 0.25rem 0.1rem;
    font-size: 0.93rem;
    scroll-margin-bottom: calc(var(--composer-clearance) + 0.75rem);
}

.dots span {
    display: inline-block;
    font-size: 1.25rem;
    line-height: 1;
    animation: blink 1.3s infinite both;
}

.dots span:nth-child(2) {
    animation-delay: 0.18s;
}

.dots span:nth-child(3) {
    animation-delay: 0.36s;
}

@keyframes blink {
    0%,
    80%,
    100% {
        opacity: 0.2;
        transform: translateY(0);
    }

    40% {
        opacity: 1;
        transform: translateY(-1px);
    }
}

.composer {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 25;
    background: linear-gradient(to top, rgba(243, 244, 246, 0.98), rgba(243, 244, 246, 0.92));
    backdrop-filter: blur(10px);
    border-top: 1px solid rgba(229, 231, 235, 0.9);
    padding: 0.75rem 0 max(0.75rem, env(safe-area-inset-bottom));
}

.composer-box {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 18px;
    box-shadow: var(--shadow);
    padding: 0.7rem;
    display: grid;
    gap: 0.65rem;
}

.composer-row {
    display: flex;
    gap: 0.65rem;
    align-items: flex-end;
}

.composer-actions {
    display: flex;
    gap: 0.55rem;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
}

.composer-note {
    color: var(--muted);
    font-size: 0.82rem;
}

.prompt-input {
    flex: 1;
    min-height: 2.9rem;
    max-height: 11rem;
    resize: none;
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 0.8rem 0.9rem;
    outline: none;
    background: #fff;
    color: var(--ink);
}

.prompt-input:focus,
.select-input:focus,
.text-input:focus {
    border-color: #a5b4fc;
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12);
}

.upload-btn,
.send-btn,
.secondary-btn {
    border-radius: 14px;
    padding: 0.82rem 1rem;
    font-weight: 700;
}

.upload-btn,
.secondary-btn {
    background: #fff;
}

.send-btn {
    border: 0;
    background: var(--brand);
    color: #fff;
    min-width: 5.6rem;
}

.send-btn.stop {
    background: #111827;
}

.upload-btn:disabled,
.send-btn:disabled,
.secondary-btn:disabled,
.chip-btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.toast {
    position: fixed;
    left: 50%;
    bottom: calc(6rem + env(safe-area-inset-bottom));
    transform: translate(-50%, 16px);
    background: #111827;
    color: #fff;
    padding: 0.6rem 0.95rem;
    border-radius: 999px;
    box-shadow: 0 16px 32px rgba(0, 0, 0, 0.24);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.18s ease, transform 0.18s ease;
    z-index: 40;
    font-size: 0.9rem;
    text-align: center;
    max-width: min(90vw, 32rem);
}

.toast.show {
    opacity: 1;
    transform: translate(-50%, 0);
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background: rgba(17, 24, 39, 0.52);
    backdrop-filter: blur(4px);
}

.modal-dialog {
    width: min(100%, 34rem);
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 20px;
    box-shadow: 0 24px 80px rgba(15, 23, 42, 0.22);
    padding: 1rem;
    display: grid;
    gap: 0.85rem;
}

.modal-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
}

.modal-title {
    margin: 0;
    font-family: var(--app-font-family);
    font-size: 1.15rem;
    line-height: 1.2;
    font-variation-settings: var(--app-font-heading-settings);
    letter-spacing: -0.02em;
}

.modal-copy {
    color: var(--muted);
    font-size: 0.92rem;
}

.modal-textarea {
    width: 100%;
    min-height: 10rem;
    resize: vertical;
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 0.85rem 0.95rem;
    outline: none;
    background: #fff;
    color: var(--ink);
}

.modal-textarea:focus {
    border-color: #a5b4fc;
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12);
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.65rem;
    flex-wrap: wrap;
}

.hidden {
    display: none !important;
}

@media (max-width: 720px) {
    .shell,
    .composer-inner {
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }

    .welcome h1 {
        font-size: 1.35rem;
    }

    .composer-row {
        flex-direction: column;
        align-items: stretch;
    }

    .send-btn,
    .upload-btn,
    .secondary-btn {
        width: 100%;
    }

    .tool-image-preview {
        grid-template-columns: 72px 1fr;
    }

    .tool-image-preview a {
        width: 72px;
        height: 72px;
    }

    .meta-actions {
        width: 100%;
        justify-content: flex-start;
        flex-wrap: wrap;
    }

    .meta-model {
        width: 100%;
        flex-basis: 100%;
    }

    .meta-actions .secondary-btn,
    .meta-actions .select-input {
        width: 100%;
    }

    .meta-actions .select-input {
        text-align: center;
        text-align-last: center;
    }
}
