/* ==========================================================================
   全域 CSS 變數，便於維護
   ========================================================================== */
:root {
  --header-width: 200px;
  --sidebar-width: 200px;
  --side-gutter: 30px; /* header/sidebar 與內容間距 */
  --top-gap: 5px;
  --content-max-width: 800px;

  --panel-bg: #333;
  --panel-line: #555;
  --accent: #4da6ff;
  --mobile-bar-height: 50px;

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC",
               "PingFang TC", "Microsoft JhengHei", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* ==========================================================================
   基礎排版
   ========================================================================== */
html {
  /* 避免 iOS 由橫向轉回直向時自動放大字體 */
  -webkit-text-size-adjust: 100%;
}

/* 為兩側固定區塊留出空間，並設定基本頁面內距 */
body {
  margin: 0;
  padding-left: calc(var(--header-width) + var(--side-gutter));
  padding-right: calc(var(--sidebar-width) + var(--side-gutter));
  padding-top: 20px;
  box-sizing: border-box;

  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.75; /* 中文閱讀需要較寬鬆的行高 */
  color: #222;
}

/* 版心容器
   （原先寫在 _layouts/default.html 的 inline <style>，移來此處統一管理） */
.container {
  display: flex;
  gap: 30px;
  max-width: 1000px;
  margin: 0 auto;
  padding: 20px;
}

/* 主內容區塊限制寬度並置中，避免被固定側欄視覺上包覆 */
.main-content {
  flex: 3;
  max-width: var(--content-max-width);
  margin: 0 auto;
  padding: 24px;
  box-sizing: border-box;
  background-color: transparent;
  overflow-wrap: break-word; /* 長網址等不可斷字串不會撐破版面 */
}

/* ==========================================================================
   左側 Header（桌機版為固定直向欄）
   ========================================================================== */
.site-header {
  position: fixed;
  top: var(--top-gap); /* 上方距離邊界 5px */
  left: var(--top-gap); /* 最左側距離邊界 5px */
  width: var(--header-width);
  /* 扣掉上下各 5px 的間距，保持滿版。
     行動瀏覽器的 100vh 含網址列高度，dvh 較準，不支援時自動退回 vh */
  height: calc(100vh - (var(--top-gap) * 2));
  height: calc(100dvh - (var(--top-gap) * 2));

  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: flex-start;
  padding: 30px 20px;
  box-sizing: border-box;
  background-color: var(--panel-bg);
  border-radius: 8px;
  z-index: 1000;
}

/* 站名與漢堡按鈕所在的橫列（桌機版只有站名） */
.site-header__bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  margin-bottom: 40px;
}

.site-title a {
  color: #fff;
  font-size: 1.2rem;
  font-weight: bold;
  text-decoration: none;
}

/* 標題與選單維持直向排列 */
.site-nav ul {
  display: flex;
  flex-direction: column;
  gap: 15px;
  list-style: none;
  margin: 0;
  padding: 0;
}

.site-nav a {
  color: #fff;
  text-decoration: none;
}

.site-nav a:hover {
  color: var(--accent);
}

/* 漢堡按鈕：桌機版不需要，僅在手機版顯示 */
.nav-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
  width: 44px; /* 觸控目標建議下限 44x44 */
  height: 44px;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
}

.nav-toggle__bar {
  display: block;
  width: 22px;
  height: 2px;
  background-color: #fff;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

/* 展開時三條線變成叉叉 */
.site-header.is-nav-open .nav-toggle__bar:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}

.site-header.is-nav-open .nav-toggle__bar:nth-child(2) {
  opacity: 0;
}

.site-header.is-nav-open .nav-toggle__bar:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

/* ==========================================================================
   右側 Sidebar（桌機版為固定直向欄）
   ========================================================================== */
.sidebar {
  position: fixed;
  top: var(--top-gap);
  right: var(--top-gap); /* 距離最右側邊界 5px */
  width: var(--sidebar-width); /* 與左側 Header 寬度一致 */
  height: calc(100vh - (var(--top-gap) * 2));
  height: calc(100dvh - (var(--top-gap) * 2));

  padding: 20px 15px;
  box-sizing: border-box;
  background-color: var(--panel-bg);
  color: #fff;
  border-radius: 8px;
  z-index: 1000;

  overflow-y: auto; /* 若內容過多，允許內部單獨垂直捲動 */
}

