:root {
    --bg-deep: #07070c;
    --bg-base: #0b0b12;
    --surface: rgba(255, 255, 255, 0.055);
    --surface-strong: rgba(255, 255, 255, 0.09);
    --foreground: #edeeff;
    --muted: #9aa0b8;
    --primary: #7c3aed;
    --primary-2: #a78bfa;
    --accent: #0891b2;
    --success: #34d399;
    --danger: #f87171;
    --border: rgba(255, 255, 255, 0.1);
    --glass: rgba(12, 12, 20, 0.55);
    --shadow: 0 30px 80px rgba(0, 0, 0, 0.45);
    --radius: 20px;
    --easing: cubic-bezier(0.16, 1, 0.3, 1);
    --space: 16px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    min-height: 100%;
    color-scheme: dark;
}

body {
    min-height: 100dvh;
    font-family: Inter, system-ui, sans-serif;
    color: var(--foreground);
    background:
        linear-gradient(180deg, #101018 0%, var(--bg-deep) 100%);
    overflow: hidden;
}

.atmosphere {
    position: fixed;
    inset: 0;
    pointer-events: none;
    overflow: hidden;
}

.blob {
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0.34;
    will-change: transform;
    animation: drift 18s var(--easing) infinite alternate;
}

.blob-a {
    width: 42vw;
    height: 42vw;
    background: #5b21b6;
    top: -12%;
    left: -8%;
}

.blob-b {
    width: 36vw;
    height: 36vw;
    background: #0e7490;
    right: -10%;
    top: 18%;
    animation-duration: 22s;
}

.blob-c {
    width: 30vw;
    height: 30vw;
    background: #7c3aed;
    left: 30%;
    bottom: -16%;
    animation-duration: 26s;
}

.grain {
    position: absolute;
    inset: 0;
    opacity: 0.07;
    background-image: radial-gradient(rgba(255,255,255,.35) 0.6px, transparent 0.6px);
    background-size: 3px 3px;
}

@keyframes drift {
    from { transform: translate3d(0, 0, 0) scale(1); }
    to { transform: translate3d(4%, 6%, 0) scale(1.08); }
}

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

.glass {
    background: var(--glass);
    border: 1px solid var(--border);
    backdrop-filter: blur(22px) saturate(140%);
    -webkit-backdrop-filter: blur(22px) saturate(140%);
    box-shadow: var(--shadow);
}

.glass-inset {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
}

.app {
    position: relative;
    z-index: 1;
    display: grid;
    grid-template-columns: 280px minmax(0, 1fr);
    width: min(1280px, calc(100vw - 32px));
    height: min(860px, calc(100dvh - 32px));
    margin: 16px auto;
    gap: 14px;
}

.rail, .stage {
    border-radius: 24px;
    min-height: 0;
}

.rail {
    display: flex;
    flex-direction: column;
    padding: 22px 18px;
}

.brand, .mobile-brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand strong, .mobile-brand strong {
    display: block;
    font-size: 16px;
    letter-spacing: -0.02em;
}

.brand span, .mobile-brand small, .rail-foot, .chip, .hint, .message-meta {
    color: var(--muted);
}

.brand span, .mobile-brand small {
    font-size: 12px;
}

.mark {
    width: 42px;
    height: 42px;
    border-radius: 14px;
    display: grid;
    place-items: center;
    color: white;
    background: linear-gradient(145deg, var(--primary), #4f46e5 55%, var(--accent));
    box-shadow: 0 10px 28px rgba(124, 58, 237, 0.35);
}

.mark.sm { width: 36px; height: 36px; border-radius: 12px; }
.mark svg, .welcome-mark svg, .btn-primary svg, .icon-btn svg, .send svg, .copy-btn svg {
    width: 18px;
    height: 18px;
}

.btn-primary {
    margin-top: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    min-height: 48px;
    border: 0;
    border-radius: 14px;
    color: #fff;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    background: linear-gradient(135deg, var(--primary), #6366f1);
    box-shadow: 0 12px 28px rgba(124, 58, 237, 0.28);
    transition: transform 180ms var(--easing), filter 180ms var(--easing);
}

.btn-primary:hover { filter: brightness(1.08); transform: translateY(-1px); }
.btn-primary:active { transform: scale(0.98); }
.btn-primary:focus-visible, .icon-btn:focus-visible, .send:focus-visible, .suggestions button:focus-visible, .prompt-nav button:focus-visible, .copy-btn:focus-visible {
    outline: 2px solid var(--primary-2);
    outline-offset: 2px;
}

.status-card {
    margin-top: 16px;
    padding: 12px;
    border-radius: 16px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.pulse, .live-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--success);
    box-shadow: 0 0 12px var(--success);
}

.pulse.offline, .live-dot.offline {
    background: #fbbf24;
    box-shadow: 0 0 12px #fbbf24;
}

.status-card strong { display: block; font-size: 13px; }
.status-card small {
    display: block;
    margin-top: 3px;
    color: var(--muted);
    font-size: 11px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 190px;
}

.prompt-nav {
    margin-top: 28px;
    display: grid;
    gap: 8px;
}

.prompt-nav p {
    margin: 0 0 4px;
    font-size: 11px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
}

.prompt-nav button, .suggestions button {
    text-align: left;
    color: #dfe3f5;
    background: rgba(255,255,255,0.03);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px 12px;
    font: inherit;
    font-size: 13px;
    cursor: pointer;
    transition: background 180ms var(--easing), border-color 180ms var(--easing);
}

.prompt-nav button:hover, .suggestions button:hover {
    background: rgba(124, 58, 237, 0.16);
    border-color: rgba(167, 139, 250, 0.4);
}

.tool-row {
    margin-top: auto;
    display: grid;
    gap: 8px;
    padding-bottom: 14px;
}

.ghost-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    padding: 8px 12px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: rgba(255,255,255,0.04);
    color: #dfe3f5;
    font: inherit;
    font-size: 13px;
    text-decoration: none;
    cursor: pointer;
    transition: background 180ms var(--easing), border-color 180ms var(--easing);
}

