/* =====================================================
   BoK Chapter Reader — CSS
   Reuses tokens from css/styles.css ( --bg, --ink, --muted,
   --accent, --accent-soft, --line, --line-strong, --success,
   --success-soft, --error, --error-soft ). No new top-level
   palette tokens.
   ===================================================== */

:root {
  --reader-max: 920px;
  --sidebar-w: 248px;
  --bok-paper: #fafaf7;
  --bok-card: #ffffff;
  --bok-line: #e3ddca;
  --bok-card-line: #ddd6c5;
  --try-some-bg: rgba(255, 230, 120, 0.30);
  --try-some-border: rgba(200, 140, 0, 0.55);
  --try-some-hover-bg: rgba(255, 220, 80, 0.45);
  --try-some-accent: #c88c00;
}

body.bok-body {
  background: var(--bok-paper);
  margin: 0;
}

/* ===================================================== */
/* Reuse-the-site top brand bar  (.page-nav already exists in styles.css)*/
.bok-page-nav-wrap {
  max-width: 1240px;
  margin: 0 auto;
  padding: 28px 28px 0;
}

/* ===================================================== */
/* Layout grid (sidebar + main) */
.reader-app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  gap: 0;
  max-width: 1240px;
  margin: 0 auto;
  padding: 18px 16px 64px;
  align-items: start;
}

/* ----- Sidebar ----- */
.reader-sidebar {
  background: var(--bok-card);
  border: 1px solid var(--bok-line);
  border-radius: 10px;
  padding: 16px 14px;
  position: sticky;
  top: 16px;
  align-self: start;
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  font-size: 13px;
  color: var(--ink);
}
.reader-sidebar h3 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin: 0 0 8px;
}
.exam-toggle {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
}
.exam-toggle button {
  flex: 1;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 6px 10px;
  background: #fff;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
  letter-spacing: 0.04em;
}
.exam-toggle button.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.exam-toggle button:hover:not(.active) { background: var(--accent-soft); color: var(--accent); }

.chapter-list {
  list-style: none;
  padding: 0;
  margin: 0;
}
.chapter-list li {
  margin: 0;
}
.chapter-link {
  display: block;
  padding: 7px 9px;
  border-radius: 6px;
  color: var(--muted);
  cursor: pointer;
  font-size: 12.5px;
  line-height: 1.35;
  border: 1px solid transparent;
  margin-bottom: 2px;
  text-decoration: none;
}
.chapter-link:hover {
  background: var(--accent-soft);
  color: var(--accent);
}
.chapter-link.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--ink);
  font-weight: 600;
}
.chapter-link .ch-progress {
  display: block;
  font-size: 10.5px;
  color: var(--muted);
  letter-spacing: 0.04em;
  margin-top: 2px;
  font-weight: 400;
}
.chapter-link.active .ch-progress { color: var(--accent); }
.chapter-link.complete .ch-progress::before {
  content: "✓ ";
  color: var(--success);
  font-weight: 700;
}

/* ----- Main area ----- */
.reader-main {
  padding: 0 16px 32px;
  min-width: 0;
}

/* Hero row */
.reader-header {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--bok-card);
  border: 1px solid var(--bok-card-line);
  border-radius: 10px;
  padding: 16px 20px;
  margin: 0 auto 18px;
  max-width: var(--reader-max);
  box-shadow: 0 2px 8px rgba(0,0,0,0.04);
  flex-wrap: wrap;
}
.reader-header .title-stack { flex: 1; min-width: 200px; }
.reader-header h1 {
  font-size: 19px;
  margin: 0;
  color: var(--ink);
  letter-spacing: -0.005em;
}
.reader-header .meta {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}
.hero-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.skip-btn {
  background: var(--success);
  color: #fff;
  border: none;
  padding: 9px 16px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  font-family: inherit;
}
.skip-btn:hover { filter: brightness(.92); }

.exam-pill {
  background: #fff;
  color: var(--muted);
  border: 1px solid var(--line-strong);
  padding: 9px 14px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  letter-spacing: 0.04em;
  font-family: inherit;
}
.exam-pill.active { background: var(--ink); color: #fff; border-color: var(--ink); }

/* Page list */
.page-list { max-width: var(--reader-max); margin: 0 auto; }
.page-wrap {
  position: relative;
  background: #fff;
  border: 1px solid var(--bok-card-line);
  margin-bottom: 22px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.06);
  border-radius: 4px;
  overflow: hidden;
}
.page-wrap img {
  display: block;
  width: 100%;
  height: auto;
  min-height: 60px; /* prevents 0-height before load */
}
.page-label {
  position: absolute;
  top: 6px;
  right: 10px;
  background: rgba(0,0,0,0.55);
  color: #fff;
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 3px;
  font-family: 'SF Mono', Menlo, monospace;
  pointer-events: none;
  z-index: 2;
}

