/* ========================================
   CSS 变量 - 默认主题（爆米花 - 暖黄色）
   ======================================== */
:root {
    --primary: #FFB347;
    --primary-dark: #E8972E;
    --primary-light: #FFD89B;
    --bg: #FFF8F0;
    --card: #FFFFFF;
    --bubble-cat: #FFE5C0;
    --bubble-user: #FFB347;
    --text: #4A3728;
    --text-light: #8B7355;
    --border: #FFE0B2;
    --shadow: rgba(255, 179, 71, 0.2);
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* 影子主题（黑猫 - 紫色） */
[data-theme="shadow"] {
    --primary: #8B5CF6;
    --primary-dark: #6D28D9;
    --primary-light: #C4B5FD;
    --bg: #F5F3FF;
    --card: #FFFFFF;
    --bubble-cat: #EDE9FE;
    --bubble-user: #8B5CF6;
    --text: #1E1B4B;
    --text-light: #6B7280;
    --border: #DDD6FE;
    --shadow: rgba(139, 92, 246, 0.25);
}

[data-theme="daji"] {
    --primary: #E11D48;
    --primary-dark: #BE123C;
    --primary-light: #FECDD3;
    --bg: #FFF1F2;
    --card: #FFFFFF;
    --bubble-cat: #FFE4E6;
    --bubble-user: #E11D48;
    --text: #4C0519;
    --text-light: #9F1239;
    --border: #FDA4AF;
    --shadow: rgba(225, 29, 72, 0.25);
}

[data-theme="inkshadow"] {
    --primary: #334155;
    --primary-dark: #1E293B;
    --primary-light: #CBD5E1;
    --bg: #F1F5F9;
    --card: #FFFFFF;
    --bubble-cat: #E2E8F0;
    --bubble-user: #334155;
    --text: #0F172A;
    --text-light: #475569;
    --border: #CBD5E1;
    --shadow: rgba(51, 65, 85, 0.25);
}

[data-theme="sunny"] {
    --primary: #F59E0B;
    --primary-dark: #D97706;
    --primary-light: #FDE68A;
    --bg: #FFFBEB;
    --card: #FFFFFF;
    --bubble-cat: #FEF3C7;
    --bubble-user: #F59E0B;
    --text: #78350F;
    --text-light: #92400E;
    --border: #FCD34D;
    --shadow: rgba(245, 158, 11, 0.25);
}

/* ========================================
   基础重置
   ======================================== */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Helvetica Neue', Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    position: fixed;
    inset: 0;
    transition: background 0.3s ease, color 0.3s ease;
}

.page {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.page.hidden {
    display: none;
}

/* ========================================
   认证页面 - 移动端全屏
   ======================================== */
#auth-page {
    background: linear-gradient(165deg, var(--bg) 0%, var(--primary-light) 100%);
    justify-content: center;
    align-items: center;
    padding: 40px 30px;
}

.auth-content {
    width: 100%;
    max-width: 360px;
    display: flex;
    flex-direction: column;
    align-items: center;
    animation: fadeSlideUp 0.5s ease;
}

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

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

.auth-hero-emoji {
    font-size: 72px;
    display: block;
    animation: heroFloat 3s ease-in-out infinite;
}

@keyframes heroFloat {
    0%, 100% { transform: translateY(0) scale(1); }
    50% { transform: translateY(-10px) scale(1.05); }
}

