/* ===================================================
   ?? 核心控制中心 (白天/黑夜模式變數)
   =================================================== */
:root {
  --bg-page: #fcfcfc;
  --bg-card: #ffffff;
  --text-main: #222222;
  --text-muted: #555555;
  --text-light: #999999;
  --border-color: #e0e0e0;
  --input-bg: #ffffff;
  --blockquote-bg: #f8f9fa;
  --blockquote-border: #cccccc;
}

[data-theme="dark"] {
  --bg-page: #121212;
  --bg-card: #1e1e1e;
  --text-main: #ffffff;
  --text-muted: #e1e1e6;
  --text-light: #8e8e93;
  --border-color: #333333;
  --input-bg: #2c2c2e;
  --blockquote-bg: #2c2c2e;
  --blockquote-border: #555555;
}

/* 全域平滑轉換 */
body, .article-item, input, .category-btn, .page-btn, .sort-btn {
  transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

body {
  background-color: var(--bg-page);
  margin: 0;
  padding: 40px 20px;
  font-family: -apple-system, BlinkMacSystemFont, sans-serif;
}

/* ?? 寬度放大到 1024px，確保一排 3 張卡片時擁有舒適的呼吸空間 */
.main-container {
  max-width: 1024px;
  margin: 0 auto;
}

.page-title {
  font-size: 1.8rem;
  color: var(--text-main);
  margin-bottom: 32px;
  font-weight: 700;
}

/* 黑夜按鈕 */
.theme-toggle-container { display: flex; justify-content: flex-end; margin-bottom: 12px; }
.theme-btn { background: none; border: 1px solid var(--border-color); background-color: var(--bg-card); padding: 8px 12px; border-radius: 20px; cursor: pointer; font-size: 0.9rem; display: flex; align-items: center; gap: 6px; color: var(--text-main); }
.theme-btn:hover { border-color: #0066cc; }

/* 搜尋框 */
.search-container { position: relative; margin-bottom: 20px; width: 100%; }
.search-container input { width: 100%; padding: 14px 45px 14px 16px; font-size: 1rem; border: 1px solid var(--border-color); border-radius: 8px; background-color: var(--input-bg); color: var(--text-main); box-sizing: border-box; }
.search-container input:focus { outline: none; border-color: #0066cc; }
.clear-btn { position: absolute; right: 16px; top: 50%; transform: translateY(-50%); background: none; border: none; font-size: 1.1rem; color: #999999; cursor: pointer; padding: 4px; }
.no-results { text-align: center; padding: 40px; color: var(--text-muted); font-size: 1.1rem; }

/* 排序與分類 */
.sort-container { display: flex; gap: 16px; margin-bottom: 16px; border-bottom: 1px solid var(--border-color); padding-bottom: 8px; }
.sort-btn { background: none; border: none; color: #86868b; font-size: 0.9rem; font-weight: 500; padding: 4px 8px; cursor: pointer; position: relative; }
.sort-btn.active { color: #0066cc; font-weight: 600; }
.sort-btn.active::after { content: ""; position: absolute; bottom: -9px; left: 0; width: 100%; height: 2px; background-color: #0066cc; }
.categories-container { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 32px; }
.category-btn { background-color: var(--bg-card); color: var(--text-muted); border: 1px solid var(--border-color); padding: 8px 16px; font-size: 0.9rem; font-weight: 500; border-radius: 20px; cursor: pointer; }
.category-btn.active { background-color: #0066cc; color: #ffffff; border-color: #0066cc; font-weight: 600; }

/* ===================================================
   ?? 3+3 響應式卡片網格 (Responsive Cards Grid)
   =================================================== */
.article-list {
  display: grid;
  /* 關鍵：使用 Grid 網格，一排固定 3 欄，間距 24px */
  grid-template-columns: repeat(3, 1fr);
  gap: 24px;
}

.article-item {
  display: flex;
  flex-direction: column; /* ?? 由橫變直：圖片在上，文字在下 */
  background-color: var(--bg-card);
  text-decoration: none;
  color: inherit;
  border-radius: 12px;
  overflow: hidden; /* 確保圖片圓角外溢被裁切 */
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.02);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.article-item:hover {
  transform: translateY(-5px);
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.08);
}

/* 圖片改為填滿卡片上方 */
.article-img {
  width: 100%;
  height: 180px; /* 固定卡片縮圖高度 */
  flex-shrink: 0;
  overflow: hidden;
}

.article-img img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s ease;
}
.article-item:hover .article-img img { transform: scale(1.04); }

/* 卡片文字內部襯距 */
.article-content {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-grow: 1; /* 讓內容自動撐滿 */
}

.article-tag {
  display: inline-block;
  align-self: flex-start;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 4px;
}

.article-title {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text-main);
  margin: 0;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2; /* 標題最多顯示兩行，超出省略，維持卡片整齊 */
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.article-item:hover .article-title { color: #0066cc; }

.article-excerpt {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin: 0;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 3; /* 摘要最多顯示三行，超出省略 */
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.article-date {
  font-size: 0.8rem;
  color: var(--text-light);
  margin-top: auto; /* ?? 關鍵：將日期推到卡片最底部，確保對齊 */
  padding-top: 12px;
}

/* ===================================================
   ?? RWD 響應式斷點設計
   =================================================== */
@media (max-width: 900px) {
  /* 平板尺寸：自動變為一排 2 張卡片 */
  .article-list { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 600px) {
  /* 手機尺寸：自動縮回一排 1 張卡片 (單欄直列) */
  .article-list { grid-template-columns: 1fr; }
  .article-img { height: 200px; } /* 手機版圖片稍微放大更吸睛 */
}

/* 分頁 */
.pagination { display: flex; justify-content: center; align-items: center; gap: 8px; margin-top: 40px; }
.page-btn { border: 1px solid var(--border-color); background-color: var(--bg-card); color: var(--text-main); padding: 8px 16px; font-size: 0.95rem; font-weight: 500; border-radius: 6px; cursor: pointer; }
.page-btn:hover:not(:disabled) { background-color: #f0f0f0; color: #0066cc; }
.page-btn.active { background-color: #0066cc; border-color: #0066cc; color: #ffffff; cursor: default; }
.page-btn:disabled { background-color: #f5f5f5; border-color: var(--border-color); color: #cccccc; cursor: not-allowed; }