.sidebar h3 {
  font-size: 1.1rem;
  margin-top: 0;
  margin-bottom: 10px;
  color: var(--accent); /* 標題套用主題藍色 */
}

.sidebar hr {
  border: 0;
  border-top: 1px solid var(--panel-line);
  margin: 15px 0;
}

.sidebar ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.sidebar ul li {
  margin-bottom: 8px;
}

.sidebar a {
  color: #fff;
  text-decoration: none;
}

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

/* 作者頭像
   （原先寫在 _includes/sidebar.html 的 inline style，因 inline 優先級高於樣式表，
     手機版的縮小規則永遠無法生效，故移來此處） */
.avatar-img {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  object-fit: cover;
}

/* ==========================================================================
   內文元素的溢出防護
   ========================================================================== */
.main-content img {
  max-width: 100%;
  height: auto;
}

.main-content pre {
  overflow-x: auto;
  padding: 12px;
  background-color: #f6f8fa;
  border-radius: 6px;
}

.main-content code {
  font-family: var(--font-mono);
  font-size: 0.92em;
}

/* 行內程式碼（不含程式碼區塊內的） */
.main-content :not(pre) > code {
  padding: 0.15em 0.35em;
  background-color: #f0f2f4;
  border-radius: 4px;
}

/* --------------------------------------------------------------------------
   文章插圖

   .shot-compare 用於同一部位、不同對象的並排對照；
   .shot-gallery 用於單一對象的多張補充圖。
   兩者的圖片長寬比落差很大（1.42 ~ 2.52），因此以 aspect-ratio + object-fit
   強制統一比例，避免並排時高低參差。
   -------------------------------------------------------------------------- */
.shot-compare,
.shot-gallery {
  display: grid;
  gap: 14px;
  margin: 20px 0 26px;
}

.shot-compare {
  grid-template-columns: repeat(3, 1fr);
}

.shot-gallery {
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}

.shot {
  margin: 0;
}

.shot img {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border: 1px solid #e2e6ea;
  border-radius: 6px;
  background-color: #f4f6f8;
}

.shot figcaption {
  margin-top: 6px;
  color: #7d858f;
  font-size: 0.84rem;
  text-align: center;
}

/* 表格捲動容器，由 assets/js/site.js 動態包上 */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.main-content table {
  border-collapse: collapse;
  width: 100%;
}

.main-content th,
.main-content td {
  border: 1px solid #ddd;
  padding: 8px 10px;
  text-align: left;
  vertical-align: top;
}

.main-content thead th {
  background-color: #f2f4f6;
}

/* --------------------------------------------------------------------------
   主觀評分表（權重試算）

   表格本體由 Markdown 產生，滑桿與「加權總分」列由 assets/js/site.js 補上。
   -------------------------------------------------------------------------- */
.score-card td,
.score-card th {
  vertical-align: middle;
}

.score-card__weight {
  display: flex;
  align-items: center;
  gap: 8px;
}

.score-card__weight input[type="range"] {
  width: 88px;
  margin: 0;
  accent-color: var(--accent);
}

.score-card__weight output {
  min-width: 1ch;
  color: #555d66;
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
}

/* 加扣分列：不吃權重，直接加到總分上 */
.score-card__bonus-mark {
  color: #8a929c;
  font-size: 0.82rem;
  white-space: nowrap;
}

.main-content .score-card tfoot th,
.main-content .score-card tfoot td {
  border-top: 2px solid var(--accent);
  background-color: #f8fafc;
  font-weight: 600;
}

.main-content .score-card tfoot td.is-best {
  background-color: #eef6ff;
}

.score-card__total {
  display: block;
  font-size: 1.05rem;
  font-variant-numeric: tabular-nums;
}

.score-card td.is-best .score-card__total {
  color: #1a4d80;
}

.score-card__bar {
  display: block;
  height: 6px;
  margin-top: 6px;
  border-radius: 3px;
  background-color: #e6eaee;
  overflow: hidden;
}

.score-card__bar i {
  display: block;
  height: 100%;
  border-radius: 3px;
  background-color: var(--accent);
  transition: width 0.18s ease;
}

