:root {
  --paper: #f4efe6;
  --ink: #1c1917;
  --muted: #57534e;
  --line: #d6d3d1;
  --accent: #7f1d1d;
  --warn: #c2410c;
  --card: #faf7f2;
  --math: #e4e0d8;
  --max: 1080px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
.ai-machine-notice {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  color: var(--ink);
  font-family: "IBM Plex Sans", system-ui, sans-serif;
  line-height: 1.5;
}

a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { color: #450a0a; }

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: color-mix(in srgb, var(--paper) 92%, white);
  z-index: 10;
}
.brand {
  font-family: Literata, Georgia, serif;
  font-weight: 700;
  font-size: 1.15rem;
  color: var(--ink);
  text-decoration: none;
  letter-spacing: -0.02em;
}
.top-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.85rem 1.1rem;
  align-items: center;
  font-size: 0.92rem;
}
.nav-search { margin: 0; }
.nav-search input {
  font: inherit;
  color: var(--ink);
  background: var(--card);
  border: 1px solid var(--line);
  padding: 0.28rem 0.5rem;
  width: 11rem;
}
.top-nav a { color: var(--muted); text-decoration: none; }
.top-nav a:hover,
.top-nav a.is-active { color: var(--ink); }
.top-nav .quiet { opacity: 0.7; }

.page {
  flex: 1 0 auto;
  width: 100%;
  max-width: var(--max);
  margin: 0 auto;
  padding: 2.5rem 1.5rem 3rem;
}

.site-foot {
  width: 100%;
  max-width: var(--max);
  margin: 0 auto;
  padding: 0 1.5rem 2rem;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.45;
}
.site-foot p { margin: 0; }
.site-foot p + p { margin-top: 0.15rem; }

.hero h1,
.section-head h1,
.lecture-head h1 {
  font-family: Literata, Georgia, serif;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.15;
  margin: 0.2rem 0 0.8rem;
}
.section-head-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem 1.5rem;
  flex-wrap: wrap;
}
.section-head-row h1 {
  margin: 0;
  flex: 1 1 auto;
}
.section-head-row .btn {
  flex: 0 0 auto;
  margin-left: auto;
}
.hero h1 { font-size: clamp(2rem, 4vw, 3rem); max-width: 18ch; }
.kicker {
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.72rem;
  color: var(--muted);
  margin: 0;
}
.lede { color: var(--muted); max-width: 46rem; }

.subject-grid {
  list-style: none;
  padding: 0;
  margin: 2.5rem 0 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1rem;
}
.subject-card {
  display: block;
  background: var(--card);
  border: 1px solid var(--line);
  padding: 1.25rem 1.2rem 1.1rem;
  text-decoration: none;
  color: inherit;
  min-height: 8.5rem;
}
.subject-card:hover { border-color: var(--ink); }
.subject-name {
  display: block;
  font-family: Literata, Georgia, serif;
  font-size: 1.35rem;
  font-weight: 700;
}
.subject-meta { display: block; color: var(--muted); font-size: 0.85rem; margin: 0.35rem 0 0.6rem; }
.subject-card p { margin: 0; color: var(--muted); font-size: 0.92rem; }

.crumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 1.5rem;
}
.crumbs a { color: var(--muted); }
.crumbs span::before,
.crumbs a + a::before { content: "/"; margin-right: 0.4rem; color: var(--line); }

.lecture-list { list-style: none; padding: 0; margin: 1.5rem 0 0; }
.lecture-list li + li { border-top: 1px solid var(--line); }
.lecture-list a {
  display: flex;
  gap: 1rem;
  align-items: baseline;
  padding: 0.85rem 0;
  text-decoration: none;
  color: inherit;
}
.lecture-list a:hover strong { color: var(--accent); }
.lecture-list .num {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  width: 2rem;
}
.lecture-list time { display: block; color: var(--muted); font-size: 0.85rem; }

.lecture-layout {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 2.5rem;
  align-items: start;
}
.toc {
  position: sticky;
  top: 5rem;
  font-size: 0.88rem;
}
.toc-label {
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.68rem;
  color: var(--muted);
}
.toc ol { margin: 0; padding-left: 1.1rem; color: var(--muted); }
.toc a { color: var(--muted); text-decoration: none; }
.toc a:hover { color: var(--ink); }

.chapter { margin: 0 0 2.5rem; }
.chapter h2 {
  font-family: Literata, Georgia, serif;
  font-size: 1.55rem;
  font-weight: 700;
  margin: 0 0 1rem;
  display: flex;
  gap: 0.6rem;
  align-items: baseline;
}
.ch-num { color: var(--accent); font-size: 1rem; font-family: "IBM Plex Sans", sans-serif; }
.prose {
  font-family: Literata, Georgia, serif;
  font-size: 1.08rem;
  line-height: 1.65;
  margin: 0 0 1rem;
}

.math {
  font-family: "IBM Plex Serif", Literata, "Times New Roman", serif;
  font-style: italic;
  font-size: 1.02em;
  background: var(--math);
  padding: 0.1em 0.42em 0.14em;
  border-radius: 2px;
  white-space: nowrap;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}
.math.is-display {
  display: block;
  width: fit-content;
  max-width: 100%;
  margin: 0.85rem auto 1rem;
  padding: 0.7rem 1.15rem;
  font-size: 1.18em;
  text-align: center;
  white-space: normal;
  border-radius: 0;
}

