/* ========================================
   雨时来信 - Web App Styles
   ======================================== */

:root {
    color-scheme: light;
    --ink: #152329;
    --ink-secondary: #3d5a5e;
    --muted: #65757b;
    --paper: #fffaf2;
    --soft: #f6efe4;
    --surface: #ffffff;
    --surface-hover: #f8f5ef;
    --line: rgba(30, 55, 61, 0.12);
    --teal: #2c8b83;
    --teal-light: #3cb8a8;
    --teal-dark: #17645f;
    --coral: #df7e6c;
    --mist: #e9f3f1;
    --shadow-sm: 0 2px 8px rgba(37, 54, 57, 0.06);
    --shadow: 0 8px 24px rgba(37, 54, 57, 0.08);
    --shadow-lg: 0 16px 48px rgba(37, 54, 57, 0.12);
    --radius-sm: 8px;
    --radius: 12px;
    --radius-lg: 20px;
    --radius-full: 999px;
    --bubble-user: var(--teal);
    --bubble-user-text: #ffffff;
    --bubble-ai: var(--surface);
    --bubble-ai-text: var(--ink);
    --input-bg: var(--surface);
    --sidebar-bg: rgba(246, 239, 228, 0.95);
    /* Character theme (defaults to 雨时) */
    --char-img: url('assets/characters/yushi.png');
    --char-accent: #C9A28B;
    --char-accent-light: rgba(201, 162, 139, 0.15);
    --chat-bg-overlay: linear-gradient(
        to bottom,
        rgba(255, 250, 242, 0.97) 0%,
        rgba(255, 250, 242, 0.88) 40%,
        rgba(246, 239, 228, 0.94) 100%
    );
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --ink: #e8ede9;
    --ink-secondary: #b8c8c4;
    --muted: #8fa3a0;
    --paper: #0f1a1e;
    --soft: #162428;
    --surface: #1a2e32;
    --surface-hover: #223a3e;
    --line: rgba(200, 220, 215, 0.1);
    --teal: #3cb8a8;
    --teal-light: #4ecdb8;
    --teal-dark: #2da89a;
    --coral: #e89882;
    --mist: #1a2e2c;
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.15);
    --shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
    --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.3);
    --bubble-user: var(--teal-dark);
    --bubble-user-text: #ffffff;
    --bubble-ai: var(--surface);
    --bubble-ai-text: var(--ink);
    --input-bg: var(--surface);
    --sidebar-bg: rgba(22, 36, 40, 0.98);
    --chat-bg-overlay: linear-gradient(
        to bottom,
        rgba(15, 26, 30, 0.96) 0%,
        rgba(15, 26, 30, 0.88) 40%,
        rgba(22, 36, 40, 0.93) 100%
    );
}

/* Character: 时屿 theme */
:root[data-character="shiyu"] {
    --char-img: url('assets/characters/shiyu.png');
    --char-accent: #B8A0C8;
    --char-accent-light: rgba(184, 160, 200, 0.15);
}

:root[data-character="shiyu"][data-theme="dark"] {
    --char-accent: #C9A0DC;
    --char-accent-light: rgba(201, 160, 220, 0.18);
}

/* Character: 见夏 theme */
:root[data-character="jianxia"] {
    --char-img: url('assets/characters/jianxia.png');
    --char-accent: #E8927C;
    --char-accent-light: rgba(232, 146, 124, 0.15);
}

:root[data-character="jianxia"][data-theme="dark"] {
    --char-accent: #F0A48E;
    --char-accent-light: rgba(240, 164, 142, 0.18);
}

/* Character: 沉川 theme */
:root[data-character="chenchuan"] {
    --char-img: url('assets/characters/chenchuan.png');
    --char-accent: #7FA3B0;
    --char-accent-light: rgba(127, 163, 176, 0.15);
}

:root[data-character="chenchuan"][data-theme="dark"] {
    --char-accent: #93B6C2;
    --char-accent-light: rgba(147, 182, 194, 0.18);
}

/* Character: 晚栀 theme */
:root[data-character="soulmate"] {
    --char-img: url('assets/characters/soulmate.png');
    --char-accent: #9AA7C7;
    --char-accent-light: rgba(154, 167, 199, 0.15);
}

:root[data-character="soulmate"][data-theme="dark"] {
    --char-accent: #AEBADA;
    --char-accent-light: rgba(174, 186, 218, 0.18);
}

/* ========== First-time character selection ========== */
#character-selection-view {
    position: fixed;
    inset: 0;
    z-index: 200;
    overflow-y: auto;
    padding: 48px 24px 64px;
    background: var(--paper);
    background-image: radial-gradient(circle at 15% 0%, var(--char-accent-light), transparent 45%),
        radial-gradient(circle at 90% 100%, var(--mist), transparent 50%);
}

.selection-hero {
    max-width: 720px;
    margin: 0 auto 32px;
    text-align: center;
}

.selection-hero h2 {
    margin: 10px 0 12px;
    font-size: 30px;
    letter-spacing: 0.02em;
    color: var(--ink);
}

.selection-hero p:last-child {
    color: var(--muted);
    line-height: 1.7;
}

.selection-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
    max-width: 1080px;
    margin: 0 auto;
}

.selection-character-card {
    display: block;
    overflow: hidden;
    text-align: left;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}

.selection-character-card:hover:not(:disabled),
.selection-character-card:focus-visible:not(:disabled) {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
    border-color: var(--char-accent);
}

.selection-character-card:disabled {
    cursor: default;
}

#character-selection-view.busy .selection-character-card:not(:disabled) {
    opacity: 0.45;
}

.selection-card-portrait {
    aspect-ratio: 1672 / 941;
    background-size: cover;
    background-position: center 25%;
    background-color: var(--soft);
}

.selection-card-body {
    padding: 18px 20px 22px;
}

.selection-card-heading {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}

.selection-card-heading strong {
    font-size: 20px;
    color: var(--ink);
}

.selection-card-archetype {
    padding: 3px 10px;
    border-radius: var(--radius-full);
    background: var(--char-accent-light);
    color: var(--char-accent);
    font-size: 12px;
    font-weight: 600;
}

.selection-card-desc {
    color: var(--ink-secondary);
    line-height: 1.65;
    font-size: 14px;
}

.selection-card-feeling {
    margin-top: 10px;
    color: var(--muted);
    font-size: 13px;
}

.selection-card-hook {
    margin-top: 12px;
    padding: 12px 14px;
    border-radius: var(--radius);
    background: var(--soft);
    color: var(--ink);
    font-size: 14px;
    line-height: 1.7;
}

.selection-busy-hint {
    max-width: 720px;
    margin: 28px auto 0;
    text-align: center;
    color: var(--char-accent);
    font-size: 14px;
}

@media (max-width: 640px) {
    #character-selection-view {
        padding: 32px 16px 48px;
    }

    .selection-hero h2 {
        font-size: 24px;
    }
}

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

html, body {
    height: 100%;
    overflow: hidden;
}

/* 手机浏览器地址栏收展/软键盘弹出时，动态视口单位能跟随实际可视高度 */
@supports (height: 100dvh) {
    html, body {
        height: 100dvh;
    }
}

body {
    font-family: "HarmonyOS Sans SC", "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
    color: var(--ink);
    background: var(--paper);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    transition: background 300ms ease, color 300ms ease;
}

/* ========== Views ========== */
.view {
    display: none;
    height: 100%;
}

.view.active {
    display: flex;
}

/* ========== Auth View ========== */
#auth-view {
    background:
        radial-gradient(ellipse at 20% 50%, rgba(44, 139, 131, 0.08) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 20%, rgba(223, 126, 108, 0.06) 0%, transparent 40%),
        var(--paper);
    padding: 20px;
    position: relative;
    /* 卡片高于视口（如注册表单）时允许纵向滚动，否则底部按钮不可达 */
    overflow-y: auto;
    overflow-x: hidden;
}

#auth-view::before {
    content: '';
    position: fixed;
    inset: 0;
    background: var(--char-img) center/cover no-repeat;
    opacity: 0.06;
    filter: blur(30px) saturate(1.4);
    pointer-events: none;
    transition: opacity 600ms ease, background 600ms ease;
}

#auth-view::after {
    content: '';
    position: fixed;
    bottom: -40px;
    right: -60px;
    width: 380px;
    height: 240px;
    background: var(--char-img) center/cover no-repeat;
    border-radius: var(--radius-lg);
    opacity: 0.18;
    filter: blur(2px) saturate(1.2);
    pointer-events: none;
    mask-image: radial-gradient(ellipse at center, black 30%, transparent 75%);
    -webkit-mask-image: radial-gradient(ellipse at center, black 30%, transparent 75%);
    transition: opacity 600ms ease, background 600ms ease;
}

.auth-container {
    width: 100%;
    max-width: 420px;
    position: relative;
    z-index: 1;
    /* flex 容器内用 margin auto 居中：超高时可从顶部完整滚动 */
    margin: auto;
}

.auth-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    padding: 40px 36px;
    box-shadow: var(--shadow-lg);
}

.auth-header {
    text-align: center;
    margin-bottom: 32px;
}

.brand-logo {
    display: inline-flex;
    margin-bottom: 16px;
}

