@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+TC:wght@400;500;700;900&display=swap');

:root {
  --ink: #172033;
  --muted: #657187;
  --faint: #96a0b3;
  --line: #dce3ee;
  --paper: #eef2f8;
  --panel: #ffffff;
  --blue: #2563eb;
  --green: #059669;
  --amber: #d97706;
  --rose: #e11d48;
  --violet: #7c3aed;
  --teal: #0891b2;
  --shadow-sm: 0 6px 18px rgba(30, 42, 68, 0.08);
  --shadow: 0 18px 50px rgba(30, 42, 68, 0.14);
  --r: 18px;
  /* 各章主題色 */
  --c1: #2563eb;
  --c2: #7c3aed;
  --c3: #059669;
  --c4: #d97706;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  color: var(--ink);
  font-family: "Noto Sans TC", system-ui, sans-serif;
  background:
    radial-gradient(1200px 700px at 12% -10%, rgba(37, 99, 235, 0.10), transparent 60%),
    radial-gradient(1000px 700px at 100% 0%, rgba(124, 58, 237, 0.10), transparent 55%),
    radial-gradient(900px 700px at 90% 110%, rgba(5, 150, 105, 0.10), transparent 55%),
    var(--paper);
  min-height: 100vh;
}

button { font: inherit; cursor: pointer; }
.hidden { display: none !important; }

/* ===================== 封面 ===================== */
.cover {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 40px 24px;
}
.cover-inner {
  max-width: 880px;
  width: 100%;
  text-align: center;
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.9);
  border-radius: 28px;
  box-shadow: var(--shadow);
  padding: 54px 46px 46px;
}
.cover-eyebrow {
  margin: 0 0 10px;
  color: var(--blue);
  font-weight: 900;
  letter-spacing: 0.22em;
  font-size: 14px;
}
.cover-title {
  margin: 0;
  font-size: clamp(44px, 8vw, 84px);
  font-weight: 900;
  line-height: 1;
  letter-spacing: 0.02em;
  background: linear-gradient(120deg, var(--blue), var(--violet) 45%, var(--teal));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.cover-sub {
  margin: 18px 0 30px;
  color: var(--muted);
  font-size: clamp(15px, 2.2vw, 20px);
  font-weight: 500;
}
.cover-chapters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 14px;
  margin-bottom: 34px;
  text-align: left;
}
.cover-card {
  border-radius: 16px;
  padding: 16px 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
  border-top: 4px solid var(--ct);
}
.cover-card .cc-num {
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.12em;
  color: var(--ct);
}
.cover-card .cc-title { font-size: 19px; font-weight: 900; margin: 4px 0 6px; }
.cover-card .cc-list { font-size: 13px; color: var(--muted); line-height: 1.7; }
.cover-start {
  border: none;
  color: #fff;
  background: linear-gradient(120deg, var(--blue), var(--violet));
  padding: 16px 40px;
  font-size: 19px;
  font-weight: 900;
  border-radius: 999px;
  box-shadow: 0 16px 34px rgba(37, 99, 235, 0.34);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.cover-start:hover { transform: translateY(-2px); box-shadow: 0 22px 40px rgba(37, 99, 235, 0.42); }
.cover-hint { margin: 22px 0 0; color: var(--faint); font-size: 13px; }

/* ===================== 主體版面 ===================== */
.app { height: 100vh; overflow: hidden; display: flex; flex-direction: column; }

.topbar {
  height: 62px;
  flex: none;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 22px;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}
.home-btn {
  border: none;
  background: none;
  font-weight: 900;
  font-size: 17px;
  color: var(--ink);
  letter-spacing: 0.04em;
}
.crumb {
  flex: 1;
  color: var(--muted);
  font-weight: 700;
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.crumb b { color: var(--ink); }
.ghost-btn {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 10px;
  padding: 8px 14px;
  font-weight: 800;
  font-size: 14px;
  box-shadow: var(--shadow-sm);
}

.body { flex: 1; display: grid; grid-template-columns: 280px minmax(0, 1fr); min-height: 0; }

/* ------- 目錄 ------- */
.toc {
  border-right: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.72);
  overflow-y: auto;
  padding: 14px 12px 40px;
}
.toc-chapter { margin-bottom: 6px; }
.toc-chead {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  font-weight: 900;
  font-size: 14px;
  color: var(--ct);
  border-radius: 10px;
  cursor: pointer;
  user-select: none;
}
.toc-chead:hover { background: rgba(37, 99, 235, 0.06); }
.toc-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--ct); flex: none; }
.toc-items { display: none; padding-left: 8px; }
.toc-chapter.open .toc-items { display: block; }
.toc-item {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: none;
  border-left: 2px solid var(--line);
  padding: 7px 12px;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.35;
}
.toc-item:hover { color: var(--ink); background: rgba(37, 99, 235, 0.05); }
.toc-item.active {
  color: var(--ct);
  font-weight: 800;
  border-left: 2px solid var(--ct);
  background: rgba(37, 99, 235, 0.08);
}
.toc-item .ti-sec { font-size: 11px; color: var(--faint); font-weight: 700; margin-right: 6px; }

