/* ========================================================
   桃園區農業改良場病蟲害智能客服系統 — 前端公共樣式
   Version: 20260408d  (與 admin.css 同步設計語言)
======================================================== */

/* ---------- Design tokens ---------- */
:root {
    --brand-green: #10b981;
    --brand-dark:  #064e3b;
    --brand-teal:  #14b8a6;
    --bg-body:     #0f172a;
    --bg-card:     rgba(30,41,59,.72);
    --bg-sidebar:  rgba(15,23,42,.92);
    --border:      rgba(148,163,184,.12);
    --text-main:   #e2e8f0;
    --text-muted:  #94a3b8;
    --glass-blur:  12px;
    --radius:      14px;
    --radius-sm:   8px;
    --shadow:      0 8px 32px rgba(0,0,0,.35);
    --transition:  .25s cubic-bezier(.4,0,.2,1);
}

/* ---------- Global ---------- */
*, *::before, *::after { box-sizing: border-box; }
body {
    font-family: "Microsoft JhengHei", "Noto Sans TC", system-ui, sans-serif;
    background: var(--bg-body);
    color: var(--text-main);
    margin: 0;
    min-height: 100vh;
}
a { color: var(--brand-green); text-decoration: none; }
a:hover { color: var(--brand-teal); }

/* ========  TOP NAVBAR  ======== */
.top-navbar {
    position: sticky; top: 0; z-index: 100;
    background: rgba(15,23,42,.85);
    backdrop-filter: blur(var(--glass-blur));
    border-bottom: 1px solid var(--border);
    padding: 0 1.5rem;
    height: 56px;
}
.top-navbar-inner {
    max-width: 1320px; margin: 0 auto;
    display: flex; align-items: center; height: 100%; gap: 1.2rem;
}
.top-navbar-brand {
    display: flex; align-items: center; gap: .6rem;
    font-weight: 700; font-size: 1.05rem; color: #fff;
    text-decoration: none; white-space: nowrap;
}
.brand-icon {
    width: 34px; height: 34px; border-radius: 8px;
    background: linear-gradient(135deg, var(--brand-green), var(--brand-teal));
    display: grid; place-items: center; font-size: 1.1rem; color: #fff;
}
.top-navbar-links { display: flex; gap: .25rem; margin-left: .5rem; }
.nav-link-item {
    color: var(--text-muted); font-size: .88rem; font-weight: 500;
    padding: .45rem .85rem; border-radius: var(--radius-sm);
    transition: var(--transition); text-decoration: none;
}
.nav-link-item:hover, .nav-link-item.active { color: #fff; background: rgba(255,255,255,.06); }
.top-navbar-right { margin-left: auto; display: flex; align-items: center; gap: .5rem; }
.admin-link { border: 1px solid var(--border); border-radius: var(--radius-sm); }

/* ========  FOOTER  ======== */
.site-footer {
    background: rgba(15,23,42,.92); border-top: 1px solid var(--border);
    padding: 2rem 0; text-align: center;
}
.footer-inner { max-width: 1320px; margin: 0 auto; padding: 0 1.5rem; }
.footer-brand { font-weight: 700; font-size: 1rem; color: var(--text-main); margin-bottom: .3rem; }
.footer-sub  { font-size: .82rem; color: var(--text-muted); margin-bottom: .5rem; }
.footer-copy { font-size: .78rem; color: var(--text-muted); opacity: .7; }

/* ========  HERO SECTION  ======== */
.hero-section {
    position: relative; overflow: hidden;
    padding: 5rem 1.5rem 4rem; text-align: center;
    background: linear-gradient(135deg, #064e3b 0%, #0f172a 60%, #1e293b 100%);
}
.hero-bg-pattern {
    position: absolute; inset: 0; opacity: .06;
    background-image: radial-gradient(circle at 20% 50%, var(--brand-green) 1.5px, transparent 1.5px),
                       radial-gradient(circle at 80% 30%, var(--brand-teal) 1px, transparent 1px);
    background-size: 40px 40px, 60px 60px;
}
.hero-content { position: relative; z-index: 1; max-width: 720px; margin: 0 auto; }
.hero-icon {
    width: 72px; height: 72px; border-radius: 18px; margin: 0 auto 1.5rem;
    background: linear-gradient(135deg, var(--brand-green), var(--brand-teal));
    display: grid; place-items: center; font-size: 2rem; color: #fff;
    box-shadow: 0 0 40px rgba(16,185,129,.3);
}
.hero-title { font-size: 2.2rem; font-weight: 800; color: #fff; margin-bottom: .75rem; letter-spacing: -.02em; }
.hero-subtitle { font-size: 1.05rem; color: var(--text-muted); margin-bottom: 2rem; line-height: 1.7; }

/* Hero search */
.hero-search { max-width: 560px; margin: 0 auto; }
.hero-search-wrap {
    display: flex; align-items: center; gap: .5rem;
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: 999px; padding: .35rem .5rem .35rem 1.2rem;
    backdrop-filter: blur(var(--glass-blur));
    transition: var(--transition);
}
.hero-search-wrap:focus-within { border-color: var(--brand-green); box-shadow: 0 0 0 3px rgba(16,185,129,.15); }
.hero-search-wrap > i { color: var(--text-muted); font-size: 1rem; }
.hero-search-input {
    flex: 1; background: none; border: none; outline: none;
    color: #fff; font-size: .95rem; padding: .5rem .25rem;
}
.hero-search-input::placeholder { color: var(--text-muted); }
.hero-search-btn {
    background: linear-gradient(135deg, var(--brand-green), var(--brand-teal));
    border: none; border-radius: 999px; color: #fff; font-weight: 600;
    padding: .55rem 1.4rem; font-size: .88rem; cursor: pointer;
    transition: var(--transition); white-space: nowrap;
}
.hero-search-btn:hover { filter: brightness(1.1); transform: translateY(-1px); }

/* ========  SECTIONS  ======== */
.section-container { max-width: 1100px; margin: 0 auto; padding: 0 1.5rem; }
.section-header {
    display: flex; align-items: center; gap: .6rem; justify-content: center;
    margin-bottom: 2.5rem;
}
.section-header i { font-size: 1.3rem; color: var(--brand-green); }
.section-header h2 { font-size: 1.5rem; font-weight: 700; color: #fff; margin: 0; }

.services-section { padding: 4rem 0; }
.faq-section { padding: 4rem 0; background: rgba(15,23,42,.55); }
.features-section { padding: 4rem 0; }

/* ========  SERVICE CARDS  ======== */
.services-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.5rem; align-items: start;
}
.home-primary-services {
    grid-template-columns: repeat(2, minmax(280px, 420px));
    justify-content: center;
}
.service-card {
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 2rem 1.5rem;
    text-align: center; cursor: pointer;
    backdrop-filter: blur(var(--glass-blur));
    transition: var(--transition);
}
.service-card-summary { min-height: 172px; display: flex; flex-direction: column; }
.service-card:hover {
    transform: translateY(-4px);
    border-color: var(--brand-green);
    box-shadow: 0 12px 32px rgba(16,185,129,.12);
}
.service-card:focus-visible {
    outline: 3px solid rgba(16,185,129,.45);
    outline-offset: 3px;
    border-color: var(--brand-green);
}
.service-card-icon {
    width: 56px; height: 56px; border-radius: 14px; margin: 0 auto 1rem;
    display: grid; place-items: center; font-size: 1.5rem;
}
.service-card-icon.svc-blue    { background: linear-gradient(135deg,#3b82f6,#60a5fa); color:#fff; }
.service-card-icon.svc-amber   { background: linear-gradient(135deg,#f59e0b,#fbbf24); color:#fff; }
.service-card-icon.svc-emerald { background: linear-gradient(135deg,#10b981,#34d399); color:#fff; }
.service-card-icon.svc-violet  { background: linear-gradient(135deg,#8b5cf6,#a78bfa); color:#fff; }
.service-card-title { font-size: 1.05rem; font-weight: 600; color: #fff; margin-bottom: .5rem; }
.service-card-desc  { font-size: .85rem; color: var(--text-muted); line-height: 1.6; margin: 0; }
.service-card-toggle {
    display: flex; align-items: center; justify-content: center; gap: .45rem;
    margin-top: auto; padding-top: 1rem; color: var(--brand-green);
    font-size: .8rem; font-weight: 600;
}
.service-card-toggle .bi-arrow-right { transition: transform .2s ease; }
.service-card:hover .service-card-toggle .bi-arrow-right { transform: translateX(4px); }
.service-question-list {
    display: grid; gap: .55rem; margin-top: 1rem; padding-top: 1rem;
    border-top: 1px solid var(--border); text-align: left;
    max-height: 470px; overflow-y: auto; padding-right: .25rem;
}
.service-question-list::-webkit-scrollbar { width: 5px; }
.service-question-list::-webkit-scrollbar-thumb {
    background: rgba(148,163,184,.45); border-radius: 999px;
}
.service-question-btn {
    width: 100%; display: grid; grid-template-columns: auto 1fr auto;
    align-items: center; gap: .6rem; padding: .72rem .8rem;
    background: rgba(15,23,42,.56); border: 1px solid var(--border);
    border-radius: 10px; color: #dbe6f5; font-size: .82rem;
    line-height: 1.45; text-align: left; cursor: pointer;
    transition: var(--transition);
}
.service-question-btn .bi-chat-left-text { color: var(--brand-green); }
.service-question-btn .bi-arrow-right { color: var(--text-muted); }
.service-question-btn:hover {
    color: #fff; border-color: var(--brand-green);
    background: rgba(16,185,129,.1); transform: translateX(2px);
}
.service-avatar-btn {
    padding: .75rem 1rem; border: 0; border-radius: 10px;
    background: linear-gradient(135deg, var(--brand-green), #2563eb);
    color: #fff; font-size: .84rem; font-weight: 600; cursor: pointer;
}
.service-avatar-btn:hover { filter: brightness(1.08); }

/* ========  FAQ  ======== */
.faq-list { max-width: 760px; margin: 0 auto; }
.faq-item {
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius-sm); margin-bottom: .75rem;
    overflow: hidden; cursor: pointer;
    transition: var(--transition);
}
.faq-item:hover { border-color: var(--brand-green); }
.faq-question {
    display: flex; align-items: center; justify-content: space-between;
    padding: 1rem 1.25rem; font-weight: 600; font-size: .95rem; color: #fff;
}
.faq-question i { font-size: .8rem; color: var(--text-muted); flex-shrink: 0; }
.faq-answer {
    padding: 0 1.25rem 1.1rem; font-size: .88rem; color: var(--text-muted);
    line-height: 1.7; border-top: 1px solid var(--border);
    padding-top: .9rem;
}
.faq-answer ol, .faq-answer ul { padding-left: 1.2rem; margin: .5rem 0; }

/* ========  FEATURES  ======== */
.features-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 1.25rem;
}
.feature-card {
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 1.75rem 1.25rem; text-align: center;
    backdrop-filter: blur(var(--glass-blur)); transition: var(--transition);
}
.feature-card:hover { border-color: var(--brand-green); transform: translateY(-3px); }
.feature-icon {
    width: 50px; height: 50px; border-radius: 12px; margin: 0 auto .9rem;
    display: grid; place-items: center; font-size: 1.3rem; color: #fff;
}
.feat-blue    { background: linear-gradient(135deg,#3b82f6,#60a5fa); }
.feat-emerald { background: linear-gradient(135deg,#10b981,#34d399); }
.feat-violet  { background: linear-gradient(135deg,#8b5cf6,#a78bfa); }
.feat-amber   { background: linear-gradient(135deg,#f59e0b,#fbbf24); }
.feature-card h5 { font-size: 1rem; font-weight: 600; color: #fff; margin-bottom: .4rem; }
.feature-card p  { font-size: .82rem; color: var(--text-muted); margin: 0; line-height: 1.5; }

/* ================================================================
   CHAT PAGE
================================================================ */
.chat-page {
    display: flex; height: calc(100vh - 56px); overflow: hidden;
}
@supports (height: 100dvh) {
    .chat-page { height: calc(100dvh - 56px); }
}
/* hide footer on chat page */
.chat-page ~ .site-footer { display: none; }

/* -- Sidebar -- */
.chat-sidebar {
    width: 280px; flex-shrink: 0; display: flex; flex-direction: column;
    background: var(--bg-sidebar); border-right: 1px solid var(--border);
}
.chat-sidebar-header {
    padding: 1rem 1.1rem .6rem; font-size: .82rem; font-weight: 600;
    color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em;
    border-bottom: 1px solid var(--border);
}
.chat-sidebar-body { flex: 1; overflow-y: auto; padding: .5rem; }
.suggest-btn {
    display: flex; align-items: flex-start; gap: .5rem; width: 100%;
    background: none; border: 1px solid transparent; border-radius: var(--radius-sm);
    padding: .6rem .75rem; font-size: .82rem; color: var(--text-muted);
    text-align: left; cursor: pointer; transition: var(--transition);
}
.suggest-btn i { flex-shrink: 0; margin-top: 2px; color: var(--brand-green); }
.suggest-btn:hover { background: rgba(255,255,255,.04); border-color: var(--border); color: #fff; }

.chat-sidebar-footer { padding: .75rem; border-top: 1px solid var(--border); }
.voice-btn {
    width: 100%; padding: .6rem; border: 1px solid var(--brand-green);
    border-radius: var(--radius-sm); background: rgba(16,185,129,.08);
    color: var(--brand-green); font-weight: 600; font-size: .85rem;
    cursor: pointer; transition: var(--transition);
}
.voice-btn:hover { background: rgba(16,185,129,.15); }
.voice-btn.recording { background: rgba(239,68,68,.12); border-color: #ef4444; color: #ef4444; animation: pulse 1.2s infinite; }
.voice-transcript {
    margin-top: .6rem; padding: .55rem .75rem; font-size: .8rem;
    background: rgba(56,189,248,.08); border: 1px solid rgba(56,189,248,.18);
    border-radius: var(--radius-sm); color: #7dd3fc;
}

/* -- Main area -- */
.chat-main-area {
    flex: 1; display: flex; flex-direction: column; min-width: 0; overflow: hidden;
    background: var(--bg-body);
}
.chat-messages { flex: 1; overflow-y: auto; padding: 1.5rem 2rem; min-height: 0; }

/* Welcome */
.chat-welcome { text-align: center; padding: 4rem 1rem; }
.chat-welcome-icon {
    width: min(220px, 62vw); aspect-ratio: 1; border-radius: 22px; margin: 0 auto 1.5rem;
    background: transparent;
    display: grid; place-items: center; font-size: 2rem; color: #fff;
    box-shadow: 0 0 40px rgba(16,185,129,.25);
    overflow: hidden;
}
.chat-welcome h3 { font-size: 1.4rem; font-weight: 700; color: #fff; margin-bottom: .5rem; }
.chat-welcome p  { color: var(--text-muted); font-size: .92rem; }
.chat-welcome-tags { display: flex; flex-wrap: wrap; gap: .5rem; justify-content: center; margin-top: 1.25rem; }
.welcome-tag {
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: 999px; padding: .45rem 1rem; font-size: .82rem;
    color: var(--text-muted); cursor: pointer; transition: var(--transition);
}
.welcome-tag:hover { border-color: var(--brand-green); color: #fff; }
.chat-topic-nav {
    display: grid;
    grid-template-columns: repeat(5, minmax(150px, 1fr));
    width: min(1100px, 100%);
    margin-inline: auto;
}
.chat-topic-tag {
    min-height: 48px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .45rem;
    border-radius: 12px;
    white-space: nowrap;
}
.chat-topic-tag i { color: var(--brand-green); }
.chat-topic-tag.active {
    border-color: var(--brand-green);
    background: rgba(16,185,129,.14);
    color: #fff;
    box-shadow: 0 0 0 2px rgba(16,185,129,.08);
}

/* Messages */
.msg-row { display: flex; align-items: flex-start; gap: .6rem; margin-bottom: 1.2rem; }
.msg-row.msg-user { justify-content: flex-end; }
.msg-avatar {
    width: 72px; height: 72px; border-radius: 14px; flex-shrink: 0;
    display: grid; place-items: center; font-size: 1rem; color: #fff;
    overflow: hidden;
}
.msg-row.msg-ai .msg-avatar { background: #16352f; border: 1px solid rgba(94,234,212,.38); }
.msg-row.msg-user .msg-avatar {
    background: linear-gradient(135deg,#6366f1,#818cf8);
    border: 2px solid rgba(129,140,248,.88);
    box-shadow: 0 8px 24px rgba(79,70,229,.22);
}
.director-chat-avatar {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: contain;
    object-position: center;
}
.customer-chat-avatar {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: cover;
    object-position: center;
}

.msg-bubble {
    max-width: 72%; padding: .9rem 1.15rem; border-radius: var(--radius);
    line-height: 1.7; word-break: break-word; white-space: pre-wrap; font-size: .9rem;
}
.bubble-user {
    background: linear-gradient(135deg, var(--brand-green), var(--brand-teal));
    color: #fff; border-bottom-right-radius: 4px;
}
.chat-user-role { margin-bottom: .25rem; font-size: .7rem; font-weight: 800; color: rgba(255,255,255,.78); }
.bubble-ai {
    background: var(--bg-card); border: 1px solid var(--border);
    color: var(--text-main); border-bottom-left-radius: 4px;
    backdrop-filter: blur(var(--glass-blur));
}
.answer-section-title { margin: .85rem 0 .45rem; padding: .35rem .6rem; border-left: 3px solid var(--brand-green); border-radius: 0 7px 7px 0; background: rgba(16,185,129,.09); color: var(--brand-green); font-size: .9rem; font-weight: 800; letter-spacing: .02em; }
.answer-section-title:first-child { margin-top: 0; }
.answer-bullet { display: flex; gap: .4rem; align-items: flex-start; margin: .38rem 0; color: inherit; }
.answer-bullet i { color: var(--brand-green); font-size: 1rem; line-height: 1.55; flex: 0 0 auto; }
.answer-paragraph { margin: .34rem 0; }

/* Sources */
.msg-sources {
    margin-top: .7rem; padding-top: .6rem; border-top: 1px solid var(--border);
    font-size: .8rem;
}
.msg-sources-label { color: var(--text-muted); font-weight: 600; }
.msg-source-item {
    color: var(--text-muted); padding: .35rem .55rem; margin-top: .35rem;
    border-radius: 6px; cursor: pointer; transition: var(--transition);
    border: 1px solid transparent;
}
.msg-source-item:hover { background: rgba(16,185,129,.06); border-color: var(--border); }
.source-header { display: flex; align-items: center; gap: .4rem; }
.source-header i { color: var(--brand-green); flex-shrink: 0; font-size: .85rem; }
.source-title { flex: 1; }
.source-page { font-size: .75rem; color: var(--brand-green); white-space: nowrap; }
.source-cat { font-size: .75rem; opacity: .7; white-space: nowrap; }
.source-web-tag { font-size: .68rem; color: var(--brand-teal); border: 1px solid rgba(20,184,166,.45); border-radius: 999px; padding: .05rem .35rem; white-space: nowrap; }
.source-link { display: inline-block; margin: .4rem .1rem 0; color: var(--brand-green); font-size: .76rem; text-decoration: none; }
.source-link:hover { text-decoration: underline; }
.source-image { display: block; width: min(360px, 100%); max-height: 240px; object-fit: cover; border-radius: 8px; margin: .55rem 0 0 .15rem; border: 1px solid var(--border); background: #fff; }
.source-excerpt {
    margin-top: .4rem; padding: .55rem .7rem;
    background: rgba(16,185,129,.05); border-radius: 6px;
    font-size: .78rem; line-height: 1.6; color: var(--text-secondary);
    border-left: 3px solid var(--brand-green);
    white-space: pre-wrap; word-break: break-word;
}

/* Feedback */
.msg-feedback { margin-top: .6rem; padding-top: .5rem; border-top: 1px solid var(--border); font-size: .8rem; color: var(--text-muted); }
.fb-btn {
    background: none; border: 1px solid var(--border); border-radius: 6px;
    padding: .25rem .55rem; font-size: .82rem; cursor: pointer; margin-left: .35rem;
    transition: var(--transition); color: var(--text-muted);
}
.fb-btn.fb-up:hover  { color: var(--brand-green); border-color: var(--brand-green); background: rgba(16,185,129,.08); }
.fb-btn.fb-down:hover { color: #ef4444; border-color: #ef4444; background: rgba(239,68,68,.08); }
.msg-feedback-done { margin-top: .5rem; font-size: .8rem; color: var(--brand-green); }

/* -- Input bar -- */
.chat-input-bar {
    padding: .85rem 1.5rem; border-top: 1px solid var(--border);
    background: var(--bg-sidebar);
}
.chat-audience-selector,
.chat-cultivation-selector {
    display: flex;
    align-items: center;
    gap: .45rem;
    margin: 0 0 .55rem;
    padding: 0;
    border: 0;
    min-width: 0;
}
.chat-audience-selector legend,
.chat-cultivation-selector legend {
    float: none;
    width: auto;
    margin: 0 .15rem 0 0;
    padding: 0;
    color: var(--text-secondary);
    font-size: .76rem;
    font-weight: 800;
    white-space: nowrap;
}
.chat-audience-selector legend i,
.chat-cultivation-selector legend i { color: var(--brand-green); margin-right: .2rem; }
.chat-audience-option,
.chat-cultivation-option {
    display: inline-flex;
    align-items: center;
    gap: .28rem;
    padding: .3rem .62rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--text-muted);
    font-size: .75rem;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
}
.chat-audience-option:hover,
.chat-cultivation-option:hover { border-color: var(--brand-green); color: var(--text-main); }
.chat-audience-option.selected,
.chat-cultivation-option.selected { border-color: var(--brand-green); background: rgba(16,185,129,.13); color: #d1fae5; }
.chat-audience-option input,
.chat-cultivation-option input { margin: 0; accent-color: var(--brand-green); }
.chat-audience-selector small,
.chat-cultivation-selector small { margin-left: auto; color: var(--text-muted); font-size: .7rem; white-space: nowrap; }
.chat-audience-selector:disabled,
.chat-cultivation-selector:disabled { opacity: .58; }
.chat-input-wrap {
    display: flex; align-items: center; gap: .5rem;
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: 999px; padding: .3rem .5rem .3rem 1rem;
    transition: var(--transition);
}
.chat-input-wrap:focus-within { border-color: var(--brand-green); box-shadow: 0 0 0 3px rgba(16,185,129,.12); }
.chat-image-input { display: none; }
.chat-attach-btn {
    width: 36px; height: 36px; border-radius: 50%; border: 0; background: transparent;
    color: var(--brand-green); cursor: pointer; font-size: 1.05rem; flex-shrink: 0;
}
.response-image-section { margin-top: .9rem; padding: .85rem; border-radius: 12px; background: linear-gradient(135deg, rgba(16,185,129,.09), rgba(37,99,235,.05)); border: 1px solid rgba(16,185,129,.24); }
.response-image-label { color: var(--brand-green); font-size: .8rem; font-weight: 700; margin-bottom: .55rem; }
.response-image-card { display: inline-flex; flex-direction: column; width: min(240px, 100%); margin: 0 .6rem .25rem 0; padding: .38rem; color: var(--text-main); text-decoration: none; vertical-align: top; border-radius: 10px; background: rgba(15,23,42,.24); }
.response-image-card img { width: 100%; aspect-ratio: 4 / 3; height: auto; object-fit: contain; border-radius: 8px; border: 1px solid var(--border); background: #071225; }
.response-image-card span { margin: .45rem .2rem .18rem; font-size: .78rem; line-height: 1.35; color: var(--text-secondary); }
.response-image-card:hover span { color: var(--brand-green); text-decoration: underline; }
.chat-attach-btn:hover { background: rgba(16,185,129,.1); }
.chat-attach-btn:disabled { opacity: .45; cursor: not-allowed; }
.chat-textarea {
    flex: 1; background: none; border: none; outline: none;
    color: #fff; font-size: .9rem; resize: none; max-height: 100px;
    padding: .45rem 0;
}
.chat-textarea::placeholder { color: var(--text-muted); }
.chat-send-btn {
    width: 40px; height: 40px; border-radius: 50%; border: none;
    background: linear-gradient(135deg, var(--brand-green), var(--brand-teal));
    color: #fff; font-size: 1rem; cursor: pointer; flex-shrink: 0;
    display: grid; place-items: center; transition: var(--transition);
}
.chat-send-btn:hover { filter: brightness(1.1); }
.chat-send-btn:disabled { opacity: .4; cursor: not-allowed; }
.chat-mic-btn {
    width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--brand-green);
    background: transparent; color: var(--brand-green); font-size: 1rem;
    cursor: pointer; flex-shrink: 0; display: grid; place-items: center;
}
.chat-disclaimer { font-size: .75rem; color: var(--text-muted); margin-top: .45rem; padding-left: .5rem; }
.web-search-toggle { float: right; cursor: pointer; color: var(--text-secondary); }
.web-search-toggle input { accent-color: var(--brand-green); vertical-align: middle; }
.chat-pending-image { display: flex; align-items: center; gap: .5rem; margin: .5rem .5rem 0; color: var(--text-secondary); font-size: .78rem; }
.chat-pending-image img, .chat-upload-preview { width: 88px; height: 64px; object-fit: cover; border-radius: 7px; border: 1px solid var(--border); }
.chat-pending-image button { border: 0; background: transparent; color: var(--text-muted); cursor: pointer; }
.chat-upload-preview { display: block; width: min(250px, 100%); height: auto; max-height: 220px; margin-top: .55rem; }

/* Typing indicator */
.typing-indicator span {
    display: inline-block; width: 8px; height: 8px;
    background: var(--brand-green); border-radius: 50%; margin: 0 2px;
    animation: typingBounce .6s infinite alternate;
}
.typing-indicator span:nth-child(2) { animation-delay: .2s; }
.typing-indicator span:nth-child(3) { animation-delay: .4s; }
@keyframes typingBounce { to { opacity: .3; transform: translateY(-4px); } }

/* Recording pulse */
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .4; } }

/* ========  LOGIN PAGE  ======== */
.login-page {
    min-height: calc(100vh - 56px); display: flex; align-items: center; justify-content: center;
    background: var(--bg-body); padding: 2rem;
}
.login-card {
    width: 400px; border: 1px solid var(--border); border-radius: var(--radius);
    background: var(--bg-card); backdrop-filter: blur(var(--glass-blur));
    box-shadow: var(--shadow);
}
.login-card-inner { padding: 2.5rem 2rem; text-align: center; }
.login-icon {
    width: 64px; height: 64px; border-radius: 16px; margin: 0 auto 1.2rem;
    background: linear-gradient(135deg, var(--brand-green), var(--brand-teal));
    display: grid; place-items: center; font-size: 1.8rem; color: #fff;
    box-shadow: 0 0 32px rgba(16,185,129,.25);
}
.login-title { font-size: 1.25rem; font-weight: 700; color: #fff; margin-bottom: 1.5rem; }
.login-error {
    background: rgba(239,68,68,.1); border: 1px solid rgba(239,68,68,.25);
    border-radius: var(--radius-sm); padding: .6rem .9rem; margin-bottom: 1rem;
    font-size: .85rem; color: #fca5a5;
}
.login-field { margin-bottom: 1.1rem; text-align: left; }
.login-field label { display: block; font-size: .82rem; font-weight: 600; color: var(--text-muted); margin-bottom: .35rem; }
.login-field input {
    width: 100%; background: rgba(255,255,255,.05); border: 1px solid var(--border);
    border-radius: var(--radius-sm); padding: .65rem .9rem; color: #fff; font-size: .9rem;
    outline: none; transition: var(--transition);
}
.login-field input:focus { border-color: var(--brand-green); box-shadow: 0 0 0 3px rgba(16,185,129,.12); }
.login-field input::placeholder { color: var(--text-muted); }
.login-submit {
    width: 100%; padding: .7rem; border: none; border-radius: var(--radius-sm);
    background: linear-gradient(135deg, var(--brand-green), var(--brand-teal));
    color: #fff; font-weight: 700; font-size: .95rem; cursor: pointer;
    margin-top: .5rem; transition: var(--transition);
}
.login-submit:hover { filter: brightness(1.1); transform: translateY(-1px); }
.login-submit:disabled { opacity: .5; cursor: not-allowed; }

/* ================================================================
   DIGITAL HUMAN PAGE
================================================================ */
.avatar-page {
    min-height: calc(100vh - 56px);
    background:
        radial-gradient(circle at 18% 18%, rgba(20,184,166,.18), transparent 28%),
        linear-gradient(135deg, #111827 0%, #0f172a 48%, #172554 100%);
}
.avatar-page ~ .site-footer { display: none; }
#homeApp ~ .site-footer { display: none; }
.avatar-stage {
    min-height: calc(100vh - 56px);
    padding: 1.2rem 1.4rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}
.avatar-scene-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    max-width: 1440px;
    width: 100%;
    margin: 0 auto;
}
.avatar-kicker {
    color: #5eead4;
    font-size: .78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .12em;
}
.avatar-scene-bar h1 {
    margin: .15rem 0 0;
    color: #fff;
    font-size: 1.35rem;
    font-weight: 800;
}
.avatar-scene-controls { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: .5rem; }
.avatar-select {
    border: 1px solid rgba(148,163,184,.24);
    border-radius: 8px;
    background: rgba(15,23,42,.78);
    color: #e2e8f0;
    padding: .5rem .8rem;
    outline: none;
}
.avatar-model-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .35rem;
    min-height: 39px;
    border: 1px solid rgba(94,234,212,.34);
    border-radius: 8px;
    padding: .48rem .72rem;
    background: rgba(13,148,136,.17);
    color: #ccfbf1;
    font: inherit;
    font-size: .88rem;
    font-weight: 700;
    cursor: pointer;
}
.avatar-model-action:hover { background: rgba(13,148,136,.3); }
.avatar-model-action.disabled,
.avatar-model-action:disabled { opacity: .5; cursor: not-allowed; }
.avatar-model-upload input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.avatar-model-delete {
    border-color: rgba(248,113,113,.38);
    background: rgba(127,29,29,.24);
    color: #fecaca;
}
.avatar-model-delete:hover { background: rgba(153,27,27,.38); }
.avatar-model-owned-hint {
    color: #94a3b8;
    font-size: .78rem;
}
.avatar-model-feedback {
    flex: 0 0 100%;
    color: #cbd5e1;
    text-align: right;
    font-size: .84rem;
}
.avatar-model-feedback.success { color: #5eead4; }
.avatar-model-feedback.error { color: #fca5a5; }
.avatar-layout {
    flex: 1;
    min-height: 0;
    max-width: 1440px;
    width: 100%;
    margin: 0 auto;
    display: grid;
    grid-template-columns: minmax(300px, .9fr) minmax(380px, 1.15fr) minmax(400px, 1fr);
    grid-template-rows: minmax(720px, calc(100vh - 180px));
    gap: 1.2rem;
}
.digital-human-wrap {
    /* 單一大型 3D 舞台：左右功能卡片疊在舞台內的空白處。 */
    grid-column: 1 / -1;
    grid-row: 1;
    position: relative;
    top: auto;
    align-self: stretch;
    overflow: hidden;
    contain: paint;
    isolation: isolate;
    z-index: 0;
    border: 1px solid rgba(148,163,184,.16);
    border-radius: 8px;
    background:
        linear-gradient(180deg, rgba(15,23,42,.18), rgba(15,23,42,.82)),
        repeating-linear-gradient(90deg, rgba(148,163,184,.06), rgba(148,163,184,.06) 1px, transparent 1px, transparent 80px);
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 0;
    touch-action: none;
    overscroll-behavior: contain;
    user-select: none;
    -webkit-user-select: none;
}
.digital-human {
    position: relative;
    width: min(360px, 62vw);
    height: 520px;
    transform-origin: 50% 70%;
    animation: avatarBreath 3.2s ease-in-out infinite;
}
.digital-human.thinking { animation: avatarThinking 1.2s ease-in-out infinite; }
.digital-human.listening .avatar-halo { box-shadow: 0 0 0 18px rgba(94,234,212,.08), 0 0 80px rgba(94,234,212,.34); }
.digital-human.speaking .avatar-head { animation: avatarTalk 1.4s ease-in-out infinite; }
.avatar-halo {
    position: absolute;
    left: 50%;
    top: 16px;
    width: 250px;
    height: 250px;
    border-radius: 50%;
    transform: translateX(-50%);
    background: radial-gradient(circle, rgba(94,234,212,.22), transparent 68%);
}
.avatar-head {
    position: absolute;
    top: 62px;
    left: 50%;
    width: 190px;
    height: 220px;
    transform: translateX(-50%);
    z-index: 2;
}
.avatar-hair {
    position: absolute;
    inset: 0;
    border-radius: 48% 48% 44% 44%;
    background: linear-gradient(135deg, #1f2937, #111827);
}
.avatar-face {
    position: absolute;
    left: 17px;
    right: 17px;
    top: 26px;
    bottom: 8px;
    border-radius: 46% 46% 48% 48%;
    background: linear-gradient(180deg, #f4c7a7, #d99a78);
    box-shadow: inset 0 -12px 24px rgba(120,53,15,.18);
}
.avatar-brow,
.avatar-eye,
.avatar-nose,
.avatar-mouth { position: absolute; left: 50%; }
.avatar-brow {
    top: 66px;
    width: 38px;
    height: 5px;
    border-radius: 999px;
    background: #4b2e23;
}
.avatar-brow-left { transform: translateX(-54px) rotate(-5deg); }
.avatar-brow-right { transform: translateX(16px) rotate(5deg); }
.avatar-eye {
    top: 84px;
    width: 22px;
    height: 14px;
    border-radius: 50%;
    background: #1f2937;
    box-shadow: inset 0 4px 0 rgba(255,255,255,.12);
}
.avatar-eye-left { transform: translateX(-43px); }
.avatar-eye-right { transform: translateX(23px); }
.avatar-nose {
    top: 106px;
    width: 16px;
    height: 32px;
    transform: translateX(-50%);
    border-radius: 50%;
    border-right: 3px solid rgba(120,53,15,.3);
}
.avatar-mouth {
    top: 154px;
    width: 46px;
    height: 12px;
    transform: translateX(-50%);
    border-radius: 0 0 999px 999px;
    background: #7f1d1d;
    transition: width .08s linear, height .08s linear, border-radius .08s linear;
}
.mouth-closed .avatar-mouth { width: 42px; height: 5px; border-radius: 999px; }
.mouth-mid .avatar-mouth { width: 42px; height: 16px; border-radius: 0 0 999px 999px; }
.mouth-open .avatar-mouth { width: 38px; height: 34px; border-radius: 50%; }
.mouth-wide .avatar-mouth { width: 58px; height: 13px; border-radius: 999px; }
.mouth-round .avatar-mouth { width: 30px; height: 30px; border-radius: 50%; }
.avatar-neck {
    position: absolute;
    top: 260px;
    left: 50%;
    width: 70px;
    height: 76px;
    transform: translateX(-50%);
    background: #d99a78;
    border-radius: 0 0 24px 24px;
}
.avatar-body {
    position: absolute;
    top: 318px;
    left: 50%;
    width: 300px;
    height: 210px;
    transform: translateX(-50%);
    border-radius: 80px 80px 20px 20px;
    background: linear-gradient(135deg, #0f766e, #1e40af);
    box-shadow: 0 24px 70px rgba(0,0,0,.32);
}
.avatar-lapel {
    position: absolute;
    top: 26px;
    width: 84px;
    height: 120px;
    background: rgba(255,255,255,.88);
    clip-path: polygon(0 0, 100% 0, 62% 100%);
}
.avatar-lapel-left { left: 70px; transform: skewX(-9deg); }
.avatar-lapel-right { right: 70px; transform: scaleX(-1) skewX(-9deg); }
.avatar-badge {
    position: absolute;
    right: 62px;
    top: 72px;
    width: 46px;
    height: 46px;
    border-radius: 8px;
    display: grid;
    place-items: center;
    background: rgba(15,23,42,.78);
    border: 1px solid rgba(255,255,255,.2);
    color: #5eead4;
    font-weight: 800;
}
.avatar-expression-positive .avatar-mouth { box-shadow: 0 5px 0 -2px rgba(255,255,255,.16); }
.avatar-expression-serious .avatar-brow-left { transform: translateX(-54px) rotate(7deg); }
.avatar-expression-serious .avatar-brow-right { transform: translateX(16px) rotate(-7deg); }
.avatar-expression-concerned .avatar-brow-left { transform: translateX(-54px) rotate(10deg); }
.avatar-expression-concerned .avatar-brow-right { transform: translateX(16px) rotate(-10deg); }
.gesture-refer_to_source .avatar-body,
.gesture-explain_steps .avatar-body,
.gesture-important_reminder .avatar-body { filter: brightness(1.15); }
.realistic-avatar {
    width: min(760px, 82vw);
    height: min(760px, calc(100vh - 180px));
    min-height: 560px;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    animation: avatarBreath 4.6s ease-in-out infinite;
    overflow: hidden;
}
.realistic-avatar::before {
    content: "";
    position: absolute;
    left: 50%;
    bottom: 1.5rem;
    width: 78%;
    height: 36%;
    transform: translateX(-50%);
    border-radius: 50%;
    background: radial-gradient(circle, rgba(15,23,42,.48), rgba(15,23,42,.15) 54%, transparent 73%);
    filter: blur(18px);
    z-index: 1;
}
.realistic-avatar .avatar-backlight {
    position: absolute;
    left: 50%;
    bottom: 4.5rem;
    width: 72%;
    height: 80%;
    transform: translateX(-50%);
    border-radius: 42% 42% 24% 24%;
    background: radial-gradient(circle at 50% 28%, rgba(94,234,212,.28), rgba(37,99,235,.16) 44%, transparent 72%);
    filter: blur(3px);
    opacity: .9;
    z-index: 1;
}
.portrait-rig {
    position: relative;
    z-index: 3;
    width: min(720px, 100%);
    aspect-ratio: 1402 / 1122;
    transform-origin: 50% 78%;
    animation: portraitIdle 5.4s ease-in-out infinite;
}
.avatar-portrait {
    position: relative;
    z-index: 2;
    width: 100%;
    height: 100%;
    object-fit: contain;
    filter: drop-shadow(0 34px 60px rgba(0,0,0,.48));
    transform-origin: 50% 78%;
}
.realistic-avatar.listening .avatar-portrait,
.realistic-avatar.thinking .avatar-portrait {
    filter: drop-shadow(0 28px 52px rgba(0,0,0,.45)) drop-shadow(0 0 24px rgba(94,234,212,.24));
}
.realistic-avatar.speaking .portrait-rig {
    animation: presenterSpeak 1.6s ease-in-out infinite;
}
.portrait-face-layer {
    position: absolute;
    inset: 0;
    z-index: 4;
    pointer-events: none;
}
.portrait-eye {
    position: absolute;
    top: 25.2%;
    width: 4.1%;
    height: 1.1%;
    border-radius: 999px;
    background: linear-gradient(180deg, rgba(245,213,191,.9), rgba(198,128,100,.95));
    opacity: 0;
    transform: translate(-50%, -50%) scaleY(.25);
    animation: portraitBlink 5.8s infinite;
}
.portrait-eye-left { left: 44.1%; }
.portrait-eye-right { left: 55.7%; animation-delay: .04s; }
.portrait-mouth {
    position: absolute;
    left: 50%;
    top: 35.2%;
    width: 5.8%;
    height: 1.15%;
    transform: translate(-50%, -50%);
    border-radius: 999px;
    background: rgba(92,20,28,.92);
    border: 1px solid rgba(255,255,255,.18);
    box-shadow: inset 0 -1px 0 rgba(255,255,255,.18), 0 1px 1px rgba(0,0,0,.16);
    opacity: 0;
    transition: width 90ms linear, height 90ms linear, border-radius 90ms linear, opacity 90ms linear;
}
.portrait-mouth span {
    position: absolute;
    left: 50%;
    bottom: 12%;
    width: 38%;
    height: 18%;
    transform: translateX(-50%);
    border-radius: 999px;
    background: rgba(255,255,255,.38);
}
.realistic-avatar.speaking .portrait-mouth,
.realistic-avatar.thinking .portrait-mouth {
    opacity: .92;
}
.mouth-closed .portrait-mouth {
    width: 5.6%;
    height: .65%;
    opacity: 0;
}
.mouth-mid .portrait-mouth {
    width: 5.2%;
    height: 1.7%;
    border-radius: 999px 999px 70% 70%;
}
.mouth-open .portrait-mouth {
    width: 4.5%;
    height: 2.85%;
    border-radius: 48%;
}
.mouth-wide .portrait-mouth {
    width: 7.4%;
    height: 1.15%;
    border-radius: 999px;
}
.mouth-round .portrait-mouth {
    width: 3.6%;
    height: 2.55%;
    border-radius: 50%;
}
.gesture-refer_to_source .portrait-rig { transform: translateY(-2px) rotate(-.7deg); }
.gesture-explain_steps .portrait-rig { filter: drop-shadow(0 0 18px rgba(94,234,212,.16)); }
.gesture-important_reminder .portrait-rig { transform: translateY(-2px) scale(1.01); }
.avatar-speaking-ring {
    position: absolute;
    z-index: 5;
    left: 50%;
    bottom: 58px;
    transform: translateX(-50%);
    display: flex;
    gap: 9px;
    padding: .55rem .8rem;
    border-radius: 999px;
    background: rgba(15,23,42,.78);
    border: 1px solid rgba(94,234,212,.28);
    box-shadow: 0 12px 28px rgba(0,0,0,.28);
}
.avatar-speaking-ring span {
    width: 7px;
    height: 26px;
    border-radius: 999px;
    background: linear-gradient(180deg, #5eead4, #2563eb);
    animation: equalizer 680ms ease-in-out infinite alternate;
}
.avatar-speaking-ring span:nth-child(2) { animation-delay: 120ms; }
.avatar-speaking-ring span:nth-child(3) { animation-delay: 240ms; }
@keyframes portraitIdle {
    0%,100% { transform: translateY(0) rotate(0); }
    50% { transform: translateY(-5px) rotate(.25deg); }
}
@keyframes portraitBlink {
    0%, 92%, 100% { opacity: 0; transform: translate(-50%, -50%) scaleY(.25); }
    94%, 96% { opacity: .85; transform: translate(-50%, -50%) scaleY(1); }
}
@keyframes presenterSpeak {
    0%,100% { transform: translateY(0) rotate(0) scale(1); }
    50% { transform: translateY(-4px) rotate(.35deg) scale(1.006); }
}
@keyframes equalizer {
    from { transform: scaleY(.35); opacity: .58; }
    to { transform: scaleY(1); opacity: 1; }
}
.avatar-status-strip {
    position: absolute;
    left: 50%;
    right: auto;
    top: 1rem;
    bottom: auto;
    z-index: 5;
    transform: translateX(-50%);
    justify-content: center;
    display: flex;
    gap: .75rem;
    flex-wrap: wrap;
}
.avatar-status-strip span {
    background: rgba(15,23,42,.78);
    border: 1px solid rgba(148,163,184,.18);
    border-radius: 999px;
    color: #e2e8f0;
    padding: .45rem .8rem;
    font-size: .82rem;
}
.avatar-status-strip i { color: #5eead4; font-size: .72rem; }
.avatar-panel {
    display: contents;
}
.avatar-controls-stack {
    grid-column: 3;
    grid-row: 1;
    min-height: 0;
    display: grid;
    grid-template-rows: auto;
    gap: 0;
    position: relative;
    z-index: 4;
    margin: 1rem 1rem 1rem 0;
    align-self: start;
}
.avatar-card {
    border: 1px solid rgba(148,163,184,.16);
    border-radius: 8px;
    background: rgba(15,23,42,.88);
    padding: 1rem;
    box-shadow: 0 14px 34px rgba(2,6,23,.28);
    backdrop-filter: blur(10px);
}
.avatar-controls-stack > .avatar-card {
    min-height: 0;
    overflow-y: auto;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    backdrop-filter: none;
}
.avatar-controls-stack > .avatar-card:nth-child(2) {
    display: block;
    padding-top: .35rem;
}
.avatar-controls-stack > .avatar-card:first-child {
    padding-bottom: .35rem;
}
.avatar-card-title {
    display: flex;
    align-items: center;
    gap: .5rem;
    color: #fff;
    font-weight: 700;
    margin-bottom: .8rem;
}
.avatar-card-title i { color: #5eead4; }
.avatar-record-btn,
.avatar-send-btn,
.avatar-stop-answer-btn {
    width: 100%;
    border: none;
    border-radius: 8px;
    background: linear-gradient(135deg, #10b981, #2563eb);
    color: #fff;
    font-weight: 800;
    padding: .8rem 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: .45rem;
}
.avatar-record-btn.recording {
    background: linear-gradient(135deg, #dc2626, #f97316);
    animation: pulse 1s infinite;
}
.avatar-send-btn:disabled,
.avatar-record-btn:disabled { opacity: .48; cursor: not-allowed; }
.avatar-hint {
    color: var(--text-muted);
    font-size: .82rem;
    margin-top: .6rem;
}
.voice-live-box {
    margin-top: .75rem;
    border: 1px solid rgba(94,234,212,.24);
    border-radius: 8px;
    background: rgba(20,184,166,.08);
    overflow: hidden;
}
.voice-live-label {
    display: flex;
    align-items: center;
    gap: .4rem;
    padding: .5rem .65rem;
    color: #99f6e4;
    font-size: .78rem;
    font-weight: 800;
    border-bottom: 1px solid rgba(94,234,212,.16);
}
.voice-live-text {
    min-height: 44px;
    padding: .65rem .75rem;
    color: #f8fafc;
    line-height: 1.55;
    white-space: pre-wrap;
    word-break: break-word;
}
.voice-live-text.empty {
    color: #94a3b8;
}
.avatar-center-actions {
    position: absolute;
    left: 50%;
    bottom: 1.25rem;
    z-index: 5;
    width: min(320px, calc(100% - 2rem));
    transform: translateX(-50%);
    padding: .75rem;
    border: 1px solid rgba(94,234,212,.28);
    border-radius: 14px;
    background: rgba(15,23,42,.82);
    box-shadow: 0 14px 34px rgba(2,6,23,.38);
    backdrop-filter: blur(10px);
}
.avatar-center-actions .avatar-record-btn,
.avatar-center-actions .avatar-stop-answer-btn {
    min-height: 52px;
    font-size: 1rem;
    cursor: pointer;
}
.avatar-center-actions .avatar-hint {
    margin-top: .5rem;
    color: #cbd5e1;
    text-align: center;
}
.avatar-stop-answer-btn {
    background: linear-gradient(135deg, #dc2626, #f97316);
    box-shadow: 0 8px 18px rgba(220,38,38,.24);
    cursor: pointer;
}
.avatar-stop-answer-btn:hover { filter: brightness(1.08); }
.avatar-audience-selector,
.avatar-cultivation-selector,
.avatar-language-selector {
    margin: 0 0 .75rem;
    padding: .7rem;
    border: 1px solid rgba(94,234,212,.22);
    border-radius: 10px;
    background: rgba(15,23,42,.48);
}
.avatar-audience-selector legend,
.avatar-cultivation-selector legend,
.avatar-language-selector legend {
    float: none;
    width: auto;
    margin: 0 0 .5rem;
    padding: 0;
    color: #ccfbf1;
    font-size: .82rem;
    font-weight: 800;
}
.avatar-audience-selector legend i,
.avatar-cultivation-selector legend i,
.avatar-language-selector legend i { margin-right: .25rem; color: #5eead4; }
.avatar-audience-options { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .42rem; }
.avatar-cultivation-options { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .42rem; }
.avatar-audience-option,
.avatar-cultivation-option {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: .32rem;
    min-height: 38px;
    padding: .42rem .3rem;
    border: 1px solid rgba(148,163,184,.28);
    border-radius: 9px;
    color: #cbd5e1;
    font-size: .78rem;
    cursor: pointer;
    transition: border-color .18s ease, background .18s ease, color .18s ease;
}
.avatar-audience-option:hover,
.avatar-cultivation-option:hover { border-color: rgba(94,234,212,.62); }
.avatar-audience-option.selected,
.avatar-cultivation-option.selected {
    border-color: #2dd4bf;
    background: linear-gradient(135deg, rgba(13,148,136,.32), rgba(37,99,235,.2));
    color: #fff;
}
.avatar-audience-option input,
.avatar-cultivation-option input { margin: 0; accent-color: #2dd4bf; }
.avatar-audience-selector small,
.avatar-cultivation-selector small { display: block; margin-top: .48rem; color: #94a3b8; line-height: 1.45; }
.avatar-audience-selector:disabled,
.avatar-cultivation-selector:disabled,
.avatar-language-selector:disabled { opacity: .62; }
.avatar-language-selector select {
    width: 100%;
    min-height: 38px;
    padding: .42rem .55rem;
    border: 1px solid rgba(148,163,184,.28);
    border-radius: 9px;
    background: rgba(15,23,42,.72);
    color: #fff;
    font-size: .82rem;
}
.avatar-textarea {
    width: 100%;
    border: 1px solid rgba(148,163,184,.2);
    border-radius: 8px;
    background: rgba(15,23,42,.72);
    color: #fff;
    padding: .75rem;
    resize: vertical;
    outline: none;
    margin-bottom: .65rem;
}
.avatar-textarea:focus { border-color: #5eead4; }
.avatar-image-input { display: none; }
.avatar-question-actions { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: stretch; gap: .55rem; }
.avatar-question-actions .avatar-send-btn { grid-column: 1 / -1; min-height: 46px; box-shadow: 0 8px 18px rgba(37,99,235,.22); }
.avatar-attach-btn, .avatar-web-toggle {
    border: 1px solid rgba(94,234,212,.38); border-radius: 10px; background: linear-gradient(135deg, rgba(13,148,136,.23), rgba(37,99,235,.14));
    color: #ccfbf1; padding: .58rem .7rem; font-size: .82rem; cursor: pointer; transition: .2s ease;
}
.avatar-attach-btn { display: flex; align-items: center; justify-content: center; gap: .38rem; font-weight: 750; }
.avatar-attach-btn small { color: #94a3b8; font-weight: 500; }
.avatar-attach-btn:hover { transform: translateY(-1px); border-color: #5eead4; background: linear-gradient(135deg, rgba(13,148,136,.4), rgba(37,99,235,.25)); }
.avatar-web-toggle { display: flex; align-items: center; white-space: nowrap; color: #e2e8f0; border-color: rgba(148,163,184,.3); }
.avatar-web-toggle input { accent-color: #2dd4bf; vertical-align: middle; }
.avatar-attach-btn:disabled, .avatar-web-toggle:has(input:disabled) { opacity: .5; cursor: not-allowed; }
.avatar-pending-image { display: flex; align-items: center; gap: .65rem; margin: 0 0 .6rem; padding: .5rem; color: #cbd5e1; font-size: .82rem; background: rgba(15,23,42,.48); border: 1px solid rgba(94,234,212,.18); border-radius: 10px; }
.avatar-pending-image img { width: 82px; height: 62px; object-fit: cover; border-radius: 7px; border: 1px solid rgba(148,163,184,.25); }
.avatar-pending-image button { border: 0; background: transparent; color: #94a3b8; cursor: pointer; }
.avatar-upload-preview { display: block; width: min(440px, 100%); aspect-ratio: 4 / 3; height: auto; object-fit: cover; border-radius: 10px; border: 1px solid rgba(94,234,212,.32); margin-top: .65rem; background: #020617; }
.answer-card {
    grid-column: 1;
    grid-row: 1;
    border: 0;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    position: relative;
    z-index: 4;
    align-self: start;
    height: calc(54% - 1rem);
    margin: 1rem 0 0 1rem;
}
.chat-log-title {
    display: flex;
    align-items: center;
    font-size: 1.5rem;
}
.avatar-live-caption {
    flex: 0 0 auto;
    margin: 0 0 .7rem;
    padding: .7rem .8rem;
    border: 1px solid rgba(94,234,212,.48);
    border-radius: 10px;
    background: linear-gradient(135deg, rgba(13,148,136,.35), rgba(37,99,235,.3));
    box-shadow: 0 8px 22px rgba(2,6,23,.3);
}
.avatar-live-caption-label {
    display: flex;
    align-items: center;
    gap: .35rem;
    margin-bottom: .28rem;
    color: #5eead4;
    font-size: .78rem;
    font-weight: 800;
}
.avatar-live-caption-text {
    display: block;
    color: #fff;
    font-size: 1.05rem;
    font-weight: 700;
    line-height: 1.5;
    overflow-wrap: anywhere;
}
.avatar-history-card {
    grid-column: 1;
    grid-row: 1;
    border: 1px solid rgba(148,163,184,.16);
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    position: relative;
    z-index: 4;
    align-self: start;
    /* 緊接在「回答」卡片下方（回答佔 54%），底部保留舞台空間。 */
    top: 55%;
    height: calc(25% - 1rem);
    margin: 1rem 0 0 1rem;
}
.avatar-history-toggle {
    margin-left: auto;
    border: 1px solid rgba(94,234,212,.3);
    border-radius: 999px;
    background: rgba(20,184,166,.1);
    color: #99f6e4;
    padding: .25rem .7rem;
    font-size: .78rem;
    font-weight: 700;
    cursor: pointer;
}
.avatar-history-toggle:hover { background: rgba(20,184,166,.22); }
.avatar-history-list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: .5rem;
    scrollbar-width: thin;
    scrollbar-color: rgba(45,212,191,.45) rgba(15,23,42,.88);
}
.avatar-history-list.empty { padding: .4rem 0; }
.avatar-history-item {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: .2rem;
    width: 100%;
    padding: .55rem .62rem;
    border: 1px solid rgba(148,163,184,.18);
    border-radius: 8px;
    background: rgba(30,41,59,.4);
    color: #f8fafc;
    text-align: left;
    cursor: pointer;
}
.avatar-history-item:hover {
    border-color: rgba(94,234,212,.5);
    background: rgba(30,41,59,.62);
}
.avatar-history-time {
    color: #94a3b8;
    font-size: .68rem;
}
.avatar-history-item strong {
    color: #fff;
    font-size: .88rem;
    line-height: 1.45;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%;
}
.avatar-history-item small {
    color: #cbd5e1;
    line-height: 1.4;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%;
}
.avatar-history-empty {
    padding: .85rem .5rem;
    color: #94a3b8;
    font-size: .82rem;
    text-align: center;
}
.avatar-reset-btn {
    margin-left: auto;
    border: 1px solid rgba(94,234,212,.3);
    border-radius: 999px;
    background: rgba(20,184,166,.1);
    color: #99f6e4;
    padding: .25rem .7rem;
    font-size: .78rem;
    font-weight: 700;
    cursor: pointer;
}
.avatar-reset-btn:hover { background: rgba(20,184,166,.22); }
.avatar-reset-btn:disabled { opacity: .5; cursor: not-allowed; }
.avatar-chat-log {
    flex: 1;
    min-height: 0;
    max-height: none;
    overflow-y: auto;
    direction: rtl !important;
    scrollbar-width: thin;
    scrollbar-color: rgba(45,212,191,.45) rgba(15,23,42,.88);
    display: flex;
    flex-direction: column;
    gap: .35rem;
    scroll-behavior: smooth;
}
.avatar-chat-log > * {
    direction: ltr !important;
}
.avatar-chat-log::-webkit-scrollbar {
    width: 10px;
}
.avatar-chat-log::-webkit-scrollbar-track {
    border-radius: 999px;
    background: rgba(15,23,42,.88);
}
.avatar-chat-log::-webkit-scrollbar-thumb {
    border: 2px solid rgba(15,23,42,.88);
    border-radius: 999px;
    background: rgba(45,212,191,.42);
}
.avatar-chat-log::-webkit-scrollbar-thumb:hover {
    background: rgba(94,234,212,.68);
}
.avatar-chat-log::-webkit-scrollbar-button {
    display: none;
    width: 0;
    height: 0;
}
.avatar-chat-empty {
    color: #94a3b8;
    line-height: 1.75;
    font-size: .92rem;
}
.avatar-chat-msg + .avatar-chat-msg {
    margin-top: .75rem;
    padding-top: .75rem;
    border-top: 1px dashed rgba(148,163,184,.18);
}
.avatar-transcript {
    color: #bfdbfe;
    font-size: 1.35rem;
    padding: .65rem .75rem;
    border-radius: 8px;
    background: rgba(37,99,235,.12);
    margin-bottom: .35rem;
}
.avatar-transcript span { color: #93c5fd; font-weight: 800; }
.avatar-transcript-origin { display: block; margin-top: .2rem; color: #94a3b8; font-size: .78rem; }
.avatar-answer {
    color: #e2e8f0;
    line-height: 1.75;
    font-size: 1.425rem;
    overflow-wrap: anywhere;
}
.avatar-answer .answer-section-title { color: #99f6e4; border-left-color: #2dd4bf; background: rgba(45,212,191,.10); font-size: 1.35rem; }
.avatar-answer .answer-bullet i { color: #5eead4; }
.avatar-answer-pending {
    color: #94a3b8;
    font-size: .88rem;
}
.response-pending-status {
    display: inline-flex;
    align-items: center;
    gap: .45rem;
    min-height: 2.25rem;
    padding: .45rem .7rem;
    color: #99f6e4;
    font-size: .9rem;
    border: 1px solid rgba(45, 212, 191, .22);
    border-radius: 10px;
    background: rgba(15, 118, 110, .12);
}
.response-pending-status .bi { animation: response-pending-pulse 1.1s ease-in-out infinite; }
@keyframes response-pending-pulse { 50% { opacity: .38; } }
.avatar-sources {
    display: none;
    margin-top: .9rem;
    padding-top: .75rem;
    border-top: 1px solid rgba(148,163,184,.14);
}
.avatar-source-title {
    color: var(--text-muted);
    font-size: .78rem;
    font-weight: 800;
    margin-bottom: .45rem;
}
.avatar-source {
    width: 100%;
    text-align: left;
    border: 1px solid rgba(148,163,184,.16);
    border-radius: 8px;
    background: rgba(255,255,255,.04);
    color: #cbd5e1;
    padding: .5rem .65rem;
    margin-bottom: .4rem;
    font-size: .82rem;
    display: block;
    text-decoration: none;
}
.avatar-source span { color: #5eead4; }
.avatar-web-images { margin-top: .75rem; padding: .8rem; border: 1px solid rgba(94,234,212,.25); border-radius: 12px; background: linear-gradient(135deg, rgba(16,185,129,.11), rgba(37,99,235,.06)); display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 240px)); justify-content: start; gap: .7rem; }
.avatar-web-images .avatar-source-title { grid-column: 1 / -1; margin: 0; color: #99f6e4; }
.avatar-web-image { display: flex; flex-direction: column; min-width: 0; color: #cbd5e1; text-decoration: none; font-size: .78rem; transition: transform .18s ease; }
.avatar-web-image:hover { transform: translateY(-2px); }
.avatar-web-image img { width: 100%; aspect-ratio: 4 / 3; height: auto; object-fit: contain; border-radius: 9px; border: 1px solid rgba(148,163,184,.25); background: #071225; }
.avatar-web-image span { margin: .4rem .2rem 0; line-height: 1.35; }
.avatar-suggestions {
    max-width: 1440px;
    width: 100%;
    margin: 0 auto;
    display: flex;
    gap: .5rem;
    overflow-x: auto;
    padding-bottom: .1rem;
}
.avatar-suggestions button {
    flex: 0 0 auto;
    border: 1px solid rgba(94,234,212,.25);
    border-radius: 999px;
    background: rgba(15,23,42,.62);
    color: #d1fae5;
    padding: .55rem .9rem;
    font-size: .86rem;
}
@keyframes avatarBreath {
    0%,100% { transform: translateY(0); }
    50% { transform: translateY(-7px); }
}
@keyframes avatarThinking {
    0%,100% { transform: translateY(0) rotate(-.5deg); }
    50% { transform: translateY(-5px) rotate(.5deg); }
}
@keyframes avatarTalk {
    0%,100% { transform: translateX(-50%) rotate(0); }
    50% { transform: translateX(-50%) rotate(1.5deg); }
}

/* ========  3840 x 2160 DEMO AT WINDOWS 250% SCALING  ========
   The physical UHD panel exposes a 1536 x 864 CSS viewport at 250% scaling.
   This is the primary full-screen demo workspace. */
@media (min-width: 1400px) and (min-height: 800px) {
    html,
    body { height: 100%; overflow: hidden; }

    .top-navbar-inner,
    .avatar-scene-bar,
    .avatar-layout,
    .avatar-suggestions {
        max-width: 1480px;
    }

    .section-container { max-width: 1240px; }
    #homeApp {
        height: calc(100dvh - 56px);
        display: grid;
        grid-template-rows: minmax(330px, 46%) minmax(0, 1fr);
        overflow: hidden;
    }
    .hero-section {
        min-height: 0;
        padding: clamp(2rem, 5vh, 3.5rem) 1.5rem;
        display: grid;
        align-items: center;
    }
    .hero-icon { width: 64px; height: 64px; margin-bottom: 1rem; }
    .hero-title { font-size: 2rem; }
    .hero-subtitle { margin-bottom: 1.35rem; }
    .services-section {
        min-height: 0;
        padding: clamp(1.5rem, 4vh, 2.75rem) 0;
        display: grid;
        align-items: center;
        overflow: hidden;
    }
    .services-section .section-header { margin-bottom: 1.5rem; }
    .home-primary-services .service-card { padding: 1.5rem; }
    .home-primary-services .service-card-summary { min-height: 155px; }

    .chat-sidebar { width: 260px; }
    .chat-messages { padding: 1.25rem 1.75rem; }
    .chat-welcome { padding: clamp(2rem, 5vh, 3.25rem) 1rem; }
    .chat-topic-nav { max-width: 1160px; }
    .chat-input-bar { padding: .7rem 1.25rem; }

    .avatar-page {
        height: calc(100dvh - 56px);
        min-height: 0;
        overflow: hidden;
    }
    .avatar-stage {
        height: 100%;
        min-height: 0;
        padding: .75rem 1rem 1rem;
        gap: .65rem;
        overflow: hidden;
    }
    .avatar-scene-bar { gap: .75rem; }
    .avatar-scene-bar h1 { font-size: 1.2rem; }
    .avatar-scene-controls { gap: .4rem; }
    .avatar-select { padding: .42rem .7rem; }
    .avatar-model-action { min-height: 36px; padding: .4rem .65rem; }
    .avatar-layout {
        flex: 1;
        min-height: 0;
        grid-template-columns: minmax(300px, .9fr) minmax(380px, 1.15fr) minmax(400px, 1fr);
        grid-template-rows: minmax(0, 1fr);
        gap: .75rem;
    }
    .digital-human-wrap {
        grid-column: 1 / -1;
        grid-row: 1;
        min-height: 0;
    }
    .avatar-controls-stack {
        grid-column: 3;
        grid-row: 1;
        min-height: 0;
        display: grid;
        grid-template-rows: auto;
        gap: 0;
        align-self: start;
    }
    .avatar-controls-stack > .avatar-card:nth-child(1) {
        grid-column: auto;
        grid-row: auto;
        min-height: 0;
        overflow: auto;
        display: flex;
        flex-direction: column;
        justify-content: flex-start;
    }
    .avatar-card { padding: .8rem; }
    .avatar-card-title { margin-bottom: .55rem; }
    .avatar-audience-selector,
    .avatar-cultivation-selector,
    .avatar-language-selector {
        margin-bottom: .5rem;
        padding: .55rem;
    }
    .avatar-audience-selector legend,
    .avatar-cultivation-selector legend,
    .avatar-language-selector legend { margin-bottom: .35rem; }
    .avatar-audience-option,
    .avatar-cultivation-option {
        min-height: 34px;
        padding-block: .32rem;
    }
    .avatar-audience-selector small,
    .avatar-cultivation-selector small {
        display: none;
    }
    .avatar-record-btn,
    .avatar-stop-answer-btn { padding: .62rem .85rem; }
    .avatar-hint { display: none; }
    .avatar-textarea {
        min-height: 82px;
        max-height: 92px;
        margin-bottom: .45rem;
        padding: .65rem;
    }
    .avatar-question-actions { gap: .4rem; }
    .avatar-question-actions .avatar-send-btn { min-height: 40px; padding-block: .55rem; }
    .avatar-attach-btn,
    .avatar-web-toggle { padding: .48rem .62rem; }
    .answer-card {
        grid-column: 1;
        grid-row: 1;
        min-height: 0;
        overflow: hidden;
    }
    .avatar-history-card {
        grid-column: 1;
        grid-row: 1;
        min-height: 0;
        overflow: hidden;
    }
    .answer-card .chat-log-title { margin-bottom: .35rem; font-size: 1rem; }
    .avatar-chat-log {
        min-height: 0;
        max-height: none;
        overflow-y: auto;
        font-size: .85rem;
    }
    .avatar-chat-empty { font-size: .82rem; line-height: 1.45; }
    .avatar-suggestions { display: none; }
    .digital-human-3d { min-height: 0; }
}

/* ========  NATIVE UHD 3840 x 2160 DEMO  ========
   Keeps the same visual density as the approved 1920 x 1080 workspace when
   the browser exposes the full native 4K viewport without OS scaling. */
@media (min-width: 2560px) and (min-height: 1400px) {
    html { font-size: 32px; }

    .top-navbar {
        height: 112px;
        padding-inline: 3rem;
    }
    .top-navbar-inner,
    .avatar-scene-bar,
    .avatar-layout,
    .avatar-suggestions { max-width: 2960px; }
    .top-navbar-brand { gap: 1.2rem; }
    .brand-icon { width: 68px; height: 68px; border-radius: 16px; }

    #homeApp,
    .avatar-page { height: calc(100dvh - 112px); }
    #homeApp { grid-template-rows: minmax(660px, 46%) minmax(0, 1fr); }
    .section-container { max-width: 2480px; }
    .hero-icon { width: 128px; height: 128px; border-radius: 36px; }
    .hero-search { max-width: 1120px; }
    .home-primary-services {
        grid-template-columns: repeat(2, minmax(560px, 840px));
        gap: 48px;
    }
    .home-primary-services .service-card-summary { min-height: 310px; }
    .service-card-icon { width: 112px; height: 112px; border-radius: 28px; }

    .chat-page { height: calc(100dvh - 112px); }
    .chat-sidebar { width: 520px; }
    .chat-welcome-icon { width: min(440px, 62vw); border-radius: 44px; }
    .chat-topic-nav { max-width: 2320px; gap: 16px; }
    .chat-topic-tag { min-height: 96px; border-radius: 24px; }
    .msg-avatar { width: 144px; height: 144px; border-radius: 28px; }
    .chat-attach-btn { width: 72px; height: 72px; }
    .chat-send-btn,
    .chat-mic-btn { width: 80px; height: 80px; }

    .login-page { min-height: calc(100dvh - 112px); }
    .login-card { width: 800px; }
    .login-icon { width: 128px; height: 128px; border-radius: 32px; }

    .avatar-layout {
        grid-template-columns: minmax(600px, .9fr) minmax(760px, 1.15fr) minmax(800px, 1fr);
        grid-template-rows: minmax(0, 1fr);
        gap: 24px;
    }
    .avatar-controls-stack { gap: 0; }
    .avatar-select { min-height: 72px; }
    .avatar-model-action { min-height: 72px; }
    .avatar-card { padding: 26px; }
    .avatar-audience-option,
    .avatar-cultivation-option { min-height: 68px; }
    .avatar-record-btn,
    .avatar-stop-answer-btn { min-height: 72px; }
    .avatar-textarea { min-height: 164px; max-height: 184px; }
    .avatar-question-actions .avatar-send-btn { min-height: 80px; }
    .avatar-status-strip { left: 50%; right: auto; top: 32px; bottom: auto; }
    .avatar-center-actions { bottom: 32px; }
}

/* ========  RESPONSIVE  ======== */
@media (min-width: 993px) and (max-width: 1180px) {
    .avatar-layout {
        grid-template-columns: minmax(280px, .85fr) minmax(340px, 1.15fr);
        grid-template-rows: minmax(620px, auto) auto;
    }
    .answer-card { grid-column: 1; grid-row: 1; }
    .avatar-history-card { grid-column: 1; grid-row: 1; }
    .digital-human-wrap { grid-column: 2; grid-row: 1; }
    .avatar-controls-stack {
        grid-column: 1 / -1;
        grid-row: 2;
        grid-template-columns: 1fr;
        grid-template-rows: auto;
        margin: 0;
    }
    .answer-card {
        height: calc(50% - 1rem);
        margin: 1rem 0 0 1rem;
    }
    .avatar-history-card {
        top: 51%;
        height: calc(28% - 1rem);
        margin: 1rem 0 0 1rem;
    }
}
@media (max-width: 992px) {
    .chat-sidebar { display: none; }
    .top-navbar-links { display: none; }
    .avatar-layout { grid-template-columns: 1fr; grid-template-rows: auto; }
    .digital-human-wrap,
    .avatar-controls-stack,
    .answer-card,
    .avatar-history-card { grid-column: 1; grid-row: auto; }
    .avatar-controls-stack {
        grid-template-columns: 1fr;
        grid-template-rows: auto;
        margin: 0;
    }
    .avatar-controls-stack > .avatar-card:nth-child(1),
    .avatar-controls-stack > .avatar-card:nth-child(2) { grid-column: 1; grid-row: auto; }
    .digital-human-wrap { min-height: 440px; }
    .answer-card {
        height: auto;
        max-height: none;
        margin: 0;
    }
    .avatar-history-card {
        top: auto;
        height: auto;
        max-height: none;
        margin: 1rem 0 0;
    }
    .avatar-panel { overflow: visible; }
}
@media (max-width: 768px) {
    .top-navbar { padding: 0 .75rem; }
    .top-navbar-inner { min-width: 0; }
    .top-navbar-brand { min-width: 0; flex: 1; }
    .brand-text { overflow: hidden; text-overflow: ellipsis; }
    .top-navbar-right { display: none; }
    .hero-section { padding: 3rem 1rem 2.5rem; }
    .hero-title { font-size: 1.5rem; }
    .services-grid { grid-template-columns: 1fr; }
    .chat-topic-nav { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .chat-topic-tag { white-space: normal; }
    .features-grid { grid-template-columns: repeat(2, 1fr); }
    .chat-messages { padding: .85rem .65rem; }
    .msg-row { gap: .4rem; margin-bottom: .9rem; }
    .msg-avatar { width: 46px; height: 46px; border-radius: 10px; }
    .msg-bubble {
        max-width: calc(100% - 50px);
        min-width: 0;
        padding: .78rem .85rem;
        font-size: .88rem;
    }
    .msg-source-item { padding: .45rem .35rem; }
    .source-header {
        display: grid;
        grid-template-columns: 1rem minmax(0, 1fr);
        align-items: start;
        column-gap: .4rem;
        row-gap: .25rem;
    }
    .source-header > i { grid-column: 1; grid-row: 1; margin-top: .15rem; }
    .source-title {
        grid-column: 2;
        min-width: 0;
        line-height: 1.5;
        overflow-wrap: anywhere;
    }
    .source-page,
    .source-cat,
    .source-web-tag {
        grid-column: 2;
        white-space: normal;
        justify-self: start;
        line-height: 1.45;
    }
    .chat-input-bar {
        padding: .65rem .65rem calc(.55rem + env(safe-area-inset-bottom, 0px));
    }
    .chat-audience-selector,
    .chat-cultivation-selector { flex-wrap: wrap; gap: .35rem; }
    .chat-audience-selector legend,
    .chat-cultivation-selector legend { flex-basis: 100%; }
    .chat-audience-selector small,
    .chat-cultivation-selector small { display: none; }
    .chat-audience-option,
    .chat-cultivation-option { flex: 1; justify-content: center; padding-inline: .35rem; }
    .chat-input-wrap { gap: .3rem; padding-left: .55rem; }
    .chat-attach-btn { width: 34px; height: 34px; }
    .chat-send-btn,
    .chat-mic-btn { width: 38px; height: 38px; }
    .chat-disclaimer {
        display: flex;
        align-items: flex-start;
        flex-wrap: wrap;
        gap: .25rem .6rem;
        padding-left: .15rem;
        line-height: 1.45;
    }
    .web-search-toggle { float: none; margin-left: auto; white-space: nowrap; }
    .avatar-stage { padding: .9rem; }
    .avatar-scene-bar { align-items: flex-start; flex-direction: column; }
    .avatar-scene-controls { width: 100%; justify-content: flex-start; }
    .avatar-select { flex: 1; min-width: 0; }
    .digital-human-wrap { min-height: 430px; }
    .digital-human { width: 300px; height: 430px; transform: scale(.82); }
    .realistic-avatar {
        width: min(520px, 94vw);
        height: 430px;
        min-height: 430px;
        transform: none;
    }
    .portrait-rig { width: min(520px, 100%); }
}

/* ===== 3D 數字人（TalkingHead）舞台 ===== */
.digital-human-3d {
    position: relative;
    width: 100%;
    /* Fill the two-row desktop stage so the avatar is not rendered inside a
       short, vertically-centred canvas with large empty bands above/below. */
    height: 100%;
    min-height: 530px;
    overflow: hidden;
}
.digital-human-3d .avatar-backlight {
    position: absolute;
    left: 50%;
    bottom: 3rem;
    width: 68%;
    height: 74%;
    transform: translateX(-50%);
    border-radius: 42% 42% 24% 24%;
    background: radial-gradient(circle at 50% 26%, rgba(94,234,212,.26), rgba(37,99,235,.15) 44%, transparent 72%);
    filter: blur(4px);
    opacity: .9;
    z-index: 1;
}
.digital-human-3d.listening .avatar-backlight,
.digital-human-3d.thinking .avatar-backlight {
    background: radial-gradient(circle at 50% 26%, rgba(94,234,212,.4), rgba(37,99,235,.2) 44%, transparent 72%);
}
.avatar-canvas-3d {
    position: absolute;
    inset: 0;
    z-index: 2;
    touch-action: none;
    overscroll-behavior: contain;
}
.avatar-canvas-3d canvas {
    display: block;
    width: 100% !important;
    height: 100% !important;
    transform: translateY(-10%) scale(1.11);
    transform-origin: 50% 52%;
    touch-action: none !important;
}
/* 場長候選模型的原始構圖邊界較寬，以特定鏡頭裁切放大，
   避免影響使用者上傳或其他骨架比例不同的模型。 */
.avatar-model-candidate .avatar-canvas-3d canvas {
    transform: translateY(-14%) scale(1.34);
    transform-origin: 50% 50%;
}
.avatar-model-broadcast .avatar-canvas-3d canvas,
.avatar-model-talkinghead .avatar-canvas-3d canvas,
.avatar-model-multiview-shape .avatar-canvas-3d canvas,
.avatar-model-textured-base .avatar-canvas-3d canvas {
    transform: none;
}
@media (max-width: 520px) {
    .chat-topic-nav { grid-template-columns: 1fr; }
    .avatar-audience-options { grid-template-columns: 1fr; }
    .avatar-cultivation-options { grid-template-columns: 1fr; }
    .avatar-question-actions { grid-template-columns: 1fr; }
    .avatar-web-toggle { justify-content: center; }
    .avatar-web-images { grid-template-columns: 1fr; }
    .avatar-model-candidate .avatar-canvas-3d canvas {
        transform: translateY(-9%) scale(1.18);
    }
}
.director-avatar-stage {
    position: absolute;
    inset: 0;
    z-index: 2;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 18px;
}
.director-avatar-photo {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: 50% 47%;
    filter: drop-shadow(0 28px 52px rgba(0,0,0,.42));
    animation: directorAvatarIdle 5.2s ease-in-out infinite;
    transform-origin: 50% 58%;
}
.digital-human-3d.listening .director-avatar-photo,
.digital-human-3d.thinking .director-avatar-photo {
    filter: brightness(1.05) drop-shadow(0 0 28px rgba(94,234,212,.34));
    animation: directorAvatarThinking 1.5s ease-in-out infinite;
}
.digital-human-3d.speaking .director-avatar-photo {
    animation: directorAvatarSpeaking 1.15s ease-in-out infinite;
    filter: brightness(1.06) drop-shadow(0 0 32px rgba(94,234,212,.4));
}
@keyframes directorAvatarIdle {
    0%, 100% { transform: scale(1.02) translateY(0); }
    50% { transform: scale(1.035) translateY(-5px); }
}
@keyframes directorAvatarThinking {
    0%, 100% { transform: scale(1.025) translateY(0); }
    50% { transform: scale(1.045) translateY(-7px); }
}
@keyframes directorAvatarSpeaking {
    0%, 100% { transform: scale(1.025) translateY(0); }
    35% { transform: scale(1.045) translateY(-4px) rotate(-.25deg); }
    70% { transform: scale(1.035) translateY(-2px) rotate(.25deg); }
}
.avatar-3d-loading {
    position: absolute;
    inset: 0;
    z-index: 3;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: .85rem;
    color: #94a3b8;
    font-size: .95rem;
    background: rgba(15,23,42,.35);
}
.avatar-3d-spinner {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 3px solid rgba(94,234,212,.2);
    border-top-color: #5eead4;
    animation: avatar3dSpin 1s linear infinite;
}
@keyframes avatar3dSpin {
    to { transform: rotate(360deg); }
}
@media (max-width: 900px) {
    .digital-human-3d { min-height: 430px; height: 60vh; }
}

/* 手機／平板：數字人必須留在自己的文件區塊內，不可 sticky 覆蓋後續操作卡片。 */
@media (max-width: 992px) {
    .digital-human-wrap {
        position: relative;
        top: auto;
        align-self: stretch;
        width: 100%;
        height: clamp(320px, 56dvh, 430px);
        min-height: clamp(320px, 56dvh, 430px);
        z-index: auto;
        overflow: hidden;
    }
    .digital-human-3d {
        width: 100%;
        height: 100%;
        min-height: 0;
    }
}
