/* ================= CSS 樣式區塊 ================= */
/* 1. 魔法設定：告訴瀏覽器這兩個變數是「顏色」，解鎖色號漸變能力 */
@property --theme-start {
    syntax: '<color>';
    inherits: true;
    initial-value: #ff9a9e;
}

@property --theme-end {
    syntax: '<color>';
    inherits: true;
    initial-value: #fecfef;
}

:root {
    --theme-start: #ff9a9e;
    --theme-end: #fecfef;
}

body.theme-female {
    --theme-start: #ff9a9e;
    --theme-end: #e0c3fc;
    background-color: #fce4ec;
}

body.theme-male {
    --theme-start: #8fd3f4;
    --theme-end: #a1c4fd;
    background-color: #f0f8ff;
}

body {
    font-family: '-apple-system', 'BlinkMacSystemFont', 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    margin: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    /* 2. 把時間拉長到 3 秒，並將兩個漸層變數也加入動畫列隊 */
    transition: background-color 4s ease-in-out,
        --theme-start 4s ease-in-out,
        --theme-end 4s ease-in-out;
}

.bg-shapes {
    position: absolute;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    top: 0;
    left: 0;
    z-index: -1;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
}

.blob {
    position: absolute;
    filter: blur(70px);
    opacity: 0.85;
    width: 85vw;
    height: 85vw;
    animation: insaneMorphAndSpin 25s infinite alternate cubic-bezier(0.4, 0, 0.2, 1);
    background: linear-gradient(135deg, var(--theme-start), var(--theme-end));
    background-size: 200% 200%;
}

@keyframes insaneMorphAndSpin {
    0% {
        transform: scale(1) rotate(0deg);
        border-radius: 30% 70% 70% 30% / 30% 30% 70% 70%;
        background-position: 0% 50%;
    }

    33% {
        transform: scale(1.15) rotate(120deg);
        border-radius: 70% 30% 40% 60% / 60% 70% 30% 40%;
    }

    66% {
        transform: scale(0.85) rotate(240deg);
        border-radius: 40% 60% 30% 70% / 40% 40% 60% 50%;
    }

    100% {
        transform: scale(1.05) rotate(360deg);
        border-radius: 30% 70% 70% 30% / 30% 30% 70% 70%;
        background-position: 100% 50%;
    }
}

.chat-container {
    position: relative;
    width: 100%;
    max-width: 420px;
    height: 100vh;
    height: 100dvh;
    max-height: 850px;
    background: rgba(255, 255, 255, 0.35);
    backdrop-filter: blur(40px) saturate(150%);
    -webkit-backdrop-filter: blur(40px) saturate(150%);
    border: 1px solid rgba(255, 255, 255, 0.6);
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 10;
}

@media (min-width: 420px) {
    .chat-container {
        border-radius: 28px;
        height: 90vh;
    }
}

.nautia-logo-main {
    width: 220px;
    max-width: 80%;
    margin-bottom: 20px;
    object-fit: contain;
    filter: drop-shadow(0 8px 16px rgba(0, 0, 0, 0.1));
}

@media screen and (max-width: 600px) {
    .nautia-logo-corner {
        display: none !important;
        visibility: hidden !important;
        opacity: 0 !important;
    }
    
    .chat-header {
        padding: 10px 14px !important;
    }
}

.nautia-logo-corner {
    position: absolute;
    top: 25px;
    left: 25px;
    width: 180px;
    object-fit: contain;
    opacity: 0;
    visibility: hidden;
    transition: opacity 1.5s ease, visibility 1.5s ease;
    z-index: 100;
    pointer-events: none;
}

.show-corner-logo {
    opacity: 0.8;
    visibility: visible;
}

.chat-header {
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 14px;
    background: rgba(255, 255, 255, 0.3);
    border-bottom: 1px solid rgba(255, 255, 255, 0.4);
}

.avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid #fff;
    background-color: #eee;
}

.user-info h2 {
    margin: 0;
    font-size: 17px;
    color: #1c1e21;
    font-weight: 700;
}

.user-info p {
    margin: 3px 0 0 0;
    font-size: 12px;
    color: #10a37f;
    font-weight: 600;
    transition: color 0.3s;
}

