:root {
  --paper: #f6f2e7;
  --paper-2: #efe9da;
  --ink: #14161a;
  --vermilion: #c0472a;
  --blue: #1e3a5f;
  --success: #2f6b4f;
  --amber: #b07a1e;
  --hairline: #d9d2bf;
  --muted: #6e685a;
  --font-display: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --font-ui: "Avenir Next", Avenir, "Gill Sans", "Helvetica Neue", sans-serif;
  --font-mono: "SF Mono", Menlo, Consolas, monospace;
}

* {
  box-sizing: border-box;
}

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

body {
  font-family: var(--font-ui);
  color: var(--ink);
  background-color: var(--paper);
  background-image: repeating-linear-gradient(
    180deg,
    transparent 0 31px,
    rgba(20, 22, 26, 0.045) 31px 32px
  );
  font-size: 14px;
  line-height: 1.45;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
  border-radius: 2px;
}

button {
  font-family: var(--font-ui);
  cursor: pointer;
  border: 1px solid transparent;
  background: none;
  color: inherit;
  font-size: 13px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ===== Top bar ===== */
.topbar {
  height: 60px;
  flex: 0 0 60px;
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 20px;
  border-bottom: 1px solid var(--hairline);
  background: var(--paper);
}

.wordmark {
  min-width: 210px;
  line-height: 1.15;
}
.wordmark .wm-title {
  font-size: 14px;
  letter-spacing: 0.22em;
  font-weight: 600;
  text-transform: uppercase;
}
.wordmark .wm-sub {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
}

.tabs {
  display: flex;
  align-items: stretch;
  gap: 20px;
  height: 100%;
}
.tab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 0 2px;
  font-size: 13px;
  color: var(--muted);
  height: 100%;
}
.tab[aria-selected="true"] {
  color: var(--ink);
  border-bottom-color: var(--vermilion);
  font-weight: 600;
}
.tab:hover {
  color: var(--ink);
}

