@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+TC:wght@400;500;700&display=swap');

body {
    font-family: 'Noto Sans TC', sans-serif;
    transition: background-color 0.3s ease, color 0.3s ease;
    background-color: var(--bs-body-bg);
    margin: 0; /* 重置 body 的 margin */
    overflow: hidden; /* 防止 body 本身出現滾動條 */
}

/* 獨立的背景容器 */
#background-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    /* 日間模式：黃昏漸層背景 */
    background-image: linear-gradient(to bottom, #0b192f 0%, #2c3e50 80%, #a85673 95%, #ff8c7f 100%);
}

/* 內容滾動容器 */
#content-wrapper {
    height: 100vh;
    overflow-y: auto; /* 讓這個容器負責垂直滾動 */
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch; /* 在移動設備上實現平滑滾動 */
}

/* --- 黃昏與星空效果 --- */
/* 星星/光點閃爍動畫 */
@keyframes twinkle {
    0%, 100% { opacity: 0.2; }
    50% { opacity: 1; }
}

/* 光點升起動畫 */
@keyframes rise-and-twinkle {
    0% {
        transform: translateY(0);
        opacity: 0;
    }
    10%, 90% {
        opacity: 1; /* 主要可見區間 */
    }
    25% { opacity: 0.4; } /* 閃爍 */
    50% { opacity: 1; }   /* 閃爍 */
    75% { opacity: 0.6; } /* 閃爍 */
    100% {
        transform: translateY(-100vh);
        opacity: 0;
    }
}

/* 創建三層星星，增加層次感 */
.stars, .stars2, .stars3 {
    position: fixed; /* 改為 fixed，相對於 viewport 定位 */
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
}

/* 使用 box-shadow 繪製星星 */
.stars {
    background: transparent;
    box-shadow: 
        10vw 25vh 1px 1px #FFF, 90vw 30vh 1px 1px #FFF, 
        50vw 10vh 1px 1px #FFF, 20vw 80vh 1px 1px #FFF,
        75vw 60vh 1px 1px #FFF, 5vw 5vh 1px 1px #FFF;
    animation: twinkle 5s infinite ease-in-out;
}

.stars2 {
    background: transparent;
    box-shadow: 
        80vw 90vh 0px 0px #FFF, 30vw 40vh 0px 0px #FFF,
        60vw 20vh 0px 0px #FFF, 40vw 70vh 0px 0px #FFF,
        95vw 50vh 0px 0px #FFF, 15vw 15vh 0px 0px #FFF;
    animation: twinkle 7s infinite ease-in-out;
    animation-delay: 2s;
}

/* 升起的光點容器 */
.rising-dots {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    pointer-events: none; /* 讓滑鼠可以穿透 */
}

/* 單個光點樣式 */
.dot {
    position: absolute;
    bottom: -50px; /* 從螢幕外開始 */
    width: 3px;
    height: 3px;
    background-color: white;
    border-radius: 50%;
    box-shadow: 0 0 6px 2px rgba(255, 255, 255, 0.7);
    animation-name: rise-and-twinkle;
    animation-timing-function: linear;
    animation-iteration-count: infinite;
}

[data-bs-theme="dark"] body {
    /* 夜間模式：維持不變 */
    /* 背景已轉移到 #background-container */
}

/* --- 日間模式文字顏色調整 --- */
[data-bs-theme="light"] .navbar-brand,
[data-bs-theme="light"] .navbar .nav-link,
[data-bs-theme="light"] .display-4,
[data-bs-theme="light"] .lead.text-muted {
    color: rgba(255, 255, 255, 0.9) !important;
}

[data-bs-theme="light"] .navbar-toggler-icon {
    background-image: var(--bs-navbar-toggler-icon-bg, url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'%3e%3cpath stroke='rgba%28255, 255, 255, 0.9%29' stroke-linecap='round' stroke-miterlimit='10' stroke-width='2' d='M4 7h22M4 15h22M4 23h22'/%3e%3c/svg%3e"));
}

/* 夜間模式背景 */
[data-bs-theme="dark"] #background-container {
    background-image: linear-gradient(135deg, #0f2027, #203a43, #2c5364);
}

/* --- Layout for Ads --- */
.main-layout-grid {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: start;
    gap: 1rem;
}

.ad-space {
    width: 160px;
    position: sticky;
    top: 80px; /* Navbar height + some margin */
}

.ad-placeholder {
    width: 160px;
    height: 600px;
    background-color: rgba(0,0,0,0.1);
    border: 2px dashed var(--bs-secondary);
    display: grid;
    place-items: center;
    color: var(--bs-secondary-text);
    border-radius: 0.375rem;
}

/* --- Glassmorphism Style --- */
.glass-nav, .glass-card {
    background: rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.3);
}

[data-bs-theme="dark"] .glass-nav,
[data-bs-theme="dark"] .glass-card {
    background: rgba(30, 30, 30, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.glass-nav {
    border-width: 0 0 1px 0;
}

/* 讓卡片和按鈕有更平滑的過渡效果 */
.card, .btn {
    transition: all 0.3s ease-in-out;
}

/* 輸入框樣式 */
#wenyan-input {
    min-height: 120px;
    font-size: 1.1rem;
}

/* 結果區域的列表樣式 */
#ai-response .list-group-item {
    border-left: 0;
    border-right: 0;
}

/* 讓列表項背景透明，以繼承卡片背景，達到視覺統一 */
#ai-response .list-group-item {
    background-color: transparent;
}

/* --- Responsive Design --- */
@media (max-width: 1300px) { /* Widened breakpoint to better accommodate ads */
    .main-layout-grid {
        grid-template-columns: 1fr; /* Stack on smaller screens */
    }
    .ad-space {
        display: none; /* Hide ads on smaller screens */
    }
}

/* --- Old Paper Style for AI Response --- */
#ai-response.glass-card {
    /* Override glass effect with old paper color */
    background: #fdf5e6; /* A warm, light yellow like Old Lace */
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    border: 1px solid #e0dccc; /* A border that fits the theme */
}

[data-bs-theme="dark"] #ai-response.glass-card {
    /* A slightly darker paper for dark mode */
    background: #4a453b;
    border-color: #6b6355;
}

#ai-response .card-body {
    /* Add horizontal lines */
    --line-height-ratio: 1.8;
    --base-font-size: 1rem; /* Corresponds to Bootstrap's default font size */
    --line-height-px: calc(var(--base-font-size) * var(--line-height-ratio));

    background-image: linear-gradient(to bottom, rgba(0, 0, 0, 0.1) 1px, transparent 1px);
    background-size: 100% var(--line-height-px);
    /* Move the background down to align with the bottom of the line */
    background-position: 0 calc(var(--line-height-px) - 1px);
    line-height: var(--line-height-px);
}

/* Adjust text elements to align with the lines */
#ai-response .card-text,
#ai-response .list-group-item {
    line-height: var(--line-height-px);
    padding-top: 0;
    padding-bottom: 0;
    margin-bottom: 0; /* Remove default paragraph margin to prevent misalignment */
}

/* Ensure list items don't have extra borders that break the paper style */
#ai-response .list-group-item,
#ai-response .list-group-flush > .list-group-item {
    border: none;
}

/* Add some space after paragraphs and lists to avoid text crowding */
#ai-response .card-text:not(:last-child),
#ai-response .list-group:not(:last-child) {
    margin-bottom: var(--line-height-px);
}
