/* ===== 胖打注音官網共用版面（issue 1895）=====
   色彩只用 shared/panda.css 的 --pz-*；字型只用 shared/panda-fonts.css 的 --font-brand／--font-body。
   site- 開頭的元件只定義在這裡；頁面專屬樣式寫在各頁 CSS。
   字級走 1rem × 1.2ⁿ（0.833／1.2／1.44／1.728／2.074／2.488／2.986）；漢字不加字距、不寫 uppercase；粉圓只用原字重。 */

:root {
  --space-xs: 0.5rem;
  --space-sm: 1rem;
  --space-md: 1.5rem;
  --space-lg: 2.5rem;
  --space-xl: 4rem;
  --space-2xl: 6rem;
  --max-width: 64rem;

  --shadow-sm: 0 1px 3px color-mix(in srgb, var(--pz-ink) 6%, transparent);
  --shadow-md: 0 4px 12px color-mix(in srgb, var(--pz-ink) 8%, transparent);
  --shadow-hover: 0 8px 24px color-mix(in srgb, var(--pz-ink) 12%, transparent);

  --site-header-h: calc(3.5rem + 1px); /* .site-header-inner 高＋下邊線 */
  --site-subbar-h: 3.25rem;
  --site-sticky-top: var(--site-header-h);
  --site-beat: calc(1rem * 1.8); /* 內文一行高，垂直間距以此為單位（T-18） */
  --site-measure: 40em; /* 長文行長上限，約 40 個全形字 */
}
[data-theme="dark"] {
  --shadow-sm: 0 1px 3px color-mix(in srgb, var(--pz-ink) 40%, transparent);
  --shadow-md: 0 4px 12px color-mix(in srgb, var(--pz-ink) 55%, transparent);
  --shadow-hover: 0 8px 24px color-mix(in srgb, var(--pz-ink) 70%, transparent);
}
/* 頁首下方還有黏性列（說明書窄螢幕）時，錨點與黏性元件一起讓開 */
@media (max-width: 959px) {
  :root:has(.site-subbar) { --site-sticky-top: calc(var(--site-header-h) + var(--site-subbar-h)); }
}

/* --- 基底 --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; background: var(--pz-bg); }
body {
  font-family: var(--font-body); font-size: 1rem; line-height: 1.8;
  color: var(--pz-text); background: var(--pz-bg);
  overflow-x: hidden; transition: opacity 0.5s ease;
}
html[data-lang="en"] body { line-height: 1.7; }
.js-loading body { opacity: 0; }
.ph { vertical-align: -0.125em; }
:focus-visible { outline: 2px solid var(--pz-text); outline-offset: 2px; }
[id] { scroll-margin-top: calc(var(--site-sticky-top) + var(--space-sm)); }
.container { max-width: var(--max-width); margin: 0 auto; padding: 0 var(--space-md); }
/* 同一格輪流換內容（例：拼寫規則、聲調說明）：全部疊在同一格，格高＝最長那則，切換時下方不跳；只有 [data-current] 看得到 */
.site-stack { display: grid; }
.site-stack > * { grid-area: 1 / 1; visibility: hidden; }
.site-stack > [data-current] { visibility: visible; }
/* 臺羅／白話字：系統字 SF 沒有 U+030D 等組合符號，字母與符號要同一套字型才接得上，一律用粉圓（測試 test_website_tailo） */
.tailo { font-family: var(--font-brand); }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
}

