/* ============================================================
   念念不忘 - 前端样式
   设计理念：温暖的咖啡馆 · 安全的倾诉空间
   ============================================================ */

:root {
    --bg: #faf7f2;
    --bg-gradient: linear-gradient(180deg, #faf7f2 0%, #f3ede3 100%);
    --surface: #ffffff;
    --surface-glass: rgba(255, 255, 255, 0.72);
    --text: #3d2e1f;
    --text-secondary: #8b7d6b;
    --text-light: #b0a595;
    --accent: #d4a574;
    --accent-light: #e8b88a;
    --accent-dark: #c9956a;
    --accent-gradient: linear-gradient(135deg, #e8a87c 0%, #d4a574 100%);
    --user-bubble: linear-gradient(135deg, #e8a87c 0%, #d4a574 100%);
    --user-text: #ffffff;
    --ai-bubble: #ffffff;
    --shadow-sm: 0 2px 8px rgba(61, 46, 31, 0.06);
    --shadow-md: 0 4px 16px rgba(61, 46, 31, 0.08);
    --shadow-lg: 0 8px 32px rgba(61, 46, 31, 0.12);
    --radius: 20px;
    --radius-sm: 12px;
    --radius-xs: 8px;
    --header-h: 64px;
    --input-h: 72px;
    --max-w: 640px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Helvetica Neue", sans-serif;
    background: var(--bg-gradient);
    color: var(--text);
    font-size: 16px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

/* ============================================================
   Screen 切换
   ============================================================ */

.screen {
    display: none;
    height: 100%;
    width: 100%;
}

.screen.active {
    display: flex;
    animation: fadeIn 0.4s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

/* ============================================================
   欢迎页
   ============================================================ */

#welcome-screen {
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.welcome-card {
    width: 100%;
    max-width: 380px;
    background: var(--surface-glass);
    backdrop-filter: blur(30px) saturate(180%);
    -webkit-backdrop-filter: blur(30px) saturate(180%);
    border: 1px solid rgba(255, 255, 255, 0.6);
    border-radius: var(--radius);
    padding: 48px 32px 40px;
    text-align: center;
    box-shadow: var(--shadow-lg);
    animation: slideUp 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

.welcome-logo {
    font-size: 32px;
    font-weight: 700;
    letter-spacing: 6px;
    color: var(--text);
    margin-bottom: 8px;
}

.welcome-subtitle {
    font-size: 14px;
    color: var(--text-secondary);
    letter-spacing: 2px;
    margin-bottom: 36px;
}

.welcome-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.name-input {
    width: 100%;
    padding: 14px 16px;
    border: none;
    border-bottom: 2px solid var(--text-light);
    border-radius: 0;
    background: transparent;
    font-size: 16px;
    color: var(--text);
    text-align: center;
    outline: none;
    transition: border-color 0.3s;
}

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

.name-input:focus {
    border-bottom-color: var(--accent);
}

.start-btn {
    width: 100%;
    padding: 14px;
    border: none;
    border-radius: var(--radius-sm);
    background: var(--accent-gradient);
    color: var(--user-text);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    box-shadow: 0 4px 12px rgba(212, 165, 116, 0.3);
}

.start-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(212, 165, 116, 0.4);
}

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

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

.welcome-hint {
    margin-top: 24px;
    font-size: 12px;
    color: var(--text-light);
}

.admin-link {
    display: inline-block;
    margin-top: 16px;
    font-size: 13px;
    color: var(--text-light);
    text-decoration: none;
    transition: color 0.2s;
}

.admin-link:hover {
    color: var(--accent-dark);
}

/* ============================================================
   对话页 - Header
   ============================================================ */

#chat-screen {
    flex-direction: column;
}

.chat-header {
    height: var(--header-h);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    background: var(--surface-glass);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid rgba(61, 46, 31, 0.06);
    flex-shrink: 0;
    z-index: 10;
}

/* 采访进度条 */
.progress-wrap {
    display: none;
    padding: 8px 16px 10px;
    background: var(--surface-glass);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid rgba(61, 46, 31, 0.06);
    flex-shrink: 0;
}

.progress-info {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
}

.progress-label {
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 500;
}

.progress-percent {
    font-size: 13px;
    color: var(--accent);
    font-weight: 600;
}

.progress-track {
    height: 8px;
    border-radius: 4px;
    background: rgba(61, 46, 31, 0.1);
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    border-radius: 4px;
    background: var(--accent-gradient);
    width: 0%;
    transition: width 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--accent-gradient);
    color: var(--user-text);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: 600;
    box-shadow: var(--shadow-sm);
}

.header-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

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

.header-status {
    font-size: 12px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 4px;
}

.status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #4ade80;
    box-shadow: 0 0 6px rgba(74, 222, 128, 0.5);
    transition: background 0.3s, box-shadow 0.3s;
}

/* 录音中 - 红色闪烁 */
.status-dot.recording {
    background: #ff4757;
    box-shadow: 0 0 8px rgba(255, 71, 87, 0.6);
    animation: dotPulse 0.8s infinite;
}

/* AI 收听中 - 橙色 */
.status-dot.listening {
    background: #ffa502;
    box-shadow: 0 0 8px rgba(255, 165, 2, 0.6);
}

/* 在线 - 绿色 */
.status-dot.online {
    background: #4ade80;
    box-shadow: 0 0 6px rgba(74, 222, 128, 0.5);
    animation: none;
}

@keyframes dotPulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.5); opacity: 0.5; }
}