.brand-logo .brand-mark {
    display: grid;
    width: 56px;
    height: 56px;
    place-items: center;
    border-radius: 16px;
    color: transparent;
    background:
        var(--char-img) center/cover no-repeat,
        linear-gradient(145deg, var(--teal), var(--teal-dark));
    box-shadow: 0 12px 28px rgba(23, 100, 95, 0.3);
    font-size: 0;
    font-weight: 700;
    overflow: hidden;
    transition: background 400ms ease;
}

.brand-logo.small .brand-mark {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    font-size: 0;
}

.auth-header h1 {
    font-size: 28px;
    font-weight: 700;
    color: var(--ink);
    margin-bottom: 8px;
}

.auth-subtitle {
    color: var(--muted);
    font-size: 14px;
}

.guest-entry {
    margin-top: 22px;
    text-align: center;
}

.guest-divider {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
    color: var(--muted);
    font-size: 12px;
}

.guest-divider::before,
.guest-divider::after {
    content: "";
    height: 1px;
    flex: 1;
    background: var(--line);
}

.guest-entry p {
    margin-top: 10px;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.5;
}

/* Auth Tabs */
.auth-tabs {
    display: flex;
    gap: 4px;
    padding: 4px;
    background: var(--soft);
    border-radius: var(--radius-full);
    margin-bottom: 28px;
}

.auth-tab {
    flex: 1;
    padding: 10px 16px;
    border: none;
    border-radius: var(--radius-full);
    background: transparent;
    color: var(--muted);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 200ms ease;
}

.auth-tab.active {
    background: var(--surface);
    color: var(--ink);
    box-shadow: var(--shadow-sm);
}

.auth-tab:hover:not(.active) {
    color: var(--ink-secondary);
}

.btn.character-switch {
    padding: 0;
    font-size: 13px;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 72px;
    height: 36px;
    border-radius: var(--radius);
    overflow: hidden;
    position: relative;
    background: var(--char-img) center/cover no-repeat;
    border: 1px solid var(--line);
    color: #fff;
    font-weight: 600;
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
    letter-spacing: 0.05em;
    transition: background 400ms ease, box-shadow 200ms ease;
}

.btn.character-switch span {
    position: relative;
    z-index: 1;
}

.btn.character-switch::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(0,0,0,0.15) 0%, rgba(0,0,0,0.35) 100%);
    pointer-events: none;
    transition: background 200ms ease;
}

.btn.character-switch:hover::before {
    background: linear-gradient(135deg, rgba(0,0,0,0.1) 0%, rgba(0,0,0,0.25) 100%);
}

.btn.character-switch:hover {
    box-shadow: 0 4px 14px var(--char-accent-light);
    border-color: var(--char-accent);
    background: var(--char-img) center/cover no-repeat;
    color: #fff;
}

.login-mode-tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
    margin-bottom: 20px;
    padding: 3px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface-hover);
}

.login-mode-tab {
    border: none;
    border-radius: calc(var(--radius) - 3px);
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    padding: 8px 10px;
    transition: all 200ms ease;
}

.login-mode-tab.active {
    background: var(--surface);
    color: var(--ink);
    box-shadow: var(--shadow-sm);
}

.login-mode-panel {
    display: none;
}

.login-mode-panel.active {
    display: block;
}

/* Auth Forms */
.auth-form {
    display: none;
}

.auth-form.active {
    display: block;
    animation: fadeIn 200ms ease;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 13px;
    font-weight: 600;
    color: var(--ink-secondary);
}

.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--input-bg);
    color: var(--ink);
    font-size: 15px;
    font-family: inherit;
    transition: border-color 200ms ease, box-shadow 200ms ease;
    outline: none;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    border-color: var(--teal);
    box-shadow: 0 0 0 3px rgba(44, 139, 131, 0.12);
}

.form-group textarea {
    resize: vertical;
    min-height: 80px;
}

.adult-confirmation {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin: -4px 0 18px;
    color: var(--ink-secondary);
    font-size: 13px;
    line-height: 1.5;
    cursor: pointer;
}

.adult-confirmation input {
    width: 18px;
    height: 18px;
    margin: 1px 0 0;
    accent-color: var(--teal);
    flex: 0 0 auto;
}

.sms-code-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 112px;
    gap: 10px;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    border: none;
    border-radius: var(--radius);
    font-size: 15px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all 200ms ease;
}

.btn-primary {
    background: linear-gradient(145deg, var(--teal), var(--teal-dark));
    color: #fff;
    box-shadow: 0 4px 16px rgba(23, 100, 95, 0.25);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(23, 100, 95, 0.3);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--line);
    color: var(--ink-secondary);
}

.btn-outline:hover {
    background: var(--surface-hover);
    border-color: var(--teal);
    color: var(--teal);
}

.btn-ghost {
    background: transparent;
    color: var(--muted);
}

.btn-ghost:hover {
    background: var(--soft);
    color: var(--ink);
}

.btn-secondary {
    border: 1px solid rgba(44, 139, 131, .3);
    background: var(--mist);
    color: var(--teal-dark);
}

.btn-secondary:hover {
    border-color: var(--teal);
    background: var(--soft);
}

.btn-danger {
    border: 1px solid rgba(223, 126, 108, .35);
    background: rgba(223, 126, 108, .08);
    color: var(--coral);
}

.btn-danger:hover {
    border-color: var(--coral);
    background: rgba(223, 126, 108, .14);
}

.btn-block {
    width: 100%;
}

.btn:disabled {
    cursor: not-allowed;
    opacity: 0.65;
    transform: none;
}

.btn-sms {
    min-width: 112px;
    padding-inline: 12px;
    white-space: nowrap;
}

.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: none;
    border-radius: var(--radius);
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    transition: all 200ms ease;
}

.btn-icon:hover {
    background: var(--soft);
    color: var(--ink);
}

/* Auth Error */
.auth-error {
    margin-top: 16px;
    padding: 12px 16px;
    border-radius: var(--radius);
    background: rgba(223, 126, 108, 0.1);
    color: var(--coral);
    font-size: 13px;
    display: none;
}

.auth-error.visible {
    display: block;
    animation: shake 400ms ease;
}

/* Public product guides: keep the discovery links quiet but crawlable. */
.auth-seo-nav {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 6px 14px;
    margin-top: 18px;
    padding-top: 14px;
    border-top: 1px solid var(--line);
    font-size: 12px;
}

.auth-seo-nav a {
    color: var(--muted);
    text-decoration: none;
}

.auth-seo-nav a:hover,
.auth-seo-nav a:focus-visible {
    color: var(--teal-dark);
    text-decoration: underline;
}

/* Spinner */
.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 600ms linear infinite;
}

.spinner.large {
    width: 32px;
    height: 32px;
    border-width: 3px;
    border-color: rgba(44, 139, 131, 0.2);
    border-top-color: var(--teal);
}

/* ========== Chat View ========== */
#chat-view {
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    background: var(--paper);
}

.chat-layout {
    display: flex;
    height: 100%;
    width: 100%;
    max-width: 960px;
    margin: 0 auto;
    background: var(--surface);
}

/* Sidebar */
.sidebar {
    width: 260px;
    height: 100%;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--line);
    display: flex;
    flex-direction: column;
    backdrop-filter: blur(16px);
    transition: transform 300ms ease;
}

.sidebar-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 20px 20px 16px;
    border-bottom: 1px solid var(--line);
}

.brand-name {
    font-size: 16px;
    font-weight: 700;
    color: var(--ink);
}

.sidebar-close {
    margin-left: auto;
    display: none;
}

.sidebar-nav {
    flex: 1;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border: none;
    border-left: 3px solid transparent;
    border-radius: 0 var(--radius) var(--radius) 0;
    background: transparent;
    color: var(--muted);
    font-size: 14px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: all 200ms ease;
    text-align: left;
}

.nav-item:hover {
    background: var(--surface-hover);
    color: var(--ink);
    border-left-color: var(--line);
}

.nav-item.active {
    background: var(--mist);
    color: var(--teal-dark);
    font-weight: 600;
    border-left-color: var(--teal);
}

:root[data-theme="dark"] .nav-item.active {
    background: rgba(60, 184, 168, 0.12);
    color: var(--teal-light);
}

.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--line);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.sidebar-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.user-avatar {
    width: 36px;
    height: 36px;
    border-radius: var(--radius);
    background: linear-gradient(145deg, var(--teal), var(--teal-dark));
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 700;
    padding: 0;
    border: 0;
    overflow: hidden;
    cursor: pointer;
    position: relative;
    font-family: inherit;
}

.user-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.user-avatar:disabled {
    cursor: default;
    opacity: .75;
}

/* Story mode */
.story-plaza {
    padding: 24px;
    overflow-y: auto;
    height: calc(100vh - 72px);
}

.story-plaza-intro {
    max-width: 720px;
    margin: 0 auto 22px;
}

.story-plaza-intro h3 { font-size: 26px; margin: 0 0 8px; }
.story-plaza-intro p { color: var(--muted); line-height: 1.65; }

.story-package-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 16px;
    max-width: 960px;
    margin: 0 auto;
}

.story-package-card {
    min-height: 154px;
    padding: 16px;
    border: 0;
    border-radius: 22px;
    color: #fff;
    text-align: left;
    box-shadow: var(--shadow);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    font-family: inherit;
    transition: transform 180ms ease, box-shadow 180ms ease;
}