/* --- 頁首 --- */
.site-header {
  position: sticky; top: 0; z-index: 100;
  border-bottom: 1px solid var(--pz-border-light);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  background: color-mix(in srgb, var(--pz-bg) 85%, transparent);
}
.site-header-inner {
  max-width: var(--max-width); height: 3.5rem; margin: 0 auto; padding: 0 var(--space-md);
  display: flex; align-items: center; gap: var(--space-md);
}
.site-logo {
  display: flex; align-items: center; gap: 0.5rem; flex: none;
  font-family: var(--font-brand); font-size: 1.2rem; color: var(--pz-text);
  text-decoration: none; white-space: nowrap;
}
.site-logo img { width: 28px; height: 28px; border-radius: 6px; }
.site-logo-icon-dark { display: none; }
[data-theme="dark"] .site-logo-icon-light { display: none; }
[data-theme="dark"] .site-logo-icon-dark { display: block; }
.site-nav { display: flex; gap: var(--space-md); margin-left: auto; }
.site-nav a { color: var(--pz-text-secondary); text-decoration: none; white-space: nowrap; transition: color 0.2s; }
.site-nav a:hover, .site-nav a[aria-current="page"] { color: var(--pz-text); }
.site-controls { display: flex; align-items: center; gap: var(--space-sm); flex: none; }
.lang-switcher { display: inline-flex; align-items: center; gap: 0.3em; font-size: 0.833rem; }
.lang-switcher button {
  font: inherit; background: none; border: none; cursor: pointer;
  padding: 0.25em 0.4em; color: var(--pz-text-secondary); opacity: 0.5;
  transition: opacity 0.15s, color 0.15s;
}
.lang-switcher button.active { opacity: 1; color: var(--pz-text); }
.lang-switcher button:hover { opacity: 1; }
.lang-switcher .divider { color: var(--pz-text-secondary); opacity: 0.4; }
.site-header-btn {
  width: 2.25rem; height: 2.25rem; border-radius: 6px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.2rem; background: none; border: 1px solid var(--pz-border); color: var(--pz-text-secondary);
  transition: color 0.2s, border-color 0.2s;
}
.site-header-btn:hover { color: var(--pz-text); border-color: var(--pz-text-secondary); }

/* 窄螢幕：品牌名只留圖示，導覽與控制項同一列不換行 */
@media (max-width: 720px) {
  .site-header-inner { gap: var(--space-sm); padding: 0 var(--space-sm); }
  .site-logo-text { display: none; }
  .site-nav { gap: var(--space-sm); }
  .site-controls { gap: var(--space-xs); }
}

/* --- 頁尾 --- */
.site-footer { border-top: 1px solid var(--pz-border-light); padding: var(--space-lg) 0; }
.site-footer-inner {
  max-width: var(--max-width); margin: 0 auto; padding: 0 var(--space-md);
  display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center;
  gap: var(--space-sm) var(--space-md);
}
.site-footer-copyright { font-size: 0.833rem; color: var(--pz-text-secondary); }
.site-footer-links, .site-footer-social { display: flex; flex-wrap: wrap; gap: var(--space-xs) var(--space-md); }
.site-footer-links a, .site-footer-social a {
  font-size: 0.833rem; color: var(--pz-text-secondary); text-decoration: none; transition: color 0.2s;
}
.site-footer-social a { display: inline-flex; font-size: 1.2rem; }
.site-footer-links a:hover, .site-footer-social a:hover { color: var(--pz-text); }
@media (max-width: 720px) {
  .site-footer-inner { flex-direction: column; text-align: center; }
  .site-footer-links { justify-content: center; }
}

/* 頁尾與最後一段同一面時不畫線，只靠段間距分（首頁 issue 1937） */
.site-footer-flush .site-footer { border-top: 0; padding-top: 0; }

/* --- 墨帶（issue 1937）：整段換成墨面。淺色模式＝墨；深色模式＝墨上一階（neutral-2），不反轉成亮帶。
   帶內把語義色換成深底取值，內文、連結、焦點框自動跟著走 --- */