.progress {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0;
  background: none;
  border: 0;
  font: inherit;
  color: inherit;
  cursor: pointer;
}
.progress:hover .progress-label {
  color: var(--vermilion);
}
.progress .progress-label {
  font-size: 13px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.track {
  width: 180px;
  height: 6px;
  border: 1px solid var(--hairline);
  background: var(--paper-2);
  border-radius: 3px;
  overflow: hidden;
}
.track .fill {
  height: 100%;
  background: var(--vermilion);
  width: 20%;
  transition: width 0.25s ease;
}

.stats {
  display: flex;
  align-items: center;
  gap: 22px;
}
.stat {
  text-align: right;
  line-height: 1.15;
}
.stat .stat-val {
  display: block;
  font-size: 15px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.stat .stat-lbl {
  display: block;
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.ghost {
  border: 1px solid var(--hairline);
  border-radius: 3px;
  padding: 7px 14px;
  color: var(--ink);
  background: transparent;
}
.ghost:hover {
  border-color: var(--ink);
}

/* ===== Shell ===== */
.shell {
  flex: 1;
  display: flex;
  min-height: 0;
}

/* ===== Left rail ===== */
.rail {
  flex: 0 0 264px;
  border-right: 1px solid var(--hairline);
  padding: 22px 18px;
  overflow-y: auto;
}
.rail .chapter-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 14px;
}
.rail .chapter-label input.scope-all {
  flex: 0 0 14px;
}
.section-row {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  width: 100%;
  padding: 9px 10px 9px 14px;
  border: none;
  border-left: 3px solid transparent;
  margin-bottom: 2px;
  text-align: left;
  font-size: inherit;
  line-height: inherit;
}
.section-row .sr-check {
  flex: 0 0 14px;
  width: 14px;
  height: 14px;
  margin-top: 1px;
  border: 1px solid var(--muted);
  border-radius: 2px;
  background: transparent;
  position: relative;
}
.section-row[aria-pressed="true"] .sr-check {
  background: var(--vermilion);
  border-color: var(--vermilion);
}
.section-row[aria-pressed="true"] .sr-check::after {
  content: "";
  position: absolute;
  left: 3px;
  top: 1px;
  width: 4px;
  height: 7px;
  border: solid var(--paper);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
.section-row .sr-body {
  flex: 1;
  min-width: 0;
}
.section-row .sr-reco-dot {
  flex: 0 0 7px;
  width: 7px;
  height: 7px;
  border: 1.5px solid var(--vermilion);
  border-radius: 50%;
  align-self: center;
}
.section-row[aria-pressed="false"] .sr-title,
.section-row[aria-pressed="false"] .sr-count,
.section-row[aria-pressed="false"] .sr-bar {
  opacity: 0.4;
}
.section-row.current {
  border-left-color: var(--vermilion);
  background: rgba(192, 71, 42, 0.04);
}
.section-row .sr-top {
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.section-row .sr-num {
  flex: 0 0 26px;
  width: 26px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--muted);
}
.section-row.current .sr-num {
  color: var(--vermilion);
}
.section-row .sr-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  font-weight: 400;
}
.section-row.current .sr-title {
  font-weight: 600;
}
.section-row .sr-count {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--muted);
  white-space: nowrap;
}
.section-row .sr-bar {
  display: block;
  height: 3px;
  background: var(--hairline);
  margin-top: 6px;
  border-radius: 2px;
  overflow: hidden;
}
.section-row .sr-bar i {
  display: block;
  height: 100%;
  background: var(--blue);
}

.due-block {
  margin-top: 22px;
  border: 1px solid var(--hairline);
  border-radius: 3px;
  padding: 14px;
}
.due-block .due-title {
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 2px;
}
.due-block .due-sub {
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 12px;
}
.due-block .ghost {
  width: 100%;
}

.keys {
  margin-top: 22px;
  font-size: 11px;
  color: var(--muted);
  line-height: 1.9;
}
.keys .keys-title {
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 6px;
}
.keys kbd {
  font-family: var(--font-mono);
  border: 1px solid var(--hairline);
  border-radius: 3px;
  padding: 0 5px;
  font-size: 10px;
  background: var(--paper-2);
}

/* ===== Center ===== */
.center {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  padding: 30px clamp(32px, 2.5vw, 40px) 40px;
  display: flex;
  justify-content: center;
}
.center-inner {
  width: 100%;
  max-width: 1000px;
}

.view {
  display: none;
}
.view.active {
  display: block;
}

/* Problem card */
.problem-card {
  background: var(--paper);
  border: 1px solid var(--hairline);
  border-radius: 3px;
  box-shadow: 0 2px 14px rgba(20, 22, 26, 0.07);
  padding: 28px 30px 24px;
}

.eyebrow {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.eyebrow .section-title {
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}
.chip {
  font-size: 11px;
  border: 1px solid var(--hairline);
  border-radius: 3px;
  padding: 2px 8px;
  background: var(--paper-2);
  color: var(--ink);
}
.chip.skill {
  color: var(--blue);
  border-color: rgba(30, 58, 95, 0.35);
}
.chip.pretest {
  color: var(--vermilion);
  border-color: rgba(192, 71, 42, 0.45);
  letter-spacing: 0.04em;
  font-weight: 600;
}
.chip.difficulty {
  color: var(--muted);
}
.chip.difficulty.easy {
  color: var(--success);
}
.chip.difficulty.medium {
  color: var(--amber);
}
.chip.difficulty.hard {
  color: var(--vermilion);
}

.exercise-num {
  font-family: var(--font-display);
  font-style: italic;
  font-size: 17px;
  margin-top: 16px;
  display: flex;
  align-items: baseline;
  gap: 10px;
}
.book-link {
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-style: normal;
  color: var(--vermilion);
  text-decoration: none;
  white-space: nowrap;
}
.book-link:hover {
  text-decoration: underline;
  text-decoration-color: var(--hairline);
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}
.instruction {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

.prompt {
  font-family: var(--font-display);
  font-size: 38px;
  line-height: 1.35;
  margin: 20px 0 26px;
  padding-top: 14px;
  border-top: 2px solid var(--vermilion);
  word-break: break-word;
}
.prompt .mono {
  font-family: var(--font-mono);
  font-size: 34px;
  white-space: nowrap;
}
.prompt.prose {
  font-family: var(--font-display);
  font-size: 21px;
  line-height: 1.55;
  max-height: 300px;
  overflow-y: auto;
}
.prompt.prose .mono {
  font-size: 17px;
  white-space: normal;
}

/* Typeset math: stacked fraction, radical, raised exponents */
.frac {
  display: inline-flex;
  flex-direction: column;
  vertical-align: middle;
  font-family: var(--font-mono);
  font-size: 34px;
  line-height: 1.15;
}
.frac .fr-num,
.frac .fr-den {
  text-align: center;
  line-height: 1.15;
  padding: 0 6px;
}
.frac .fr-bar {
  height: 1px;
  background: var(--ink);
  margin: 3px 0;
  width: 100%;
}
.frac sup {
  font-size: 19px;
  line-height: 0;
  position: relative;
  top: 0.05em;
}
.rad {
  display: inline-flex;
  align-items: flex-start;
  font-family: var(--font-mono);
  font-size: 34px;
  line-height: 1.2;
  white-space: nowrap;
  vertical-align: baseline;
}
.rad .rad-sign {
  display: inline-block;
}
.rad .rad-in {
  display: inline-block;
  border-top: 1px solid var(--ink);
  padding: 0 3px 0 1px;
}
.prompt sup {
  font-size: 18px;
  line-height: 1;
}

/* Multi-part prompts: one labelled part per line, label stays with its text. */
.prompt-lead {
  margin-bottom: 8px;
}
.prompt-lead:empty {
  display: none;
}
ol.parts {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.parts .part {
  display: flex;
  align-items: baseline;
  gap: 0.5em;
}
.parts .part-label {
  flex: none;
  margin-right: 0.25em;
}

.answer-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.answer-row .eq {
  font-family: var(--font-mono);
  font-size: 22px;
  color: var(--muted);
}
.answer-input {
  flex: 1;
  font-family: var(--font-mono);
  font-size: 20px;
  padding: 12px 14px;
  border: 1px solid var(--hairline);
  border-radius: 3px;
  background: #fff;
  color: var(--ink);
  min-width: 0;
}
textarea.answer-input {
  resize: none;
  overflow-y: auto;
  line-height: 1.35;
  min-height: 50px;
  max-height: 180px;
  align-self: stretch;
  font-size: 18px;
}
.answer-input::placeholder {
  color: #b7af9c;
}
.answer-input:focus {
  border-color: var(--vermilion);
  outline: 2px solid rgba(192, 71, 42, 0.3);
  outline-offset: 0;
}
.btn-primary {
  background: var(--vermilion);
  color: #fdfbf5;
  border: 1px solid var(--vermilion);
  border-radius: 3px;
  padding: 13px 20px;
  font-weight: 600;
  white-space: nowrap;
}
.btn-primary:hover {
  background: #a63c23;
}

.quiet-row {
  display: flex;
  gap: 20px;
  margin-top: 12px;
}
/* Paste-question control: link-like affordance alongside the text buttons. */
.paste-question {
  display: inline-flex;
  align-items: center;
  color: var(--blue);
  font-size: 13px;
  padding: 0;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}
.paste-question:hover {
  color: var(--vermilion);
}
.paste-question[hidden] {
  display: none;
}
.text-btn {
  color: var(--blue);
  font-size: 13px;
  padding: 0;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.text-btn:hover {
  color: var(--vermilion);
}
.text-btn.muted {
  color: var(--muted);
}

/* Pre-test question counter under the quiet row. */
.pretest-progress {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
  margin-top: 12px;
}

/* Feedback strip */
.empty-scope {
  margin-top: 18px;
  padding: 40px 32px;
  background: var(--paper);
  border: 1px solid var(--hairline);
  border-radius: 3px;
  text-align: center;
}
.empty-scope .es-title {
  font-family: var(--font-display);
  font-size: 24px;
  margin-bottom: 6px;
}
.empty-scope .es-body {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 18px;
}

.feedback {
  margin-top: 18px;
  padding: 16px 18px;
  border-radius: 3px;
  font-size: 14px;
  border: 1px solid var(--hairline);
}
.feedback.hidden {
  display: none;
}
.feedback.correct {
  border-left: 3px solid var(--success);
  background: rgba(47, 107, 79, 0.06);
  color: var(--success);
}
.feedback.incorrect {
  border-left: 3px solid var(--vermilion);
  background: rgba(192, 71, 42, 0.05);
}
.feedback.warn {
  border-left: 3px solid var(--amber);
  background: rgba(176, 122, 30, 0.06);
  color: var(--amber);
}
.feedback .fb-head {
  font-weight: 600;
}
.feedback.correct .fb-head {
  color: var(--success);
}
.feedback.incorrect .fb-head {
  color: var(--vermilion);
}
.feedback.warn .fb-head {
  color: var(--amber);
}
.feedback .fb-book {
  color: var(--muted);
}
.feedback .fb-answer {
  font-family: var(--font-mono);
  font-size: 15px;
  white-space: nowrap;
  background: var(--paper-2);
  border: 1px solid var(--hairline);
  border-radius: 3px;
  padding: 3px 8px;
  margin-left: 4px;
}
.feedback .fb-answer sup {
  font-size: 0.62em;
  line-height: 1;
}
.feedback .fb-reason {
  color: var(--muted);
  margin-top: 8px;
}
.feedback .fb-pretest-line {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--muted);
  margin-top: 8px;
}
.feedback .next-btn {
  display: inline-block;
  margin-top: 12px;
  border: 1px solid var(--ink);
  border-radius: 3px;
  padding: 8px 16px;
  font-weight: 600;
}
.feedback .next-btn:hover {
  background: var(--ink);
  color: var(--paper);
}
.feedback .fb-actions {
  margin-top: 12px;
  display: flex;
  gap: 14px;
  align-items: center;
}
.streak-note {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--success);
}

/* Session sheet (closes the practice column) */
#viewPractice.active {
  display: flex;
  flex-direction: column;
  min-height: 100%;
}

.session-sheet {
  margin-top: auto;
  background: var(--paper);
  border: 1px solid var(--hairline);
  border-radius: 3px;
  padding: 16px 18px;
}
.session-sheet .ss-head {
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 10px;
}
.ss-pips {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 10px;
}
.ss-pip {
  width: 8px;
  height: 18px;
  padding: 0;
  border: 0;
  border-radius: 2px;
  background: var(--hairline);
  cursor: pointer;
}
.ss-pip.unanswered {
  background: var(--hairline);
}
.ss-pip.correct {
  background: var(--success);
}
.ss-pip.wrong {
  background: #b4392b;
}
.ss-pip:hover {
  opacity: 0.78;
}
.ss-pip.current {
  outline: 1px solid var(--ink);
  outline-offset: 2px;
}
.session-sheet .ss-note {
  font-size: 11px;
  color: var(--muted);
}

/* Above the question: the sheet's own `margin-top: auto` would push it back to
   the foot of the column, so a two-class rule cancels it and leaves air below. */
.session-sheet.session-sheet--top {
  margin-top: 0;
  margin-bottom: 20px;
}

.session-sheet.session-sheet--top .ss-pips {
  flex-wrap: wrap;
}

/* ===== Right column ===== */
.rightcol {
  flex: 0 0 340px;
  border-left: 1px solid var(--hairline);
  padding: 22px 20px;
  overflow-y: auto;
}

.tutor-preview {
  border: 1px solid var(--hairline);
  border-radius: 3px;
  background: var(--paper);
}
.tutor-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--hairline);
}
.tutor-head .tutor-label {
  font-size: 11px;
  letter-spacing: 0.22em;
  font-weight: 600;
}
.tutor-head .tutor-subtitle {
  font-family: var(--font-display);
  font-style: italic;
  font-size: 14px;
  color: var(--muted);
}
.tutor-thread {
  flex: 0 0 auto;
  min-height: 120px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px 20px 18px;
}
.chat-msg {
  display: flex;
  flex-direction: column;
  max-width: 100%;
}
.chat-msg.tutor {
  align-items: flex-start;
  text-align: left;
}
.chat-msg.tutor .msg-body {
  font-family: var(--font-display);
  font-size: 13px;
  line-height: 1.5;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
  white-space: normal;
}
.chat-msg.learner {
  align-self: flex-end;
  align-items: flex-end;
  background: var(--paper-2);
  border-radius: 3px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  max-width: 78%;
  padding: 8px 12px;
  word-break: break-word;
}
.msg-label {
  font-size: 9.5px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 3px;
}
.msg-time {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--muted);
  margin-top: 3px;
}
.chat-msg .mono {
  font-family: var(--font-mono);
  font-size: 12px;
  white-space: nowrap;
}
.chat-msg sup {
  font-size: 0.75em;
  line-height: 0;
  vertical-align: 0.42em;
  position: static;
}
.prompt-inline {
  font-family: var(--font-mono);
  font-size: 13px;
  white-space: nowrap;
  padding: 0 2px;
}
.prompt-inline .mono,
.prompt-inline .frac,
.prompt-inline .rad {
  font-size: 13px;
}
.prompt-inline .frac .fr-num,
.prompt-inline .frac .fr-den {
  padding: 0 3px;
}
.prompt-inline .frac .fr-bar {
  margin: 1px 0;
}
.prompt-inline sup {
  font-size: 0.68em;
  line-height: 0;
  vertical-align: super;
  position: static;
}