.story-package-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.story-package-card h3 { margin: 0 0 5px; font-size: 21px; }
.story-package-genre { opacity: .82; font-size: 13px; }
.story-package-badge { align-self: flex-start; margin-top: 10px; padding: 4px 8px; border: 1px solid rgba(255,255,255,.5); border-radius: 999px; background: rgba(10, 20, 28, .24); font-size: 11px; font-weight: 600; }
.story-package-summary { margin: 10px 0; line-height: 1.45; flex: 1; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.story-package-meta { opacity: .82; font-size: 12px; }
.story-detail-overlay { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 20px; background: rgba(18, 28, 34, .55); }
.story-detail-card { position: relative; width: min(620px, 100%); max-height: min(760px, 90vh); overflow-y: auto; padding: 28px; border-radius: 20px; background: var(--surface); box-shadow: var(--shadow-lg); }
.story-detail-card h2 { margin: 4px 0 14px; }.story-detail-card h3 { margin: 22px 0 8px; }.story-detail-card p { line-height: 1.65; }.story-detail-meta { color: var(--muted); font-size: 13px; }.story-detail-close { position: absolute; top: 10px; right: 14px; border: 0; background: none; font-size: 28px; cursor: pointer; color: var(--muted); }.story-detail-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 26px; }

.story-sessions { max-width: 960px; margin: 0 auto; }
.story-sessions h3 { font-size: 17px; margin: 0 0 10px; }
.story-sessions:not(:empty) { margin-bottom: 26px; }
.story-session-item { width: 100%; display: flex; align-items: center; gap: 12px; padding: 13px 16px; margin-bottom: 8px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); cursor: pointer; font-family: inherit; font-size: 14px; text-align: left; transition: border-color 150ms ease, box-shadow 150ms ease; }
.story-session-item:hover { border-color: var(--teal); box-shadow: var(--shadow); }
.story-session-item:disabled { opacity: .6; cursor: default; }
.story-session-info { flex: 1; min-width: 0; }
.story-session-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.story-session-meta { color: var(--muted); font-size: 12px; margin-top: 2px; }
.story-session-arrow { color: var(--muted); font-size: 18px; }

.story-chat { height: calc(100vh - 72px); display: flex; flex-direction: column; }
.story-chat[hidden] { display: none; }
.story-memory-notice { padding: 8px 16px; text-align: center; background: var(--mist); color: var(--muted); font-size: 12px; }
.story-messages { flex: 1; overflow-y: auto; padding: 22px max(18px, calc((100% - 760px) / 2)); }
.story-message { max-width: 78%; padding: 13px 15px; margin-bottom: 14px; border-radius: 18px; line-height: 1.65; white-space: pre-wrap; }
.story-message.user { margin-left: auto; color: #fff; background: var(--teal); border-bottom-right-radius: 5px; }
.story-message.assistant { background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 5px; }
.story-variant-controls { display: flex; align-items: center; gap: 5px; margin-top: 9px; color: var(--muted); }
.story-variant-controls button { border: 0; background: transparent; color: inherit; cursor: pointer; padding: 4px 7px; border-radius: 8px; }
.story-variant-controls button:hover:not(:disabled) { background: var(--mist); color: var(--teal-dark); }
.story-variant-controls button:disabled { opacity: .35; cursor: default; }
.story-composer { border-top: 1px solid var(--line); background: var(--surface); padding: 10px max(14px, calc((100% - 780px) / 2)); }
.story-candidate-toggle { display: inline-flex; gap: 7px; align-items: center; color: var(--muted); font-size: 12px; margin-bottom: 7px; }
.story-input-row { display: flex; align-items: flex-end; gap: 9px; }
.story-input-row textarea { flex: 1; resize: none; min-height: 42px; max-height: 140px; }

@media (max-width: 768px) {
    .story-plaza { padding: 16px; }
    .story-package-grid { grid-template-columns: 1fr; }
    .story-message { max-width: 90%; }
    #story-import-btn { padding: 8px 10px; font-size: 12px; }
}

.user-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--ink);
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    position: relative;
}

.panel {
    display: none;
    flex-direction: column;
    height: 100%;
}

.panel.active {
    display: flex;
}

/* Chat Header */
.chat-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
}

.chat-title {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 10px;
}

.chat-title h2 {
    font-size: 16px;
    font-weight: 600;
}

.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border-radius: var(--radius-full);
    font-size: 12px;
    font-weight: 500;
}

.status-badge.online {
    background: rgba(44, 139, 131, 0.1);
    color: var(--teal);
}

.status-badge.online::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--teal);
    animation: pulse 2s ease infinite;
}

/* Theme Toggle */
.theme-toggle .icon-sun,
.theme-toggle .icon-moon {
    display: none;
}

:root:not([data-theme="dark"]) .theme-toggle .icon-moon {
    display: block;
}

:root[data-theme="dark"] .theme-toggle .icon-sun {
    display: block;
}

/* Chat Messages */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    scroll-behavior: smooth;
    position: relative;
    background:
        var(--chat-bg-overlay),
        var(--char-img) center bottom / cover no-repeat;
    background-attachment: scroll;
    transition: background 500ms ease;
}

.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: var(--line);
    border-radius: 3px;
}

/* Welcome Message */
.welcome-message {
    text-align: center;
    padding: 48px 20px 56px;
    color: var(--muted);
    position: relative;
}

.welcome-avatar {
    width: 80px;
    height: 80px;
    margin: 0 auto 18px;
    border-radius: 24px;
    background: var(--char-img) center/cover no-repeat;
    box-shadow:
        0 8px 28px var(--char-accent-light),
        0 2px 8px rgba(0, 0, 0, 0.08);
    border: 2px solid var(--char-accent-light);
    position: relative;
    transition: background 400ms ease, box-shadow 400ms ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.welcome-avatar::after {
    content: '';
    position: absolute;
    inset: -6px;
    border-radius: 28px;
    border: 1px solid var(--char-accent-light);
    opacity: 0.5;
    pointer-events: none;
}

.welcome-message h3 {
    font-size: 20px;
    font-weight: 600;
    color: var(--ink);
    margin-bottom: 8px;
}

.welcome-message p {
    font-size: 14px;
}

.welcome-message .welcome-opening {
    max-width: 420px;
    margin: 14px auto 0;
    padding: 13px 16px;
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
    color: var(--ink-secondary);
    line-height: 1.65;
    text-align: left;
}

.welcome-action-hint {
    margin-top: 18px;
    color: var(--muted);
    font-size: 12px;
}

/* Message Bubbles */
.message {
    display: flex;
    flex-direction: column;
    max-width: 75%;
}

.message.message-enter {
    transform-origin: top left;
    animation: messagePop 210ms cubic-bezier(.2, .8, .2, 1) both;
}

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

.message.ai {
    align-self: flex-start;
    max-width: 75%;
    flex-direction: row;
    align-items: flex-start;
    gap: 8px;
}

/* AI Avatar */
.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 10px;
    background: var(--char-img) center/cover no-repeat;
    flex-shrink: 0;
    box-shadow: 0 2px 8px var(--char-accent-light);
    border: 1.5px solid var(--char-accent-light);
    transition: background 400ms ease;
    margin-top: 6px;
}

.message.ai .message-content {
    display: flex;
    flex-direction: column;
    min-width: 0;
    flex: 1;
}

.message-bubble {
    padding: 12px 16px;
    border-radius: var(--radius-lg);
    font-size: 15px;
    line-height: 1.6;
    word-wrap: break-word;
    white-space: pre-wrap;
}

.message.user .message-bubble {
    background: var(--bubble-user);
    color: var(--bubble-user-text);
    border-top-right-radius: 4px;
}

.message.ai .message-bubble {
    background: var(--bubble-ai);
    color: var(--bubble-ai-text);
    border: 1px solid var(--line);
    border-top-left-radius: 4px;
    box-shadow: var(--shadow-sm);
    width: fit-content;
    max-width: 100%;
}

/* 动作描述斜体文本（*动作*） */
.action-text {
    font-style: italic;
    color: var(--muted);
    opacity: 0.8;
}

/* 表情包图片（嵌在气泡内） */
.message-sticker {
    display: block;
    max-width: 140px;
    max-height: 140px;
    border-radius: var(--radius);
    margin: 4px 0;
    object-fit: contain;
}

/* Message Timestamp */
.message-time {
    font-size: 11px;
    color: var(--muted);
    margin-top: 4px;
    padding: 0 4px;
    opacity: 0.7;
}

.message.user .message-time {
    text-align: right;
}

.message.ai .message-time {
    text-align: left;
}

/* Chat Input */
.chat-input-container {
    padding: 16px 20px 20px;
    background: var(--surface);
    border-top: 1px solid var(--line);
}

.media-compose-preview {
    position: relative;
    width: min(280px, 100%);
    min-height: 78px;
    margin: 0 0 10px;
    padding: 8px 38px 8px 8px;
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--input-bg);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
}

.media-compose-preview[hidden] { display: none; }

.media-compose-thumb {
    width: 62px;
    height: 62px;
    flex: 0 0 62px;
    overflow: hidden;
    border-radius: 10px;
    background: var(--soft);
}

