:root {
    --bg: #000000;
    --primary: #b153ff;
    --bubble-me: #b153ff;
    --bubble-other: #262626;
    --quote-bg: rgba(255,255,255,0.15);
    --input-bg: #1c1c1c;
    --border: #2b2b2b;
    --text-main: #ffffff;
    --text-sub: #aaaaaa;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
    margin: 0; padding: 0;
    background: var(--bg); color: var(--text-main);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    height: 100dvh; overflow: hidden;
}

#homeScreen, #chatScreen {
    height: 100%; width: 100%; position: absolute; top: 0; left: 0;
}

.btn {
    display: inline-flex; align-items: center; justify-content: center;
    padding: 12px 24px; border-radius: 999px; border: none;
    font-size: 16px; font-weight: 600; color: #fff; background: var(--primary);
    cursor: pointer; width: 100%; max-width: 200px; transition: transform 0.1s;
}
.btn:active { transform: scale(0.98); opacity: 0.9; }

#homeScreen {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    padding: 20px; text-align: center; overflow-y: auto; z-index: 20;
}
.home-title {
    font-size: 28px; font-weight: 800; margin-bottom: 8px;
    background: linear-gradient(45deg, #b153ff, #ff7bb0);
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}
.home-sub { font-size: 14px; color: var(--text-sub); margin-bottom: 30px; }

.profile-card {
    background: #121212; border-radius: 20px; padding: 20px;
    width: 100%; max-width: 360px; text-align: left;
    border: 1px solid var(--border); margin-bottom: 30px;
}
.profile-row { display: flex; align-items: center; margin-bottom: 20px; }
.avatar-preview {
    width: 60px; height: 60px; border-radius: 50%;
    background: radial-gradient(circle at 30% 30%, #ffd27a, #ff7bb0);
    display: flex; align-items: center; justify-content: center;
    font-size: 28px; font-weight: 700; margin-right: 15px; flex-shrink: 0; border: 2px solid #333; overflow: hidden;
}
.avatar-preview img { width: 100%; height: 100%; object-fit: cover; }
.profile-input {
    width: 100%; padding: 12px; border-radius: 12px; border: 1px solid var(--border);
    background: #181818; color: var(--text-main); font-size: 15px; margin-top: 5px; outline: none;
}
.profile-input:focus { border-color: var(--primary); }

#chatScreen { display: none; flex-direction: column; background: var(--bg); z-index: 10; }
.chat-header {
    padding: 10px 15px; display: flex; align-items: center;
    border-bottom: 1px solid var(--border); background: rgba(0,0,0,0.8);
    backdrop-filter: blur(10px); position: sticky; top: 0; z-index: 100;
}
.header-avatar {
    width: 36px; height: 36px; border-radius: 50%; background: #333;
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-weight: 700; font-size: 18px; margin-right: 10px; border: 1px solid #333; overflow: hidden;
}
.header-avatar img { width: 100%; height: 100%; object-fit: cover; }
.header-text { flex: 1; }
.header-name { font-size: 16px; font-weight: 600; }
.header-status { font-size: 12px; color: var(--text-sub); display: flex; align-items: center; gap: 5px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #ccc; }
.status-dot.active { background: #4CAF50; box-shadow: 0 0 5px #4CAF50; }

#chat { padding: 15px; flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; position: relative; padding-bottom: 20px; }

.welcome-hero {
    min-height: 45vh; display: flex; flex-direction: column; justify-content: flex-end;
    align-items: center; text-align: center; padding-bottom: 20px; opacity: 0.8;
}
.welcome-hero h2 {
    margin: 5px 0; font-size: 22px;
    background: linear-gradient(45deg, #b153ff, #ff7bb0);
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}
.welcome-hero p { margin: 0; font-size: 13px; color: #888; }

.msg-row { display: flex; align-items: flex-end; max-width: 85%; cursor: pointer; }
.msg-row.me { align-self: flex-end; justify-content: flex-end; }
.msg-row.other { align-self: flex-start; }
.msg-avatar-small {
    width: 28px; height: 28px; border-radius: 50%; background: #333;
    margin-right: 8px; flex-shrink: 0; display: flex; align-items: center; justify-content: center;
    font-size: 12px; font-weight: bold; overflow: hidden;
}
.msg-avatar-small img { width: 100%; height: 100%; object-fit: cover; }
.msg-bubble {
    padding: 10px 16px; border-radius: 20px; font-size: 15px;
    line-height: 1.5; word-wrap: break-word; position: relative;
    transition: transform 0.2s, background 0.3s;
}
.msg-row.me .msg-bubble { background: var(--bubble-me); color: #fff; border-bottom-right-radius: 4px; }
.msg-row.other .msg-bubble { background: var(--bubble-other); color: #fff; border-bottom-left-radius: 4px; }

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-4px); }
    20%, 40%, 60%, 80% { transform: translateX(4px); }
}
.shake {
    animation: shake 0.5s ease-in-out;
    background: #444 !important;
}

.msg-img {
    max-width: 100%; border-radius: 10px; margin-bottom: 5px; display: block;
}

.msg-quote {
    display: block; font-size: 12px; color: rgba(255,255,255,0.7); background: var(--quote-bg);
    border-left: 3px solid rgba(255,255,255,0.5); padding: 4px 8px; margin-bottom: 6px;
    border-radius: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%;
}
.msg-quote strong { color: #fff; margin-right: 5px; }

.sys-msg {
    align-self: center; font-size: 12px; color: var(--text-sub);
    background: rgba(255,255,255,0.1); padding: 4px 12px; border-radius: 99px; margin: 10px 0;
}

.typing-bubble {
    padding: 12px 16px; border-radius: 20px; background: var(--bubble-other);
    display: inline-flex; align-items: center; gap: 4px; border-bottom-left-radius: 4px;
}
.typing-dot {
    width: 6px; height: 6px; border-radius: 50%; background: #888;
    animation: typing 1.4s infinite ease-in-out;
}
.typing-dot:nth-child(1) { animation-delay: 0s; }
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing {
    0%, 100% { transform: translateY(0); opacity: 0.5; }
    50% { transform: translateY(-3px); opacity: 1; }
}

.input-container {
    border-top: 1px solid var(--border); background: #000;
    position: relative; z-index: 20; display: flex; flex-direction: column;
}
.reply-bar {
    display: none; background: #111; padding: 8px 15px; border-bottom: 1px solid #333;
    font-size: 13px; color: #ccc; align-items: center; justify-content: space-between;
}
.reply-bar.active { display: flex; }
.reply-content { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-right: 10px; }
.reply-close { background: none; border: none; color: #666; font-size: 18px; cursor: pointer; padding: 0 5px; }

.input-bar { padding: 10px; display: flex; align-items: center; gap: 10px; background: #000; }
.leave-btn {
    color: #ff5555; background: none; border: none; font-weight: 600; font-size: 15px;
    padding: 8px 12px; cursor: pointer; border-radius: 8px; white-space: nowrap;
}

/* ✅ IG 風格相機按鈕 */
.camera-btn {
    width: 40px; height: 40px; border-radius: 50%;
    /* 粉色漸層背景 */
    background: linear-gradient(45deg, #b153ff, #ff7bb0);
    color: white; border: none; font-size: 20px;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; margin-right: 5px; flex-shrink: 0;
}
.camera-btn:active { transform: scale(0.95); opacity: 0.9; }

/* Wrapper 變回灰色膠囊 */
.input-wrapper {
    flex: 1; background: var(--input-bg); border-radius: 24px; padding: 8px 16px;
    display: flex; align-items: center; border: 1px solid transparent; transition: border 0.2s;
}
.input-wrapper:focus-within { border-color: #444; }

#msg {
    flex: 1; border: none; background: transparent; color: var(--text-main); font-size: 15px; outline: none; padding: 4px 0;
}
.send-btn {
    border: none; background: none; color: var(--primary); font-weight: 700; font-size: 15px;
    cursor: pointer; padding: 4px 8px; transition: opacity 0.2s; white-space: nowrap;
}
.send-btn:disabled { opacity: 0.3; cursor: default; }

#confirmOverlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.6); display: none;
    align-items: center; justify-content: center; z-index: 1000; backdrop-filter: blur(2px);
}
.confirm-box {
    width: 80%; max-width: 280px; background: #1c1c1c; border-radius: 16px; overflow: hidden;
    box-shadow: 0 10px 40px rgba(0,0,0,0.5);
}
.confirm-title { padding: 20px 20px 10px; text-align: center; font-weight: 600; font-size: 17px; }
.confirm-desc { padding: 0 20px 20px; text-align: center; font-size: 13px; color: #aaa; line-height: 1.4; }
.confirm-actions { display: flex; border-top: 1px solid #333; }
.c-btn {
    flex: 1; padding: 14px; background: none; border: none; color: #fff;
    font-size: 15px; cursor: pointer; border-right: 1px solid #333;
}
.c-btn:last-child { border: none; }
.c-destruct { color: #ff5555; font-weight: 600; }
