/* ═══════════════════════════════════════════════════════════════
   AI BABA-G — Dark Mystical AI Assistant Theme
   ═══════════════════════════════════════════════════════════════ */

:root {
    --bg: #0A0B14;
    --bg-panel: rgba(15, 17, 30, 0.85);
    --bg-card: rgba(20, 22, 40, 0.9);
    --bg-glass: rgba(30, 33, 55, 0.6);
    --gold: #D4A853;
    --gold-dim: #8B7335;
    --gold-glow: rgba(212, 168, 83, 0.3);
    --purple: #6C3AED;
    --blue: #4779F7;
    --gradient: linear-gradient(135deg, #4779F7 0%, #6C3AED 100%);
    --text: #E8DCC8;
    --text-dim: #8B8070;
    --text-bright: #F5EDE0;
    --border: rgba(212, 168, 83, 0.15);
    --border-active: rgba(212, 168, 83, 0.5);
    --radius: 14px;
    --glow: 0 0 30px rgba(212, 168, 83, 0.08);
    --nav-h: 56px;
    --footer-h: 40px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body {
    font-family: 'Inter', sans-serif;
    background: var(--bg);
    color: var(--text);
    background-image:
        radial-gradient(ellipse at 30% 20%, rgba(71, 121, 247, 0.04), transparent 50%),
        radial-gradient(ellipse at 70% 80%, rgba(108, 58, 237, 0.04), transparent 50%);
    -webkit-font-smoothing: antialiased;
}

/* ─── TOP NAV ──────────────────────────────────────── */
.top-nav {
    height: var(--nav-h); display: flex; align-items: center; justify-content: space-between;
    padding: 0 24px; border-bottom: 1px solid var(--border);
    background: rgba(10, 11, 20, 0.9); backdrop-filter: blur(20px);
    position: relative; z-index: 100;
}
.nav-brand {
    display: flex; align-items: center; gap: 8px; font-family: 'Cinzel', serif;
    font-size: 14px; color: var(--gold); font-weight: 600; text-decoration: none;
}
.nav-brand:hover { color: var(--text-bright); }
.nav-logo { display: block; filter: drop-shadow(0 0 8px var(--gold-glow)); }
.nav-icon { font-size: 18px; }
.nav-center { text-align: center; }
.main-title { font-family: 'Cinzel', serif; font-size: 28px; font-weight: 900; color: var(--gold); letter-spacing: 6px; text-shadow: 0 0 30px var(--gold-glow); }
.main-subtitle { font-size: 10px; color: var(--text-dim); letter-spacing: 3px; margin-top: -2px; }
.nav-right { display: flex; align-items: center; gap: 12px; }
.lang-badge { font-size: 12px; color: var(--text-dim); padding: 4px 10px; border: 1px solid var(--border); border-radius: 8px; }
.icon-btn { background: none; border: none; font-size: 18px; cursor: pointer; opacity: 0.6; color: inherit; }
.icon-btn:hover { opacity: 1; }

/* ─── MAIN GRID ────────────────────────────────────── */
.app-grid {
    display: grid; grid-template-columns: 240px 1fr 260px;
    height: calc(100vh - var(--nav-h) - var(--footer-h)); gap: 0;
    min-height: 0;
}

/* ─── PANELS (LEFT + RIGHT) ────────────────────────── */
.panel {
    background: var(--bg-panel); border-right: 1px solid var(--border);
    backdrop-filter: blur(16px); padding: 16px; overflow-y: auto;
    min-height: 0;
}
.panel-right { border-right: none; border-left: 1px solid var(--border); }
.panel-title {
    font-family: 'Cinzel', serif; font-size: 11px; letter-spacing: 2px;
    color: var(--gold); text-align: center; margin-bottom: 16px;
}
.panel-title span { color: var(--gold-dim); }
.panel-subtitle {
    font-family: 'Cinzel', serif; font-size: 10px; letter-spacing: 2px;
    color: var(--gold-dim); text-align: center; margin: 14px 0 8px;
    padding-top: 12px; border-top: 1px dashed var(--border);
}

/* Avatar Cards */
.avatar-list { display: flex; flex-direction: column; gap: 8px; }
.avatar-card {
    display: flex; align-items: center; gap: 10px; padding: 10px;
    border: 1px solid var(--border); border-radius: 12px;
    cursor: pointer; transition: all 0.25s; background: var(--bg-glass);
}
.avatar-card:hover { border-color: var(--gold-dim); background: rgba(212, 168, 83, 0.05); transform: translateY(-1px); }
.avatar-card.active { border-color: var(--gold); background: rgba(212, 168, 83, 0.1); box-shadow: 0 0 20px var(--gold-glow); }
.avatar-img {
    width: 48px; height: 48px; border-radius: 10px; position: relative;
    background: linear-gradient(135deg, #2a1f0a, #1a1520);
    display: flex; align-items: center; justify-content: center; font-size: 24px; flex-shrink: 0;
}
.sage-img::after { content: '🧙‍♂️'; }
.philosopher-img::after { content: '🤔'; }
.healer-img::after { content: '🙏'; }
.elder-img::after { content: '👳'; }
.storyteller-img::after { content: '📖'; }
.designer-img::after { content: '🎨'; }
.developer-img::after { content: '💻'; }
.pm-img::after { content: '📋'; }
.marketing-img::after { content: '📣'; }
.sales-img::after { content: '💼'; }
.hr-img::after { content: '🤝'; }
.avatar-check { position: absolute; top: -4px; right: -4px; width: 18px; height: 18px; border-radius: 50%; background: var(--gradient); color: #fff; font-size: 10px; display: flex; align-items: center; justify-content: center; }
.avatar-info { min-width: 0; }
.avatar-info strong { display: block; font-size: 13px; color: var(--text-bright); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.avatar-info small { font-size: 10px; color: var(--text-dim); }

/* Mindset Cards */
.mindset-list { display: flex; flex-direction: column; gap: 8px; }
.mindset-card {
    display: flex; align-items: center; gap: 10px; padding: 12px;
    border: 1px solid var(--border); border-radius: 12px;
    cursor: pointer; transition: all 0.25s; background: var(--bg-glass);
}
.mindset-card:hover { border-color: var(--gold-dim); transform: translateY(-1px); }
.mindset-card.active { border-color: var(--blue); background: rgba(71, 121, 247, 0.08); box-shadow: 0 0 20px rgba(71, 121, 247, 0.15); }
.mindset-icon { font-size: 24px; width: 36px; text-align: center; }
.mindset-info strong { display: block; font-size: 13px; color: var(--text-bright); }
.mindset-info small { font-size: 10px; color: var(--text-dim); }
.mindset-check { margin-left: auto; width: 22px; height: 22px; border-radius: 50%; background: var(--gradient); color: #fff; font-size: 11px; display: flex; align-items: center; justify-content: center; }

/* Settings */
.settings-section { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border); }
.settings-title { font-family: 'Cinzel', serif; font-size: 11px; letter-spacing: 1.5px; color: var(--gold); margin-bottom: 12px; }
.setting-row { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; font-size: 12px; }
.setting-row label:first-child { color: var(--text-dim); min-width: 44px; }
.setting-select { flex: 1; background: var(--bg-card); border: 1px solid var(--border); border-radius: 8px; color: var(--text); padding: 6px 8px; font-size: 12px; font-family: inherit; }
.setting-range { flex: 1; accent-color: var(--gold); }

/* ─── CENTER AREA ──────────────────────────────────── */
.center-area {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    position: relative; overflow: hidden;
    background:
        radial-gradient(ellipse at center 30%, rgba(212, 168, 83, 0.03), transparent 60%),
        radial-gradient(circle at center, rgba(15, 17, 30, 0.5), transparent);
    padding: 16px 16px 12px;
    min-height: 0; gap: 14px;
}

.avatar-display {
    text-align: center; position: relative;
    display: flex; flex-direction: column; align-items: center;
    width: 100%; max-width: 560px;
    flex: 1 1 auto; min-height: 0;
}

.avatar-glow {
    position: absolute; top: 90px; left: 50%; transform: translate(-50%, -50%);
    width: 240px; height: 240px; border-radius: 50%;
    background: radial-gradient(circle, var(--gold-glow), transparent 70%);
    animation: pulse-glow 3s ease-in-out infinite; pointer-events: none; z-index: 0;
}
@keyframes pulse-glow { 0%, 100% { opacity: 0.4; transform: translate(-50%, -50%) scale(1); } 50% { opacity: 0.7; transform: translate(-50%, -50%) scale(1.1); } }

.avatar-main {
    position: relative; width: 220px; height: 180px;
    display: flex; align-items: center; justify-content: center;
    z-index: 1; flex-shrink: 0;
}
.avatar-figure {
    font-size: 110px; line-height: 1;
    filter: drop-shadow(0 0 30px var(--gold-glow));
    animation: breathe 4s ease-in-out infinite;
}
@keyframes breathe { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.03); } }
.avatar-figure.speaking { animation: speak-pulse 0.3s ease-in-out infinite alternate; }
@keyframes speak-pulse { 0% { transform: scale(1); } 100% { transform: scale(1.05); } }

.avatar-3d { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }

.speech-bubble {
    background: rgba(20, 22, 40, 0.92); backdrop-filter: blur(16px);
    border: 1px solid var(--border); border-radius: 16px;
    padding: 14px 22px; margin-top: 6px; position: relative; z-index: 3;
    width: min(560px, 100%);
    max-height: 220px; overflow-y: auto; overflow-x: hidden;
    text-align: left;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
    scrollbar-width: thin; scrollbar-color: var(--gold-dim) transparent;
}
.speech-bubble::before {
    /* Speech-bubble pointer up to the avatar */
    content: ''; position: absolute; top: -8px; left: 50%; transform: translateX(-50%) rotate(45deg);
    width: 14px; height: 14px;
    background: rgba(20, 22, 40, 0.92);
    border-left: 1px solid var(--border); border-top: 1px solid var(--border);
}
.speech-bubble::-webkit-scrollbar { width: 6px; }
.speech-bubble::-webkit-scrollbar-thumb { background: var(--gold-dim); border-radius: 6px; }
.quote-mark { color: var(--gold-dim); font-size: 18px; opacity: 0.7; }
.quote-mark.top { float: left; margin-right: 6px; }
.quote-mark.bottom { float: right; margin-left: 6px; }
#babaText {
    font-size: 14px; line-height: 1.7; color: var(--text); margin: 2px 0;
    word-wrap: break-word; overflow-wrap: anywhere;
    text-align: center; white-space: pre-wrap;
}
/* When the renderer outputs markdown blocks, use left-aligned prose. */
#babaText.formatted { text-align: left; white-space: normal; }

/* ─── Markdown blocks inside the speech bubble ─────── */
#babaText .md-p { margin: 0 0 8px; }
#babaText .md-p:last-child { margin-bottom: 0; }
#babaText .md-h1, #babaText .md-h2, #babaText .md-h3 {
    font-family: 'Cinzel', serif; color: var(--gold);
    letter-spacing: 1px; margin: 6px 0 6px; line-height: 1.3;
}
#babaText .md-h1 { font-size: 17px; }
#babaText .md-h2 { font-size: 15px; }
#babaText .md-h3 { font-size: 14px; color: var(--gold-dim); }
#babaText .md-list { margin: 0 0 8px; padding-left: 22px; }
#babaText .md-list li { margin: 2px 0; }
#babaText .md-list li::marker { color: var(--gold-dim); }
#babaText strong { color: var(--text-bright); font-weight: 700; }
#babaText em { color: var(--text-bright); font-style: italic; }
#babaText a { color: var(--gold); border-bottom: 1px dotted var(--gold-dim); text-decoration: none; }
#babaText a:hover { border-bottom-color: var(--gold); }
#babaText code {
    font-family: ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace;
    font-size: 12px; padding: 1px 6px; border-radius: 4px;
    background: rgba(212, 168, 83, 0.08); border: 1px solid var(--border);
    color: var(--text-bright);
}
#babaText .md-code {
    margin: 6px 0 10px; padding: 10px 12px;
    background: rgba(8, 9, 16, 0.7); border: 1px solid var(--border);
    border-radius: 10px; overflow-x: auto;
    font-family: ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace;
    font-size: 12px; line-height: 1.55; color: var(--text-bright);
    max-width: 100%; white-space: pre;
}
#babaText .md-code code { background: transparent; border: none; padding: 0; }
#babaText .md-quote {
    margin: 6px 0; padding: 6px 12px;
    border-left: 3px solid var(--gold-dim);
    color: var(--text-dim); font-style: italic;
    background: rgba(212, 168, 83, 0.04); border-radius: 0 8px 8px 0;
}