/* Typing indicator */
.typing-dots {
  display: flex;
  gap: 4px;
  padding: 6px 0 4px;
}
.typing-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  animation: typing-blink 1s infinite;
}
.typing-dots span:nth-child(2) {
  animation-delay: 0.2s;
}
.typing-dots span:nth-child(3) {
  animation-delay: 0.4s;
}
@keyframes typing-blink {
  0%,
  60%,
  100% {
    opacity: 0.25;
  }
  30% {
    opacity: 1;
  }
}
.tutor-foot {
  flex: 0 0 auto;
  padding: 10px 16px;
  border-top: 1px solid var(--hairline);
  font-size: 11px;
  color: var(--muted);
}
.tutor-foot .mono {
  font-family: var(--font-mono);
}

.tutor-composer {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 14px;
  border-top: 1px solid var(--hairline);
}
textarea.tutor-input {
  resize: none;
  overflow-y: auto;
  line-height: 1.4;
  min-height: 36px;
  max-height: 120px;
}
.tutor-input {
  flex: 1;
  min-width: 0;
  font-family: var(--font-ui);
  font-size: 13px;
  padding: 8px 10px;
  border: 1px solid var(--hairline);
  border-radius: 3px;
  background: #fff;
  color: var(--ink);
}
.tutor-input::placeholder {
  color: #b7af9c;
}
.tutor-input:focus {
  border-color: var(--vermilion);
  outline: 2px solid rgba(192, 71, 42, 0.3);
  outline-offset: 0;
}
.tutor-send {
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  border-radius: 0;
  background: var(--vermilion);
  color: #fdfbf5;
  border: none;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
}
.tutor-send:hover {
  background: #a63c23;
}

