/* ==========================================================================
   Scrilab Base — reset、排版、無障礙、全域護欄
   依賴 tokens.css，必須在其之後載入。
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Reset
   -------------------------------------------------------------------------- */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  /* 修正既有 bug：fixed navbar 會蓋住錨點目標 */
  scroll-padding-top: calc(var(--nav-h) + var(--sp-4));
  /* 捲軸配色，避免深色頁面配亮色捲軸 */
  color-scheme: dark;
}

body {
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  font-weight: var(--fw-normal);
  line-height: var(--lh-relax);
  letter-spacing: var(--ls-cjk);
  color: var(--text-mid);
  background: var(--bg-base);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
  min-height: 100vh;
}

img,
picture,
video,
canvas,
svg {
  display: block;
  max-width: 100%;
}

/* <picture> 只是容器，尺寸與樣式都掛在裡面的 <img> 上，
   讓它完全貼合子元素，才不會在圖片外多出一層有高度差的盒子 */
picture {
  display: contents;
}

img,
video {
  height: auto;
}

input,
button,
textarea,
select {
  font: inherit;
  color: inherit;
  letter-spacing: inherit;
}

button {
  background: none;
  border: none;
  cursor: pointer;
}

ul,
ol {
  list-style: none;
}

table {
  border-collapse: collapse;
  border-spacing: 0;
}

/* 避免長字串（UUID、URL）撐破版面 */
p,
li,
dd,
h1, h2, h3, h4, h5, h6 {
  overflow-wrap: break-word;
}

/* --------------------------------------------------------------------------
   2. 排版
   中文行高比西文高、字距略開；西文大標則收緊字距。
   -------------------------------------------------------------------------- */
h1, h2, h3, h4, h5, h6 {
  color: var(--text-hi);
  font-weight: var(--fw-semi);
  line-height: var(--lh-tight);
  letter-spacing: var(--ls-tight);
  text-wrap: balance;  /* 標題斷行更平均（漸進增強） */
}

h1 { font-size: var(--fs-4xl); }
h2 { font-size: var(--fs-3xl); }
h3 { font-size: var(--fs-2xl); }
h4 { font-size: var(--fs-xl); }
h5 { font-size: var(--fs-lg); }
h6 { font-size: var(--fs-base); }

p {
  text-wrap: pretty;  /* 避免單字孤行 */
}

strong, b { font-weight: var(--fw-semi); color: var(--text-hi); }
em, i     { font-style: italic; }
small     { font-size: var(--fs-sm); }

a {
  color: var(--accent);
  text-decoration: none;
  transition: color var(--dur-fast) var(--ease-out);
}

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

code, kbd, samp, pre {
  font-family: var(--font-mono);
  font-size: 0.9em;
  letter-spacing: 0;
}

:where(p, li, td) > code {
  background: var(--bg-sunken);
  border: 1px solid var(--line-subtle);
  border-radius: var(--r-sm);
  padding: 0.15em 0.4em;
  color: var(--accent-hi);
}

hr {
  border: none;
  height: 1px;
  background: var(--line);
  margin: var(--sp-8) 0;
}

/* 長文區塊：限制行寬到 68ch，中文長文可讀性關鍵 */
.prose {
  max-width: var(--prose-max);
  line-height: var(--lh-relax);
}

.prose > * + * { margin-top: var(--sp-4); }
.prose h2      { margin-top: var(--sp-12); }
.prose h3      { margin-top: var(--sp-8); }
.prose ul,
.prose ol      { padding-left: var(--sp-6); }
.prose ul li   { list-style: disc; }
.prose ol li   { list-style: decimal; }
.prose li + li { margin-top: var(--sp-2); }

/* --------------------------------------------------------------------------
   3. 版面容器
   -------------------------------------------------------------------------- */
.wrap {
  max-width: var(--wrap-max);
  margin: 0 auto;
  background: var(--bg-surface);
  border-left: 1px solid var(--line-subtle);
  border-right: 1px solid var(--line-subtle);
  min-height: 100vh;
  position: relative;
  /* 導覽列是 fixed，內容必須讓開 */
  padding-top: var(--nav-h);
}

