/* ============================================================
   大不了自己學 — 人文紙本書 design system
   Tokens → base → topbar → onboarding → workspace shell
   → left panel → center reading → right panel → mobile nav → RWD
   ============================================================ */

:root {
  --paper: #fbf9f4;
  --panel: #f4f1ea;
  --panel-2: #efebe1;
  --ink: #1f1b16;
  --ink-2: #6b6358;
  --ink-3: #9a9385;
  --accent: #2f5d50;
  --accent-strong: #264c41;
  --accent-soft: #e8f0ec;
  --line: #e5e0d6;
  --line-soft: #ede9df;
  --danger: #9a3b2f;
  --danger-soft: #f4e6e2;

  --serif: "Source Serif 4", Georgia, "Songti TC", serif;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "PingFang TC", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;

  --radius: 12px;
  --radius-sm: 8px;
  --topbar-h: 56px;
  --left-w: 260px;
  --right-w: 380px;
  --reading-max: 720px;
  --shadow-pop: 0 14px 38px rgba(31, 27, 22, 0.16);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  font-family: var(--sans);
  font-size: 15px;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button {
  font-family: inherit;
  cursor: pointer;
}

a {
  color: var(--accent);
  text-underline-offset: 2px;
}

::selection {
  background: var(--accent-soft);
}

.page-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

/* ---------------- Topbar ---------------- */

.topbar {
  flex: none;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 18px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  z-index: 30;
}

.topbar-left,
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.pane-toggle {
  display: none;
  flex: none;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-2);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 7px 11px;
}

.pane-toggle:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.pane-toggle.is-active {
  color: var(--accent);
  background: var(--accent-soft);
  border-color: var(--accent);
}

.status-pill {
  font-size: 11.5px;
  font-weight: 500;
  color: var(--ink-2);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 11px;
  white-space: nowrap;
}

.status-pill[data-state="ready"] {
  color: var(--accent);
  background: var(--accent-soft);
  border-color: #cfe0d8;
}

.status-pill[data-state="error"] {
  color: var(--danger);
  background: var(--danger-soft);
  border-color: #e6cbc4;
}

/* ---------------- Project switcher ---------------- */

.project-switcher {
  position: relative;
}

.project-switcher-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 5px 9px 5px 5px;
}

.project-switcher-toggle:hover {
  background: var(--panel);
}

.brand-mark {
  width: 30px;
  height: 30px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-family: var(--serif);
  font-weight: 700;
  font-size: 16px;
}

.project-switcher-copy {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
  text-align: left;
}

.project-switcher-title {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 15px;
  color: var(--ink);
  max-width: 40vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.project-switcher-meta {
  font-size: 11.5px;
  color: var(--ink-3);
}

.project-menu-panel {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  width: 320px;
  max-width: 86vw;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-pop);
  padding: 12px;
  z-index: 40;
}

.project-menu-heading {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.7px;
  text-transform: uppercase;
  color: var(--ink-3);
  padding: 2px 6px 10px;
}

.project-menu-error {
  font-size: 12px;
  color: var(--danger);
  background: var(--danger-soft);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  margin-bottom: 8px;
}

.project-menu-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 320px;
  overflow-y: auto;
}

.project-menu-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 9px 10px;
}

.project-menu-item:hover {
  background: var(--panel);
}

.project-menu-item.is-active {
  background: #fff;
  border-color: var(--line);
}

.project-menu-item-title {
  font-weight: 600;
  font-size: 14px;
}

.project-menu-item-meta {
  font-size: 12px;
  color: var(--ink-3);
}

.project-menu-empty {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 10px;
  font-size: 13px;
  color: var(--ink-2);
}

.project-menu-create {
  width: 100%;
  margin-top: 8px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px;
  font-weight: 600;
  font-size: 13.5px;
}

.project-menu-create:hover {
  background: var(--accent-strong);
}

/* ---------------- Buttons ---------------- */

.primary-button {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 18px;
  font-weight: 600;
  font-size: 14px;
}

.primary-button:hover {
  background: var(--accent-strong);
}

.ghost-button {
  background: transparent;
  color: var(--ink-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font-weight: 500;
  font-size: 13px;
}

.ghost-button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ---------------- Onboarding (start / mission) ---------------- */

.start-view,
.mission-view {
  max-width: 640px;
  margin: 0 auto;
  padding: 64px 28px 80px;
}

.paper-header .eyebrow {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: var(--accent);
}

.paper-header h1 {
  font-family: var(--serif);
  font-weight: 700;
  font-size: 30px;
  line-height: 1.25;
  margin: 10px 0 10px;
}

.paper-header p {
  font-size: 15px;
  color: var(--ink-2);
  line-height: 1.65;
  margin: 0;
}

.topic-chip {
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 999px;
  padding: 4px 12px;
  margin-bottom: 6px;
}

.start-body,
.mission-body {
  margin-top: 26px;
}

.input-row {
  display: flex;
  gap: 10px;
}

.topic-input {
  flex: 1;
  font-family: var(--sans);
  font-size: 15px;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
}

.topic-input:focus,
.mission-textarea:focus,
.answer-textarea:focus,
.rp-composer-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.mission-textarea {
  width: 100%;
  min-height: 130px;
  resize: vertical;
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.6;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 13px 14px;
}

.mission-form .answer-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-top: 14px;
}

/* ---------------- Onboarding: intake (Phase 3a) ---------------- */

.intake-view {
  max-width: 640px;
  margin: 0 auto;
  padding: 64px 28px 80px;
}