.voice-wave {
    display: flex; align-items: center; justify-content: center; gap: 3px;
    height: 26px; opacity: 0; transition: opacity 0.3s; flex-shrink: 0;
}
.voice-wave.active { opacity: 1; }
.wave-bar {
    width: 3px; height: 8px; border-radius: 2px;
    background: linear-gradient(to top, var(--blue), var(--purple));
    animation: wave-anim 0.8s ease-in-out infinite alternate;
}
.wave-bar:nth-child(1) { animation-delay: 0s; }
.wave-bar:nth-child(2) { animation-delay: 0.1s; }
.wave-bar:nth-child(3) { animation-delay: 0.2s; }
.wave-bar:nth-child(4) { animation-delay: 0.3s; }
.wave-bar:nth-child(5) { animation-delay: 0.4s; }
.wave-bar:nth-child(6) { animation-delay: 0.3s; }
.wave-bar:nth-child(7) { animation-delay: 0.2s; }
.wave-bar:nth-child(8) { animation-delay: 0.1s; }
.wave-bar:nth-child(9) { animation-delay: 0s; }
.wave-bar:nth-child(10) { animation-delay: 0.15s; }
.wave-bar:nth-child(11) { animation-delay: 0.25s; }
.wave-bar:nth-child(12) { animation-delay: 0.35s; }
@keyframes wave-anim { 0% { height: 6px; } 100% { height: 22px; } }