/* Hero 若要延伸到半透明導覽列底下，自行抵銷 padding */
.wrap > main > .hero:first-child {
  margin-top: calc(var(--nav-h) * -1);
  padding-top: var(--nav-h);
}

.container {
  max-width: var(--content-max);
  margin: 0 auto;
  padding-inline: var(--sp-8);
}

.section {
  padding-block: var(--sp-24);
}

.section--tight { padding-block: var(--sp-16); }
.section--alt   { background: var(--bg-base); }

/* --------------------------------------------------------------------------
   4. 無障礙
   -------------------------------------------------------------------------- */

/* 統一 focus ring — 只在鍵盤操作時顯示，滑鼠點擊不出現 */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

:focus:not(:focus-visible) {
  outline: none;
}

/* 螢幕閱讀器專用（視覺隱藏但可被讀取） */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* 跳到主要內容 — Tab 第一下就會出現 */
.skip-link {
  position: absolute;
  top: var(--sp-2);
  left: var(--sp-2);
  z-index: calc(var(--z-nav) + 1);
  background: var(--accent);
  color: var(--text-inverse);
  font-weight: var(--fw-semi);
  font-size: var(--fs-sm);
  padding: var(--sp-3) var(--sp-5);
  border-radius: var(--r);
  transform: translateY(-200%);
  transition: transform var(--dur-fast) var(--ease-out);
}

.skip-link:focus-visible {
  transform: translateY(0);
  color: var(--text-inverse);
}

/* 捲軸 */
::-webkit-scrollbar        { width: 10px; height: 10px; }
::-webkit-scrollbar-track  { background: var(--bg-base); }
::-webkit-scrollbar-thumb  {
  background: var(--line-strong);
  border-radius: var(--r-full);
  border: 2px solid var(--bg-base);
}
::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, .28); }

/* 選取 */
::selection {
  background: var(--accent-dim);
  color: var(--text-hi);
}

/* --------------------------------------------------------------------------
   5. 全域動效護欄
   使用者若在系統設定關閉動畫，全站必須立即安靜下來。
   -------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }

  html { scroll-behavior: auto; }
}

/* --------------------------------------------------------------------------
   6. 工具類（節制使用，不做 utility framework）
   -------------------------------------------------------------------------- */
.text-hi   { color: var(--text-hi); }
.text-mid  { color: var(--text-mid); }
.text-lo   { color: var(--text-lo); }
.text-accent { color: var(--accent); }

.mono      { font-family: var(--font-mono); }
.nowrap    { white-space: nowrap; }
.center    { text-align: center; }

.stack     { display: flex; flex-direction: column; }
.row       { display: flex; align-items: center; }
.gap-2     { gap: var(--sp-2); }
.gap-3     { gap: var(--sp-3); }
.gap-4     { gap: var(--sp-4); }
.gap-6     { gap: var(--sp-6); }

.hidden    { display: none !important; }

/* --------------------------------------------------------------------------
   7. 響應式
   斷點：480 / 768 / 1024 / 1280
   -------------------------------------------------------------------------- */
@media (max-width: 1024px) {
  :root {
    --fs-5xl: 3rem;
    --fs-4xl: 2.5rem;
    --fs-3xl: 2rem;
  }

  .section { padding-block: var(--sp-20); }
}

@media (max-width: 768px) {
  :root {
    --fs-5xl: 2.5rem;
    --fs-4xl: 2rem;
    --fs-3xl: 1.625rem;
    --fs-2xl: 1.375rem;
    --nav-h: 60px;
  }

  .container { padding-inline: var(--sp-5); }
  .section   { padding-block: var(--sp-16); }

  .wrap {
    border-left: none;
    border-right: none;
  }
}

@media (max-width: 480px) {
  .container { padding-inline: var(--sp-4); }
  .section   { padding-block: var(--sp-12); }
}