/* ------- 舞台 ------- */
.stage { display: flex; flex-direction: column; min-height: 0; padding: 14px 24px 0; }

.slide {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 0.92fr) minmax(0, 1.08fr);
  gap: 24px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow);
  padding: 22px 30px;
  overflow: hidden;
  animation: slidein 0.32s ease;
}
@keyframes slidein {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

/* 章節分隔頁 */
.slide.divider {
  grid-template-columns: 1fr;
  place-items: center;
  text-align: center;
  background: linear-gradient(135deg, var(--ct), color-mix(in srgb, var(--ct) 62%, #111));
  color: #fff;
  border: none;
}
.divider .dv-num { font-size: 15px; font-weight: 900; letter-spacing: 0.3em; opacity: 0.85; }
.divider .dv-title { font-size: clamp(38px, 6vw, 66px); font-weight: 900; margin: 12px 0 18px; }
.divider .dv-list { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; max-width: 720px; }
.divider .dv-chip { background: rgba(255,255,255,0.18); border: 1px solid rgba(255,255,255,0.35); padding: 8px 16px; border-radius: 999px; font-weight: 700; font-size: 15px; }

/* 左：概念欄（改為不捲動，內容過高時由 JS 自動縮放） */
.slide-info { display: flex; flex-direction: column; min-height: 0; overflow: hidden; padding-right: 6px; }
.col-fit { display: flex; flex-direction: column; min-height: 100%; transform-origin: top center; }
.slide-info::-webkit-scrollbar, .toc::-webkit-scrollbar, .slide-visual::-webkit-scrollbar { width: 8px; }
.slide-info::-webkit-scrollbar-thumb, .toc::-webkit-scrollbar-thumb, .slide-visual::-webkit-scrollbar-thumb { background: #cfd7e6; border-radius: 8px; }

.badge {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.08em;
  color: #fff;
  background: var(--ct);
  padding: 5px 12px;
  border-radius: 999px;
  margin-bottom: 10px;
}
.slide-title { font-size: clamp(23px, 2.6vw, 32px); font-weight: 900; line-height: 1.18; margin: 0 0 10px; }

.formula {
  background: color-mix(in srgb, var(--ct) 8%, #fff);
  border: 1px solid color-mix(in srgb, var(--ct) 24%, #fff);
  border-radius: 12px;
  padding: 10px 14px;
  margin-bottom: 12px;
  overflow-x: auto;
}
.formula .formula-label { font-size: 12px; font-weight: 900; color: var(--ct); letter-spacing: 0.06em; margin-bottom: 4px; }

.points { list-style: none; margin: 0 0 16px; padding: 0; }
.points li {
  position: relative;
  padding: 4px 0 4px 26px;
  font-size: 15.5px;
  line-height: 1.55;
  color: #29344a;
}
.points li::before {
  content: "";
  position: absolute;
  left: 4px; top: 13px;
  width: 9px; height: 9px;
  border-radius: 3px;
  background: var(--ct);
  transform: rotate(45deg);
}
.points li b { color: var(--ct); }
.points .k { font-weight: 900; color: var(--ct); }

/* 範例 */
.example {
  margin-top: auto;
  border: 1px dashed color-mix(in srgb, var(--ct) 40%, var(--line));
  border-radius: 14px;
  padding: 12px 16px;
  background: color-mix(in srgb, var(--ct) 5%, #fff);
}
.ex-head { display: flex; align-items: center; gap: 8px; font-weight: 900; color: var(--ct); font-size: 14px; margin-bottom: 8px; }
.ex-head::before { content: "✎"; }
.ex-q { font-size: 15px; line-height: 1.6; color: var(--ink); }
.ex-toggle {
  margin-top: 12px;
  border: 1px solid var(--ct);
  color: var(--ct);
  background: #fff;
  border-radius: 999px;
  padding: 6px 16px;
  font-weight: 800;
  font-size: 13px;
}
.ex-toggle:hover { background: var(--ct); color: #fff; }
.ex-sol { margin-top: 12px; display: none; }
.ex-sol.show { display: block; animation: slidein 0.25s ease; }
.ex-sol ol { margin: 0; padding-left: 20px; }
.ex-sol li { font-size: 14.5px; line-height: 1.7; margin-bottom: 4px; }
.ex-ans {
  margin-top: 10px;
  font-weight: 900;
  color: #fff;
  background: var(--ct);
  display: inline-block;
  padding: 6px 16px;
  border-radius: 10px;
  font-size: 15px;
}

/* 右：視覺欄 */
.slide-visual {
  position: relative; /* 浮動互動面板（.ictrl）的定位基準 */
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  background: linear-gradient(180deg, #fbfcfe, #f3f6fb);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 20px;
}
.visual-host { flex: 1; display: flex; flex-direction: column; min-height: 0; width: 100%; overflow: hidden; transform-origin: center center; }
.visual-host > * { margin: auto; max-width: 100%; }
/* 繪圖用 SVG 撐滿欄寬並限高 */
.visual-host svg { width: 100%; height: auto; max-height: 100%; display: block; }
/* 但 MathJax 內嵌數學的 SVG 要保留原始尺寸，否則分數會被拉成滿寬而暴大 */
.visual-host mjx-container svg { width: auto !important; height: auto !important; max-height: none !important; display: inline-block; }
.visual-caption { margin-top: 12px; text-align: center; font-size: 13px; color: var(--muted); line-height: 1.55; }

/* 互動控制元件（通用） */
.ictrl { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: center; margin-top: 14px; }
.ictrl label { font-size: 13px; font-weight: 800; color: var(--muted); }
.ictrl input[type="range"] { width: 180px; accent-color: var(--ct); }
/* 寬螢幕：滑桿改為「圖下方一列」，不再浮動蓋住圖形 */
@media (min-width: 641px) {
  .ictrl {
    margin: 10px auto 0; max-width: 100%;
    flex-direction: row; flex-wrap: wrap; align-items: center; justify-content: center; gap: 6px 18px;
    padding: 8px 16px;
    background: rgba(255, 255, 255, 0.92);
    border: 1.5px solid var(--ct); border-radius: 14px;
    box-shadow: 0 4px 14px rgba(23, 32, 51, 0.10);
  }
  .ictrl label { display: flex; align-items: baseline; gap: 8px; }
  .ictrl input[type="range"] { width: 160px; }
  .ictrl .step-txt { max-width: 300px; }
  /* 有滑桿的視覺欄：圖形頂端對齊，讓「圖＋滑桿」由 JS(fitSlide) 當一整組等比縮放，
     不再用固定保留高度硬切 SVG（步驟說明會換行、控制列高度不固定，硬切會裁掉滑桿） */
  .slide-visual:has(.ictrl) .visual-host { justify-content: flex-start; }
  .slide-visual:has(.ictrl) .visual-host > * { margin-top: 0; }
  .slide-visual:has(.ictrl) .visual-host svg { max-height: none; }
}
/* 步驟講解器文字 */
.step-txt { font-size: 12.5px; font-weight: 700; color: var(--ink, #172033); text-align: left; line-height: 1.55; min-height: 1em; }
.step-txt b { color: var(--ct); }
.step-hint { font-weight: 700; color: var(--ct); font-size: 11px; }
.ibtn {
  border: 1px solid var(--ct);
  color: var(--ct);
  background: #fff;
  border-radius: 999px;
  padding: 7px 16px;
  font-weight: 800;
  font-size: 13px;
}
.ibtn:hover { background: var(--ct); color: #fff; }
.ibtn.active { background: var(--ct); color: #fff; }
.ival { font-weight: 900; color: var(--ct); font-size: 15px; min-width: 26px; text-align: center; }
.chiprow { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 12px; }

/* SVG 共用樣式 */
svg .lbl { font-family: "Noto Sans TC", sans-serif; font-weight: 800; }
svg .mth { font-family: "Cambria Math", "Times New Roman", serif; font-style: italic; }
svg .dim { fill: var(--muted); }

/* 控制列 */
.controlbar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 10px 4px 12px;
}
.nav-btn {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 12px;
  padding: 11px 22px;
  font-weight: 800;
  font-size: 15px;
  box-shadow: var(--shadow-sm);
  color: var(--ink);
}
.nav-btn:hover:not(:disabled) { border-color: var(--blue); color: var(--blue); }
.nav-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.progress { flex: 1; max-width: 460px; display: flex; align-items: center; gap: 14px; }
.progress-track { flex: 1; height: 8px; background: #dbe2ee; border-radius: 999px; overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--blue), var(--violet)); border-radius: 999px; transition: width 0.3s ease; }
.progress-text { font-weight: 800; font-size: 13px; color: var(--muted); min-width: 62px; text-align: right; }

/* ===================== 授課教具 ===================== */
/* 側欄收合 → 投影滿版 */
.app.toc-collapsed .toc { display: none; }
.app.toc-collapsed .body { grid-template-columns: 1fr; }

/* 畫筆畫布 */
.pen-canvas { position: fixed; inset: 0; z-index: 800; pointer-events: none; touch-action: none; }
.laser-canvas { position: fixed; inset: 0; z-index: 1150; pointer-events: none; }
.app.pen-on .body { cursor: crosshair; }
.app.laser-on .body { cursor: none; }

/* 雷射點 */
.laser-dot {
  position: fixed; left: 0; top: 0; width: 22px; height: 22px; margin: -11px 0 0 -11px;
  border-radius: 50%; pointer-events: none; z-index: 1200;
  background: radial-gradient(circle, rgba(255,60,60,0.98), rgba(255,0,0,0.55) 55%, rgba(255,0,0,0) 72%);
  box-shadow: 0 0 14px 5px rgba(255,0,0,0.55);
}

/* 浮動工具列 */
.dock {
  position: fixed; right: 14px; top: 50%; transform: translateY(-50%);
  z-index: 1000; display: flex; flex-direction: column; gap: 7px;
  padding: 10px 8px; background: rgba(255,255,255,0.9); backdrop-filter: blur(10px);
  border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow);
}
.dbtn {
  width: 42px; height: 42px; border-radius: 12px; border: 1px solid transparent;
  background: transparent; color: var(--ink); display: grid; place-items: center; transition: background 0.15s, color 0.15s;
}
.dbtn svg { width: 22px; height: 22px; }
.dbtn:hover { background: rgba(37,99,235,0.10); color: var(--blue); }
.dbtn.active { background: var(--blue); color: #fff; }
#dkLaser.active { background: var(--rose); color: #fff; }
#dkPen.active { background: var(--green); color: #fff; }
.dsep { height: 1px; background: var(--line); margin: 2px 5px; }
.dcolors { display: flex; flex-direction: column; gap: 6px; align-items: center; padding: 4px 0; }
.dcolor {
  width: 26px; height: 26px; border-radius: 50%; border: 2px solid #fff;
  box-shadow: 0 0 0 1px var(--line); background: var(--sc); cursor: pointer; padding: 0;
}
.dcolor.active { box-shadow: 0 0 0 3px var(--sc); transform: scale(1.1); }
.derase { width: 34px; height: 34px; }
.derase.active { background: var(--amber); color: #fff; }

/* ===================== 範例／圖解「放大成整頁」 ===================== */
/* 範例框內的放大鈕 */
.ex-zoom {
  margin-left: auto; border: 1px solid var(--ct); color: var(--ct); background: #fff;
  border-radius: 999px; padding: 3px 11px; font-size: 12px; font-weight: 800; line-height: 1.4;
}
.ex-zoom:hover { background: var(--ct); color: #fff; }
/* 視覺欄右上角的放大鈕 */
.vis-zoom {
  position: absolute; top: 10px; right: 12px; z-index: 6;
  border: 1.5px solid var(--ct); color: var(--ct); background: rgba(255, 255, 255, 0.9);
  border-radius: 999px; padding: 5px 13px; font-size: 12.5px; font-weight: 800;
  box-shadow: 0 4px 12px rgba(23, 32, 51, 0.12);
}
.vis-zoom:hover { background: var(--ct); color: #fff; }

/* 放大內容層：z-index 700 < 畫筆畫布(800)，才能用畫筆寫在放大內容上面 */
.zoom-modal {
  position: fixed; inset: 0; z-index: 700; background: #fff;
  overflow: auto; padding: 82px clamp(20px, 5vw, 80px) 56px;
}
.zoom-modal.hidden, .zoom-bar.hidden { display: none !important; }
.zoom-body { position: relative; min-height: 100%; display: flex; flex-direction: column; }
.zoom-q { font-size: clamp(23px, 3.3vw, 42px); line-height: 1.7; color: var(--ink); font-weight: 500; }
.zoom-sol { display: none; margin-top: 28px; padding-top: 20px; border-top: 2px dashed #cdd6e2; }
.zoom-sol.show { display: block; }
.zoom-sol ol { font-size: clamp(19px, 2.7vw, 33px); line-height: 1.9; padding-left: 1.3em; margin: 0; }
.zoom-sol li { margin-bottom: 10px; }
.zoom-ans { margin-top: 20px; font-size: clamp(21px, 2.9vw, 35px); font-weight: 900; color: #fff; background: var(--ct); display: inline-block; padding: 9px 26px; border-radius: 14px; }
/* 圖解模式：放大的視覺 host 撐滿 */
.zoom-body > .visual-host { flex: 1; min-height: 0; }
.zoom-body > .visual-host svg { max-height: 80vh; }

/* 放大控制列：z-index 1300 > 畫筆畫布，按鈕隨時可點 */
.zoom-bar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 1300;
  display: flex; align-items: center; gap: 14px; padding: 12px 20px;
  background: rgba(255, 255, 255, 0.96); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  border-bottom: 3px solid var(--ct, #2563eb);
}
.zoom-badge { flex: 1; font-weight: 900; color: var(--ct, #2563eb); font-size: clamp(14px, 2vw, 18px); }
.zoom-btn { border: 1.5px solid var(--ct, #2563eb); color: var(--ct, #2563eb); background: #fff; border-radius: 999px; padding: 8px 20px; font-weight: 800; font-size: 15px; }
.zoom-btn:hover { background: var(--ct, #2563eb); color: #fff; }
.zoom-x { border-color: #e11d48; color: #e11d48; }
.zoom-x:hover { background: #e11d48; color: #fff; }

/* 右側浮動教具列（.dock）是 fixed 且垂直置中，會壓在投影片右緣上方；
   視窗一矮，教具列就升到「🔍 放大」鈕的高度並蓋住它（dock z-index 1000 > 放大鈕 6）。
   寬螢幕（兩欄不捲動版面）預留一條「教具列車道」，讓投影片內容永遠不進入該區。 */
@media (min-width: 1081px) {
  .stage { padding-right: 86px; }
}

/* 響應式 */
@media (max-width: 1080px) {
  .body { grid-template-columns: 1fr; }
  .toc { position: fixed; inset: 62px 0 0 0; z-index: 30; width: min(320px, 86vw); border-right: 1px solid var(--line); transform: translateX(-105%); transition: transform 0.25s ease; background: #fff; }
  .toc.open { transform: none; box-shadow: var(--shadow); }
  .slide { grid-template-columns: 1fr; overflow-y: auto; }
  .slide-info { overflow: visible; }
  .slide-visual { overflow: visible; }
}
@media (max-width: 640px) {
  .stage { padding: 12px 12px 0; }
  .slide { padding: 20px; gap: 18px; }
  .nav-btn { padding: 10px 14px; font-size: 14px; }
}