.intake-body {
  margin-top: 26px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.intake-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.intake-label {
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  line-height: 1.4;
}

.intake-hint {
  font-size: 13px;
  color: var(--ink-3);
  margin: 0;
  line-height: 1.5;
}

/* Level chips */
.intake-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.intake-chip {
  font-family: var(--sans);
  font-size: 13.5px;
  font-weight: 500;
  color: var(--ink-2);
  background: var(--panel);
  border: 1.5px solid var(--line);
  border-radius: 999px;
  padding: 8px 18px;
  transition: border-color 0.12s, background 0.12s, color 0.12s;
}

.intake-chip:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.intake-chip.is-selected {
  color: var(--accent);
  background: var(--accent-soft);
  border-color: var(--accent);
}

/* Goal input */
.intake-goal-input,
.intake-constraints-input {
  width: 100%;
  font-family: var(--sans);
  font-size: 15px;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
}

.intake-goal-input:focus,
.intake-constraints-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* Clarifying question box */
.intake-clarify-box {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.intake-clarify-question {
  font-size: 14px;
  font-weight: 500;
  color: var(--ink);
  margin: 0;
  line-height: 1.5;
}

.intake-clarify-examples {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.intake-clarify-chip {
  font-family: var(--sans);
  font-size: 12.5px;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid #cfe0d8;
  border-radius: 999px;
  padding: 5px 13px;
  transition: background 0.1s, border-color 0.1s;
}

.intake-clarify-chip:hover {
  background: #d8eae3;
  border-color: var(--accent);
}

/* Action row */
.intake-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.intake-submit {
  margin-left: auto;
}

.intake-skip {
  flex: none;
}

.intake-change-topic {
  flex: none;
}

/* ---------------- Workspace shell ---------------- */

.workspace {
  flex: 1;
  min-height: 0;
  position: relative;
  display: grid;
  grid-template-columns: var(--left-w) minmax(0, 1fr) var(--right-w);
}

.panel {
  min-height: 0;
  overflow-y: auto;
}

.panel-left {
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 18px 14px;
}

.panel-center {
  background: var(--paper);
}

.panel-right {
  background: var(--panel);
  border-left: 1px solid var(--line);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.panel-scrim {
  position: absolute;
  inset: 0;
  background: rgba(31, 27, 22, 0.3);
  z-index: 18;
}

/* Onboarding hides the panels and shows a single centered column */
body[data-mode="onboarding"] .panel-left,
body[data-mode="onboarding"] .panel-right,
body[data-mode="onboarding"] .pane-toggle,
body[data-mode="onboarding"] .panel-scrim {
  display: none;
}

body[data-mode="onboarding"] .workspace {
  grid-template-columns: 1fr;
}

/* ---------------- Left panel: progress ---------------- */

.lp-head {
  padding: 4px 8px 14px;
  border-bottom: 1px solid var(--line-soft);
  margin-bottom: 14px;
}

.lp-title {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 17px;
  margin: 0 0 11px;
  line-height: 1.3;
}

.lp-bar {
  height: 6px;
  border-radius: 999px;
  background: var(--panel-2);
  overflow: hidden;
}

.lp-bar > i {
  display: block;
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.4s ease;
}

.lp-meta {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--ink-2);
  margin-top: 8px;
}

.lp-section-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: var(--ink-3);
  padding: 0 8px;
  margin-bottom: 10px;
}

.lp-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.lp-empty {
  font-size: 13px;
  color: var(--ink-3);
  padding: 8px;
}

.lp-item {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 9px 8px;
}

.lp-item:hover {
  background: var(--panel-2);
}

.lp-item.is-current {
  background: #fff;
  border-color: var(--line);
}

.lp-num {
  flex: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1.5px solid var(--line);
  background: var(--paper);
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-2);
}

.lp-item.is-current .lp-num {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.lp-item.is-done .lp-num {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.lp-item-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.lp-item-title {
  font-size: 13.5px;
  font-weight: 500;
  line-height: 1.35;
}

.lp-item.is-current .lp-item-title {
  font-weight: 600;
}

.lp-item-sub {
  font-size: 11.5px;
  color: var(--ink-3);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lp-footer {
  position: sticky;
  bottom: 0;
  margin-top: 16px;
  padding: 12px 8px calc(4px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line-soft);
  background: var(--panel);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.lp-footer .ghost-button {
  width: 100%;
}

.lp-new-course {
  width: 100%;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px;
  font-weight: 600;
  font-size: 13.5px;
}

.lp-new-course:hover {
  background: var(--accent-strong);
}

/* ---------------- Center: reading column ---------------- */

.reading {
  max-width: var(--reading-max);
  margin: 0 auto;
  padding: 36px 48px 140px;
}

.reading-crumb {
  font-size: 12px;
  color: var(--ink-3);
  letter-spacing: 0.3px;
  margin-bottom: 18px;
}

.lesson-stack {
  display: flex;
  flex-direction: column;
}

.lesson {
  padding-bottom: 36px;
  margin-bottom: 36px;
  border-bottom: 1px solid var(--line);
  outline: none;
}

.lesson:last-child {
  border-bottom: none;
}

.lesson-header .lesson-label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 8px;
}

.lesson-header h2 {
  font-family: var(--serif);
  font-weight: 700;
  font-size: 27px;
  line-height: 1.25;
  margin: 0 0 6px;
}

.lesson-focus {
  font-size: 14.5px;
  color: var(--ink-2);
  line-height: 1.6;
  margin: 0;
}

.callout {
  background: var(--accent-soft);
  border-radius: var(--radius);
  padding: 13px 16px;
  margin: 18px 0;
  font-size: 14.5px;
  line-height: 1.65;
  color: var(--accent-strong);
}

.callout strong {
  font-weight: 600;
}

.lesson-preamble {
  margin: 12px 0 22px;
  font-size: 1.05rem;
  line-height: 1.72;
  color: var(--ink-2);
  font-style: italic;
}

.panel-kicker {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 6px;
}

/* Lesson section */
.lesson-section {
  margin-top: 24px;
  padding: 8px 12px;
  margin-left: -12px;
  margin-right: -12px;
  border-radius: var(--radius);
  border-left: 2px solid transparent;
}

.lesson-section.is-selected {
  background: #fff;
  border-left-color: var(--accent);
  box-shadow: 0 0 0 1px var(--line);
}

.section-selected-tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 6px;
  padding: 3px 8px;
  margin-bottom: 8px;
}

.section-heading {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 6px;
}

.section-heading .num {
  flex: none;
  font-family: var(--serif);
  font-weight: 700;
  font-size: 14px;
  color: var(--accent);
}

.section-heading h3 {
  font-family: var(--serif);
  font-size: 19px;
  font-weight: 600;
  margin: 0;
  line-height: 1.35;
}

.lesson-section > p {
  font-family: var(--serif);
  font-size: 16.5px;
  line-height: 1.78;
  color: #2c2620;
  margin: 0 0 12px;
}

.lesson-section ul,
.lesson-section ol {
  font-family: var(--serif);
  font-size: 16px;
  line-height: 1.7;
  color: #2c2620;
  padding-left: 22px;
  margin: 0 0 12px;
}

.lesson-section li {
  margin-bottom: 5px;
}

.section-ask-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 6px;
}

.section-ask-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--accent);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 6px 12px;
  min-height: 34px;
}