.media-compose-thumb img,
.media-compose-thumb video {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.media-compose-meta {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.media-compose-name {
    overflow: hidden;
    color: var(--ink);
    font-size: 13px;
    font-weight: 600;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.media-compose-status { color: var(--muted); font-size: 12px; }

.media-compose-remove {
    position: absolute;
    top: 6px;
    right: 7px;
    width: 26px;
    height: 26px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--muted);
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
}

.media-compose-remove:hover { background: var(--soft); color: var(--ink); }

.chat-input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    padding: 8px 8px 8px 16px;
    background: var(--input-bg);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    transition: border-color 200ms ease, box-shadow 200ms ease;
}

.chat-input-wrapper:focus-within {
    border-color: var(--teal);
    box-shadow: 0 0 0 3px rgba(44, 139, 131, 0.1);
}

.chat-input {
    flex: 1;
    border: none;
    background: transparent;
    color: var(--ink);
    font-size: 15px;
    font-family: inherit;
    line-height: 1.5;
    resize: none;
    outline: none;
    max-height: 120px;
    padding: 6px 0;
}

.chat-input::placeholder {
    color: var(--muted);
}

.btn-send {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: none;
    border-radius: var(--radius);
    background: var(--teal);
    color: #fff;
    cursor: pointer;
    transition: all 200ms ease;
    flex-shrink: 0;
}

.btn-send:hover:not(:disabled) {
    background: var(--teal-dark);
    transform: scale(1.05);
}

.btn-send:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* Voice Button */
.btn-voice {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: none;
    border-radius: var(--radius);
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    transition: all 200ms ease;
    flex-shrink: 0;
}

.btn-attach {
    width: 40px;
    height: 40px;
    flex: 0 0 40px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--text-secondary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.btn-attach:hover { background: var(--bg-secondary); color: var(--primary); }
.btn-attach:disabled { opacity: .45; cursor: not-allowed; }

.btn-voice:hover {
    background: var(--soft);
    color: var(--teal);
}

.btn-voice:active {
    transform: scale(0.95);
}

.btn-voice.recording {
    color: #fff;
    background: var(--coral);
    box-shadow: 0 0 0 5px rgba(223, 126, 108, 0.16);
    animation: voicePulse 1.2s ease-in-out infinite;
}

.realtime-call-btn {
    color: var(--teal);
}

.realtime-call-btn.connecting {
    animation: pulse 1s ease-in-out infinite;
}

.realtime-call-btn.active {
    color: #fff;
    background: var(--coral);
    box-shadow: 0 0 0 5px rgba(223, 126, 108, 0.14);
    animation: voicePulse 1.4s ease-in-out infinite;
}

.voice-player {
    display: block;
    width: min(240px, 100%);
    height: 32px;
    margin: 8px 4px 0;
}

.voice-bubble {
    min-width: 112px;
    height: 46px;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 0 14px;
    border: 0;
    border-radius: var(--radius-lg);
    color: inherit;
    background: var(--bubble-ai);
    cursor: pointer;
    box-shadow: var(--shadow-sm);
}

.message.user .voice-bubble {
    flex-direction: row-reverse;
    background: var(--bubble-user);
    color: var(--bubble-user-text);
    border-top-right-radius: 4px;
}

.message.ai .voice-bubble {
    border: 1px solid var(--line);
    border-top-left-radius: 4px;
}

.voice-wave {
    height: 22px;
    display: inline-flex;
    align-items: center;
    gap: 2px;
}

.voice-wave i {
    width: 2px;
    height: 7px;
    border-radius: 2px;
    background: currentColor;
    opacity: .75;
}

.voice-wave i:nth-child(2) { height: 14px; }
.voice-wave i:nth-child(3) { height: 20px; }

.voice-bubble.playing .voice-wave i {
    animation: voiceBars .75s ease-in-out infinite alternate;
}

.voice-bubble.playing .voice-wave i:nth-child(2) { animation-delay: .15s; }
.voice-bubble.playing .voice-wave i:nth-child(3) { animation-delay: .3s; }
.voice-bubble.loading { opacity: .65; cursor: wait; }
.voice-duration { min-width: 28px; font-size: 12px; opacity: .75; }
.voice-speaker { font-size: 20px; line-height: 1; }

@keyframes voiceBars {
    from { transform: scaleY(.45); }
    to { transform: scaleY(1); }
}

.input-hint {
    margin-top: 8px;
    text-align: center;
    font-size: 12px;
    color: var(--muted);
}

/* ========== Character Dropdown ========== */
.character-switch-wrapper {
    position: relative;
}

.character-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    z-index: 50;
    min-width: 220px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 6px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-6px);
    transition: all 200ms ease;
}

.character-dropdown.open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.character-dropdown-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    width: 100%;
    cursor: pointer;
    transition: background 150ms ease;
    text-align: left;
    font-family: inherit;
}

.character-dropdown-item:hover {
    background: var(--surface-hover);
}

.character-dropdown-item.active {
    background: var(--mist);
}

:root[data-theme="dark"] .character-dropdown-item.active {
    background: rgba(60, 184, 168, 0.12);
}

.character-dropdown-avatar {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    background-size: cover;
    background-position: center;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.character-dropdown-info {
    flex: 1;
    min-width: 0;
}

.character-dropdown-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--ink);
    display: block;
}

.character-dropdown-desc {
    font-size: 12px;
    color: var(--muted);
    display: block;
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.character-dropdown-check {
    width: 18px;
    height: 18px;
    color: var(--teal);
    flex-shrink: 0;
}

/* ========== Welcome Starter Cards ========== */
.welcome-starters {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    margin-top: 10px;
    max-width: 420px;
    margin-left: auto;
    margin-right: auto;
}

.starter-card {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    border: 1px solid var(--line);
    border-radius: var(--radius-full);
    background: var(--surface);
    color: var(--ink-secondary);
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
    transition: all 200ms ease;
    box-shadow: var(--shadow-sm);
}

.starter-card:hover {
    border-color: var(--teal);
    color: var(--teal);
    box-shadow: 0 4px 16px rgba(44, 139, 131, 0.12);
    transform: translateY(-1px);
}

.starter-card-emoji {
    font-size: 16px;
    flex-shrink: 0;
}

/* ========== Header Overflow Menu ========== */
.header-overflow-wrapper {
    position: relative;
}

.btn-overflow {
    display: none;
}

.header-overflow-menu {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    z-index: 50;
    min-width: 160px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 4px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-4px);
    transition: all 200ms ease;
}

.header-overflow-menu.open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.overflow-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--ink-secondary);
    font-size: 14px;
    font-family: inherit;
    cursor: pointer;
    width: 100%;
    text-align: left;
    transition: background 150ms ease;
}

.overflow-item:hover {
    background: var(--surface-hover);
    color: var(--ink);
}

.overflow-item svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

/* ========== Realtime Call Screen ========== */
.call-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    color: #fff;
    background:
        radial-gradient(circle at 50% 28%, rgba(84, 199, 181, .26), transparent 34%),
        linear-gradient(165deg, #173f43 0%, #102e33 48%, #0b2025 100%);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: scale(1.015);
    transition: opacity 220ms ease, transform 300ms ease, visibility 220ms;
}

.call-overlay.active {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: scale(1);
}

.call-background-glow {
    position: absolute;
    border-radius: 50%;
    filter: blur(10px);
    pointer-events: none;
}

.call-background-glow.glow-one {
    width: 340px;
    height: 340px;
    top: -170px;
    right: -80px;
    background: rgba(60, 184, 168, .12);
}

.call-background-glow.glow-two {
    width: 300px;
    height: 300px;
    bottom: -180px;
    left: -100px;
    background: rgba(223, 126, 108, .12);
}

.call-topbar {
    position: relative;
    z-index: 1;
    display: flex;
    justify-content: center;
    padding: max(28px, env(safe-area-inset-top)) 24px 8px;
}

.call-encrypted {
    padding: 7px 13px;
    border: 1px solid rgba(255, 255, 255, .12);
    border-radius: var(--radius-full);
    color: rgba(255, 255, 255, .66);
    background: rgba(255, 255, 255, .06);
    font-size: 12px;
    letter-spacing: .04em;
}

.call-main {
    position: relative;
    z-index: 1;
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 0;
    padding: 12px 24px;
}

.call-avatar-wrap {
    position: relative;
    display: grid;
    place-items: center;
    width: 168px;
    height: 168px;
    margin-bottom: 32px;
}

.call-avatar {
    position: relative;
    z-index: 2;
    display: grid;
    place-items: center;
    width: 126px;
    height: 126px;
    border: 1px solid rgba(255, 255, 255, .2);
    border-radius: 42px;
    background:
        var(--char-img) center/cover no-repeat,
        linear-gradient(145deg, rgba(74, 187, 170, .95), rgba(31, 112, 106, .96));
    box-shadow: 0 24px 70px rgba(0, 0, 0, .34), inset 0 1px 0 rgba(255, 255, 255, .25);
    font-size: 0;
    font-weight: 700;
    color: transparent;
    overflow: hidden;
    transition: background 400ms ease;
}

.call-ring {
    position: absolute;
    border: 1px solid rgba(93, 211, 193, .28);
    border-radius: 50%;
    opacity: .5;
}

.call-ring.ring-one { inset: 8px; }
.call-ring.ring-two { inset: -8px; opacity: .25; }

.call-avatar-wrap.listening .call-ring,
.call-avatar-wrap.speaking .call-ring {
    animation: callRing 1.8s ease-out infinite;
}

