/*
Theme Name: zanzantheme031
Description: 長英文換行及H3標題統一，CSS預載入優化
Version: 31
Author: 贊贊小屋
*/

/* ========================================
   CSS 變數定義 (保持23版穩定結構)
======================================== */
:root {
  --color-primary: #2d2d2d;
  --color-bg: #fff;
  --color-border: #e5e5e5;
  --color-overlay: rgba(0, 0, 0, 0.5);
  --color-accent: #5dac81;
  --color-link: #006666;
  --color-link-hover: #5dac81;
  
  --header-height: 85px;
  --logo-height: 55px;
  --content-max-width: 800px; /* 16版的800px */
  --header-max-width: 960px; /* 保持23版寬度 */
  
  --nav-gap: 25px;
  --font-size-nav: 15px; /* 導航保持15px */
  --font-family: 'Noto Sans TC', '微軟正黑體', sans-serif;
  
  --transition-speed: 0.25s;
  --z-header: 999;
  --z-mobile-nav: 1000;
  --z-overlay: 999;
}

/* ========================================
   基礎重置 (整合16版全站基礎設定)
======================================== */
* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0;
  background-color: #f0f0f0; /* 16版淺灰底 */
  font-family: var(--font-family);
  color: var(--color-primary);
  font-size: 17px; /* 16版字體大小 */
  line-height: 1.85; /* 16版行高 */
  letter-spacing: 0.02em; /* 16版字距 */
}

/* 內容連結使用16版樣式 */
.site-content a {
  color: var(--color-link); /* 16版連結顏色 */
  text-decoration: none;
  transition: color var(--transition-speed) ease-in-out;
}

.site-content a:hover {
  color: var(--color-link-hover); /* 16版懸停顏色 */
  text-decoration: underline;
}

/* 圖片響應式基礎設定 */
img {
  max-width: 100%;
  height: auto;
  vertical-align: middle;
}

/* ========================================
   Header 樣式 (修正間距合併問題)
======================================== */
.site-header {
  background-color: #ffffff; /* 16版白色背景 */
  border-bottom: 1px solid #e5e5e5; /* 16版邊框顏色 */
  padding: 15px 0 10px; /* 減少底部padding，總間距15px */
  width: 100%;
  position: sticky;
  top: 0;
  z-index: var(--z-header);
  transition: box-shadow var(--transition-speed);
  margin-bottom: 0; /* 確保沒有額外margin */
}

.site-header.scrolled {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

/* 恢復23版的完美置中頁首佈局 */
.header-container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  max-width: var(--header-max-width); /* 使用23版的960px */
  margin: 0 auto;
  padding: 0 20px;
  min-height: 85px; /* 確保高度一致 */
}

/* ========================================
   Logo 樣式
======================================== */
.site-logo {
  flex-shrink: 0;
  text-align: center; /* 16版置中 */
  margin-bottom: 0;
}

.site-logo a {
  display: block;
  line-height: 0;
}

.site-logo-img {
  height: var(--logo-height);
  width: auto;
  display: block;
}

/* ========================================
   導覽列基礎樣式 (保持23版穩定結構)
======================================== */
.primary-menu,
.mobile-menu {
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: var(--font-size-nav); /* 使用15px字體 */
}

.primary-menu a,
.mobile-menu a {
  text-decoration: none;
  color: var(--color-primary);
  transition: opacity var(--transition-speed);
  font-weight: 500; /* 16版字重 */
  letter-spacing: normal; /* 導航無字距 */
}

/* ========================================
   桌機版導覽 (保持23版穩定結構 + 防止換行)
======================================== */
.desktop-nav {
  display: none;
}

.primary-menu {
  display: flex;
  gap: var(--nav-gap);
  flex-direction: row;
  text-align: center;
  margin: 0 auto;
  flex-wrap: nowrap; /* 防止換行 */
  white-space: nowrap; /* 防止文字換行 */
}

