:root {
  color-scheme: light;
  --paper: #f6f3ec;
  --surface: #ede8dd;
  --ink: #2b2927;
  --muted: #635e55;
  --line: #d3ccbd;
  --accent: #31584b;
  --accent-end: #82563b;
  --active: #dfe8dc;
  --code: #eae5da;
  --syntax-keyword: #793951;
  --syntax-value: #325d4e;
  --syntax-number: #855025;
  --inverse: #f6f3ec;
  --ui: Inter, system-ui, sans-serif;
  --serif: Lora, Georgia, serif;
  --mono: "Fira Code", Consolas, monospace;
  --bar-height: 4.5rem;
  --sidebar-width: 20rem;
  --top-offset: var(--bar-height);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --paper: #18191c;
  --surface: #222327;
  --ink: #e4e2dd;
  --muted: #b7b4ab;
  --line: #424448;
  --accent: #a7c9b8;
  --accent-end: #e0ae8e;
  --active: #2c3935;
  --code: #24262a;
  --syntax-keyword: #e4a8c0;
  --syntax-value: #a7c9b8;
  --syntax-number: #e0ae8e;
  --inverse: #18231e;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { background: var(--paper); scroll-padding-top: calc(var(--top-offset) + 1rem); }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 1rem/1.5 var(--ui);
  transition: background-color 180ms ease, color 180ms ease;
}
button { color: inherit; font: inherit; cursor: pointer; }
a { color: var(--accent); text-underline-offset: .17em; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
svg {
  width: 1.25rem;
  height: 1.25rem;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.65;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.sr-only, .skip-link:not(:focus) {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
.skip-link:focus {
  position: fixed;
  z-index: 10;
  top: .75rem;
  left: .75rem;
  padding: .6rem 1rem;
  background: var(--paper);
}

.topbar {
  position: fixed;
  inset: 0 0 auto;
  z-index: 4;
  height: var(--bar-height);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: .5rem;
  padding-inline: clamp(.75rem, 3vw, 2rem);
  border-bottom: 1px solid var(--line);
  background: var(--paper);
  transition: background-color 180ms ease;
}
.identity, .actions { display: flex; align-items: center; gap: .65rem; }
.wordmark {
  color: var(--accent);
  font: 600 clamp(.84rem, 2.4vw, 1.13rem)/1.25 var(--serif);
}
@supports (background-clip: text) {
  .wordmark {
    background: linear-gradient(115deg, var(--accent), var(--accent-end), var(--accent)) 0 / 200%;
    background-clip: text;
    color: transparent;
    animation: wordmark 14s ease-in-out infinite alternate;
  }
}
@keyframes wordmark { to { background-position: 100%; } }
.icon-button, .text-button, .completion-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .55rem;
  min-height: 2.75rem;
  border: 1px solid var(--line);
  border-radius: .5rem;
  background: transparent;
  padding: .46rem .75rem;
  font-size: .875rem;
  font-weight: 600;
  transition: background-color 160ms ease, border-color 160ms ease;
}
.icon-button { min-width: 2.75rem; }
.icon-button:hover, .text-button:hover, .completion-button:hover { background: var(--active); border-color: var(--accent); }
body .sun, [data-theme="dark"] .moon { display: none; }
[data-theme="dark"] .sun { display: block; }
.reading-meter {
  position: fixed;
  z-index: 5;
  inset: 0 0 auto;
  height: 3px;
  pointer-events: none;
}
.reading-meter span {
  display: block;
  height: 100%;
  background: var(--accent);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 140ms ease-out;
}

.sidebar {
  position: fixed;
  inset: var(--bar-height) auto 0 0;
  z-index: 3;
  display: flex;
  flex-direction: column;
  width: var(--sidebar-width);
  background: var(--surface);
  border-right: 1px solid var(--line);
  transition: background-color 180ms ease;
}
.course-progress { padding: 1.65rem 1.45rem 1.25rem; border-bottom: 1px solid var(--line); }
.progress-caption { display: flex; justify-content: space-between; gap: .5rem; font-size: .875rem; font-weight: 700; }
#course-percent { color: var(--accent); font-variant-numeric: tabular-nums; }
#course-meter {
  display: block;
  width: 100%;
  height: .4rem;
  margin-block: .65rem;
  appearance: none;
  border: 0;
  border-radius: 1rem;
  overflow: hidden;
  background: var(--line);
  color: var(--accent);
}
#course-meter::-webkit-progress-bar { background: var(--line); }
#course-meter::-webkit-progress-value { background: var(--accent); }
#course-meter::-moz-progress-bar { background: var(--accent); }
#course-count { margin: 0; color: var(--muted); font-size: .8125rem; }
.sidebar nav { padding: 1.25rem .9rem; overflow-y: auto; overscroll-behavior: contain; }
.nav-title { margin: 0 .55rem .65rem; font-size: .875rem; font-weight: 700; color: var(--muted); }
.sidebar ol { list-style: none; padding: 0; margin: 0; }
.module-link {
  display: grid;
  grid-template-columns: 1.65rem minmax(0, 1fr) 1rem;
  align-items: baseline;
  gap: .4rem;
  padding: .62rem .55rem;
  border-left: 3px solid transparent;
  border-radius: .25rem .45rem .45rem .25rem;
  color: var(--ink);
  font-size: .875rem;
  line-height: 1.4;
  text-decoration: none;
}
.module-link:hover, .module-link[aria-current="page"] { background: var(--active); }
.module-link[aria-current="page"] { border-color: var(--accent); color: var(--accent); font-weight: 700; }
.module-number { color: var(--muted); font: 500 .75rem var(--mono); }
.module-check { color: var(--accent); font-weight: 700; }
.sidebar-footer { margin-top: auto; padding: .9rem 1.45rem; border-top: 1px solid var(--line); }
.sidebar-footer button { width: 100%; justify-content: flex-start; }
.sidebar-closed .sidebar, .reading-mode .sidebar, .reading-mode .topbar { display: none; }

.main {
  min-height: 100dvh;
  margin-left: var(--sidebar-width);
  padding: calc(var(--top-offset) + clamp(2.5rem, 6vw, 5rem)) clamp(1.25rem, 5vw, 5rem) 4rem;
}
.sidebar-closed .main, .reading-mode .main { margin-left: 0; }
.chapter { max-width: 47rem; margin-inline: auto; }
.chapter-heading { padding-bottom: 1.5rem; margin-bottom: 1.85rem; border-bottom: 1px solid var(--line); }
.chapter-number { margin: 0 0 .8rem; color: var(--accent); font-size: .875rem; font-weight: 700; }
h1, .prose h2, .prose h3, dialog h2 { font-family: var(--serif); font-weight: 600; }
h1 { margin: 0; font-size: clamp(2rem, 4.6vw, 3.75rem); line-height: 1.13; letter-spacing: -.035em; text-wrap: balance; overflow-wrap: break-word; }
.prose { font: 400 clamp(1.03rem, 1.6vw, 1.19rem)/1.85 var(--serif); overflow-wrap: break-word; }
.prose > :first-child { margin-top: 0; }
.prose h2 { margin: 1.55em 0 .45em; font-size: 1.45em; line-height: 1.35; }
.prose h3 { font-size: 1.2em; line-height: 1.4; }
.prose p { margin: 0 0 1em; }
.prose img { max-width: 100%; height: auto; }
.prose .lesson-diagram {
  display: block;
  width: 100%;
  margin: 1.5rem auto;
  padding: clamp(.5rem, 2vw, 1.25rem);
  border: 1px solid var(--line);
  border-radius: .6rem;
  background: #f6f3ec;
}
.prose blockquote { margin-inline: 0; padding: .25rem 1rem; border-inline-start: 3px solid var(--accent); color: var(--muted); }
.prose blockquote p:last-child { margin-bottom: 0; }
.prose .table-wrap { overflow-x: auto; }
.prose table { min-width: 100%; border-collapse: collapse; }
.prose th, .prose td { border: 1px solid var(--line); padding: .4em .65em; text-align: start; }
.prose th { background: var(--surface); }
.prose code, kbd { font-family: var(--mono); }
.prose :not(pre) > code { background: var(--code); border-radius: .25rem; padding: .15em .3em; font-size: .84em; }
.prose pre {
  margin-block: 1.3em;
  padding: 1.15rem 1.3rem;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: .6rem;
  background: var(--code);
  font: .875rem/1.7 var(--mono);
}
.hljs-keyword, .hljs-type, .hljs-built_in, .hljs-literal { color: var(--syntax-keyword); font-weight: 500; }
.hljs-string, .hljs-attr, .hljs-name, .hljs-title { color: var(--syntax-value); }
.hljs-number, .hljs-symbol { color: var(--syntax-number); }
.hljs-comment, .hljs-quote { color: var(--muted); font-style: italic; }
.term-button {
  padding: 0;
  border: 0;
  color: var(--accent);
  background: transparent;
  text-decoration: underline dotted;
  text-underline-offset: .18em;
}
.term-button:hover { text-decoration-style: solid; }
.chapter-footer { margin-top: 2.8rem; padding-top: 1.4rem; border-top: 1px solid var(--line); }
.completion-button { background: var(--accent); color: var(--inverse); border-color: var(--accent); }
.completion-button:hover, .completion-button.is-completed { color: var(--accent); background: var(--active); }

dialog {
  width: min(35rem, calc(100% - 2rem));
  max-height: min(75dvh, 38rem);
  padding: 1.5rem;
  border: 1px solid var(--line);
  border-radius: .75rem;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 .75rem 3rem #12141138;
  overscroll-behavior: contain;
}
dialog::backdrop, .scrim { background: #11151280; }
.dialog-header { display: flex; justify-content: space-between; align-items: center; gap: .75rem; border-bottom: 1px solid var(--line); padding-bottom: .85rem; }
dialog h2 { font-size: clamp(1.35rem, 4vw, 1.85rem); margin: 0; }
dialog dt { margin-top: 1rem; font-weight: 700; color: var(--accent); }
dialog dd { margin: .3rem 0 0; font: 1rem/1.7 var(--serif); }
dialog dl:empty { display: none; }

.reading-mode { --top-offset: 0rem; }
.reading-mode .main { padding-bottom: 6.5rem; }
.reading-controls {
  position: fixed;
  z-index: 2;
  inset: auto .75rem .75rem auto;
  display: flex;
  align-items: center;
  gap: .65rem;
  padding: .3rem .4rem .3rem .75rem;
  border: 1px solid var(--line);
  border-radius: .6rem;
  background: var(--paper);
  color: var(--muted);
  font-size: .8125rem;
}

@media (max-width: 48rem) {
  :root { --bar-height: 4rem; }
  .main { margin-left: 0; }
  .sidebar { width: min(21rem, calc(100% - 2.5rem)); }
  .scrim { position: fixed; z-index: 2; inset: var(--bar-height) 0 0; }
  .sidebar-open { overflow: hidden; }
}
@media (max-width: 36rem) {
  #reading-toggle span { display: none; }
  .actions, .identity { gap: .36rem; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