.section-ask-button:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.section-ask-button.is-on {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.section-ask-hint {
  font-size: 11.5px;
  color: var(--ink-3);
}

.lesson-ask-button {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 12px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 7px 13px;
  min-height: 34px;
}

.lesson-ask-button:hover {
  border-color: var(--accent);
}

.lesson-ask-button.is-on {
  background: var(--accent);
  color: #fff;
}

.lesson-header {
  display: flex;
  flex-direction: column;
}

/* Checkpoint / resources / saved answer */
.checkpoint {
  margin-top: 24px;
  background: var(--accent-soft);
  border-radius: var(--radius);
  padding: 16px 18px;
}

.checkpoint h3 {
  font-family: var(--serif);
  font-size: 17px;
  font-weight: 600;
  margin: 4px 0 6px;
}

.checkpoint p {
  font-size: 14.5px;
  line-height: 1.65;
  color: var(--accent-strong);
  margin: 0;
}

.resource-box {
  margin-top: 22px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  background: var(--panel);
}

.resource-box h3 {
  font-family: var(--serif);
  font-size: 16px;
  font-weight: 600;
  margin: 0 0 8px;
}

.answer-frame {
  display: grid;
  gap: 2px;
  font-size: 14px;
  line-height: 1.6;
}

.answer-frame .label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--ink-3);
}

.saved-answer {
  margin-top: 22px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 13px 15px;
  background: var(--panel);
}

/* Immediate answer-check feedback */
.answer-check-loading {
  margin-top: 12px;
  padding: 11px 15px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--ink-2);
  font-size: 14px;
}

.answer-feedback {
  margin-top: 12px;
  padding: 13px 15px 15px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius);
  background: var(--panel);
}

.answer-feedback.is-on-track {
  border-left-color: var(--accent);
  background: var(--accent-soft);
}

.answer-feedback.is-partial {
  border-left-color: #c9923e;
  background: #f8f1e3;
}

.answer-feedback.is-misconception {
  border-left-color: var(--danger);
  background: var(--danger-soft);
}

.answer-feedback-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}

.answer-feedback-badge {
  font-weight: 600;
  font-size: 14px;
  color: var(--ink);
}

.answer-feedback-kicker {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--ink-3);
}

.answer-feedback-body {
  margin: 0;
  font-size: 15px;
  line-height: 1.65;
  color: var(--ink);
}

/* Visual diagram */
.visual-box {
  margin: 20px 0;
}

.visual-box h3 {
  font-family: var(--serif);
  font-size: 16px;
  font-weight: 600;
  margin: 0 0 10px;
}

.visual-frame {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  overflow-x: auto;
}

.diagram-svg {
  width: 100%;
  height: auto;
}

/* rich HTML figure (sandboxed iframe) */
.visual-frame.is-figure {
  background: transparent;
  border: none;
  padding: 0;
  overflow: visible;
}

.figure-frame {
  width: 100%;
  border: 0;
  display: block;
  background: transparent;
  color-scheme: light;
}

.figure-image-wrap {
  width: 100%;
}

.figure-image {
  max-width: 100%;
  height: auto;
  display: block;
  border-radius: 8px;
}

.diagram-node-box {
  fill: var(--paper);
  stroke: var(--accent);
  stroke-width: 1.4;
}

.diagram-node-index {
  fill: var(--accent);
}

.diagram-node-index-text {
  fill: #fff;
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 600;
}

.diagram-node-label {
  fill: var(--ink);
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 500;
}

.diagram-line {
  stroke: var(--ink-3);
  stroke-width: 1.6;
}

.diagram-arrow {
  fill: var(--ink-3);
}