.listening-text { font-size: 11px; color: var(--text-dim); margin-top: 2px; display: none; flex-shrink: 0; }
.listening-text.visible { display: block; }

/* ─── CHAT INPUT ───────────────────────────────────── */
.chat-input-area { width: 100%; max-width: 640px; padding: 0 8px; flex-shrink: 0; }
.chat-bar {
    display: flex; align-items: center; gap: 8px;
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: 14px; padding: 6px 6px 6px 18px;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.chat-bar:focus-within { border-color: var(--gold-dim); box-shadow: 0 0 0 3px var(--gold-glow); }
.chat-bar input {
    flex: 1; background: none; border: none; color: var(--text);
    font-family: inherit; font-size: 14px; outline: none; min-width: 0;
}
.chat-bar input::placeholder { color: var(--text-dim); }
.mic-btn {
    width: 40px; height: 40px; border-radius: 50%; border: none;
    background: var(--bg-glass); font-size: 18px; cursor: pointer;
    transition: all 0.2s; display: flex; align-items: center; justify-content: center;
    flex-shrink: 0; color: inherit;
}
.mic-btn:hover { background: rgba(212, 168, 83, 0.15); }
.mic-btn.recording { background: rgba(239, 68, 68, 0.3); animation: mic-pulse 1s infinite; }
@keyframes mic-pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4); } 50% { box-shadow: 0 0 0 10px rgba(239, 68, 68, 0); } }
.ask-btn {
    display: inline-flex; align-items: center; gap: 6px;
    background: var(--gradient); color: #fff; border: none;
    padding: 10px 22px; border-radius: 10px; font-family: inherit;
    font-size: 14px; font-weight: 700; cursor: pointer; transition: all 0.2s;
    flex-shrink: 0;
}
.ask-btn:hover { opacity: 0.9; transform: translateY(-1px); }
.ask-btn.danger { background: linear-gradient(135deg, #b91c1c, #7f1d1d); }

.topic-tags { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; justify-content: center; }
.tag {
    padding: 6px 14px; border-radius: 20px; font-size: 12px;
    background: var(--bg-glass); border: 1px solid var(--border);
    color: var(--text-dim); cursor: pointer; transition: all 0.2s;
}
.tag:hover { border-color: var(--gold-dim); color: var(--text); }

/* ─── FOOTER ───────────────────────────────────────── */
.app-footer {
    height: var(--footer-h); display: flex; align-items: center; justify-content: center;
    border-top: 1px solid var(--border); background: rgba(10, 11, 20, 0.9);
    flex-shrink: 0;
}
.footer-quote { font-size: 12px; color: var(--gold-dim); letter-spacing: 1px; }
.footer-quote em { color: var(--gold); }

/* ─── ADDED FOR PORTAL: auth pill, conv list, 3D canvas, hints ─── */
.nav-link {
    color: var(--text-dim); padding: 4px 8px; border: 1px solid var(--border);
    border-radius: 8px; font-size: 12px; text-decoration: none; transition: all .2s;
}
.nav-link:hover { color: var(--gold); border-color: var(--gold-dim); }
.auth-pill {
    font-size: 12px; padding: 4px 10px; border: 1px solid var(--border); border-radius: 999px;
    color: var(--text); background: var(--bg-glass); cursor: pointer;
    max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.auth-pill:hover { border-color: var(--gold); }

.conv-list { list-style: none; padding: 0; margin: 8px 0; display: flex; flex-direction: column; gap: 4px; max-height: 220px; overflow-y: auto; }
.conv-list li {
    font-size: 12px; padding: 6px 8px; border-radius: 8px; cursor: pointer;
    border: 1px solid transparent; color: var(--text-dim);
    display: flex; align-items: center; gap: 6px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.conv-list li:hover { background: rgba(212, 168, 83, 0.06); color: var(--text); }
.conv-list li.active { background: rgba(212, 168, 83, 0.12); border-color: var(--border-active); color: var(--text-bright); }
.conv-list li .del { margin-left: auto; opacity: 0.5; flex-shrink: 0; }
.conv-list li .del:hover { opacity: 1; color: #ef4444; }
.conv-list .conv-empty { font-style: italic; color: var(--text-dim); cursor: default; }
.conv-list .conv-empty:hover { background: transparent; color: var(--text-dim); }

.ghost-btn {
    background: transparent; border: 1px solid var(--border); color: var(--gold);
    padding: 6px 10px; border-radius: 8px; cursor: pointer; font-family: inherit; font-size: 12px;
    width: 100%; transition: all .2s;
}
.ghost-btn:hover { border-color: var(--gold); background: rgba(212, 168, 83, 0.06); }

.toggle-mini { display: flex; gap: 6px; align-items: center; font-size: 11px; color: var(--text-dim); cursor: pointer; min-width: 0; }
.toggle-mini input { accent-color: var(--gold); }

.hint {
    margin-top: 8px; font-size: 11px; color: var(--text-dim); text-align: center;
}
.hint a { color: var(--gold); text-decoration: none; border-bottom: 1px dotted var(--gold-dim); }

.footer-links { margin-left: 20px; display: inline-flex; gap: 14px; }
.footer-links a { color: var(--text-dim); font-size: 11px; text-decoration: none; letter-spacing: 1px; text-transform: uppercase; }
.footer-links a:hover { color: var(--gold); }

.cursor-blink::after { content: '▍'; opacity: 0.6; animation: cursor-blink 1s steps(2) infinite; }
@keyframes cursor-blink { 50% { opacity: 0; } }

/* ─── PORTAL PAGES (Auth/Memory/Personalities/Avatars/About/Terms) ── */
.portal-page {
    max-width: 920px; margin: 24px auto; padding: 28px;
    background: var(--bg-panel); border: 1px solid var(--border); border-radius: var(--radius);
    backdrop-filter: blur(16px);
}
.portal-page h1 { font-family: 'Cinzel', serif; color: var(--gold); letter-spacing: 3px; margin-bottom: 6px; }
.portal-page h2 { font-family: 'Cinzel', serif; color: var(--gold-dim); margin-top: 24px; letter-spacing: 2px; font-size: 16px; }
.portal-page p, .portal-page li { color: var(--text); line-height: 1.7; }
.portal-page .muted { color: var(--text-dim); font-size: 13px; }
.portal-page label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-dim); margin-bottom: 10px; }
.portal-page label.row { flex-direction: row; align-items: center; gap: 8px; }
.portal-page input, .portal-page select, .portal-page textarea {
    background: var(--bg-card); border: 1px solid var(--border); border-radius: 8px;
    color: var(--text); padding: 10px; font-family: inherit; font-size: 13px;
}
.portal-page button.primary {
    background: var(--gradient); color: white; border: none;
    padding: 10px 18px; border-radius: 10px; font-weight: 700; cursor: pointer;
}
.portal-page button.primary:hover { opacity: 0.9; }
.portal-page button.ghost {
    background: transparent; border: 1px solid var(--border); color: var(--text);
    padding: 6px 12px; border-radius: 8px; cursor: pointer;
}
.portal-page .auth-tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.portal-page .auth-tabs button {
    flex: 1; padding: 10px; border-radius: 8px; border: 1px solid var(--border);
    background: transparent; color: var(--text-dim); cursor: pointer; font-family: inherit;
}
.portal-page .auth-tabs button.active {
    background: rgba(212, 168, 83, 0.1); color: var(--gold); border-color: var(--gold-dim);
}
.portal-page .auth-form { display: none; flex-direction: column; gap: 8px; }
.portal-page .auth-form.active { display: flex; }
.portal-page .auth-msg { font-size: 12px; color: #ef4444; min-height: 16px; }
.portal-page .auth-msg.ok { color: #22c55e; }

.portal-page .grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px;
}
.portal-page .card {
    background: var(--bg-card); border: 1px solid var(--border); border-radius: 12px; padding: 14px;
    display: flex; flex-direction: column; gap: 6px;
}
.portal-page .card.preset { border-color: var(--gold-dim); }
.portal-page .card.mine { border-color: rgba(108, 58, 237, 0.5); }
.portal-page .card .title { font-weight: 700; color: var(--text-bright); }
.portal-page .card .sub { font-size: 11px; color: var(--text-dim); }
.portal-page .card .swatch { width: 56px; height: 56px; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 32px; }
.portal-page .card .actions { margin-top: auto; display: flex; gap: 8px; }
.portal-page .gate {
    margin-top: 12px; padding: 10px 14px; border: 1px dashed var(--border-active);
    border-radius: 10px; color: var(--gold); background: rgba(212, 168, 83, 0.05); font-size: 13px;
}
.portal-page .row-grid { display: grid; grid-template-columns: 1fr 140px auto; gap: 8px; margin-top: 10px; }
.portal-page .mem-list { list-style: none; padding: 0; display: flex; flex-direction: column; gap: 6px; margin-top: 12px; }
.portal-page .mem-list li {
    display: flex; gap: 12px; align-items: flex-start;
    background: var(--bg-card); border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px;
}
.portal-page .mem-list .kind {
    font-size: 10px; padding: 3px 8px; border-radius: 999px; text-transform: uppercase; letter-spacing: 1px;
    background: rgba(212, 168, 83, 0.1); color: var(--gold); flex-shrink: 0;
}
.portal-page .mem-list .body { flex: 1; }
.portal-page .mem-list .meta { font-size: 11px; color: var(--text-dim); margin-top: 2px; }
.portal-page .mem-list .del { background: transparent; border: none; color: var(--text-dim); font-size: 16px; cursor: pointer; }
.portal-page .mem-list .del:hover { color: #ef4444; }

.portal-topbar { padding: 12px 24px; display: flex; align-items: center; gap: 16px; border-bottom: 1px solid var(--border); }
.portal-topbar a { color: var(--gold); text-decoration: none; font-family: 'Cinzel', serif; letter-spacing: 2px; font-size: 14px; }

/* ─── TYPING DOTS (instant feedback) ──────────────── */
.typing-dots { display: inline-flex; gap: 4px; align-items: center; }
.typing-dots span {
    width: 6px; height: 6px; border-radius: 50%; background: var(--gold);
    animation: typing-bounce 1s infinite ease-in-out;
}
.typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.typing-dots span:nth-child(3) { animation-delay: 0.3s; }
@keyframes typing-bounce {
    0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
    40% { transform: translateY(-4px); opacity: 1; }
}

/* ─── MOBILE NAV ───────────────────────────────────── */
.menu-btn {
    display: none;
    background: var(--bg-glass); border: 1px solid var(--border); color: var(--gold);
    border-radius: 8px; padding: 6px 10px; font-size: 18px; cursor: pointer;
}
.panel-backdrop {
    display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5);
    backdrop-filter: blur(4px); z-index: 80;
}
.panel-backdrop.open { display: block; }

/* ─── RESPONSIVE: TABLET ───────────────────────────── */
@media (max-width: 1100px) {
    .app-grid { grid-template-columns: 200px 1fr 220px; }
    .nav-center { display: none; }
}

/* ─── RESPONSIVE: PHONE ─────────────────────────────── */
@media (max-width: 900px) {
    html, body { overflow: auto; height: auto; min-height: 100%; }
    :root { --footer-h: auto; }
    .nav-center { display: none; }
    .top-nav { padding: 0 12px; gap: 8px; }
    .nav-link, .lang-badge { display: none; }
    .nav-brand span { font-size: 13px; letter-spacing: 1px; }
    .auth-pill { font-size: 11px; padding: 3px 8px; max-width: 110px; }
    .menu-btn { display: inline-flex; align-items: center; justify-content: center; }

    .app-grid {
        display: block; height: auto;
    }
    .panel {
        position: fixed; top: 0; bottom: 0; width: 86%; max-width: 320px;
        z-index: 90; transform: translateX(-105%); transition: transform 0.3s ease;
        background: var(--bg); border-right: 1px solid var(--border);
        padding-top: calc(var(--nav-h) + 8px);
    }
    .panel-right {
        right: 0; left: auto; transform: translateX(105%); border-right: none; border-left: 1px solid var(--border);
    }
    .panel.open { transform: translateX(0); }

    .center-area { padding: 12px 8px 24px; min-height: calc(100vh - var(--nav-h) - 80px); justify-content: flex-start; }
    .avatar-display { margin-bottom: 8px; }
    .avatar-glow { width: 180px; height: 180px; top: 70px; }
    .avatar-figure { font-size: 76px; }
    .avatar-main { width: 180px; height: 140px; }
    .speech-bubble { padding: 12px 16px; max-width: 100%; max-height: 180px; font-size: 13px; }
    .chat-input-area { padding: 0 4px; }
    .chat-bar { padding: 6px 6px 6px 14px; }
    .chat-bar input { font-size: 16px; } /* prevents iOS zoom on focus */
    .ask-btn { padding: 8px 14px; font-size: 12px; }
    .topic-tags { margin-top: 8px; }
    .tag { font-size: 11px; padding: 4px 10px; }
    .main-title { font-size: 20px; letter-spacing: 3px; }
    .footer-links { display: none; }
    .app-footer { height: auto; padding: 10px 8px; text-align: center; }

    .portal-page { margin: 12px; padding: 18px; }
    .portal-page h1 { font-size: 22px; letter-spacing: 2px; }
    .row-grid { grid-template-columns: 1fr; }
}

/* ─── RESPONSIVE: SMALL PHONE ──────────────────────── */
@media (max-width: 480px) {
    .avatar-figure { font-size: 64px; }
    .avatar-main { width: 160px; height: 120px; }
    .avatar-glow { width: 150px; height: 150px; }
    .speech-bubble { max-height: 160px; padding: 10px 14px; }
    #babaText { font-size: 13px; line-height: 1.6; }
    .ask-btn span { display: none; }
    .ask-btn { padding: 8px 12px; }
    .topic-tags .tag:nth-child(n+5) { display: none; }
}

/* iOS safe-area */
@supports (padding: max(0px)) {
    .top-nav { padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right)); }
    .app-footer { padding-bottom: max(8px, env(safe-area-inset-bottom)); }
}