/* ===== Tutor view (full tab) ===== */
#viewTutor.active {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 720px;
  min-height: 0;
}
.tutor-sheet {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: calc(100vh - 148px);
  min-height: 520px;
  overflow-x: hidden;
  overflow-y: auto;
  background: var(--paper);
  border: 1px solid var(--hairline);
  border-radius: 3px;
  box-shadow: 0 2px 14px rgba(20, 22, 26, 0.07);
}

/* Context strip above the thread (scrolls with the page) */
.tutor-context {
  flex: 0 0 auto;
  padding: 14px 20px 12px;
  border-bottom: 1px solid var(--hairline);
}
.tc-top {
  font-size: 10.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}
.tc-prompt {
  font-family: var(--font-mono);
  font-size: 20px;
  line-height: 1.3;
  margin: 8px 0 10px;
  word-break: break-word;
}
.tc-prompt .frac {
  font-size: 20px;
}
.tc-prompt .frac sup {
  font-size: 12px;
}
.tc-prompt .rad {
  font-size: 20px;
}
.tc-prompt .mono {
  font-family: var(--font-mono);
  font-size: 20px;
}
.tc-prompt.prose {
  font-family: var(--font-display);
  font-size: 15px;
  line-height: 1.5;
  max-height: 110px;
  overflow-y: auto;
}
.tc-prompt.prose .mono {
  font-size: 14px;
  white-space: normal;
}
.tc-meta {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--muted);
  text-align: right;
}
.tc-book {
  text-align: right;
  margin-top: 4px;
}

/* Stacked tutor sections with sticky headers */
.tutor-block {
  flex: 0 0 auto;
}
.tutor-block-head {
  position: sticky;
  top: 0;
  z-index: 2;
  margin: 0;
  padding: 12px 20px 10px;
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  background: var(--paper);
  border-bottom: 1px solid var(--hairline);
}

/* Tutor panels */
.tutor-panel {
  flex: 0 0 auto;
  padding: 14px 20px 16px;
  border-bottom: 1px solid var(--hairline);
}
.tutor-panel sup {
  font-size: 0.72em;
  line-height: 0;
  vertical-align: 0.42em;
  position: static;
}
.panel-lead {
  font-family: var(--font-display);
  font-size: 14px;
  color: var(--ink);
  margin: 0 0 4px;
}
.need-row {
  padding: 10px 0;
  border-bottom: 1px solid var(--hairline);
}
.need-row:last-child {
  border-bottom: none;
}
.need-name {
  display: block;
  font-family: var(--font-display);
  font-size: 14.5px;
  margin-bottom: 2px;
}
.need-rule {
  display: block;
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--ink);
  overflow-wrap: anywhere;
}
.panel-note {
  font-size: 11px;
  color: var(--muted);
  margin-top: 10px;
}
.need-rule.muted {
  color: var(--muted);
  font-style: italic;
  font-family: var(--font-ui);
}
.solve-step {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--hairline);
}
.solve-step:last-child {
  border-bottom: none;
}
.solve-num {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--muted);
  flex: 0 0 16px;
  text-align: right;
}
.solve-text {
  font-family: var(--font-display);
  font-size: 14px;
  line-height: 1.5;
  flex: 1;
  min-width: 0;
}
.solve-text .mono {
  font-family: var(--font-mono);
  font-size: 13px;
}
.solve-book {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--muted);
  margin-top: 10px;
}

/* Practice-side compact transcript preview */
.tutor-preview-thread {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 12px;
}
.tutor-preview-thread .chat-msg.tutor .msg-body {
  font-size: 12px;
}
.tutor-preview-thread .chat-msg.learner {
  font-size: 11px;
}
.tutor-preview-thread .chat-msg .mono {
  font-size: 10.5px;
}
.tutor-preview-thread .msg-label {
  font-size: 8px;
}
.tutor-preview-thread .msg-time {
  font-size: 8.5px;
}

.tutor-open-btn {
  display: block;
  width: calc(100% - 28px);
  margin: 12px 14px 14px;
  padding: 9px 0;
  border: 1px solid var(--ink);
  border-radius: 3px;
  background: transparent;
  color: var(--ink);
  font-weight: 600;
  font-size: 13px;
}
.tutor-open-btn:hover {
  background: var(--ink);
  color: var(--paper);
}

/* ===== Ask-the-tutor pill (narrow widths) ===== */
.tutor-fab {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 40;
  height: 34px;
  display: none;
  align-items: center;
  padding: 0 18px;
  border: 1px solid var(--vermilion);
  border-radius: 17px;
  background: var(--paper-2);
  color: var(--vermilion);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  box-shadow: 0 2px 10px rgba(20, 22, 26, 0.14);
}
.tutor-fab:hover {
  background: var(--vermilion);
  color: #fdfbf5;
}
body.tutor-active .tutor-fab {
  display: none;
}
@media (max-width: 1200px) {
  .tutor-fab {
    display: inline-flex;
  }
}

.skills-mini {
  margin-top: 18px;
  border: 1px solid var(--hairline);
  border-radius: 3px;
}
.skills-mini .sm-head {
  font-size: 11px;
  letter-spacing: 0.22em;
  font-weight: 600;
  padding: 12px 14px;
  border-bottom: 1px solid var(--hairline);
}
.skills-mini .sm-row {
  padding: 10px 14px;
  border-bottom: 1px solid var(--hairline);
}
.skills-mini .sm-row:last-child {
  border-bottom: none;
}
.skills-mini .sm-top {
  display: flex;
  align-items: center;
  gap: 8px;
}
.skills-mini .sm-name {
  font-size: 12px;
  font-weight: 500;
}
.state-chip {
  font-size: 10px;
  letter-spacing: 0.05em;
  border-radius: 3px;
  padding: 1px 7px;
  margin-left: auto;
}
.state-chip.learning {
  color: var(--amber);
  background: rgba(176, 122, 30, 0.12);
}
.state-chip.fluent {
  color: var(--blue);
  background: rgba(30, 58, 95, 0.1);
}
.state-chip.mastered {
  color: var(--success);
  background: rgba(47, 107, 79, 0.12);
}
.pips {
  display: flex;
  gap: 4px;
  margin-top: 8px;
}
.pip {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  border: 1px solid var(--hairline);
}
.pip.on {
  background: var(--blue);
  border-color: var(--blue);
}
.skills-mini .sm-review {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
  margin-top: 6px;
}

