:root {
  color-scheme: light;
  --bg: #f6f5ef;
  --paper: #fffdfa;
  --surface: #ffffff;
  --ink: #22272a;
  --soft-ink: #465350;
  --muted: #6c7774;
  --line: #d9ded8;
  --green: #227864;
  --blue: #315f8c;
  --amber: #a56522;
  --red: #9d443c;
  --wash: #edf4f1;
  --shadow: 0 18px 48px rgba(35, 45, 42, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top left, rgba(237, 244, 241, 0.9), transparent 34rem),
    linear-gradient(180deg, #fffdfa 0, var(--bg) 42rem);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Noto Sans SC", sans-serif;
}

body.drawer-open {
  overflow: hidden;
}

button,
textarea {
  font: inherit;
}

button {
  min-height: 40px;
  border: 1px solid var(--green);
  border-radius: 7px;
  background: var(--green);
  color: #fff;
  padding: 8px 14px;
  font-weight: 800;
  cursor: pointer;
}

button:hover {
  filter: brightness(0.98);
}

button:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(34, 120, 100, 0.22);
  outline-offset: 2px;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.ghost-button {
  border-color: #bfd0c8;
  background: #fff;
  color: var(--green);
}

.text-button {
  border-color: transparent;
  background: transparent;
  color: var(--blue);
  padding-inline: 0;
}

.kicker {
  margin: 0 0 6px;
  color: var(--amber);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 24px;
  align-items: center;
  padding: 20px clamp(18px, 4vw, 52px);
  border-bottom: 1px solid var(--line);
  background: rgba(255, 253, 250, 0.94);
  backdrop-filter: blur(16px);
}

.header-main h1 {
  margin: 0;
  max-width: 760px;
  font-size: clamp(28px, 4vw, 46px);
  line-height: 1.08;
  letter-spacing: 0;
}

.header-main p:last-child {
  margin: 10px 0 0;
  max-width: 760px;
  color: var(--soft-ink);
  font-size: 16px;
  line-height: 1.65;
}

.header-actions,
.chapter-actions,
.mentor-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.status-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-width: 1040px;
  margin: 16px auto 0;
  padding: 0 20px;
}

.status-bar span {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.82);
  padding: 7px 10px;
  color: var(--muted);
  font-size: 13px;
}

.reader-shell {
  width: min(100%, 1040px);
  margin: 0 auto;
  padding: 24px 20px 72px;
}

.chapter-hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 24px;
  align-items: end;
  padding: clamp(24px, 4vw, 38px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(255, 253, 250, 0.98), rgba(237, 244, 241, 0.86)),
    var(--paper);
  box-shadow: var(--shadow);
}

.chapter-hero h2 {
  margin: 0;
  max-width: 820px;
  font-size: clamp(32px, 4.5vw, 56px);
  line-height: 1.08;
  letter-spacing: 0;
}

.chapter-hero p:last-child {
  margin: 14px 0 0;
  max-width: 760px;
  color: var(--soft-ink);
  font-size: 18px;
  line-height: 1.75;
}

.reader-tabs {
  position: sticky;
  top: 108px;
  z-index: 20;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin: 18px 0;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 12px 30px rgba(35, 45, 42, 0.06);
  backdrop-filter: blur(12px);
}

.reader-tabs button {
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}

.reader-tabs button.active {
  border-color: var(--blue);
  background: var(--blue);
  color: #fff;
}

.reader-view {
  display: none;
}

.reader-view.active {
  display: block;
}