.site-ink {
  --pz-bg: var(--pz-ink);
  --pz-text: var(--pz-paper);
  --pz-text-secondary: var(--pz-neutral-5);
  --pz-border: var(--pz-neutral-3);
  --pz-border-light: var(--pz-neutral-2);
  --pz-bg-card: var(--pz-neutral-2);
  --pz-bg-alt: var(--pz-neutral-2);
  background: var(--pz-bg);
  color: var(--pz-text);
}
:root[data-theme="dark"] .site-ink {
  --pz-bg: var(--pz-neutral-2);
  --pz-border: var(--pz-neutral-4);
  --pz-border-light: var(--pz-neutral-3);
  --pz-bg-card: var(--pz-neutral-3);
  --pz-bg-alt: var(--pz-neutral-3);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .site-ink {
    --pz-bg: var(--pz-neutral-2);
    --pz-border: var(--pz-neutral-4);
    --pz-border-light: var(--pz-neutral-3);
    --pz-bg-card: var(--pz-neutral-3);
    --pz-bg-alt: var(--pz-neutral-3);
  }
}

/* --- 切換鈕（issue 1937 自說明書提升）：一組兩三個選項、button＋aria-pressed。
   說明書的佈局／介音位置／鍵盤外觀、首頁的鍵盤語言／佈局／打法都用這一個 --- */
.site-seg {
  display: inline-flex; padding: 3px; gap: 2px;
  border: 1px solid var(--pz-border); border-radius: 999px; background: var(--pz-bg-card);
}
.site-seg button {
  font: inherit; font-size: 0.833rem; border: 0; border-radius: 999px; cursor: pointer;
  padding: 0.35rem 1rem; background: transparent; color: var(--pz-text-secondary);
  white-space: nowrap;
}
/* 全站佈局偏好寫在 <html data-manual-layout>（首頁與說明書共用，head 首繪前設定）：
   腳本同步 aria-pressed 之前就亮對的那顆；只給某佈局看的內容帶 data-show。沒有 JS 時是九宮格 */
html:not([data-manual-layout="classic"]) [data-manual-layout-set="grid"],
html[data-manual-layout="classic"] [data-manual-layout-set="classic"],
.site-seg button[aria-pressed="true"] {
  background: var(--pz-text); color: var(--pz-bg);
}
html:not([data-manual-layout="classic"]) [data-show="classic"],
html[data-manual-layout="classic"] [data-show="grid"] { display: none; }

/* --- 欄網格：手機 4、平板 8、桌面 12（CIS 版面欄數）；子元素預設跨滿 --- */
.site-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); column-gap: var(--space-md); }
.site-grid > * { grid-column: 1 / -1; }
@media (min-width: 721px) {
  .site-grid { grid-template-columns: repeat(8, minmax(0, 1fr)); }
}
@media (min-width: 960px) {
  .site-grid { grid-template-columns: repeat(12, minmax(0, 1fr)); align-items: start; }
  .site-grid > .site-sidebar { grid-column: 1 / span 3; }
  .site-grid > .site-main { grid-column: 1 / span 8; } /* 內容欄與頁首標誌同一條左緣 */
}

/* --- 側欄（≥960）／黏性列（<960）：同一個 nav，頁面 CSS 決定裡面放什麼 --- */
.site-sidebar {
  position: sticky; top: var(--site-sticky-top);
  max-height: calc(100svh - var(--site-sticky-top)); overflow-y: auto;
  padding: var(--space-lg) var(--space-sm) var(--space-lg) 0;
}
.site-subbar { display: flex; flex-direction: column; align-items: flex-start; gap: var(--space-xs); margin-bottom: var(--space-md); }
@media (max-width: 959px) {
  .site-sidebar { position: static; max-height: none; overflow: visible; padding: var(--space-md) 0; }
  .site-subbar { flex-direction: row; align-items: center; justify-content: space-between; margin-bottom: 0; }
}

/* --- 頁首區與長文 --- */
.site-page-head { padding: calc(var(--site-beat) * 2) 0 var(--site-beat); }
.site-page-head h1 {
  font-family: var(--font-brand); font-size: 2.488rem; line-height: 1.3;
  word-break: keep-all; text-wrap: balance;
}
.site-page-head p { margin-top: var(--space-xs); font-size: 1.2rem; color: var(--pz-text-secondary); text-wrap: pretty; }
@media (max-width: 720px) {
  .site-page-head h1 { font-size: 2.074rem; }
}