.user-info p.offline {
    color: #888;
    font-weight: 500;
}

.logout-btn {
    padding: 0 16px;
    height: 32px;
    margin-left: auto;
    cursor: pointer;
    background: linear-gradient(135deg, var(--theme-start), var(--theme-end));
    background-size: 200% 200%;
    animation: gradientShift 5s ease infinite alternate;
    color: #fff;
    border: none;
    border-radius: 16px;
    font-weight: bold;
    font-size: 13px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    transition: transform 0.2s;
}

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

.chat-messages {
    flex: 1;
    padding: 24px 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
    scrollbar-width: none;
}

.chat-messages::-webkit-scrollbar {
    display: none;
}

.timestamp {
    align-self: center;
    font-size: 11px;
    color: #888;
    margin: 15px 0 5px 0;
    background: rgba(0, 0, 0, 0.06);
    padding: 4px 12px;
    border-radius: 12px;
    font-weight: 500;
}

.message-wrapper {
    display: flex;
    flex-direction: column;
    max-width: 75%;
    animation: fadeIn 0.4s cubic-bezier(0.25, 0.8, 0.25, 1) forwards;
}

.message-wrapper.incoming {
    align-self: flex-start;
}

.message-wrapper.outgoing {
    align-self: flex-end;
    align-items: flex-end;
}

/* 換人講話時間距拉大 */
.message-wrapper.incoming+.message-wrapper.outgoing {
    margin-top: 12px;
}

.message-wrapper.outgoing+.message-wrapper.incoming {
    margin-top: 12px;
}

.timestamp+.message-wrapper {
    margin-top: 8px;
}

.message {
    padding: 12px 16px;
    font-size: 15px;
    line-height: 1.5;
    word-wrap: break-word;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04);
}

.message.incoming {
    background: rgba(255, 255, 255, 0.65);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    color: #1c1e21;
    border: 1px solid rgba(255, 255, 255, 0.7);
}

/* Incoming 小尾巴邏輯 */
.message.incoming.single {
    border-radius: 4px 20px 20px 20px;
}

.message.incoming.first {
    border-radius: 20px 20px 20px 4px;
}

.message.incoming.middle {
    border-radius: 4px 20px 20px 4px;
}

.message.incoming.last {
    border-radius: 4px 20px 20px 20px;
}

.message.outgoing {
    background: linear-gradient(135deg, var(--theme-start), var(--theme-end));
    background-size: 200% 200%;
    animation: gradientShift 5s ease infinite alternate;
    color: #fff;
}

/* Outgoing 小尾巴邏輯 */
.message.outgoing.single {
    border-radius: 20px 4px 20px 20px;
}

.message.outgoing.first {
    border-radius: 20px 20px 4px 20px;
}

.message.outgoing.middle {
    border-radius: 20px 4px 4px 20px;
}

.message.outgoing.last {
    border-radius: 20px 4px 20px 20px;
}

@keyframes gradientShift {
    0% {
        background-position: 0% 50%;
    }

    100% {
        background-position: 100% 50%;
    }
}

.read-status {
    font-size: 10px;
    color: #888;
    margin-top: 4px;
    margin-right: 4px;
    transition: color 0.3s;
}

.read-status.read {
    color: var(--theme-start);
    filter: brightness(0.8);
    font-weight: bold;
}

.typing-text {
    font-size: 13px;
    color: #888;
    align-self: flex-start;
    margin-left: 5px;
    animation: pulse 1.5s infinite;
    margin-top: 8px;
}