/* ===== Progress view ===== */
.sheet {
  background: var(--paper);
  border: 1px solid var(--hairline);
  border-radius: 3px;
  padding: 24px 26px;
}
.sheet-title {
  font-family: var(--font-display);
  font-size: 22px;
  margin: 0 0 2px;
}
.sheet-sub {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 18px;
}
.skills-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.skills-table th {
  text-align: left;
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
  padding: 8px 10px;
  border-bottom: 1px solid var(--hairline);
}
.skills-table td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--hairline);
  vertical-align: middle;
}
.skills-table tr:last-child td {
  border-bottom: none;
}
.skills-table .skill-name {
  font-weight: 500;
}
.acc-bar {
  display: inline-block;
  width: 60px;
  height: 6px;
  background: var(--hairline);
  border-radius: 3px;
  overflow: hidden;
  vertical-align: middle;
  margin-right: 8px;
}
.acc-bar i {
  display: block;
  height: 100%;
  background: var(--blue);
}
.acc-pct {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--muted);
}

/* Progress view sub-tabs (Skills / Rules) */
.progress-tabs {
  display: flex;
  gap: 28px;
  border-bottom: 1px solid var(--hairline);
  margin-bottom: 18px;
}
.progress-tab {
  border: none;
  background: transparent;
  padding: 0 0 9px;
  margin-bottom: -1px;
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
}
.progress-tab:hover {
  color: var(--ink);
}
.progress-tab[aria-selected="true"] {
  color: var(--ink);
  border-bottom-color: var(--vermilion);
  font-weight: 600;
}
#progressSkillsPanel[hidden],
#progressRulesPanel[hidden] {
  display: none;
}

/* Rules panel */
.rules-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.rules-select {
  font-family: var(--font-ui);
  font-size: 13px;
  padding: 7px 10px;
  border: 1px solid var(--hairline);
  border-radius: 3px;
  background: var(--paper);
  color: var(--ink);
}
.rules-summary {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--muted);
  margin-left: auto;
  text-align: right;
  white-space: nowrap;
}
.rules-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 18px;
}
.rules-chip {
  border: 1px solid var(--hairline);
  border-radius: 3px;
  padding: 6px 12px;
  background: transparent;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 12px;
  white-space: nowrap;
}
.rules-chip:hover {
  border-color: var(--ink);
  color: var(--ink);
}
.rules-chip[aria-pressed="true"] {
  background: var(--vermilion);
  color: #fdfbf5;
  border-color: var(--vermilion);
}
.rules-section-head {
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom: 1px solid var(--hairline);
  padding-bottom: 5px;
  margin: 18px 0 8px;
}
.rules-section-head:first-child {
  margin-top: 0;
}
.rules-skill-head {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 600;
  margin: 14px 0 6px;
}
.rule-card {
  border: 1px solid var(--hairline);
  border-left: 3px solid var(--vermilion);
  border-radius: 3px;
  padding: 12px 16px;
  margin-bottom: 8px;
  background: var(--paper);
}
.rule-card .rule-name {
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 4px;
}
.rule-card .rule-html {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--muted);
  line-height: 1.5;
}
.rule-card .rule-html sup {
  font-size: 0.72em;
  line-height: 0;
  vertical-align: 0.42em;
  position: static;
}

/* ===== Summary view ===== */
.summary-wrap {
  display: flex;
  justify-content: center;
  padding: 24px 24px;
}
.summary-sheet {
  width: 100%;
  max-width: 620px;
  background: var(--paper);
  border: 1px solid var(--hairline);
  border-radius: 3px;
  box-shadow: 0 2px 14px rgba(20, 22, 26, 0.06);
  padding: 28px 36px;
  text-align: center;
}
.summary-sheet .sum-title {
  font-family: var(--font-display);
  font-size: 28px;
  margin: 0;
}
.summary-sheet .sum-breakdown {
  font-family: var(--font-mono);
  font-size: 14px;
  color: var(--muted);
  margin-top: 6px;
}
.summary-sheet .sum-pct {
  font-family: var(--font-display);
  font-size: 56px;
  line-height: 1;
  margin: 12px 0 6px;
}
.sum-section {
  text-align: left;
  margin-top: 18px;
}
.sum-section .sum-h {
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom: 1px solid var(--hairline);
  padding-bottom: 5px;
  margin-bottom: 8px;
}
.sum-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 0;
  font-size: 13px;
}
.sum-row .sum-name {
  flex: 1;
}
.sum-row .sum-pct {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--muted);
  width: 38px;
  text-align: right;
}
.sum-row .bar {
  flex: 0 0 140px;
  height: 6px;
  background: var(--hairline);
  border-radius: 3px;
  overflow: hidden;
}
.sum-row .bar i {
  display: block;
  height: 100%;
  background: var(--blue);
}
.sum-row.due .sum-date {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--muted);
}
.summary-sheet .btn-primary {
  margin-top: 20px;
  font-size: 14px;
  padding: 13px 26px;
}
.summary-sheet .sum-row.missed {
  justify-content: center;
}
.summary-sheet .sum-row.missed .sum-name {
  flex: none;
}
.summary-sheet .pretest-note {
  font-size: 12px;
  color: var(--muted);
  margin-top: 16px;
}
.summary-sheet #retakePretest {
  margin-top: 18px;
}

/* ===== Scope block (rail) ===== */
.scope-block {
  margin-top: 18px;
  background: var(--paper-2);
  border: 1px solid var(--hairline);
  border-radius: 3px;
  padding: 12px 14px;
}
.scope-block .scope-title {
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 6px;
}
.scope-block .scope-count {
  font-family: var(--font-display);
  font-size: 14px;
  line-height: 1.3;
}
.scope-block .scope-sub {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--muted);
  margin-bottom: 10px;
}

