:root {
  --ok: #1a7f37; --warn: #b76e00; --bad: #c0392b;
  --bg: #f6f7f9; --card: #fff; --line: #e3e6ea; --mut: #6b7280; --ink: #1f2328;
}
* { box-sizing: border-box; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans CJK TC", sans-serif;
  margin: 0; background: var(--bg); color: var(--ink); line-height: 1.5;
}
header { background: #1f2328; color: #fff; padding: 18px 24px; }
header h1 { margin: 0; font-size: 19px; }
header .sub { opacity: .8; font-size: 13px; margin-top: 4px; }
/* The bottom padding clears the fixed controls (#progress bottom-left, #float's Note and
   Topics stack bottom-right). On a wide screen they sit in the empty margins, but in a
   narrower window they cover the last card, and without room below it the page cannot
   scroll that card out from under them. */
.wrap { max-width: 920px; margin: 0 auto; padding: 20px 20px 130px; }

.filters { position: sticky; top: 0; z-index: 10; background: var(--bg);
  padding: 12px 0 10px; margin-bottom: 14px; border-bottom: 1px solid var(--line); }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 8px;
  padding: 7px 12px; font-size: 13px; cursor: pointer; color: var(--ink); }
.chip:hover { border-color: #b9bfc7; }
.chip.active { background: #1f2328; color: #fff; border-color: #1f2328; }
/* Quiz · Study · Book: one segmented control, borders collapsed between the three */
.modeseg { display: inline-flex; }
.modeseg .chip { margin: 0; border-radius: 0; font-weight: 600; }
.modeseg .chip + .chip { margin-left: -1px; }
.modeseg .chip:first-child { border-radius: 8px 0 0 8px; }
.modeseg .chip:last-child { border-radius: 0 8px 8px 0; }
.modeseg .chip.active { position: relative; z-index: 1; }
.tsep { width: 1px; align-self: stretch; background: var(--line); margin: 2px 4px; }
.fsel { position: relative; display: inline-flex; }
.fsel select { appearance: none; -webkit-appearance: none; border: 1px solid var(--line);
  background: #fff; border-radius: 8px; padding: 7px 28px 7px 12px; font-size: 13px;
  color: var(--ink); cursor: pointer; font-family: inherit; max-width: 200px; }
.fsel::after { content: '▾'; position: absolute; right: 10px; top: 50%;
  transform: translateY(-50%); pointer-events: none; color: var(--mut); font-size: 11px; }
.fsel.on select { background: #eef2ff; border-color: #9db2ff; color: #2952cc; font-weight: 600; }


.summary { font-size: 14px; color: var(--ink); margin-bottom: 14px; }
.summary b { font-size: 20px; font-weight: 700; }
.summary .sdetail { color: var(--mut); font-size: 13px; }
/* year ticks in the book view's summary line */
.ybar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 8px; }
.ybar-l { font-size: 12px; color: var(--mut); margin-right: 2px; }
.ybox { display: inline-flex; align-items: center; gap: 5px; font-size: 12.5px; cursor: pointer;
  border: 1px solid #ded6ff; background: #f7f5ff; color: #4a34b8; border-radius: 999px;
  padding: 3px 10px 3px 7px; user-select: none; font-variant-numeric: tabular-nums; }
.ybox input { margin: 0; accent-color: #7c5cff; cursor: pointer; }
.ybox-n { color: #8b7fd0; font-size: 11px; }
.ybox.off { background: #fff; border-color: var(--line); color: var(--mut); text-decoration: line-through; }
.ybox.off .ybox-n { color: #b6bcc5; }
.ybar .chip.small { margin: 0; padding: 3px 10px; font-size: 12px; }

.q { background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 18px 20px; margin-bottom: 16px; box-shadow: 0 1px 2px rgba(0,0,0,.04); }
.q .top { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.prov { font-size: 12px; color: var(--mut); font-weight: 600; }
.prov .dot { margin: 0 6px; opacity: .5; }
.badges { display: flex; gap: 6px; flex-wrap: wrap; }
.badge { font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 999px;
  text-transform: uppercase; letter-spacing: .03em; white-space: nowrap; }
.b-correct { background: #e6f4ea; color: var(--ok); }
.b-questionable { background: #fdf1dd; color: var(--warn); }
.b-incorrect { background: #fce8e6; color: var(--bad); }
.b-multi { background: #e8eefc; color: #2952cc; }
.b-conflict { background: #fde8e6; color: var(--bad); }
.b-dispute { background: #f3e8fd; color: #7c3aed; }
.b-diff { background: #eef0f3; color: #444; }

.question { font-size: 15px; font-weight: 600; margin: 8px 0 12px; }
.figs { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 12px; }
.figs img.qfig { max-width: 100%; max-height: 360px; border: 1px solid var(--line);
  border-radius: 8px; background: #fff; cursor: zoom-in; }
.figs img.qfig:hover { box-shadow: 0 2px 8px rgba(0,0,0,.15); }
ul.opts { list-style: none; padding: 0; margin: 0; }
ul.opts li { border: 1px solid var(--line); border-radius: 8px; padding: 9px 12px;
  margin-bottom: 7px; display: flex; gap: 10px; align-items: center; font-size: 14px; }
.opt-key { flex: none; width: 22px; height: 22px; border-radius: 50%; background: #eef0f3;
  color: #444; font-weight: 700; font-size: 12px; display: flex; align-items: center;
  justify-content: center; }
.opt-text { flex: 1; }
.optags { flex: none; margin-left: auto; display: flex; gap: 6px; align-items: center; }
li.key { border-color: var(--ok); background: #f1faf4; }
li.key .opt-key { background: var(--ok); color: #fff; }
li.pick-wrong { border-color: var(--bad); background: #fdecea; }
li.pick-wrong .opt-key { background: var(--bad); color: #fff; }
li.model { border-color: #2952cc; background: #eef2ff; }
li.model .opt-key { background: #2952cc; color: #fff; }
.tag.model { background: #2952cc; }
.ansline { display: flex; flex-wrap: wrap; gap: 8px 10px; align-items: center;
  margin-top: 10px; padding: 8px 12px; border-radius: 8px; font-size: 13px;
  font-weight: 600; }
.ansline b { color: inherit; }
.ansline.agree { background: #e6f4ea; border: 1px solid #b7e0c2; color: var(--ok); }
.ansline.disagree { background: #fce8e6; border: 1px solid #f3c0ba; color: var(--bad); }
.muted { color: var(--mut); font-style: italic; }
li.opt.clickable { cursor: pointer; transition: background .12s, border-color .12s; }
li.opt.clickable:hover { border-color: #1f2328; background: #eef0f3; }
.tag { font-size: 10px; font-weight: 700; padding: 2px 7px; border-radius: 6px;
  white-space: nowrap; background: var(--ok); color: #fff; }
.tag.wrong { background: var(--bad); }
.tag.you { background: var(--bad); }   /* your selection — constant red marker */

.reveal-row { display: flex; align-items: center; gap: 12px; margin-top: 4px; }
.reveal-row .hint { font-size: 12px; color: var(--mut); }
.result { margin-top: 10px; padding: 8px 12px; border-radius: 8px; font-size: 14px; font-weight: 700; }
.result.ok { background: #e6f4ea; color: var(--ok); }
.result.bad { background: #fce8e6; color: var(--bad); }
.result.warn { background: #fdf1dd; color: var(--warn); font-weight: 600; }
.result.warn b { color: inherit; }

.meta-row { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 12px;
  color: var(--mut); margin-top: 12px; }
.expl-wrap { display: grid; grid-template-columns: 1fr; gap: 10px; margin-top: 12px; }
.expl-wrap.two { grid-template-columns: 1fr 1fr; }
.expl { font-size: 13px; color: #374151; background: #fafbfc; border: 1px dashed var(--line);
  border-radius: 8px; padding: 10px 12px; white-space: pre-wrap; }
.expl .hd { font-weight: 700; display: block; margin-bottom: 4px; color: #374151; font-size: 12px; }
.expl.model { background: #f4f8ff; border-color: #cfe0ff; }
.expl .ref { margin-top: 8px; padding-top: 6px; border-top: 1px dotted #cfe0ff;
  font-size: 12px; color: var(--mut); font-style: italic; word-break: break-word; }
.note { margin-top: 10px; padding: 9px 12px; border-radius: 8px; font-size: 13px;
  background: #fde8e6; border-left: 3px solid var(--bad); color: #7a1f17; }
.note .hd { font-weight: 700; }
.empty { text-align: center; color: var(--mut); padding: 40px; }
@media (max-width: 640px) { .expl-wrap.two { grid-template-columns: 1fr; } }

/* ---- inline editor ------------------------------------------------------ */
.q.editing { border-color: #7c5cff; box-shadow: 0 0 0 2px #ece7ff; }
.badge.b-edit { background: #ece7ff; color: #4a34b8; }
.badge.b-editbtn { background: #fff; border: 1px solid var(--line); color: var(--mut);
  cursor: pointer; font: inherit; font-size: 11px; padding: 2px 8px; border-radius: 999px; }
.badge.b-editbtn:hover { border-color: #7c5cff; color: #4a34b8; background: #f7f5ff; }

.editor { margin-top: 10px; }
.editor .ed-l { display: block; font-size: 12px; font-weight: 700; color: #374151;
  margin: 14px 0 4px; }
.editor .ed-hint { font-weight: 400; color: var(--mut); font-size: 11px; margin-left: 6px; }
.editor textarea, .editor input:not([type=checkbox]), .editor select {
  width: 100%; box-sizing: border-box; font: inherit; font-size: 13px;
  border: 1px solid var(--line); border-radius: 7px; padding: 7px 9px;
  background: #fff; color: inherit; resize: vertical; }
.editor textarea:focus, .editor input:focus, .editor select:focus {
  outline: none; border-color: #7c5cff; box-shadow: 0 0 0 3px #ece7ff; }
.ed-opts { display: flex; flex-direction: column; gap: 6px; }
.ed-opt { display: flex; align-items: flex-start; gap: 8px; }
.ed-keybox { flex: none; display: flex; align-items: center; gap: 4px; margin-top: 6px;
  padding: 3px 7px 3px 5px; border: 1px solid var(--line); border-radius: 999px;
  cursor: pointer; background: #fff; user-select: none; }
.ed-keybox:hover { border-color: var(--ok); }
.ed-keybox .ed-key { accent-color: var(--ok); margin: 0; cursor: pointer; }
.ed-keytag { font-size: 10px; font-weight: 700; letter-spacing: .04em;
  text-transform: uppercase; color: var(--mut); }
.ed-opt.is-key .ed-keybox { border-color: var(--ok); background: #e6f4ea; }
.ed-opt.is-key .ed-keytag { color: var(--ok); }
.ed-opt.is-key .ed-otext { border-color: var(--ok); }
.ed-keynow { font-size: 12px; color: #374151; background: #f6f8fa; border-radius: 7px;
  padding: 6px 10px; margin-bottom: 8px; }
.ed-keynow.bad { background: #fce8e6; color: #7a1f17; }
.ed-warn { font-weight: 700; }
.ed-opt .ed-letter { flex: none; width: 20px; margin-top: 8px; font-weight: 700;
  font-size: 12px; color: var(--mut); }
.ed-opt .ed-otext { min-height: 34px; }
.ed-opt .ed-x { flex: none; margin-top: 5px; border: 1px solid var(--line); background: #fff;
  color: var(--mut); border-radius: 6px; cursor: pointer; padding: 4px 8px; font-size: 12px; }
.ed-opt .ed-x:hover { border-color: var(--bad); color: var(--bad); }
.ed-grid2, .ed-grid3 { display: grid; gap: 10px; }
.ed-grid2 { grid-template-columns: 1fr 1fr; }
.ed-grid3 { grid-template-columns: 1fr 1fr 1fr; }
.ed-sep { margin: 18px 0 0; padding-top: 12px; border-top: 1px dashed var(--line);
  font-size: 12px; font-weight: 700; color: #4a34b8; }
.ed-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 16px; }
.ed-note { font-size: 11px; color: var(--mut); }
.ed-note code { background: #f3f4f6; padding: 1px 4px; border-radius: 4px; }
.chip.primary { background: #7c5cff; border-color: #7c5cff; color: #fff; }
.chip.primary:hover { background: #6a48f5; }
.chip.primary:disabled { opacity: .6; cursor: default; }
.chip.danger { color: var(--bad); }
.chip.small { font-size: 11px; padding: 3px 9px; margin-top: 6px; }

#toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 80px);
  background: #1f2430; color: #fff; padding: 10px 16px; border-radius: 8px;
  font-size: 13px; box-shadow: 0 6px 24px rgba(0,0,0,.25); opacity: 0;
  transition: transform .2s, opacity .2s; pointer-events: none; z-index: 50; }
#toast.show { transform: translate(-50%, 0); opacity: 1; }
@media (max-width: 640px) { .ed-grid2, .ed-grid3 { grid-template-columns: 1fr; } }

.q.is-deleted { opacity: .55; border-style: dashed; }
.q.is-deleted .question { text-decoration: line-through; text-decoration-color: #c9ced6; }
.badge.b-deleted { background: #fce8e6; color: var(--bad); }

/* ---- book / topic view --------------------------------------------------- */
.toc { display: flex; flex-direction: column; gap: 8px; }
.toc-sec { border: 1px solid var(--line); border-radius: 10px; background: #fff;
  overflow: hidden; }
.toc-sec.open { border-color: #cfc4ff; }
.toc-sechead { display: flex; align-items: baseline; gap: 10px; width: 100%; text-align: left;
  font: inherit; cursor: pointer; background: #fff; border: 0; padding: 14px 16px; }
.toc-sechead:hover { background: #fbfaff; }
.toc-sec.open .toc-sechead { background: #f7f5ff; border-bottom: 1px solid #ece7ff; }
.toc-caret { color: #7c5cff; font-size: 11px; width: 10px; flex: none; }
.toc-subs { display: flex; flex-direction: column; }
.toc-sub { display: flex; flex-direction: column; align-items: flex-start; gap: 3px;
  width: 100%; text-align: left; font: inherit; cursor: pointer; background: #fff;
  border: 0; border-top: 1px solid #f1f2f4; padding: 11px 16px 11px 38px; }
.toc-sub:hover { background: #fbfaff; }
.toc-subtitle { font-size: 14px; font-weight: 600; color: #1f2430; }
.toc-sechead .toc-meta { margin-left: auto; }
.toc-title { font-size: 15px; font-weight: 700; color: #1f2430; }
.toc-meta { font-size: 12px; color: var(--mut); }
.toc-meta i { color: var(--bad); font-style: italic; }

.chapter { background: #fff; border: 1px solid var(--line); border-left: 4px solid #7c5cff;
  border-radius: 10px; padding: 16px 20px 18px; margin-bottom: 18px; }
.ch-title { margin: 10px 0 12px; font-size: 20px; line-height: 1.35; color: #1f2430; }
.ch-note { font-size: 14px; line-height: 1.75; color: #303743; white-space: pre-wrap; }
.ch-note.empty { color: var(--mut); font-style: italic; }
.ch-count { margin-top: 14px; padding-top: 10px; border-top: 1px dashed var(--line);
  font-size: 12px; color: var(--mut); }

/* ---- wide screens: note left, questions right (see splitActive) ------------------ */
body.split-on .wrap { max-width: 1600px; }
.tsplit { display: grid; grid-template-columns: minmax(380px, 1fr) minmax(0, 1.15fr);
  gap: 22px; align-items: start; }
.tsplit-main { min-width: 0; }
/* The questions scroll with the page; the note keeps its own scroll, pinned under the
   sticky filter bar. overscroll-behavior stops a finished note from dragging the page. */
.tsplit-note { position: sticky; top: calc(var(--filters-h, 60px) + 14px);
  max-height: calc(100vh - var(--filters-h, 60px) - 28px); overflow-y: auto;
  overscroll-behavior: contain; background: #fff; border: 1px solid var(--line);
  border-left: 4px solid #7c5cff; border-radius: 10px; }
.tsn-head { position: sticky; top: 0; z-index: 1; background: #fff; padding: 12px 18px 10px;
  border-bottom: 1px solid var(--line); font-size: 14px; font-weight: 700; color: #1f2430; }
.tsn-body { padding: 14px 18px 24px; }
.tsn-body > :first-child { margin-top: 0; }

/* ---- topics on a card + the topic picker ---------------------------------- */
.qtopics { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 12px; }
.qtopics.none { font-size: 11px; color: #b6bcc5; font-style: italic; }
.tchip { font: inherit; font-size: 11px; cursor: pointer; border: 1px solid #ded6ff;
  background: #f7f5ff; color: #4a34b8; border-radius: 999px; padding: 3px 10px; }
.tchip:hover { border-color: #7c5cff; background: #efeaff; }

.ed-topics { display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
  padding: 8px; border: 1px solid var(--line); border-radius: 8px; background: #fafbfc; }
.ed-tchip { display: inline-flex; align-items: center; gap: 6px; font-size: 12px;
  border: 1px solid #ded6ff; background: #f2eeff; color: #4a34b8;
  border-radius: 999px; padding: 4px 6px 4px 11px; }
.ed-tchip .ed-x { border: 0; background: none; cursor: pointer; color: #8b7fd0;
  font-size: 11px; padding: 0 3px; line-height: 1; }
.ed-tchip .ed-x:hover { color: var(--bad); }
.ed-tadd { display: inline-flex; align-items: center; gap: 6px; flex: 1 1 260px; }
/* The generic `.editor input { width: 100% }` rule would push the section select and
   the Add button off the row, so the picker sizes its own controls. */
.ed-tadd .ed-tinput { flex: 1 1 auto; width: auto; min-width: 130px; font-size: 12px;
  padding: 6px 9px; border: 1px solid var(--line); border-radius: 7px; background: #fff; }
.ed-tadd .ed-tsec { flex: none; font-size: 11px; padding: 5px 6px; max-width: 150px;
  border: 1px solid var(--line); border-radius: 7px; background: #fff; color: var(--mut); }
.ed-tadd .chip.small { margin-top: 0; }

/* ---- bulk filing dialog ---------------------------------------------------- */
.modal-back { position: fixed; inset: 0; background: rgba(20,22,28,.45); z-index: 60;
  display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal { background: #fff; border-radius: 12px; padding: 20px 22px; width: min(560px, 100%);
  box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal h3 { margin: 0 0 4px; font-size: 17px; }
.modal-sub { margin: 0 0 14px; font-size: 12px; color: var(--mut); line-height: 1.5; }
.modal .ed-topics.bulk { background: #fff; }
.modal-actions { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.modal-note { font-size: 12px; color: var(--warn); margin-top: 10px; }

/* ---- floating controls ------------------------------------------------------ */
#float { position: fixed; right: 20px; bottom: 20px; z-index: 55; display: flex;
  flex-direction: column; gap: 8px; align-items: flex-end;
  opacity: 0; transform: translateY(12px); pointer-events: none;
  transition: opacity .18s, transform .18s; }
#float.show { opacity: 1; transform: none; pointer-events: auto; }
#float:empty { display: none; }
#float button { display: flex; align-items: center; gap: 7px; border: 1px solid var(--line);
  background: #fff; color: var(--ink); border-radius: 10px; padding: 9px 13px;
  font: inherit; font-size: 14px; cursor: pointer; box-shadow: 0 4px 16px rgba(0,0,0,.14); }
#float button span { font-size: 11px; font-weight: 600; letter-spacing: .02em; }
#float button:hover { border-color: #7c5cff; color: #4a34b8; }
#float button[data-act="note"] { background: #f7f5ff; border-color: #ded6ff; color: #4a34b8; }

/* ---- question numbering + quiz progress ---------------------------------------- */
.qnum { margin-right: 8px; color: var(--ink); font-weight: 700; font-variant-numeric: tabular-nums; }
#progress { position: fixed; left: 20px; bottom: 20px; z-index: 55; display: flex;
  align-items: center; gap: 2px; border: 1px solid var(--line); background: #fff;
  color: var(--ink); border-radius: 999px; padding: 8px 14px; font: inherit; font-size: 13px;
  cursor: pointer; box-shadow: 0 4px 16px rgba(0,0,0,.14); font-variant-numeric: tabular-nums; }
#progress[hidden] { display: none; }   /* display:flex above would otherwise override [hidden] */
#progress b { font-weight: 700; }
#progress .pg-sep { margin: 0 7px; opacity: .45; }
#progress:hover { border-color: #7c5cff; color: #4a34b8; }
#progress.finished { background: #eaf7ee; border-color: #bfe5cb; color: #1d6b3a; cursor: default; }
@media (max-width: 640px) { #progress { left: 12px; bottom: 12px; padding: 7px 11px; font-size: 12px; } }

/* ---- note panel + image zoom -------------------------------------------------- */
.note-back .note-panel { width: min(760px, 100%); max-height: 84vh; display: flex;
  flex-direction: column; padding: 0; }
.np-head { display: flex; align-items: center; gap: 12px; padding: 16px 20px 12px;
  border-bottom: 1px solid var(--line); }
.np-head h3 { margin: 0; flex: 1; font-size: 16px; }
.np-body { overflow-y: auto; padding: 18px 22px 22px; font-size: 14px; line-height: 1.75; }
.np-meta { display: block; margin-top: 3px; font-size: 12px; font-weight: 400; color: var(--mut); }
.np-empty { color: var(--mut); font-style: italic; }
.np-foot { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap;
  padding: 12px 20px 16px; border-top: 1px solid var(--line); }
.np-foot .chip { margin: 0; }
#float button[data-act="quiz"] { background: #1f2328; border-color: #1f2328; color: #fff; }
.note-fig img { cursor: zoom-in; }
.zoom-back { position: fixed; inset: 0; background: rgba(12,14,18,.9); z-index: 80;
  display: flex; align-items: center; justify-content: center; padding: 24px;
  cursor: zoom-out; }
.zoom-back img { max-width: 100%; max-height: 100%; border-radius: 6px; }

/* ---- topic notes (rendered markdown) --------------------------------------- */
.ch-note { white-space: normal; }
.ch-note p { margin: 0 0 11px; }
.ch-note h3 { font-size: 16px; margin: 20px 0 8px; color: #1f2430; }
.ch-note h4, .ch-note h5 { font-size: 14px; margin: 16px 0 6px; color: #303743; }
.ch-note ul, .ch-note ol { margin: 0 0 12px; padding-left: 22px; }
.ch-note li { margin-bottom: 4px; }
.ch-note code { background: #f3f4f6; padding: 1px 5px; border-radius: 4px; font-size: 92%; }
/* Equations are written as `code` spans. Inside a note's table they read better in the
   text face on a faint tint than in a monospace that wraps mid-formula. */
.ch-note .note-table code, .np-body .note-table code { font-family: inherit; font-size: 100%;
  background: #f4f1ff; color: #2b2250; padding: 1px 6px; white-space: normal; }
.ch-note sup, .np-body sup { font-size: 75%; line-height: 0; }
.ch-note a { color: #4a34b8; }
.note-fig { margin: 14px 0; }
.note-fig img { max-width: 100%; border: 1px solid var(--line); border-radius: 8px;
  display: block; }
.note-fig figcaption { font-size: 12px; color: var(--mut); margin-top: 5px; }
.note-missing { color: var(--bad); font-size: 12px; font-style: italic; }
/* Stands in for a figure in a text-only bundle: deliberate, not a load failure. */
.nofig { display: inline-block; margin: 6px 6px 6px 0; padding: 6px 10px; font-size: 12px;
  color: var(--mut); background: #f6f6fa; border: 1px dashed var(--line); border-radius: 6px; }

/* ---- topic editor ---------------------------------------------------------- */
.ch-bar { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; }
.ch-bar .js-edit-topic { margin-left: auto; }
.toc-actions { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.topic-editor { margin-top: 10px; }
.topic-editor input, .topic-editor textarea, .topic-editor select {
  width: 100%; font: inherit; font-size: 13px; padding: 8px 10px; box-sizing: border-box;
  border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink); }
.topic-editor textarea { line-height: 1.65; resize: vertical; font-size: 14px; }
.topic-editor .ed-l { display: block; font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .04em; color: var(--mut); margin: 14px 0 5px; }
.topic-editor .ed-hint { font-weight: 400; text-transform: none; letter-spacing: 0; }
.tp-tools { display: flex; align-items: center; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.tp-tools .chip.small { margin-top: 0; }
.tp-preview { margin-top: 14px; padding: 14px 16px; background: #faf9ff;
  border: 1px dashed #cfc4ff; border-radius: 10px; font-size: 14px; line-height: 1.75; }
.js-new-section { margin-top: 6px !important; }

/* ---- subtopic management --------------------------------------------------- */
.toc-sechead-wrap { display: flex; align-items: center; gap: 8px; }
.toc-sechead-wrap .toc-sechead { flex: 1; }
.toc-sechead-wrap .js-manage { margin: 0 14px 0 0; flex: none; }
.toc-sub.managing { display: flex; align-items: center; gap: 10px;
  border-top: 1px solid #f1f2f4; padding: 9px 16px 9px 38px; background: #fdfdff; }
.mg-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.mg-title { font: inherit; font-size: 14px; font-weight: 600; color: #1f2430;
  border: 1px solid transparent; border-radius: 6px; padding: 4px 7px; width: 100%;
  background: #fff; box-sizing: border-box; }
.mg-title:hover { border-color: var(--line); }
.mg-title:focus { border-color: #7c5cff; outline: none; }
.mg-main .toc-meta { padding-left: 7px; }
.mg-acts { display: flex; gap: 4px; flex: none; flex-wrap: wrap; justify-content: flex-end; }
.mg-b { font: inherit; font-size: 11px; padding: 4px 8px; border: 1px solid var(--line);
  background: #fff; border-radius: 6px; cursor: pointer; color: var(--ink); }
.mg-b:hover:not(:disabled) { border-color: #7c5cff; color: #4a34b8; }
.mg-b:disabled { opacity: .35; cursor: default; }
.mg-b.danger { color: var(--bad); }
.mg-b.danger:hover { border-color: var(--bad); }
.mg-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 12px 16px 14px 38px; border-top: 1px solid #f1f2f4; background: #f7f5ff; }
.mg-bar .chip { margin-top: 0; }
.modal select.mrg-target { width: 100%; font: inherit; font-size: 13px; padding: 9px 10px;
  border: 1px solid var(--line); border-radius: 8px; background: #fff; }
@media (max-width: 640px) {
  .toc-sub.managing { flex-direction: column; align-items: stretch; padding-left: 20px; }
  .mg-acts { justify-content: flex-start; }
}

/* ---- tables, callouts and dividers inside notes ----------------------------- */
/* A wide comparison table is easier to read scrolled sideways than squeezed: with
   width:100% a 5-column table folded into the 560px note pane wrapped every cell over
   half a dozen lines and became metres tall. So the table takes its natural width
   (min-width keeps a small one filling the pane) and each cell wraps at a comfortable
   measure instead. The shadows on the left and right edges appear only when there is
   more table off-screen — a silently clipped column reads as a missing column. */
.note-table { overflow-x: auto; margin: 14px 0;
  background:
    linear-gradient(to right, #fff 30%, rgba(255,255,255,0)) 0 0,
    linear-gradient(to right, rgba(255,255,255,0), #fff 70%) 100% 0,
    radial-gradient(farthest-side at 0 50%, rgba(40,30,90,.16), rgba(40,30,90,0)) 0 0,
    radial-gradient(farthest-side at 100% 50%, rgba(40,30,90,.16), rgba(40,30,90,0)) 100% 0;
  background-repeat: no-repeat;
  background-size: 40px 100%, 40px 100%, 13px 100%, 13px 100%;
  background-attachment: local, local, scroll, scroll; }
.note-table table { border-collapse: collapse; width: max-content; min-width: 100%;
  font-size: 13px; background: #fff; }
.note-table th, .note-table td { border: 1px solid var(--line); padding: 7px 11px;
  text-align: left; vertical-align: top; max-width: 34ch; }
.note-table th { background: #f7f5ff; font-weight: 700; color: #4a34b8;
  white-space: nowrap; }
.note-table tbody tr:nth-child(even) { background: #fbfbfd; }
.ch-note blockquote { margin: 14px 0; padding: 10px 14px; border-left: 3px solid #7c5cff;
  background: #faf9ff; border-radius: 0 8px 8px 0; color: #303743; }
.ch-note hr { border: 0; border-top: 1px solid var(--line); margin: 20px 0; }

/* ---- chapters and subsections ------------------------------------------------ */
.toc-chap { display: flex; align-items: center; border-top: 1px solid #f1f2f4; background: #fff; }
.toc-chap .toc-chapbtn { border-top: 0; flex: 1; min-width: 0; }
.toc-chap.open .toc-chapbtn, .toc-chap.open { background: #fbfaff; }
.toc-chap .toc-all { margin: 0 14px 0 6px; flex: none; }
/* in the gutter, so chapter titles align whether or not they have subsections */
.toc-chap .toc-caret { display: inline-block; margin-left: -16px; width: 16px; }
.toc-leaves { display: flex; flex-direction: column; }
.toc-sub.leaf { padding-left: 62px; background: #fdfdff; }
.toc-sub.leaf:hover { background: #f7f5ff; }
.toc-sub.leaf .toc-subtitle { font-weight: 500; }
/* A chapter's note: its subsections' notes in order, each under its own title. */
.subnote + .subnote, .ch-note > :not(.subnote) + .subnote { margin-top: 26px; }
.subnote-h { display: flex; align-items: baseline; gap: 10px; width: 100%; text-align: left;
  font: inherit; font-size: 17px; font-weight: 700; color: #3b2a9c; background: none;
  border: 0; border-bottom: 2px solid #e4ddff; padding: 0 0 6px; margin: 0 0 12px; }
button.subnote-h { cursor: pointer; }
button.subnote-h:hover { color: #7c5cff; border-bottom-color: #7c5cff; }
.subnote-n { font-size: 12px; font-weight: 500; color: var(--mut); margin-left: auto; }
.toc-sub.managing.leaf { padding-left: 62px; }
.tc-par { opacity: .62; }
.np-crumb { display: block; margin-bottom: 2px; font-size: 12px; font-weight: 500; color: var(--mut); }
.np-subs { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 20px 4px;
  border-top: 1px solid #f1f2f4; }
.np-foot .np-up { margin-right: auto; }
.ch-crumb { margin-top: 10px; font-size: 12px; color: var(--mut); }
.ch-crumb + .ch-title { margin-top: 2px; }
.ch-subs { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 14px; }
.ch-subs-l { font-size: 12px; color: var(--mut); margin-right: 4px; }
.ch-subs + .ch-note { margin-top: 22px; }
.tp-parent-row { margin-top: 10px; }
.tp-parent-row select { font: inherit; padding: 5px 8px; border: 1px solid var(--line);
  border-radius: 6px; background: #fff; min-width: 240px; max-width: 100%; }

/* ---- hand corrections: original vs now ---------------------------------- */
.edited-box { margin-top: 10px; padding: 9px 12px; border-radius: 8px; font-size: 13px;
  background: #fff8e6; border-left: 3px solid #d99a00; }
.edited-box .hd { font-weight: 700; display: block; margin-bottom: 6px; color: #6b4e00; }
table.chg { border-collapse: collapse; width: 100%; font-size: 12.5px; table-layout: fixed; }
table.chg th, table.chg td { text-align: left; vertical-align: top; padding: 5px 8px;
  border-top: 1px solid var(--line); white-space: pre-wrap; word-break: break-word; }
table.chg thead th { border-top: 0; color: var(--mut); font-weight: 600; font-size: 11.5px; }
table.chg tbody th { width: 118px; color: #374151; font-weight: 600; }
table.chg td.was { color: #8a1c1c; background: #fdf1f1; }
table.chg td.now { color: #135c2b; background: #eef8f1; }
table.chg details summary { cursor: pointer; }
.modal.eh { width: min(920px, 100%); max-height: 88vh; overflow: auto; }
.eh-counts { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.eh-count { background: #f3f4f6; border-radius: 8px; padding: 5px 10px; font-size: 12.5px; }
.eh-item { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-bottom: 10px; }
.eh-head { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap;
  font-size: 12px; color: var(--mut); margin-bottom: 4px; }
.eh-k { display: inline-block; background: #fff3cd; color: #7a5a00; border-radius: 6px;
  padding: 1px 7px; margin-right: 4px; font-weight: 600; }
.eh-k.k-key { background: #fde8e6; color: #9b1c1c; }
.eh-k.k-ai { background: #e8f0ff; color: #1d4ed8; }
.eh-q { font-size: 13.5px; margin: 2px 0 8px; color: var(--ink); }


.progress-status{padding:10px 24px;color:var(--mut);font-size:14px;border-bottom:1px solid var(--line)}

.question-marks{display:flex;gap:8px;flex-wrap:wrap;margin:10px 0}.question-marks .chip{min-height:40px}.question-marks .mark-active{background:#fff3cd;color:#684600;border-color:#c69b24}