.score-card-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin: 10px 0 26px;
}

.score-card-actions__hint {
  margin: 0;
  color: #7d858f;
  font-size: 0.84rem;
}

.score-card-actions__reset {
  padding: 5px 12px;
  border: 1px solid #d7dde3;
  border-radius: 4px;
  background-color: #fbfcfd;
  color: #555d66;
  font-family: inherit;
  font-size: 0.84rem;
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.score-card-actions__reset:hover {
  border-color: var(--accent);
  background-color: #f4f9ff;
}

/* ==========================================================================
   首頁
   ========================================================================== */
.home-hero {
  padding-bottom: 22px;
  margin-bottom: 30px;
  border-bottom: 1px solid #e5e8eb;
}

.home-hero h1 {
  margin: 0 0 10px;
  font-size: 1.8rem;
}

.home-hero__lead {
  margin: 0;
  max-width: 46em;
  color: #555d66;
  font-size: 1.02rem;
}

.home-section {
  margin-bottom: 38px;
}

.home-section h2 {
  margin: 0 0 16px;
  font-size: 1.15rem;
}

/* 分類卡片：篇數與最新文章皆由 site.categories 自動帶入 */
.cat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}

.cat-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 14px 16px;
  border: 1px solid #e2e6ea;
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  background-color: #fbfcfd;
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.cat-card:hover {
  border-color: var(--accent);
  background-color: #f4f9ff;
}

.cat-card__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.cat-card__name {
  color: #1a4d80;
  font-weight: 600;
}

.cat-card__count {
  color: #8a929c;
  font-size: 0.8rem;
  white-space: nowrap;
}

.cat-card__latest {
  color: #7d858f;
  font-size: 0.84rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.home-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.home-list li {
  padding: 10px 0;
  border-bottom: 1px solid #eceff2;
}

.home-list__meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 5px;
  color: #8a929c;
  font-size: 0.82rem;
}

.home-links {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 22px;
  margin: 0;
}

/* ==========================================================================
   標籤與分類文章列表
   ========================================================================== */
.tag {
  display: inline-block;
  padding: 1px 8px;
  border: 1px solid #d6dae0;
  border-radius: 999px;
  background-color: #f4f6f8;
  color: #5a6572;
  font-size: 0.78rem;
  line-height: 1.6;
  white-space: nowrap;
}

/* 文章頁底部的標籤列 */
.post-tags {
  margin-top: 28px;
  padding-top: 16px;
  border-top: 1px solid #e5e8eb;
  font-size: 0.9rem;
  color: #666;
}

/* 依分類分組的文章列表 */
.post-index__group {
  margin-bottom: 34px;
}

.post-index__group h2 {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--accent);
  font-size: 1.15rem;
}

.post-index__count {
  padding: 0 8px;
  border-radius: 999px;
  background-color: #eef1f4;
  color: #6b7480;
  font-size: 0.78rem;
  font-weight: normal;
}

.post-index ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.post-index li {
  padding: 11px 0;
  border-bottom: 1px solid #eceff2;
}

.post-index__link {
  color: #1a4d80;
  text-decoration: none;
  font-weight: 600;
}

.post-index__link:hover {
  color: var(--accent);
  text-decoration: underline;
}

/* 日期與標籤同一行，作為次要資訊 */
.post-index__meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 5px;
  color: #8a929c;
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
}

/* ==========================================================================
   手機與平板版 (螢幕寬度 <= 768px)
   ========================================================================== */