.diagram-edge-label {
  fill: var(--ink-2);
  font-family: var(--sans);
  font-size: 11px;
}

.visual-caption {
  font-size: 12px;
  color: var(--ink-3);
  text-align: center;
  margin: 8px 0 0;
}

/* ----- content-adaptive charts ----- */
.chart-wrap {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chart-svg {
  width: 100%;
  height: auto;
  display: block;
}

.chart-axis {
  stroke: var(--ink-3);
  stroke-width: 1.2;
}

.chart-gridline {
  stroke: var(--line);
  stroke-width: 1;
  stroke-dasharray: 3 3;
}

.chart-seg-label {
  fill: #fff;
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 600;
}

.chart-bar-value {
  fill: var(--ink);
  font-family: var(--sans);
  font-size: 12.5px;
  font-weight: 600;
}

.chart-bar-label {
  fill: var(--ink-2);
  font-family: var(--sans);
  font-size: 12px;
}

.chart-legend {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.chart-legend-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.chart-swatch {
  flex: none;
  width: 12px;
  height: 12px;
  border-radius: 3px;
}

.chart-legend-label {
  font-weight: 500;
  color: var(--ink);
}

.chart-legend-value {
  font-weight: 600;
  color: var(--accent);
}

.chart-legend-hint {
  color: var(--ink-3);
  font-size: 12px;
}

.chart-total {
  display: flex;
  justify-content: space-between;
  border-top: 1px solid var(--line);
  padding-top: 8px;
  font-size: 13px;
  color: var(--ink-2);
}

.chart-total-value {
  font-weight: 700;
  color: var(--ink);
}

/* number line */
.nl-tick {
  fill: var(--ink-2);
  font-family: var(--sans);
  font-size: 12px;
}

.nl-mark-label {
  fill: var(--ink-2);
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 500;
}

.nl-knob {
  cursor: grab;
}

.nl-knob:active {
  cursor: grabbing;
}

.nl-knob-dot {
  fill: var(--accent);
  stroke: #fff;
  stroke-width: 2.5;
  touch-action: none;
}

.nl-readout {
  fill: var(--accent);
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 700;
}

/* function plot */
.plot-curve {
  stroke: var(--accent);
  stroke-width: 2.4;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.plot-axis-label {
  fill: var(--ink-3);
  font-family: var(--sans);
  font-size: 12px;
}

.chart-control {
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.chart-formula {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--ink-2);
}

.chart-control-label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  color: var(--ink-2);
}

.chart-control-value {
  font-weight: 700;
  color: var(--accent);
  font-family: var(--mono);
}

.chart-range {
  width: 100%;
  accent-color: var(--accent);
}

/* compare table */
.visual-table {
  overflow-x: auto;
}

.compare-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

.compare-table th,
.compare-table td {
  border: 1px solid var(--line);
  padding: 9px 11px;
  text-align: left;
  vertical-align: top;
  line-height: 1.5;
}

.compare-table thead th {
  background: var(--panel-2);
  font-weight: 600;
  color: var(--ink);
}

.compare-table .col-row-label {
  background: var(--panel);
  font-weight: 600;
  color: var(--ink);
}

/* tree */
.tree-link {
  stroke: var(--ink-3);
  stroke-width: 1.6;
}

.tree-node {
  fill: var(--paper);
  stroke: var(--accent);
  stroke-width: 1.4;
}

.tree-node-label {
  fill: var(--ink);
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 500;
}

.visual-notes {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.visual-note {
  display: flex;
  gap: 8px;
  font-size: 13.5px;
  line-height: 1.55;
}

.visual-note strong {
  flex: none;
  color: var(--accent);
  font-weight: 600;
}

.visual-note span {
  color: var(--ink-2);
}

/* Formulas */
.formula-box {
  margin: 20px 0;
}

.formula-box h3 {
  font-family: var(--serif);
  font-size: 16px;
  font-weight: 600;
  margin: 0 0 10px;
}

.formula-list {
  display: grid;
  gap: 12px;
}

.formula-item {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
}

.formula-item h4 {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-2);
  margin: 0 0 8px;
}

.math-display {
  overflow-x: auto;
  font-size: 17px;
  color: var(--ink);
}

.formula-item p {
  font-size: 13px;
  color: var(--ink-2);
  line-height: 1.55;
  margin: 8px 0 0;
}

/* Answer composer (next lesson) */
.answer-card {
  margin-top: 28px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  background: var(--panel);
}

.answer-prompt {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
}

.answer-prompt label {
  font-family: var(--serif);
  font-size: 16px;
  line-height: 1.6;
  color: var(--ink);
}

.answer-textarea {
  width: 100%;
  min-height: 84px;
  resize: vertical;
  font-family: var(--sans);
  font-size: 14.5px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px 13px;
}

.answer-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 12px;
}

.answer-hint {
  font-size: 12px;
  color: var(--ink-3);
}

/* States */
.pending-recovery,
.error-box {
  margin-top: 24px;
  border-radius: var(--radius);
  padding: 16px 18px;
}

.pending-recovery {
  background: var(--panel);
  border: 1px dashed var(--line);
}

.pending-recovery h3 {
  font-family: var(--serif);
  font-size: 16px;
  margin: 0 0 4px;
}

.pending-recovery p {
  font-size: 13.5px;
  color: var(--ink-2);
  margin: 0;
}

.error-box {
  background: var(--danger-soft);
  border: 1px solid #e6cbc4;
  display: grid;
  gap: 10px;
}

.error-box p {
  margin: 0;
  font-size: 14px;
  color: var(--danger);
}

.inline-loader {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--ink-2);
  padding: 6px 2px;
}

