/* --- CSS 變數 --- */
:root {
    --font-primary: 'Noto Sans TC', system-ui, -apple-system, sans-serif;
    
    --gradient-primary: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
    
    --color-bg: #f3f4f6;          
    --color-card-bg: #ffffff;     
    --color-text-main: #1f2937;   
    --color-text-sub: #4b5563;    
    --color-accent: #7c3aed;      

    --spacing-unit: 1rem;
    
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --shadow-hover: 0 20px 25px -5px rgba(0, 0, 0, 0.15), 0 10px 10px -5px rgba(0, 0, 0, 0.04);

    --border-radius-lg: 16px;
    --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

*, *::before, *::after { box-sizing: border-box; }

body {
    font-family: var(--font-primary);
    margin: 0;
    background-color: var(--color-bg);
    color: var(--color-text-main);
    line-height: 1.75;
    -webkit-font-smoothing: antialiased;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 var(--spacing-unit);
}

/* --- 頁首 --- */
.site-header {
    background: var(--gradient-primary);
    color: white;
    padding: 4rem 1rem 5rem;
    text-align: center;
    clip-path: ellipse(150% 100% at 50% 0%);
    margin-bottom: 2rem;
    box-shadow: var(--shadow-md);
    transition: padding 0.3s ease;
}

.site-header.compact { padding: 2rem 1rem 3rem; }

.site-header h1 {
    margin: 0;
    font-size: clamp(2rem, 5vw, 3rem);
    font-weight: 800;
    text-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.site-header h2 {
    margin-top: 1rem;
    font-size: 1.1rem;
    opacity: 0.9;
}

.hidden { display: none !important; }

/* --- 方塊網格佈局 (Grid of Blocks) --- */
.blog-posts {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); /* 自動填滿，最小寬度280px */
    gap: 2rem;
    margin-top: -3rem;
    padding-bottom: 4rem;
}

/* --- 卡片方塊設計 --- */
.post-card {
    background-color: var(--color-card-bg);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    transition: var(--transition-smooth);
    display: flex;
    flex-direction: column;
    cursor: pointer; /* 讓使用者知道可以點擊 */
    position: relative;
    height: 100%; /* 讓高度統一 */
}

/* 懸浮效果：整塊浮起 */
.post-card:hover {
    transform: translateY(-8px);
    box-shadow: var(--shadow-hover);
}

.post-image-wrapper {
    position: relative;
    overflow: hidden;
    width: 100%;
    /* 保持 4:3 比例的容器，確保版面整齊 */
    aspect-ratio: 4 / 3; 
    /* 背景改為白色，因為 contain 模式下旁邊會留白 */
    background-color: #ffffff; 
    /* 增加一點內距，讓圖片不要貼邊，像畫框一樣 (可選) */
    padding: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.post-card img {
    width: 100%;
    height: 100%;
    /* 關鍵修改：改為 contain，確保圖片完整顯示不裁切 */
    object-fit: contain; 
    transition: transform 0.6s ease;
}

.post-card:hover img {
    transform: scale(1.05); /* 圖片輕微放大 */
}

.post-content {
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    justify-content: center;
    flex-grow: 1;
    text-align: center; /* 標題置中 */
}

/* 列表模式下的標題 */
.post-content h2 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--color-text-main);
    line-height: 1.4;
    
    /* 限制標題最多顯示 2 行 */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* 在列表模式隱藏內文，只顯示標題 */
.post-content p {
    display: none; 
}

/* --- 單篇文章閱讀模式 --- */
.single-post-container {
    background: white;
    max-width: 900px;
    margin: -3rem auto 3rem;
    padding: 3rem;
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-lg);
    position: relative;
    min-height: 500px;
    animation: fadeIn 0.5s ease;
}

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

.btn-back {
    display: inline-flex;
    align-items: center;
    color: var(--color-text-sub);
    text-decoration: none;
    font-weight: 600;
    margin-bottom: 2rem;
    cursor: pointer;
    transition: color 0.2s;
}

.btn-back:hover { color: var(--color-accent); }

.single-post-header { margin-bottom: 2rem; text-align: center; }

.single-post-header h1 {
    font-size: clamp(1.8rem, 4vw, 2.5rem);
    margin-bottom: 0.5rem;
    color: var(--color-text-main);
}

.single-post-date { color: #9ca3af; font-size: 0.9rem; }

.single-post-image {
    width: 100%;
    max-height: 500px;
    /* 單篇文章內頁也改為完整顯示，避免裁切，但允許一定程度的 cover 如果需要滿版 */
    object-fit: contain; 
    border-radius: 12px;
    margin-bottom: 2.5rem;
    background-color: #f9f9f9; /* 內頁圖片若有留白，給個淡灰底 */
    box-shadow: var(--shadow-md);
}

/* 內文樣式 */
.single-post-content {
    font-size: 1.1rem;
    color: #374151;
    line-height: 1.8;
}

.single-post-content p {
    margin-bottom: 1.5rem;
    display: block; /* 確保在單篇文章模式下顯示 */
}

.single-post-actions {
    margin-top: 3rem;
    padding-top: 2rem;
    border-top: 1px solid #f3f4f6;
    text-align: center;
}

.btn-external {
    display: inline-block;
    background-color: #10b981;
    color: white;
    padding: 0.8rem 2rem;
    border-radius: 50px;
    text-decoration: none;
    font-weight: bold;
    box-shadow: 0 4px 6px rgba(16, 185, 129, 0.3);
    transition: transform 0.2s;
}

.btn-external:hover {
    transform: translateY(-2px);
    background-color: #059669;
}

/* --- 頁尾 --- */
.site-footer {
    text-align: center;
    padding: 3rem 1rem;
    background-color: white;
    color: var(--color-text-sub);
    border-top: 1px solid #e5e7eb;
}

/* --- 動畫 --- */
.fade-in-up {
    opacity: 0;
    transform: translateY(30px);
    transition: opacity 0.6s ease, transform 0.6s ease;
}

.fade-in-up.visible {
    opacity: 1;
    transform: translateY(0);
}