:root {
  color-scheme: light;
  --ink: #161616;
  --muted: #6f665d;
  --paper: #fbfaf7;
  --rule: #ddd6cb;
  --accent: #0f766e;
  --accent-soft: #e2f3ef;
  --pin: #fffdf8;
  --shade: rgb(22 22 22 / 20%);
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: ui-serif, Georgia, Cambria, "Times New Roman", Times, serif;
  line-height: 1.58;
}
header {
  min-height: 54vh;
  display: grid;
  align-content: end;
  padding: 48px clamp(20px, 5vw, 80px) 38px;
  border-bottom: 1px solid var(--rule);
  background: linear-gradient(180deg, #f6f2ea 0%, var(--paper) 100%);
}
h1 {
  max-width: 980px;
  margin: 0;
  font-size: clamp(42px, 8vw, 96px);
  line-height: .9;
  font-weight: 650;
  letter-spacing: 0;
}
.subtitle { margin: 18px 0 0; color: var(--muted); font-size: clamp(18px, 2vw, 26px); }
.layout {
  display: grid;
  grid-template-columns: clamp(220px, 24vw, 340px) minmax(0, 1fr);
  gap: clamp(18px, 3vw, 44px);
  width: 100%;
  margin: 0;
  padding: 26px clamp(18px, 2vw, 34px) 80px 0;
}
aside {
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  padding: 20px 0;
  overflow: auto;
}
main { min-width: 0; }
.stack { display: grid; gap: 8px; padding-left: clamp(10px, 1vw, 18px); }
.pin {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  width: 100%;
  padding: 10px 12px;
  border-left: 3px solid var(--accent);
  border-top: 0;
  border-right: 0;
  border-bottom: 0;
  background: var(--pin);
  box-shadow: 0 1px 0 var(--rule);
  cursor: pointer;
  text-align: left;
  font: inherit;
}
.pin:hover, .pin:focus-visible {
  background: color-mix(in srgb, var(--pin) 82%, var(--accent-soft));
  outline: 1px solid #b9ded6;
}
.pin .num, .number, .toc-link span:first-child, .glossary-meta {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-weight: 750;
}
.pin .num { color: var(--accent); font-size: 13px; line-height: 1.5; }
.pin .txt {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  color: #302b25;
  font-size: 14px;
  line-height: 1.45;
}
.preface { max-width: min(980px, 100%); margin: 10px 0 56px; color: #3b352f; font-size: 18px; white-space: pre-wrap; }
.sentence { padding: 30px 0 38px; border-top: 1px solid var(--rule); scroll-margin-top: 24px; }
.sentence.active .number { color: var(--accent); }
.number { display: inline-flex; min-width: 74px; margin-bottom: 12px; color: var(--muted); font-size: 15px; }
.text { max-width: min(1080px, 100%); font-size: clamp(22px, 2.4vw, 34px); line-height: 1.35; white-space: pre-wrap; }
.text em { font-style: italic; }
.glossary-link {
  border: 0;
  border-bottom: 1px dotted rgb(15 118 110 / 55%);
  padding: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  cursor: pointer;
  -webkit-user-select: text;
  user-select: text;
}
.glossary-link:hover, .glossary-link:focus-visible {
  color: var(--accent);
  border-bottom-style: solid;
  outline: none;
}
.mjx-container { overflow-x: auto; overflow-y: hidden; max-width: 100%; }
.children { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 20px; max-width: 820px; }
.children a {
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid #b9ded6;
  padding: 3px 8px;
  text-decoration: none;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px;
}
.fab {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 20;
  width: 52px;
  height: 52px;
  border: 1px solid rgb(15 118 110 / 35%);
  border-radius: 999px;
  background: var(--accent);
  color: white;
  box-shadow: 0 14px 36px rgb(15 20 18 / 20%);
  cursor: pointer;
  font-size: 0;
}
.fab::before {
  content: "";
  display: block;
  width: 20px;
  height: 14px;
  margin: 18px auto;
  background: linear-gradient(white 0 0) 0 0 / 20px 2px no-repeat,
              linear-gradient(white 0 0) 0 6px / 20px 2px no-repeat,
              linear-gradient(white 0 0) 0 12px / 20px 2px no-repeat;
}
.toc-backdrop {
  position: fixed;
  inset: 0;
  z-index: 18;
  background: var(--shade);
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease;
}
.toc-drawer {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 19;
  width: min(420px, 92vw);
  height: 100vh;
  transform: translateX(100%);
  transition: transform .2s ease;
  border-left: 1px solid var(--rule);
  background: color-mix(in srgb, var(--paper) 96%, white);
  box-shadow: -18px 0 45px rgb(15 20 18 / 14%);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}
body.toc-open .toc-backdrop { opacity: 1; pointer-events: auto; }
body.toc-open .toc-drawer { transform: translateX(0); }
.toc-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 18px 12px;
  border-bottom: 1px solid var(--rule);
}
.toc-title { margin: 0; color: var(--muted); font: 700 13px/1 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; }
.toc-tabs { display: flex; gap: 6px; }
.toc-tab {
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  padding: 5px 9px;
  cursor: pointer;
  font: 700 12px/1 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}
.toc-tab.active { background: var(--accent-soft); color: var(--accent); border-color: #b9ded6; }
.toc-close {
  width: 34px;
  height: 34px;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: transparent;
  cursor: pointer;
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
}
.toc-list { overflow: auto; padding: 10px 10px 28px; }
.toc-link {
  display: grid;
  grid-template-columns: 68px minmax(0, 1fr);
  gap: 8px;
  align-items: baseline;
  padding: 6px 8px;
  margin-left: calc((var(--level) - 1) * 14px);
  color: #332e29;
  text-decoration: none;
  border-left: 2px solid transparent;
}
.toc-link span:first-child { color: var(--muted); font-size: 12px; }
.toc-link span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.toc-link:hover, .toc-link.current { background: var(--accent-soft); border-left-color: var(--accent); }
.glossary-panel {
  position: fixed;
  left: max(18px, calc((100vw - 1420px) / 2 + 34vw + 60px));
  bottom: 24px;
  z-index: 21;
  width: min(520px, calc(100vw - 36px));
  max-height: min(70vh, 620px);
  overflow: auto;
  padding: 18px;
  border: 1px solid var(--rule);
  background: color-mix(in srgb, var(--paper) 97%, white);
  box-shadow: 0 18px 48px rgb(15 20 18 / 18%);
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity .16s ease, transform .16s ease;
}
body.glossary-open .glossary-panel { opacity: 1; transform: translateY(0); pointer-events: auto; }
.glossary-head { display: flex; justify-content: space-between; gap: 14px; align-items: start; }
.glossary-term { margin: 0; font-size: 24px; line-height: 1.1; }
.glossary-close {
  width: 30px;
  height: 30px;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
}
.glossary-meta { margin: 8px 0 0; color: var(--muted); font-size: 12px; }
.glossary-definition { margin: 14px 0 0; color: #2d2823; font-size: 17px; line-height: 1.45; }
.glossary-notes { margin: 12px 0 0; padding-left: 18px; color: #4a423a; font-size: 15px; }
.glossary-refs { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 14px; }
.glossary-refs a {
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid #b9ded6;
  padding: 3px 8px;
  text-decoration: none;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px;
}
.sentence-modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 22;
  background: rgb(22 22 22 / 28%);
  opacity: 0;
  pointer-events: none;
  transition: opacity .16s ease;
}
.sentence-modal {
  position: fixed;
  left: 50%;
  top: 50%;
  z-index: 23;
  width: min(780px, calc(100vw - 34px));
  max-height: min(78vh, 720px);
  overflow: auto;
  padding: clamp(22px, 3vw, 34px);
  border: 1px solid var(--rule);
  background: color-mix(in srgb, var(--paper) 98%, white);
  box-shadow: 0 28px 80px rgb(15 20 18 / 24%);
  transform: translate(-50%, calc(-50% + 10px));
  opacity: 0;
  pointer-events: none;
  transition: opacity .16s ease, transform .16s ease;
}
body.sentence-modal-open .sentence-modal-backdrop { opacity: 1; pointer-events: auto; }
body.sentence-modal-open .sentence-modal { opacity: 1; pointer-events: auto; transform: translate(-50%, -50%); }
.sentence-modal-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 16px;
}
.sentence-modal-number {
  margin: 0;
  color: var(--accent);
  font: 800 22px/1.1 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}
.sentence-modal-path {
  margin: 8px 0 0;
  color: var(--muted);
  font: 700 13px/1.35 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}
.sentence-modal-close {
  width: 34px;
  height: 34px;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 22px;
  line-height: 1;
  flex: 0 0 auto;
}
.sentence-modal-text {
  color: #211d19;
  font-size: clamp(24px, 3vw, 36px);
  line-height: 1.32;
  white-space: pre-wrap;
}
.sentence-modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 22px;
}
.sentence-modal-actions a, .sentence-modal-actions button {
  border: 1px solid #b9ded6;
  background: var(--accent-soft);
  color: var(--accent);
  padding: 7px 11px;
  text-decoration: none;
  cursor: pointer;
  font: 800 13px/1 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}
@media (max-width: 820px) {
  header { min-height: 42vh; }
  .layout { display: block; padding: 0 clamp(16px, 4vw, 64px) 80px; }
  aside {
    z-index: 2;
    height: auto;
    max-height: 42vh;
    margin: 0 calc(clamp(16px, 4vw, 64px) * -1) 18px;
    padding: 10px clamp(16px, 4vw, 64px);
    border-bottom: 1px solid var(--rule);
    background: color-mix(in srgb, var(--paper) 94%, white);
  }
  .pin .txt { -webkit-line-clamp: 2; }
  .sentence { padding: 30px 0 42px; }
  .text { font-size: 24px; }
  .fab { right: 16px; bottom: 16px; }
  .glossary-panel { left: 12px; bottom: 12px; width: calc(100vw - 24px); }
}