/* ===== Scope modal ===== */
.scope-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(20, 22, 26, 0.28);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 9vh 20px 24px;
}
.scope-backdrop[hidden] {
  display: none;
}
.scope-sheet {
  background: var(--paper);
  border: 1px solid var(--hairline);
  border-radius: 4px;
  box-shadow: 0 18px 48px rgba(20, 22, 26, 0.22);
  width: 100%;
  max-width: 700px;
  padding: 26px 30px 22px;
  animation: scope-in 180ms ease;
}
@keyframes scope-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
.scope-eyebrow {
  font-size: 10px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--muted);
}
.scope-sheet .scope-title {
  font-family: var(--font-display);
  font-size: 30px;
  line-height: 1.1;
  margin: 4px 0 2px;
}
.scope-subline {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 18px;
}

/* Step 1 pre-test block at the top of the scope sheet. */
.pretest-block {
  border: 1px solid var(--hairline);
  border-radius: 3px;
  background: var(--paper-2);
  padding: 12px 14px;
  margin-bottom: 14px;
}
.pretest-step {
  font-size: 10px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 6px;
}
.pretest-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.pretest-main {
  flex: 1;
  min-width: 0;
}
.pretest-title {
  font-family: var(--font-display);
  font-size: 15.5px;
}
.pretest-sub {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
  margin-top: 1px;
}
.pretest-chip {
  flex: 0 0 auto;
  font-size: 10px;
  letter-spacing: 0.08em;
  border-radius: 3px;
  padding: 2px 8px;
  white-space: nowrap;
}
.pretest-chip.required {
  color: var(--vermilion);
  border: 1px solid rgba(192, 71, 42, 0.45);
}
.pretest-block .seg {
  margin-top: 10px;
}
.pretest-chip.passed {
  color: var(--success);
  border: 1px solid rgba(47, 107, 79, 0.45);
}

.scope-rows {
  border-top: 1px solid var(--hairline);
}
.scope-suggested {
  font-size: 11px;
  color: var(--muted);
  margin: 14px 0 8px;
}
.scope-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--hairline);
  cursor: pointer;
}
.scope-row:hover {
  background: var(--paper-2);
}
.scope-row:focus-within {
  background: var(--paper-2);
}
.scope-row input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  flex: 0 0 14px;
  width: 14px;
  height: 14px;
  margin: 0;
  border: 1px solid var(--muted);
  border-radius: 2px;
  background: transparent;
  cursor: pointer;
  position: relative;
}
.scope-row input[type="checkbox"]:checked {
  background: var(--vermilion);
  border-color: var(--vermilion);
}
.scope-row input[type="checkbox"]:checked::after {
  content: "";
  position: absolute;
  left: 3px;
  top: 1px;
  width: 4px;
  height: 7px;
  border: solid var(--paper);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
.scope-row-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.scope-row-line1 {
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.scope-row .scope-row-num {
  flex: 0 0 24px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
}
.scope-row .scope-row-title {
  flex: 1;
  min-width: 0;
  font-family: var(--font-display);
  font-size: 14.5px;
}
.scope-row .scope-row-meta {
  flex: 0 0 auto;
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--muted);
  white-space: nowrap;
}
.scope-row-line2 {
  display: flex;
  align-items: center;
  gap: 8px;
}
.scope-row .scope-reason {
  flex: 1;
  min-width: 0;
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--muted);
  white-space: nowrap;
}
.scope-row .scope-reco {
  flex: 0 0 auto;
  font-size: 10px;
  letter-spacing: 0.04em;
  color: var(--vermilion);
  border: 1px solid rgba(192, 71, 42, 0.45);
  border-radius: 3px;
  padding: 1px 6px;
  white-space: nowrap;
}
.scope-row.locked {
  cursor: default;
  opacity: 0.55;
}
.scope-row.locked:hover,
.scope-row.locked:focus-within {
  background: transparent;
}
.scope-row.locked .scope-row-title,
.scope-row.locked .scope-row-meta,
.scope-row.locked .scope-row-num,
.scope-row.locked .scope-reason {
  color: var(--muted);
}
.scope-lock-label {
  flex: 0 0 auto;
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  border: 1px solid var(--hairline);
  border-radius: 3px;
  padding: 1px 6px;
  white-space: nowrap;
}
.scope-lock-note {
  font-size: 11px;
  color: var(--vermilion);
  margin: 10px 2px 0;
}

/* Master select/clear all (scope sheet + rail) */
input.scope-all {
  appearance: none;
  -webkit-appearance: none;
  flex: 0 0 14px;
  width: 14px;
  height: 14px;
  margin: 0;
  border: 1px solid var(--muted);
  border-radius: 2px;
  background: transparent;
  cursor: pointer;
  position: relative;
}
input.scope-all:checked {
  background: var(--vermilion);
  border-color: var(--vermilion);
}
input.scope-all:checked::after {
  content: "";
  position: absolute;
  left: 3px;
  top: 1px;
  width: 4px;
  height: 7px;
  border: solid var(--paper);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
input.scope-all:indeterminate {
  background: var(--vermilion);
  border-color: var(--vermilion);
}
input.scope-all:indeterminate::after {
  content: "";
  position: absolute;
  left: 2px;
  top: 5px;
  width: 8px;
  height: 2px;
  background: var(--paper);
}
.scope-master {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  padding: 8px 10px;
  border-top: 1px solid var(--hairline);
  cursor: pointer;
}
.scope-master:hover,
.scope-master:focus-within {
  background: var(--paper-2);
}
.scope-master-label {
  flex: 1;
  min-width: 0;
  font-family: var(--font-display);
  font-size: 14.5px;
}
.scope-master-count {
  flex: 0 0 auto;
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--muted);
  white-space: nowrap;
}

.scope-quick {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 16px 0;
}
.scope-quick-btn {
  border: 1px solid var(--hairline);
  border-radius: 3px;
  padding: 6px 12px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
}
.scope-quick-btn:hover {
  border-color: var(--ink);
  color: var(--ink);
}
.scope-quick-btn.clear-all {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: #4a4e57;
  border-color: #d9d2bf;
}
.scope-quick-btn.clear-all:hover {
  border-color: var(--vermilion);
  color: var(--vermilion);
}