.inline-loader-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1s ease-in-out infinite;
}

.figure-pending {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin-top: 8px;
  font-size: 13px;
  font-style: italic;
  color: var(--ink-3);
}

.figure-pending::before {
  content: "";
  flex: none;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.6;
  animation: pulse 1.1s ease-in-out infinite;
}

/* Figure generating placeholder — replaces the SVG body while the gpt-image is in flight */
.figure-generating-placeholder {
  min-height: 160px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.figure-generating-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.figure-generating-spinner {
  display: block;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.figure-generating-text {
  font-size: 13px;
  font-style: italic;
  color: var(--ink-3);
  letter-spacing: 0.01em;
}

/* Quiet failure note when gpt-image generation did not succeed */
.figure-unavailable {
  margin: 8px 0 0;
  font-size: 12px;
  font-style: italic;
  color: var(--ink-3);
  opacity: 0.7;
}

.loader-card {
  margin-top: 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
}

.loader-copy .eyebrow {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.7px;
  text-transform: uppercase;
  color: var(--accent);
}

.loader-copy h2 {
  font-family: var(--serif);
  font-size: 18px;
  font-weight: 600;
  margin: 4px 0 0;
}

.dots {
  display: flex;
  gap: 6px;
}

.dots span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.4;
  animation: pulse 1.1s ease-in-out infinite;
}

.dots span:nth-child(2) {
  animation-delay: 0.18s;
}

.dots span:nth-child(3) {
  animation-delay: 0.36s;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 0.35;
    transform: scale(0.85);
  }
  50% {
    opacity: 1;
    transform: scale(1);
  }
}

.is-nav-target {
  animation: nav-flash 1.1s ease;
}

@keyframes nav-flash {
  0% {
    background: var(--accent-soft);
  }
  100% {
    background: transparent;
  }
}

/* ---------------- Right panel: Q&A + notes ---------------- */

.rp-tabs {
  flex: none;
  display: flex;
  gap: 4px;
  padding: 14px 16px 0;
  border-bottom: 1px solid var(--line);
}

.rp-tab {
  flex: 1;
  text-align: center;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-2);
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 8px 4px 10px;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}

.rp-tab:hover:not(.is-active) {
  background: var(--panel-2);
}

.rp-tab.is-active {
  color: var(--accent);
  font-weight: 600;
  border-bottom-color: var(--accent);
}

.rp-chat {
  flex: 1;
  min-height: 0;
  position: relative;
  z-index: 1;
  overflow-y: auto;
  padding: 18px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 13px;
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 18px);
  mask-image: linear-gradient(to bottom, transparent 0, #000 18px);
}

.rp-scope-note {
  font-size: 11.5px;
  color: var(--ink-3);
  text-align: center;
}

.rp-empty {
  font-size: 13px;
  color: var(--ink-3);
  line-height: 1.6;
  text-align: center;
  padding: 8px 6px;
}

.rp-empty-lg {
  margin: auto;
  max-width: 240px;
  padding: 40px 16px;
}

.rp-bubble {
  max-width: 90%;
  font-size: 14px;
  line-height: 1.62;
  padding: 11px 13px;
  border-radius: var(--radius);
}

.rp-bubble.is-user {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.rp-bubble.is-ai {
  align-self: flex-start;
  background: var(--paper);
  border: 1px solid var(--line);
  border-bottom-left-radius: 4px;
}

.rp-ai-name {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 4px;
}

.rp-bubble-text {
  margin: 0;
  white-space: pre-wrap;
}

.rp-bubble-takeaway {
  margin: 8px 0 0;
  font-size: 12.5px;
  color: var(--ink-2);
  border-top: 1px solid var(--line-soft);
  padding-top: 6px;
}

.rp-save-note {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-top: 8px;
  font-size: 11.5px;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid #cfe0d8;
  border-radius: 6px;
  padding: 3px 9px;
  cursor: pointer;
}

.rp-save-note:hover {
  background: #d8eae3;
  border-color: var(--accent);
}

.rp-error {
  font-size: 12.5px;
  color: var(--danger);
  background: var(--danger-soft);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
}

.rp-quote {
  flex: none;
  position: relative;
  z-index: 2;
  margin: 14px 16px 10px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: 0 8px 14px -10px rgba(31, 27, 22, 0.25);
}

.rp-quote-close {
  position: absolute;
  top: 8px;
  right: 8px;
  background: none;
  border: none;
  color: var(--ink-3);
  font-size: 13px;
  line-height: 1;
  padding: 4px;
}

.rp-quote-close:hover {
  color: var(--ink);
}

.rp-quote-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 6px;
  padding: 2px 8px;
}

.rp-quote-where {
  font-size: 11.5px;
  color: var(--ink-3);
  margin: 8px 0 5px;
}

.rp-quote-head {
  font-family: var(--serif);
  font-size: 14.5px;
  font-weight: 600;
  margin-bottom: 5px;
}

.rp-quote-body {
  font-family: var(--serif);
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--ink-2);
}

/* lesson-scope header (整課提問) */
.rp-scope-head {
  flex: none;
  position: relative;
  z-index: 2;
  margin: 14px 16px 10px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 11px 14px;
  box-shadow: 0 8px 14px -10px rgba(31, 27, 22, 0.25);
}

.rp-scope-tag {
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 6px;
  padding: 2px 8px;
}

.rp-scope-where {
  font-family: var(--serif);
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink);
  margin-top: 8px;
}

