/* 全站設計系統（從模板原站的 nature.css 改出來）
   風格：墨線 × 透明水彩。鬆散的黑色線稿、手繪的不規則圓角、透明水彩色塊、大量留白。
   跟原版的差別：
   · 字型：內文用系統字型，不再連 Google Fonts；標題用楷書類系統字型（見 notes/build-log.md 的取捨說明）。
   · 拿掉時事、廣告、課綱代碼表、尺度地圖的樣式；加上書頁（目錄大綱、試閱、下載框）與分類頁。
   所有顏色一律走變數；新增元件請勿寫死色碼。 */

/* ── 色票 ───────────────────────────────────────────── */
:root {
  color-scheme: light;

  /* 紙 */
  --bg:         #F2EDE3;
  --bg-warm:    #F6F1E7;
  --surface:    #FBF8F1;
  --surface-2:  #FFFCF6;
  --tint:       #EEF0EA;
  --dusk:       #2B3A42;
  --halo:       rgba(234, 181, 47, .16);

  /* 墨 */
  --ink:        #1F1E1C;
  --ink-soft:   #4C4841;
  --ink-faint:  #6F695E;   /* 原站 #8F887C 在奶白底上對比不到 4.5:1，加深一階 */
  --line:       #CFC6B6;
  --line-soft:  #E3DCCF;

  /* 五個水彩色 */
  --mint:       #7FA68E;
  --pink:       #E46F6B;
  --lilac:      #7B6CA0;
  --butter:     #EAB52F;
  --sky:        #7FB0C0;

  --accent:     #2F6F82;
  --accent-2:   #E46F6B;
  --accent-ink: #2A5F70;

  --ok:         #5F9468;
  --warn:       #D98A2B;
  --bad:        #D04A32;

  /* 分類色（categories.json 的 color 欄位對應 .c-<名稱>） */
  --s-phy:   #3F7F99;
  --s-chem:  #E07B2F;
  --s-bio:   #6E9C57;
  --s-earth: #A7813A;
  --s-cross: #D9573F;

  /* 手繪的不規則圓角 */
  --r-sm: 14px 10px 16px 9px / 10px 15px 9px 14px;
  --r:    22px 14px 24px 12px / 14px 22px 12px 24px;
  --r-lg: 30px 18px 34px 16px / 18px 30px 16px 34px;
  --r-pill: 255px 18px 225px 18px / 18px 225px 18px 255px;

  --shadow:    none;
  --shadow-lg: 0 10px 30px rgba(60, 50, 30, .08);

  --wc-blend: multiply;
  --wash-op: .42;

  /* 內文：系統字型，0 KB 下載 */
  --font-sans: system-ui, "Microsoft JhengHei", "PingFang TC", sans-serif;
  /* 標題：只用一種粗細（400）。裝了霞鶩文楷的電腦會用它，否則用系統內建的楷書。 */
  --font-read: "LXGW WenKai TC", "Kaiti TC", "STKaiti", "BiauKai", "DFKai-SB", "標楷體", serif;
  --measure: 36rem;
}

:root[data-theme="dark"] {
  color-scheme: dark;

  --bg:         #1C2124;
  --bg-warm:    #22282B;
  --surface:    #242B2F;
  --surface-2:  #2A3236;
  --tint:       #243035;
  --dusk:       #0E1214;
  --halo:       rgba(242, 200, 82, .12);

  --ink:        #EEE8DC;
  --ink-soft:   #C7BFB1;
  --ink-faint:  #A39C90;
  --line:       #465055;
  --line-soft:  #333C41;

  --mint:       #9CC4AA;
  --pink:       #F08A84;
  --lilac:      #A898C8;
  --butter:     #F2C852;
  --sky:        #9CC9D6;

  --accent:     #7FB6C9;
  --accent-2:   #F08A84;
  --accent-ink: #A3D2E2;

  --ok:         #8CC196;
  --warn:       #F0AE5A;
  --bad:        #F07C62;

  --s-phy:   #7FB6C9;
  --s-chem:  #F2A262;
  --s-bio:   #9CC98A;
  --s-earth: #D4B06A;
  --s-cross: #F2866B;

  --shadow-lg: 0 10px 30px rgba(0, 0, 0, .35);
  --wc-blend: screen;
  --wash-op: .30;
}

/* 上課模式：拉高對比、放大字級 */
:root[data-mode="class"] {
  --line: #A99F8E;
  --ink-soft: #3A3630;
  font-size: 19px;
}

/* ── 基底 ───────────────────────────────────────────── */
* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; overflow-x: clip; }

body {
  margin: 0;
  background-color: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 1rem;
  font-weight: 400;
  line-height: 1.85;
  letter-spacing: .02em;
  overflow-x: clip;
}

/* 紙紋：極淡的雜訊，鋪滿整頁 */
body::after {
  content: "";
  position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Cfilter id='p'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .35 0 0 0 0 .3 0 0 0 0 .22 0 0 0 .09 0'/%3E%3C/filter%3E%3Crect width='240' height='240' filter='url(%23p)'/%3E%3C/svg%3E");
  background-size: 240px 240px;
  opacity: .9;
}
:root[data-theme="dark"] body::after { opacity: .55; }

/* 整頁的水痕：角落幾團極淡的暈染 */
body::before {
  content: "";
  position: fixed; inset: -10%; pointer-events: none; z-index: 0;
  background:
    radial-gradient(30rem 22rem at 88% 6%, color-mix(in srgb, var(--butter) 10%, transparent), transparent 70%),
    radial-gradient(26rem 20rem at 4% 12%, color-mix(in srgb, var(--sky) 10%, transparent), transparent 72%),
    radial-gradient(28rem 20rem at 70% 104%, color-mix(in srgb, var(--pink) 7%, transparent), transparent 70%);
}

main, header, footer, nav { position: relative; z-index: 1; }

