:root, [data-theme="dark"] {
    --bg: #050508;
    --bg-card: #0c0c14;
    --bg-base: #050508;
    --surface: #0c0c12;
    --surface-hover: #141420;
    --border: #1a1a2e;
    --border-glow: #7c3aed20;
    --text: #d4d4dc;
    --text-dim: #666680;
    --text-faint: #333345;
    --accent: #7c3aed;
    --accent-bright: #8b5cf6;
    --accent-dim: #4c1d95;
    --accent-glow: #7c3aed15;
    --user-bg: #0d0d18;
    --ai-bg: #0a0a10;
    --prism-1: #7c3aed;
    --prism-2: #6366f1;
    --prism-3: #3b82f6;
    --prism-4: #06b6d4;
    --prism-5: #10b981;
    --header-gradient: linear-gradient(180deg, #08060f 0%, var(--bg) 100%);
    --shadow-color: #00000060;
    --msg-user-border: #1a1a30;
    --code-bg: #111118;
    --code-block-bg: #08080e;
    --code-block-border: #1a1a2e;
    color-scheme: dark;
}

[data-theme="light"] {
    --bg: #f8f7fc;
    --bg-card: #ffffff;
    --bg-base: #f0eef6;
    --surface: #ffffff;
    --surface-hover: #f0edf8;
    --border: #e0dce8;
    --border-glow: #7c3aed18;
    --text: #1a1625;
    --text-dim: #6b6580;
    --text-faint: #b0aab8;
    --accent: #7c3aed;
    --accent-bright: #6d28d9;
    --accent-dim: #ddd6fe;
    --accent-glow: #7c3aed10;
    --user-bg: #ede9f6;
    --ai-bg: #f5f3fa;
    --prism-1: #7c3aed;
    --prism-2: #6366f1;
    --prism-3: #3b82f6;
    --prism-4: #06b6d4;
    --prism-5: #10b981;
    --header-gradient: linear-gradient(180deg, #f0ecf8 0%, var(--bg) 100%);
    --shadow-color: #00000012;
    --msg-user-border: #e0dce8;
    --code-bg: #f0edf5;
    --code-block-bg: #f5f3fa;
    --code-block-border: #e0dce8;
    color-scheme: light;
}

/* -- Sidebar -- */
/* Mobile: sidebar is overlay */
.sidebar {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    width: 280px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    z-index: 9000;
    display: flex;
    flex-direction: column;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
}
.sidebar.open { transform: translateX(0); }
.sidebar-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 8999;
    display: none;
}
.sidebar.open ~ .sidebar-overlay { display: block; }

/* ── Icon rail (shown when sidebar collapsed on desktop) ── */
.sidebar-rail {
    display: none;
}

/* Desktop: sidebar in-flow, pushes content (ChatGPT style) */
@media (min-width: 1024px) {
    /* Body becomes a flex row so sidebar + main sit side by side */
    body {
        display: flex !important;
        flex-direction: row !important;
        height: 100dvh !important;
        overflow: hidden !important;
    }
    .sidebar {
        position: relative;
        transform: none;
        z-index: 1;
        flex-shrink: 0;
        width: 280px;
        transition: width 0.25s ease, margin-left 0.25s ease;
    }
    body.sidebar-collapsed .sidebar {
        width: 0;
        min-width: 0;
        overflow: hidden;
        border-right: none;
        padding: 0;
    }
    .sidebar-overlay { display: none !important; }

    /* Icon rail */
    .sidebar-rail {
        display: none;
        position: relative;
        width: 48px;
        flex-shrink: 0;
        background: var(--surface);
        border-right: 1px solid var(--border);
        flex-direction: column;
        align-items: center;
        padding: 12px 0;
        gap: 4px;
    }
    body.sidebar-collapsed .sidebar-rail {
        display: flex;
    }
    .sidebar-rail-btn {
        width: 36px; height: 36px;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 8px;
        border: none;
        background: transparent;
        color: var(--text-dim);
        cursor: pointer;
        transition: all 0.15s;
    }
    .sidebar-rail-btn:hover {
        background: color-mix(in srgb, var(--accent) 10%, transparent);
        color: var(--text);
    }
    .sidebar-rail-spacer { flex: 1; }

    /* Hide hamburger on desktop */
    .sidebar-toggle-btn { display: none; }
}
/* Sidebar brand */
.sidebar-brand {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 16px 12px;
}
.sidebar-brand-left {
    display: flex;
    align-items: center;
    gap: 10px;
}
.sidebar-brand-icon {
    width: 36px; height: 36px;
    border-radius: 50%;
    background: color-mix(in srgb, var(--accent) 15%, transparent);
    display: flex;
    align-items: center;
    justify-content: center;
}
.sidebar-brand-name {
    font-size: 0.88rem;
    font-weight: 700;
    color: var(--text);
}
.sidebar-brand-tier {
    font-size: 0.65rem;
    color: var(--text-dim);
    font-weight: 500;
}
.sidebar-new-btn {
    display: flex;
    width: 100%;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 14px;
    background: var(--accent);
    color: var(--bg);
    border: none;
    border-radius: 10px;
    font-size: 0.82rem;
    font-weight: 700;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.2s;
}
.sidebar-new-btn:hover { opacity: 0.9; transform: translateY(-1px); }
.sidebar-close-btn {
    background: none;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    padding: 0.3rem;
    display: flex;
    align-items: center;
}
.sidebar-close-btn:hover { color: var(--text); }

/* Sidebar nav links */
.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 0 10px;
    margin-bottom: 12px;
}
.sidebar-nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 12px;
    border-radius: 8px;
    color: var(--text-dim);
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 500;
    transition: all 0.15s;
}
.sidebar-nav-link:hover {
    background: color-mix(in srgb, var(--accent) 8%, transparent);
    color: var(--text);
}
.sidebar-nav-divider {
    height: 1px;
    background: var(--border);
    margin: 6px 12px;
}

