/* ============================================================================
 * The Learn library (/learn) — reading surface on top of theme.css tokens.
 * Paper first: large type, generous measure, a quiet left contents panel and a
 * right rail that follows the reader. Light by default (see _LearnTheme.cshtml);
 * dark is a softened slate, never black. All classes are `lb-` prefixed.
 * ========================================================================== */

.learn {
  --lb-bg: #faf9f6;
  --lb-paper: #ffffff;
  --lb-panel: #f3f1ec;
  --lb-ink: #1d2430;
  --lb-ink-soft: #3d4654;
  --lb-muted: #6a7382;
  --lb-faint: #9aa3b1;
  --lb-border: #e4e0d8;
  --lb-border-strong: #cfcac0;
  --lb-accent: var(--sc-accent, #3b82f6);
  /* Text on the accent: the site derives a dark ink from the accent (theme.css), which stays
     readable whether the visitor picked gold, blue or green. */
  --lb-accent-ink: var(--sc-accent-ink, #1d2430);
  /* Links in running text need more contrast than the raw accent gives on paper. */
  --lb-link: color-mix(in srgb, var(--lb-accent), #1d2430 38%);
  --lb-accent-soft: color-mix(in srgb, var(--lb-accent) 12%, #ffffff);
  --lb-hl: #fff2a8;
  --lb-hl-note: #dff3e4;
  --lb-hl-comment: #e2ecff;
  --lb-hl-other: #f1e9ff;
  --lb-good: #2f9e5b;
  --lb-bad: #d64545;
  --lb-sq-l: #f0e6d2;
  --lb-sq-d: #b58a63;
  --lb-shadow: 0 10px 30px -14px rgba(20, 24, 32, 0.25), 0 2px 6px -2px rgba(20, 24, 32, 0.12);
  --lb-radius: 12px;
  --lb-nav-w: 290px;
  --lb-rail-w: 270px;

  color: var(--lb-ink);
  background: var(--lb-bg);
  font-family: var(--sc-font-body, Inter, system-ui, sans-serif);
  /* The library fills the screen: a fixed two-column shell where the main column, not the
     window, scrolls. The site header and footer are not rendered on these pages. */
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-columns: var(--lb-nav-w) minmax(0, 1fr);
  overflow: hidden;
}
body.learn-body {
  overflow: hidden;
  height: 100vh;
}
body.learn-body::before {
  display: none;
}
[data-bs-theme='dark'] .learn {
  --lb-link: color-mix(in srgb, var(--lb-accent), #ffffff 25%);
  --lb-bg: #242b36;
  --lb-paper: #2b333f;
  --lb-panel: #1f262f;
  --lb-ink: #e9ebef;
  --lb-ink-soft: #cfd4dc;
  --lb-muted: #a5adba;
  --lb-faint: #7b8493;
  --lb-border: #3a4352;
  --lb-border-strong: #4a5567;
  --lb-accent-soft: color-mix(in srgb, var(--lb-accent) 22%, #2b333f);
  --lb-hl: #6b5a1a;
  --lb-hl-note: #24503a;
  --lb-hl-comment: #27406a;
  --lb-hl-other: #45385f;
  --lb-sq-l: #c9c2b2;
  --lb-sq-d: #7d6350;
  --lb-shadow: 0 10px 30px -14px rgba(0, 0, 0, 0.6), 0 2px 6px -2px rgba(0, 0, 0, 0.4);
}
/* Running-text links only. Buttons, cards, nav rows and outline entries carry their own colour. */
.lb-prose a,
.lb-callout a,
.lb-lede a,
.lb-muted a,
.lb-section-blurb a,
.lb-nav-progress-label a,
.lb-nav-foot a,
.lb-tutor-empty a,
.lb-quiz-score a,
.lb-comment a,
.lb-rail-tip a {
  color: var(--lb-link);
}

/* ---- Reading progress bar ------------------------------------------------- */
.lb-readbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  z-index: 1040;
  background: transparent;
  pointer-events: none;
}
.lb-readbar span {
  display: block;
  height: 100%;
  width: 0;
  background: var(--lb-accent);
  transition: width 0.15s linear;
}

/* ---- Left contents panel -------------------------------------------------- */
.lb-nav {
  height: 100vh;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--lb-panel);
  border-right: 1px solid var(--lb-border);
  padding: 1.25rem 1rem 2rem;
  font-size: 0.95rem;
  scrollbar-width: thin;
}
.lb-nav-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.6rem;
}
.lb-nav-brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  color: var(--lb-ink);
  text-decoration: none;
  min-width: 0;
}
.lb-nav-brand img {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25), 0 0 0 1px rgba(255, 255, 255, 0.08) inset;
}
.lb-nav-brand span {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}
.lb-nav-brand b {
  font-family: var(--sc-font-display, inherit);
  font-weight: 700;
  font-size: 0.98rem;
  letter-spacing: -0.02em;
  white-space: nowrap;
}
.lb-nav-brand b em {
  font-style: normal;
  color: var(--lb-accent);
}
.lb-nav-brand small {
  font-family: var(--sc-font-mono, monospace);
  font-size: 0.62rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--lb-muted);
  margin-top: 0.15rem;
}
.lb-nav-back {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.82rem;
  color: var(--lb-muted);
  text-decoration: none;
  margin-bottom: 0.9rem;
}
.lb-nav-back:hover {
  color: var(--lb-ink);
}
.lb-nav-empty {
  font-size: 0.85rem;
  color: var(--lb-muted);
  padding: 0.5rem 0.25rem;
}
.lb-nav-close {
  display: none;
  border: 0;
  background: transparent;
  font-size: 1.6rem;
  line-height: 1;
  color: var(--lb-muted);
}
.lb-nav-progress {
  margin-bottom: 1rem;
}
.lb-nav-progress-bar,
.lb-rail-progress-bar {
  height: 6px;
  border-radius: 99px;
  background: var(--lb-border);
  overflow: hidden;
}
.lb-nav-progress-bar span,
.lb-rail-progress-bar span {
  display: block;
  height: 100%;
  background: var(--lb-accent);
  border-radius: 99px;
  transition: width 0.3s ease;
}
.lb-nav-progress-label {
  margin-top: 0.4rem;
  font-size: 0.82rem;
  color: var(--lb-muted);
}
.lb-nav-section {
  border-top: 1px solid var(--lb-border);
  padding: 0.5rem 0;
}
.lb-nav-section summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.45rem 0.25rem;
  font-weight: 600;
  color: var(--lb-ink);
}
.lb-nav-section summary::-webkit-details-marker {
  display: none;
}
.lb-nav-section summary::after {
  content: '';
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--lb-faint);
  border-bottom: 2px solid var(--lb-faint);
  transform: rotate(-45deg);
  margin-left: 0.5rem;
  transition: transform 0.15s;
}
.lb-nav-section[open] summary::after {
  transform: rotate(45deg);
}
.lb-nav-section-count {
  font-size: 0.75rem;
  color: var(--lb-faint);
  font-variant-numeric: tabular-nums;
  margin-left: auto;
  margin-right: 0.5rem;
}
.lb-nav ul {
  list-style: none;
  margin: 0;
  padding: 0 0 0.25rem;
}
.lb-nav-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.45rem 0.55rem 0.45rem 0.4rem;
  border-radius: 8px;
  color: var(--lb-ink-soft);
  text-decoration: none;
  line-height: 1.3;
}
.lb-nav-item:hover {
  background: var(--lb-paper);
  color: var(--lb-ink);
}
.lb-nav-item.is-current {
  background: var(--lb-accent-soft);
  color: var(--lb-ink);
  font-weight: 600;
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--lb-accent) 45%, transparent);
}
.lb-check {
  flex: 0 0 auto;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 1.5px solid var(--lb-border-strong);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: transparent;
  background: transparent;
  transition: all 0.15s;
}
.is-read > .lb-check,
.is-read .lb-check {
  background: var(--lb-good);
  border-color: var(--lb-good);
  color: #fff;
}
.lb-nav-label {
  flex: 1 1 auto;
}
.lb-quiz-badge {
  flex: 0 0 auto;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  border: 1px solid var(--lb-border-strong);
  color: var(--lb-faint);
}
.lb-quiz-badge.is-passed {
  background: var(--lb-good);
  border-color: var(--lb-good);
  color: #fff;
}
.lb-nav-foot {
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--lb-border);
  display: grid;
  gap: 0.35rem;
  font-size: 0.85rem;
}