h1, h2 { font-family: var(--font-read); line-height: 1.35; letter-spacing: .03em; font-weight: 400; margin: 0 0 .5em; }
h1 { font-size: clamp(2rem, 5vw, 3.1rem); }
h2 { font-size: clamp(1.4rem, 3.4vw, 1.9rem); }
/* h3 用內文字型的粗體：楷書類系統字型沒有真正的粗體，硬加粗會糊 */
h3 { font-size: 1.1rem; font-weight: 700; line-height: 1.5; margin: 0 0 .4em; }

p { margin: 0 0 1em; max-width: var(--measure); }
a { color: var(--accent-ink); text-decoration-thickness: 1px; text-underline-offset: .26em; }
a:hover { text-decoration-color: var(--accent-2); }
.muted { color: var(--ink-soft); }
.faint { color: var(--ink-faint); font-size: .9rem; }
.lede { font-family: var(--font-read); font-size: 1.16rem; color: var(--ink-soft); }
b, strong { font-weight: 700; color: var(--ink); }

.wrap { width: min(100% - 2rem, 68rem); margin-inline: auto; }
@media (min-width: 720px) { .wrap { width: min(100% - 4rem, 68rem); } }

.skip-link {
  position: absolute; left: 1rem; top: -4rem; z-index: 50;
  background: var(--surface); padding: .5rem 1rem; border: 1px solid var(--ink); border-radius: var(--r-sm);
}
.skip-link:focus { top: .5rem; }