/* Sidebar section label */
.sidebar-section-label {
    padding: 12px 22px 6px;
    font-size: 0.58rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    color: var(--text-faint);
}

/* Sidebar user footer */
.sidebar-user-footer {
    padding: 12px 14px;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: auto;
}
.sidebar-user-avatar {
    width: 32px; height: 32px;
    border-radius: 50%;
    background: color-mix(in srgb, var(--accent) 15%, transparent);
    border: 1px solid color-mix(in srgb, var(--accent) 20%, transparent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--accent);
    flex-shrink: 0;
}
.sidebar-user-info { flex: 1; min-width: 0; overflow: hidden; }
.sidebar-user-name { font-size: 0.78rem; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user-email { font-size: 0.65rem; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-search {
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--border);
}
.sidebar-search input {
    width: 100%;
    padding: 0.4rem 0.6rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 5px;
    color: var(--text);
    font-family: inherit;
    font-size: 0.78rem;
    outline: none;
}
.sidebar-search input:focus { border-color: var(--accent-dim); }
.sidebar-search input::placeholder { color: var(--text-faint); }
.sidebar-list {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
}
.sidebar-empty {
    text-align: center;
    color: var(--text-faint);
    font-size: 0.8rem;
    padding: 2rem 0.5rem;
}
.sidebar-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.55rem 0.65rem;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s;
    margin-bottom: 2px;
}
.sidebar-item:hover { background: var(--surface-hover); }
.sidebar-item.active { background: var(--accent-glow); border: 1px solid var(--accent-dim); }
.sidebar-item-text {
    flex: 1;
    min-width: 0;
}
.sidebar-item-title {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
/* Sidebar project folders */
.sidebar-project {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s;
    margin-bottom: 2px;
    color: var(--text);
}
.sidebar-project:hover { background: var(--surface-hover); }
.sidebar-project.open { background: color-mix(in srgb, var(--accent) 6%, transparent); }

.sidebar-item-date, .sidebar-item-meta {
    font-size: 0.65rem;
    color: var(--text-faint);
}
.sidebar-item-delete {
    opacity: 0;
    background: none;
    border: none;
    color: var(--text-faint);
    cursor: pointer;
    padding: 0.2rem;
    flex-shrink: 0;
}
.sidebar-item:hover .sidebar-item-delete { opacity: 1; }
.sidebar-item-delete:hover { color: #ef4444; }
.sidebar-toggle-btn {
    background: none;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    padding: 0.3rem;
    display: flex;
    align-items: center;
}
.sidebar-toggle-btn:hover { color: var(--text); }

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    background: var(--bg);
    color: var(--text);
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
    padding-top: env(safe-area-inset-top);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
}

/* -- Header -- */
.header {
    padding: 1.25rem 1.5rem 1rem;
    flex-shrink: 0;
    position: relative;
    background: var(--header-gradient);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

@media (display-mode: standalone) {
    .header {
        padding-top: calc(1.25rem + 36px);
    }
}

.header::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent 0%, var(--prism-3) 25%, var(--prism-1) 50%, var(--prism-4) 75%, transparent 100%);
    opacity: 0.3;
}

.header p {
    color: #888;
    font-size: 0.75rem;
    letter-spacing: 0.06em;
    font-weight: 400;
}

/* -- Chat area -- */
.chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 2rem 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    scroll-behavior: smooth;
}