.primary-menu li {
  display: inline-block;
  white-space: nowrap; /* 防止文字換行 */
  flex-shrink: 0; /* 防止收縮 */
}

.primary-menu a {
  position: relative;
  padding: 10px 0; /* 調整內邊距 */
  color: var(--color-primary);
  font-weight: 500;
  white-space: nowrap; /* 防止文字換行 */
  display: block;
}

.primary-menu a:hover,
.primary-menu a:focus {
  opacity: 0.7;
  text-decoration: none;
}

/* ========================================
   手機版選單按鈕（漢堡）- 保持23版穩定結構
======================================== */
.mobile-menu-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  background: transparent;
  border: none;
  cursor: pointer;
  z-index: calc(var(--z-mobile-nav) + 1);
}

.hamburger-icon {
  width: 24px;
  height: 18px;
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.hamburger-icon .line {
  width: 100%;
  height: 2px;
  background-color: var(--color-primary);
  transition: all var(--transition-speed);
}

.mobile-menu-toggle:hover .line,
.mobile-menu-toggle:focus .line {
  background-color: #666;
}

/* 選單開啟時的動畫 */
.mobile-menu-open .mobile-menu-toggle .line:nth-child(1) {
  transform: translateY(8px) rotate(45deg);
}

.mobile-menu-open .mobile-menu-toggle .line:nth-child(2) {
  opacity: 0;
}

.mobile-menu-open .mobile-menu-toggle .line:nth-child(3) {
  transform: translateY(-8px) rotate(-45deg);
}

/* ========================================
   手機版滑出選單 - 保持23版穩定結構
======================================== */
.mobile-navigation {
  position: fixed;
  top: 0;
  right: -100%;
  width: 280px;
  height: 100vh;
  background: var(--color-bg);
  z-index: var(--z-mobile-nav);
  padding: 80px 30px 30px;
  overflow-y: auto;
  transition: right var(--transition-speed);
  box-shadow: -2px 0 8px rgba(0, 0, 0, 0.1);
}

.mobile-navigation.active {
  right: 0;
}

.mobile-nav-header {
  position: absolute;
  top: 15px;
  right: 15px;
}

.mobile-menu-close {
  width: 44px;
  height: 44px;
  background: transparent;
  border: none;
  font-size: 32px;
  line-height: 1;
  cursor: pointer;
  color: var(--color-primary);
  display: flex;
  align-items: center;
  justify-content: center;
}

.mobile-menu {
  flex-direction: column;
  gap: 0;
  display: flex;
}

.mobile-menu li {
  border-bottom: 1px solid var(--color-border);
}

.mobile-menu a {
  display: block;
  padding: 15px 0;
  font-size: 16px;
  color: var(--color-primary);
}

.mobile-menu a:hover {
  color: var(--color-accent);
}

/* ========================================
   手機版選單遮罩 - 保持23版穩定結構
======================================== */
.mobile-nav-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100vh;
  background: var(--color-overlay);
  z-index: calc(var(--z-mobile-nav) - 1);
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--transition-speed), visibility var(--transition-speed);
}

.mobile-nav-overlay.active {
  opacity: 1;
  visibility: visible;
}

/* 防止背景滾動 */
body.mobile-menu-open {
  overflow: hidden;
}

/* ========================================
   主內容區域 (修正間距合併問題)
======================================== */
.site-content {
  max-width: var(--content-max-width); /* 16版的800px */
  margin: 5px auto 0; /* 大幅減少margin-top，從20px改為5px */
  padding: 40px 35px; /* 16版的內邊距 */
  background-color: #f0f0f0; /* 16版的淺灰背景 */
  border-radius: 6px; /* 16版的圓角 */
  box-sizing: border-box;
}

article {
  background-color: #f0f0f0; /* 16版的淺灰背景 */
}

