:root {
  --bg: #f8fafc;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #1d4ed8;
  --primary-soft: #dbeafe;
  --accent: #0d9488;
  --border: #e2e8f0;
  --success: #059669;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-heading: Georgia, "Times New Roman", serif;
}

*, *::before, *::after { box-sizing: border-box; }
html {
  scroll-behavior: smooth;
  overflow-x: hidden;
}

body {
  margin: 0;
  font-family: var(--font);
  font-size: 1.05rem;
  line-height: 1.7;
  color: var(--text);
  background: var(--bg);
}

/* Text fields stay within layout (checkbox/radio excluded) */
input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="file"]):not([type="hidden"]),
textarea,
select {
  max-width: 100%;
}

a { color: var(--primary); }
a:hover { text-decoration: underline; }

.wrap {
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 0 min(1.25rem, 4vw);
  box-sizing: border-box;
}

.wrap-wide {
  width: 100%;
  max-width: min(70rem, 100%);
  margin-left: auto;
  margin-right: auto;
  padding: 0 min(1.25rem, 4vw);
  box-sizing: border-box;
}

main.chapter-main {
  padding-bottom: 3rem;
}

/* Chapter lessons: span full width of the content column (beside course sidebar) */
main.chapter-main.wrap-wide {
  max-width: none;
  width: 100%;
}

/* Match hero title band to the same width as chapter main */
body.course-logged-in.course-page:has(> main.chapter-main) .hero .wrap-wide {
  max-width: none;
  width: 100%;
}

/* Structure lesson — full-height column; width comes from global .wrap-wide (min(70rem, 100%)). */
body.structure-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

body.structure-page .structure-main {
  flex: 1 1 auto;
  width: 100%;
}

body.structure-page .structure-section {
  flex: 1 1 auto;
}

body.structure-page .structure-pair-grid {
  display: grid;
  gap: 2rem;
  margin: 1.5rem 0 0;
}

@media (min-width: 768px) {
  body.structure-page .structure-pair-grid {
    grid-template-columns: 1fr 1fr;
    gap: 2rem 2.5rem;
    align-items: start;
  }
}

@media (min-width: 640px) {
  ul.structure-chapter-grid.check {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.4rem 1.75rem;
    margin: 0.75rem 0 1rem;
  }
}

body.structure-page .structure-mcq {
  margin-top: 2.25rem;
  padding: 2rem min(1.25rem, 4vw) 2.25rem;
  margin-left: calc(-1 * min(1.25rem, 4vw));
  margin-right: calc(-1 * min(1.25rem, 4vw));
  width: calc(100% + 2 * min(1.25rem, 4vw));
  max-width: none;
  box-sizing: border-box;
  border-radius: 10px;
}

body.structure-page .structure-mcq h2 {
  margin-top: 0;
}

/* Top bar */
:root {
  --course-bar-height: 3.35rem;
  --course-account-width: min(18rem, 92vw);
  /* Above article overlays (1000), stylish overlays (1200), sticky course bar (1080) */
  --course-menu-fab-z: 1250;
  /* When offcanvas is open: backdrop over FAB, panel over backdrop (Bootstrap defaults are ~1040–1045) */
  --course-offcanvas-backdrop-z: 1265;
  --course-offcanvas-panel-z: 1270;
}

.course-bar.navbar {
  background: var(--card) !important;
  padding: 0;
  position: sticky;
  top: 0;
  z-index: 1080;
  min-height: var(--course-bar-height);
}

.course-bar-inner {
  padding-left: calc(min(1rem, 3vw) + env(safe-area-inset-left, 0px)) !important;
  padding-right: calc(min(1rem, 3vw) + env(safe-area-inset-right, 0px)) !important;
  min-height: calc(var(--course-bar-height) - 0.25rem);
}