::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* -- Messages -- */
.message {
    max-width: 70%;
    padding: 1rem 1.25rem;
    border-radius: 14px;
    line-height: 1.65;
    font-size: 0.92rem;
    animation: fadeIn 0.25s ease;
    margin-bottom: 0.5rem;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

.message.user {
    background: var(--user-bg);
    border: 1px solid var(--msg-user-border);
    margin-left: auto;
    border-radius: 14px 14px 4px 14px;
}

.message.assistant {
    background: var(--ai-bg);
    border: 1px solid var(--border);
    border-left: 2px solid var(--persona-color, var(--accent-dim));
    margin-right: auto;
    border-radius: 14px 14px 14px 4px;
}

.message.assistant.streaming {
    border-left-color: var(--persona-color, var(--accent));
    animation: stream-pulse 1.5s ease-in-out infinite;
}

@keyframes stream-pulse {
    0%, 100% { box-shadow: -2px 0 8px color-mix(in srgb, var(--persona-color, var(--accent)) 10%, transparent); }
    50% { box-shadow: -2px 0 16px color-mix(in srgb, var(--persona-color, var(--accent)) 25%, transparent); }
}

.message .role {
    font-size: 0.6rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    margin-bottom: 0.6rem;
}

.message.user .role { color: #6366f1; }
.message.assistant .role { color: var(--accent); }

.message .content p { margin-bottom: 0.75rem; }
.message .content p:last-child { margin-bottom: 0; }
.message .content strong { color: var(--text); font-weight: 700; }
.message .content em { color: var(--accent-bright); font-style: normal; font-weight: 600; }
.message .content ul, .message .content ol { margin: 0.5rem 0 0.75rem 1.25rem; }
.message .content li { margin-bottom: 0.25rem; }
.message .content code {
    background: var(--code-bg);
    padding: 0.15rem 0.4rem;
    border-radius: 3px;
    font-size: 0.85em;
    color: var(--accent-bright);
    border: 1px solid var(--code-block-border);
}
.message .content pre {
    background: var(--code-block-bg);
    padding: 0.75rem 1rem;
    border-radius: 6px;
    overflow-x: auto;
    margin: 0.5rem 0;
    border: 1px solid var(--code-block-border);
}
.message .content pre code {
    background: none;
    padding: 0;
    color: var(--text);
    border: none;
}
.message .content h1, .message .content h2, .message .content h3 {
    color: var(--text);
    margin: 1rem 0 0.5rem;
}
.message .content h1 { font-size: 1.2rem; }
.message .content h2 { font-size: 1.05rem; }
.message .content h3 { font-size: 0.95rem; }

/* -- Welcome screen -- */
.welcome {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 1.5rem 2rem;
    gap: 0.85rem;
    position: relative;
}

.welcome::before {
    content: '';
    position: absolute;
    top: 20%;
    left: 50%;
    transform: translateX(-50%);
    width: 600px;
    height: 400px;
    background: radial-gradient(ellipse, color-mix(in srgb, var(--accent) 5%, transparent), transparent 70%);
    pointer-events: none;
    z-index: 0;
}

.welcome > * {
    position: relative;
    z-index: 1;
}

.welcome-logo {
    width: 96px;
    height: 96px;
    object-fit: contain;
    filter: drop-shadow(0 0 20px #7c3aed30) drop-shadow(0 0 40px #6366f120);
    animation: logo-glow 4s ease-in-out infinite;
}

@keyframes logo-glow {
    0%, 100% { filter: drop-shadow(0 0 20px #7c3aed30) drop-shadow(0 0 40px #6366f120); }
    33% { filter: drop-shadow(0 0 24px #6366f140) drop-shadow(0 0 48px #3b82f620); }
    66% { filter: drop-shadow(0 0 24px #3b82f140) drop-shadow(0 0 48px #06b6d420); }
}

.welcome h2 {
    color: var(--text);
    letter-spacing: -0.02em;
}

.welcome p {
    color: var(--text-dim);
    max-width: 460px;
    line-height: 1.6;
    font-size: 0.88rem;
}

.welcome .suggestions {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
    margin-top: 0.5rem;
    max-width: 680px;
    width: 100%;
}

.welcome .suggestions button {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--accent);
    font-weight: 700;
    padding: 0.55rem 1.1rem;
    border-radius: 6px;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
    letter-spacing: 0.01em;
    text-align: left;
}

.welcome .suggestions button span {
    color: var(--text-dim);
    font-weight: 400;
    font-size: 0.72rem;
}

.welcome .suggestions button:hover {
    border-color: var(--accent-dim);
    color: var(--text);
    background: var(--accent-glow);
    box-shadow: 0 0 20px #7c3aed10;
}

/* -- Grade badges (rendered in markdown) -- */
.message .content p em:first-child {
    display: inline-block;
    padding: 0.1rem 0.5rem;
    border-radius: 3px;
    font-size: 0.75rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

/* -- Input area -- */
.input-area {
    padding: 1rem 1.5rem;
    padding-bottom: calc(1rem + env(safe-area-inset-bottom));
    border-top: 1px solid var(--border);
    background: var(--surface);
    flex-shrink: 0;
    position: relative;
}

.input-area::before {
    content: '';
    position: absolute;
    top: -1px;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent 0%, #7c3aed30 30%, #6366f130 50%, #3b82f630 70%, transparent 100%);
}

.input-wrap {
    max-width: 780px;
    margin: 0 auto;
    display: flex;
    gap: 0.75rem;
    align-items: flex-end;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    backdrop-filter: blur(12px);
    padding: 0.4rem 0.5rem;
}

.input-wrap textarea {
    flex: 1;
    background: transparent;
    border: none;
    border-radius: 8px;
    color: var(--text);
    padding: 0.75rem 0.5rem;
    font-family: inherit;
    font-size: 0.9rem;
    resize: none;
    height: 44px;
    max-height: 200px;
    line-height: 1.5;
    outline: none;
    overflow-y: hidden;
}

.input-wrap:focus-within {
    border-color: var(--accent-dim);
    box-shadow: 0 0 0 1px #7c3aed15, 0 0 20px #7c3aed08;
}

.input-wrap textarea::placeholder {
    color: var(--text-faint);
}

.input-wrap #sendBtn {
    background: var(--accent);
    color: var(--bg);
    border: none;
    border-radius: 10px;
    width: 44px;
    height: 44px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.15s;
    flex-shrink: 0;
}

.input-wrap #sendBtn:hover {
    background: var(--accent-bright);
    box-shadow: 0 0 20px #7c3aed30;
}

.input-wrap #sendBtn:disabled {
    background: var(--accent-dim);
    cursor: not-allowed;
    opacity: 0.5;
    box-shadow: none;
}

/* -- Header layout -- */
.header-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

/* -- Mic button -- */
.mic-btn {
    background: transparent;
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    width: 44px;
    height: 44px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.mic-btn:hover {
    border-color: var(--accent-dim);
    color: var(--accent);
}

.mic-btn.recording {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-glow);
    animation: mic-pulse 1s ease-in-out infinite;
}

.mic-btn.transcribing {
    opacity: 0.5;
    pointer-events: none;
}

@keyframes mic-pulse {
    0%, 100% { box-shadow: 0 0 0 0 #7c3aed40; }
    50% { box-shadow: 0 0 0 8px #7c3aed00; }
}

/* -- Typing indicator -- */
.typing-indicator {
    display: inline-flex;
    gap: 5px;
    padding: 4px 0;
}

.typing-indicator span {
    width: 5px;
    height: 5px;
    background: var(--accent);
    border-radius: 50%;
    animation: bounce 1.2s infinite;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-5px); opacity: 1; }
}

/* -- Enhanced mode theme (no mercy) -- */
body.lv2 {
    --bg: #020005;
    --surface: #0a0010;
    --border: #1a0030;
    --accent: #a855f7;
    --accent-bright: #c084fc;
    --accent-dim: #6b21a8;
    --accent-glow: #a855f720;
    --ai-bg: #080010;
}

body.lv2 .chat-container {
    box-shadow: inset 0 0 80px #a855f710;
}

body.lv2 .chat-container::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: repeating-linear-gradient(
        0deg,
        transparent,
        transparent 2px,
        #a855f703 2px,
        #a855f703 4px
    );
    pointer-events: none;
    z-index: 9999;
}

body.lv2 .message.assistant {
    border-left: 2px solid #a855f7;
    box-shadow: -2px 0 12px #a855f715;
}

body.lv2 .input-wrap:focus-within {
    border-color: #a855f7;
    box-shadow: 0 0 0 1px #a855f730, 0 0 20px #a855f715;
}

body.lv2 .input-wrap #sendBtn {
    background: #7c3aed;
}

body.lv2 .input-wrap #sendBtn:hover {
    background: #a855f7;
    box-shadow: 0 0 24px #a855f750;
}

._si {
    text-align: center;
    padding: 1.5rem;
    animation: fadeIn 0.3s ease;
}

._si span {
    font-size: 0.7rem;
    font-weight: 800;
    letter-spacing: 0.3em;
    text-transform: uppercase;
    background: linear-gradient(135deg, #c084fc, #a855f7, #7c3aed);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: _pt 2s ease-in-out infinite;
}

@keyframes _pt {
    0%, 100% { opacity: 0.8; }
    50% { opacity: 1; }
}

._fo {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 99999;
    pointer-events: none;
    animation: _ga 2s ease-out forwards;
}

@keyframes _ga {
    0% { background: #7c3aed30; }
    10% { background: transparent; }
    15% { background: #7c3aed20; }
    20% { background: transparent; }
    25% { background: #7c3aed15; }
    35% { background: transparent; }
    100% { background: transparent; opacity: 0; }
}

/* -- PWA install banner -- */
/* -- Delete Confirmation Modal -- */
.delete-modal {
    display: none;
    position: fixed; inset: 0;
    z-index: 10002;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    align-items: center;
    justify-content: center;
}
.delete-modal.open { display: flex; }
.delete-modal-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 1.75rem;
    max-width: 340px;
    width: 90%;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

/* -- Login Modal -- */
.login-modal {
    display: none;
    position: fixed; inset: 0;
    z-index: 10001;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    align-items: center;
    justify-content: center;
}
.login-modal.open { display: flex; }
.login-modal-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 2rem;
    max-width: 380px;
    width: 90%;
    position: relative;
    box-shadow: 0 20px 60px rgba(0,0,0,0.4);
}
.login-modal-close {
    position: absolute;
    top: 12px; right: 14px;
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 1.4rem;
    cursor: pointer;
    line-height: 1;
    padding: 4px;
}
.login-modal-close:hover { color: var(--text); }
.login-modal-google {
    width: 100%;
    padding: 0.7rem;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    transition: all 0.2s;
}
.login-modal-google:hover {
    border-color: color-mix(in srgb, var(--accent) 30%, var(--border));
    background: var(--surface-hover);
}
.login-modal-input {
    width: 100%;
    padding: 0.7rem 1rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-family: inherit;
    font-size: 0.88rem;
    outline: none;
    margin-bottom: 0.75rem;
    transition: border-color 0.2s;
}
.login-modal-input:focus { border-color: var(--accent-dim); }
.login-modal-input::placeholder { color: var(--text-faint); }
.login-modal-submit {
    width: 100%;
    padding: 0.7rem;
    background: var(--accent);
    color: var(--bg);
    border: none;
    border-radius: 8px;
    font-size: 0.88rem;
    font-weight: 700;
    cursor: pointer;
    font-family: inherit;
    transition: opacity 0.15s;
}
.login-modal-submit:hover { opacity: 0.9; }

.pwa-banner {
    position: fixed;
    bottom: 5rem;
    left: 50%;
    transform: translateX(-50%);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 0.65rem 0.75rem 0.65rem 1.1rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    z-index: 1000;
    animation: bannerIn 0.3s ease;
    box-shadow: 0 4px 24px var(--shadow-color);
    max-width: calc(100vw - 2rem);
}

.pwa-banner span {
    font-size: 0.8rem;
    color: var(--text);
    white-space: nowrap;
}

.pwa-banner #pwaInstall {
    background: var(--accent);
    color: var(--bg);
    border: none;
    border-radius: 6px;
    padding: 0.4rem 0.9rem;
    font-size: 0.75rem;
    font-weight: 700;
    cursor: pointer;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    font-family: inherit;
}

.pwa-banner #pwaInstall:hover {
    background: var(--accent-bright);
}

.pwa-banner .pwa-dismiss {
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 1.1rem;
    cursor: pointer;
    padding: 0 0.2rem;
    line-height: 1;
}

.pwa-banner .pwa-dismiss:hover {
    color: var(--text);
}

@keyframes bannerIn {
    from { opacity: 0; transform: translateX(-50%) translateY(10px); }
    to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* -- Attach button -- */
.attach-btn {
    background: transparent;
    border: none;
    color: var(--text-faint);
    width: 32px;
    height: 32px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    border-radius: 6px;
    transition: color 0.2s;
    align-self: flex-end;
    margin-bottom: 6px;
}

.attach-btn:hover {
    color: var(--text-dim);
}

/* -- Image preview strip -- */
.image-preview {
    max-width: 780px;
    margin: 0 auto 0.5rem;
    display: none;
    align-items: center;
    gap: 0.5rem;
}

.image-preview.active {
    display: flex;
}

.image-preview img {
    width: 56px;
    height: 56px;
    object-fit: cover;
    border-radius: 6px;
    border: 1px solid var(--border);
}

.image-preview .remove-img {
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0 0.25rem;
    line-height: 1;
    transition: color 0.2s;
}

.image-preview .remove-img:hover {
    color: var(--accent);
}

/* -- File preview -- */
.file-preview {
    max-width: 780px;
    margin: 0 auto 0.5rem;
}

.file-preview-card {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.5rem 0.75rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    max-width: 320px;
}

.file-preview-icon {
    color: var(--accent);
    flex-shrink: 0;
}

.file-preview-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
    flex: 1;
}

.file-preview-name {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.file-preview-size {
    font-size: 0.65rem;
    color: var(--text-dim);
}

.file-preview-card .remove-img {
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0 0.25rem;
    line-height: 1;
    transition: color 0.2s;
    flex-shrink: 0;
}

.file-preview-card .remove-img:hover {
    color: var(--accent);
}

/* -- Message images -- */
.message .msg-image {
    max-width: 240px;
    max-height: 180px;
    border-radius: 6px;
    border: 1px solid var(--border);
    margin-bottom: 0.5rem;
}

/* -- Command palette dropdown -- */
.cmd-palette {
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 780px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.4rem;
    margin-bottom: 0.5rem;
    max-height: 320px;
    overflow-y: auto;
    z-index: 100;
    box-shadow: 0 -8px 32px rgba(0,0,0,0.5);
}

.cmd-palette-item {
    display: flex;
    align-items: baseline;
    gap: 0.6rem;
    padding: 0.6rem 0.75rem;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.12s;
}

.cmd-palette-item:hover,
.cmd-palette-item.active {
    background: var(--accent-glow);
}

.cmd-palette-name {
    color: var(--accent);
    font-weight: 700;
    font-size: 0.82rem;
    font-family: monospace;
    white-space: nowrap;
}

.cmd-palette-label {
    color: var(--text);
    font-size: 0.82rem;
    font-weight: 600;
    white-space: nowrap;
}

.cmd-palette-desc {
    color: var(--text-dim);
    font-size: 0.75rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* -- Active command badge -- */
.cmd-badge {
    max-width: 780px;
    margin: 0 auto 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.45rem 0.5rem 0.45rem 0.85rem;
    background: var(--accent-glow);
    border: 1px solid var(--accent-dim);
    border-radius: 8px;
    animation: fadeIn 0.2s ease;
}

.cmd-badge-name {
    color: var(--accent);
    font-weight: 700;
    font-size: 0.8rem;
    font-family: 'Inter', monospace;
    letter-spacing: 0.02em;
    white-space: nowrap;
}

.cmd-badge-label {
    color: var(--text-dim);
    font-size: 0.75rem;
    padding-left: 0.5rem;
    border-left: 1px solid var(--border);
    white-space: nowrap;
}

.cmd-badge-close {
    margin-left: auto;
    background: var(--surface-hover);
    border: 1px solid var(--border);
    color: var(--text-dim);
    font-size: 0.85rem;
    cursor: pointer;
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    line-height: 1;
    transition: all 0.15s;
    flex-shrink: 0;
}

.cmd-badge-close:hover {
    color: var(--accent);
    border-color: var(--accent-dim);
    background: var(--accent-glow);
}

/* -- Pitch timer -- */
.pitch-timer {
    max-width: 780px;
    margin: 0 auto 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0.75rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
}

.pitch-timer-bar {
    flex: 1;
    height: 6px;
    background: var(--accent);
    border-radius: 3px;
    transition: width 1s linear, background 0.3s;
}

.pitch-timer-text {
    color: var(--accent-bright);
    font-size: 0.85rem;
    font-weight: 700;
    font-family: monospace;
    min-width: 3.5rem;
    text-align: right;
}

.pitch-timer-start {
    background: var(--accent);
    color: var(--text);
    border: none;
    border-radius: 6px;
    padding: 0.35rem 0.85rem;
    font-size: 0.75rem;
    font-weight: 700;
    cursor: pointer;
    font-family: inherit;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    transition: background 0.15s;
}

.pitch-timer-start:hover {
    background: var(--accent-bright);
}

/* -- Rapid fire counter -- */
.rapid-counter {
    max-width: 780px;
    margin: 0 auto 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.5rem 0.85rem;
    background: linear-gradient(135deg, var(--accent-glow), transparent);
    border: 1px solid var(--accent-dim);
    border-radius: 8px;
    color: var(--accent-bright);
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    font-family: 'Inter', monospace;
    text-shadow: 0 0 12px var(--accent-glow);
}

/* -- Grade card styling -- */
.grade-card {
    background: var(--surface) !important;
    border: 1px solid var(--accent-dim) !important;
    border-radius: 8px;
    padding: 0.5rem;
}

.grade-card strong {
    display: inline-block;
}

/* Welcome command suggestion chips */
.cmd-suggestions button {
    display: inline-flex;
    flex-direction: column;
    align-items: flex-start;
    padding: 0.6rem 1rem 0.6rem 0.85rem !important;
    text-align: left;
    gap: 0.15rem;
    min-width: 155px;
    border-left: 2px solid var(--accent-dim) !important;
}

.cmd-suggestions button:hover {
    border-left-color: var(--accent) !important;
}

.cmd-suggestions button span {
    font-size: 0.65rem;
    color: var(--text-faint);
    font-weight: 400;
}

.create-agent-link {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    margin-top: 1rem;
    font-size: 0.82rem;
    color: var(--accent);
    text-decoration: none;
    transition: opacity 0.2s;
}

.create-agent-link:hover {
    opacity: 0.8;
}

.header-text {
    display: flex;
    flex-direction: column;
}

.header-avatar-wrap {
    position: relative;
    flex-shrink: 0;
}

.header-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    object-fit: cover;
    position: relative;
    z-index: 1;
}

.header-avatar-ring {
    position: absolute;
    inset: -3px;
    border-radius: 50%;
    border: 2px solid var(--accent);
    z-index: 0;
    animation: ring-pulse 3s ease-in-out infinite;
}

@keyframes ring-pulse {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 1; }
}

.header-persona-name {
    font-family: 'Playfair Display', serif;
    font-size: 0.95rem;
    font-weight: 600;
    font-style: italic;
    text-transform: none;
    letter-spacing: 0.02em;
    margin-top: 0.1rem;
}
.header-tagline {
    font-size: 0.75rem;
    color: var(--text-dim);
    font-style: italic;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.msg-counter {
    font-size: 0.65rem;
    color: var(--text-faint);
    font-weight: 700;
    background: var(--surface);
    padding: 0.2rem 0.5rem;
    border-radius: 10px;
    border: 1px solid var(--border);
    letter-spacing: 0.04em;
}

.header-action-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-faint);
    border-radius: 6px;
    width: 28px;
    height: 28px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.header-action-btn:hover {
    border-color: var(--accent-dim);
    color: var(--accent);
}

/* -- Message avatar -- */
.msg-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.6rem;
}

.msg-avatar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    object-fit: cover;
    border: 1px solid var(--border);
}

/* -- Personality Picker Overlay -- */
.picker-overlay {
    position: fixed;
    inset: 0;
    z-index: 10000;
    background: var(--bg);
    display: none;
    flex-direction: column;
    align-items: center;
    overflow-y: auto;
    padding: 2rem 1rem;
}

.picker-overlay.open {
    display: flex;
}

.picker-content {
    max-width: 900px;
    width: 100%;
}

.picker-header {
    text-align: center;
    margin-bottom: 2rem;
}

.picker-logo {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    gap: 0.3rem;
    margin-bottom: 1.5rem;
    opacity: 0.5;
    transition: opacity 0.2s;
    text-decoration: none;
}

.picker-logo:hover { opacity: 0.8; }

.picker-logo span {
    font-size: 0.55rem;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

.picker-logo img {
    height: 56px;
    width: auto;
}

.picker-header h2 {
    font-size: 1.75rem;
    font-weight: 800;
    color: var(--text);
    margin-bottom: 0.5rem;
}

.picker-header h2 span {
    background: linear-gradient(135deg, var(--prism-1), var(--prism-2), var(--prism-3));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.picker-header p {
    color: var(--text-dim);
    font-size: 0.9rem;
}

/* -- Picker grid: 5x2 with hero images -- */
.picker-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.picker-card {
    position: relative;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border);
    border-radius: 14px;
    cursor: pointer;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    background: var(--surface);
    overflow: hidden;
    animation: fadeInUp 0.5s ease-out forwards;
    opacity: 0;
}

@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

.picker-card:hover { transform: translateY(-2px); }

.picker-card.selected {
    border-color: var(--card-color, var(--accent));
    box-shadow: 0 0 30px color-mix(in srgb, var(--card-color) 15%, transparent);
}

/* Dual-layer crossfade hero */
.picker-card-hero {
    position: relative;
    aspect-ratio: 1;
    overflow: hidden;
    background: var(--bg);
}

.picker-hero-img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1), opacity 1.5s ease-in-out;
}

.picker-card:hover .picker-hero-img { transform: scale(1.05); }

.picker-card-glow {
    position: absolute;
    inset-inline: 0;
    bottom: 0;
    height: 50%;
    pointer-events: none;
}

.picker-card-ring {
    position: absolute;
    inset: 0;
    pointer-events: none;
    border-radius: 14px 14px 0 0;
    animation: subtlePulse 3s ease-in-out infinite;
}

@keyframes subtlePulse {
    0%, 100% { opacity: 0.15; }
    50% { opacity: 0.3; }
}

.picker-card-info {
    padding: 0.6rem 0.75rem 0.7rem;
    position: relative;
}

.picker-card-accent {
    position: absolute;
    top: 0;
    left: 0.75rem;
    right: 0.75rem;
    height: 1px;
}

.picker-card-name {
    font-size: 0.8rem;
    font-weight: 700;
    margin-bottom: 0.15rem;
}

.picker-card-tagline {
    font-size: 0.65rem;
    color: var(--text-dim);
    font-style: italic;
    line-height: 1.3;
}

/* Checkmark */
.picker-card-check {
    position: absolute;
    top: 0.6rem;
    right: 0.6rem;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    opacity: 0;
    transform: scale(0.5);
    transition: all 0.25s ease;
    box-shadow: 0 2px 8px #00000040;
}

.picker-card-check.visible {
    opacity: 1;
    transform: scale(1);
}

/* -- Mood chips -- */
.mood-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 1rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: color-mix(in srgb, var(--chip-color) 5%, transparent);
    color: var(--text-faint);
    font-size: 0.82rem;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.25s ease;
}
.mood-chip:hover {
    border-color: var(--chip-color);
    color: var(--text);
    background: color-mix(in srgb, var(--chip-color) 18%, transparent);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px color-mix(in srgb, var(--chip-color) 20%, transparent);
}