@keyframes pulse {
    0% {
        opacity: 0.5;
    }

    50% {
        opacity: 1;
    }

    100% {
        opacity: 0.5;
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chat-input-area {
    padding: 16px;
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
    background: rgba(255, 255, 255, 0.5);
    border-top: 1px solid rgba(255, 255, 255, 0.6);
    display: flex;
    align-items: center;
    gap: 12px;
}

.attach-btn {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.8);
    border: none;
    color: var(--theme-start);
    font-size: 24px;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
}

.attach-btn:hover {
    background: #fff;
    transform: scale(1.05);
}

#messageInput {
    flex: 1;
    padding: 12px 18px;
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 24px;
    font-size: 15px;
    background: rgba(255, 255, 255, 0.8);
    color: #1c1e21;
    
    /* 🌟 新增這些來重置 textarea 的醜樣式 */
    resize: none;         /* 禁止使用者手動拉大縮小 */
    overflow: hidden;     /* 隱藏捲軸，因為我們會用 JS 讓它自動長高 */
    font-family: inherit; /* 繼承你網站漂亮的字體，不然會變成醜醜的預設字體 */
    outline: none;        /* 點擊時不要有藍色框框 */
    box-sizing: border-box; /* 確保 padding 不會撐破外框 */
    min-height: 40px;     /* 設定一個最小高度，避免太扁 */
    max-height: 120px;    /* 🌟 設定一個最大高度，超過這個高度才出現捲軸，才不會蓋住整個畫面 */
}

.chat-input-area button.send-btn {
    padding: 0 20px;
    height: 42px;
    background: linear-gradient(135deg, var(--theme-start), var(--theme-end));
    background-size: 200% 200%;
    animation: gradientShift 5s ease infinite alternate;
    color: #fff;
    border: none;
    border-radius: 24px;
    cursor: pointer;
    font-weight: bold;
    font-size: 15px;
}

.overlay-screen {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.75);
    backdrop-filter: blur(30px);
    z-index: 100;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 30px;
    text-align: center;
    border-radius: inherit;
    transition: opacity 0.6s;
}

.overlay-screen h1 {
    margin: 0 0 10px;
    color: #1c1e21;
    font-size: 24px;
}

.overlay-screen p {
    color: #65676b;
    font-size: 14px;
    margin-bottom: 25px;
}

.form-group {
    width: 100%;
    max-width: 280px;
    margin-bottom: 16px;
    text-align: left;
}

.form-group label {
    display: block;
    font-size: 13px;
    color: #4b4f56;
    margin-bottom: 8px;
    font-weight: 600;
}

.form-group input,
.form-group select {
    width: 100%;
    box-sizing: border-box;
    padding: 12px 16px;
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 12px;
    font-size: 15px;
    outline: none;
    background: #fff;
}

.divider {
    width: 100%;
    max-width: 280px;
    display: flex;
    align-items: center;
    text-align: center;
    margin-bottom: 12px;
    margin-top: 2px;
    color: #aaa;
    font-size: 12px;
}

.divider::before,
.divider::after {
    content: '';
    flex: 1;
    border-bottom: 1px solid #ddd;
}

.divider span {
    padding: 0 10px;
}

.google-btn {
    width: 100%;
    max-width: 280px;
    padding: 10px;
    background: #fff;
    color: #4b4f56;
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 12px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-bottom: 10px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.02);
    transition: background 0.2s;
}

.google-btn:hover {
    background: #f9f9f9;
}

.google-btn svg {
    width: 18px;
    height: 18px;
}

.start-btn {
    margin-top: 5px;
    width: 100%;
    max-width: 280px;
    padding: 14px;
    background: linear-gradient(135deg, var(--theme-start), var(--theme-end));
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.auth-links {
    margin-top: 20px;
    font-size: 13px;
    color: #666;
    cursor: pointer;
    line-height: 2;
}

.auth-links span:hover {
    color: #1c1e21;
    text-decoration: underline;
}

.error-msg {
    color: #e74c3c;
    font-size: 13px;
    margin-top: 5px;
    min-height: 18px;
}

/* ================= 更多選項選單 (三個點) ================= */
.more-options-container {
    margin-left: auto;
    position: relative;
}

.more-options-btn {
    background: none;
    border: none;
    font-size: 24px;
    font-weight: bold;
    color: #4b4f56;
    cursor: pointer;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: background 0.2s;
}

.more-options-btn:hover {
    background: rgba(0, 0, 0, 0.05);
}

.dropdown-menu {
    position: absolute;
    top: 45px;
    right: 0;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    width: 140px;
    display: flex;
    flex-direction: column;
    padding: 8px 0;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    z-index: 200;
}

.dropdown-menu.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.dropdown-menu button {
    background: none;
    border: none;
    padding: 12px 16px;
    text-align: left;
    font-size: 14px;
    font-weight: 600;
    color: #1c1e21;
    cursor: pointer;
    transition: background 0.2s;
}

.dropdown-menu button:hover {
    background: rgba(0, 0, 0, 0.05);
}

.dropdown-menu button.danger {
    color: #e74c3c;
}

.dropdown-menu button.danger:hover {
    background: rgba(231, 76, 60, 0.1);
}

.menu-divider {
    height: 1px;
    background: rgba(0, 0, 0, 0.08);
    margin: 4px 0;
}

/* ================= 照片預覽浮窗 ================= */
#imagePreviewContainer {
    display: none;
    position: absolute;
    top: -100px;
    left: 20px;
    background: rgba(255, 255, 255, 0.9);
    padding: 5px;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

#imagePreview {
    max-height: 80px;
    border-radius: 8px;
    object-fit: contain;
}