/* past conversations (依課程分段) */
.rp-past {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 12px 14px 20px;
}

.rp-past-lesson {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 10px 4px 6px;
  margin-top: 6px;
  background: linear-gradient(var(--panel) 70%, rgba(244, 241, 234, 0));
}

.rp-past-lesson:first-child {
  margin-top: 0;
}

.rp-past-lesson-num {
  font-family: var(--serif);
  font-weight: 700;
  font-size: 13px;
  color: var(--accent);
  flex: none;
}

.rp-past-lesson-title {
  font-size: 12.5px;
  color: var(--ink-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rp-past-item {
  display: flex;
  flex-direction: column;
  gap: 5px;
  width: 100%;
  text-align: left;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin-bottom: 6px;
}

.rp-past-item:hover {
  border-color: var(--accent);
  background: #fff;
}

.rp-past-item-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.rp-past-item-tag {
  font-size: 11px;
  font-weight: 600;
  border-radius: 6px;
  padding: 2px 8px;
}

.rp-past-item-tag.is-section {
  color: var(--accent);
  background: var(--accent-soft);
}

.rp-past-item-tag.is-lesson {
  color: var(--ink-2);
  background: var(--panel-2);
}

.rp-past-item-count {
  font-size: 11px;
  color: var(--ink-3);
  flex: none;
}

.rp-past-item-title {
  font-family: var(--serif);
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink);
  line-height: 1.4;
}

.rp-past-item-preview {
  font-size: 12.5px;
  color: var(--ink-2);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.rp-composer {
  flex: none;
  border-top: 1px solid var(--line);
  padding: 12px 14px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
}

.rp-composer-box {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.rp-composer-input {
  flex: 1;
  resize: none;
  font-family: var(--sans);
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 11px 12px;
  min-height: 44px;
  max-height: 140px;
}

.rp-send {
  flex: none;
  width: 44px;
  height: 44px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 16px;
}

.rp-send:hover:not([disabled]) {
  background: var(--accent-strong);
}

.rp-send[disabled] {
  opacity: 0.5;
  cursor: default;
}

.rp-notes {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 8px;
  padding: 40px 28px;
}

.rp-notes-badge {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.5px;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 999px;
  padding: 3px 11px;
}

.rp-notes h3 {
  font-family: var(--serif);
  font-size: 18px;
  margin: 4px 0 0;
}

.rp-notes-copy {
  font-size: 13.5px;
  color: var(--ink-2);
  line-height: 1.65;
  margin: 0;
  max-width: 260px;
}

/* ============================================================
   Phase 3b: North-Star map (left panel rebuild)
   ============================================================ */

/* North Star pinned header */
.ns-head {
  padding: 10px 10px 12px;
  border-bottom: 1px solid var(--line-soft);
  margin-bottom: 10px;
}

.ns-kicker {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--accent);
}

.ns-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-top: 5px;
}

.ns-text {
  flex: 1;
  font-family: var(--serif);
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1.4;
  color: var(--ink);
  margin: 0;
}

.ns-adjust-btn {
  flex: none;
  font-size: 12px;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid #cfe0d8;
  border-radius: 6px;
  padding: 3px 10px;
  white-space: nowrap;
}

.ns-adjust-btn:hover {
  background: #d8eae3;
}

.ns-progress {
  font-size: 11.5px;
  color: var(--ink-3);
  padding: 0 10px 8px;
}

/* Chapter map */
.ns-map {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 2px;
}

.ns-chapter {
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.ns-chapter.is-active {
  background: #fff;
  border: 1px solid var(--line);
}

.ns-chapter.is-mastered {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  opacity: 0.65;
}

.ns-chapter-head {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 9px 10px;
}

.ns-chapter:not(.is-active) .ns-chapter-head:hover {
  background: var(--panel-2);
}

.ns-chapter.is-active .ns-chapter-head {
  border-color: transparent;
}

.ns-chapter-glyph {
  flex: none;
  font-size: 13px;
  color: var(--accent);
  width: 18px;
  text-align: center;
}

.ns-chapter-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  line-height: 1.35;
  flex: 1;
}

.ns-chapter-title-muted {
  font-size: 12.5px;
  color: var(--ink-3);
}

/* Nested lesson list */
.ns-lesson-list {
  padding: 2px 10px 8px 32px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.ns-lesson-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  border-radius: 6px;
  padding: 5px 6px;
}

.ns-lesson-item:hover {
  background: var(--panel-2);
}

.ns-lesson-item.is-current .ns-lesson-glyph {
  color: var(--accent);
  font-weight: 700;
}

.ns-lesson-item.is-done .ns-lesson-glyph {
  color: var(--accent);
}

.ns-lesson-glyph {
  flex: none;
  font-size: 11px;
  color: var(--ink-3);
  width: 16px;
  text-align: center;
}

.ns-lesson-title {
  font-size: 12.5px;
  color: var(--ink-2);
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.ns-lesson-item.is-current .ns-lesson-title {
  font-weight: 600;
  color: var(--ink);
}

.ns-lesson-loading {
  font-size: 12px;
  color: var(--ink-3);
  padding: 4px 6px;
}

/* Extra committed titles */
.ns-extra-toggle {
  font-size: 12.5px;
  color: var(--accent);
  background: transparent;
  border: none;
  text-align: left;
  padding: 8px 10px;
  cursor: pointer;
}

.ns-extra-toggle:hover {
  text-decoration: underline;
}

.ns-extra-list {
  padding: 0 10px 4px 28px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.ns-extra-item {
  font-size: 12px;
  color: var(--ink-3);
  padding: 3px 0;
}

.ns-horizon-caption {
  font-size: 11.5px;
  color: var(--ink-3);
  padding: 6px 10px 4px;
  letter-spacing: 0.2px;
}

/* Mastered toggle */
.ns-mastered-toggle {
  font-size: 12px;
  color: var(--ink-3);
  background: transparent;
  border: 1px solid var(--line-soft);
  border-radius: 6px;
  padding: 5px 10px;
  margin: 6px 0 4px;
  cursor: pointer;
}

.ns-mastered-toggle:hover {
  color: var(--ink-2);
  border-color: var(--line);
}

/* Completed-modules section (top of the map, collapsible, drillable to lessons) */
.ns-completed {
  display: flex;
  flex-direction: column;
  margin: 4px 0 10px;
  border-bottom: 1px solid var(--line-soft);
  padding-bottom: 8px;
}

.ns-completed-toggle {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-2);
  background: transparent;
  border: none;
  text-align: left;
  padding: 6px 10px;
  cursor: pointer;
}

.ns-completed-toggle:hover {
  color: var(--ink);
}

.ns-completed-list {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.ns-chapter.is-completed .ns-chapter-head {
  opacity: 0.82;
}

.ns-chapter.is-completed .ns-chapter-head:hover {
  opacity: 1;
  background: var(--panel-2);
}

.ns-chapter-caret {
  flex: none;
  margin-left: auto;
  font-size: 11px;
  color: var(--ink-3);
}

.ns-lesson-empty {
  font-size: 12px;
  color: var(--ink-3);
  padding: 4px 0;
}

/* Per-module page header in the reading column (page switching: one module shown at a time) */
.module-page-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 0 18px;
  padding: 10px 0 14px;
  border-bottom: 1px solid var(--line);
}

.module-page-titlewrap {
  flex: 1;
  text-align: center;
  min-width: 0;
}

.module-page-kicker {
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.4px;
  color: var(--accent);
}

.module-page-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--ink);
  line-height: 1.3;
  margin-top: 2px;
}