/* ---- Main column: top bar, then article + rail --------------------------- */
.lb-main {
  min-width: 0;
  height: 100vh;
  overflow-y: auto;
  overscroll-behavior: contain;
  scroll-behavior: smooth;
}
.lb-content {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--lb-rail-w);
  gap: 3rem;
  padding: 1.5rem clamp(1rem, 4vw, 3.5rem) 5rem;
  max-width: 1320px;
  margin: 0 auto;
}
.learn--index .lb-content {
  grid-template-columns: minmax(0, 1fr);
  max-width: 1040px;
}

/* Top bar: contents (phones), search, tutor, theme, account. Sticks to the top of the scroller. */
.lb-topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.55rem clamp(1rem, 3vw, 2rem);
  background: color-mix(in srgb, var(--lb-bg) 86%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--lb-border);
}
.lb-topbar-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  border: 1px solid var(--lb-border-strong);
  background: var(--lb-paper);
  color: var(--lb-ink);
  border-radius: 9px;
  padding: 0.45rem 0.75rem;
  font-size: 0.88rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}
.lb-topbar-btn:hover {
  border-color: var(--lb-accent);
  color: var(--lb-ink);
}
.lb-topbar-btn--icon {
  padding: 0.45rem 0.55rem;
}
.lb-topbar-btn--nav {
  display: none;
}
.lb-topbar-btn--tutor {
  color: var(--lb-link);
  border-color: color-mix(in srgb, var(--lb-accent) 50%, transparent);
}
.lb-topbar-link {
  border-color: transparent;
  background: transparent;
  color: var(--lb-ink-soft);
}
.lb-topbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
[data-bs-theme='dark'] .lb-icon-moon {
  display: none;
}
[data-bs-theme='light'] .lb-icon-sun {
  display: none;
}

