/**
 * AI 树洞 — 前端样式
 */

/* ===== 主题变量 ===== */
.ai-tree-hole-container {
    --bg-start: #0f0c29;
    --bg-mid: #302b63;
    --bg-end: #24243e;
    --bg-color: #1a1a2e;
    --card-bg: rgba(255, 255, 255, 0.05);
    --card-border: rgba(255, 255, 255, 0.08);
    --accent: #e94560;
    --accent-dark: #c23152;
    --accent-glow: rgba(233, 69, 96, 0.4);
    --text-primary: #e0e0e0;
    --text-secondary: #a0a0b8;
    --text-dim: #707080;
}

/* 雨夜 */
.ai-tree-hole-container[data-theme="rainy"] {
    --bg-start: #1a1a1a;
    --bg-mid: #2d3436;
    --bg-end: #2d3436;
    --bg-color: #1a1a1a;
    --accent: #74b9ff;
    --accent-dark: #0984e3;
    --accent-glow: rgba(116, 185, 255, 0.4);
}

/* 森林 */
.ai-tree-hole-container[data-theme="forest"] {
    --bg-start: #0a2a1a;
    --bg-mid: #1b3a2a;
    --bg-end: #1b3a2a;
    --bg-color: #0a2a1a;
    --accent: #55efc4;
    --accent-dark: #00b894;
    --accent-glow: rgba(85, 239, 196, 0.4);
}

.ai-tree-hole-container {
    max-width: 640px;
    margin: 40px auto;
    padding: 40px 24px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: linear-gradient(160deg, var(--bg-start), var(--bg-mid), var(--bg-end));
    color: var(--text-primary);
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    position: relative;
    min-height: 400px;
    transition: background 0.6s ease;
}

/* ===== 右上角控制栏 ===== */
.th-controls {
    position: absolute;
    top: 16px;
    right: 16px;
    display: flex;
    gap: 8px;
}

.th-ctrl-btn {
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.th-ctrl-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    color: var(--text-primary);
}

#th-theme-btn::before { content: '\1F32C'; }
#th-history-btn::before { content: '\1F552'; }

/* ===== 会话信息 ===== */
.th-session-info {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    margin-bottom: 16px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 8px;
    font-size: 13px;
    color: var(--text-secondary);
}

.th-new-session-btn {
    background: none;
    border: 1px solid var(--card-border);
    color: var(--text-secondary);
    padding: 4px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    transition: border-color 0.2s, color 0.2s;
}

.th-new-session-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.ai-tree-hole-header {
    text-align: center;
    margin-bottom: 40px;
}

.ai-tree-hole-header h2 {
    font-size: 28px;
    color: var(--accent);
    margin: 0 0 8px;
}

.ai-tree-hole-header p {
    font-size: 15px;
    color: var(--text-secondary);
    margin: 0;
}

/* 录音按钮 */
.ai-tree-hole-recorder {
    text-align: center;
    margin-bottom: 32px;
}

.th-record-btn {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 140px;
    height: 140px;
    border: none;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), var(--accent-dark));
    color: #fff;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    box-shadow: 0 4px 20px var(--accent-glow);
}

.th-record-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 28px var(--accent-glow);
}

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

.th-record-btn.processing {
    opacity: 0.5;
    cursor: not-allowed;
}

.th-btn-icon {
    font-size: 40px;
    line-height: 1;
}

.th-btn-text {
    font-size: 14px;
    margin-top: 8px;
    font-weight: 500;
}

/* 录音中动画 */
.th-record-btn.recording {
    animation: th-pulse 1.5s ease-in-out infinite;
    background: linear-gradient(135deg, var(--accent-dark), #8b1a30);
}

@keyframes th-pulse {
    0%, 100% { box-shadow: 0 0 0 0 var(--accent-glow); }
    50% { box-shadow: 0 0 0 16px rgba(233, 69, 96, 0); }
}

/* 投递动画 */
.th-record-btn.th-thrown {
    animation: th-throw 0.6s ease-in forwards;
}

@keyframes th-throw {
    0%   { transform: scale(1); opacity: 1; }
    60%  { transform: scale(1.15); opacity: 0.8; }
    100% { transform: scale(0.3) translateY(40px); opacity: 0; }
}

.th-timer {
    margin-top: 16px;
    font-size: 24px;
    font-weight: 600;
    color: var(--accent);
    font-variant-numeric: tabular-nums;
}

.th-status {
    margin-top: 12px;
    font-size: 14px;
    color: var(--text-secondary);
    min-height: 20px;
}

.th-status.th-processing {
    color: #e2a721;
}

.th-status.th-success {
    color: #4caf50;
}

.th-status.th-error {
    color: #f44336;
}

/* 对话流容器 */
.th-conversation {
    margin-bottom: 32px;
}

.th-dialog-turn {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 16px;
    border: 1px solid var(--card-border);
}

.th-dialog-turn .th-turn-label {
    font-size: 12px;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

.th-dialog-turn .th-turn-content {
    font-size: 15px;
    line-height: 1.7;
    color: var(--text-primary);
    white-space: pre-wrap;
}

.th-dialog-turn .th-turn-reply .th-turn-content {
    color: var(--accent);
}

/* 打字机光标 */
.th-typing-cursor::after {
    content: '|';
    animation: th-blink 0.7s step-end infinite;
}

@keyframes th-blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

/* 淡入动画 */
.th-fade-in {
    animation: th-fadeIn 0.6s ease-out;
}

@keyframes th-fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* 错误提示 */
.th-error {
    text-align: center;
    padding: 12px 16px;
    background: rgba(244, 67, 54, 0.1);
    border-radius: 8px;
    color: #f44336;
    font-size: 14px;
    margin-bottom: 16px;
}

/* 免责声明 */
.ai-tree-hole-disclaimer {
    text-align: center;
    padding: 16px;
    border-top: 1px solid var(--card-border);
    font-size: 12px;
    color: var(--text-dim);
    line-height: 1.6;
}

.ai-tree-hole-disclaimer strong {
    color: var(--text-secondary);
}

/* ===== 侧滑历史面板 ===== */
.th-history-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 9998;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.th-history-overlay.th-visible {
    opacity: 1;
    pointer-events: auto;
}

.th-history-panel {
    position: fixed;
    top: 0;
    right: -420px;
    width: 400px;
    max-width: 90vw;
    height: 100vh;
    background: var(--bg-color);
    color: var(--text-primary);
    z-index: 9999;
    box-shadow: -4px 0 24px rgba(0, 0, 0, 0.4);
    transition: right 0.3s ease;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.th-history-panel.th-visible {
    right: 0;
}

.th-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px;
    border-bottom: 1px solid var(--card-border);
}

.th-panel-header h3 {
    margin: 0;
    font-size: 18px;
    color: var(--accent);
}

.th-panel-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 28px;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}

.th-panel-close:hover {
    color: var(--text-primary);
}

.th-history-stats {
    padding: 16px 20px;
    font-size: 14px;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--card-border);
    text-align: center;
}