.call-avatar-wrap.speaking .ring-two { animation-delay: .55s; }

.call-main h2 {
    margin-bottom: 8px;
    font-size: 28px;
    font-weight: 650;
    letter-spacing: .04em;
}

.call-status {
    min-height: 24px;
    color: rgba(255, 255, 255, .72);
    font-size: 15px;
}

.call-duration {
    margin-top: 6px;
    color: rgba(255, 255, 255, .46);
    font-variant-numeric: tabular-nums;
    font-size: 14px;
    letter-spacing: .08em;
}

.call-wave {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    height: 42px;
    margin-top: 20px;
    opacity: .2;
    transition: opacity 200ms ease;
}

.call-wave.active { opacity: .9; }

.call-wave span {
    width: 3px;
    height: 8px;
    border-radius: 4px;
    background: #79d9ca;
}

.call-wave.active span { animation: callWave .9s ease-in-out infinite alternate; }
.call-wave span:nth-child(2), .call-wave span:nth-child(8) { animation-delay: .12s; }
.call-wave span:nth-child(3), .call-wave span:nth-child(7) { animation-delay: .24s; }
.call-wave span:nth-child(4), .call-wave span:nth-child(6) { animation-delay: .36s; }
.call-wave span:nth-child(5) { animation-delay: .48s; }

.call-actions {
    position: relative;
    z-index: 1;
    display: flex;
    justify-content: center;
    gap: 76px;
    padding: 18px 24px max(42px, env(safe-area-inset-bottom));
}

.call-action-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    min-width: 76px;
    color: rgba(255, 255, 255, .75);
    font-size: 13px;
}

.call-control {
    display: grid;
    place-items: center;
    width: 64px;
    height: 64px;
    border: none;
    border-radius: 50%;
    color: #fff;
    cursor: pointer;
    transition: transform 160ms ease, background 160ms ease;
}

.call-control:active { transform: scale(.92); }
.call-control.mute { background: rgba(255, 255, 255, .14); }
.call-control.mute:hover { background: rgba(255, 255, 255, .22); }
.call-control.hangup { background: #e85d55; box-shadow: 0 12px 30px rgba(232, 93, 85, .28); }
.call-control.hangup:hover { background: #f06b63; }
.call-control .mic-off { display: none; }
.call-control.muted { background: rgba(255, 255, 255, .9); color: #173f43; }
.call-control.muted .mic-on { display: none; }
.call-control.muted .mic-off { display: block; }

/* ========== Voice History ========== */
.voice-memory-badge {
    padding: 4px 9px;
    border-radius: var(--radius-full);
    color: var(--teal);
    background: rgba(44, 139, 131, .1);
    font-size: 11px;
    font-weight: 600;
}

.voice-history-content {
    flex: 1;
    overflow-y: auto;
    padding: 22px 20px 40px;
}

.voice-history-loading,
.voice-history-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 55vh;
    color: var(--muted);
    text-align: center;
}

.voice-history-empty > span { margin-bottom: 14px; font-size: 44px; }
.voice-history-empty h3 { margin-bottom: 7px; color: var(--ink); font-size: 18px; }
.voice-history-empty p { max-width: 340px; font-size: 13px; }

.voice-call-card {
    max-width: 720px;
    margin: 0 auto 18px;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
}

.voice-call-heading {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 18px;
    border-bottom: 1px solid var(--line);
    background: linear-gradient(135deg, var(--mist), var(--surface));
}

.voice-call-icon {
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    border-radius: 12px;
    color: #fff;
    background: var(--teal);
    font-size: 18px;
}

.voice-call-heading div:nth-child(2) { flex: 1; min-width: 0; }
.voice-call-heading h3 { color: var(--ink); font-size: 14px; }
.voice-call-heading p { color: var(--muted); font-size: 11px; }
.voice-call-heading > span { color: var(--muted); font-size: 11px; }

.voice-transcript-list {
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 18px;
}

.voice-transcript {
    max-width: 82%;
}

.voice-transcript.user { align-self: flex-end; }
.voice-transcript.assistant { align-self: flex-start; }

.voice-transcript-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0 5px 4px;
    color: var(--muted);
    font-size: 10px;
}

.voice-transcript.user .voice-transcript-meta { justify-content: flex-end; }
.voice-transcript-meta strong { color: var(--ink-secondary); font-size: 11px; }

.voice-transcript > p {
    padding: 10px 13px;
    border-radius: 15px;
    color: var(--ink);
    background: var(--soft);
    font-size: 14px;
    line-height: 1.6;
}

.voice-transcript.user > p {
    color: #fff;
    background: var(--teal);
    border-bottom-right-radius: 4px;
}

.voice-transcript.assistant > p {
    border: 1px solid var(--line);
    background: var(--surface-hover);
    border-bottom-left-radius: 4px;
}

/* ========== Companion Settings ========== */
.companion-content {
    flex: 1;
    overflow-y: auto;
    padding: 24px 20px 32px;
}

.relationship-card,
.setting-section {
    max-width: 680px;
    margin: 0 auto 24px;
}

.relationship-card {
    padding: 22px;
    border: 1px solid rgba(44, 139, 131, 0.2);
    border-radius: var(--radius-lg);
    background: linear-gradient(135deg, var(--mist), var(--surface));
}

.relationship-heading {
    display: flex;
    align-items: center;
    gap: 12px;
}

.relationship-emoji {
    display: grid;
    place-items: center;
    width: 48px;
    height: 48px;
    border-radius: 16px;
    background: var(--surface);
    font-size: 24px;
    box-shadow: var(--shadow-sm);
}

.eyebrow {
    color: var(--teal);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: .08em;
}

.relationship-heading h3,
.setting-section h3 {
    color: var(--ink);
    font-size: 18px;
}

.relationship-heading strong {
    margin-left: auto;
    color: var(--teal-dark);
    font-size: 26px;
}

.relationship-heading strong small {
    color: var(--muted);
    font-size: 12px;
    font-weight: 500;
}

.affinity-track {
    height: 8px;
    margin: 18px 0 10px;
    overflow: hidden;
    border-radius: var(--radius-full);
    background: rgba(44, 139, 131, .14);
}

.affinity-track span {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--teal), var(--teal-light));
    transition: width 300ms ease;
}

.relationship-card > p {
    color: var(--ink-secondary);
    font-size: 14px;
}

.relationship-card .relationship-tip {
    margin-top: 10px;
    color: var(--muted);
    font-size: 12px;
}

.setting-section-heading {
    margin-bottom: 12px;
}

.setting-heading-row {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
}

.setting-heading-row .btn {
    flex-shrink: 0;
    padding: 9px 14px;
    font-size: 13px;
}

.choice-grid {
    display: grid;
    gap: 10px;
}

.persona-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.scenario-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.choice-card {
    position: relative;
    display: flex;
    align-items: flex-start;
    gap: 10px;
    min-height: 88px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--ink);
    text-align: left;
    font: inherit;
    cursor: pointer;
    transition: border-color 180ms ease, box-shadow 180ms ease, transform 180ms ease;
}

.choice-card:hover {
    border-color: rgba(44, 139, 131, .55);
    transform: translateY(-1px);
}

.choice-card.selected {
    border-color: var(--teal);
    box-shadow: 0 0 0 3px rgba(44, 139, 131, .12);
}

.choice-emoji {
    font-size: 23px;
    line-height: 1;
}

.choice-copy {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding-right: 16px;
}

.choice-copy strong { font-size: 14px; }
.choice-copy small { color: var(--muted); font-size: 12px; line-height: 1.5; }

.choice-check {
    position: absolute;
    top: 10px;
    right: 10px;
    display: none;
    color: var(--teal);
    font-weight: 800;
}

.choice-card.selected .choice-check { display: block; }

/* Character Card with Image */
.character-card {
    min-height: 110px;
    overflow: hidden;
    padding: 0;
}

.character-card .character-card-bg {
    position: absolute;
    inset: 0;
    background-size: cover;
    background-position: center;
    opacity: 0.12;
    transition: opacity 300ms ease;
    pointer-events: none;
}

.character-card:hover .character-card-bg {
    opacity: 0.22;
}

.character-card.selected .character-card-bg {
    opacity: 0.18;
}

.character-card .character-card-inner {
    position: relative;
    z-index: 1;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px;
    height: 100%;
}

.character-card-avatar {
    width: 56px;
    height: 56px;
    border-radius: 16px;
    background-size: cover;
    background-position: center;
    flex-shrink: 0;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
    border: 2px solid var(--char-accent-light);
    transition: transform 300ms ease, box-shadow 300ms ease;
}

.character-card:hover .character-card-avatar {
    transform: scale(1.05);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
}

.character-card.selected .character-card-avatar {
    border-color: var(--teal);
    box-shadow: 0 0 0 3px var(--char-accent-light), 0 6px 20px rgba(0, 0, 0, 0.15);
}

.companion-save-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    max-width: 680px;
    margin: 0 auto;
    padding: 16px 0;
}

.companion-save-row p { color: var(--muted); font-size: 12px; }

.custom-relationship-card {
    background: linear-gradient(135deg, rgba(44, 139, 131, .1), var(--surface));
}

.custom-character-create {
    margin-top: 16px;
    padding: 18px;
    border: 1px dashed rgba(44, 139, 131, .42);
    border-radius: var(--radius-lg);
    background: var(--soft);
}