.module-nav-btn {
  flex: none;
  font-size: 12.5px;
  color: var(--ink-2);
  background: transparent;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
  white-space: nowrap;
}

.module-nav-btn:hover:not(:disabled) {
  color: var(--ink);
  border-color: var(--line);
  background: var(--panel-2);
}

.module-nav-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

/* Complete banner */
.ns-complete-banner {
  margin: 12px 8px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 13px;
  font-weight: 600;
  text-align: center;
}

/* Course-complete center banner */
.course-complete-banner {
  margin: 32px 0 16px;
  padding: 24px 32px;
  background: var(--accent-soft);
  border-radius: var(--radius);
  border: 1px solid #cfe0d8;
  text-align: center;
}

.course-complete-banner h2 {
  font-family: var(--serif);
  font-size: 22px;
  font-weight: 700;
  color: var(--accent-strong);
  margin: 0 0 8px;
}

.course-complete-banner p {
  font-size: 14.5px;
  color: var(--accent-strong);
  margin: 0 0 16px;
}

/* ============================================================
   Phase 3b: Lesson cite-row (center column)
   ============================================================ */

.cite-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin: 14px 0 8px;
  padding: 8px 0;
  border-top: 1px solid var(--line-soft);
  font-size: 12.5px;
  color: var(--ink-3);
}

.cite-label {
  color: var(--accent);
  font-weight: 500;
}

.cite-building {
  color: var(--ink-3);
  font-style: italic;
}

.cite-failed {
  color: var(--danger);
  font-size: 12px;
}

.cite-retry-btn {
  font-size: 12px;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid #cfe0d8;
  border-radius: 6px;
  padding: 3px 10px;
  margin-left: 6px;
}

.cite-empty {
  color: var(--ink-3);
  font-size: 12px;
  font-style: italic;
}

.cite-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.cite-chip {
  font-size: 12px;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink-2);
  text-decoration: none;
  transition: border-color 0.1s, background 0.1s;
  cursor: pointer;
}

.cite-chip:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.cite-chip.is-verified {
  border-color: #cfe0d8;
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.cite-chip.is-snippet {
  border-color: var(--line);
  color: var(--ink-2);
}

.cite-chip.is-unverified {
  border-color: #e8d5b0;
  background: #fdf6e3;
  color: #8a6120;
}

/* Calibration / milestone lesson markers */
.lesson.is-calibration .lesson-header::after {
  content: "📊 程度探測";
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  color: #7a6b55;
  background: var(--panel-2);
  border-radius: 5px;
  padding: 2px 8px;
  margin-top: 6px;
}

.lesson.is-milestone .lesson-header::after {
  content: "🏆 關卡題";
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  color: var(--accent-strong);
  background: var(--accent-soft);
  border-radius: 5px;
  padding: 2px 8px;
  margin-top: 6px;
}

/* ============================================================
   Phase 3b: Right panel new tabs (詞庫 / 來源 / 偏好)
   ============================================================ */

.rp-panel-title {
  font-family: var(--serif);
  font-size: 16px;
  font-weight: 600;
  margin: 0 0 12px;
  color: var(--ink);
}

/* Glossary panel */
.rp-glossary {
  flex: 1;
  overflow-y: auto;
  padding: 16px 16px 24px;
}

.rp-glossary-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.rp-glossary-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.rp-glossary-card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 11px 13px;
}

.rp-glossary-term {
  font-weight: 600;
  font-size: 13.5px;
  color: var(--ink);
  margin-bottom: 4px;
}