/* TRY SOME overlay */
.try-some-overlay {
  position: absolute;
  background: var(--try-some-bg);
  border: 2px dashed var(--try-some-border);
  border-radius: 6px;
  cursor: pointer;
  transition: background 120ms;
  z-index: 3;
}
.try-some-overlay:hover { background: var(--try-some-hover-bg); }
.try-some-overlay::after {
  content: "Click to practice ▾";
  position: absolute;
  top: -2px;
  left: 10px;
  background: var(--try-some-accent);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 0 0 4px 4px;
  letter-spacing: 0.03em;
}

/* TRY SOME widget under page */
.try-some-widget {
  background: #fffbeb;
  border: 1.5px solid #e1cf78;
  border-radius: 8px;
  padding: 14px 18px;
  margin: -12px auto 24px;
  max-width: var(--reader-max);
  box-shadow: 0 2px 8px rgba(150, 120, 0, 0.10);
}
.try-some-widget[hidden] { display: none !important; }
.try-some-widget h3 {
  font-size: 13px;
  margin: 0 0 4px;
  color: #8a6a00;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.try-some-widget .instruction {
  font-style: italic;
  font-size: 14px;
  margin-bottom: 12px;
  color: var(--ink);
}
.ts-item {
  padding: 10px 0;
  border-top: 1px solid #f0e5b5;
  font-size: 14px;
  line-height: 1.6;
  color: var(--ink);
}
.ts-item:first-of-type { border-top: none; }
.ts-choice-btn {
  display: inline-block;
  padding: 3px 10px;
  margin: 0 3px;
  background: #fff;
  border: 1.5px solid #b3a575;
  border-radius: 4px;
  cursor: pointer;
  font: inherit;
  color: var(--ink);
}
.ts-choice-btn:hover { background: #fef6c8; }
.ts-choice-btn.correct {
  background: var(--success-soft);
  border-color: var(--success);
  color: var(--success);
  font-weight: 600;
}
.ts-choice-btn.correct::before { content: "✓ "; font-weight: 700; }
.ts-choice-btn.wrong {
  background: var(--error-soft);
  border-color: var(--error);
  color: var(--error);
  text-decoration: line-through;
}
.ts-explanation {
  display: block;
  margin-top: 8px;
  font-size: 13px;
  font-style: italic;
  color: #4a6a4a;
  padding-left: 14px;
  border-left: 3px solid var(--success);
}
.ts-explanation[hidden] { display: none; }
.ts-numeric-stub {
  display: block;
  margin-top: 6px;
  font-size: 13px;
  color: var(--muted);
  font-style: italic;
}

/* Drill section */
.drills-section {
  max-width: var(--reader-max);
  margin: 32px auto 24px;
  padding: 24px;
  background: var(--bok-card);
  border: 1.5px solid var(--bok-card-line);
  border-radius: 10px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}
.drills-section h2 {
  font-size: 20px;
  margin: 0 0 4px;
  color: var(--ink);
}
.drills-section .lede {
  font-size: 13px;
  color: var(--muted);
  margin: 0 0 18px;
}
.drill-group {
  margin-bottom: 28px;
}
.drill-group:last-child { margin-bottom: 0; }
.drill-group-head {
  display: flex;
  align-items: baseline;
  gap: 12px;
  border-bottom: 1.5px solid var(--bok-line);
  padding-bottom: 8px;
  margin-bottom: 12px;
}
.drill-group-head h3 {
  margin: 0;
  font-size: 16px;
  color: var(--ink);
}
.drill-group-head .meta {
  font-size: 12px;
  color: var(--muted);
}
.drill-group-head .group-progress {
  font-size: 11px;
  color: var(--success);
  margin-left: auto;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.drill-card {
  background: #fafaf3;
  border: 1px solid var(--bok-line);
  border-radius: 8px;
  padding: 14px 16px;
  margin-bottom: 10px;
  font-size: 14px;
  line-height: 1.55;
}
.drill-card.answered.correct {
  border-color: var(--success);
  background: var(--success-soft);
}
.drill-card.answered.wrong {
  border-color: var(--error);
  background: var(--error-soft);
}
.drill-card .stem {
  margin: 0 0 10px;
  color: var(--ink);
}
.drill-card .stem strong { font-weight: 600; }
.drill-card .choices {
  display: grid;
  gap: 6px;
  margin: 0;
}
.drill-choice-btn {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  text-align: left;
  width: 100%;
  background: #fff;
  border: 1.5px solid var(--line);
  border-radius: 6px;
  padding: 8px 12px;
  cursor: pointer;
  font: inherit;
  color: var(--ink);
  line-height: 1.5;
}
.drill-choice-btn:hover { border-color: var(--ink); background: var(--accent-soft); }
.drill-choice-btn .letter {
  display: inline-block;
  width: 22px;
  font-weight: 700;
  color: var(--muted);
  flex: none;
}
.drill-choice-btn.correct {
  border-color: var(--success);
  background: var(--success-soft);
  color: var(--success);
  font-weight: 600;
}
.drill-choice-btn.correct .letter { color: var(--success); }
.drill-choice-btn.correct::after {
  content: " ✓";
  font-weight: 700;
}
.drill-choice-btn.wrong {
  border-color: var(--error);
  background: var(--error-soft);
  color: var(--error);
  text-decoration: line-through;
}
.drill-choice-btn.wrong .letter { color: var(--error); }
.drill-choice-btn:disabled { cursor: default; }
.drill-explanation {
  display: block;
  margin-top: 10px;
  font-size: 13px;
  color: #4a6a4a;
  font-style: italic;
  padding-left: 12px;
  border-left: 3px solid var(--success);
}
.drill-explanation[hidden] { display: none; }

.bluebook-launch {
  display: block;
  margin: 26px auto 0;
  max-width: var(--reader-max);
  text-align: center;
}
.bluebook-btn {
  display: inline-block;
  background: var(--success);
  color: #fff;
  padding: 12px 24px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 14px;
  text-decoration: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
}
.bluebook-btn:hover { filter: brightness(.92); text-decoration: none; color: #fff; }

/* Footer prev/next */
.chapter-foot {
  max-width: var(--reader-max);
  margin: 32px auto 0;
  display: flex;
  justify-content: space-between;
  gap: 12px;
}
.chapter-foot a {
  flex: 1;
  background: var(--bok-card);
  border: 1px solid var(--bok-card-line);
  border-radius: 8px;
  padding: 12px 16px;
  font-size: 13px;
  color: var(--ink);
  text-decoration: none;
}
.chapter-foot a:hover { border-color: var(--accent); background: var(--accent-soft); }
.chapter-foot a.disabled { opacity: 0.4; pointer-events: none; }
.chapter-foot a .lbl {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  color: var(--muted);
  letter-spacing: 0.06em;
  margin-bottom: 2px;
}
.chapter-foot a.next { text-align: right; }

/* Loading / empty states */
.loading {
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
  font-style: italic;
}
.loading.error { color: var(--error); }

/* Responsive */
@media (max-width: 880px) {
  .reader-app { grid-template-columns: 1fr; padding: 12px; }
  .reader-sidebar {
    position: relative;
    top: auto;
    max-height: none;
  }
  .reader-main { padding: 0; }
}

/* ===================================================== */
/* Whiteboard — optional 3rd column (chapters | textbook | whiteboard).
   Toggled by a `wb-on` class on <body> (js/whiteboard.js). */
:root { --whiteboard-w: 360px; }

body.wb-on .bok-page-nav-wrap,
body.wb-on .reader-app { max-width: 1640px; }
body.wb-on .reader-app {
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr) var(--whiteboard-w);
  column-gap: 18px;
}

.reader-whiteboard { display: none; }
body.wb-on .reader-whiteboard {
  display: flex;
  flex-direction: column;
  background: var(--bok-card);
  border: 1px solid var(--bok-line);
  border-radius: 10px;
  position: sticky;
  top: 16px;
  align-self: start;
  height: calc(100vh - 32px);
  overflow: hidden;
}
.wb-toolbar {
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
  padding: 10px; border-bottom: 1px solid var(--bok-line);
  background: var(--bok-paper);
}
.wb-swatch {
  width: 22px; height: 22px; border-radius: 50%; padding: 0;
  border: 2px solid #fff; box-shadow: 0 0 0 1px var(--bok-line); cursor: pointer;
}
.wb-swatch.is-active { box-shadow: 0 0 0 2px var(--ink, #23201c); }
.wb-sizes { display: flex; gap: 4px; margin-left: 2px; }
.wb-btn {
  font-size: 12px; line-height: 1; padding: 6px 9px; cursor: pointer;
  border: 1px solid var(--bok-line); border-radius: 7px;
  background: #fff; color: var(--ink, #23201c);
}
.wb-btn.is-active { background: var(--accent-soft, #e7ecff); border-color: var(--accent, #1f5ba8); }
.wb-size { min-width: 26px; font-weight: 700; text-align: center; }
.wb-canvas-wrap { flex: 1; position: relative; overflow: hidden; background: #fff; }
.wb-canvas { display: block; width: 100%; height: 100%; touch-action: none; cursor: crosshair; }
.wb-hint { font-size: 11px; color: var(--muted); padding: 7px 10px; border-top: 1px solid var(--bok-line); }

#bokWhiteboardToggle.is-on { background: var(--accent-soft, #e7ecff); }

/* Below 1100px there isn't room for 3 columns — collapse the whiteboard back to
   the 2-col reading layout even when wb-on (same body.wb-on specificity so it
   overrides the wide rules above), and hide the now-irrelevant toggle. */
@media (max-width: 1100px) {
  body.wb-on .bok-page-nav-wrap,
  body.wb-on .reader-app { max-width: 1240px; }
  body.wb-on .reader-app { grid-template-columns: var(--sidebar-w) 1fr; column-gap: 0; }
  body.wb-on .reader-whiteboard { display: none; }
  #bokWhiteboardToggle { display: none; }
}
@media (max-width: 880px) {
  body.wb-on .reader-app { grid-template-columns: 1fr; }
}
