/* ==========================================================================
   Jollen.org main.css — 繁體中文技術文最佳閱讀體驗（可直接替換）
   目標：穩定字重、柔和亮度、舒適行距、清晰層級、向下相容舊站結構
   ========================================================================== */

/* 基礎色票（可依品牌微調） */
:root {
  --bg: #ffffff;
  --fg: #222222;
  --muted: #666666;
  --border: #dddddd;
  --soft-border: #e5e7eb;
  --heading: #111111;
  --link: #0055aa;
  --link-hover: #003d80;
  --accent: #ddad08; /* 舊站金色識別線 */
  --code-bg: #f6f8fa;
  --code-inline-bg: #f2f4f7;
  --quote-bg: #f9f9f9;
}

/* 全站排版基準 */
html {
  font-size: 17px;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  color: var(--fg);
  background-color: var(--bg);
  font-family: "Noto Serif TC", "Source Han Serif TC", "PingFang TC",
               "Heiti TC", "Microsoft JhengHei", serif;
  line-height: 1.75;
  letter-spacing: 0.02em;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* 連結樣式 */
a {
  color: var(--link);
  text-decoration: none;
  transition: color .15s ease, background-color .15s ease, box-shadow .15s ease;
}
a:hover,
a:focus {
  color: var(--link-hover);
  text-decoration: underline;
}
a:focus-visible {
  outline: 2px solid var(--link);
  outline-offset: 2px;
}

/* 標題層級（中文用無襯線，穩定視覺節奏） */
h1, h2, h3, h4, h5, h6 {
  margin: 0;
  color: var(--heading);
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
  font-weight: 600;
  line-height: 1.4;
  letter-spacing: 0.01em;
}
h1 { font-size: 1.8rem; margin: 1.8em 0 0.6em; }
h2 { font-size: 1.4rem; margin: 1.6em 0 0.6em; }
h3 { font-size: 1.2rem; margin: 1.2em 0 0.5em; }
h4 { font-size: 1.05rem; margin: 1.0em 0 0.4em; }

/* 文章文字與段落 */
p { margin: 0.9em 0; }
#article-body { max-width: 720px; margin: 0 auto; }
#article-body p { margin: 0.9em 0; word-break: break-word; }
#article-body h1, #article-body h2, #article-body h3 { margin-top: 1.6em; margin-bottom: 0.8em; }

/* 列表 */
#article-body ul, #article-body ol {
  padding-left: 1.4em;
  margin: 0.8em 0;
}
#article-body li { margin: 0.25em 0; }

/* 圖片與圖說 */
#article-body img {
  max-width: 100%;
  height: auto;
}
#article-body figure {
  margin: 1.2em 0;
}
#article-body figcaption {
  color: var(--muted);
  font-size: 0.9rem;
  margin-top: 0.4em;
  text-align: center;
}

/* 引用區塊 */
#article-body blockquote {
  background: var(--quote-bg);
  border-left: 4px solid #cccccc;
  margin: 1em 0;
  padding: 0.8em 1.2em;
  border-radius: 4px;
  color: #555555;
  font-style: normal;
}

/* 粗體強調 */
strong { color: #000000; font-weight: 600; }

/* 程式碼（等寬字與柔和對比） */
#article-body pre,
pre {
  background: var(--code-bg);
  border: 1px solid var(--soft-border);
  padding: 12px;
  overflow-x: auto;
  border-radius: 6px;
  font-size: 15px;
  line-height: 1.6;
  -webkit-overflow-scrolling: touch;
}
#article-body code,
code {
  background: var(--code-inline-bg);
  border: 1px solid var(--soft-border);
  padding: 0 4px;
  border-radius: 4px;
  font-family: "Source Code Pro", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 15px;
}
pre code {
  background: transparent;
  border: 0;
  padding: 0;
}

/* 表格（文中） */
#article-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 1em 0;
  font-size: 0.98rem;
}
#article-body th, #article-body td {
  border: 1px solid var(--soft-border);
  padding: 8px 10px;
  vertical-align: top;
}
#article-body th {
  background: #f3f4f6;
  text-align: left;
  font-weight: 600;
}

/* 舊站結構對齊（以 table 做版心，加入寬度限制） */
table[width="70%"] {
  max-width: 820px;
  min-width: 680px;
  margin-left: auto;
  margin-right: auto;
}
td[width="90%"][valign="middle"] { vertical-align: middle; }
td[width="100%"][align="left"] { text-align: left; }

/* 舊式 font 標籤細部修正（相容舊內容） */
font[size="-1"] { font-size: 0.875rem; }
font[size="2"]  { font-size: 0.9rem; }

/* 上下分隔線與識別色 */
hr, .rule, #table8 + tr td[bgcolor="#ddad08"] {
  border: 0;
  height: 1px;
  background: var(--border);
}

/* 導覽列與資訊列微調（保留舊站語意） */
#table8 td a { font-weight: 500; }
#table8 td div font a { font-weight: 400; }
#table8 td[align="left"] a { color: var(--link); }

/* 文章標籤區 */
.tags, #article-body .tags, #article-body p b + span {
  color: var(--muted);
  font-size: 0.9rem;
}

/* 頁尾（copyright 區） */
.footer, body > p[align="center"] {
  color: var(--muted);
  font-size: 0.9rem;
}
.footer a, body > p[align="center"] a { color: var(--link); }

/* 互動可用性 */
::selection {
  background: #dbeafe;
  color: #0b1e3b;
}

/* 深色模式（選配，依系統偏好自動切換） */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --fg: #e5e7eb;
    --muted: #a3a3a3;
    --border: #2a2f3a;
    --soft-border: #2a2f3a;
    --heading: #ffffff;
    --link: #82b1ff;
    --link-hover: #a3c5ff;
    --code-bg: #161a20;
    --code-inline-bg: #141821;
    --quote-bg: #141821;
  }
  body { background-color: var(--bg); color: var(--fg); }
  #article-body th { background: #1d2230; }
  a:hover, a:focus { text-decoration: underline; }
}

/* 行動裝置最佳化：維持行長與內距 */
@media (max-width: 900px) {
  table[width="70%"] { width: 92% !important; min-width: 0; max-width: 100%; }
  #article-body { max-width: 92%; }
  html { font-size: 16px; }
}

/* 列印樣式（純黑白、去除底色） */
@media print {
  :root {
    --bg: #ffffff;
    --fg: #000000;
    --border: #cccccc;
  }
  body {
    background: #ffffff;
    color: #000000;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  a { color: #000000; text-decoration: underline; }
  #article-body pre, #article-body code {
    border-color: #cccccc;
    background: #ffffff;
  }
  table[width="70%"] { width: 100% !important; }
}

/* 細節微調（間距、校正） */
small, .small { font-size: 0.875rem; color: var(--muted); }
em { font-style: italic; }
kbd {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  border: 1px solid var(--soft-border);
  background: var(--code-inline-bg);
  padding: 0 4px;
  border-radius: 4px;
  font-size: 0.95em;
}
mark {
  background: #fff3b0;
  padding: 0 2px;
  border-radius: 2px;
}