/* -- Group cards (Stitch glass-card style) -- */
.group-card {
    padding: 1.5rem 1.25rem;
    border-radius: 14px;
    border: 1px solid color-mix(in srgb, var(--group-color) 10%, var(--border));
    background: var(--surface);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}
.group-card-glow {
    position: absolute;
    inset: 0;
    background: radial-gradient(ellipse at 50% 0%, color-mix(in srgb, var(--group-color) 8%, transparent), transparent 70%);
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}
.group-card:hover {
    border-color: color-mix(in srgb, var(--group-color) 30%, transparent);
    border-top: 2px solid var(--group-color);
    transform: translateY(-4px);
    box-shadow: 0 12px 36px var(--shadow-color);
    background: var(--surface-hover);
}
.group-card:hover .group-card-glow { opacity: 1; }
.group-card-avatars {
    display: flex;
    justify-content: center;
    position: relative;
    z-index: 1;
    padding-left: 10px;
}
.group-card-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 2px solid var(--bg-base);
    object-fit: cover;
    margin-left: -10px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.4);
    transition: transform 0.2s ease;
}
.group-card:hover .group-card-avatar { transform: translateY(-2px); }
.group-card-body {
    text-align: center;
    position: relative;
    z-index: 1;
}
.group-card-icon { font-size: 1.3rem; margin-bottom: 0.15rem; }
.group-card-name {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--group-color);
    margin-bottom: 0.15rem;
}
.group-card-desc {
    font-size: 0.7rem;
    color: var(--text-dim);
    line-height: 1.3;
}