@media (max-width: 768px) {
  body {
    padding-left: 0;
    padding-right: 0;
    /* 留空間給頂部固定導覽列 */
    padding-top: var(--mobile-bar-height);
  }

  .container {
    flex-direction: column;
    gap: 0;
    padding: 15px;
  }

  /* Header 改為頂部固定橫列，選單以下拉面板呈現 */
  .site-header {
    top: 0;
    left: 0;
    width: 100%;
    height: auto; /* 讓下拉面板得以撐開 */
    border-radius: 0;
    padding: 0;
    display: block; /* 取消桌機版的直向 flex */
    z-index: 1200;
  }

  .site-header__bar {
    height: var(--mobile-bar-height);
    margin-bottom: 0;
    padding: 0 15px;
    box-sizing: border-box;
  }

  .nav-toggle {
    display: flex; /* 手機版才顯示漢堡按鈕 */
  }

  /* 選單預設收合，點漢堡後才展開 */
  .site-nav {
    display: none;
    border-top: 1px solid var(--panel-line);
    background-color: var(--panel-bg);
  }

  .site-header.is-nav-open .site-nav {
    display: block;
  }

  .site-nav ul {
    flex-direction: column;
    gap: 0;
  }

  .site-nav a {
    display: block;
    padding: 14px 15px; /* 觸控區高度 >= 44px */
    border-bottom: 1px solid #444;
  }

  .site-nav li:last-child a {
    border-bottom: 0;
  }

  /* 手機版主內容：取消最大寬度限制 */
  .main-content {
    max-width: 100%;
    margin: 0;
    padding: 16px 0 0;
  }

  /* ------------------------------------------------------------------
     側邊欄改造為滿版頁尾

     原先為 display: none，「最新文章」等內容在手機上完全看不到。
     單純改成靜態堆疊又會像一塊掉在底部的浮動面板，因此去圓角、拉成
     貫穿左右的色帶，讓它讀起來就是頁尾。
     ------------------------------------------------------------------ */
  .sidebar {
    position: static;
    width: auto;
    height: auto;
    overflow-y: visible;
    border-radius: 0;
    margin: 40px -15px 0; /* 負值抵銷 .container 的 15px 內距，做出滿版 */
    padding: 26px 20px 30px;

    display: flex;
    flex-direction: column;
  }

  /* 視覺順序改為：最新文章 → 關於作者 → 追蹤我。
     讀完內文先給下一篇，其次才是身分與社群。
     註：依賴 sidebar.html 目前的三個 widget 順序，日後增減需同步調整。 */
  .sidebar .widget:nth-of-type(1) { order: 2; } /* 關於作者 */
  .sidebar .widget:nth-of-type(2) { order: 1; } /* 最新文章 */
  .sidebar .widget:nth-of-type(3) { order: 3; } /* 追蹤我 */

  /* 改用區塊間距與分隔線取代原本的 <hr>（flex 重排後 <hr> 位置會錯亂） */
  .sidebar hr {
    display: none;
  }

  .sidebar .widget {
    margin-top: 22px;
    padding-top: 20px;
    border-top: 1px solid var(--panel-line);
  }

  /* 視覺上的第一塊不需要上分隔線 */
  .sidebar .widget:nth-of-type(2) {
    margin-top: 0;
    padding-top: 0;
    border-top: 0;
  }

  .sidebar h3 {
    font-size: 0.95rem;
    letter-spacing: 0.04em;
    margin-bottom: 4px;
  }

  /* 最新文章：整列可點，觸控區加大 */
  .sidebar ul li {
    margin-bottom: 0;
  }

  .sidebar ul li a {
    display: block;
    padding: 10px 0;
  }

  /* 關於作者：頭像縮小並與簡介同一行 */
  .avatar-img {
    width: 48px;
    height: 48px;
    float: left;
    margin: 6px 12px 8px 0;
  }

  .sidebar .widget:nth-of-type(1)::after {
    content: "";
    display: block;
    clear: both;
  }

  .sidebar .widget:nth-of-type(1) p {
    margin: 6px 0 0;
    font-size: 0.95rem;
    color: #ddd;
  }

  /* 追蹤我：改為行內連結列 */
  .sidebar .widget:nth-of-type(3) ul {
    display: flex;
    flex-wrap: wrap;
    gap: 0 22px;
  }

  /* 寬表格在窄螢幕維持可讀的欄寬，並於容器內橫向捲動 */
  .table-scroll table {
    min-width: 600px;
  }

  /* 插圖改為單欄，避免三張並排在手機上各只剩約 110px 寬而看不清細節 */
  .shot-compare,
  .shot-gallery {
    grid-template-columns: 1fr;
    gap: 18px;
  }

  /* 評分表在 600px 的捲動寬度下，滑桿也要跟著縮短才不會擠掉分數欄 */
  .score-card__weight input[type="range"] {
    width: 62px;
  }
}