.rp-glossary-def {
  font-size: 13px;
  color: var(--ink-2);
  line-height: 1.55;
}

/* Sources panel */
.rp-sources {
  flex: 1;
  overflow-y: auto;
  padding: 16px 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.rp-sources-loading {
  font-size: 13.5px;
  color: var(--ink-3);
  font-style: italic;
  padding: 20px 0;
  text-align: center;
}

.rp-sources-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.rp-source-card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 11px 13px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.rp-source-card-head {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  justify-content: space-between;
}

.rp-source-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  line-height: 1.35;
  flex: 1;
}

.rp-source-trust {
  flex: none;
  font-size: 11px;
  font-weight: 600;
  border-radius: 5px;
  padding: 2px 7px;
}

.rp-source-trust.is-verified {
  color: var(--accent-strong);
  background: var(--accent-soft);
}

.rp-source-trust.is-snippet {
  color: var(--ink-2);
  background: var(--panel-2);
}

.rp-source-trust.is-unverified {
  color: #8a6120;
  background: #fdf6e3;
}

.rp-source-site {
  font-size: 11.5px;
  color: var(--ink-3);
}

.rp-source-excerpt-wrap {
  font-size: 12.5px;
  color: var(--ink-2);
  line-height: 1.55;
}

.rp-source-excerpt-wrap summary {
  font-size: 12px;
  color: var(--accent);
  cursor: pointer;
  padding: 2px 0;
}

.rp-source-excerpt {
  margin: 6px 0 0;
  line-height: 1.55;
}

.rp-source-link {
  font-size: 12px;
  color: var(--accent);
  text-decoration: none;
}

.rp-source-link:hover {
  text-decoration: underline;
}

.rp-sources-add {
  border: 1px dashed var(--line);
  border-radius: var(--radius-sm);
  padding: 12px 13px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--panel);
  margin-top: 4px;
}

.rp-sources-add-label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-2);
}

.rp-sources-url-input {
  width: 100%;
  font-family: var(--sans);
  font-size: 13.5px;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
}

.rp-sources-url-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.rp-sources-add-btn {
  align-self: flex-start;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 7px 16px;
  font-size: 13px;
  font-weight: 600;
}

.rp-sources-add-btn:hover:not([disabled]) {
  background: var(--accent-strong);
}

.rp-sources-add-btn[disabled] {
  opacity: 0.55;
  cursor: default;
}

.rp-sources-add-status {
  font-size: 12px;
  color: var(--accent);
}

/* Prefs panel */
.rp-prefs {
  flex: 1;
  overflow-y: auto;
  padding: 16px 16px 24px;
}

.rp-prefs-section {
  margin-bottom: 18px;
}

.rp-prefs-label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-2);
  letter-spacing: 0.4px;
  text-transform: uppercase;
  margin-bottom: 8px;
}

.rp-prefs-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.rp-prefs-chip {
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-2);
  background: var(--panel-2);
  border: 1.5px solid var(--line);
  border-radius: 999px;
  padding: 7px 16px;
  transition: border-color 0.1s, background 0.1s, color 0.1s;
}

.rp-prefs-chip:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.rp-prefs-chip.is-selected {
  color: var(--accent);
  background: var(--accent-soft);
  border-color: var(--accent);
}

.rp-prefs-hint {
  font-size: 12.5px;
  color: var(--ink-3);
  line-height: 1.55;
  margin: 4px 0 0;
}

/* ============================================================
   Responsive
   ============================================================ */

/* Tablet + mobile: panels become overlays over the center column */
@media (max-width: 1199px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  body[data-mode="workspace"] .pane-toggle {
    display: inline-flex;
  }

  .panel-left,
  .panel-right {
    position: absolute;
    top: 0;
    bottom: 0;
    z-index: 20;
    width: 320px;
    box-shadow: var(--shadow-pop);
    transition: transform 0.24s ease;
  }

  .panel-left {
    left: 0;
    transform: translateX(-100%);
  }

  .panel-right {
    right: 0;
    width: 400px;
    max-width: 88%;
    transform: translateX(100%);
  }

  body[data-open-panel="left"] .panel-left {
    transform: none;
  }

  body[data-open-panel="right"] .panel-right {
    transform: none;
  }

  body[data-open-panel="none"] .panel-scrim {
    display: none;
  }

  .reading {
    padding: 30px 32px 120px;
  }
}

/* Mobile: full-screen drawers + bottom nav */
@media (max-width: 767px) {
  :root {
    --reading-max: 100%;
  }

  .panel-left,
  .panel-right {
    width: 100%;
    max-width: 100%;
    box-shadow: none;
  }

  .reading {
    padding: 22px 18px 40px;
  }

  .lesson-header h2 {
    font-size: 23px;
  }

  .lesson-section > p {
    font-size: 16px;
  }

  /* Keep the top bar to two corner buttons + brand */
  .topbar {
    padding: 0 10px;
  }

  body[data-mode="workspace"] .status-pill {
    display: none;
  }

  .pane-toggle {
    padding: 7px 10px;
  }

  .project-switcher-title {
    max-width: 30vw;
  }

  .project-switcher-meta {
    display: none;
  }

  /* iOS Safari auto-zooms (and pushes the send button off-screen) when a focused
     field has font-size < 16px. Pin all text inputs to 16px on mobile. */
  .topic-input,
  .mission-textarea,
  .answer-textarea,
  .rp-composer-input {
    font-size: 16px;
  }
}