/* Search */
.lb-search {
  position: relative;
  flex: 0 1 460px;
  min-width: 140px;
}
.lb-search-icon {
  position: absolute;
  left: 0.7rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--lb-faint);
  pointer-events: none;
}
.lb-search input {
  width: 100%;
  border: 1px solid var(--lb-border-strong);
  background: var(--lb-paper);
  color: var(--lb-ink);
  border-radius: 99px;
  padding: 0.5rem 0.9rem 0.5rem 2.1rem;
  font: inherit;
  font-size: 0.92rem;
}
.lb-search input:focus {
  outline: none;
  border-color: var(--lb-accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--lb-accent) 22%, transparent);
}
.lb-search-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  z-index: 40;
  background: var(--lb-paper);
  border: 1px solid var(--lb-border-strong);
  border-radius: 12px;
  box-shadow: var(--lb-shadow);
  overflow: hidden;
  max-height: 60vh;
  overflow-y: auto;
}
.lb-search-hit {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.1rem 0.75rem;
  padding: 0.65rem 0.9rem;
  border-bottom: 1px solid var(--lb-border);
  color: var(--lb-ink);
  text-decoration: none;
  font-size: 0.9rem;
}
.lb-search-hit:last-child {
  border-bottom: 0;
}
.lb-search-hit:hover,
.lb-search-hit.is-first {
  background: var(--lb-accent-soft);
}
.lb-search-hit-title {
  font-weight: 700;
}
.lb-search-hit-section {
  font-size: 0.72rem;
  color: var(--lb-faint);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  align-self: center;
}
.lb-search-hit-snippet {
  grid-column: 1 / -1;
  color: var(--lb-muted);
  font-size: 0.82rem;
  line-height: 1.4;
}

.lb-article {
  max-width: 74ch;
  min-width: 0;
}
.lb-article .op-crumbs {
  margin-bottom: 1.25rem;
}
.lb-eyebrow {
  font-family: var(--sc-font-mono, monospace);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--lb-link);
  margin: 0 0 0.6rem;
}
.lb-article-head h1,
.lb-hero h1 {
  font-family: var(--sc-font-display, inherit);
  font-weight: 700;
  font-size: clamp(2rem, 3.6vw, 2.75rem);
  line-height: 1.12;
  letter-spacing: -0.015em;
  margin: 0 0 0.9rem;
  color: var(--lb-ink);
}
.lb-lede {
  font-size: 1.22rem;
  line-height: 1.6;
  color: var(--lb-ink-soft);
  margin: 0 0 1rem;
}
.lb-article-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1.25rem;
  font-size: 0.88rem;
  color: var(--lb-muted);
  padding: 0.9rem 0 1.4rem;
  border-bottom: 1px solid var(--lb-border);
  margin-bottom: 1.75rem;
}
.lb-markread {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  border: 1px solid var(--lb-border-strong);
  background: var(--lb-paper);
  color: var(--lb-ink);
  border-radius: 99px;
  padding: 0.4rem 0.9rem 0.4rem 0.5rem;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  margin-left: auto;
}
.lb-markread:hover {
  border-color: var(--lb-good);
}
.lb-markread.is-read {
  background: color-mix(in srgb, var(--lb-good) 12%, var(--lb-paper));
  border-color: var(--lb-good);
}
.lb-markread--big {
  font-size: 1rem;
  padding: 0.6rem 1.2rem 0.6rem 0.7rem;
  margin: 0;
}