/* ========================================
   標題樣式 (整合16版自然字重設計)
======================================== */
h1 {
  font-size: 30px;
  font-weight: 500; /* 16版自然字重 */
  color: #222;
  margin: 25px 0 20px 0; /* 16版的外邊距 */
  line-height: 1.4;
  letter-spacing: 0.02em;
}

h2 {
  border-left: 10px solid #5dac81; /* 16版綠色邊框 */
  background: #f9f9f9; /* 16版背景色 */
  padding: 12px 10px; /* 16版的內邊距 */
  margin: 25px 0 20px 0; /* 16版的外邊距 */
  font-size: 23px;
  font-weight: normal; /* 16版自然字重 */
  color: #222;
  box-sizing: border-box;
  letter-spacing: 0.02em;
  line-height: 1.6;
}

h3 {
  font-size: 19px;
  font-weight: normal; /* 16版自然字重 */
  margin-top: 20px;
  color: #333;
}

/* ========================================
   表格樣式 (整合16版設計)
======================================== */
table {
  width: 100%;
  border-collapse: collapse;
  margin: 25px 0; /* 16版外邊距 */
  background-color: #fff;
}

th, td {
  border: 1px solid #ddd;
  padding: 10px; /* 16版內邊距 */
  text-align: left;
  line-height: 1.7; /* 16版行高 */
}

th {
  background-color: #f2f2f2; /* 16版背景色 */
}

/* ========================================
   圖片樣式 (整合16版精緻設計)
======================================== */
.site-content img {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 25px auto; /* 16版外邊距 */
  padding: 0;
  border: 1px solid #d8d8d8; /* 16版邊框 */
  border-radius: 3px; /* 16版圓角 */
  box-shadow: 0 1px 3px rgba(0,0,0,0.05); /* 16版陰影 */
  background-color: transparent; /* 16版透明背景 */
}

.site-content img.aligncenter {
  margin-left: auto;
  margin-right: auto;
}

.site-content img.alignleft {
  float: left;
  margin-right: 25px; /* 16版外邊距 */
  margin-left: 5px; /* 16版外邊距 */
}

.site-content img.alignright {
  float: right;
  margin-left: 25px; /* 16版外邊距 */
  margin-right: 5px; /* 16版外邊距 */
}

/* ========================================
   頁尾樣式 (整合16版設計)
======================================== */
.site-footer {
  text-align: center;
  padding: 20px; /* 16版內邊距 */
  font-size: 14px; /* 16版字體大小 */
  color: #666; /* 16版文字顏色 */
  background: #f5f5f5; /* 16版背景色 */
  border-top: 1px solid #e0e0e0; /* 16版邊框 */
}

/* ========================================
   手機版斷點 (≤ 768px) - 保持23版穩定結構
======================================== */
@media (max-width: 768px) {
  
  /* 強制隱藏桌機版導覽 */
  .desktop-nav,
  .site-navigation {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
  }
  
  /* Header 布局 */
  .header-container {
    position: relative;
    justify-content: center;
  }
  
  /* Logo 置中 */
  .site-logo {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
  }
  
  /* 漢堡按鈕固定在右側 */
  .mobile-menu-toggle {
    position: absolute;
    right: 10px;
    display: flex !important;
  }
  
  /* 手機版內容調整 */
  .site-content {
    margin: 5px auto; /* 保持小間距 */
    padding: 20px;
  }
  
  h1 {
    font-size: 26px;
  }
  
  h2 {
    font-size: 20px;
  }
}

/* ========================================
   平板斷點調整 (768px - 900px)
======================================== */
@media (min-width: 769px) and (max-width: 900px) {
  
  .primary-menu {
    gap: 15px;
    font-size: 14px;
  }
  
}

/* ========================================
   桌機版斷點 - 確保導航正常顯示
======================================== */
@media (min-width: 769px) {
  .desktop-nav {
    display: block !important;
  }
  
  .mobile-menu-toggle,
  .mobile-navigation,
  .mobile-nav-overlay {
    display: none !important;
  }
}

