:root {
  color-scheme: light dark;
  --paper: light-dark(#f7f6f1, #151915);
  --white: light-dark(#fffefa, #20251f);
  --ink: light-dark(#232a25, #eceee7);
  --muted: light-dark(#545f55, #b5c0b3);
  --forest: light-dark(#203d30, #d6e7d9);
  --green: light-dark(#315d47, #a8d1b6);
  --wash: light-dark(#eaece4, #29332b);
  --line: light-dark(#d9ddd2, #3a463c);
  --accent: light-dark(#8a6240, #dab48a);
  --header-bg: light-dark(#faf9f4, #1a201a);
  --header-hover: light-dark(#edf0e8, #28382d);
  --image-mat: light-dark(#eeeee7, #252b25);
  --focus: light-dark(#3f7659, #9dd2b7);
  --highlight: light-dark(#fff1bd, #f0cf8a);
  --highlight-ink: light-dark(var(--ink), #261d11);
  --note-bg: light-dark(#fff3d6, #392e1e);
  --note-ink: light-dark(#693a17, #ffce98);
  --note-rule: light-dark(#a96a35, #e2a468);
  --step-disabled: light-dark(#8b9289, #778478);
  --display-font: "Songti TC", "Noto Serif TC", "PMingLiU", Georgia, serif;
  --frame-inset: clamp(.82rem, 2.1vw, 1.5rem);
  font-family: "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  color: var(--ink);
  background: var(--paper);
  --header-height: 3.5rem;
  --slide-bottom-space: 1.5rem;
  --reading-gap: .5rem;
  --reading-top: calc(var(--header-height) + var(--reading-gap));
  scroll-padding-top: var(--reading-top);
}

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

* { box-sizing: border-box; }
body { margin: 0; line-height: 1.7; }
button { font: inherit; cursor: pointer; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }
#slides:focus, .slide-group:focus, .sample-group:focus { outline: none; }
img { max-width: 100%; display: block; }
p, h1, h2, figure { margin: 0; }
.shell { width: min(100% - 2rem, 50rem); margin-inline: auto; }

.skip-link { position: fixed; inset: .5rem auto auto .5rem; z-index: 5; background: var(--white); padding: .55rem; transform: translateY(-150%); }
.skip-link:focus { transform: none; }
.masthead { position: sticky; top: 0; z-index: 4; background: var(--header-bg); color: var(--forest); border-bottom: 1px solid var(--line); }
.masthead-inner { width: min(100% - 2rem, 77rem); display: flex; align-items: center; justify-content: space-between; gap: .65rem; min-height: var(--header-height); font-size: .92rem; font-weight: 650; }

.masthead-actions { display: flex; align-items: center; gap: .75rem; }
.nav-toggle {
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  min-height: 44px;
  padding: .2rem .65rem;
  border: 1px solid var(--line);
  border-radius: .5rem;
  background: var(--white);
  color: var(--forest);
  font-size: .875rem;
  white-space: nowrap;
}
.nav-toggle:hover { background: var(--header-hover); }
.theme-toggle {
  display: grid;
  place-items: center;
  flex-shrink: 0;
  min-height: 44px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: transparent;
}
.theme-toggle:hover .theme-track { border-color: var(--muted); }
.theme-toggle:focus-visible { outline: none; }
.theme-toggle:focus-visible .theme-track { border-color: var(--focus); }
.theme-track {
  --theme-slot: 1.85rem;
  --theme-knob: 1.55rem;
  --theme-inset: .17rem;
  position: relative;
  display: grid;
  grid-template-columns: repeat(2, var(--theme-slot));
  align-items: center;
  justify-items: center;
  height: 2.05rem;
  padding-inline: var(--theme-inset);
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--wash);
}
.theme-thumb {
  position: absolute;
  inset-block-start: 50%;
  inset-inline-start: calc(var(--theme-inset) + (var(--theme-slot) - var(--theme-knob)) / 2);
  width: var(--theme-knob);
  aspect-ratio: 1;
  transform: translateY(-50%);
  border-radius: 50%;
  background: var(--white);
  box-shadow: 0 1px 3px #172b2229;
  transition: transform 170ms ease;
}
.theme-toggle[aria-checked="true"] .theme-thumb {
  transform: translate(var(--theme-slot), -50%);
}
.theme-toggle[hidden] { display: none; }
.theme-icon {
  z-index: 1;
  width: 1rem;
  height: 1rem;
  color: var(--muted);
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.theme-toggle[aria-checked="false"] .theme-icon--sun,
.theme-toggle[aria-checked="true"] .theme-icon--moon { color: var(--green); }
@media (prefers-reduced-motion: reduce) {
  .theme-thumb { transition: none; }
}
.nav-toggle:focus-visible { outline-color: var(--focus); }
#menu-toggle { display: none; }
.menu-icon { position: relative; width: 1rem; height: .8rem; border-block: 2px solid currentColor; }
.menu-icon::after { content: ""; position: absolute; top: calc(50% - 1px); inset-inline: 0; border-top: 2px solid currentColor; }

.lesson-layout {
  --sidebar-width: 248px;
  --sidebar-gap: 1.95rem;
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  gap: var(--sidebar-gap);
  width: min(100% - 2rem, 77rem);
  align-items: start;
  margin: var(--reading-gap) auto 0;
}
.lesson-layout > main { min-width: 0; }

.sidebar { position: sticky; top: var(--reading-top); min-width: 0; }
.chapter-nav {
  padding: .2rem .7rem .8rem .2rem;
  max-height: calc(100dvh - var(--header-height) - 1.2rem);
  overflow-y: auto;
  scrollbar-width: thin;
}
.sidebar-heading { display: flex; align-items: center; justify-content: space-between; gap: .35rem; }
.chapter-nav h2 { color: var(--forest); font-size: 1rem; font-weight: 700; }
.sidebar-toggle {
  display: grid;
  align-items: center;
  justify-items: center;
  flex: 0 0 38px;
  min-height: 38px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: .45rem;
  background: transparent;
  color: var(--green);
}
.sidebar-toggle:hover, .sidebar-toggle:focus-visible { border-color: var(--line); background: var(--wash); }
.sidebar-toggle:focus-visible { outline: none; border-color: var(--focus); }
.sidebar-toggle svg { fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.sidebar-toggle[aria-expanded="false"] .sidebar-toggle-arrow { transform: scaleX(-1); transform-origin: 15px 12px; }
.chapter-list { list-style: none; margin: 0 0 .35rem; padding: 0; }
.chapter-list a {
  display: grid;
  grid-template-columns: 2rem minmax(0, 1fr);
  gap: .25rem;
  min-height: 44px;
  align-items: center;
  padding: .3rem .65rem;
  border-inline-start: 2px solid transparent;
  border-radius: .35rem;
  text-decoration: none;
}
.chapter-list a:hover, .chapter-list a[aria-current] { background: var(--wash); }
.chapter-list a[aria-current] { border-inline-start-color: var(--green); color: var(--forest); font-weight: 700; }
.sidebar-resize {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 100%;
  width: var(--sidebar-gap);
  cursor: col-resize;
  touch-action: none;
}
.sidebar-resize::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 1px;
  height: 100%;
  background: var(--line);
  transform: translate(-50%, -50%);
}
.sidebar-resize:hover::after, .sidebar-resize:focus-visible::after { background: var(--green); }
.lesson-layout.is-resizing { user-select: none; cursor: col-resize; }

.intro { border-bottom: 1px solid var(--line); padding-block: clamp(.9rem, 2.1vw, 1.75rem) clamp(.8rem, 2vw, 1.35rem); }
.lesson-label { font-size: .875rem; color: var(--green); font-weight: 700; }
h1 { color: var(--forest); font-family: var(--display-font); font-size: clamp(1.65rem, 3.15vw, 2.65rem); line-height: 1.26; margin-top: .35rem; font-weight: 700; text-wrap: balance; }
.lesson-body { padding-bottom: calc(2.5rem + var(--slide-scroll-room, 0px)); }
.slide-group { padding-block: .9rem 1.1rem; border-bottom: 1px solid var(--line); }
h2 { font-size: clamp(1.18rem, 3.5vw, 1.5rem); line-height: 1.4; }
.slide-group > h2 { margin-bottom: .65rem; }
.slide {
  --slide-height: calc(100dvh - var(--header-height) - var(--slide-bottom-space));
  display: grid;
  grid-template-rows: max-content minmax(2.75rem, auto) max-content;
  max-block-size: var(--slide-height);
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: .55rem;
  overflow: hidden;
}
.slide + .slide { margin-top: 1.1rem; }
.figure-head { display: flex; justify-content: space-between; align-items: center; gap: .75rem; padding: .44rem var(--frame-inset); font-size: .9rem; font-weight: 650; }
.frame-time {
  display: flex;
  align-items: baseline;
  gap: .4rem;
  flex-shrink: 0;
  color: var(--muted);
  font-size: .75rem;
  font-weight: 400;
  white-space: nowrap;
}
.frame-time time { font: .84rem/1.6 ui-monospace, monospace; }
@media (max-width: 34rem) {
  .frame-time { flex-direction: column; align-items: flex-end; gap: 0; line-height: 1.3; }
}
.open-frame {
  display: grid;
  grid-template: minmax(0, 1fr) / minmax(0, 1fr);
  position: relative;
  min-block-size: 0;
  background: var(--image-mat);
  color: var(--forest);
  cursor: zoom-in;
}
.open-frame:focus-visible { outline: none; }
.open-frame:focus-visible .frame-action {
  outline: 2px solid var(--green);
  outline-offset: 2px;
  border-radius: .3rem;
  background: #ffffffe6;
}
.open-frame img {
  width: 100%;
  height: 100%;
  min-block-size: 0;
  object-fit: contain;
}
.frame-overlay {
  --image-ratio: 1.779755;
  position: absolute;
  inset: 0;
  container-type: size;
  pointer-events: none;
}
.open-frame:has(img[width="640"]) .frame-overlay { --image-ratio: 1.333333; }
.frame-action {
  position: absolute;
  right: max(.55rem, calc((100cqw - 100cqh * var(--image-ratio)) / 2 + .55rem));
  bottom: max(.5rem, calc((100cqh - 100cqw / var(--image-ratio)) / 2 + .5rem));
  color: #173b31;
  width: 1.65rem;
  height: 1.65rem;
  pointer-events: none;
  filter: drop-shadow(0 0 1px white) drop-shadow(0 0 1px white);
}
.frame-action::before, .frame-action::after { content: ""; position: absolute; }
.frame-action::before {
  inset: .14rem auto auto .14rem;
  width: .85rem;
  height: .85rem;
  border: 2px solid currentColor;
  border-radius: 50%;
}
.frame-action::after {
  top: 1.05rem;
  left: 1.05rem;
  width: .58rem;
  height: 2px;
  border-radius: 1px;
  background: currentColor;
  transform: rotate(45deg);
  transform-origin: left center;
}
figcaption {
  max-block-size: max(3rem, calc(var(--slide-height) - 5.35rem));
  overflow: auto;
  padding: .68rem var(--frame-inset) .73rem;
  color: var(--ink);
}
figcaption p { line-break: strict; text-wrap: pretty; }
figcaption .keep-together { white-space: nowrap; }
figcaption p + p { margin-top: .55rem; }
figcaption strong { color: var(--green); }
@media (max-width: 34rem) and (max-height: 42rem) {
  .slide { display: block; max-block-size: none; }
  .open-frame { display: block; }
  .open-frame img { height: auto; }
  figcaption { max-block-size: none; overflow: visible; }
}
figcaption mark {
  padding-inline: .1em;
  border-radius: .15em;
  color: var(--highlight-ink);
  background: var(--highlight);
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}
.reading-cue {
  color: var(--forest);
  font-style: normal;
  font-weight: 700;
  text-decoration: underline;
  text-decoration-color: var(--note-rule);
  text-decoration-thickness: .11em;
  text-underline-offset: .16em;
}

.lightbox {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100dvh;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: clamp(.4rem, 1.3vmin, 1rem);
  border: 0;
  background: transparent;
  overflow: hidden;
}
.lightbox::backdrop {
  background: rgb(16 23 19 / 55%);
  backdrop-filter: blur(8px);
}
.lightbox img { width: 100%; height: 100%; object-fit: contain; }
.lightbox-close {
  position: absolute;
  top: calc(var(--viewport-top, 0px) + max(.75rem, env(safe-area-inset-top)));
  right: calc(var(--viewport-right, 0px) + max(.75rem, env(safe-area-inset-right)));
  min-width: 44px;
  min-height: 44px;
  padding-inline: .75rem;
  border: 1px solid #fff6;
  border-radius: .4rem;
  background: #111e;
  color: #fff;
  transform: scale(var(--viewport-inverse-scale, 1));
  transform-origin: top right;
}
body:has(.lightbox[open]) { overflow: hidden; }

@media (max-width: 55rem) {
  #sidebar-toggle { display: none; }
  #menu-toggle { display: inline-flex; }
  .lesson-layout { display: block; width: 100%; margin: 0; }
  .sidebar { display: none; }
  .lesson-layout.is-menu-open .sidebar {
    display: block;
    position: fixed;
    top: calc(var(--header-height) + .55rem);
    inset-inline: auto .75rem;
    z-index: 3;
    width: min(calc(100% - 1.5rem), 22rem);
    box-shadow: 0 .65rem 2rem #173b3133;
    border-radius: .65rem;
  }
  .chapter-nav { padding: .65rem .75rem; background: var(--white); border: 1px solid var(--line); border-radius: .65rem; }
  .sidebar-resize { display: none; }
}
@media (max-width: 32rem) {
  .masthead-actions { gap: .4rem; }
}

.site-home { color: inherit; text-decoration: none; }
.site-home:hover { text-decoration: underline; }
.site-home:focus-visible { outline-color: var(--focus); }
.course-toc { border-top: 1px solid var(--line); }
.course-toc summary {
  display: grid;
  grid-template-columns: 1.25rem minmax(0, 1fr) .65rem;
  gap: .3rem;
  align-items: start;
  min-height: 44px;
  padding: .55rem .12rem;
  font-weight: 700;
  line-height: 1.45;
  list-style: none;
  cursor: pointer;
}
.course-toc summary::-webkit-details-marker { display: none; }
.course-toc summary::after {
  content: "";
  width: .42rem;
  height: .42rem;
  border: solid var(--green);
  border-width: 0 1.5px 1.5px 0;
  transform: rotate(45deg);
  margin-top: .35rem;
}
.course-toc[open] summary::after { transform: rotate(225deg); margin-top: .53rem; }
.toc-number, .heading-number { font-variant-numeric: tabular-nums; }
.toc-number { color: var(--muted); font-weight: 600; }
.chapter-list a { padding-inline: .5rem .28rem; font-size: .875rem; line-height: 1.48; }
.heading-number { color: var(--green); }
h1 .heading-number { color: var(--accent); font-size: .82em; margin-inline-end: .2em; }
.section-summary {
  margin-bottom: .95rem;
  padding: .85rem var(--frame-inset) .95rem;
  background: var(--white);
  border: 1px solid var(--line);
  border-inline-start: 3px solid var(--green);
  border-radius: .55rem;
}
.section-summary h2 { margin: 0 0 .32rem; color: var(--green); font-size: inherit; }
.section-summary p, .section-summary li { line-break: strict; text-wrap: pretty; }
.section-summary p + p { margin-top: .35rem; }
.section-summary ul, .section-summary ol { margin: 0; padding-inline-start: 1.35em; }
.verify-note { margin-block: .8rem; padding: .75rem .9rem; border-inline-start: 3px solid var(--note-rule); background: var(--note-bg); border-radius: .3rem; }
.verify-note strong { color: var(--note-ink); }
.sample-group h3 { margin: .6rem 0 .48rem; font-size: 1.04rem; color: var(--green); }
.sample-group + .sample-group, .sample-group + .slide { margin-top: 1rem; }

.slide-controls {
  display: grid;
  justify-items: center;
  gap: .12rem;
  padding: .18rem;
  border: 1px solid var(--line);
  border-radius: .65rem;
  background: var(--white);
}
.slide-controls--reading {
  position: fixed;
  z-index: 2;
  inset: 50% max(.45rem, calc((100% - 86rem) / 2)) auto auto;
  transform: translateY(-50%);
  box-shadow: 0 .14rem .5rem #172c2016;
}
.slide-step {
  display: grid;
  place-items: center;
  width: 44px;
  min-height: 44px;
  border: 0;
  border-radius: .45rem;
  background: transparent;
  color: var(--forest);
}
.slide-step:hover:not(:disabled) { background: var(--wash); }
.slide-step:disabled { color: var(--step-disabled); cursor: default; }
.step-icon {
  width: .65rem;
  height: .65rem;
  border: solid currentColor;
  border-width: 0 2px 2px 0;
  transform: translateY(.12rem) rotate(225deg);
}
.slide-step[data-slide-step="1"] .step-icon { transform: translateY(-.12rem) rotate(45deg); }
.slide-position {
  min-width: 4ch;
  text-align: center;
  color: var(--muted);
  font: .75rem/1.65 ui-monospace, monospace;
}
@media (min-width: 55.01rem) {
  .lesson-layout { padding-inline-end: 2.35rem; }
  .lesson-layout.is-sidebar-collapsed { grid-template-columns: 3rem minmax(0, 1fr); }
  .is-sidebar-collapsed .chapter-nav { padding: .2rem; background: var(--white); border: 1px solid var(--line); border-radius: .55rem; }
  .is-sidebar-collapsed .sidebar-heading { justify-content: center; }
  .is-sidebar-collapsed #chapter-nav-title { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .is-sidebar-collapsed #chapter-nav-content,
  .is-sidebar-collapsed .sidebar-resize { display: none; }
  .lesson-body { width: 100%; }
  .intro > .shell { width: 100%; }
}
@media (max-width: 55rem) {
  .slide-controls--reading {
    inset: auto max(.55rem, env(safe-area-inset-right)) max(.55rem, env(safe-area-inset-bottom)) auto;
    grid-template-columns: auto auto auto;
    align-items: center;
    gap: .22rem;
    transform: none;
  }
  .lesson-layout.is-menu-open ~ .slide-controls--reading { visibility: hidden; }
  .intro { margin-inline: 1rem; }
  .intro > .shell { width: 100%; }
  .site-home { font-size: .875rem; }
  figcaption p {
    text-wrap: wrap;
    hanging-punctuation: allow-end;
  }
  .lesson-body { --slide-bottom-space: calc(max(.55rem, env(safe-area-inset-bottom)) + 3.85rem); padding-bottom: calc(5rem + var(--slide-scroll-room, 0px)); }
}

.section-pager {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .75rem;
  margin-top: 1rem;
}
.section-pager a {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 4.3rem;
  border: 1px solid var(--line);
  border-radius: .55rem;
  background: transparent;
  padding: .55rem .75rem;
  color: var(--forest);
  text-decoration: none;
  line-height: 1.4;
}
.section-pager a:hover { background: var(--wash); border-color: #8ca599; }
.section-pager a span { font-size: .875rem; color: var(--green); margin-bottom: .15rem; }
.section-pager--previous { grid-column: 1; }
.section-pager--next { grid-column: 2; text-align: right; }
.section-pager a strong { font-size: .95rem; }