.ghost-btn:hover {
    background: rgba(124, 58, 237, 0.16);
    border-color: rgba(167, 139, 250, 0.4);
}

.rail-foot {
    display: grid;
    gap: 2px;
    font-size: 11px;
    line-height: 1.6;
}

.composer-meta {
    max-width: 760px;
    margin: 8px auto 0;
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: center;
}

.char-count {
    color: var(--muted);
    font-size: 12px;
    white-space: nowrap;
}

.icon-btn[hidden] { display: none; }

.stage {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.topbar {
    min-height: 72px;
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.mobile-brand { display: none; }

.session {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    font-weight: 500;
}

.top-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }

.chip {
    max-width: 280px;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 999px;
    font-size: 11px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    background: rgba(255,255,255,0.03);
}

.icon-btn, .send, .copy-btn {
    cursor: pointer;
}

.icon-btn {
    width: 44px;
    height: 44px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: rgba(255,255,255,0.04);
    color: var(--muted);
    display: grid;
    place-items: center;
    transition: color 160ms var(--easing), background 160ms var(--easing);
}

.icon-btn:hover { color: white; background: rgba(255,255,255,0.09); }

.banner {
    margin: 12px 20px 0;
    padding: 10px 12px;
    border-radius: 12px;
    border: 1px solid rgba(251, 191, 36, 0.28);
    background: rgba(251, 191, 36, 0.08);
    color: #fde68a;
    font-size: 13px;
}

.banner code {
    font-size: 12px;
    color: #fff;
}

.thread {
    flex: 1;
    overflow-y: auto;
    padding: 28px clamp(16px, 5vw, 72px);
    scroll-behavior: smooth;
}

.thread::-webkit-scrollbar { width: 8px; }
.thread::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.14);
    border-radius: 20px;
}

.welcome {
    min-height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    text-align: center;
}

.welcome-mark {
    width: 64px;
    height: 64px;
    display: grid;
    place-items: center;
    border-radius: 20px;
    color: white;
    background: linear-gradient(145deg, var(--primary), var(--accent));
    box-shadow: 0 16px 40px rgba(124, 58, 237, 0.32);
    margin-bottom: 20px;
}

.welcome-mark svg { width: 28px; height: 28px; }

.welcome h1 {
    margin: 0;
    font-size: clamp(24px, 3.4vw, 36px);
    letter-spacing: -0.03em;
    font-weight: 600;
}

.welcome p {
    max-width: 520px;
    margin: 12px 0 24px;
    color: var(--muted);
    line-height: 1.65;
}

.suggestions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: center;
}

.suggestions button { border-radius: 999px; }

.message {
    display: flex;
    gap: 12px;
    margin: 0 auto 22px;
    max-width: 760px;
    animation: rise 220ms var(--easing);
}

@keyframes rise {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: none; }
}