/* ── 手繪線的共用做法 ───────────────────────────────── */
.card, .stage, .opt, .caution, .readout { position: relative; }
.card::before, .stage::before {
  content: "";
  position: absolute; inset: -3px -2px -2px -4px;
  border: 1px solid var(--ink);
  border-radius: var(--r);
  opacity: .14;
  transform: rotate(-.5deg);
  pointer-events: none;
  filter: url(#nx-rough);
}
.stage::before { border-radius: var(--r-lg); transform: rotate(.35deg); opacity: .18; }

/* ── 卡片與標籤 ─────────────────────────────────────── */
.card {
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  border: 1px solid color-mix(in srgb, var(--ink) 48%, transparent);
  border-radius: var(--r);
  padding: 1.15rem 1.3rem;
}

/* ── 裝飾層 ─────────────────────────────────────────── */
.deco-host { position: relative; isolation: isolate; overflow: hidden; }
.deco {
  position: absolute; inset: 0; width: 100%; height: 100%;
  pointer-events: none; z-index: -1;
}
.deco-band { display: block; width: 100%; height: auto; max-height: 70px; margin: .5rem 0 1.25rem; pointer-events: none; }
.deco .wc, .deco-band .wc { mix-blend-mode: var(--wc-blend); }
:root[data-theme="dark"] .deco path.wc[opacity^="0.1"] { opacity: .06; }

/* 段落標籤、站名前面的一小枝墨線 */
.sec-label::before,
.brand::before {
  content: "";
  display: inline-block;
  width: 1.5em; height: 1.1em;
  background: var(--ink);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 36 26'%3E%3Cg fill='none' stroke='%23000' stroke-width='1.3' stroke-linecap='round'%3E%3Cpath d='M2 23c9-2 17-8 24-19'/%3E%3Cpath d='M12 18c-3-4-2-8 1-10 1 4 1 7-1 10z'/%3E%3Cpath d='M19 12c1-4 5-6 8-5-2 3-5 5-8 5z'/%3E%3Cpath d='M26 4c2-1 4 0 5 2'/%3E%3C/g%3E%3C/svg%3E") center / contain no-repeat;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 36 26'%3E%3Cg fill='none' stroke='%23000' stroke-width='1.3' stroke-linecap='round'%3E%3Cpath d='M2 23c9-2 17-8 24-19'/%3E%3Cpath d='M12 18c-3-4-2-8 1-10 1 4 1 7-1 10z'/%3E%3Cpath d='M19 12c1-4 5-6 8-5-2 3-5 5-8 5z'/%3E%3Cpath d='M26 4c2-1 4 0 5 2'/%3E%3C/g%3E%3C/svg%3E") center / contain no-repeat;
}
/* 有自訂標誌圖時，站名前面改放圖 */
.brand.has-logo::before { display: none; }
.brand img { width: 1.6em; height: 1.6em; display: block; }
:root[data-theme="dark"] .brand img { filter: invert(.92) hue-rotate(180deg); }

/* 標題：一團水彩墊在字的後面、偏一點位置，下方一筆墨線 */
.sec h2 {
  position: relative;
  isolation: isolate;
  display: inline-block;
  justify-self: start;
  padding: 0 .2em .3rem 0;
}
.sec h2::before {
  content: "";
  position: absolute;
  left: -.5em; top: .05em; width: 3.6em; height: 1.35em;
  z-index: -1;
  background: var(--wash, var(--butter));
  border-radius: 62% 38% 55% 45% / 48% 58% 42% 52%;
  opacity: var(--wash-op);
  mix-blend-mode: var(--wc-blend);
  filter: url(#nx-wc);
}
.sec h2::after {
  content: "";
  position: absolute; left: 0; right: -.4em; bottom: -.1rem; height: 9px;
  background: var(--ink);
  opacity: .85;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 300 9' preserveAspectRatio='none'%3E%3Cpath d='M1 6c40-3 90-4 140-3s110 2 158-1c-50 3-108 4-158 3S40 3 1 6z' fill='%23000'/%3E%3C/svg%3E") center / 100% 100% no-repeat;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 300 9' preserveAspectRatio='none'%3E%3Cpath d='M1 6c40-3 90-4 140-3s110 2 158-1c-50 3-108 4-158 3S40 3 1 6z' fill='%23000'/%3E%3C/svg%3E") center / 100% 100% no-repeat;
}
/* 七段版型（互動單元）每段的水彩色 */
#hook   { --wash: var(--butter); }
#guess  { --wash: var(--pink); }
#lab    { --wash: var(--sky); }
#why    { --wash: var(--mint); }
#limits { --wash: var(--pink); }
#across { --wash: var(--butter); }
#exam   { --wash: var(--lilac); }
/* 書頁三段 */
#outline  { --wash: var(--sky); }
#preview  { --wash: var(--butter); }
#download { --wash: var(--pink); }

/* 可點的卡片：右上角一支墨線小箭頭 */
a.card { color: inherit; text-decoration: none; }
a.card::after {
  content: "↗";
  position: absolute; top: .5rem; right: .85rem;
  font-family: var(--font-read);
  color: var(--ink-soft);
  font-size: 1rem;
  transition: transform .3s;
}
a.card:hover::after { transform: translate(2px, -2px); }
a.card:hover { border-color: var(--ink); }

/* ── 按鈕與控制元件 ─────────────────────────────────── */
.btn {
  appearance: none;
  font: inherit;
  font-weight: 500;
  font-size: .95rem;
  letter-spacing: .06em;
  color: var(--ink);
  background: transparent;
  border: 1.2px solid var(--ink);
  border-radius: var(--r-pill);
  padding: .45rem 1.15rem;
  min-height: 44px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  text-decoration: none;
  white-space: nowrap;
  position: relative;
  isolation: isolate;
  transition: transform .15s, background .2s, border-color .2s;
}
.btn:hover  { background: color-mix(in srgb, var(--butter) 16%, transparent); }
.btn:active { transform: translateY(1px) rotate(-.3deg); }
.btn:focus-visible { outline: 1.5px dashed var(--accent); outline-offset: 3px; }
.btn.primary { border-color: var(--ink); }
.btn.primary::before {
  content: ""; position: absolute; inset: -4px -8px -3px -5px; z-index: -1;
  background:
    radial-gradient(60% 80% at 30% 55%, var(--pink), transparent 72%),
    radial-gradient(60% 80% at 75% 45%, var(--butter), transparent 72%);
  opacity: calc(var(--wash-op) + .1);
  border-radius: 45% 55% 48% 52% / 60% 40% 60% 40%;
  mix-blend-mode: var(--wc-blend);
  filter: url(#nx-wc);
  transition: opacity .2s;
}
.btn.primary:hover { background: transparent; }
.btn.primary:hover::before { opacity: calc(var(--wash-op) + .25); }
.btn.ghost { border-color: color-mix(in srgb, var(--ink) 45%, transparent); }
.btn[aria-pressed="true"] {
  background: color-mix(in srgb, var(--sky) 22%, transparent);
  border-color: var(--ink);
}
/* 鎖住的按鈕：灰掉、虛線框，看得出「現在按不了」 */
.btn:disabled, .btn[aria-disabled="true"] {
  cursor: not-allowed;
  color: var(--ink-soft);
  border-style: dashed;
  background: color-mix(in srgb, var(--ink) 5%, transparent);
  transform: none;
}
.btn.primary:disabled::before { opacity: .12; }
select.btn { text-align: left; padding-right: .6rem; background: var(--surface); }

.chips { display: flex; flex-wrap: wrap; gap: .5rem; }
.chip {
  font: inherit;
  font-weight: 400;
  font-size: .88rem;
  padding: .2rem .85rem;
  min-height: 36px;
  border-radius: var(--r-pill);
  border: 1px solid color-mix(in srgb, var(--ink) 55%, transparent);
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  text-decoration: none;
  transition: border-color .16s, background .2s, color .16s;
}
.chip:hover { border-color: var(--ink); color: var(--ink); }
.chip[aria-pressed="true"], .chip[aria-current="page"] {
  color: var(--ink);
  border-color: var(--ink);
  background: color-mix(in srgb, var(--butter) 24%, transparent);
}
.chip .dot {
  width: .7em; height: .6em;
  border-radius: 58% 42% 63% 37% / 45% 55% 45% 55%;
  background: var(--tag-c, currentColor); opacity: .75;
}
.chip .count { font-size: .8em; color: var(--ink-faint); }

/* ── 分類標記 ───────────────────────────────────────── */
.tag {
  position: relative; isolation: isolate;
  display: inline-flex; align-items: center; gap: .3rem;
  font-size: .8rem; font-weight: 500; letter-spacing: .08em;
  padding: .06rem .6rem;
  color: var(--ink);
  text-decoration: none;
}
.tag::before {
  content: ""; position: absolute; inset: 20% -4% 0 0; z-index: -1;
  background: var(--tag-c, var(--butter));
  opacity: var(--wash-op);
  border-radius: 58% 42% 63% 37% / 45% 55% 45% 55%;
  mix-blend-mode: var(--wc-blend); filter: url(#nx-wc);
}
a.tag:hover { text-decoration: underline; }
.tag.is-plain::before { background: var(--line); }
.c-phy    { --tag-c: var(--s-phy);   --uc: var(--s-phy); }
.c-chem   { --tag-c: var(--s-chem);  --uc: var(--s-chem); }
.c-bio    { --tag-c: var(--s-bio);   --uc: var(--s-bio); }
.c-earth  { --tag-c: var(--s-earth); --uc: var(--s-earth); }
.c-cross  { --tag-c: var(--s-cross); --uc: var(--s-cross); }
.c-sky    { --tag-c: var(--sky);     --uc: var(--sky); }
.c-mint   { --tag-c: var(--mint);    --uc: var(--mint); }
.c-pink   { --tag-c: var(--pink);    --uc: var(--pink); }
.c-butter { --tag-c: var(--butter);  --uc: var(--butter); }
.c-lilac  { --tag-c: var(--lilac);   --uc: var(--lilac); }

/* ── 頁首（書頁、分類頁、互動單元共用） ─────────────── */
.unit-head, .book-head { padding: 3.5rem 0 2rem; }
.unit-head .formula {
  position: relative; isolation: isolate;
  font-size: 1.1rem;
  margin: 1.2rem 0 0;
  padding: .7rem 1.3rem;
  display: inline-block;
  border-top: 1px solid color-mix(in srgb, var(--ink) 60%, transparent);
  border-bottom: 1px solid color-mix(in srgb, var(--ink) 60%, transparent);
}
.unit-head .formula::before {
  content: ""; position: absolute; inset: 8% 25% 5% -4%; z-index: -1;
  background: var(--sky); opacity: calc(var(--wash-op) - .12);
  border-radius: 58% 42% 63% 37% / 45% 55% 45% 55%;
  mix-blend-mode: var(--wc-blend); filter: url(#nx-wc);
}
.unit-head .formula .katex-display { margin: 0; text-align: left; }

/* 麵包屑 */
.crumbs { font-size: .88rem; color: var(--ink-soft); margin: 0 0 1rem; }
.crumbs ol { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: .2rem .5rem; }
.crumbs li + li::before { content: "›"; margin-right: .5rem; color: var(--ink-faint); }
.crumbs a { color: inherit; }
.crumbs [aria-current] { color: var(--ink); }

.book-meta { display: flex; flex-wrap: wrap; gap: .4rem 1.2rem; align-items: center; margin-top: 1rem; }
.book-meta .faint { font-size: .85rem; }
.book-head .head-actions { margin-top: 1.4rem; display: flex; flex-wrap: wrap; gap: .6rem; }

.sec {
  padding: 3rem 0;
  scroll-margin-top: 4rem;
}
/* 段與段之間：一條鬆散的長墨線 */
.sec + .sec > .wrap::before {
  content: "";
  display: block;
  height: 10px;
  margin: 0 0 2.4rem;
  background: var(--ink);
  opacity: .45;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1000 10' preserveAspectRatio='none'%3E%3Cpath d='M0 6c120-2 260-3 420-2s330 3 470-1c40-1 80 0 110 1' fill='none' stroke='%23000' stroke-width='1.2'/%3E%3Cpath d='M640 4c90 1 170 3 250 1' fill='none' stroke='%23000' stroke-width='.8'/%3E%3C/svg%3E") center / 100% 100% no-repeat;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1000 10' preserveAspectRatio='none'%3E%3Cpath d='M0 6c120-2 260-3 420-2s330 3 470-1c40-1 80 0 110 1' fill='none' stroke='%23000' stroke-width='1.2'/%3E%3Cpath d='M640 4c90 1 170 3 250 1' fill='none' stroke='%23000' stroke-width='.8'/%3E%3C/svg%3E") center / 100% 100% no-repeat;
}
.sec > .wrap { display: grid; gap: 1.5rem; }
.sec > .wrap > * { min-width: 0; }

.sec-label {
  font-size: .8rem; font-weight: 500; letter-spacing: .22em;
  color: var(--ink-soft); margin: 0 0 .2rem;
  display: flex; align-items: center; gap: .55rem;
}

/* ── 書頁：目錄大綱 ─────────────────────────────────── */
.outline { max-width: 46rem; }
.outline ol { list-style: none; margin: 0; padding: 0; }
.outline ol ol { padding-left: 1.4rem; border-left: 1px dashed color-mix(in srgb, var(--ink) 25%, transparent); margin: .1rem 0 .4rem .35rem; }
.outline li { margin: 0; }
.outline .ol-row { display: flex; align-items: baseline; gap: .5rem; padding: .3rem 0; }
.outline .ol-title { flex: 0 1 auto; }
/* 標題與頁碼之間的點線 */
.outline .ol-row::after {
  content: ""; flex: 1 1 2rem; order: 1; min-width: 1.5rem;
  border-bottom: 1px dotted color-mix(in srgb, var(--ink) 35%, transparent);
  transform: translateY(-.3em);
}
.outline .ol-page { order: 2; flex: none; font-variant-numeric: tabular-nums; color: var(--ink-faint); font-size: .85rem; }
.outline > ol > li > .ol-row .ol-title { font-family: var(--font-read); font-size: 1.12rem; }
.outline > ol > li + li { margin-top: .35rem; }
.outline ol ol .ol-title { color: var(--ink-soft); }

/* ── 書頁：試閱 ─────────────────────────────────────── */
.preview { display: grid; gap: 1.6rem; max-width: 44rem; }
.preview-block {
  position: relative;
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  border: 1px solid color-mix(in srgb, var(--ink) 35%, transparent);
  border-radius: var(--r);
  padding: 1.3rem 1.5rem 1rem;
}
.preview-block h3 { font-family: var(--font-read); font-weight: 400; font-size: 1.2rem; }
.preview-block .katex-display { overflow-x: auto; overflow-y: hidden; padding: .2rem 0; }
/* KaTeX 給螢幕報讀器的 MathML 雖然被 clip 掉，仍會撐寬頁面；在手機上造成橫向捲動 */
.preview-block .katex-mathml { width: 1px; height: 1px; overflow: hidden; }
.preview-end { color: var(--ink-faint); font-size: .9rem; text-align: center; letter-spacing: .2em; }

/* ── 書頁：下載框 ───────────────────────────────────── */
.download-box { display: grid; gap: .8rem; justify-items: start; max-width: 36rem; }
.download-box .lock-note { margin: 0; color: var(--ink-soft); font-size: .92rem; }

/* ── 書卡、分類卡 ───────────────────────────────────── */
.unit-grid { display: grid; gap: .9rem; grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr)); }
.unit-card {
  text-decoration: none; color: inherit;
  display: grid; gap: .25rem; position: relative; align-content: start;
  transition: transform .16s, border-color .16s, background .16s;
}
.unit-title {
  margin: 0; display: flex; align-items: center; gap: .5rem;
  font-family: var(--font-read); font-size: 1.12rem; font-weight: 400; line-height: 1.45;
  padding-right: 1.2rem;
}
.unit-dot {
  width: .75rem; height: .6rem; flex: 0 0 auto; opacity: .8;
  border-radius: 58% 42% 63% 37% / 45% 55% 45% 55%;
  background: var(--uc, var(--s-cross));
}
.unit-sub { margin: 0; color: var(--ink-soft); font-size: .92rem; }
.unit-foot { margin: .45rem 0 0; display: flex; gap: .4rem; flex-wrap: wrap; align-items: center; font-size: .82rem; color: var(--ink-faint); }
.unit-foot > span:not(.mark-state) + span:not(.mark-state)::before { content: "·"; margin-right: .4rem; }
.book-head .chips, .unit-head .chips { margin-bottom: .6rem; }
.mark-state { font-size: .78rem; padding: 0 .5rem; border-radius: var(--r-pill); border: 1px solid var(--line); color: var(--ink-soft); }
.mark-state[data-state="got"] { background: color-mix(in srgb, var(--mint) 30%, transparent); }
.mark-state[data-state="stuck"] { background: color-mix(in srgb, var(--butter) 30%, transparent); }
@media (hover: hover) {
  a.unit-card:hover { transform: translateY(-2px); border-color: var(--uc, var(--ink)); }
}
.empty-note { color: var(--ink-faint); }

.cat-tree, .cat-tree ul { list-style: none; margin: 0; padding: 0; }
.cat-tree ul { padding-left: 1.3rem; border-left: 1px dashed color-mix(in srgb, var(--ink) 25%, transparent); margin: .2rem 0 .5rem .4rem; }
.cat-tree li { padding: .15rem 0; }
.cat-tree > li > a { font-family: var(--font-read); font-size: 1.2rem; }
.cat-tree .count { color: var(--ink-faint); font-size: .85rem; margin-left: .3rem; }

/* ── 首頁 hero ──────────────────────────────────────── */
.stage-hero { position: relative; background: transparent; overflow: hidden; isolation: isolate; }
.stage-hero .deco { position: absolute; inset: 0; pointer-events: none; z-index: -1; }
.hero-body { padding: 5rem 0 4rem; }
.hero-lede { max-width: 34rem; font-size: 1.12rem; }
.hero-actions { margin-top: 1.4rem; display: flex; flex-wrap: wrap; gap: .6rem; }

/* ── 互動單元用：舞台、面板、滑桿、讀數、資料表、預測題（sim.js 使用） ── */
.two-col { display: grid; gap: 1.5rem; }
.two-col > * { min-width: 0; }
@media (min-width: 900px) {
  .two-col { grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); align-items: start; }
}
.stage {
  background: var(--surface);
  border: 1.2px solid color-mix(in srgb, var(--ink) 75%, transparent);
  border-radius: var(--r-lg);
  padding: .7rem;
}
.stage > svg, .stage > canvas, .stage > div { position: relative; }
.stage svg, .stage canvas { display: block; width: 100%; height: auto; }
.panel { display: grid; gap: 1rem; align-content: start; }
.sim-controls { display: grid; gap: 1rem; min-width: 0; }
.panel .row { display: grid; gap: .15rem; }
.panel label {
  font-size: .9rem; font-weight: 400; color: var(--ink-soft);
  display: flex; justify-content: space-between; gap: 1rem; align-items: baseline;
}
.panel label b { font-family: var(--font-read); font-size: 1.05rem; color: var(--ink); font-variant-numeric: tabular-nums; font-weight: 400; }

input[type="range"] {
  appearance: none; -webkit-appearance: none;
  width: 100%; height: 44px; background: transparent; cursor: pointer; margin: 0;
  min-width: 0; touch-action: pan-y pinch-zoom;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 8px; border-radius: 999px;
  background:
    linear-gradient(var(--ink), var(--ink)) 0 50% / 100% 1.2px no-repeat,
    linear-gradient(90deg, color-mix(in srgb, var(--pink) 45%, transparent) var(--fill, 50%), transparent var(--fill, 50%));
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 20px; height: 20px; margin-top: -6px;
  border-radius: 52% 48% 55% 45% / 48% 55% 45% 52%;
  background: var(--surface); border: 1.4px solid var(--ink);
}
input[type="range"]::-moz-range-track { height: 1.2px; background: var(--ink); }
input[type="range"]::-moz-range-progress { height: 8px; border-radius: 999px; background: color-mix(in srgb, var(--pink) 45%, transparent); }
input[type="range"]::-moz-range-thumb {
  width: 18px; height: 18px; border-radius: 52% 48% 55% 45% / 48% 55% 45% 52%;
  background: var(--surface); border: 1.4px solid var(--ink);
}
input[type="range"]:focus-visible { outline: 1.5px dashed var(--accent); outline-offset: 4px; }

.readout {
  font-variant-numeric: tabular-nums;
  background: color-mix(in srgb, var(--butter) 8%, transparent);
  border-left: 1.5px solid var(--ink);
  border-radius: 2px 12px 14px 2px / 2px 14px 12px 2px;
  padding: .7rem 1rem;
  font-size: .96rem;
}
.transport { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.datatable { width: 100%; border-collapse: collapse; font-size: .88rem; font-variant-numeric: tabular-nums; }
.datatable th, .datatable td { text-align: right; padding: .35rem .55rem; border-bottom: 1px solid var(--line); }
.datatable th { color: var(--ink-soft); font-weight: 500; border-bottom-color: var(--ink); }
.datatable caption { caption-side: top; text-align: left; color: var(--ink-soft); font-size: .85rem; padding-bottom: .35rem; font-family: var(--font-read); }

.guess { display: grid; gap: .7rem; max-width: var(--measure); }
.opt {
  text-align: left; font: inherit; cursor: pointer; color: inherit;
  border: 1px solid color-mix(in srgb, var(--ink) 55%, transparent);
  background: transparent;
  border-radius: var(--r-sm); padding: .8rem 1.05rem; min-height: 44px;
  isolation: isolate;
  transition: border-color .16s;
}
.opt:hover { border-color: var(--ink); }
.opt::before {
  content: ""; position: absolute; inset: -3px -6px -3px 30%; z-index: -1;
  border-radius: 58% 42% 63% 37% / 45% 55% 45% 55%;
  opacity: 0; transition: opacity .3s;
  mix-blend-mode: var(--wc-blend); filter: url(#nx-wc);
}
.opt[data-state="right"] { border-color: var(--ink); }
.opt[data-state="right"]::before { background: var(--mint); opacity: var(--wash-op); }
.opt[data-state="wrong"]::before { background: var(--pink); opacity: calc(var(--wash-op) - .12); }
.opt .why { display: none; margin: .5rem 0 0; font-size: .93rem; color: var(--ink-soft); }
.opt[data-state] .why { display: block; }
.opt .mark {
  font-family: var(--font-read);
  margin-right: .55rem;
  display: inline-flex; align-items: center; justify-content: center;
  width: 1.6rem; height: 1.6rem;
  border: 1px solid var(--ink);
  border-radius: 52% 48% 55% 45% / 48% 55% 45% 52%;
  color: var(--ink);
}
.caution {
  border: none;
  border-left: 1.5px solid var(--ink);
  padding: .5rem 1.1rem .6rem;
  max-width: var(--measure);
  isolation: isolate;
}
.caution::before {
  content: ""; position: absolute; left: -.6rem; top: .2rem; width: 3.2rem; height: 2rem; z-index: -1;
  background: var(--warn); opacity: calc(var(--wash-op) - .08);
  border-radius: 58% 42% 63% 37% / 45% 55% 45% 55%;
  mix-blend-mode: var(--wc-blend); filter: url(#nx-wc);
}
.caution h3 { color: var(--ink); font-size: 1.02rem; margin-bottom: .25rem; }
.model-note {
  font-size: .88rem; color: var(--ink-soft);
  border-top: 1px dashed color-mix(in srgb, var(--ink) 45%, transparent); padding-top: .8rem; margin-top: .3rem;
}
.model-note b { color: var(--ink); }
.model-note ul { margin: .35rem 0 0; padding-left: 1.2em; }

/* ── 進度 ───────────────────────────────────────────── */
.progress-bar { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.got-it[data-state="got"]   { background: color-mix(in srgb, var(--mint) 30%, transparent); }
.got-it[data-state="stuck"] { background: color-mix(in srgb, var(--butter) 30%, transparent); }

/* ── 頂列 ───────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 30;
  padding: .55rem 0;
  background: color-mix(in srgb, var(--bg) 94%, transparent);
}
.topbar::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 6px;
  background: var(--ink); opacity: .35;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1000 6' preserveAspectRatio='none'%3E%3Cpath d='M0 3c200-1 400 1 600 0s300-1 400 1' fill='none' stroke='%23000' stroke-width='1'/%3E%3C/svg%3E") center / 100% 100% no-repeat;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1000 6' preserveAspectRatio='none'%3E%3Cpath d='M0 3c200-1 400 1 600 0s300-1 400 1' fill='none' stroke='%23000' stroke-width='1'/%3E%3C/svg%3E") center / 100% 100% no-repeat;
}
.topbar .wrap { display: flex; align-items: center; gap: .6rem; }
.topbar .brand { flex: none; }
.topbar-actions { display: flex; align-items: center; gap: .9rem; }
.topbar-menu-toggle { display: none; }
.topbar .spacer { flex: 1; }

.nav-links { display: flex; align-items: center; gap: .1rem; }
.nav-link {
  position: relative; isolation: isolate;
  padding: .4rem .7rem; border-radius: var(--r-pill);
  font-size: .95rem; letter-spacing: .06em; white-space: nowrap;
  color: var(--ink-soft); text-decoration: none;
  transition: color .16s, background .2s;
}
.nav-link:hover { color: var(--ink); background: color-mix(in srgb, var(--butter) 14%, transparent); }
.nav-link:focus-visible { outline: 1.5px dashed var(--accent); outline-offset: 2px; }
.nav-link[aria-current="page"] { color: var(--ink); font-weight: 500; }
.nav-link[aria-current="page"]::after {
  content: ""; position: absolute; left: .45rem; right: .45rem; bottom: .25rem; height: .5em; z-index: -1;
  background: var(--butter); opacity: calc(var(--wash-op) + .15);
  border-radius: 58% 42% 63% 37% / 45% 55% 45% 55%;
  mix-blend-mode: var(--wc-blend);
}
.nav-tools { display: flex; align-items: center; gap: .4rem; padding-left: .9rem; border-left: 1px solid var(--line); }
.nav-tools:not(:has(> :not([hidden]))) { display: none; }
.btn.btn-sm { min-height: 36px; padding: .2rem .85rem; font-size: .88rem; letter-spacing: .04em; }
.btn.btn-icon { width: 36px; padding: 0; justify-content: center; font-size: 1rem; letter-spacing: 0; }
.brand {
  font-family: var(--font-read);
  font-size: 1.2rem;
  letter-spacing: .08em; text-decoration: none;
  color: inherit; white-space: nowrap;
  display: inline-flex; align-items: center; gap: .45rem;
}

/* ── 頁尾 ───────────────────────────────────────────── */
.site-foot { padding: 1rem 0 3rem; color: var(--ink-soft); font-size: .9rem; }
.site-foot .foot-row { display: flex; flex-wrap: wrap; gap: .5rem 1.4rem; align-items: baseline; }
.site-foot nav a { color: inherit; margin-right: 1rem; }
.site-foot p { margin: .4rem 0 0; max-width: none; }

/* ── 上課模式：一次只顯示一段 ───────────────────────── */
:root[data-mode="class"] .sec { min-height: 100svh; display: flex; align-items: center; }
:root[data-mode="class"] .sec[hidden] { display: none; }
:root[data-mode="class"] .sec + .sec > .wrap::before { display: none; }
:root[data-mode="class"] .unit-head[hidden], :root[data-mode="class"] body > footer { display: none; }
.class-pager { display: none; }
:root[data-mode="class"] .class-pager {
  display: flex; position: fixed; bottom: max(.7rem, env(safe-area-inset-bottom));
  left: 50%; transform: translateX(-50%); z-index: 25;
  width: max-content; max-width: calc(100% - 1rem); padding: .4rem;
  align-items: center; gap: .5rem; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--r-sm); box-shadow: var(--shadow-lg);
}
.class-pager .btn { padding-inline: .65rem; letter-spacing: 0; }
.class-pager .btn:disabled { opacity: .4; cursor: default; }
.class-pager .faint { min-width: 3rem; text-align: center; font-variant-numeric: tabular-nums; }
:root[data-mode="class"] main > .sec { padding-bottom: 6rem; }

a, button, summary, input { -webkit-tap-highlight-color: transparent; }
@media (hover: none) {
  .btn:active, .chip:active, .opt:active { transform: scale(.97); }
}

[hidden] { display: none !important; }

/* ── 手機 ───────────────────────────────────────────── */
@media (max-width: 899px) {
  .topbar-menu-toggle { display: inline-flex; }
  .topbar-actions {
    display: none; position: absolute; top: 100%; right: 1rem;
    width: min(25rem, calc(100% - 2rem)); max-height: calc(100svh - 5rem);
    overflow-y: auto; overscroll-behavior: contain;
    padding: .8rem; background: var(--surface);
    border: 1px solid var(--line); border-radius: var(--r-sm); box-shadow: var(--shadow-lg);
  }
  /* 沒有 JS 時選單按鈕不會出現，入口直接攤開在頂列下方 */
  .topbar-menu-toggle[hidden] + .topbar-actions { display: flex; position: static; width: auto; box-shadow: none; border: 0; padding: 0; background: none; }
  .topbar-actions.is-open { display: flex; flex-direction: column; align-items: stretch; gap: .7rem; }
  .nav-links { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .35rem; }
  .nav-link { min-height: 44px; display: flex; align-items: center; justify-content: center; border: 1px solid var(--line-soft); }
  .nav-tools { flex-wrap: wrap; gap: .6rem; padding: .7rem 0 0; border-left: 0; border-top: 1px solid var(--line-soft); }
  .topbar-actions .btn { width: 100%; min-height: 44px; justify-content: center; white-space: normal; }
  .topbar-actions .btn-icon { width: 44px; flex: none; }
}
@media (max-width: 719px) {
  :root { --topbar-h: 3.3rem; }
  body { font-size: .97rem; }
  .card { padding: 1rem 1.05rem; }
  .topbar {
    padding: .3rem 0; min-height: var(--topbar-h); display: flex; align-items: center;
    background: color-mix(in srgb, var(--bg) 80%, transparent);
    -webkit-backdrop-filter: saturate(1.3) blur(12px);
            backdrop-filter: saturate(1.3) blur(12px);
  }
  .topbar .wrap { gap: .45rem; }
  .brand { font-size: 1.08rem; }
  .topbar .btn { padding: .3rem .8rem; min-height: 44px; font-size: .9rem; letter-spacing: .02em; }
  .sec { scroll-margin-top: calc(var(--topbar-h) + 1rem); padding: 2.3rem 0; }
  .chip { min-height: 44px; }
  .unit-head .formula { max-width: 100%; overflow-x: auto; }
  .unit-head, .book-head { padding: 2.2rem 0 1.4rem; }
  .hero-body { padding: 2.4rem 0 1rem; }
  .stage-hero h1 { font-size: 2.4rem; letter-spacing: .06em; }
  /* 花瓶移到文字下面，不壓在字後 */
  .stage-hero { display: flex; flex-direction: column; }
  .stage-hero > .wrap { order: 1; }
  .stage-hero .deco.bouquet { position: relative; inset: auto; order: 2; height: 200px; margin-top: -1rem; z-index: 0; }
  .preview-block { padding: 1.1rem 1.05rem .8rem; }
  .outline ol ol { padding-left: .9rem; }
  .panel, .sim-controls { grid-template-columns: minmax(0, 1fr); }
  .panel .row {
    background: var(--surface); border: 1px solid color-mix(in srgb, var(--ink) 35%, transparent);
    border-radius: var(--r-sm); padding: .65rem .85rem;
  }
  input[type="range"]::-webkit-slider-thumb { width: 26px; height: 26px; margin-top: -9px; }
  input[type="range"]::-moz-range-thumb { width: 24px; height: 24px; }
  .deco { opacity: .5; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

@media print {
  body::before, body::after, .topbar, .transport, .btn, .class-pager, .deco, .deco-band, .download-box { display: none !important; }
  body { background: #fff; }
  .sec { break-inside: avoid; }
}

/* 有裝飾帶的段落不再畫分隔線，避免兩條疊在一起 */
.sec + .sec > .wrap:has(> .deco-band:first-child)::before { display: none; }

/* ── 會員：頂列登入、登入頁、帳號頁、管理頁、隱私權頁（第 2 週） ── */
.topbar-auth { flex: none; max-width: 11rem; overflow: hidden; text-overflow: ellipsis; display: inline-block; line-height: 34px; }
.topbar-auth.is-signed-in { border-style: dashed; }
@media (max-width: 719px) { .topbar-auth { max-width: 7.5rem; line-height: 40px; } }

.btn.btn-lg { min-height: 52px; padding: .6rem 1.6rem; font-size: 1.05rem; }

.auth-box { display: grid; gap: 1rem; justify-items: start; max-width: 32rem; padding: 1.4rem 1.5rem; }
.auth-box > * { margin: 0; }
.auth-google { width: 100%; justify-content: center; }
/* Google 按鈕下方的小字：說明 Google 畫面上的 …supabase.co 是本站的登入服務 */
.auth-host-note { margin-top: -.5rem !important; font-size: .85rem; line-height: 1.6; color: var(--ink-faint); }
.auth-host { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: .8rem; overflow-wrap: anywhere; color: var(--ink-soft); }
.auth-msg { margin: 0; padding: .6rem .8rem; border-radius: var(--r-sm); background: var(--tint); color: var(--ink-soft); }
.auth-msg.is-error, .lock-note.is-error { color: var(--bad); }
.auth-msg.is-error { background: color-mix(in srgb, var(--bad) 10%, transparent); }
.auth-msg.is-ok, .lock-note.is-ok { color: var(--ok); }
.auth-msg.is-ok { background: color-mix(in srgb, var(--ok) 12%, transparent); }
.auth-alt { width: 100%; }
.auth-alt summary { cursor: pointer; color: var(--accent-ink); padding: .5rem 0; min-height: 44px; display: flex; align-items: center; }
:root[data-theme="dark"] .auth-alt summary { color: var(--accent); }
.auth-alt summary:focus-visible { outline: 1.5px dashed var(--accent); outline-offset: 2px; }
.auth-form { display: grid; gap: .6rem; padding-top: .4rem; }
.auth-form p { margin: 0; }
.auth-sent { display: grid; gap: .6rem; }
.auth-sent p { margin: 0; }
.auth-actions { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; }
.auth-foot { max-width: 32rem; margin-top: 1rem; }

.auth-box input[type="email"], .auth-box input[type="text"], .admin input[type="search"], .admin input[type="text"], .admin input[type="number"] {
  font: inherit; font-size: 16px;   /* 16px 以上 iPhone 才不會自動放大 */
  color: var(--ink); background: var(--surface-2);
  border: 1.2px solid color-mix(in srgb, var(--ink) 45%, transparent); border-radius: var(--r-sm);
  padding: .55rem .75rem; min-height: 46px; width: 100%; box-sizing: border-box;
}
.auth-box input:focus-visible, .admin input:focus-visible { outline: 1.5px dashed var(--accent); outline-offset: 2px; border-color: var(--ink); }
.auth-box label, .admin label { font-weight: 500; font-size: .95rem; }

.account-info { display: grid; grid-template-columns: max-content 1fr; gap: .7rem 1.2rem; margin: 0; width: 100%; }
.account-info dt { color: var(--ink-faint); }
.account-info dd { margin: 0; overflow-wrap: anywhere; }
.name-form { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.name-form input { flex: 1 1 10rem; width: auto !important; }
.name-form .auth-msg { flex-basis: 100%; padding: .3rem .6rem; }
.account-delete { max-width: 32rem; margin-top: 1.5rem; padding: 1.2rem 1.5rem; }
.account-delete h2 { font-size: 1.25rem; margin-top: 0; }
@media (max-width: 479px) { .account-info { grid-template-columns: 1fr; gap: .2rem; } .account-info dd { margin-bottom: .6rem; } }

.lock-note a { color: inherit; }

/* 管理頁：會在補習班現場用手機操作，按鈕與輸入框都放大 */
.admin-sec { margin-bottom: 2.4rem; }
.admin-sec h2 { margin-top: 0; }
.admin-search { display: grid; gap: .45rem; max-width: 36rem; margin-bottom: 1rem; }
.admin-search p { margin: 0; }
.admin-search-row { display: flex; gap: .5rem; }
.admin-search-row input { flex: 1; min-width: 0; }
.admin-list { display: grid; gap: .9rem; grid-template-columns: repeat(auto-fill, minmax(min(100%, 22rem), 1fr)); }
.admin-card { display: grid; gap: .5rem; padding: 1rem 1.1rem; }
.admin-card > p { margin: 0; }
.admin-email { font-weight: 600; overflow-wrap: anywhere; }
.admin-status { color: var(--ink-soft); font-size: .95rem; }
.admin-form { display: grid; grid-template-columns: 6rem 1fr; gap: .5rem .6rem; align-items: end; }
.admin-form .field { display: grid; gap: .25rem; min-width: 0; }
.admin-form .admin-go { grid-column: 1 / -1; width: 100%; justify-content: center; min-height: 50px; font-size: 1.05rem; }
.admin-result { margin: 0; font-weight: 500; }
.admin-card.is-unconfirmed { background: color-mix(in srgb, var(--warn) 9%, transparent); }
.admin-badge-warn {
  justify-self: start; padding: .2rem .65rem; border-radius: 999px; font-weight: 700; font-size: .95rem;
  color: var(--ink); background: color-mix(in srgb, var(--warn) 32%, transparent); border: 1.5px solid var(--warn);
}
.admin-warn-note { color: var(--ink-soft); font-size: .92rem; }
.admin-result.is-ok { color: var(--ok); }
.admin-result.is-error { color: var(--bad); }
.admin-log { list-style: none; padding: 0; margin: 0; display: grid; gap: .5rem; max-width: 48rem; }
.admin-log li { display: flex; flex-wrap: wrap; gap: .2rem 1rem; padding: .55rem .2rem; border-bottom: 1px solid var(--line-soft); }
.admin-log .log-when { color: var(--ink-faint); font-variant-numeric: tabular-nums; }
.admin-log .log-who { font-weight: 500; overflow-wrap: anywhere; }
.admin-log .log-note { flex-basis: 100%; color: var(--ink-soft); font-size: .92rem; }

/* 隱私權說明 */
.prose .wrap > * { max-width: var(--measure); }
.prose h2 { margin-top: 2rem; }
.prose ul { padding-left: 1.3rem; }
.prose li { margin: .35rem 0; }
.draft-note { padding: .9rem 1.1rem; }
mark.todo { background: color-mix(in srgb, var(--butter) 40%, transparent); color: inherit; padding: 0 .25rem; border-radius: 4px; }