/* ---- Prose ----------------------------------------------------------------- */
.lb-prose {
  font-size: 1.16rem;
  line-height: 1.78;
  color: var(--lb-ink);
  position: relative;
}
.lb-prose > * + * {
  margin-top: 1.15em;
}
.lb-prose h2 {
  font-family: var(--sc-font-display, inherit);
  font-size: 1.65rem;
  line-height: 1.25;
  font-weight: 700;
  margin-top: 2.4em;
  margin-bottom: 0.1em;
  scroll-margin-top: 4.5rem;
  letter-spacing: -0.01em;
}
.lb-prose h3 {
  font-size: 1.25rem;
  font-weight: 700;
  margin-top: 1.8em;
  scroll-margin-top: 4.5rem;
}
.lb-prose p {
  margin: 0;
}
.lb-prose ul,
.lb-prose ol {
  padding-left: 1.4em;
}
.lb-prose li + li {
  margin-top: 0.5em;
}
.lb-prose strong {
  color: var(--lb-ink);
  font-weight: 700;
}
.lb-prose code {
  font-family: var(--sc-font-mono, monospace);
  font-size: 0.9em;
  background: var(--lb-panel);
  padding: 0.05em 0.35em;
  border-radius: 4px;
}
.lb-prose blockquote {
  border-left: 3px solid var(--lb-accent);
  padding: 0.25rem 0 0.25rem 1.1rem;
  color: var(--lb-ink-soft);
  font-style: italic;
}
.lb-prose table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}
.lb-prose th,
.lb-prose td {
  border-bottom: 1px solid var(--lb-border);
  padding: 0.5rem 0.6rem;
  text-align: left;
}
.lb-prose ::selection {
  background: color-mix(in srgb, var(--lb-accent) 30%, transparent);
}

/* Marks: highlight (yellow), note (green), comment (blue), other readers (violet). */
mark.lb-hl {
  background: var(--lb-hl);
  color: inherit;
  padding: 0.05em 0;
  border-radius: 2px;
  cursor: pointer;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}
mark.lb-hl--note {
  background: var(--lb-hl-note);
  border-bottom: 2px solid var(--lb-good);
}
mark.lb-hl--comment {
  background: var(--lb-hl-comment);
  border-bottom: 2px solid var(--lb-accent);
}
mark.lb-hl--other {
  background: var(--lb-hl-other);
  border-bottom: 2px dotted #8b6bd6;
}

/* ---- Board diagrams --------------------------------------------------------- */
.lb-figure {
  margin: 1.6em auto;
  max-width: 400px;
}
.lb-figure figcaption {
  margin-top: 0.7rem;
  font-size: 0.93rem;
  line-height: 1.5;
  color: var(--lb-muted);
  text-align: center;
}
.lb-board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  aspect-ratio: 1;
  width: 100%;
  border-radius: 6px;
  overflow: hidden;
  box-shadow: var(--lb-shadow);
  border: 1px solid var(--lb-border-strong);
  user-select: none;
}
.lb-sq {
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 1;
}
.lb-sq--l {
  background: var(--lb-sq-l);
}
.lb-sq--d {
  background: var(--lb-sq-d);
}
.lb-pc {
  font-size: clamp(22px, 5.5vw, 36px);
  line-height: 1;
  font-family: 'DejaVu Sans', 'Segoe UI Symbol', 'Noto Sans Symbols2', sans-serif;
}
.lb-pc--w {
  color: #fbfaf5;
  text-shadow: 0 0 1px #000, 0 0 2px #000, 0 1px 2px rgba(0, 0, 0, 0.7);
}
.lb-pc--b {
  color: #1a1a1a;
  text-shadow: 0 0 1px rgba(255, 255, 255, 0.35);
}
.lb-board-turn {
  position: absolute;
  right: 6px;
  bottom: 6px;
  font-family: var(--sc-font-mono, monospace);
  font-size: 0.62rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
}

/* ---- Chessground diagrams: the same board and controls as /patterns -------- */
.lb-cg {
  max-width: 460px;
  margin: 0 auto;
}
.lb-figure {
  max-width: 460px;
}
.learn .op-cg {
  gap: 0.6rem;
}
.learn .op-cg-holder {
  width: 100%;
  aspect-ratio: 1 / 1;
}
.learn .op-cg-controls .btn {
  margin-right: 0.5rem !important;
}
/* The board controls hard-code a white icon for the dark site; on paper they need ink. */
.learn .op-cg-controls .btn svg {
  color: var(--lb-ink) !important;
}
[data-bs-theme='dark'] .learn .op-cg-controls .btn svg {
  color: #ffffff !important;
}
.learn .op-cg-analysis {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
  justify-content: center;
}
.learn .op-cg-eval {
  font-family: var(--sc-font-mono, monospace);
  font-weight: 700;
}
.learn .op-cg-hint {
  font-size: 0.82rem;
  color: var(--lb-faint);
  text-align: center;
  margin: 0;
}
.learn .op-cg-caption {
  font-size: 0.93rem;
  color: var(--lb-muted);
  text-align: center;
  margin: 0;
}
.lb-q-board .lb-cg,
.lb-q-board .op-cg {
  max-width: 320px;
  margin: 0;
}
.lb-q-board .op-cg-controls {
  justify-content: flex-start !important;
}