.avatar {
    flex: 0 0 34px;
    height: 34px;
    border-radius: 11px;
    display: grid;
    place-items: center;
    font-size: 12px;
    font-weight: 700;
}

.user .avatar { background: linear-gradient(135deg, var(--accent), #2563eb); }
.assistant .avatar { background: linear-gradient(135deg, var(--primary), #6366f1); }
.bubble-wrap { min-width: 0; flex: 1; }
.message-meta { font-size: 11px; margin: 2px 0 6px; }

.bubble {
    line-height: 1.65;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    color: #eceefc;
}

.user .bubble {
    display: inline-block;
    padding: 12px 14px;
    border: 1px solid rgba(124, 58, 237, 0.28);
    border-radius: 16px 16px 6px 16px;
    background: rgba(124, 58, 237, 0.16);
}

.bubble.error {
    color: #fecaca;
    border: 1px solid rgba(248, 113, 113, 0.28);
    background: rgba(248, 113, 113, 0.08);
    border-radius: 14px;
    padding: 12px 14px;
}

.bubble code {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.9em;
    background: rgba(255,255,255,0.08);
    padding: 0.1em 0.35em;
    border-radius: 6px;
}

.bubble pre {
    margin: 10px 0 0;
    padding: 12px;
    overflow-x: auto;
    border-radius: 12px;
    background: rgba(0,0,0,0.28);
    border: 1px solid var(--border);
}

.bubble pre code {
    background: none;
    padding: 0;
}

.copy-btn {
    margin-top: 8px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 32px;
    border: 0;
    background: transparent;
    color: #8b90a8;
    font: inherit;
    font-size: 12px;
    padding: 0;
}

.copy-btn:hover { color: white; }

.typing {
    display: flex;
    gap: 5px;
    padding: 10px 0;
}

.typing i {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--primary-2);
    animation: bounce 1s infinite;
}

.typing i:nth-child(2) { animation-delay: .15s; }
.typing i:nth-child(3) { animation-delay: .3s; }

@keyframes bounce {
    0%, 80%, 100% { transform: translateY(0); opacity: .4; }
    40% { transform: translateY(-5px); opacity: 1; }
}

.composer-wrap { padding: 12px clamp(16px, 5vw, 72px) 18px; }

.form-error {
    max-width: 760px;
    margin: 0 auto 8px;
    color: #fecaca;
    font-size: 13px;
}

.composer {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    max-width: 760px;
    margin: auto;
    padding: 10px 10px 10px 16px;
    border-radius: 20px;
    box-shadow: 0 16px 40px rgba(0,0,0,0.22);
}

.composer:focus-within {
    border-color: rgba(167, 139, 250, 0.5);
}

textarea {
    flex: 1;
    resize: none;
    max-height: 160px;
    min-height: 44px;
    border: 0;
    outline: 0;
    color: white;
    background: transparent;
    font: inherit;
    line-height: 1.5;
    padding: 10px 0;
}

textarea::placeholder { color: #7d8399; }

.send {
    width: 44px;
    height: 44px;
    flex: 0 0 44px;
    border: 0;
    border-radius: 14px;
    color: white;
    display: grid;
    place-items: center;
    background: linear-gradient(135deg, var(--primary), #6366f1);
    box-shadow: 0 8px 22px rgba(124, 58, 237, 0.28);
    transition: transform 160ms var(--easing), filter 160ms var(--easing), opacity 160ms var(--easing);
}

.send:hover { filter: brightness(1.1); transform: translateY(-1px); }
.send:active { transform: scale(0.97); }
.send:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

.hint {
    margin: 0;
    font-size: 12px;
}



.toast {
    position: fixed;
    left: 50%;
    bottom: 24px;
    transform: translateX(-50%);
    z-index: 20;
    padding: 10px 14px;
    border-radius: 12px;
    background: rgba(12, 12, 20, 0.9);
    border: 1px solid var(--border);
    backdrop-filter: blur(16px);
    font-size: 13px;
}

@media (max-width: 860px) {
    body { overflow: auto; }
    .app {
        width: 100%;
        height: 100dvh;
        margin: 0;
        gap: 0;
        grid-template-columns: 1fr;
    }
    .rail { display: none; }
    .stage { border-radius: 0; border: 0; }
    .mobile-brand { display: flex; }
    .session { display: none; }
    .chip { display: none; }
    .topbar { padding: 12px 14px; }
    .thread { padding: 18px 14px; }
    .composer-wrap { padding: 10px 14px 16px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation: none !important;
        transition: none !important;
        scroll-behavior: auto !important;
    }
}