.end-btn {
    padding: 6px 16px;
    border: 1px solid var(--text-light);
    border-radius: 20px;
    background: transparent;
    color: var(--text-secondary);
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
}

.end-btn:hover {
    border-color: #e8a87c;
    color: #e8a87c;
}

/* ============================================================
   对话页 - Messages
   ============================================================ */

.messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 16px 12px;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

.messages::-webkit-scrollbar {
    width: 4px;
}

.messages::-webkit-scrollbar-thumb {
    background: var(--text-light);
    border-radius: 2px;
}

.messages::-webkit-scrollbar-track {
    background: transparent;
}

.msg-row {
    display: flex;
    margin-bottom: 16px;
    max-width: var(--max-w);
    animation: slideUp 0.3s ease;
}

.msg-row.user {
    margin-left: auto;
    flex-direction: row-reverse;
}

.msg-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
}

.msg-row.ai .msg-avatar {
    background: var(--accent-gradient);
    color: var(--user-text);
    margin-right: 8px;
}

.msg-row.user .msg-avatar {
    background: var(--surface);
    color: var(--text-secondary);
    border: 2px solid var(--text-light);
    margin-left: 8px;
}

.msg-bubble {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: 15px;
    line-height: 1.6;
    word-break: break-word;
    position: relative;
    max-width: calc(100% - 52px);
}

.msg-row.ai .msg-bubble {
    background: var(--ai-bubble);
    color: var(--text);
    border-top-left-radius: 4px;
    box-shadow: var(--shadow-sm);
}

.msg-row.user .msg-bubble {
    background: var(--user-bubble);
    color: var(--user-text);
    border-top-right-radius: 4px;
    box-shadow: 0 2px 8px rgba(232, 168, 124, 0.2);
}

/* 正在输入指示器 */
.typing-row {
    display: flex;
    margin-bottom: 16px;
    animation: slideUp 0.3s ease;
}

.typing-bubble {
    background: var(--ai-bubble);
    padding: 16px 20px;
    border-radius: var(--radius-sm);
    border-top-left-radius: 4px;
    box-shadow: var(--shadow-sm);
    margin-left: 44px;
    display: flex;
    gap: 5px;
}

.typing-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--text-light);
    animation: typingBounce 1.2s infinite;
}

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

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

/* 音频播放指示器 */
.audio-bars {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    margin-left: 6px;
    vertical-align: middle;
    height: 14px;
}

.audio-bar {
    width: 3px;
    border-radius: 2px;
    background: var(--accent);
    animation: audioWave 0.8s infinite ease-in-out;
}

.audio-bar:nth-child(1) { height: 6px; animation-delay: 0s; }
.audio-bar:nth-child(2) { height: 12px; animation-delay: 0.15s; }
.audio-bar:nth-child(3) { height: 8px; animation-delay: 0.3s; }
.audio-bar:nth-child(4) { height: 10px; animation-delay: 0.45s; }