.th-history-list {
    padding: 16px 20px;
    flex: 1;
}

.th-history-item {
    padding: 12px 0;
    border-bottom: 1px solid var(--card-border);
    cursor: pointer;
}

.th-history-item:last-child {
    border-bottom: none;
}

.th-history-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.th-history-item-date {
    font-size: 12px;
    color: var(--text-dim);
}

.th-history-item-emotion {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 10px;
    background: rgba(233, 69, 96, 0.15);
    color: var(--accent);
}

.th-history-item-preview {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.5;
}

.th-history-item-full {
    display: none;
    margin-top: 8px;
    font-size: 14px;
    color: var(--text-primary);
    line-height: 1.7;
    white-space: pre-wrap;
    padding-top: 8px;
    border-top: 1px dashed var(--card-border);
}

.th-history-item.th-expanded .th-history-item-full {
    display: block;
}

.th-history-empty {
    text-align: center;
    color: var(--text-dim);
    padding: 40px 0;
}

/* 加载状态 */
.th-loading {
    text-align: center;
    color: var(--text-secondary);
    font-size: 14px;
}

.th-loading::after {
    content: '';
    display: inline-block;
    animation: th-dots 1.5s steps(4, end) infinite;
}

@keyframes th-dots {
    0%   { content: ''; }
    25%  { content: '.'; }
    50%  { content: '..'; }
    75%  { content: '...'; }
}

/* HTTPS 提示 */
.ai-tree-hole-https-hint {
    text-align: center;
    padding: 16px 20px;
    margin-bottom: 32px;
    background: rgba(226, 167, 33, 0.08);
    border: 1px solid rgba(226, 167, 33, 0.3);
    border-radius: 12px;
    font-size: 13px;
    line-height: 1.7;
    color: #e2a721;
}

.th-hint-icon {
    font-size: 28px;
    margin-bottom: 8px;
}

.ai-tree-hole-https-hint code {
    background: rgba(0, 0, 0, 0.25);
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 12px;
    color: #f0f0f0;
}

/* 星空粒子（纯CSS） */
.ai-tree-hole-container[data-theme="starlight"]::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    pointer-events: none;
    border-radius: 16px;
    background-image:
        radial-gradient(1px 1px at 10% 20%, rgba(255,255,255,0.4) 50%, transparent 51%),
        radial-gradient(1px 1px at 30% 60%, rgba(255,255,255,0.3) 50%, transparent 51%),
        radial-gradient(1px 1px at 55% 15%, rgba(255,255,255,0.5) 50%, transparent 51%),
        radial-gradient(1px 1px at 70% 45%, rgba(255,255,255,0.2) 50%, transparent 51%),
        radial-gradient(1.5px 1.5px at 85% 75%, rgba(255,255,255,0.35) 50%, transparent 51%),
        radial-gradient(1px 1px at 45% 85%, rgba(255,255,255,0.3) 50%, transparent 51%),
        radial-gradient(1px 1px at 20% 40%, rgba(255,255,255,0.25) 50%, transparent 51%),
        radial-gradient(1.5px 1.5px at 65% 70%, rgba(255,255,255,0.4) 50%, transparent 51%);
    animation: th-twinkle 4s ease-in-out infinite alternate;
}

@keyframes th-twinkle {
    0%   { opacity: 0.5; }
    100% { opacity: 1; }
}

/* 雨滴 */
.ai-tree-hole-container[data-theme="rainy"]::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    pointer-events: none;
    border-radius: 16px;
    background:
        linear-gradient(to bottom, transparent 0%, rgba(116, 185, 255, 0.03) 100%);
    overflow: hidden;
}

/* 森林光斑 */
.ai-tree-hole-container[data-theme="forest"]::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    pointer-events: none;
    border-radius: 16px;
    background:
        radial-gradient(ellipse at 20% 30%, rgba(85, 239, 196, 0.05) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 70%, rgba(0, 184, 148, 0.05) 0%, transparent 50%);
    animation: th-forest-glow 6s ease-in-out infinite alternate;
}

@keyframes th-forest-glow {
    0%   { opacity: 0.5; }
    100% { opacity: 1; }
}