/* ---- Callouts, footer, prev/next ----------------------------------------- */
.lb-callout {
  margin-top: 2.5rem;
  padding: 1.1rem 1.3rem;
  border-radius: var(--lb-radius);
  background: var(--lb-accent-soft);
  border: 1px solid color-mix(in srgb, var(--lb-accent) 35%, transparent);
  font-size: 1rem;
  line-height: 1.6;
}
.lb-callout a {
  font-weight: 600;
}
.lb-callout > a:last-child {
  display: inline-block;
  margin-top: 0.4rem;
}
.lb-article-foot {
  margin-top: 2.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--lb-border);
  display: grid;
  gap: 1.5rem;
}
.lb-prevnext {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}
.lb-prevnext-link {
  display: block;
  padding: 0.9rem 1.1rem;
  border: 1px solid var(--lb-border);
  border-radius: var(--lb-radius);
  background: var(--lb-paper);
  color: var(--lb-ink);
  text-decoration: none;
  font-weight: 600;
  line-height: 1.3;
}
.lb-prevnext-link:hover {
  border-color: var(--lb-accent);
}
.lb-prevnext-link small {
  display: block;
  font-weight: 400;
  font-size: 0.78rem;
  color: var(--lb-muted);
  margin-bottom: 0.2rem;
}
.lb-prevnext-link--next {
  text-align: right;
}
.lb-muted {
  color: var(--lb-muted);
}

/* ---- Buttons ----------------------------------------------------------------- */
.lb-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border: 1px solid var(--lb-border-strong);
  background: var(--lb-paper);
  color: var(--lb-ink);
  border-radius: 10px;
  padding: 0.65rem 1.1rem;
  font-weight: 600;
  font-size: 0.95rem;
  text-decoration: none;
  cursor: pointer;
  transition: all 0.15s;
}
.lb-btn:hover {
  border-color: var(--lb-accent);
  color: var(--lb-ink);
}
.lb-btn--primary {
  background: var(--lb-accent);
  border-color: var(--lb-accent);
  color: var(--lb-accent-ink);
}
.lb-btn--primary:hover {
  filter: brightness(1.08);
  color: var(--lb-accent-ink);
}
.lb-btn--sm {
  padding: 0.4rem 0.75rem;
  font-size: 0.85rem;
}
.lb-btn--danger {
  color: var(--lb-bad);
}
.lb-btn:disabled {
  opacity: 0.55;
  cursor: default;
}

/* ---- Right rail ------------------------------------------------------------ */
.lb-rail {
  min-width: 0;
}
.lb-rail-inner {
  position: sticky;
  top: 4.5rem;
  display: grid;
  gap: 1.1rem;
}
.lb-practice {
  border: 1.5px solid var(--lb-accent);
  border-radius: var(--lb-radius);
  padding: 1rem 1.1rem 1.1rem;
  background: linear-gradient(160deg, var(--lb-accent-soft), var(--lb-paper) 70%);
}
.lb-practice-head {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 1.02rem;
  margin-bottom: 0.4rem;
}
.lb-practice-icon {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--lb-paper);
  border: 1px solid var(--lb-border);
  font-size: 1.2rem;
}
.lb-practice p {
  font-size: 0.9rem;
  color: var(--lb-ink-soft);
  margin: 0 0 0.8rem;
  line-height: 1.5;
}
.lb-practice .lb-btn {
  width: 100%;
}
.lb-tutor-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  border: 1px solid color-mix(in srgb, var(--lb-accent) 50%, transparent);
  background: var(--lb-paper);
  color: var(--lb-link);
  border-radius: 10px;
  padding: 0.65rem 1rem;
  font-weight: 600;
  cursor: pointer;
}
.lb-tutor-btn:hover {
  background: var(--lb-accent-soft);
}
.lb-rail-progress-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.82rem;
  color: var(--lb-muted);
  margin-bottom: 0.4rem;
}
.lb-outline-title {
  font-weight: 700;
  font-size: 0.95rem;
  margin-bottom: 0.4rem;
}
.lb-outline ul {
  list-style: none;
  margin: 0;
  padding: 0;
  border-left: 2px solid var(--lb-border);
}
.lb-outline li a {
  display: block;
  padding: 0.3rem 0 0.3rem 0.85rem;
  font-size: 0.88rem;
  line-height: 1.35;
  color: var(--lb-muted);
  text-decoration: none;
  margin-left: -2px;
  border-left: 2px solid transparent;
}
.lb-outline-l3 a {
  padding-left: 1.6rem !important;
  font-size: 0.82rem !important;
}
.lb-outline li a:hover {
  color: var(--lb-ink);
}
.lb-outline li a.is-active {
  color: var(--lb-link);
  border-left-color: var(--lb-accent);
  font-weight: 600;
}
.lb-rail-tip {
  font-size: 0.8rem;
  color: var(--lb-faint);
  line-height: 1.45;
}