.scope-length {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}
.scope-length-label {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.seg {
  display: inline-flex;
  border: 1px solid var(--hairline);
  border-radius: 3px;
  overflow: hidden;
}
.seg-btn {
  padding: 5px 14px;
  border: none;
  border-right: 1px solid var(--hairline);
  background: transparent;
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 12px;
}
.seg-btn:last-child {
  border-right: none;
}
.seg-btn.active {
  background: var(--vermilion);
  color: #fdfbf5;
}

.scope-live {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 18px;
}
.scope-live.empty {
  color: var(--vermilion);
}

.scope-footer {
  display: flex;
  align-items: center;
  gap: 18px;
}
.btn-primary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.btn-primary:disabled:hover {
  background: var(--vermilion);
}
.scope-cancel {
  color: var(--muted);
  font-size: 13px;
  padding: 0;
  border: none;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.scope-cancel:hover {
  color: var(--ink);
}

/* ===== Book viewer modal ===== */
.book-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(20, 22, 26, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
}
.book-backdrop[hidden] {
  display: none;
}
.book-sheet {
  background: var(--paper);
  border: 1px solid var(--hairline);
  border-radius: 4px;
  box-shadow: 0 18px 48px rgba(20, 22, 26, 0.22);
  width: 100%;
  max-width: 760px;
  height: calc(100vh - 80px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: scope-in 180ms ease;
}
.book-head {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--hairline);
  flex: 0 0 auto;
}
.book-head .book-label {
  font-family: var(--font-mono);
  font-size: 11px;
  white-space: nowrap;
}
.book-head .book-section {
  font-family: var(--font-display);
  font-style: italic;
  font-size: 12px;
  color: var(--muted);
  margin-left: auto;
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.book-head .book-close {
  font-size: 18px;
  line-height: 1;
  color: var(--muted);
  padding: 2px 7px;
  flex: 0 0 auto;
}
.book-head .book-close:hover {
  color: var(--ink);
}
.book-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  background: var(--paper-2);
  padding: 16px;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}
.book-body img {
  width: 100%;
  max-width: 640px;
  height: auto;
  display: block;
  border: 1px solid var(--hairline);
  background: #ffffff;
  box-shadow: 0 2px 12px rgba(20, 22, 26, 0.14);
}
.book-foot {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 12px 16px;
  border-top: 1px solid var(--hairline);
  flex: 0 0 auto;
}
.book-foot .book-open-pdf {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--vermilion);
  text-decoration: none;
}
.book-foot .book-open-pdf:hover {
  text-decoration: underline;
}
.book-foot .book-close-btn {
  color: var(--muted);
  font-size: 13px;
  padding: 0;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.book-foot .book-close-btn:hover {
  color: var(--ink);
}

/* ===== Responsive ===== */
@media (max-width: 1180px) {
  .rightcol {
    display: none;
  }
  .rail {
    flex-basis: 210px;
  }
  .prompt {
    font-size: 32px;
  }
  .prompt .mono {
    font-size: 28px;
  }
}
@media (max-width: 1024px) {
  .wordmark {
    min-width: 150px;
  }
  .progress .track {
    width: 110px;
  }
  .stats {
    gap: 14px;
  }
}

/* ===== Mobile-only chrome (hidden on desktop) ===== */
.mobile-tabs,
.mobile-scope-chip,
.rail-handle,
.rail-head,
.mobile-backdrop {
  display: none;
}

/* ===== Mobile layout — applies at every viewport ===== */
:root {
  --tabbar-h: calc(49px + env(safe-area-inset-bottom));
}

body {
  overflow-x: hidden;
}

/* Top bar → compact grid: wordmark+counter / progress bar / scope chip+stats */
.topbar {
  height: auto;
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas:
    "wordmark counter"
    "track    track"
    "scope    stats";
  align-items: center;
  column-gap: 14px;
  row-gap: 6px;
  padding: calc(8px + env(safe-area-inset-top)) 16px 8px;
}
.topbar .tabs {
  display: none;
}
.topbar .progress {
  display: contents;
}
.topbar .progress .progress-label {
  grid-area: counter;
  justify-self: end;
}
.topbar .track {
  grid-area: track;
  width: 100%;
}
.wordmark {
  grid-area: wordmark;
  min-width: 0;
}
.wordmark .wm-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.wordmark .wm-sub {
  display: none;
}
.stats {
  grid-area: stats;
  justify-self: end;
  gap: 12px;
}
.stats .stat-val {
  font-size: 13px;
}
#endSession {
  display: none;
}

.mobile-scope-chip {
  grid-area: scope;
  justify-self: start;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  min-width: 0;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--hairline);
  border-radius: 3px;
  background: var(--paper-2);
  color: var(--ink);
}
.mobile-scope-chip .msc-title {
  flex: 0 0 auto;
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}
.mobile-scope-chip .msc-value {
  flex: 0 1 auto;
  min-width: 0;
  font-family: var(--font-mono);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Single column */
.shell {
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.rightcol {
  display: none;
}

/* Rail → fixed bottom sheet */
.rail {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 80;
  flex: none;
  background: var(--paper);
  border-right: none;
  border-top: 1px solid var(--hairline);
  border-top-left-radius: 16px;
  border-top-right-radius: 16px;
  max-height: 85dvh;
  padding: 8px 18px calc(18px + env(safe-area-inset-bottom));
  overflow-y: auto;
  overscroll-behavior: contain;
  box-shadow: 0 -8px 30px rgba(20, 22, 26, 0.18);
  transform: translateY(105%);
  transition: transform 220ms ease;
  visibility: hidden;
}
body.rail-open .rail {
  transform: translateY(0);
  visibility: visible;
}
.rail-handle {
  display: block;
  width: 40px;
  height: 4px;
  border-radius: 2px;
  background: var(--hairline);
  margin: 4px auto 10px;
}
.rail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}
.rail-head .rail-head-title {
  font-family: var(--font-display);
  font-size: 18px;
}
.rail-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  font-size: 22px;
  line-height: 1;
  color: var(--muted);
  border-radius: 3px;
}
.rail-close:hover {
  color: var(--ink);
}
.keys {
  display: none;
}