/* -- Recommendation badge -- */
.picker-card-badge {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    background: var(--card-color);
    color: var(--text);
    font-size: 0.6rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: 0.2rem 0.5rem;
    border-radius: 6px;
    z-index: 5;
}
.picker-card.recommended {
    border-color: var(--card-color);
    box-shadow: 0 0 20px color-mix(in srgb, var(--card-color) 25%, transparent);
}

/* -- Style thumbs (used in Tailwind expanded panel) -- */
.style-thumb {
    cursor: pointer;
    opacity: 0.5;
    border: 2px solid transparent;
    transition: all 0.2s ease;
}

.style-thumb:hover { opacity: 0.85; transform: scale(1.08); }

.style-thumb.active {
    opacity: 1;
    border-color: var(--accent-color);
    box-shadow: 0 0 12px var(--accent-color-glow);
}

/* -- Upsell Banner -- */
.upsell-banner {
    position: fixed;
    bottom: 5.5rem;
    left: 50%;
    transform: translateX(-50%);
    max-width: 600px;
    width: calc(100% - 2rem);
    background: linear-gradient(135deg, #1a1030, #0f0f20);
    border: 1px solid var(--accent-dim);
    border-radius: 12px;
    padding: 0.85rem 1rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    z-index: 500;
    animation: bannerIn 0.3s ease;
    box-shadow: 0 4px 30px var(--shadow-color);
}

.upsell-text {
    flex: 1;
    min-width: 0;
}

.upsell-text strong {
    display: block;
    font-size: 0.82rem;
    color: var(--text);
    margin-bottom: 0.15rem;
}

.upsell-text span {
    font-size: 0.72rem;
    color: var(--text-dim);
}

.upsell-btn {
    background: var(--accent);
    color: var(--text);
    border: none;
    border-radius: 6px;
    padding: 0.45rem 1rem;
    font-size: 0.75rem;
    font-weight: 700;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
    transition: background 0.15s;
    font-family: inherit;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.upsell-btn:hover {
    background: var(--accent-bright);
}

.upsell-dismiss {
    background: none;
    border: none;
    color: var(--text-faint);
    font-size: 1.3rem;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    flex-shrink: 0;
}

.upsell-dismiss:hover {
    color: var(--text-dim);
}

/* -- Responsive -- */
@media (max-width: 768px) {
    .picker-grid { grid-template-columns: repeat(2, 1fr); }
    .picker-expanded-inner { flex-direction: column; }
    .picker-expanded-preview { width: 100%; max-height: 280px; }
    .picker-expanded-thumbs { grid-template-columns: repeat(4, 1fr); }
    .picker-expanded-details { padding: 1rem 1.25rem; }
    #groupGrid { grid-template-columns: repeat(2, 1fr) !important; }
}

@media (max-width: 640px) {
    .header-avatar { width: 28px; height: 28px; }
    .message { padding: 0.75rem 1rem; font-size: 0.88rem; }
    .input-area { padding: 0.75rem; }
    .welcome h2 { font-size: 1.5rem !important; }
    .welcome .suggestions { grid-template-columns: repeat(2, 1fr); }
    .header-left { gap: 0.5rem; }
    .header-actions { gap: 0.35rem; }
}