#clearImageBtn {
    position: absolute;
    top: -8px;
    right: -8px;
    background: #e74c3c;
    color: white;
    border: none;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    cursor: pointer;
    font-size: 14px;
    font-weight: bold;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* 🌟 Google 官方質感登入按鈕 (終極原廠版) */
.google-login-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #ffffff;
    color: #3c4043;
    border: 1px solid #dadce0;
    width: 100%;
    max-width: 280px;
    box-sizing: border-box;
    border-radius: 12px;
    /* 配合你原本的圓潤感 */
    height: 44px;
    /* 稍微縮減高度，看起來更精緻 */
    font-size: 14px;
    /* 字體稍微縮小一點會更有質感 */
    font-weight: 500;
    font-family: 'Roboto', 'Noto Sans TC', sans-serif;
    cursor: pointer;
    box-shadow: 0 1px 2px 0 rgba(60, 64, 67, 0.3);
    transition: background-color 0.2s, box-shadow 0.2s;
    margin-top: 15px;
    position: relative;
}

/* 確保裡面的 Google Logo 絕對居左或保持完美間距 */
.google-login-btn img {
    width: 18px;
    height: 18px;
    margin-right: 12px;
}

.google-login-btn:hover {
    background-color: #f8f9fa;
    box-shadow: 0 1px 3px 1px rgba(60, 64, 67, 0.15), 0 2px 6px 2px rgba(60, 64, 67, 0.15);
}

/* 發送按鈕預設隱藏 */
.send-btn {
    display: none;
    /* (保留你原本的其他發送按鈕樣式...) */
}

/* 麥克風按鈕預設顯示 */
.mic-btn {
    display: block;
    /* (保留你原本的其他麥克風按鈕樣式...) */
}

/* 🌟 麥克風按鈕基本樣式 (固定寬高以呈現完美圓形) */
.mic-btn {
    background: none;
    border: none;
    cursor: pointer;
    margin: 0 4px;
    border-radius: 50%;
    transition: background-color 0.3s, transform 0.2s;
    outline: none;
    display: block;

    /* 👇 核心修改：固定正方形寬高，並使用 Flex 讓圖示居中 👇 */
    width: 38px;  /* 固定寬度 */
    height: 38px; /* 固定高度 (跟輸入框差不多高) */
    padding: 0;   /* 清除原本的 padding */
    display: flex; /* 啟用 Flex 佈局 */
    align-items: center; /* 垂直居中 */
    justify-content: center; /* 水平居中 */
}

/* 確保裡面的 SVG 圖示顏色與尺寸正確 */
.mic-btn svg {
    width: 20px;
    height: 20px;
    stroke: #666; /* 官方灰色 */
    transition: stroke 0.2s;
}

.mic-btn:hover {
    background-color: #f0f0f0; /* 灰色的圓形背景 */
    transform: scale(1.05); /* 微小的放大效果 */
}

.mic-btn:hover svg {
    stroke: #333; /* 滑過時圖示變深色 */
}

/* 🌟 錄音中的紅光閃爍動畫 */
.mic-btn.recording {
    background-color: #ffebee;
    border: 1px solid #ff5252;
    animation: pulse-red 1.5s infinite;
}

@keyframes pulse-red {
    0% {
        box-shadow: 0 0 0 0 rgba(255, 82, 82, 0.7);
    }

    70% {
        box-shadow: 0 0 0 10px rgba(255, 82, 82, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(255, 82, 82, 0);
    }
}