.custom-character-form {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}

.custom-character-form label {
    display: flex;
    flex-direction: column;
    gap: 7px;
    color: var(--ink-secondary);
    font-size: 13px;
    font-weight: 600;
}

.custom-character-form input,
.custom-character-form textarea,
.custom-character-form select {
    width: 100%;
    padding: 11px 12px;
    border: 1px solid var(--line);
    border-radius: 12px;
    outline: none;
    background: var(--surface);
    color: var(--ink);
    font: inherit;
    font-weight: 400;
    transition: border-color 180ms ease, box-shadow 180ms ease;
}

.custom-character-form input[type="file"] {
    min-height: 44px;
    padding: 8px;
    color: var(--muted);
}

.custom-character-form input:focus,
.custom-character-form textarea:focus,
.custom-character-form select:focus {
    border-color: var(--teal);
    box-shadow: 0 0 0 3px rgba(44, 139, 131, .12);
}

.custom-character-form textarea {
    min-height: 132px;
    resize: vertical;
    line-height: 1.6;
}

.custom-character-identity,
.custom-character-examples,
.custom-character-note,
.custom-character-actions {
    grid-column: 1 / -1;
}

.character-voice-picker {
    display: flex;
    gap: 8px;
}

.character-voice-picker select {
    flex: 1;
    min-width: 0;
}

.character-voice-preview {
    flex: 0 0 auto;
}

.voice-clone-form {
    display: grid;
    gap: 12px;
    max-width: 720px;
}

.voice-clone-input-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
    align-items: end;
}
.voice-clone-input-row .btn { min-height: 44px; white-space: nowrap; }
.voice-clone-input-row .recording { color: var(--coral); border-color: var(--coral); }
.voice-clone-recording-hint { margin: -4px 0 0; color: var(--coral); font-size: 12px; }
.voice-clone-record-progress { width: 100%; height: 8px; accent-color: var(--teal); }

.voice-clone-form label {
    display: grid;
    gap: 6px;
    color: var(--ink-secondary);
    font-size: 13px;
    font-weight: 600;
}

.voice-clone-form input,
.voice-clone-form select {
    width: 100%;
    min-height: 44px;
    padding: 9px 11px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--surface);
    color: var(--ink);
    font: inherit;
}

.voice-clone-form .voice-clone-consent {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    font-weight: 400;
    line-height: 1.5;
}

.voice-clone-consent input {
    width: auto;
    min-height: auto;
    margin-top: 3px;
}

.voice-clone-form > .btn {
    justify-self: start;
}

.voice-clone-confirm {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    padding: 14px;
    border: 1px solid rgba(44, 139, 131, .24);
    border-radius: 14px;
    background: rgba(44, 139, 131, .06);
}

.voice-clone-confirm[hidden] { display: none; }
.voice-clone-confirm audio,
.voice-clone-confirm p,
.voice-clone-confirm .btn { grid-column: 1 / -1; }
.voice-clone-confirm audio { width: 100%; }
.voice-clone-confirm p,
.voice-clone-ready p { margin: 0; color: var(--muted); font-size: 12px; }
.voice-clone-ready { display: flex; align-items: center; gap: 10px; }

@media (max-width: 520px) {
    .voice-clone-input-row { grid-template-columns: 1fr; }
    .voice-clone-confirm { grid-template-columns: 1fr; }
    .voice-clone-confirm label { grid-column: 1; }
}

.custom-character-examples > span {
    color: var(--ink-secondary);
    font-size: 13px;
    font-weight: 600;
}

.custom-character-examples > p {
    margin: 5px 0 9px;
    color: var(--muted);
    font-size: 12px;
}

.dialogue-example-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 8px;
}

.custom-character-note {
    margin-top: -4px;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.55;
}

.custom-character-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 2px;
}

.custom-character-actions .btn-danger {
    margin-right: auto;
}

/* ========== Profile Panel ========== */
.profile-content {
    flex: 1;
    overflow-y: auto;
    padding: 24px 20px;
}

.profile-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px;
    gap: 16px;
    color: var(--muted);
}

.profile-empty {
    text-align: center;
    padding: 60px 20px;
    color: var(--muted);
}

.profile-empty-icon {
    font-size: 48px;
    margin-bottom: 16px;
}

.fact-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.fact-card {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 16px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    transition: all 200ms ease;
}

.fact-card:hover {
    border-color: var(--teal);
    box-shadow: var(--shadow-sm);
}

.fact-category {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 60px;
    padding: 4px 10px;
    border-radius: var(--radius-full);
    background: var(--mist);
    color: var(--teal-dark);
    font-size: 12px;
    font-weight: 600;
    flex-shrink: 0;
}

:root[data-theme="dark"] .fact-category {
    background: rgba(60, 184, 168, 0.15);
    color: var(--teal-light);
}

.fact-content {
    flex: 1;
    font-size: 14px;
    line-height: 1.6;
    color: var(--ink);
}

.fact-actions {
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: opacity 200ms ease;
}

.fact-card:hover .fact-actions {
    opacity: 1;
}

@media (hover: none) {
    .fact-actions {
        opacity: 1;
    }
}

.fact-action-btn {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    transition: all 150ms ease;
}

.fact-action-btn:hover {
    background: var(--soft);
    color: var(--coral);
}

.fact-action-btn.edit-fact:hover {
    color: var(--teal);
}

.add-fact-container {
    padding: 16px 20px;
    border-top: 1px solid var(--line);
}

.add-fact-container .btn {
    width: 100%;
}

/* ========== Modal ========== */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal.active {
    display: flex;
    animation: fadeIn 200ms ease;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
}

.modal-content {
    position: relative;
    width: 100%;
    max-width: 400px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    padding: 28px;
    box-shadow: var(--shadow-lg);
    animation: slideUp 300ms ease;
}

.modal-content h3 {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 20px;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 24px;
}

.account-data-modal-content > p,
.account-danger-zone p {
    color: var(--muted);
    font-size: 14px;
    line-height: 1.65;
}

.account-danger-zone {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid var(--line);
}

.account-danger-zone h4 {
    margin-bottom: 6px;
    color: var(--coral);
    font-size: 15px;
}

.account-danger-zone .form-group:first-of-type {
    margin-top: 18px;
}

.account-data-error {
    min-height: 20px;
    margin-top: 10px;
    color: var(--coral);
    font-size: 13px;
}

/* ========== Toast ========== */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 14px 20px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    font-size: 14px;
    animation: slideIn 300ms ease;
    max-width: 320px;
}

.toast.error {
    border-color: var(--coral);
    color: var(--coral);
}

.toast.success {
    border-color: var(--teal);
    color: var(--teal);
}

/* ========== Animations ========== */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

@keyframes messagePop {
    from { opacity: 0; transform: translateY(8px) scale(.985); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

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

@keyframes spin {
    to { transform: rotate(360deg); }
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

@keyframes voicePulse {
    50% { transform: scale(1.07); }
}

@keyframes callRing {
    0% { transform: scale(.82); opacity: .7; }
    100% { transform: scale(1.14); opacity: 0; }
}

@keyframes callWave {
    from { height: 7px; }
    to { height: 30px; }
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-4px); }
    40%, 80% { transform: translateX(4px); }
}

/* ========== Responsive ========== */
@media (max-width: 768px) {
    .chat-layout {
        max-width: 100%;
        border-left: none;
        border-right: none;
    }

    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        height: auto;
        z-index: 100;
        transform: translateX(-100%);
        box-shadow: var(--shadow-lg);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .call-avatar-wrap {
        width: 148px;
        height: 148px;
        margin-bottom: 24px;
    }

    .call-avatar {
        width: 112px;
        height: 112px;
        border-radius: 36px;
        font-size: 48px;
    }

    .call-actions { gap: 52px; }
    .voice-history-content { padding: 16px 12px 32px; }
    .voice-call-heading { padding: 14px; }
    .voice-transcript-list { padding: 14px; }
    .voice-transcript { max-width: 90%; }

    .sidebar-close {
        display: flex !important;
    }

    .sidebar-toggle {
        display: flex !important;
    }

    .message {
        max-width: 85%;
    }

    #auth-view {
        padding: 12px;
    }

    .auth-card {
        padding: 28px 24px;
    }

    .auth-header {
        margin-bottom: 24px;
    }

    .auth-tabs {
        margin-bottom: 20px;
    }

    .form-group {
        margin-bottom: 16px;
    }

    /* iOS Safari 对小于 16px 的输入框聚焦时会自动放大页面 */
    .form-group input,
    .form-group select,
    .form-group textarea,
    .chat-input {
        font-size: 16px;
    }

    .sms-code-row {
        grid-template-columns: 1fr;
    }

    .chat-header {
        padding: 12px 16px;
    }

    .chat-messages {
        padding: 16px;
    }

    .chat-input-container {
        padding: 12px 16px calc(16px + env(safe-area-inset-bottom, 0px));
    }

    .persona-grid,
    .scenario-grid {
        grid-template-columns: 1fr;
    }

    .setting-heading-row {
        align-items: flex-start;
    }

    .custom-character-form {
        grid-template-columns: 1fr;
    }

    .dialogue-example-row {
        grid-template-columns: 1fr;
    }

    .custom-character-actions {
        align-items: stretch;
        flex-direction: column-reverse;
    }

    .custom-character-actions .btn,
    .custom-character-actions .btn-danger {
        width: 100%;
        margin-right: 0;
    }

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

    .companion-save-row .btn {
        width: 100%;
    }

    /* #7: Header overflow on mobile */
    .btn-overflow {
        display: flex;
    }

    .chat-header > .character-switch-wrapper,
    .chat-header > .theme-toggle,
    .chat-header > .realtime-call-btn {
        display: none;
    }

    .welcome-starters {
        gap: 6px;
        margin-top: 16px;
    }

    .starter-card {
        padding: 8px 12px;
        font-size: 12px;
    }
}