/* ---- Selection toolbar + popover ------------------------------------------- */
.lb-toolbar {
  position: fixed;
  transform: translate(-50%, calc(-100% - 10px));
  z-index: 1050;
  display: flex;
  gap: 2px;
  padding: 4px;
  background: var(--lb-ink);
  color: #fff;
  border-radius: 10px;
  box-shadow: var(--lb-shadow);
  white-space: nowrap;
}
[data-bs-theme='dark'] .lb-toolbar {
  background: #0f141b;
}
.lb-toolbar > button {
  border: 0;
  background: transparent;
  color: #fff;
  padding: 0.45rem 0.7rem;
  border-radius: 7px;
  font-size: 0.86rem;
  font-weight: 600;
}
.lb-toolbar > button:hover {
  background: rgba(255, 255, 255, 0.12);
}
.lb-toolbar-tutor {
  color: #ffd66b !important;
}
.lb-compose {
  padding: 0.5rem;
  width: min(360px, 90vw);
  white-space: normal;
}
.lb-compose-quote {
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.7);
  font-style: italic;
  margin-bottom: 0.4rem;
}
.lb-compose textarea,
.lb-popover textarea {
  width: 100%;
  border-radius: 8px;
  border: 1px solid var(--lb-border-strong);
  padding: 0.5rem 0.6rem;
  font: inherit;
  font-size: 0.92rem;
  color: var(--lb-ink);
  background: var(--lb-paper);
  resize: vertical;
}
.lb-compose-actions {
  display: flex;
  gap: 0.4rem;
  margin-top: 0.5rem;
}
.lb-popover {
  position: fixed;
  z-index: 1050;
  width: min(360px, 92vw);
  background: var(--lb-paper);
  color: var(--lb-ink);
  border: 1px solid var(--lb-border-strong);
  border-radius: 10px;
  box-shadow: var(--lb-shadow);
  padding: 0.7rem 0.8rem;
  font-size: 0.92rem;
}
.lb-popover-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 600;
  margin-bottom: 0.45rem;
}
.lb-popover-close {
  border: 0;
  background: transparent;
  font-size: 1.3rem;
  line-height: 1;
  color: var(--lb-muted);
}
.lb-popover-body {
  white-space: pre-wrap;
  margin: 0 0 0.5rem;
  line-height: 1.5;
}

/* ---- Tutor panel ------------------------------------------------------------ */
.lb-tutor {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(440px, 100vw);
  background: var(--lb-paper);
  color: var(--lb-ink);
  border-left: 1px solid var(--lb-border);
  box-shadow: -12px 0 40px -20px rgba(0, 0, 0, 0.35);
  z-index: 1060;
  display: flex;
  flex-direction: column;
  transform: translateX(105%);
  transition: transform 0.22s ease;
}
.lb-tutor.is-open {
  transform: translateX(0);
}
.lb-tutor-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1rem 1rem 0.8rem;
  border-bottom: 1px solid var(--lb-border);
  background: var(--lb-accent);
  color: var(--lb-accent-ink);
}
.lb-tutor-title {
  font-weight: 700;
  font-size: 1.05rem;
}
.lb-tutor-sub {
  font-size: 0.82rem;
  opacity: 0.85;
}
.lb-tutor-head-actions {
  display: flex;
  gap: 0.3rem;
  flex: 0 0 auto;
}
.lb-tutor-iconbtn {
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: rgba(255, 255, 255, 0.12);
  color: inherit;
  border-radius: 7px;
  padding: 0.25rem 0.6rem;
  font-size: 0.85rem;
  line-height: 1.3;
}
.lb-tutor-thread {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 1rem;
  display: grid;
  gap: 0.9rem;
  align-content: start;
}
.lb-tutor-empty {
  color: var(--lb-muted);
  font-size: 0.95rem;
  line-height: 1.55;
}
.lb-msg-role {
  font-size: 0.72rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--lb-faint);
  margin-bottom: 0.25rem;
}
.lb-msg-body {
  padding: 0.7rem 0.9rem;
  border-radius: 12px;
  background: var(--lb-panel);
  font-size: 0.97rem;
  line-height: 1.55;
  max-width: 92%;
}
.lb-msg--user .lb-msg-body {
  background: var(--lb-accent);
  color: var(--lb-accent-ink);
  margin-left: auto;
}
.lb-msg--user .lb-msg-role {
  text-align: right;
}
.lb-msg-body p {
  margin: 0;
}
.lb-msg-body p + p,
.lb-msg-body ul,
.lb-msg-body blockquote {
  margin-top: 0.55em;
}
.lb-msg-body ul {
  padding-left: 1.2em;
  margin-bottom: 0;
}
.lb-msg-body blockquote {
  border-left: 3px solid rgba(255, 255, 255, 0.5);
  padding-left: 0.6em;
  opacity: 0.85;
  margin: 0;
  font-style: italic;
}
.lb-msg--assistant .lb-msg-body blockquote {
  border-left-color: var(--lb-border-strong);
}
.lb-msg-thinking {
  color: var(--lb-muted);
  font-style: italic;
}
.lb-tutor-suggest {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  padding: 0 1rem 0.5rem;
}
.lb-tutor-suggest button {
  border: 1px solid var(--lb-border-strong);
  background: var(--lb-paper);
  color: var(--lb-ink-soft);
  border-radius: 99px;
  padding: 0.3rem 0.7rem;
  font-size: 0.8rem;
}
.lb-tutor-suggest button:hover {
  border-color: var(--lb-accent);
  color: var(--lb-link);
}
.lb-tutor-quote {
  margin: 0 1rem 0.5rem;
  padding: 0.5rem 0.7rem;
  background: var(--lb-hl);
  border-radius: 8px;
  font-size: 0.85rem;
  font-style: italic;
  display: flex;
  gap: 0.5rem;
  align-items: flex-start;
  color: #3a3000;
}
.lb-tutor-quote button {
  border: 0;
  background: transparent;
  font-size: 1.1rem;
  line-height: 1;
  margin-left: auto;
  color: inherit;
}
.lb-tutor-form {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem 1rem 1rem;
  border-top: 1px solid var(--lb-border);
}
.lb-tutor-form textarea {
  flex: 1 1 auto;
  border: 1px solid var(--lb-border-strong);
  border-radius: 10px;
  padding: 0.6rem 0.75rem;
  font: inherit;
  font-size: 0.95rem;
  background: var(--lb-paper);
  color: var(--lb-ink);
  resize: none;
}

