/* Scoped textbook reader; clean, readable typography inspired by Hugging Face & D2L */
.book-shell {
  display: block;
  width: 100%;
}

/* Hide duplicate inner catalog slot when main unified sidebar is active */
.book-desktop-catalog-slot {
  display: none;
}

.book-lesson-body {
  min-width: 0;
  width: 100%;
}

.book-reading-wrap {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 220px;
  gap: 32px;
  align-items: start;
}

.book-reading-main {
  min-width: 0;
  max-width: 820px;
}

/* In-page Table of Contents (TOC) */
.book-toc {
  position: sticky;
  top: 24px;
  max-height: calc(100vh - 120px);
  overflow-y: auto;
  padding: 16px 14px;
  background: #ffffff;
  border: 1px solid var(--line, #e2e8f0);
  border-radius: 14px;
  font-size: 13px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.03);
}

.book-toc-title {
  font-size: 11px;
  font-weight: 850;
  letter-spacing: 1px;
  color: var(--muted, #64748b);
  text-transform: uppercase;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line, #e2e8f0);
}

.book-toc-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.book-toc-link {
  color: var(--ink-secondary, #475569);
  text-decoration: none;
  line-height: 1.5;
  padding: 4px 6px;
  border-radius: 6px;
  transition: all 0.15s ease;
  word-break: break-word;
}

.book-toc-link:hover {
  color: var(--accent, #5145e5);
  background: var(--accent-soft, #f0edff);
}

.book-toc-link.level-3 {
  padding-left: 16px;
  font-size: 12px;
  color: var(--muted, #64748b);
}

/* Breadcrumbs */
.book-breadcrumb {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 12px;
  color: var(--muted, #64748b);
  margin-bottom: 14px;
}

.book-bc-link {
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  color: var(--accent, #5145e5);
  cursor: pointer;
  font-weight: 600;
}

.book-bc-link:hover {
  text-decoration: underline;
}

.book-bc-sep {
  color: #cbd5e1;
}

.book-bc-current {
  color: var(--ink, #0f172a);
  font-weight: 600;
}

.book-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 20px;
}

.book-meta span {
  border: 1px solid var(--line, #e2e8f0);
  border-radius: 100px;
  padding: 4px 10px;
  color: var(--muted, #64748b);
  font-size: 12px;
  background: #ffffff;
}

.book-meta .book-meta-done {
  background: #ecfdf5;
  border-color: #a7f3d0;
  color: #059669;
  font-weight: 600;
}

/* Article Typography */
.book-article {
  background: #ffffff;
  border: 1px solid var(--line, #e2e8f0);
  border-radius: 18px;
  padding: 38px 42px;
  color: #1e293b;
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.03);
}

.book-article h1 {
  font-size: clamp(24px, 3.2vw, 32px);
  line-height: 1.35;
  margin: 0 0 24px;
  color: #0f172a;
  letter-spacing: -0.5px;
}

.book-article h2 {
  font-size: 21px;
  margin: 40px 0 16px;
  border-bottom: 1px solid var(--line, #e2e8f0);
  padding-bottom: 10px;
  line-height: 1.45;
  color: #0f172a;
  letter-spacing: -0.3px;
  scroll-margin-top: 24px;
}

.book-article h3 {
  font-size: 17px;
  margin: 28px 0 12px;
  line-height: 1.5;
  color: #1e293b;
  scroll-margin-top: 24px;
}

.book-article p {
  font-size: 17.5px;
  line-height: 1.85;
  color: var(--ink, #1f272c);
  margin: 18px 0;
}

.book-article li {
  font-size: 16.5px;
  line-height: 1.85;
  color: var(--ink, #1f272c);
  margin: 8px 0;
}

.book-article blockquote {
  border-left: 4px solid var(--accent, #5145e5);
  background: #f8fafc;
  padding: 14px 20px;
  margin: 20px 0;
  border-radius: 0 10px 10px 0;
  color: #334155;
}

.book-article blockquote p {
  margin: 0;
  font-size: 15px;
}

.book-article ul, .book-article ol {
  padding-left: 24px;
  margin: 16px 0;
}

.book-article code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  background: #f1f5f9;
  padding: 3px 6px;
  border-radius: 6px;
  color: #4338ca;
  font-size: 14px;
  border: 1px solid #e2e8f0;
}

.book-article pre {
  background: #0f172a;
  color: #e2e8f0;
  border-radius: 12px;
  padding: 20px 22px;
  max-width: 100%;
  overflow-x: auto;
  line-height: 1.65;
  font-size: 13.5px;
  margin: 20px 0;
}

.book-article pre code {
  background: none;
  color: inherit;
  white-space: pre;
  padding: 0;
  border: none;
}

.book-article table {
  border-collapse: collapse;
  display: block;
  width: 100%;
  overflow-x: auto;
  white-space: normal;
  font-size: 14px;
  margin: 22px 0;
  -webkit-overflow-scrolling: touch;
}

.book-article th, .book-article td {
  padding: 12px 16px;
  border: 1px solid #e2e8f0;
  min-width: 110px;
  text-align: left;
  line-height: 1.6;
  vertical-align: top;
}

.book-article th {
  background: #f8fafc;
  color: #0f172a;
  font-weight: 700;
}

.book-article tr:nth-child(even) td {
  background: #fafbfc;
}

.book-article a {
  color: var(--accent, #5145e5);
  text-underline-offset: 3px;
  overflow-wrap: anywhere;
}

.book-article strong {
  color: #0f172a;
}

/* Understanding Checkpoint & Lab */
.book-checkpoint, .book-lab {
  border-radius: 18px;
  border: 1px solid #e2e8f0;
  background: #ffffff;
  padding: 28px 32px;
  margin-top: 24px;
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.03);
}

.book-checkpoint h3, .book-lab h3 {
  font-size: 20px;
  margin: 0 0 10px;
  color: #0f172a;
}

.book-checkpoint p, .book-lab p {
  color: #64748b;
  font-size: 13.5px;
  line-height: 1.8;
  margin-top: 0;
}

.book-quiz-item {
  margin: 22px 0 28px;
}

.book-quiz-item > strong {
  display: block;
  font-size: 15px;
  line-height: 1.6;
  margin-bottom: 12px;
  color: #0f172a;
}

.book-answer {
  display: block;
  padding: 13px 16px;
  margin: 9px 0;
  border: 1px solid #e2e8f0;
  background: #ffffff;
  border-radius: 11px;
  font: inherit;
  font-size: 13.5px;
  text-align: left;
  width: 100%;
  cursor: pointer;
  color: #334155;
  transition: all 0.15s ease;
  line-height: 1.5;
}

.book-answer:hover:not(:disabled) {
  border-color: #a5b4fc;
  background: #f5f3ff;
}

.book-answer.selected {
  background: #eef2ff;
  border-color: #6366f1;
  color: #3730a3;
  font-weight: 600;
}

.book-answer.correct {
  background: #ecfdf5;
  border-color: #34d399;
  color: #065f46;
  font-weight: 600;
}

.book-answer.wrong {
  background: #fff1f2;
  border-color: #f43f5e;
  color: #9f1239;
}

.book-explain {
  background: #f0fdf4;
  border-left: 3px solid #10b981;
  margin: 14px 0;
  padding: 14px 16px;
  font-size: 13.5px;
  line-height: 1.75;
  border-radius: 0 8px 8px 0;
  color: #14532d;
}

.book-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin-top: 20px;
}

.book-btn {
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  border: 0;
  border-radius: 10px;
  background: var(--accent, #5145e5);
  color: #ffffff;
  padding: 11px 18px;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.15s ease;
}

.book-btn:hover:not(:disabled) {
  background: var(--accent-dark, #372abb);
  transform: translateY(-1px);
}

.book-btn.secondary {
  border: 1px solid #cbd5e1;
  background: #ffffff;
  color: #475569;
}

.book-btn.secondary:hover:not(:disabled) {
  background: #f8fafc;
  border-color: #94a3b8;
}

.book-btn:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.book-note {
  color: #64748b;
  font-size: 12px;
}

/* Previous / Next Lesson Navigation Footer */
.book-nav-footer {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin: 32px 0 20px;
}

.book-nav-btn {
  display: flex;
  flex-direction: column;
  padding: 16px 20px;
  border: 1px solid var(--line, #e2e8f0);
  background: #ffffff;
  border-radius: 14px;
  text-align: left;
  cursor: pointer;
  transition: all 0.2s ease;
  color: inherit;
}

.book-nav-btn:hover {
  border-color: #a5b4fc;
  box-shadow: 0 6px 18px rgba(99, 102, 241, 0.08);
  transform: translateY(-1px);
}

.book-nav-btn.next {
  text-align: right;
  margin-left: auto;
  width: 100%;
}

.book-nav-dir {
  font-size: 11px;
  font-weight: 750;
  color: var(--accent, #5145e5);
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}

.book-nav-btn strong {
  font-size: 14px;
  color: #0f172a;
  line-height: 1.4;
}

.book-nav-placeholder {
  min-height: 1px;
}

/* Interactive Lab Form */
.book-lab-form {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin: 18px 0;
}

.book-lab-form label {
  font-size: 13px;
  font-weight: 700;
  color: #334155;
}

.book-lab-form input[type=number],
.book-lab-form input[type=text] {
  border: 1px solid #cbd5e1;
  border-radius: 9px;
  padding: 9px 12px;
  font: inherit;
  font-size: 13.5px;
  min-width: 0;
}

.book-lab-form input[type=range] {
  max-width: 180px;
  accent-color: var(--accent, #5145e5);
}

.book-lab-output {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 16px 18px;
  line-height: 1.8;
  font-size: 13.5px;
  white-space: pre-wrap;
  overflow-wrap: anywher;
  color: #334155;
}

/* Textbook Library Grid (Overview) */
.book-intro {
  padding: 22px 26px;
  background: var(--surface, #ffffff);
  border: 1px solid var(--line, #e3e6e3);
  border-radius: 12px;
  margin-bottom: 22px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.03);
}

.book-intro h2 {
  font-size: 22px;
  line-height: 1.35;
  margin: 6px 0 8px;
  color: var(--ink, #1f272c);
}

.book-intro p {
  line-height: 1.7;
  color: var(--ink-secondary, #48535a);
  font-size: 13.5px;
  margin: 0;
}

.book-overline {
  font-size: 11px;
  letter-spacing: 1px;
  color: var(--accent, #5145e5);
  font-weight: 850;
  text-transform: uppercase;
}

.book-library-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin: 20px 0;
}

.book-library-card {
  border: 1px solid var(--line, #e3e6e3);
  background: #ffffff;
  border-radius: 12px;
  padding: 18px 20px;
  text-align: left;
  cursor: pointer;
  font: inherit;
  color: inherit;
  transition: all 0.15s ease;
  display: flex;
  flex-direction: column;
  box-shadow: 0 1px 3px rgba(0,0,0,0.03);
}

.book-library-card:hover {
  border-color: var(--accent-border, #c8dede);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
  transform: translateY(-1px);
}

.book-library-card strong {
  display: block;
  font-size: 16px;
  margin: 10px 0 8px;
  line-height: 1.45;
  color: #0f172a;
}

.book-library-card p {
  font-size: 12.5px;
  color: #64748b;
  line-height: 1.65;
  margin: 0 0 14px;
  flex: 1;
}

.book-skip {
  display: inline-block;
  color: var(--accent, #5145e5);
  font-weight: 700;
  font-size: 12.5px;
}

.book-foot {
  padding: 24px 0 10px;
  font-size: 12px;
  color: #94a3b8;
  line-height: 1.7;
}

.book-empty {
  padding: 40px;
  border: 1px dashed #cbd5e1;
  border-radius: 16px;
  text-align: center;
  color: #64748b;
  background: #ffffff;
}

.book-notice {
  background: #fffbeb;
  border-left: 3px solid #f59e0b;
  padding: 14px 18px;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.8;
  color: #92400e;
  margin-top: 18px;
}

/* Responsive queries */
@media (max-width: 1200px) {
  .book-reading-wrap {
    grid-template-columns: 1fr;
  }
  .book-toc {
    display: none;
  }
}

@media (max-width: 768px) {
  .book-article {
    padding: 20px 18px;
    border-radius: 14px;
  }
  .book-breadcrumb {
    margin-bottom: 10px;
    font-size: 11.5px;
  }
  .book-meta {
    margin-bottom: 12px;
    gap: 6px;
  }
  .book-meta span {
    padding: 3px 8px;
    font-size: 11px;
  }
  .book-article h1 {
    font-size: 21px;
    margin: 0 0 16px;
  }
  .book-article h2 {
    font-size: 18px;
  }
  .book-intro {
  padding: 22px 26px;
  background: var(--surface, #ffffff);
  border: 1px solid var(--line, #e3e6e3);
  border-radius: 12px;
  margin-bottom: 22px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.03);
}
  .book-intro h2 {
  font-size: 22px;
  line-height: 1.35;
  margin: 6px 0 8px;
  color: var(--ink, #1f272c);
}
  .book-library-grid {
    grid-template-columns: 1fr;
  }
  .book-checkpoint, .book-lab {
    padding: 20px 18px;
  }
  .book-nav-footer {
    grid-template-columns: 1fr;
  }
}

/* Keep editable calculations inside the existing reading column. */
.book-matrix-fields { display:grid; grid-template-columns:repeat(auto-fit,minmax(min(100%,220px),1fr)); gap:14px; margin:16px 0; }
.book-matrix-fields label { display:grid; gap:6px; font-weight:600; }
.book-matrix-fields textarea { width:100%; box-sizing:border-box; min-width:0; padding:10px; font:inherit; font-family:monospace; border:1px solid var(--line,#d9dfe4); border-radius:8px; }
.book-lab-form label:has(input[type="number"]) { display:grid; gap:5px; }
.book-lab-form input[type="number"] { width:110px; max-width:100%; padding:8px; box-sizing:border-box; }
.book-lab-output { overflow-wrap:anywhere; white-space:pre-wrap; }
/* Inline formulae wrap on narrow screens; diagrams keep their own scroll area. */
.book-article { min-width:0; overflow-wrap:anywhere; }
.book-article :not(pre) > code { white-space:normal; overflow-wrap:anywhere; }


/* Interactive Labs & Visualizations in Textbook */
.book-matrix-presets {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.book-tag-btn {
  border: 1px solid var(--line, #e2e8f0);
  background: var(--surface, #ffffff);
  color: var(--ink-secondary, #475569);
  padding: 6px 14px;
  border-radius: 9999px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s cubic-bezier(0.16, 1, 0.3, 1);
}
.book-tag-btn:hover {
  background: #f8fafc;
  color: var(--accent, #4f46e5);
  border-color: #cbd5e1;
}
.book-tag-btn.active {
  background: #eef2ff;
  color: #4338ca;
  border-color: #818cf8;
  box-shadow: 0 1px 3px rgba(79, 70, 229, 0.1);
}

/* Attention Heatmap Visualizer */
.book-attn-visual-box {
  margin-top: 16px;
  padding: 20px;
  background: #ffffff;
  border: 1px solid var(--line, #e2e8f0);
  border-radius: 12px;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.03);
}
.book-attn-visual-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  flex-wrap: wrap;
  gap: 8px;
}
.book-attn-visual-head span {
  font-size: 14px;
  font-weight: 700;
  color: #0f172a;
}
.book-attn-visual-head small {
  font-size: 11.5px;
  color: #64748b;
}
.book-attn-rows {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.book-attn-row {
  display: grid;
  grid-template-columns: 140px 110px 1fr 180px;
  align-items: center;
  gap: 12px;
  font-size: 12.5px;
  padding: 8px 12px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
}
.book-attn-row-key {
  font-family: monospace;
  color: #334155;
}
.book-attn-row-score {
  color: #64748b;
  font-variant-numeric: tabular-nums;
}
.book-attn-row-bar-wrap {
  height: 22px;
  background: #f1f5f9;
  border-radius: 6px;
  overflow: hidden;
  position: relative;
}
.book-attn-row-bar {
  height: 100%;
  border-radius: 6px;
  display: flex;
  align-items: center;
  padding-left: 8px;
  font-size: 11px;
  font-weight: 700;
  transition: width 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.book-attn-row-val {
  font-size: 11.5px;
  color: #64748b;
  font-family: monospace;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.book-attn-context-box {
  margin-top: 14px;
  padding: 12px 16px;
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-radius: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}
.book-attn-context-box span {
  font-size: 13px;
  font-weight: 600;
  color: #166534;
}
.book-attn-context-box strong {
  font-size: 14px;
  color: #15803d;
  font-family: monospace;
  font-variant-numeric: tabular-nums;
}

/* Tokenizer Styles */
.book-token-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin: 16px 0;
  background: #f8fafc;
  border: 1px solid var(--line, #e2e8f0);
  border-radius: 10px;
  padding: 14px;
}
.book-token-stats div {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.book-token-stats span {
  font-size: 11px;
  color: #64748b;
}
.book-token-stats strong {
  font-size: 17px;
  font-weight: 700;
  color: #0f172a;
}
.book-token-stream-box {
  padding: 16px;
  background: #ffffff;
  border: 1px solid var(--line, #e2e8f0);
  border-radius: 12px;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.02);
}
.book-token-stream-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  font-size: 12px;
  color: #64748b;
}
.book-token-stream-head span {
  font-weight: 600;
  color: #0f172a;
}
.book-token-stream {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  line-height: 1.8;
  max-height: 240px;
  overflow-y: auto;
  padding: 8px;
  background: #f8fafc;
  border-radius: 8px;
  border: 1px solid #e2e8f0;
}
.book-tok-pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 7px;
  border-radius: 6px;
  font-size: 12.5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  cursor: default;
  transition: transform 0.1s ease, box-shadow 0.1s ease;
  user-select: text;
}
.book-tok-pill:hover {
  transform: translateY(-1px);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
}
.tok-c0 { background: #ede9fe; border: 1px solid #ddd6fe; color: #6d28d9; }
.tok-c1 { background: #e0f2fe; border: 1px solid #bae6fd; color: #0369a1; }
.tok-c2 { background: #ecfdf5; border: 1px solid #a7f3d0; color: #047857; }
.tok-c3 { background: #fef3c7; border: 1px solid #fde68a; color: #b45309; }
.tok-c4 { background: #ffe4e6; border: 1px solid #fecdd3; color: #be123c; }
.tok-c5 { background: #f3e8ff; border: 1px solid #e9d5ff; color: #7e22ce; }

/* Agent ReAct Lab */
.book-agent-flow {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 14px;
}
.book-agent-card {
  background: #ffffff;
  border: 1px solid var(--line, #e2e8f0);
  border-radius: 10px;
  padding: 14px 18px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.02);
  animation: bookCardFade 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes bookCardFade {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}
.book-agent-card.thought { border-left: 4px solid #818cf8; }
.book-agent-card.action { border-left: 4px solid #10b981; }
.book-agent-card.observation { border-left: 4px solid #f59e0b; }
.book-agent-card.final { border-left: 4px solid #6366f1; background: #faf5ff; }
.book-agent-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.book-agent-card-header strong {
  font-size: 13.5px;
  color: #0f172a;
}
.book-agent-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 9999px;
}
.badge-thought { background: #e0e7ff; color: #3730a3; }
.badge-action { background: #d1fae5; color: #065f46; }
.badge-obs { background: #fef3c7; color: #92400e; }
.badge-final { background: #ede9fe; color: #5b21b6; }
.book-agent-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px;
  line-height: 1.5;
  padding: 10px 12px;
  border-radius: 6px;
  border: 1px solid var(--line, #e2e8f0);
  margin: 6px 0 0;
  white-space: pre-wrap;
  word-break: break-all;
}

/* Engineering Intuition Takeaway Card */
.book-intuition-card {
  padding: 16px 20px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  margin-top: 18px;
}
.book-intuition-card strong {
  display: block;
  font-size: 13.5px;
  color: #0f172a;
  margin-bottom: 8px;
}
.book-intuition-card p {
  margin: 6px 0;
  font-size: 13px;
  line-height: 1.65;
  color: #475569;
}

@media (max-width: 900px) {
  .book-attn-row {
    grid-template-columns: 1fr;
    gap: 6px;
  }
  .book-token-stats {
    grid-template-columns: 1fr 1fr;
  }
}
