/* ============================================================================
   base.css — reset + CJK 排版
   ============================================================================ */

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

html {
  font-size: var(--fs-base);
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);

  /* 拉丁在前：ASCII 用拉丁字型的 metrics（數字、程式碼對齊才會漂亮），
     漢字自動 fallback 到 --font-zh。 */
  font-family: var(--font-latin), var(--font-zh);
  line-height: var(--lh-body);

  line-break: strict;           /* CJK 禁則處理 */
  word-break: normal;
  overflow-wrap: break-word;
  text-spacing-trim: trim-start; /* 漸進增強：修正「」（）的空隙 */
  font-variant-east-asian: traditional;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 {
  font-weight: 650;
  line-height: 1.45;
  margin: 0;
  text-wrap: balance;
}
h1 { font-size: 1.9rem; letter-spacing: -.01em; }
h2 { font-size: 1.42rem; margin-block: 2.4em .7em; }
h3 { font-size: 1.14rem; margin-block: 1.9em .5em; }
h4 { font-size: 1rem; margin-block: 1.5em .4em; color: var(--muted); }

p { margin: 0 0 1.05em; }
ul, ol { margin: 0 0 1.05em; padding-inline-start: 1.6em; }
li { margin-bottom: .4em; }
li > ul, li > ol { margin-top: .4em; }

strong, b { font-weight: 650; }

a {
  color: var(--accent);
  text-underline-offset: .18em;
  text-decoration-thickness: 1px;
}
a:hover { text-decoration-thickness: 2px; }

hr {
  border: 0;
  border-top: 1px solid var(--rule);
  margin: var(--sp-7) 0;
}

/* --- 程式碼 ------------------------------------------------------------ */
code, kbd, samp, pre { font-family: var(--font-mono); }

:not(pre) > code {
  font-size: .875em;
  background: var(--paper-sunken);
  border: 1px solid var(--rule);
  border-radius: 4px;
  padding: .1em .35em;
}

pre {
  font-size: .85rem;
  line-height: 1.65;
  background: var(--paper-sunken);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: var(--sp-4);
  overflow-x: auto;
  margin: 0 0 1.2em;
  tab-size: 2;
}
pre code { background: none; border: 0; padding: 0; font-size: inherit; }

/* --- 表格 -------------------------------------------------------------- */
.table-wrap { overflow-x: auto; margin: 0 0 1.4em; }
table {
  border-collapse: collapse;
  width: 100%;
  font-size: .93rem;
  line-height: 1.6;
}
th, td {
  text-align: left;
  padding: .55em .7em;
  border-bottom: 1px solid var(--rule);
  vertical-align: top;
}
thead th {
  border-bottom: 2px solid var(--rule-strong);
  font-weight: 650;
  white-space: nowrap;
}
tbody tr:hover { background: var(--paper-sunken); }

/* --- 混排：漢字與拉丁之間的 1/4 em -------------------------------------
   沒有瀏覽器會自動插入這個間距，只能自己補。
   注意用 :is() 一次涵蓋所有內嵌拉丁的情境。                              */
:is(.term, .en, abbr, :not(pre) > code) {
  margin-inline: .15em;
}

.term, .en {
  font-family: var(--font-latin);
  letter-spacing: .005em;
  font-feature-settings: "kern" 1;
}

/* 中文內文絕不 justify：CJK + 拉丁混排會在英文詞周圍產生「河流」 */
.prose { max-width: var(--measure); text-align: left; }
.prose > p + p { margin-top: 1.1em; }

/* 螢幕閱讀器 */
.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.skip-link {
  position: absolute;
  left: var(--sp-4); top: -100px;
  z-index: 100;
  background: var(--accent);
  color: var(--accent-ink);
  padding: var(--sp-2) var(--sp-4);
  border-radius: 0 0 var(--radius) var(--radius);
  text-decoration: none;
  transition: top .15s;
}
.skip-link:focus { top: 0; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 3px;
}

img { max-width: 100%; height: auto; }