@keyframes audioWave {
    0%, 100% { transform: scaleY(0.4); }
    50% { transform: scaleY(1); }
}

.audio-bars.idle .audio-bar {
    animation: none;
    transform: scaleY(0.4);
}

/* ============================================================
   对话页 - Input Area
   ============================================================ */

.input-area {
    height: var(--input-h);
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 12px 12px;
    background: var(--surface-glass);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid rgba(61, 46, 31, 0.06);
    flex-shrink: 0;
}

/* 麦克风按钮 — 输入框左侧，金色圆形，醒目 */
.mic-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 2px solid var(--accent);
    background: var(--accent-gradient);
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 3px 10px rgba(212, 165, 116, 0.35);
    transition: all 0.2s;
    flex-shrink: 0;
}

.mic-btn:hover {
    transform: scale(1.08);
    box-shadow: 0 4px 16px rgba(212, 165, 116, 0.5);
}

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

.mic-btn.recording {
    background: #ff4757;
    border-color: #ff4757;
    color: #ffffff;
    animation: micPulse 1.2s infinite;
}

@keyframes micPulse {
    0% { box-shadow: 0 0 0 0 rgba(255, 71, 87, 0.4); }
    50% { box-shadow: 0 0 0 12px rgba(255, 71, 87, 0); }
    100% { box-shadow: 0 0 0 0 rgba(255, 71, 87, 0); }
}

.mic-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

/* 句子计数角标 — 麦克风按钮上 */
.mic-btn-wrapper {
    position: relative;
    flex-shrink: 0;
}

.pending-count {
    position: absolute;
    top: -6px;
    right: -6px;
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    border-radius: 10px;
    background: #ff6b6b;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    line-height: 20px;
    text-align: center;
    box-shadow: 0 2px 6px rgba(255, 107, 107, 0.4);
    display: none;
}

.pending-count.visible {
    display: block;
}

.text-input {
    flex: 1;
    height: 44px;
    padding: 0 16px;
    border: 1px solid rgba(61, 46, 31, 0.1);
    border-radius: 22px;
    background: var(--surface);
    font-size: 15px;
    color: var(--text);
    outline: none;
    transition: border-color 0.2s;
}

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

.text-input:focus {
    border-color: var(--accent);
}

.text-input:disabled {
    opacity: 0.5;
}

.send-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: var(--accent-gradient);
    color: var(--user-text);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 3px 10px rgba(212, 165, 116, 0.3);
    transition: transform 0.15s;
    flex-shrink: 0;
}

.send-btn:hover {
    transform: scale(1.05);
}

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

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

/* ============================================================
   结束页
   ============================================================ */

#end-screen {
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.end-card {
    text-align: center;
    animation: slideUp 0.5s ease;
}

.end-icon {
    color: var(--accent);
    margin-bottom: 20px;
}

.end-text {
    font-size: 22px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 8px;
}

.end-subtext {
    font-size: 15px;
    color: var(--text-secondary);
    margin-bottom: 32px;
}

.restart-btn {
    padding: 12px 36px;
    border: none;
    border-radius: var(--radius-sm);
    background: var(--accent-gradient);
    color: var(--user-text);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(212, 165, 116, 0.3);
    transition: transform 0.2s;
}

.restart-btn:hover {
    transform: translateY(-1px);
}

/* ============================================================
   Toast
   ============================================================ */

.toast {
    position: fixed;
    bottom: 90px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: rgba(61, 46, 31, 0.9);
    color: #ffffff;
    padding: 10px 20px;
    border-radius: 24px;
    font-size: 14px;
    opacity: 0;
    pointer-events: none;
    transition: all 0.3s;
    z-index: 100;
    white-space: nowrap;
}

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

/* ============================================================
   响应式
   ============================================================ */

@media (max-width: 480px) {
    .welcome-logo {
        font-size: 28px;
    }
    .msg-bubble {
        font-size: 14px;
    }
    .header-name {
        font-size: 15px;
    }
}