@media (min-width: 769px) {
    .sidebar-toggle {
        display: none;
    }

    #chat-view {
        padding: 24px 32px;
    }

    .chat-layout {
        height: calc(100% - 48px);
        border-radius: var(--radius-lg);
        box-shadow: var(--shadow-lg);
        border: 1px solid var(--line);
        overflow: hidden;
    }
}

/* ========== Scrollbar ========== */
.sidebar::-webkit-scrollbar,
.profile-content::-webkit-scrollbar,
.companion-content::-webkit-scrollbar {
    width: 4px;
}

.sidebar::-webkit-scrollbar-thumb,
.profile-content::-webkit-scrollbar-thumb,
.companion-content::-webkit-scrollbar-thumb {
    background: var(--line);
    border-radius: 2px;
}

/* ========== Character Theme Transitions ========== */
.chat-layout,
.chat-header,
.chat-input-container,
.sidebar,
.message-bubble,
.welcome-avatar,
.message-avatar,
.call-avatar,
.brand-logo .brand-mark,
.btn.character-switch,
.character-dropdown-avatar,
.character-card-avatar {
    transition: background 500ms ease, border-color 300ms ease, box-shadow 400ms ease;
}

/* Avatar hover glow */
.message-avatar:hover {
    box-shadow: 0 4px 16px var(--char-accent-light);
    transform: scale(1.08);
    transition: transform 200ms ease, box-shadow 200ms ease;
}

/* Character card shine effect */
.character-card::after {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 60%;
    height: 100%;
    background: linear-gradient(
        90deg,
        transparent 0%,
        rgba(255, 255, 255, 0.06) 50%,
        transparent 100%
    );
    pointer-events: none;
    z-index: 2;
    transition: left 600ms ease;
}

.character-card:hover::after {
    left: 120%;
}

/* Welcome avatar floating animation */
@keyframes avatarFloat {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-4px); }
}

.welcome-avatar {
    animation: avatarFloat 4s ease-in-out infinite;
}

@media (prefers-reduced-motion: reduce) {
    .message.message-enter {
        animation-duration: 1ms;
    }
}

/* ========== Moments (朋友圈) ========== */
.nav-badge {
    margin-left: auto;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: var(--radius-full);
    background: var(--coral);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.nav-badge[hidden] {
    display: none;
}

.moments-content {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    max-width: 720px;
    width: 100%;
    margin: 0 auto;
}

.moments-content::-webkit-scrollbar {
    width: 6px;
}

.moments-content::-webkit-scrollbar-thumb {
    background: var(--line);
    border-radius: 3px;
}

.moments-empty {
    text-align: center;
    padding: 64px 20px;
    color: var(--muted);
}

.moments-empty-icon {
    font-size: 40px;
    margin-bottom: 12px;
}

.moments-empty h3 {
    color: var(--ink);
    font-size: 16px;
    margin-bottom: 6px;
}

.moment-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    padding: 16px 18px;
    box-shadow: var(--shadow-sm);
}

.moment-head {
    display: flex;
    align-items: center;
    gap: 10px;
}

.moment-avatar {
    width: 40px;
    height: 40px;
    border-radius: var(--radius);
    object-fit: cover;
    flex-shrink: 0;
}

.moment-avatar-user {
    background: linear-gradient(145deg, var(--teal), var(--teal-dark));
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    font-weight: 700;
}

.moment-head-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.moment-author {
    font-size: 14px;
    font-weight: 600;
    color: var(--teal-dark);
}

:root[data-theme="dark"] .moment-author {
    color: var(--teal-light);
}

.moment-time {
    font-size: 12px;
    color: var(--muted);
}

.moment-remove {
    border: none;
    background: transparent;
    color: var(--muted);
    font-size: 12px;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: var(--radius-sm);
}

.moment-remove:hover {
    color: var(--coral);
    background: var(--surface-hover);
}

.moment-text {
    margin: 10px 0 0;
    font-size: 14px;
    line-height: 1.7;
    color: var(--ink);
    word-break: break-word;
}

.moment-sticker {
    display: block;
    max-width: 140px;
    max-height: 140px;
    border-radius: var(--radius);
    margin-top: 10px;
}

.moment-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}

.moment-action {
    border: none;
    background: var(--soft);
    color: var(--ink-secondary);
    font-size: 12px;
    padding: 5px 12px;
    border-radius: var(--radius-full);
    cursor: pointer;
    transition: all 150ms ease;
}

.moment-action:hover {
    background: var(--surface-hover);
    color: var(--teal-dark);
}

.moment-action.liked {
    color: var(--coral);
    background: rgba(223, 126, 108, 0.12);
}

.moment-likes {
    margin-top: 10px;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    background: var(--soft);
    font-size: 12px;
    color: var(--coral);
}

.moment-comments {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.moment-comments:not(:empty) {
    margin-top: 8px;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    background: var(--soft);
}

.moment-comment {
    font-size: 13px;
    line-height: 1.6;
    color: var(--ink);
    word-break: break-word;
}

.moment-comment-author {
    font-weight: 600;
    color: var(--teal-dark);
}

:root[data-theme="dark"] .moment-comment-author {
    color: var(--teal-light);
}

.moment-comment-op {
    border: none;
    background: transparent;
    color: var(--muted);
    font-size: 12px;
    cursor: pointer;
    margin-left: 6px;
    padding: 0 2px;
}

.moment-comment-op:hover {
    color: var(--teal);
}

.moment-comment-op.remove:hover {
    color: var(--coral);
}

.moment-comment-input {
    display: flex;
    gap: 8px;
    margin-top: 10px;
}

.moment-comment-input input {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--input-bg);
    color: var(--ink);
    font-size: 13px;
    outline: none;
}

.moment-comment-input input:focus {
    border-color: var(--teal);
}

.moment-comment-input .btn {
    padding: 6px 16px;
    font-size: 13px;
}

.moments-load-more {
    align-self: center;
    margin: 4px 0 12px;
}

.moment-mention-suggestions {
    max-height: 220px;
    margin-top: 8px;
    overflow-y: auto;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow);
}

.moment-mention-suggestion {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 10px;
    border: 1px solid var(--line);
    border-width: 0 0 1px;
    padding: 9px 12px;
    background: transparent;
    color: var(--text);
    font: inherit;
    text-align: left;
    cursor: pointer;
    transition: border-color 150ms ease, background 150ms ease, color 150ms ease;
}

.moment-mention-suggestion:last-child {
    border-bottom: 0;
}

.moment-mention-suggestion:hover,
.moment-mention-suggestion:focus-visible,
.moment-mention-suggestion.active {
    background: var(--surface-hover);
    outline: none;
}

.moment-mention-suggestion-avatar {
    width: 34px;
    height: 34px;
    flex: 0 0 34px;
    border-radius: 10px;
    background-position: center;
    background-size: cover;
}

.moment-mention-suggestion-info {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.moment-mention-suggestion-name {
    font-weight: 650;
}

.moment-mention-suggestion-desc {
    overflow: hidden;
    color: var(--muted);
    font-size: 12px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.moment-mention-hint {
    margin: 8px 0 0;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.5;
}

.moments-setting-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 0;
    border-bottom: 1px solid var(--line);
    cursor: pointer;
}

.moments-setting-row:last-of-type {
    border-bottom: none;
}

.moments-setting-label {
    font-size: 14px;
    color: var(--ink);
}

.moments-setting-row input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--teal);
    cursor: pointer;
}

#compose-moment-btn {
    white-space: nowrap;
    padding: 8px 14px;
    font-size: 13px;
}

/* ==================== Reply Feedback ==================== */

.reply-feedback {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 4px;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.reply-feedback-menu {
    display: inline-flex;
    gap: 6px;
    margin-top: 6px;
    padding: 4px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--surface);
    box-shadow: 0 6px 18px rgba(21, 35, 41, .12);
}

.reply-feedback-menu .fb-btn {
    opacity: 1;
    color: var(--ink-secondary);
    font-size: 12px;
}

.message-content:hover .reply-feedback,
.reply-feedback.fb-submitted {
    opacity: 1;
}

@media (hover: none) {
    .reply-feedback { opacity: 0.6; }
}

.fb-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 13px;
    padding: 2px 5px;
    border-radius: 6px;
    opacity: 0.5;
    transition: opacity 0.15s, transform 0.15s, background 0.15s;
}

.fb-btn:hover {
    opacity: 1;
    background: rgba(0, 0, 0, 0.05);
    transform: scale(1.15);
}

.fb-btn:disabled {
    cursor: default;
    transform: none;
}

.fb-btn.fb-active {
    opacity: 1;
    transform: scale(1.2);
}

.fb-reasons {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    margin-top: 5px;
}