/* ========================================
   防止 WordPress 區塊導覽干擾
======================================== */
.wp-block-navigation,
.wp-block-navigation__responsive-container,
.wp-block-navigation__responsive-container-open,
.wp-block-navigation__responsive-container-close,
.wp-block-navigation__container {
  display: none;
  visibility: hidden;
  opacity: 0;
  height: 0;
  overflow: hidden;
  pointer-events: none;
}

/* ========================================
   列印樣式
======================================== */
@media print {
  
  .site-header,
  .mobile-menu-toggle,
  .mobile-navigation,
  .mobile-nav-overlay {
    display: none;
  }
  
}

/* ========================================
   25版 - 最新文章區塊樣式
   ======================================== */

/* 最新文章容器 */
.recent-posts {
  margin: 40px 0;
  padding: 25px;
  background: #f9f9f9;
  border-radius: 8px;
  border-left: 4px solid #5dac81;
}

.recent-posts h3 {
  font-size: 20px;
  font-weight: 500;
  color: #2d2d2d;
  margin: 0 0 20px 0;
  padding: 0;
  border: none;
  background: none;
}

/* 最新文章列表 - 去掉圓點 */
.recent-posts-list {
  list-style: none; /* 移除列表樣式 */
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ========================================
   25版 - 最新文章樣式調整
   ======================================== */

/* 去掉最新文章列表圓點 */
.recent-posts ul {
  list-style: none;
  padding-left: 0;
}

/* 最新文章標題改為一般段落樣式 */
.recent-posts-title {
  font-size: 18px;
  font-weight: 500;
  color: #2d2d2d;
  margin: 0 0 15px 0;
  padding: 0;
  border: none;
  background: none;
}

/* ========================================
   26版 - 永久修復偽元素顯示 "mobile" 問題
   ======================================== */

/* 強制清除任何可能的偽元素內容 */
*::before,
*::after {
  content: none !important;
  display: none !important;
}

/* ========================================
   贊贊小屋小卡片模板
   ======================================== */

.zan-card-wrap {
  width: 92%;
  max-width: 900px;
  margin: 30px auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 18px;
}

.zan-card {
  background: #ffffff;
  border: 1px solid #e5e5e5;
  border-radius: 14px;
  padding: 18px 20px;
  box-shadow: 0 3px 10px rgba(0,0,0,0.06);
  transition: transform .2s, box-shadow .2s;
}

.zan-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 5px 18px rgba(0,0,0,0.1);
}

.zan-card h3 {
  margin: 0 0 10px;
  font-size: 17px;
  color: #333;
}

.zan-card p {
  margin: 0;
  font-size: 15px;
  line-height: 1.6;
  color: #555;
}

/* ========================================
   031避免長英文造成頁面橫向滾動
======================================== */
/* CLS 安全版：只針對內容區，避免 Layout Shift */
@media (max-width: 768px){

  /* 不影響布局高度，只防止橫向撐破 */
  html, body {
    overflow-x: clip; /* 與 Critical CSS 保持一致 */
    width: 100%; /* 確保寬度不會超出 */
    max-width: 100%; /* 防止任何元素超出視口 */
  }

  /* 只限定內容區，不動 header/footer */
  main#content {
    overflow-wrap: anywhere;
    word-break: break-word;
    max-width: 100%; /* 確保內容不會超出 */
    box-sizing: border-box; /* 包含 padding 在寬度內 */
  }

  main#content p,
  main#content li,
  main#content span {
    overflow-wrap: anywhere;
    word-break: break-word;
    white-space: normal;
    max-width: 100%; /* 確保文本元素不會超出 */
  }

  /* 特別針對可能造成問題的元素 */
  .site-content img,
  .site-content iframe,
  .site-content table {
    max-width: 100% !important;
    height: auto;
  }

}