.figure {
  margin: 1.25rem 0 1.6rem;
  background: #efe8dc;
  padding: 0.75rem 0.75rem 0.85rem;
}
.figure img { display: block; width: 100%; height: auto; max-height: 420px; object-fit: contain; background: #fff; }
.figure figcaption { margin-top: 0.55rem; font-size: 0.85rem; color: var(--muted); display: flex; flex-direction: column; gap: 0.2rem; }
.figure .cap { color: var(--ink); }

.ai-warn {
  position: relative;
  display: inline;
  cursor: help;
}
.ai-warn-icon {
  font-size: 0.95em;
  vertical-align: text-bottom;
}
.ai-warn-tip {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 8px);
  transform: translateX(-50%);
  width: min(320px, 70vw);
  background: #1c1917;
  color: #fafaf9;
  font-family: "IBM Plex Sans", sans-serif;
  font-size: 0.8rem;
  line-height: 1.4;
  padding: 0.7rem 0.8rem;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  z-index: 20;
}
.ai-warn:hover .ai-warn-tip,
.ai-warn:focus .ai-warn-tip,
.ai-warn:focus-within .ai-warn-tip {
  opacity: 1;
  visibility: visible;
}

.pager {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 2rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
}
.pager a,
.pager span {
  min-width: 2rem;
  text-align: center;
  padding: 0.25rem 0.4rem;
  text-decoration: none;
  color: var(--muted);
}
.pager .is-current { color: var(--ink); font-weight: 600; border-bottom: 2px solid var(--accent); }

.export-form .fields {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin: 1.5rem 0;
}
.export-form label { display: flex; flex-direction: column; gap: 0.35rem; font-size: 0.85rem; color: var(--muted); }
.export-form input,
.export-form select,
.export-form textarea {
  font: inherit;
  color: var(--ink);
  background: var(--card);
  border: 1px solid var(--line);
  padding: 0.5rem 0.6rem;
}
.export-form textarea { resize: vertical; min-height: 8rem; }

.idea-card {
  background: var(--card);
  border: 1px solid var(--line);
  padding: 1.15rem 1.2rem 1.2rem;
  margin: 1.75rem 0 1.5rem;
  max-width: 40rem;
}
.idea-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem 1rem;
  align-items: baseline;
  margin: 0 0 0.75rem;
  font-size: 0.85rem;
  color: var(--muted);
}
.idea-status {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.72rem;
}
.idea-verdict { font-weight: 600; color: var(--ink); }
.idea-text {
  font-family: Literata, Georgia, serif;
  font-size: 1.05rem;
  line-height: 1.55;
  white-space: pre-wrap;
  margin: 0;
}
.idea-wait { color: var(--muted); margin: 0.9rem 0 0; font-size: 0.92rem; }
.idea-reply {
  margin: 1rem 0 0;
  padding: 0.75rem 0 0;
  border-top: 1px solid var(--line);
}
.idea-reply-label {
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.68rem;
  color: var(--muted);
  margin: 0 0 0.35rem;
}
.idea-reply p + p { margin: 0; }
.idea-form { max-width: 40rem; }
.errorlist { color: var(--warn); list-style: none; padding: 0; margin: 0.2rem 0 0; font-size: 0.8rem; }
.actions { display: flex; gap: 0.75rem; flex-wrap: wrap; }

.btn {
  appearance: none;
  border: 1px solid var(--ink);
  background: var(--ink);
  color: var(--paper);
  font: inherit;
  padding: 0.55rem 1rem;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}
.btn.ghost {
  background: transparent;
  color: var(--ink);
}
.btn:hover { opacity: 0.86; }

.empty { color: var(--muted); }
code { font-size: 0.9em; background: #efe8dc; padding: 0.05em 0.3em; }

.draft-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  margin: 0 0 1.5rem;
  padding: 0.75rem 0.9rem;
  border: 1px dashed var(--line);
  background: var(--card);
  font-size: 0.9rem;
}
.draft-bar form { margin: 0; }

.revisions { margin: 0 0 1.5rem; font-size: 0.88rem; color: var(--muted); }
.revisions ul { list-style: none; padding: 0; margin: 0.6rem 0 0; }
.revisions li {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: center;
  justify-content: space-between;
  padding: 0.35rem 0;
  border-top: 1px solid var(--line);
}

.votes { display: flex; gap: 0.5rem; margin: 0.4rem 0 0; }
.vote-btn {
  appearance: none;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.85rem;
  padding: 0.2rem 0.55rem;
  cursor: pointer;
}
.vote-btn.is-on { border-color: var(--ink); color: var(--ink); }

.prose { position: relative; padding-right: 1.2rem; }
.flag-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: #a8a29e;
  font: inherit;
  font-size: 0.7rem;
  font-weight: 600;
  line-height: 1;
  padding: 0;
  margin-left: 0.25rem;
  cursor: pointer;
  vertical-align: super;
  opacity: 0.35;
}
.prose:hover .flag-btn,
.flag-btn:focus { opacity: 0.85; }

.missed { margin: 2.5rem 0 0; }

.report-dialog {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  padding: 1.1rem 1.2rem 1.2rem;
  width: min(420px, 92vw);
}
.report-dialog::backdrop { background: rgb(28 25 23 / 0.35); }
.report-dialog h2 { font-family: Literata, Georgia, serif; font-size: 1.25rem; margin: 0 0 0.4rem; }
.report-hint { color: var(--muted); font-size: 0.85rem; margin: 0 0 0.8rem; }
.report-dialog textarea {
  width: 100%;
  font: inherit;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--line);
  padding: 0.5rem 0.6rem;
  resize: vertical;
}
.report-error { color: var(--warn); font-size: 0.85rem; }

@media (max-width: 800px) {
  .lecture-layout { grid-template-columns: 1fr; }
  .toc { position: static; }
  .top { flex-direction: column; align-items: flex-start; }
}