/* Center */
.center {
  flex: 1 1 auto;
  min-height: 0;
  display: block;
  padding: 16px 16px calc(64px + env(safe-area-inset-bottom));
  overscroll-behavior: contain;
}
.center-inner {
  max-width: none;
}
.problem-card {
  padding: 18px 16px;
}
.prompt {
  font-size: clamp(22px, 7vw, 30px);
  margin: 14px 0 18px;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.prompt .mono {
  font-size: clamp(22px, 7vw, 30px);
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.prompt.prose {
  max-height: none;
}
.frac {
  font-size: clamp(22px, 6vw, 28px);
}
.rad {
  font-size: clamp(22px, 6vw, 28px);
}

/* Answer controls stack, ≥44px touch targets, 16px inputs */
.answer-row {
  flex-wrap: wrap;
  align-items: stretch;
}
.answer-row .eq {
  display: none;
}
.answer-input,
textarea.answer-input {
  flex: 1 1 100%;
  width: 100%;
  min-height: 48px;
  font-size: 16px;
}
#checkBtn {
  flex: 1 1 100%;
  width: 100%;
  min-height: 48px;
}
.quiet-row {
  gap: 12px;
  margin-top: 12px;
}
#explainBtn,
#skipBtn {
  min-height: 44px;
  font-size: 14px;
}
.text-btn {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
}

/* Progress → stacked cards */
.skills-table {
  display: block;
}
.skills-table thead {
  display: none;
}
.skills-table tbody {
  display: block;
}
.skills-table tr {
  display: block;
  border: 1px solid var(--hairline);
  border-radius: 3px;
  margin-bottom: 12px;
  padding: 4px 14px 8px;
}
.skills-table td {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid var(--hairline);
  font-size: 13px;
}
.skills-table tr td:last-child {
  border-bottom: none;
}
.skills-table td::before {
  content: attr(data-label);
  flex: 0 0 auto;
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.skills-table td.skill-name {
  display: block;
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 600;
  padding: 10px 0 2px;
  border-bottom: none;
}
.skills-table td.skill-name::before {
  content: none;
}

/* Sheets fluid / full width */
.sheet {
  padding: 18px 16px;
}
.summary-wrap {
  padding: 12px 12px;
}
.summary-sheet {
  max-width: none;
  padding: 20px 16px;
}

/* Rules panel (mobile) */
.progress-tabs {
  gap: 16px;
}
.progress-tab {
  min-height: 44px;
}
.rules-head {
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
}
.rules-select {
  width: 100%;
  min-height: 44px;
}
.rules-summary {
  margin-left: 0;
  text-align: left;
  white-space: normal;
}
.rules-chips {
  flex-wrap: nowrap;
  overflow-x: auto;
  padding-bottom: 4px;
}
.rules-chip {
  flex: 0 0 auto;
  min-height: 44px;
}
.rule-card {
  width: 100%;
}

.scope-backdrop {
  padding: 0;
  align-items: flex-end;
}
.scope-sheet {
  max-width: none;
  border-radius: 16px 16px 0 0;
  max-height: 90dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
}

.book-backdrop {
  padding: 0;
}
.book-sheet {
  max-width: none;
  height: 100dvh;
  border-radius: 0;
}

/* Tutor */
#viewTutor.active {
  max-width: none;
  width: 100%;
}
.tutor-sheet {
  height: calc(var(--vvh, 100dvh) - var(--topbar-h, 0px) - var(--tabbar-h, 0px) - 16px);
  min-height: 0;
}
.tutor-thread {
  min-height: 0;
}
.tutor-panel {
  flex: 0 0 auto;
  min-height: 0;
}
.tutor-context {
  flex: 0 1 auto;
  min-height: 0;
  overflow: hidden;
}
.tutor-foot {
  display: none;
}
/* When the on-screen keyboard is open, collapse the context chrome so the
       thread and composer get the (smaller) visible viewport; the two stacked
       sections stay in the scrolling sheet. */
body.kb-open .tutor-context {
  display: none;
}
body.kb-open .tutor-sheet {
  height: calc(var(--vvh, 100dvh) - var(--topbar-h, 0px) - 16px);
}
.tutor-composer {
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
}
textarea.tutor-input,
.tutor-input {
  font-size: 16px;
}
.tutor-send {
  width: 44px;
  height: 44px;
  flex-basis: 44px;
}

/* Bottom tab bar */
.mobile-tabs {
  display: flex;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 60;
  border-top: 1px solid var(--hairline);
  background: var(--paper);
  box-shadow: 0 -2px 10px rgba(20, 22, 26, 0.08);
  padding-bottom: env(safe-area-inset-bottom);
}
.mobile-tabs .mtab {
  flex: 1 1 0;
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: none;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  padding: 0;
}
.mobile-tabs .mtab[aria-selected="true"] {
  color: var(--vermilion);
  font-weight: 600;
}

/* Mobile backdrop (rail sheet) */
.mobile-backdrop {
  position: fixed;
  inset: 0;
  z-index: 70;
  background: rgba(20, 22, 26, 0.32);
  display: block;
}
.mobile-backdrop[hidden] {
  display: none;
}

/* FAB above the tab bar */
.tutor-fab {
  display: inline-flex;
  bottom: calc(64px + env(safe-area-inset-bottom));
}

/* Touch targets */
.seg-btn {
  min-height: 44px;
  padding: 5px 12px;
}
.scope-quick-btn {
  min-height: 44px;
}

.pretest-retake {
  margin: 18px 0 6px;
  padding-top: 14px;
  border-top: 1px solid var(--hairline);
}
.pretest-retake-label {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 8px;
}
.pretest-retake .seg {
  margin-bottom: 10px;
}

.summary-sheet .pretest-verdict {
  font-family: var(--font-display);
  font-size: 34px;
  line-height: 1.2;
  margin-top: 18px;
}
.summary-sheet .pretest-verdict.passed {
  color: var(--success);
}
.summary-sheet .pretest-verdict.failed {
  color: var(--vermilion);
}
.summary-sheet .pretest-sentence {
  font-size: 14px;
  color: var(--ink);
  margin-top: 6px;
}

.summary-sheet .pretest-counts {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--muted);
  margin-top: 10px;
}