.lesson-article {
  max-width: 820px;
  margin: 0 auto;
  padding: clamp(20px, 4vw, 38px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.lesson-article h3,
.wide-section h3 {
  margin: 0 0 12px;
  font-size: clamp(24px, 3vw, 34px);
  line-height: 1.18;
  letter-spacing: 0;
}

.lesson-article h4,
.wide-section h4,
.practice-card h4,
.concept-card h4 {
  margin: 0 0 8px;
  color: var(--ink);
  font-size: 18px;
  line-height: 1.35;
}

.lesson-article p,
.lesson-article li,
.wide-section p,
.wide-section li {
  color: var(--soft-ink);
  font-size: 17px;
  line-height: 1.86;
}

.lesson-article p {
  margin: 0 0 18px;
}

.lesson-article ul,
.lesson-article ol,
.wide-section ul,
.wide-section ol {
  margin: 10px 0 0;
  padding-left: 24px;
}

.reading-lead {
  padding: 18px 20px;
  border-left: 5px solid var(--green);
  border-radius: 8px;
  background: #f3faf7;
}

.reading-lead strong {
  color: var(--green);
}

.chapter-section {
  padding-top: 30px;
  margin-top: 30px;
  border-top: 1px solid var(--line);
}

.professor-thesis {
  padding: 16px 18px;
  border: 1px solid #c7ded7;
  border-radius: 8px;
  background: #f7fbf8;
  color: var(--ink) !important;
  font-weight: 750;
}

.deep-lecture {
  display: grid;
  gap: 18px;
}

.deep-section {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf8;
}

.deep-section h4 {
  margin-bottom: 12px;
  color: var(--blue);
}

.deep-section p:last-of-type {
  margin-bottom: 10px;
}

.deep-section li {
  font-size: 16px;
  line-height: 1.75;
}

.lab-section {
  background: linear-gradient(180deg, rgba(241, 248, 246, 0.92), rgba(255, 255, 255, 0));
}

.lab-mission {
  padding: 14px 16px;
  border: 1px solid #c7ded7;
  border-radius: 8px;
  background: #f6fbf9;
  color: var(--ink) !important;
  font-weight: 700;
}

.lab-list {
  display: grid;
  gap: 14px;
  margin-top: 16px;
}

.lab-card {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  gap: 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.lab-index {
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: var(--green);
  color: #fff;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.lab-body h4 {
  margin-bottom: 12px;
  color: var(--ink);
}

.lab-body dl {
  display: grid;
  grid-template-columns: 86px minmax(0, 1fr);
  gap: 8px 12px;
  margin: 0;
}

.lab-body dt {
  color: var(--muted);
  font-size: 14px;
  font-weight: 900;
}

.lab-body dd {
  min-width: 0;
  margin: 0;
  color: var(--soft-ink);
  font-size: 15px;
  line-height: 1.65;
}

.lab-body code {
  white-space: normal;
  overflow-wrap: anywhere;
}

.route-list {
  display: grid;
  gap: 14px;
  margin-top: 16px;
}

.route-item {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

.route-index,
.module-stage {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 7px;
  background: var(--wash);
  color: var(--blue);
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.wide-section {
  margin-top: 18px;
  padding: clamp(20px, 3vw, 30px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow);
}

.concept-grid,
.practice-grid,
.prompt-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-top: 16px;
}

.concept-card,
.practice-card,
.prompt-card {
  min-height: 132px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.concept-card p,
.practice-card p,
.prompt-card p {
  margin: 0;
  color: var(--soft-ink);
  font-size: 15px;
  line-height: 1.7;
}

.prompt-card {
  text-align: left;
  color: var(--ink);
}

.check-list {
  display: grid;
  gap: 12px;
  margin-top: 16px;
}

.check-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 12px;
  align-items: start;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.check-row input {
  margin-top: 6px;
  accent-color: var(--green);
}

.quiz-answer {
  display: none;
  margin-top: 10px;
  padding: 12px;
  border-radius: 8px;
  background: #f5f7f4;
  color: var(--soft-ink);
  line-height: 1.7;
}

.quiz-answer.visible {
  display: block;
}

.note-area {
  width: 100%;
  min-height: 300px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: #fff;
  color: var(--ink);
  line-height: 1.75;
  resize: vertical;
}

.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(31, 37, 40, 0.18);
  backdrop-filter: blur(2px);
}

.drawer-backdrop[hidden] {
  display: none;
}

.drawer {
  position: fixed;
  top: 18px;
  bottom: 18px;
  z-index: 60;
  width: min(430px, calc(100vw - 28px));
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: var(--shadow);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition:
    opacity 160ms ease,
    transform 180ms ease,
    visibility 180ms ease;
}

.catalog-drawer {
  left: 14px;
  padding: 16px;
  transform: translateX(calc(-100% - 24px));
}

.mentor-drawer {
  right: 14px;
  padding: 16px;
  transform: translateX(calc(100% + 24px));
}

body.catalog-open .catalog-drawer,
body.mentor-open .mentor-drawer {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateX(0);
}

.drawer-head {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: flex-start;
  margin-bottom: 14px;
}

.drawer-head h2 {
  margin: 0;
  font-size: 28px;
  line-height: 1.15;
}

.progress-track {
  height: 9px;
  margin: 12px 0 16px;
  overflow: hidden;
  border: 1px solid #cbd6d0;
  border-radius: 999px;
  background: #edf0eb;
}

.progress-track span {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--green), var(--blue));
}

.module-list {
  display: grid;
  gap: 8px;
}

.module-button {
  width: 100%;
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
  min-height: 86px;
  padding: 12px;
  text-align: left;
  border-color: var(--line);
  background: #fff;
  color: var(--ink);
}

.module-button.active {
  border-color: var(--green);
  background: #eef8f4;
}

.module-button.done {
  border-color: #9fc5b8;
}

.module-copy strong {
  display: block;
  line-height: 1.3;
}

.module-copy span {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.prompt-list {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

.prompt-list button {
  width: 100%;
  height: auto;
  min-height: 42px;
  text-align: left;
  line-height: 1.5;
  border-color: #c7d8d2;
  background: #fff;
  color: var(--blue);
}

#questionInput {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  color: var(--ink);
  background: #fff;
  line-height: 1.65;
  resize: vertical;
}

.mentor-actions {
  justify-content: flex-start;
  margin: 12px 0;
}

.answer-box {
  min-height: 260px;
  max-height: 46vh;
  overflow: auto;
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
  color: #303733;
  font-size: 15px;
  line-height: 1.75;
}

.answer-box h3 {
  margin: 18px 0 8px;
  color: var(--ink);
  font-size: 18px;
  line-height: 1.35;
}

.answer-box h3:first-child {
  margin-top: 0;
}

.answer-box p {
  margin: 0 0 12px;
}

.answer-box ul,
.answer-box ol {
  margin: 8px 0 14px;
  padding-left: 22px;
}

.answer-box li {
  margin: 6px 0;
}

.answer-box strong {
  color: var(--green);
}

.answer-box code {
  border-radius: 5px;
  background: #eef3ef;
  padding: 1px 5px;
  color: #1d3f36;
}

.answer-meta {
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.answer-muted {
  color: var(--muted);
}

.answer-error {
  color: var(--red);
}

.empty-state {
  padding: 24px;
  border: 1px dashed #c7d2cc;
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
}

@media (max-width: 860px) {
  .site-header {
    position: static;
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .header-actions,
  .chapter-actions {
    justify-content: flex-start;
  }

  .chapter-hero {
    grid-template-columns: 1fr;
  }

  .reader-tabs {
    position: static;
  }

  .concept-grid,
  .practice-grid,
  .prompt-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .reader-shell {
    padding-inline: 12px;
  }

  .site-header {
    padding: 16px 14px;
  }

  .status-bar {
    padding-inline: 12px;
  }

  .reader-tabs {
    grid-template-columns: 1fr 1fr;
  }

  .lesson-article,
  .wide-section,
  .chapter-hero {
    padding: 18px;
  }

  .route-item {
    grid-template-columns: 1fr;
  }

  .lab-card {
    grid-template-columns: 1fr;
  }

  .lab-body dl {
    grid-template-columns: 1fr;
  }
}