/* ---- Quiz ---------------------------------------------------------------------- */
.lb-quiz {
  margin-top: 3rem;
  padding: 1.5rem 1.6rem 1.7rem;
  border: 1px solid var(--lb-border);
  border-radius: var(--lb-radius);
  background: var(--lb-paper);
}
.lb-quiz h2,
.lb-comments h2 {
  font-family: var(--sc-font-display, inherit);
  font-size: 1.5rem;
  margin: 0 0 0.35rem;
}
.lb-quiz-body {
  display: grid;
  gap: 1.5rem;
  margin-top: 1rem;
}
.lb-q {
  padding: 1.1rem 1.2rem;
  border-radius: 10px;
  border: 1px solid var(--lb-border);
  background: var(--lb-bg);
}
.lb-q.is-correct {
  border-color: var(--lb-good);
}
.lb-q.is-wrong {
  border-color: var(--lb-bad);
}
.lb-q-text {
  font-weight: 600;
  font-size: 1.05rem;
  line-height: 1.5;
  margin-bottom: 0.8rem;
}
.lb-q-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--lb-ink);
  color: var(--lb-paper);
  font-size: 0.8rem;
  margin-right: 0.4rem;
}
.lb-q-board {
  max-width: 300px;
  margin: 0 0 1rem;
}
.lb-q-options {
  display: grid;
  gap: 0.45rem;
}
.lb-q-option {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--lb-border);
  border-radius: 8px;
  background: var(--lb-paper);
  cursor: pointer;
  font-size: 0.98rem;
  line-height: 1.45;
}
.lb-q-option:hover {
  border-color: var(--lb-accent);
}
.lb-q-option.is-chosen {
  border-color: var(--lb-accent);
  background: var(--lb-accent-soft);
}
.lb-q-option.is-answer {
  border-color: var(--lb-good);
  background: color-mix(in srgb, var(--lb-good) 12%, var(--lb-paper));
}
.lb-q-option input {
  margin-top: 0.3rem;
}
.lb-q-explain {
  margin-top: 0.8rem;
  font-size: 0.95rem;
  line-height: 1.5;
  color: var(--lb-ink-soft);
  padding-top: 0.6rem;
  border-top: 1px dashed var(--lb-border-strong);
}
.lb-quiz-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}
.lb-quiz-score {
  font-weight: 700;
  font-size: 1.1rem;
}

/* ---- Comments -------------------------------------------------------------- */
.lb-comments {
  margin-top: 3rem;
}
.lb-comments-body {
  display: grid;
  gap: 1rem;
  margin-top: 0.8rem;
}
.lb-comment {
  padding: 0.9rem 1rem;
  border: 1px solid var(--lb-border);
  border-radius: 10px;
  background: var(--lb-paper);
  font-size: 0.97rem;
}
.lb-comment-head {
  display: flex;
  gap: 0.75rem;
  align-items: baseline;
  font-size: 0.85rem;
  color: var(--lb-muted);
  margin-bottom: 0.35rem;
}
.lb-comment-head strong {
  color: var(--lb-ink);
}
.lb-comment-delete {
  margin-left: auto;
  border: 0;
  background: transparent;
  color: var(--lb-bad);
  font-size: 0.8rem;
}
.lb-comment blockquote {
  margin: 0.2rem 0 0.5rem;
  padding-left: 0.8rem;
  border-left: 3px solid var(--lb-hl-comment);
  color: var(--lb-muted);
  font-style: italic;
  font-size: 0.9rem;
}
.lb-comment p {
  margin: 0;
  white-space: pre-wrap;
  line-height: 1.55;
}
.lb-comment-form {
  display: grid;
  gap: 0.6rem;
  justify-items: start;
}
.lb-comment-form textarea {
  width: 100%;
  border: 1px solid var(--lb-border-strong);
  border-radius: 10px;
  padding: 0.7rem 0.85rem;
  font: inherit;
  font-size: 0.97rem;
  background: var(--lb-paper);
  color: var(--lb-ink);
}