.auth-title {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 8px;
    background: linear-gradient(135deg, var(--primary-dark), var(--primary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.auth-desc {
    font-size: 14px;
    color: var(--text-light);
    text-align: center;
    margin-bottom: 32px;
    line-height: 1.5;
}

/* Tab 切换 */
.auth-tabs {
    display: flex;
    width: 100%;
    background: var(--card);
    border-radius: 14px;
    padding: 4px;
    margin-bottom: 24px;
    box-shadow: 0 2px 12px var(--shadow);
}

.auth-tab {
    flex: 1;
    padding: 12px;
    border: none;
    background: transparent;
    color: var(--text-light);
    font-size: 15px;
    font-weight: 600;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.25s ease;
}

.auth-tab.active {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 4px 12px var(--shadow);
}

/* 表单 */
.auth-form {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.input-group {
    position: relative;
    display: flex;
    align-items: center;
}

.input-icon {
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 18px;
    line-height: 1;
    pointer-events: none;
    z-index: 1;
}

.input-group input {
    width: 100%;
    padding: 16px 16px 16px 50px;
    border: 2px solid var(--border);
    border-radius: 14px;
    background: var(--card);
    color: var(--text);
    font-size: 16px;
    outline: none;
    transition: border-color 0.25s, box-shadow 0.25s;
}

.input-group input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px var(--shadow);
}

.input-group input::placeholder {
    color: var(--text-light);
}

/* 修复 iOS 输入框圆角问题 */
.input-group input {
    -webkit-appearance: none;
    border-radius: 14px;
}

/* 登录/注册按钮 */
.auth-btn {
    width: 100%;
    padding: 16px;
    margin-top: 6px;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: #fff;
    border: none;
    border-radius: 14px;
    font-size: 17px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 6px 20px var(--shadow);
    transition: transform 0.2s, box-shadow 0.2s, opacity 0.2s;
    min-height: 54px;
}

.auth-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px var(--shadow);
}

.auth-btn:active {
    transform: translateY(0) scale(0.98);
}

.auth-btn:disabled {
    opacity: 0.7;
    transform: none;
}

/* 错误提示 */
.auth-message {
    margin-top: 16px;
    font-size: 13px;
    min-height: 18px;
    color: #FF6B6B;
    text-align: center;
}

/* ========================================
   主界面布局
   ======================================== */
#main-page {
    background: var(--bg);
    overflow: hidden;
}

/* ========================================
   顶部导航栏
   ======================================== */
.top-nav {
    position: relative;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: calc(12px + var(--safe-top)) 16px 12px;
    background: var(--primary);
    color: #fff;
    box-shadow: 0 2px 16px var(--shadow);
    flex-shrink: 0;
    transition: background 0.3s ease;
}

.nav-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border: none;
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
    border-radius: 12px;
    font-size: 20px;
    cursor: pointer;
    transition: background 0.2s, transform 0.15s;
    min-width: 44px;
    min-height: 44px;
}

.nav-btn:active {
    background: rgba(255, 255, 255, 0.35);
    transform: scale(0.92);
}

.nav-pet {
    display: flex;
    align-items: center;
    gap: 10px;
}

.nav-pet-avatar {
    font-size: 32px;
    line-height: 1;
}

.nav-pet-name {
    font-size: 18px;
    font-weight: 600;
}

/* ========================================
   左侧抽屉菜单
   ======================================== */
.drawer-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 200;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.drawer-overlay.open {
    opacity: 1;
    pointer-events: auto;
}

.drawer {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 280px;
    max-width: 80vw;
    background: var(--card);
    z-index: 201;
    display: flex;
    flex-direction: column;
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.15);
}

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

.drawer-header {
    padding: calc(30px + var(--safe-top)) 20px 20px;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: #fff;
}

.drawer-user {
    display: flex;
    align-items: center;
    gap: 12px;
}

.drawer-user-avatar {
    font-size: 44px;
}

.drawer-user-info {
    display: flex;
    flex-direction: column;
}

.drawer-user-name {
    font-size: 18px;
    font-weight: 600;
}

.drawer-user-label {
    font-size: 12px;
    opacity: 0.85;
}

.drawer-section {
    flex: 1;
    padding: 20px 16px;
    overflow-y: auto;
}

.drawer-section-title {
    font-size: 12px;
    color: var(--text-light);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 12px;
    padding-left: 8px;
}

.pet-item {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 14px 16px;
    border: none;
    background: var(--bg);
    border-radius: 14px;
    cursor: pointer;
    margin-bottom: 8px;
    transition: all 0.2s ease;
    text-align: left;
}

.pet-item:active {
    transform: scale(0.95);
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
}

@keyframes iconWiggle {
    0% { transform: rotate(0deg) scale(1); }
    25% { transform: rotate(-15deg) scale(1.1); }
    50% { transform: rotate(15deg) scale(1.1); }
    75% { transform: rotate(-10deg) scale(1.05); }
    100% { transform: rotate(0deg) scale(1); }
}

.pet-item.active .pet-icon {
    animation: iconWiggle 0.5s ease;
}