.course-bar-brand {
  flex: 1 1 auto;
  min-width: 0;
  font-weight: 600;
  color: var(--text);
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.course-bar-brand:hover {
  color: var(--primary);
}

.course-bar-auth {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  font-size: 0.9rem;
  align-items: center;
  flex: 0 0 auto;
  margin-left: auto;
}

.course-bar-auth a {
  font-weight: 600;
  color: var(--text);
  text-decoration: none;
}

.course-bar-auth a:hover {
  color: var(--primary);
}

.course-bar-actions {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  align-self: stretch;
}

.course-bar-user {
  flex: 0 1 auto;
  max-width: min(14rem, 42vw);
  margin-left: auto;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: right;
}

@media (min-width: 992px) {
  .course-bar-user {
    margin-left: 0;
    text-align: left;
  }
}

@media (max-width: 380px) {
  .course-bar-user {
    max-width: min(9rem, 32vw);
    font-size: 0.75rem;
  }
}

/* Menu toggle (Bootstrap btn + custom icon) */
.course-account-toggle {
  position: relative;
  min-width: 2.75rem;
  min-height: 2.75rem;
  padding: 0.45rem 0.75rem;
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  border-radius: 999px !important;
  background-color: #dcf4fc !important;
  border-color: #86baef !important;
  color: #161b65 !important;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.course-account-toggle-burger {
  display: block;
  flex-shrink: 0;
  opacity: 0.9;
}

.course-account-toggle-label {
  display: inline;
}

@media (max-width: 380px) {
  .course-account-toggle {
    padding: 0.45rem;
    min-width: 2.75rem;
    gap: 0 !important;
  }
  .course-account-toggle-label {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }
}

@media (min-width: 992px) {
  .course-account-toggle {
    display: none !important;
  }
}

/* Top-right so chapter/main content keeps normal symmetric horizontal padding (no left gutter) */
.course-account-toggle--floating {
  position: fixed;
  top: calc(0.55rem + env(safe-area-inset-top, 0px));
  left: auto;
  right: calc(0.55rem + env(safe-area-inset-right, 0px));
  z-index: var(--course-menu-fab-z);
  box-shadow: 0 2px 14px rgba(15, 23, 42, 0.14);
}

@media (max-width: 991.98px) {
  body.course-logged-in .offcanvas-backdrop {
    z-index: var(--course-offcanvas-backdrop-z) !important;
  }
}

/* Bootstrap offcanvas: course sidebar (full-height overlay on small screens; fixed column on lg+) */
.course-account-panel.offcanvas {
  --bs-offcanvas-width: var(--course-account-width);
  --bs-offcanvas-zindex: var(--course-offcanvas-panel-z);
  top: 0;
  height: 100vh;
  height: 100dvh;
  max-height: none;
  z-index: var(--course-offcanvas-panel-z);
  padding-left: env(safe-area-inset-left, 0px);
  border-right: 1px solid var(--border);
  box-shadow: 8px 0 32px rgba(15, 23, 42, 0.12);
  background-color: var(--card) !important;
  color: var(--text) !important;
}

.course-account-panel .offcanvas-body {
  flex: 1 1 auto;
  min-height: 0;
}

.course-account-panel .offcanvas-header {
  padding: 0.85rem 1rem;
  flex-shrink: 0;
}

@media (min-width: 992px) {
  .course-account-panel.offcanvas {
    transform: translateX(0) !important;
    visibility: visible !important;
    z-index: 195;
    --bs-offcanvas-zindex: 195;
  }

  .offcanvas-backdrop {
    display: none !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  .course-account-panel.offcanvas {
    transition: none !important;
  }
}

.course-account-panel-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
}

.course-account-panel-inner {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1rem 1.15rem calc(1.25rem + env(safe-area-inset-bottom, 0px));
  overflow-y: auto;
  flex: 1;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.course-account-panel-user {
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.course-account-name {
  margin: 0 0 0.35rem;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  word-break: break-word;
}

.course-account-id {
  margin: 0 0 0.35rem;
  font-size: 0.88rem;
  color: var(--muted);
  font-family: ui-monospace, Consolas, monospace;
  letter-spacing: 0.04em;
}

.course-account-id-label {
  font-family: var(--font);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-right: 0.25rem;
}

.course-account-email {
  margin: 0.25rem 0 0;
  font-size: 0.85rem;
  color: var(--muted);
  word-break: break-all;
}

.course-account-panel-links-label {
  margin: 0 0 0.35rem;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.course-account-panel-links {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.course-account-panel-links a {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--primary);
  text-decoration: none;
  padding: 0.35rem 0;
}
.course-account-panel-links a:hover {
  text-decoration: underline;
}

.course-account-panel-links a[aria-current="page"] {
  color: var(--text, #0f172a);
  font-weight: 700;
  text-decoration: none;
  background: rgba(13, 148, 136, 0.12);
  border-radius: 6px;
  box-shadow: inset 3px 0 0 var(--accent, #0d9488);
  padding-left: 0.4rem;
  margin-left: -0.4rem;
  margin-right: -0.15rem;
}
.course-account-panel-links a[aria-current="page"]:hover {
  text-decoration: none;
  background: rgba(13, 148, 136, 0.18);
}

.course-account-panel-links--chapters {
  gap: 0.2rem;
}

.course-account-panel-links--chapters a {
  display: flex;
  align-items: baseline;
  gap: 0.45rem;
  font-weight: 500;
  padding: 0.28rem 0;
}

.course-account-panel-links--chapters a[aria-current="page"] {
  padding: 0.35rem 0.35rem 0.35rem 0.45rem;
  margin-left: -0.45rem;
  margin-right: -0.35rem;
}

.course-account-panel-links--chapters a[aria-current="page"] .course-chapter-link-num {
  color: var(--accent, #0d9488);
  font-weight: 700;
}

.course-account-panel-links--chapters a[aria-current="page"] .course-chapter-link-title {
  color: var(--text, #0f172a);
  font-weight: 600;
}

.course-chapter-link-num {
  flex: 0 0 2rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.course-chapter-link-title {
  color: var(--primary);
  line-height: 1.25;
}

.course-account-logout {
  display: block;
  margin-top: auto;
  padding: 0.65rem 1rem;
  text-align: center;
  font-weight: 600;
  font-size: 0.95rem;
  color: #b91c1c;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 8px;
  text-decoration: none;
  transition: background 0.15s;
}
.course-account-logout:hover {
  background: #fee2e2;
}

/* Chapter lesson pages: fixed left column from lg up; below lg use offcanvas + floating Menu control */
body.course-logged-in.course-page {
  --course-account-width: min(17rem, min(88vw, 45vw + 7.5rem));
}
@media (max-width: 479px) {
  body.course-logged-in.course-page {
    --course-account-width: min(15.5rem, calc(100vw - 10.5rem));
  }
}
@media (min-width: 992px) {
  body.course-logged-in.course-page {
    --course-account-width: min(18rem, 92vw);
  }
  body.course-logged-in.course-page .course-account-panel.offcanvas {
    transform: translateX(0) !important;
    visibility: visible !important;
  }
  body.course-logged-in.course-page .course-account-toggle {
    display: none !important;
  }
  
  body.course-logged-in.course-page .hero,
  body.course-logged-in.course-page main,
  body.course-logged-in.course-page > footer {
    padding-left: calc(var(--course-account-width) + min(1.25rem, 4vw));
  }
  /* Course home, part overviews, etc.: same left gutter when the panel is present */
  body.course-logged-in:has(#course-account-panel) .hero,
  body.course-logged-in:has(#course-account-panel) main,
  body.course-logged-in:has(#course-account-panel) > footer {
    padding-left: calc(var(--course-account-width) + min(1.25rem, 4vw));
  }
}

/* Hero */
.hero {
  padding: 2.5rem min(1.25rem, 4vw) 2rem;
  max-width: 100%;
  box-sizing: border-box;
  background: linear-gradient(135deg, #1e3a5f 0%, #0f172a 100%);
  color: #f1f5f9;
}
.hero h1 {
  font-family: var(--font-heading);
  font-size: clamp(1.75rem, 4vw, 2.35rem);
  margin: 0 0 0.75rem;
  line-height: 1.2;
}
.hero .tagline { margin: 0; opacity: 0.92; font-size: 1.05rem; }
.hero .chapter-label {
  margin: 0 0 0.35rem;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  opacity: 0.85;
  font-weight: 600;
}
.hero .teacher-note {
  margin-top: 1.25rem;
  padding: 1rem 1.25rem;
  background: rgba(255,255,255,0.1);
  border-radius: 8px;
  border-left: 4px solid var(--accent);
  font-size: 0.98rem;
}

/* Home: chapter list with progress + score */
.course-chapter-board {
  margin: 1.25rem 0 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--card);
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
}
.course-chapter-board__head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 9.5rem 6.5rem;
  gap: 0.75rem 1rem;
  align-items: center;
  padding: 0.55rem 1rem;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
  color: var(--muted);
  background: #f1f5f9;
  border-bottom: 1px solid var(--border);
}
.course-chapter-board__list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.course-chapter-board__row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 9.5rem 6.5rem;
  gap: 0.75rem 1rem;
  align-items: center;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border);
}
.course-chapter-board__row:last-child {
  border-bottom: none;
}
.course-chapter-board__row:hover {
  background: rgba(29, 78, 216, 0.04);
}
.course-chapter-board__link {
  display: block;
  text-decoration: none;
  color: inherit;
}
.course-chapter-board__link:hover .course-chapter-board__title {
  text-decoration: underline;
  color: var(--primary);
}
.course-chapter-board__title {
  display: block;
  font-weight: 700;
  font-size: 1rem;
  color: #0f172a;
}
.course-chapter-board__blurb {
  display: block;
  font-size: 0.86rem;
  color: var(--muted);
  margin-top: 0.2rem;
  line-height: 1.35;
}
.course-chapter-board__progress {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  align-items: flex-start;
  font-size: 0.82rem;
  color: #334155;
}
.course-chapter-board__progress-text {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.course-chapter-board__correct-hint {
  font-size: 0.78rem;
  color: var(--muted);
}
.course-chapter-segments {
  display: flex;
  gap: 3px;
  flex-wrap: nowrap;
}
.course-chapter-segments__seg {
  width: 7px;
  height: 10px;
  border-radius: 2px;
  background: var(--border);
}
.course-chapter-segments__seg--on {
  background: var(--primary);
  opacity: 0.9;
}
.course-chapter-board__score {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.15rem;
}
.course-score-pill {
  display: inline-block;
  font-weight: 700;
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
  padding: 0.2rem 0.55rem;
  border-radius: 6px;
  line-height: 1.2;
}
.course-score-pill--high {
  background: #ecfdf5;
  color: #047857;
  border: 1px solid rgba(5, 150, 105, 0.35);
}
.course-score-pill--mid {
  background: #fffbeb;
  color: #b45309;
  border: 1px solid rgba(245, 158, 11, 0.4);
}
.course-score-pill--low {
  background: #fef2f2;
  color: #b91c1c;
  border: 1px solid rgba(248, 113, 113, 0.45);
}
.course-chapter-board__score-detail {
  font-size: 0.75rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.course-chapter-board__na {
  color: var(--muted);
  font-size: 1.1rem;
  line-height: 1;
}

@media (max-width: 900px) {
  .course-chapter-board__head {
    display: none;
  }
  .course-chapter-board__row {
    grid-template-columns: 1fr;
    gap: 0.65rem;
    padding: 1rem 1rem;
  }
  .course-chapter-board__progress,
  .course-chapter-board__score {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem 0.75rem;
  }
  .course-chapter-board__progress::before {
    content: "Progress";
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
    flex-basis: 100%;
    font-weight: 600;
  }
  .course-chapter-board__score::before {
    content: "Saved score";
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
    flex-basis: 100%;
    font-weight: 600;
  }
}

/* Sections */
.section {
  padding: 2.5rem min(1.25rem, 4vw);
  max-width: 100%;
  box-sizing: border-box;
}
.section-alt { background: var(--card); border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }

.chapter-constitution-wrap {
  margin-top: 1rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card);
  overflow: hidden;
}
.chapter-constitution-pre {
  margin: 0;
  padding: 1.25rem 1.25rem 1.5rem;
  font-size: 0.8125rem;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-x: auto;
  font-family: ui-monospace, "Cascadia Code", "Source Code Pro", Menlo, Consolas, monospace;
  color: #1e293b;
}

/* Full chapter extract on the page (from chapter.txt) */
.chapter-fulltext-section {
  margin-top: 1.25rem;
}
.chapter-fulltext-section h3 {
  margin-top: 0;
  margin-bottom: 0.35rem;
}
.chapter-fulltext-lead {
  margin-bottom: 1rem;
}
.chapter-fulltext-header {
  margin-bottom: 1rem;
}
.chapter-fulltext-heading-wrap {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
}
.chapter-fulltext-icon {
  flex-shrink: 0;
  margin-top: 0.15rem;
}
h3.chapter-fulltext-heading {
  margin-top: 0;
  margin-bottom: 0.35rem;
  font-size: 1.15rem;
}
.chapter-constitution-wrap.enhanced-scroll {
  max-height: min(70vh, 42rem);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}
.chapter-fulltext-details {
  margin-top: 1rem;
  padding: 0.75rem 1rem;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.92rem;
  color: #475569;
}
.chapter-fulltext-details summary {
  cursor: pointer;
  font-weight: 600;
  color: #334155;
}
.chapter-fulltext-details p {
  margin: 0.65rem 0 0;
  line-height: 1.55;
}

.article-grid-intro-wrap {
  font-size: 0.96rem;
  color: #334155;
  line-height: 1.55;
}

h2 {
  font-family: var(--font-heading);
  font-size: 1.5rem;
  margin: 0 0 1rem;
  color: #0f172a;
}
h3 { font-size: 1.15rem; margin: 1.75rem 0 0.5rem; color: #1e293b; }
h4 { font-size: 1rem; margin: 1.25rem 0 0.4rem; color: #334155; }

.lead { color: var(--muted); margin: 0 0 1rem; }

/* Teacher boxes */
.teacher {
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: 8px;
  padding: 1rem 1.25rem;
  margin: 1rem 0;
}
.teacher strong { color: #92400e; }
.tip {
  background: var(--primary-soft);
  border-left: 4px solid var(--primary);
  padding: 0.85rem 1.1rem;
  margin: 1rem 0;
  border-radius: 0 6px 6px 0;
  font-size: 0.98rem;
}

/* Article lists (dt/dd pairs: label column + text) */
.article-grid {
  display: grid;
  grid-template-columns: minmax(3.5rem, max-content) minmax(0, 1fr);
  column-gap: 1rem;
  row-gap: 0.5rem;
  margin: 0.75rem 0 1rem;
  font-size: 0.95rem;
  align-items: start;
}
.article-grid dt {
  font-weight: 600;
  color: var(--primary);
  margin: 0;
  padding-top: 0.1rem;
}
.article-grid dd {
  margin: 0 0 0.65rem 0;
  color: #334155;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.5rem;
}
@media (max-width: 420px) {
  .article-grid {
    grid-template-columns: 1fr;
  }
  .article-grid dt {
    margin-bottom: -0.2rem;
  }
}
.article-grid-more-wrap {
  line-height: 1.55;
}
.article-grid-more {
  align-self: flex-end;
  margin-top: 0.15rem;
  padding: 0.35rem 0.75rem;
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--primary);
  background: var(--primary-soft);
  border: 1px solid rgba(29, 78, 216, 0.25);
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.article-grid-more:hover {
  background: #dbeafe;
  border-color: var(--primary);
}
.article-grid-more:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

ul.check { margin: 0.5rem 0 1rem; padding-left: 1.35rem; }
ul.check li { margin-bottom: 0.35rem; }

/* Quiz */
.quiz {
  margin-top: 1.75rem;
  padding: 1.35rem 1.5rem;
  background: #f1f5f9;
  border-radius: 10px;
  border: 1px solid var(--border);
}
.quiz h3 {
  margin: 0 0 1rem;
  font-size: 1.1rem;
  color: #0f172a;
}
.quiz details {
  margin-bottom: 0.85rem;
  background: var(--card);
  border-radius: 6px;
  border: 1px solid var(--border);
  overflow: hidden;
}
.quiz summary {
  padding: 0.85rem 1rem;
  cursor: pointer;
  font-weight: 500;
  list-style: none;
}
.quiz summary::-webkit-details-marker { display: none; }
.quiz summary::before { content: "❓ "; }
.quiz details[open] summary { border-bottom: 1px solid var(--border); }
.quiz .answer {
  padding: 0.75rem 1rem 1rem;
  font-size: 0.95rem;
  color: var(--muted);
  border-top: 1px dashed var(--border);
}
.quiz .answer strong { color: var(--success); }

/* TOC */
.toc {
  display: grid;
  gap: 0.5rem;
  margin: 1rem 0 0;
  padding: 0;
  list-style: none;
}
.toc a {
  display: block;
  padding: 0.65rem 1rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 6px;
  text-decoration: none;
  color: var(--text);
  transition: border-color 0.2s, box-shadow 0.2s;
}
.toc a:hover {
  border-color: var(--primary);
  box-shadow: 0 2px 8px rgba(29, 78, 216, 0.12);
}

.toc-chapters {
  display: grid;
  gap: 0.45rem;
}
@media (min-width: 640px) {
  .toc-chapters {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* Multiple choice (chapter pages) */
.mcq-section h2 { margin-top: 0; }
.mcq-progress-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.75rem 1rem;
  margin: 0.75rem 0 0;
  padding: 0.65rem 0.85rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: rgba(29, 78, 216, 0.04);
}
.mcq-progress-line {
  margin: 0;
  font-size: 0.92rem;
  color: #334155;
  text-align: center;
  flex: 1 1 12rem;
}
.mcq-progress-text {
  font-weight: 500;
}
.mcq-redo-btn {
  flex-shrink: 0;
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 600;
  padding: 0.45rem 0.85rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--primary);
}
.mcq-redo-btn:hover {
  border-color: var(--primary);
}
.mcq-section.mcq-choices-locked .mcq-opt {
  cursor: not-allowed;
}
.mcq-section.mcq-choices-locked .mcq-opt input:disabled {
  cursor: not-allowed;
  opacity: 0.88;
}
.mcq-block {
  margin-bottom: 1.35rem;
  padding: 1rem 1.15rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.mcq-q { margin: 0 0 0.65rem; }
.mcq-options {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 0.65rem;
}
.mcq-opt {
  display: flex;
  align-items: flex-start;
  gap: 0.35rem;
  cursor: default;
  font-size: 0.98rem;
  color: #334155;
  min-width: 0;
}
.mcq-opt > span {
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
}
.mcq-opt input { margin-top: 0.35rem; flex-shrink: 0; accent-color: var(--primary); }
.mcq-reveal {
  border-top: 1px dashed var(--border);
  padding-top: 0.5rem;
}
.mcq-reveal summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--primary);
  list-style: none;
  font-size: 0.95rem;
}
.mcq-reveal summary::-webkit-details-marker { display: none; }
.mcq-reveal[open] summary { margin-bottom: 0.5rem; }
.mcq-answer {
  padding: 0.65rem 0.85rem;
  background: #ecfdf5;
  border-radius: 6px;
  border-left: 3px solid var(--success);
  font-size: 0.95rem;
}
.mcq-answer p { margin: 0; }

.mcq-notes-link {
  margin: 0.45rem 0 0;
  font-size: 0.88rem;
}
.mcq-notes-link-a {
  font-weight: 600;
  color: var(--primary);
  text-decoration: none;
  border-bottom: 1px solid rgba(29, 78, 216, 0.35);
}
.mcq-notes-link-a:hover {
  border-bottom-color: var(--primary);
}
/* Pulsating ring + soft background breathe (~3.6s total, 3 cycles) */
@keyframes course-notes-target-pulse {
  0%,
  100% {
    box-shadow:
      0 1px 0 rgba(29, 78, 216, 0.12),
      inset 0 0 0 1px rgba(29, 78, 216, 0.12),
      0 0 0 0 rgba(29, 78, 216, 0.5);
    filter: brightness(1);
  }
  50% {
    box-shadow:
      0 1px 0 rgba(29, 78, 216, 0.12),
      inset 0 0 0 1px rgba(29, 78, 216, 0.12),
      0 0 0 16px rgba(29, 78, 216, 0);
    filter: brightness(1.03);
  }
}

@keyframes course-notes-sibling-pulse {
  0%,
  100% {
    background: rgba(29, 78, 216, 0.055);
    border-left-color: rgba(29, 78, 216, 0.35);
  }
  50% {
    background: rgba(29, 78, 216, 0.11);
    border-left-color: rgba(29, 78, 216, 0.55);
  }
}

/* Quiz “Review in notes” jump target: persistent band + pulsate a few seconds */
main article.section h3[id^="course-note-"],
main .structure-wrap h2[id^="course-note-"],
main .structure-wrap h3[id^="course-note-"] {
  scroll-margin-top: 5rem;
  transition:
    background 0.35s ease,
    box-shadow 0.35s ease,
    border-color 0.35s ease;
}

main article.section h3[id^="course-note-"]:target,
main .structure-wrap h2[id^="course-note-"]:target,
main .structure-wrap h3[id^="course-note-"]:target {
  background: linear-gradient(
    90deg,
    rgba(29, 78, 216, 0.14) 0%,
    rgba(29, 78, 216, 0.05) 55%,
    transparent 100%
  );
  border-left: 4px solid var(--primary);
  padding: 0.55rem 0.85rem 0.55rem 0.75rem;
  margin-left: -0.35rem;
  margin-right: -0.35rem;
  border-radius: 0 10px 10px 0;
  box-shadow:
    0 1px 0 rgba(29, 78, 216, 0.12),
    inset 0 0 0 1px rgba(29, 78, 216, 0.12);
  filter: none;
  animation: course-notes-target-pulse 1.2s ease-in-out 3;
}

/* First block of notes under that heading (dl / list / paragraph) */
main article.section h3[id^="course-note-"]:target + dl,
main article.section h3[id^="course-note-"]:target + p,
main article.section h3[id^="course-note-"]:target + ul,
main .structure-wrap h2[id^="course-note-"]:target + p,
main .structure-wrap h2[id^="course-note-"]:target + dl,
main .structure-wrap h2[id^="course-note-"]:target + ul,
main .structure-wrap h3[id^="course-note-"]:target + dl {
  background: rgba(29, 78, 216, 0.055);
  border-radius: 0 0 10px 10px;
  padding: 0.65rem 0.85rem;
  margin-left: -0.35rem;
  margin-right: -0.35rem;
  margin-top: -0.25rem;
  padding-top: 0.85rem;
  border-left: 3px solid rgba(29, 78, 216, 0.35);
  box-shadow: inset 0 1px 0 rgba(29, 78, 216, 0.08);
  transition: background 0.35s ease;
  animation: course-notes-sibling-pulse 1.2s ease-in-out 3;
}

@media (prefers-reduced-motion: reduce) {
  main article.section h3[id^="course-note-"]:target,
  main .structure-wrap h2[id^="course-note-"]:target,
  main .structure-wrap h3[id^="course-note-"]:target {
    animation: none;
    filter: none;
  }
  main article.section h3[id^="course-note-"]:target + dl,
  main article.section h3[id^="course-note-"]:target + p,
  main article.section h3[id^="course-note-"]:target + ul,
  main .structure-wrap h2[id^="course-note-"]:target + p,
  main .structure-wrap h2[id^="course-note-"]:target + dl,
  main .structure-wrap h2[id^="course-note-"]:target + ul,
  main .structure-wrap h3[id^="course-note-"]:target + dl {
    animation: none;
  }
}

.mcq-quiz-status {
  margin: 0.5rem 0 0;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--muted);
}
.mcq-block-correct .mcq-quiz-status { color: var(--success); }
.mcq-block-incorrect .mcq-quiz-status { color: #b45309; }
.mcq-block-correct {
  border-color: rgba(5, 150, 105, 0.35);
}
.mcq-block-incorrect {
  border-color: rgba(180, 83, 9, 0.35);
}

.mcq-lock-notice {
  margin-top: 0.25rem;
  margin-bottom: 1.25rem;
  color: var(--muted);
  font-weight: 500;
}

.progress-table-wrap {
  overflow-x: auto;
  margin: 1rem 0;
}
.progress-table {
  width: 100%;
  max-width: 36rem;
  border-collapse: collapse;
  font-size: 0.95rem;
}
.progress-table th,
.progress-table td {
  padding: 0.55rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.progress-table th {
  font-weight: 600;
  color: var(--muted);
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* Article explanation overlay */
.article-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}
.article-overlay.is-open {
  visibility: visible;
  opacity: 1;
  pointer-events: auto;
}
.article-overlay-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  cursor: pointer;
}
.article-overlay-panel {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 46rem;
  max-height: min(92vh, 52rem);
  display: flex;
  flex-direction: column;
  background: var(--card);
  border-radius: 12px;
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.25);
  border: 1px solid var(--border);
  overflow: hidden;
}
.article-overlay-close {
  position: absolute;
  top: 0.65rem;
  right: 0.65rem;
  width: 2.25rem;
  height: 2.25rem;
  border: none;
  border-radius: 8px;
  background: #f1f5f9;
  color: #475569;
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.article-overlay-close:hover {
  background: #e2e8f0;
  color: #0f172a;
}
.article-overlay-heading {
  font-family: var(--font-heading);
  font-size: 1.15rem;
  margin: 0;
  padding: 1.1rem 3rem 0.75rem 1.25rem;
  color: #0f172a;
  border-bottom: 1px solid var(--border);
  line-height: 1.4;
  letter-spacing: -0.01em;
}
.article-overlay-body {
  padding: 1.1rem 1.25rem 1.35rem;
  overflow-y: auto;
  color: #334155;
  font-size: 0.98rem;
  line-height: 1.65;
}
.article-overlay-body .article-overlay-chapter-txt {
  margin: 0;
  font-family: Courier, monospace;
  font-size: 0.8125rem;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: break-word;
  color: #1e293b;
  text-align: justify;
  text-justify: inter-word;
  hyphens: auto;
  -webkit-hyphens: auto;
}

/* Verbatim article text (matches chapter.txt layout; Courier, not reformatted lists) */
.article-overlay-body .article-overlay-article-pre {
  margin: 0;
  font-family: Courier, monospace;
  font-size: 0.8125rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: break-word;
  color: #1e293b;
  text-align: left;
  tab-size: 4;
}
.article-overlay-body .article-excerpt-plain {
  margin: 0;
}
.article-overlay-body .article-excerpt-clauses {
  list-style: none;
  margin: 0;
  padding: 0;
}
.article-overlay-body .article-excerpt-clauses > li {
  display: flex;
  gap: 0.65rem;
  align-items: flex-start;
  margin-bottom: 1rem;
}
.article-overlay-body .article-excerpt-clauses > li:last-child {
  margin-bottom: 0;
}
.article-overlay-body .article-clause-label {
  flex: 0 0 auto;
  min-width: 1.75em;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--primary);
  line-height: 1.65;
}
.article-overlay-body .article-clause-text {
  flex: 1;
  min-width: 0;
}
.article-overlay-body .article-clause-text > p {
  margin: 0 0 0.5rem 0;
}
.article-overlay-body .article-clause-text > p:last-child {
  margin-bottom: 0;
}
.article-overlay-body .article-excerpt-lead {
  margin: 0 0 0.6rem 0;
}
.article-overlay-body .article-excerpt-subclauses {
  list-style: none;
  margin: 0.35rem 0 0 0;
  padding: 0 0 0 0.65rem;
  border-left: 2px solid #e2e8f0;
}
.article-overlay-body .article-excerpt-subclauses li {
  margin-bottom: 0.45rem;
  display: flex;
  gap: 0.4rem;
  align-items: flex-start;
  line-height: 1.55;
}
.article-overlay-body .article-excerpt-subclauses li:last-child {
  margin-bottom: 0;
}
.article-overlay-body .article-sub-label {
  flex: 0 0 auto;
  font-weight: 600;
  color: #475569;
  font-size: 0.95em;
}
.article-overlay-body .article-clause-unnumbered .article-clause-text {
  flex: 1;
}
.article-overlay-body .article-overlay-block + .article-overlay-block {
  margin-top: 1.25rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
}
.article-overlay-body .article-overlay-block:first-child .article-overlay-subheading {
  margin-top: 0;
}
.article-overlay-subheading {
  font-family: var(--font-heading);
  font-size: 0.95rem;
  font-weight: 600;
  margin: 0 0 0.5rem 0;
  color: #0f172a;
}

/* Footer */
footer {
  padding: 2rem 1.25rem;
  text-align: center;
  font-size: 0.85rem;
  color: var(--muted);
  border-top: 1px solid var(--border);
}

/* Final quiz %: directly under the MCQ, before “Finished this chapter?” */
.chapter-score-wrap {
  margin: 2rem 0 0;
}
.chapter-score-wrap:has(.chapter-score-slot:empty) {
  display: none;
  margin: 0;
}
.chapter-score-slot {
  margin: 0;
}
.chapter-score-slot--primary .chapter-score-card {
  width: 100%;
  max-width: 40rem;
  margin: 0 auto;
  box-sizing: border-box;
  text-align: center;
  padding: 1.1rem 1.35rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  background: linear-gradient(
    120deg,
    rgba(29, 78, 216, 0.09) 0%,
    var(--card) 42%,
    var(--card) 100%
  );
  box-shadow: 0 2px 12px rgba(15, 23, 42, 0.06);
}
.chapter-score-main {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: center;
  gap: 0.65rem 1.1rem;
  margin: 0 0 0.35rem;
}
.chapter-score-pct {
  font-family: var(--font-heading);
  font-size: clamp(2.1rem, 6vw, 3rem);
  font-weight: 700;
  color: var(--primary);
  line-height: 1;
  letter-spacing: -0.02em;
}
.chapter-score-fraction {
  font-size: 1.05rem;
  font-weight: 600;
  color: #0f172a;
}
.chapter-score-note {
  margin: 0;
  font-size: 0.88rem;
  color: var(--muted);
}
.chapter-done {
  margin-top: 1.35rem;
}
.chapter-score-wrap:not(:has(.chapter-score-slot:empty)) + .chapter-done {
  margin-top: 1.25rem;
}
.chapter-done-inner {
  text-align: center;
  max-width: 36rem;
  margin: 0 auto;
}
.chapter-done-title {
  font-family: var(--font-heading);
  font-size: 1.25rem;
  margin: 0 0 0.35rem;
  color: #0f172a;
}
.chapter-done-lead {
  margin: 0 0 1.1rem;
  font-size: 0.95rem;
  color: var(--muted);
}
.chapter-done-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  justify-content: center;
  align-items: center;
}
.chapter-done-primary,
.chapter-done-secondary {
  display: inline-block;
  padding: 0.65rem 1.25rem;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.95rem;
  text-decoration: none;
  transition: opacity 0.15s, background 0.15s;
}
.chapter-done-primary {
  background: var(--primary);
  color: #fff !important;
  border: 1px solid var(--primary);
}
.chapter-done-primary:hover {
  opacity: 0.94;
  text-decoration: none;
}
.chapter-done-secondary {
  background: var(--card);
  color: var(--primary) !important;
  border: 1px solid var(--border);
}
.chapter-done-secondary:hover {
  border-color: var(--primary);
  text-decoration: none;
}

.page-nav {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 1rem;
  margin: 2rem 0 0;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}
.page-nav > *:nth-child(1) {
  justify-self: start;
}
.page-nav > *:nth-child(2) {
  justify-self: center;
}
.page-nav > *:nth-child(3) {
  justify-self: end;
}
@media (max-width: 640px) {
  .page-nav {
    grid-template-columns: 1fr;
  }
  .page-nav > *:nth-child(1),
  .page-nav > *:nth-child(2),
  .page-nav > *:nth-child(3) {
    justify-self: stretch;
  }
  .page-nav a {
    text-align: center;
    width: 100%;
    box-sizing: border-box;
  }
}
.page-nav-spacer {
  flex: 0 0 auto;
  width: 0;
  height: 0;
  overflow: hidden;
  pointer-events: none;
  justify-self: start;
}
.page-nav a {
  display: inline-block;
  padding: 0.6rem 1.2rem;
  background: var(--primary);
  color: #fff !important;
  text-decoration: none;
  border-radius: 6px;
  font-weight: 600;
  font-size: 0.95rem;
}
.page-nav a:hover { opacity: 0.92; text-decoration: none; }
.page-nav a.secondary {
  background: var(--card);
  color: var(--primary) !important;
  border: 1px solid var(--border);
}

kbd {
  font-size: 0.85em;
  padding: 0.15rem 0.4rem;
  background: #e2e8f0;
  border-radius: 4px;
}

/* Auth: login / register + gate modal */
.auth-panel {
  width: 100%;
  max-width: min(28.75rem, 100%);
  margin: 0 auto;
  padding: 2rem 0 3rem;
  box-sizing: border-box;
}

.auth-panel h1 {
  font-family: var(--font-heading);
  font-size: clamp(1.35rem, 2.5vw, 1.65rem);
  margin: 0 0 0.5rem;
}

.auth-panel img {
  max-width: 100%;
  height: auto;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-top: 1.5rem;
  width: 100%;
  max-width: 100%;
  min-width: 0;
}
.auth-form-section-title {
  font-family: var(--font-heading);
  font-size: 1.05rem;
  font-weight: 600;
  color: #0f172a;
  margin: 1.25rem 0 0;
  padding-bottom: 0.25rem;
  border-bottom: 1px solid var(--border);
}
.auth-form-section-title:first-child {
  margin-top: 0;
}
.auth-form label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.9rem;
  font-weight: 600;
  color: #334155;
  width: 100%;
  min-width: 0;
}
.auth-form label span { font-weight: 600; }
.auth-form input,
.auth-form textarea,
.auth-form select {
  display: block;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  padding: 0.65rem 0.75rem;
  font-size: max(16px, 1rem);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: inherit;
  box-sizing: border-box;
}
.auth-form input:focus,
.auth-form select:focus,
.auth-form textarea:focus {
  outline: 2px solid var(--primary-soft);
  border-color: var(--primary);
}
.auth-submit {
  margin-top: 0.5rem;
  width: 100%;
  max-width: 100%;
  padding: 0.75rem 1.25rem;
  font-size: 1rem;
  font-weight: 600;
  color: #fff;
  background: var(--primary);
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  box-sizing: border-box;
}
.auth-submit:hover { opacity: 0.92; }
.auth-error {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #991b1b;
  padding: 0.75rem 1rem;
  border-radius: 6px;
  margin: 1rem 0 0;
  font-size: 0.95rem;
}

.auth-modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.auth-modal.is-open { display: flex; }
.auth-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
}
.auth-modal-box {
  position: relative;
  background: var(--card);
  border-radius: 10px;
  padding: 1.5rem min(1.5rem, 4vw) 1.25rem;
  max-width: min(26.25rem, calc(100vw - 2rem));
  width: 100%;
  box-sizing: border-box;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.18);
  border: 1px solid var(--border);
}
.auth-modal-box h2 {
  margin: 0 0 0.5rem;
  font-size: 1.25rem;
}
.auth-modal-box p {
  margin: 0 0 1rem;
  color: var(--muted);
  font-size: 0.98rem;
}
.auth-modal-actions {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.auth-modal-actions a {
  display: block;
  text-align: center;
  padding: 0.65rem 1rem;
  border-radius: 6px;
  font-weight: 600;
  text-decoration: none;
}
.auth-modal-actions a.primary {
  background: var(--primary);
  color: #fff !important;
}
.auth-modal-actions a.primary:hover { opacity: 0.92; text-decoration: none; }
.auth-modal-actions a.secondary {
  background: var(--card);
  color: var(--primary) !important;
  border: 1px solid var(--border);
}
.auth-modal-actions a.secondary:hover { text-decoration: none; }
.auth-modal-close {
  margin-top: 0.75rem;
  width: 100%;
  padding: 0.5rem;
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 0.9rem;
  cursor: pointer;
  font-family: inherit;
}
.auth-modal-close:hover { color: var(--text); }

/* Register: fill viewport on large screens, form uses width comfortably */
@media (min-width: 900px) {
  body.auth-register {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
  }

  main.auth-register-main {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-top: clamp(1.25rem, 4vh, 2.75rem);
    padding-bottom: clamp(1.25rem, 4vh, 2.75rem);
    box-sizing: border-box;
  }

  body.auth-register .auth-register-panel {
    width: 100%;
    max-width: min(44rem, 100%);
    margin-left: auto;
    margin-right: auto;
    padding: clamp(1.75rem, 3vh, 2.5rem) clamp(1.5rem, 3vw, 2.25rem);
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 4px 24px rgba(15, 23, 42, 0.06);
  }

  body.auth-register .auth-register-panel .auth-form {
    margin-top: 1.25rem;
  }
}

@media (min-width: 1100px) {
  body.auth-register .auth-register-panel {
    max-width: min(52rem, 100%);
  }

  body.auth-register .auth-form {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem 1.5rem;
    align-items: start;
  }

  body.auth-register .auth-form-section-title {
    grid-column: 1 / -1;
    margin-top: 1.15rem;
  }

  body.auth-register .auth-form-section-title:first-of-type {
    margin-top: 0;
  }

  body.auth-register .auth-submit {
    grid-column: 1 / -1;
    margin-top: 0.35rem;
  }
}