/* ---- Index page -------------------------------------------------------------- */
.lb-hero {
  padding: 1rem 0 2rem;
  border-bottom: 1px solid var(--lb-border);
  margin-bottom: 1.5rem;
  max-width: 70ch;
}
.lb-hero .lb-lede {
  font-size: 1.2rem;
}
.lb-hero-actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-top: 1.2rem;
}
.lb-section-block {
  padding: 1.5rem 0;
  border-bottom: 1px solid var(--lb-border);
}
.lb-section-block h2 {
  font-family: var(--sc-font-display, inherit);
  font-size: 1.55rem;
  margin: 0 0 0.3rem;
}
.lb-section-blurb {
  color: var(--lb-muted);
  font-size: 1.02rem;
  max-width: 70ch;
  margin-bottom: 1.1rem;
}
.lb-cards {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 0.9rem;
}
.lb-card a {
  display: grid;
  gap: 0.35rem;
  height: 100%;
  padding: 1rem 1.1rem;
  border: 1px solid var(--lb-border);
  border-radius: var(--lb-radius);
  background: var(--lb-paper);
  color: var(--lb-ink);
  text-decoration: none;
  transition: all 0.15s;
}
.lb-card a:hover {
  border-color: var(--lb-accent);
  transform: translateY(-1px);
  box-shadow: var(--lb-shadow);
}
.lb-card-title {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  font-weight: 700;
  font-size: 1.05rem;
  line-height: 1.3;
}
.lb-card-summary {
  font-size: 0.92rem;
  line-height: 1.5;
  color: var(--lb-ink-soft);
}
.lb-card-meta {
  font-size: 0.78rem;
  color: var(--lb-faint);
  margin-top: auto;
}
.lb-app-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 0.9rem;
  margin-top: 1rem;
}
.lb-app-card {
  display: grid;
  gap: 0.35rem;
  padding: 1rem 1.1rem;
  border-radius: var(--lb-radius);
  border: 1.5px solid var(--lb-accent);
  background: linear-gradient(160deg, var(--lb-accent-soft), var(--lb-paper) 70%);
  color: var(--lb-ink);
  text-decoration: none;
  font-size: 0.92rem;
  line-height: 1.5;
}
.lb-app-card strong {
  font-size: 1.02rem;
}

/* ---- Phones and small laptops ------------------------------------------------ */
.lb-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  z-index: 1044;
}
@media (max-width: 1199px) {
  .learn {
    --lb-rail-w: 240px;
  }
  .lb-main {
    gap: 2rem;
  }
}
@media (max-width: 991px) {
  .learn {
    grid-template-columns: minmax(0, 1fr);
  }
  .lb-nav {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(320px, 88vw);
    z-index: 1045;
    transform: translateX(-105%);
    transition: transform 0.2s ease;
    box-shadow: var(--lb-shadow);
  }
  .lb-nav.is-open {
    transform: translateX(0);
  }
  .lb-nav-close {
    display: block;
  }
  .lb-content {
    grid-template-columns: minmax(0, 1fr);
    padding: 1rem 1rem 3rem;
  }
  .lb-topbar {
    padding: 0.5rem 0.75rem;
    gap: 0.4rem;
  }
  .lb-topbar-btn--nav {
    display: inline-flex;
  }
  .lb-topbar-btn--nav span,
  .lb-topbar-btn--tutor span,
  .lb-topbar-link {
    display: none;
  }
  .lb-search {
    flex: 1 1 auto;
  }
  .lb-search input {
    padding-left: 1.9rem;
    font-size: 0.88rem;
  }
  .lb-rail {
    order: 3;
  }
  .lb-rail-inner {
    position: static;
  }
  .lb-outline,
  .lb-rail-tip,
  .lb-rail-progress,
  .lb-tutor-btn {
    display: none;
  }
  .lb-prose {
    font-size: 1.08rem;
  }
  .lb-prevnext {
    grid-template-columns: 1fr;
  }
  .lb-prevnext-link--next {
    text-align: left;
  }
  .lb-tutor {
    width: 100vw;
  }
}
@media (max-width: 575px) {
  .lb-article-meta {
    gap: 0.5rem 0.9rem;
  }
  .lb-markread {
    margin-left: 0;
  }
  .lb-toolbar > button {
    padding: 0.45rem 0.5rem;
    font-size: 0.8rem;
  }
}