.pet-item.active {
    background: var(--primary);
}

.pet-item.active .pet-name,
.pet-item.active .pet-desc,
.pet-item.active .pet-check {
    color: #fff;
}

.pet-icon {
    font-size: 30px;
    flex-shrink: 0;
}

.pet-info {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.pet-name {
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
}

.pet-desc {
    font-size: 13px;
    color: var(--text-light);
}

.pet-check {
    font-size: 16px;
    color: var(--text-light);
    font-weight: bold;
    opacity: 0;
    transition: opacity 0.2s;
}

.pet-item.active .pet-check {
    opacity: 1;
}

.drawer-footer {
    padding: 16px;
    border-top: 1px solid var(--border);
}

.logout-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 14px;
    border: 2px solid #FF6B6B;
    background: transparent;
    color: #FF6B6B;
    border-radius: 12px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    min-height: 48px;
}

.logout-btn:active {
    background: #FF6B6B;
    color: #fff;
}

/* ========================================
   聊天区域
   ======================================== */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding-bottom: calc(70px + var(--safe-bottom));
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    background-image:
        radial-gradient(var(--bubble-cat) 1.5px, transparent 1.5px);
    background-size: 20px 20px;
    transition: background-image 0.3s;
}

/* 滚动条 */
.chat-messages::-webkit-scrollbar {
    width: 4px;
}
.chat-messages::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

/* ========================================
   消息气泡
   ======================================== */
.message {
    margin-bottom: 14px;
    display: flex;
    flex-direction: column;
    animation: msgIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes msgIn {
    0% { opacity: 0; transform: translateY(20px) scale(0.6); }
    60% { opacity: 1; transform: translateY(-4px) scale(1.05); }
    80% { transform: translateY(2px) scale(0.98); }
    100% { opacity: 1; transform: translateY(0) scale(1); }
}

.bubble {
    max-width: 82%;
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 16px;
    line-height: 1.5;
    word-break: break-word;
}

.cat-msg .bubble {
    align-self: flex-start;
    background: var(--bubble-cat);
    color: var(--text);
    border-bottom-left-radius: 4px;
}

.user-msg {
    align-items: flex-end;
}

.user-msg .bubble {
    align-self: flex-end;
    background: var(--bubble-user);
    color: #fff;
    border-bottom-right-radius: 4px;
}

/* ========================================
   统一的自定义语音播放器 UI
   ======================================== */
.custom-audio-player {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: rgba(255, 255, 255, 0.4);
    border-radius: 20px;
    cursor: pointer;
    margin-top: 10px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.05);
    transition: all 0.2s;
    width: fit-content;
    user-select: none;
}

/* 用户的语音胶囊排版优化（微信风格：向右对齐） */
.user-msg .custom-audio-player {
    background: rgba(255, 255, 255, 0.25);
    margin-top: 0;
    margin-bottom: 10px;
    flex-direction: row-reverse;
}

.custom-audio-player:active {
    transform: scale(0.95);
    background: rgba(255, 255, 255, 0.6);
}

.play-icon {
    font-size: 14px;
}

.duration {
    font-size: 13px;
    opacity: 0.85;
}

/* 动态波纹动画 */
.wave-animation {
    display: flex;
    align-items: center;
    gap: 3px;
    height: 14px;
}

.wave-bar {
    width: 3px;
    background-color: currentColor;
    border-radius: 2px;
    height: 4px;
    transition: height 0.2s;
}

.playing .wave-bar {
    animation: waveAction 0.8s infinite alternate ease-in-out;
}

.playing .wave-bar:nth-child(1) { animation-delay: 0s; }
.playing .wave-bar:nth-child(2) { animation-delay: 0.2s; }
.playing .wave-bar:nth-child(3) { animation-delay: 0.4s; }

@keyframes waveAction {
    0%   { height: 4px; }
    100% { height: 14px; }
}

/* 彻底隐藏原生 audio */
.voice-bubble audio {
    display: none !important;
}

/* 语音转文字的优美虚线分割线 */
.voice-transcript {
    font-size: 15px;
    padding-top: 10px;
    border-top: 1px dashed rgba(255,255,255,0.4);
    line-height: 1.5;
}