.site-prose { max-width: var(--site-measure); padding-bottom: calc(var(--site-beat) * 3); }
.site-prose h2 {
  font-family: var(--font-brand); font-size: 1.44rem; line-height: 1.4; text-wrap: balance;
  margin: calc(var(--site-beat) * 2) 0 calc(var(--site-beat) / 2);
}
.site-prose h3 { font-family: var(--font-brand); font-size: 1.2rem; line-height: 1.4; margin: var(--site-beat) 0 calc(var(--site-beat) / 2); }
.site-prose p, .site-prose ul, .site-prose ol { margin-bottom: var(--site-beat); text-wrap: pretty; }
.site-prose ul, .site-prose ol { padding-left: 1.5em; }
.site-prose li + li { margin-top: calc(var(--site-beat) / 4); }
.site-prose a { color: var(--pz-text); text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 0.2em; }
.site-prose a:hover { text-decoration-thickness: 2px; }
.site-prose-updated {
  margin-top: calc(var(--site-beat) * 2); padding-top: var(--space-sm);
  border-top: 1px solid var(--pz-border-light);
  font-size: 0.833rem; color: var(--pz-text-secondary);
}

/* --- 區段：垂直節拍＋區段標頭 --- */
.site-section { padding: calc(var(--site-beat) * 2) 0; }
.site-section-head { display: flex; align-items: center; gap: 0.75rem; margin-bottom: var(--site-beat); font-size: 0.833rem; color: var(--pz-text-secondary); }

/* 音節條（CIS 元件）：四格等寬、格間距＝格寬 1/8，依序聲母／介音／韻母／聲調，只亮在講的那格 */
.sbar {
  --sbar-cell: 0.55rem;
  --sbar-off: var(--pz-neutral-6);
  display: inline-flex; gap: calc(var(--sbar-cell) / 8); flex: none;
}
:root[data-theme="dark"] .sbar { --sbar-off: var(--pz-neutral-3); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .sbar { --sbar-off: var(--pz-neutral-3); }
}
.sbar i { width: var(--sbar-cell); height: 1rem; border-radius: 0.12rem; background: var(--sbar-off); }
.sbar[data-slot="onset"] i:nth-child(1) { background: var(--pz-slot-onset); }
.sbar[data-slot="medial"] i:nth-child(2) { background: var(--pz-slot-medial); }
.sbar[data-slot="rime"] i:nth-child(3) { background: var(--pz-slot-rime); }
.sbar[data-slot="tone"] i:nth-child(4) { background: var(--pz-slot-tone); }

/* --- 行動按鈕 --- */
.cta-actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-md); }
.cta-secondary {
  display: inline-flex; align-items: center; gap: 0.4em; padding: 0.6em 0;
  color: var(--pz-text-secondary); text-decoration: none;
  border-bottom: 1px solid transparent; transition: color 0.2s, border-color 0.2s;
}
.cta-secondary:hover { color: var(--pz-text); border-bottom-color: var(--pz-text); }
.app-store-badge { display: inline-flex; align-items: center; height: 60px; text-decoration: none; transition: transform 0.2s, opacity 0.2s; }
.app-store-badge:hover { transform: translateY(-1px); opacity: 0.85; }
.app-store-badge img { height: 60px; width: auto; display: block; }
.app-store-badge .badge-dark { display: none; }
[data-theme="dark"] .app-store-badge .badge-light { display: none; }
[data-theme="dark"] .app-store-badge .badge-dark { display: block; }

/* --- 捲動淡入（main.js） --- */
@keyframes site-fade-in { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }
.js-fade-ready .fade-in { opacity: 0; transform: translateY(16px); }
.js-fade-ready .fade-in.visible { animation: site-fade-in 0.6s ease forwards; }
@media (prefers-reduced-motion: reduce) {
  .js-fade-ready .fade-in, .js-fade-ready .fade-in.visible { opacity: 1; transform: none; animation: none; }
}