.fb-reason-chip {
    font-size: 11px;
    padding: 3px 9px;
    border-radius: 12px;
    border: 1px solid rgba(0, 0, 0, 0.12);
    background: rgba(255, 255, 255, 0.7);
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}

.fb-reason-chip:hover {
    background: rgba(223, 126, 108, 0.1);
    border-color: var(--coral);
}
/* ========================================
   Web/App 对齐新增：今日页 / 记忆子Tab / 设置
   ======================================== */

/* [hidden] 属性优先级兜底：新增容器多为 display 覆盖型样式 */
.memory-extra-content[hidden],
.settings-content[hidden],
.profile-content[hidden],
.add-fact-container[hidden] {
    display: none !important;
}

/* ---------- 今日页 ---------- */
.today-content {
    flex: 1;
    overflow-y: auto;
    padding: 24px 20px calc(24px + env(safe-area-inset-bottom, 0px));
    display: flex;
    flex-direction: column;
    gap: 14px;
    /* 桌面端限宽居中，移动端自然单列 */
    width: 100%;
    max-width: 620px;
    margin: 0 auto;
}

.today-header {
    padding: 8px 4px 4px;
}

.today-greeting {
    font-size: 24px;
    font-weight: 700;
    color: var(--ink);
}

.today-subtitle {
    margin-top: 6px;
    font-size: 14px;
    color: var(--muted);
}

.today-companion {
    margin-top: 10px;
    font-size: 13px;
    color: var(--char-accent);
    font-weight: 600;
}

.today-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    padding: 18px;
    box-shadow: var(--shadow-sm);
    text-align: left;
    font-family: inherit;
    color: var(--ink);
    font-size: 14px;
}

.today-card-loading {
    color: var(--muted);
}

.today-card-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--muted);
    margin-bottom: 10px;
}

.today-resume-card {
    cursor: pointer;
    display: block;
    width: 100%;
    transition: border-color 150ms ease, box-shadow 150ms ease;
}

.today-resume-card:hover {
    border-color: var(--char-accent);
    box-shadow: var(--shadow);
}

.today-resume-topic {
    font-size: 15px;
    line-height: 1.6;
    color: var(--ink);
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.today-resume-time {
    display: inline-block;
    margin-top: 8px;
    font-size: 12px;
    color: var(--muted);
}

.today-relation-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.today-relation-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 10px 4px;
    border-radius: var(--radius);
    background: var(--char-accent-light);
}

.today-relation-item strong {
    font-size: 17px;
    color: var(--ink);
}

.today-relation-item span {
    font-size: 12px;
    color: var(--muted);
}

.today-mood-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}

.today-mood-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 12px 4px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: transparent;
    cursor: pointer;
    font-family: inherit;
    transition: border-color 150ms ease, background 150ms ease, transform 150ms ease;
}

.today-mood-btn:hover {
    border-color: var(--char-accent);
}

.today-mood-btn.selected {
    border-color: var(--char-accent);
    background: var(--char-accent-light);
    transform: scale(1.03);
}

.today-mood-emoji {
    font-size: 24px;
    line-height: 1;
}

.today-mood-label {
    font-size: 12px;
    color: var(--ink-secondary);
}

.today-mood-feedback {
    margin-top: 10px;
    font-size: 12px;
    color: var(--muted);
}

.today-quick-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.today-quick-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 12px 4px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: transparent;
    cursor: pointer;
    font-family: inherit;
    transition: border-color 150ms ease, background 150ms ease;
}

.today-quick-btn:hover {
    border-color: var(--teal);
    background: var(--surface-hover);
}

.today-quick-icon {
    font-size: 22px;
    line-height: 1;
}

.today-quick-label {
    font-size: 12px;
    color: var(--ink-secondary);
}

/* ---------- 画像/记忆 子 Tab ---------- */
.memory-subtabs {
    display: flex;
    gap: 4px;
    padding: 10px 20px 0;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
}

.memory-subtab {
    padding: 8px 14px;
    border: none;
    border-bottom: 2px solid transparent;
    background: transparent;
    color: var(--muted);
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: color 150ms ease, border-color 150ms ease;
}

.memory-subtab:hover {
    color: var(--ink);
}

.memory-subtab.active {
    color: var(--teal-dark);
    font-weight: 600;
    border-bottom-color: var(--teal);
}

:root[data-theme="dark"] .memory-subtab.active {
    color: var(--teal-light);
}

/* ---------- 时间线 / 收藏 ---------- */
.memory-extra-content {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    max-width: 620px;
    width: 100%;
    margin: 0 auto;
}

.memory-loading {
    text-align: center;
    color: var(--muted);
    font-size: 13px;
    padding: 40px 0;
}

.memory-empty {
    text-align: center;
    padding: 56px 20px;
    color: var(--muted);
}

.memory-empty-icon {
    font-size: 40px;
    margin-bottom: 12px;
}

.memory-empty h3 {
    font-size: 16px;
    color: var(--ink);
    margin-bottom: 6px;
}

.memory-empty p {
    font-size: 13px;
}

.memory-section-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--ink);
    margin: 12px 0 8px;
}

.memory-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.memory-item {
    padding: 12px 14px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
}

.memory-item-title {
    font-size: 14px;
    color: var(--ink);
}

.memory-item-sub {
    font-size: 12px;
    color: var(--ink-secondary);
    margin-top: 2px;
}

.memory-item-meta {
    font-size: 11px;
    color: var(--muted);
    margin-top: 4px;
}

/* ---------- 设置区块 ---------- */
.settings-content {
    flex: 1;
    overflow-y: auto;
    padding: 20px 20px calc(20px + env(safe-area-inset-bottom, 0px));
    max-width: 620px;
    width: 100%;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.settings-section {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    padding: 18px;
}

.settings-section h3 {
    font-size: 15px;
    font-weight: 600;
    color: var(--ink);
    margin-bottom: 12px;
}

.settings-field {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid var(--line);
    font-size: 14px;
    color: var(--ink);
}

.settings-field:last-of-type {
    border-bottom: none;
}

.settings-switch {
    cursor: pointer;
}

.settings-field input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--teal);
    cursor: pointer;
}

.settings-field input[type="time"],
.settings-field input[type="text"],
.settings-field select {
    padding: 6px 10px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--input-bg);
    color: var(--ink);
    font-family: inherit;
    font-size: 14px;
}

.settings-field input[type="text"] {
    max-width: 200px;
}

.settings-time-inputs {
    display: flex;
    align-items: center;
    gap: 8px;
}

.settings-time-sep {
    color: var(--muted);
    font-size: 13px;
}

.settings-channel-options {
    display: flex;
    gap: 16px;
}

.settings-channel-options label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    color: var(--ink);
    cursor: pointer;
}

.settings-hint {
    margin: 10px 0 0;
    font-size: 12px;
    color: var(--teal-dark);
    background: var(--mist);
    padding: 8px 12px;
    border-radius: var(--radius-sm);
}

.settings-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 14px;
}

/* ---------- Safari / 移动端适配 ---------- */

/* 触控高亮与选区：非文本控件禁用系统高亮与长按选中，气泡文本保持可复制 */
button,
.nav-item,
.memory-subtab,
.today-mood-btn,
.today-quick-btn,
.voice-bubble,
.sidebar-toggle,
.btn,
.btn-icon {
    -webkit-tap-highlight-color: transparent;
}

.nav-item,
.memory-subtab,
.today-mood-btn,
.today-quick-btn,
.voice-bubble,
.btn-icon,
.sidebar-toggle {
    -webkit-user-select: none;
    user-select: none;
}

.message-bubble,
.story-message {
    -webkit-user-select: text;
    user-select: text;
}

@media (max-width: 768px) {
    /* 抽屉 sidebar 与面板 header 让出刘海/圆角安全区 */
    .sidebar {
        padding-top: env(safe-area-inset-top, 0px);
        padding-left: env(safe-area-inset-left, 0px);
    }

    .chat-header {
        padding-top: calc(12px + env(safe-area-inset-top, 0px));
        padding-left: calc(16px + env(safe-area-inset-left, 0px));
        padding-right: calc(16px + env(safe-area-inset-right, 0px));
    }

    .today-content,
    .memory-extra-content,
    .settings-content {
        padding-left: calc(16px + env(safe-area-inset-left, 0px));
        padding-right: calc(16px + env(safe-area-inset-right, 0px));
    }
}

@media (max-width: 480px) {
    /* 窄屏气泡放宽，减少无谓换行 */
    .message {
        max-width: 90%;
    }

    .message.ai {
        max-width: 90%;
    }

    .today-mood-row {
        gap: 6px;
    }

    .settings-field {
        flex-wrap: wrap;
    }
}

/* Billing: the close action remains visible on narrow/short displays. */
#billing-modal .billing-content {
    width: min(680px, calc(100vw - 32px));
    max-width: 680px;
    max-height: 85dvh;
    overflow-y: auto;
}
.billing-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.billing-header h3 { margin-bottom: 0; }
#billing-body p { margin: 10px 0; line-height: 1.65; }
#billing-body details { margin: 16px 0; }
#billing-body summary { cursor: pointer; font-weight: 600; }
#billing-error { color: #b42318; margin: 10px 0; }
.billing-header { position: sticky; top: -28px; z-index: 1; padding: 12px 0; background: var(--surface); }