/* 加载动画 */
.loading {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 0;
    font-size: 14px;
    color: var(--text-light);
    font-style: italic;
}

.loading-dots {
    display: flex;
    gap: 4px;
}

.loading-dots span {
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-light);
    animation: dotBounce 1.4s ease-in-out infinite;
}

.loading-dots span:nth-child(1) { animation-delay: 0s; }
.loading-dots span:nth-child(2) { animation-delay: 0.2s; }
.loading-dots span:nth-child(3) { animation-delay: 0.4s; }

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

/* ========================================
   底部输入栏（固定）
   ======================================== */
.input-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 40;
    background: var(--card);
    border-top: 1px solid var(--border);
    padding: 10px 14px calc(10px + var(--safe-bottom));
    transition: background 0.3s, border-color 0.3s;
}

.input-wrapper {
    display: flex;
    align-items: center;
    gap: 10px;
}

#user-input {
    flex: 1;
    padding: 14px 18px;
    border: 2px solid var(--border);
    border-radius: 24px;
    background: var(--bg);
    color: var(--text);
    font-size: 16px;
    outline: none;
    transition: border-color 0.25s, box-shadow 0.25s;
    min-height: 48px;
}

#user-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--shadow);
}

#user-input::placeholder {
    color: var(--text-light);
}

/* iOS 输入框样式修复 */
#user-input {
    -webkit-appearance: none;
    border-radius: 24px;
}

.send-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    border: none;
    background: var(--primary);
    color: #fff;
    border-radius: 50%;
    cursor: pointer;
    flex-shrink: 0;
    transition: all 0.2s;
    box-shadow: 0 4px 12px var(--shadow);
}

.send-btn:active {
    transform: scale(0.88);
    box-shadow: none;
}

/* ========================================
   录音按钮
   ======================================== */
.record-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    border: 2px solid var(--border);
    background: transparent;
    color: var(--text-light);
    border-radius: 50%;
    cursor: pointer;
    flex-shrink: 0;
    font-size: 20px;
    transition: all 0.2s;
}

.record-btn:active {
    transform: scale(0.88);
}

.record-btn.recording {
    background: #ef4444;
    border-color: #ef4444;
    color: #fff;
    animation: pulse 1.2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.5); }
    50%       { box-shadow: 0 0 0 10px rgba(239, 68, 68, 0); }
}

/* ========================================
   Toast 提示
   ======================================== */
.toast {
    position: fixed;
    bottom: 90px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: rgba(30, 30, 30, 0.9);
    color: #fff;
    padding: 12px 20px;
    border-radius: 24px;
    font-size: 14px;
    z-index: 9999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease, transform 0.3s ease;
    white-space: nowrap;
    backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    gap: 10px;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.toast-icon {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: bold;
    flex-shrink: 0;
}

.toast-success .toast-icon { background: #22c55e; }
.toast-success { border: 1px solid rgba(34, 197, 94, 0.3); }

.toast-warning .toast-icon { background: #f59e0b; }
.toast-warning { border: 1px solid rgba(245, 158, 11, 0.3); }

.toast-error .toast-icon { background: #ef4444; }
.toast-error { border: 1px solid rgba(239, 68, 68, 0.3); }

.toast-info .toast-icon { background: #3b82f6; }
.toast-info { border: 1px solid rgba(59, 130, 246, 0.3); }

/* ========================================
   响应式 - 大屏幕（横屏或平板）
   ======================================== */
@media (min-width: 600px) {
    .top-nav {
        padding: 16px 24px;
    }

    .chat-messages {
        padding: 20px 40px;
    }

    .input-bar {
        padding: 14px 40px calc(14px + var(--safe-bottom));
    }

    .bubble {
        max-width: 65%;
    }
}

@media (min-width: 900px) {
    .top-nav {
        max-width: 500px;
        left: 50%;
        transform: translateX(-50%);
        border-radius: 0 0 20px 20px;
    }

    .chat-area {
        max-width: 500px;
        margin: 0 auto;
        border-left: 1px solid var(--border);
        border-right: 1px solid var(--border);
    }

    .input-bar {
        max-width: 500px;
        left: 50%;
        transform: translateX(-50%);
    }
}
