* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
    --bg-dark: #2a1f1a; --bg-medium: #3d2e26; --bg-light: #4a3830;
    --gold: #c9a227; --gold-light: #e8d5a3; --rose-gold: #d4a574;
    --pink: #e8a0a0; --pink-bright: #ff6b9d;
    --text-gold: #d4b896; --text-light: #f5e6d3;
}
body {
    font-family: 'Noto Serif TC', serif;
    background: linear-gradient(145deg, #1a1210 0%, #2a1f1a 50%, #1a1210 100%);
    min-height: 100vh; display: flex; justify-content: center; align-items: center;
    padding: 0; overflow: hidden;
}
.app-container {
    width: 100%; max-width: 100vw; height: 100vh;
    background: linear-gradient(180deg, #3d2e26 0%, #2a1f1a 100%);
    border-radius: 0; border: none;
    box-shadow: 0 20px 60px rgba(0,0,0,0.6), inset 0 1px 0 rgba(255,255,255,0.1);
    display: flex; flex-direction: column; position: relative; overflow: hidden;
}
.header { padding: 18px 28px; display: flex; justify-content: space-between; align-items: center; }
.logo {
    font-family: 'Cinzel Decorative', cursive; font-size: 2rem; font-weight: 700;
    color: var(--gold-light);
    text-shadow: 0 2px 4px rgba(0,0,0,0.5), 0 0 30px rgba(212,165,116,0.3);
}
.toolbar {
    position: absolute; right: 18px; top: 75px;
    display: flex; flex-direction: column; gap: 7px; z-index: 10;
}
.tool-btn {
    width: 40px; height: 40px;
    background: linear-gradient(145deg, #4a3830, #3d2e26);
    border: 2px solid #6a5a4a; border-radius: 9px;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; opacity: 0.7; transition: all 0.3s ease;
    box-shadow: 0 4px 12px rgba(0,0,0,0.4); position: relative;
}
.tool-btn:hover { transform: translateY(-2px); opacity: 1; }
.tool-btn:hover .tooltip { opacity: 1; transform: translateX(-10px); }
.tool-btn.active { opacity: 1; border-color: var(--gold); }
.tool-btn svg { width: 18px; height: 18px; fill: var(--rose-gold); }
.tool-btn .emoji { font-size: 18px; }
.tooltip {
    position: absolute; right: 50px; background: var(--bg-medium);
    color: var(--text-gold); padding: 5px 9px; border-radius: 5px;
    font-size: 0.7rem; white-space: nowrap; opacity: 0;
    transition: all 0.3s ease; pointer-events: none; border: 1px solid #5a4a3a;
}
.dropdown-menu {
    position: absolute; right: 50px; top: 0;
    background: var(--bg-medium); border: 1px solid #5a4a3a;
    border-radius: 8px; overflow: hidden; display: none;
    box-shadow: 0 4px 16px rgba(0,0,0,0.4); min-width: 160px;
}
.dropdown-menu.show { display: block; }
.dropdown-item {
    padding: 8px 12px; color: var(--text-gold); cursor: pointer;
    font-size: 0.75rem; transition: background 0.2s; border-bottom: 1px solid #4a3a30;
}
.dropdown-item:last-child { border-bottom: none; }
.dropdown-item:hover { background: var(--bg-light); }
.dropdown-item.active { background: var(--gold); color: var(--bg-dark); }

.name-input-popup { padding: 10px; min-width: 160px; }
.name-input-popup label { display: block; color: var(--text-gold); font-size: 0.7rem; margin-bottom: 5px; }
.name-input-popup input {
    width: 100%; padding: 7px 9px; border: 1px solid #5a4a3a;
    background: var(--bg-dark); color: var(--text-light);
    border-radius: 5px; font-size: 0.8rem; margin-bottom: 7px;
}
.name-input-popup button {
    width: 100%; padding: 7px; background: var(--gold);
    border: none; border-radius: 5px; color: var(--bg-dark);
    font-weight: 600; cursor: pointer; font-size: 0.75rem;
}

.chat-area {
    flex: 1; padding: 0 70px 12px 120px;
    overflow-y: auto; display: flex; flex-direction: column; gap: 10px;
}
.chat-area::-webkit-scrollbar { width: 5px; }
.chat-area::-webkit-scrollbar-track { background: var(--bg-dark); border-radius: 3px; }
.chat-area::-webkit-scrollbar-thumb { background: var(--gold); border-radius: 3px; }
.message { max-width: 85%; padding: 10px 15px; border-radius: 16px; line-height: 1.5; font-size: 0.85rem; word-wrap: break-word; overflow-wrap: break-word; }
.message.user {
    align-self: flex-end; color: var(--text-light);
    background: linear-gradient(145deg, var(--bg-light), var(--bg-medium));
    border: 1px solid #5a4a3a; display: flex; flex-direction: column; align-items: flex-end;
}
.message.ai {
    align-self: flex-start; color: var(--text-light);
    background: linear-gradient(145deg, #4a3a32, #3d2e26);
    border: 1px solid rgba(212,165,116,0.3);
}
.diary-ready-btn {
    align-self: center; margin: 8px 0;
    background: linear-gradient(145deg, var(--gold), #a88420);
    color: var(--bg-dark); border: none; border-radius: 20px;
    padding: 10px 28px; font-family: 'Noto Serif TC', serif;
    font-size: 0.85rem; font-weight: 600;
    cursor: pointer; transition: all 0.3s ease;
    box-shadow: 0 4px 20px rgba(201,162,39,0.4);
    animation: glowPulse 2s infinite;
}
.diary-ready-btn:hover { transform: scale(1.05); }
@keyframes glowPulse {
    0%, 100% { box-shadow: 0 4px 20px rgba(201,162,39,0.4); }
    50% { box-shadow: 0 4px 30px rgba(201,162,39,0.7); }
}
.diary-modal {
    position: absolute; inset: 0; background: rgba(0,0,0,0.85);
    display: flex; justify-content: center; align-items: center;
    z-index: 100; padding: 20px;
}
.diary-book {
    background: linear-gradient(145deg, #f5e6d3, #e8d5c0);
    border-radius: 12px; max-width: 1000px; width: 95%;
    max-height: 90vh; overflow-y: auto; position: relative;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.diary-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 20px 25px 5px;
}
.diary-header h2 { color: #8b7355; font-size: 1.1rem; letter-spacing: 8px; }
.diary-close {
    background: none; border: none; font-size: 1.5rem; color: #8b7355;
    cursor: pointer; padding: 5px 10px;
}
/* 自動日期 */
.diary-date {
    text-align: center; color: #a08060; font-size: 0.8rem;
    padding: 5px 0 10px; font-style: italic; letter-spacing: 2px;
}
.diary-content { display: flex; min-height: 300px; }
.diary-page {
    flex: 1; padding: 20px 25px; position: relative;
    color: #4a3830; line-height: 1.8; font-size: 0.9rem;
}
.diary-page:first-child { border-right: 1px solid #d4c4b0; }
.diary-page h3 { color: #8b7355; margin-bottom: 10px; font-size: 1rem; }
.diary-page .ai-title { color: var(--pink-bright); }
.diary-page p { white-space: pre-wrap; }
.copy-btn {
    position: absolute; top: 20px; right: 20px;
    background: none; border: none; font-size: 1.2rem;
    cursor: pointer; opacity: 0.5; transition: opacity 0.2s;
}
.copy-btn:hover { opacity: 1; }

/* 小粉立繪區域 - 支援 emoji fallback 和自訂圖片 */
.cat-mascot {
    position: absolute; left: 12px; bottom: 85px;
    width: 110px; height: 110px;
    z-index: 5; display: flex; align-items: center; justify-content: center;
    filter: drop-shadow(0 4px 20px rgba(232,160,160,0.6));
    transition: all 0.3s ease;
}
.cat-mascot .emoji-fallback { font-size: 65px; }
.cat-mascot img {
    width: 100%; height: 100%; object-fit: contain;
}

.input-area {
    padding: 12px 20px; display: flex; align-items: center; gap: 8px;
    background: linear-gradient(180deg, transparent, rgba(0,0,0,0.2));
}
.input-container {
    flex: 1; display: flex; align-items: center;
    background: linear-gradient(145deg, #3d2e26, #2a1f1a);
    border: 2px solid #5a4a3a; border-radius: 20px; padding: 9px 14px;
}
.input-container input {
    flex: 1; background: transparent; border: none; outline: none;
    color: var(--text-light); font-size: 0.85rem; font-family: 'Noto Serif TC', serif;
}
.input-container input::placeholder { color: rgba(212,184,150,0.5); }
.mic-btn, .send-btn {
    width: 44px; height: 44px; border-radius: 50%; border: none; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    background: linear-gradient(145deg, #4a3830, #3d2e26);
    border: 3px solid #6a5a4a; transition: all 0.3s ease;
}
.mic-btn:hover, .send-btn:hover { transform: scale(1.05); }
.mic-btn.recording {
    background: linear-gradient(145deg, #ff6b9d, #d4547a);
    border-color: #ff8ab5; animation: pulse 1.5s infinite;
}
@keyframes pulse {
    0%, 100% { box-shadow: 0 4px 20px rgba(255,107,157,0.5); }
    50% { box-shadow: 0 4px 30px rgba(255,107,157,0.7); }
}
.mic-btn svg, .send-btn svg { width: 20px; height: 20px; fill: var(--rose-gold); }
.mic-btn.recording svg { fill: white; }
.mic-btn:disabled, .send-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.loading { display: flex; gap: 4px; padding: 8px; }
.loading span {
    width: 6px; height: 6px; background: var(--rose-gold);
    border-radius: 50%; animation: bounce 1.4s ease-in-out infinite both;
}
.loading span:nth-child(1) { animation-delay: -0.32s; }
.loading span:nth-child(2) { animation-delay: -0.16s; }
@keyframes bounce { 0%, 80%, 100% { transform: scale(0); } 40% { transform: scale(1); } }
.status-bar {
    position: absolute; top: 16px; right: 70px;
    font-size: 0.65rem; color: var(--text-gold); opacity: 0.7;
}
.input-container input.typewriter-active { caret-color: var(--gold); }

/* ===== v9: 圖片上傳相關樣式 ===== */
.camera-btn {
    width: 44px; height: 44px; border-radius: 50%; border: none; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    background: linear-gradient(145deg, #4a3830, #3d2e26);
    border: 3px solid #6a5a4a; transition: all 0.3s ease;
    flex-shrink: 0;
}
.camera-btn:hover { transform: scale(1.05); }
.camera-btn svg { width: 20px; height: 20px; fill: var(--rose-gold); }
.camera-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.image-preview-bar {
    display: flex; align-items: center; gap: 8px;
    padding: 8px 20px; background: rgba(0,0,0,0.15);
}
.image-preview-thumb {
    position: relative; width: 60px; height: 60px; border-radius: 8px;
    overflow: hidden; border: 2px solid var(--rose-gold);
}
.image-preview-thumb img {
    width: 100%; height: 100%; object-fit: cover;
}
.image-preview-remove {
    position: absolute; top: -4px; right: -4px; width: 20px; height: 20px;
    background: #ff6b6b; color: white; border: none; border-radius: 50%;
    font-size: 12px; cursor: pointer; display: flex; align-items: center;
    justify-content: center; line-height: 1;
}
.image-preview-label {
    font-size: 0.75rem; color: var(--text-gold); opacity: 0.8;
}
.chat-image {
    max-width: 200px; max-height: 150px; border-radius: 8px;
    margin-bottom: 6px; object-fit: cover; border: 1px solid rgba(212,184,150,0.3);
    display: block;
}
/* v11: 日記朗讀按鈕 */
.read-aloud-btn {
    background: none; border: none; cursor: pointer; font-size: 1.1rem;
    padding: 2px 6px; border-radius: 6px; transition: all 0.3s ease;
    opacity: 0.7; vertical-align: middle; margin-left: 6px;
}
.read-aloud-btn:hover { opacity: 1; transform: scale(1.1); }
.read-aloud-btn.reading {
    opacity: 1; animation: pulse-read 1.5s infinite;
}
@keyframes pulse-read {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* ===== v12: 版本標示 ===== */
.version-tag {
    position: absolute; bottom: 8px; right: 12px;
    font-size: 0.6rem; color: rgba(212,184,150,0.3);
    font-family: 'Cinzel Decorative', cursive; letter-spacing: 2px;
    pointer-events: none; z-index: 1;
}

/* ===== v12.1: SR debug log overlay ===== */
.sr-debug-toggle {
    position: fixed; top: 10px; right: 10px;
    width: 28px; height: 28px; border-radius: 50%;
    background: rgba(0,0,0,0.5); color: #0f0;
    border: 1px solid rgba(0,255,0,0.3);
    font-size: 14px; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    z-index: 10000; backdrop-filter: blur(4px);
    transition: all 0.2s;
}
.sr-debug-toggle:hover { background: rgba(0,0,0,0.8); }
.sr-debug-log {
    position: fixed; top: 44px; right: 10px;
    background: rgba(0,0,0,0.7); color: #0f0;
    font-family: 'Courier New', monospace; font-size: 11px;
    padding: 6px 8px; border-radius: 6px;
    max-width: 300px; max-height: 72px;
    overflow-y: auto; line-height: 1.3;
    z-index: 9999; pointer-events: none;
    backdrop-filter: blur(4px);
    border: 1px solid rgba(0,255,0,0.15);
}

/* ===== v12: 日記本歷史列表 ===== */
.diary-history-panel {
    background: linear-gradient(145deg, #f5e6d3, #e8d5c0);
    border-radius: 12px; max-width: 520px; width: 92%;
    max-height: 85vh; overflow: hidden; position: relative;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
    display: flex; flex-direction: column;
}
.diary-history-count {
    padding: 0 20px 8px; font-size: 0.7rem; color: #a08060;
    text-align: right; font-style: italic;
}
.diary-history-list {
    flex: 1; overflow-y: auto; padding: 0 16px 16px;
}
.diary-history-list::-webkit-scrollbar { width: 4px; }
.diary-history-list::-webkit-scrollbar-thumb { background: #c4a882; border-radius: 2px; }
.diary-history-empty {
    text-align: center; padding: 50px 20px; color: #8b7355;
    display: flex; flex-direction: column; align-items: center; gap: 12px;
}
.diary-history-empty p { white-space: pre-line; line-height: 1.6; font-size: 0.9rem; }
.diary-history-item {
    padding: 14px 16px; margin-bottom: 8px;
    background: linear-gradient(145deg, #fff8f0, #f5e6d3);
    border: 1px solid #e0d0c0; border-radius: 10px;
    cursor: pointer; transition: all 0.25s ease; position: relative;
}
.diary-history-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(139,115,85,0.2);
    border-color: var(--gold);
}
.diary-history-item-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 6px;
}
.diary-history-item-date {
    font-size: 0.75rem; color: #a08060;
    font-style: italic; letter-spacing: 1px;
}
.diary-history-item-emotion { font-size: 1rem; }
.diary-history-item-preview {
    font-size: 0.82rem; color: #4a3830; line-height: 1.5;
    overflow: hidden; text-overflow: ellipsis;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
.diary-history-item-delete {
    position: absolute; top: 10px; right: 10px;
    background: none; border: none; font-size: 0.9rem;
    cursor: pointer; opacity: 0; transition: opacity 0.2s;
    padding: 4px;
}
.diary-history-item:hover .diary-history-item-delete { opacity: 0.6; }
.diary-history-item-delete:hover { opacity: 1 !important; }
.diary-back-btn {
    background: none; border: none; color: #8b7355;
    font-size: 0.85rem; cursor: pointer; padding: 5px 10px;
    font-family: 'Noto Serif TC', serif; transition: color 0.2s;
}
.diary-back-btn:hover { color: var(--gold); }

@media (max-width: 768px) {
    .app-container { height: 100vh; max-height: none; border-radius: 0; }
    .logo { font-size: 1.3rem; }
    .chat-area { padding: 0 60px 12px 12px; }
    .toolbar { right: 6px; top: 60px; }
    .tool-btn { width: 34px; height: 34px; }
    .cat-mascot { width: 45px; height: 45px; left: 6px; bottom: 75px; }
    .cat-mascot .emoji-fallback { font-size: 40px; }
    .input-container { margin-left: 0; }
    .diary-content { flex-direction: column; }
    .diary-page:first-child { border-right: none; border-bottom: 1px solid #d4c4b0; }
}
