/* Opt-in textbook skin. Legacy chapters and notebook/day pages are unaffected. */
.textbook-chapter { --study-accent: var(--subject-color, var(--accent)); font-size: 17px; line-height: 1.75; }
[data-theme="light"] .textbook-chapter,
.textbook-chapter[data-theme="light"] { --bg: #f7f8fa; --surface: #fff; --surface2: #f0f2f5; --text: #1e2633; --text2: #46536a; --border: #d7dde6; --border2: #dfe4eb; color: var(--text); background: var(--bg); padding: 20px; border-radius: 12px; }
.textbook-chapter .study-reading > p,
.textbook-chapter .study-reading > ul,
.textbook-chapter .study-reading > ol { max-width: 74ch; }
.textbook-chapter .study-reading > h2 { margin-bottom: 1.1em; line-height: 1.25; }
.textbook-chapter .study-reading > h3 { margin: 2.7em 0 1em; padding-top: 1.3em; font-size: 1.3em; }
.textbook-chapter .study-intro { margin: 0 0 1.4em; padding: 16px 20px; border: 1px solid var(--border2); border-radius: 12px; background: color-mix(in srgb, var(--study-accent) 4%, var(--surface)); }
.textbook-chapter .study-intro > p { margin: 0; max-width: 74ch; }
.textbook-chapter .study-intro > p + p { margin-top: .65em; }
.textbook-chapter .study-reading > .study-intro + h3 { margin-top: 0; padding-top: 0; border-top: 0; }
.textbook-chapter .study-table { max-width: 100%; min-width: 0; overflow-x: auto; margin: 1.4em 0; }
.textbook-chapter .study-table table { margin: 0; }
.textbook-chapter .study-table:focus-visible { outline: 2px solid var(--study-accent); outline-offset: 3px; }
.textbook-chapter .study-panel-title { font-size: 1.12em; font-weight: 750; line-height: 1.4; margin-bottom: .65em; color: var(--text); }
.textbook-chapter .study-card-title { font-weight: 750; font-size: 1.05em; line-height: 1.4; color: var(--text); margin-bottom: .4em; }
.textbook-chapter .study-eyebrow { color: var(--study-accent); font-size: .78em; font-weight: 750; letter-spacing: .06em; text-transform: uppercase; margin-bottom: 1em; }
.textbook-chapter .study-muted { color: var(--text2); font-size: .85em; }
.textbook-chapter .study-callout,
.textbook-chapter .study-check,
.textbook-chapter .study-exercise,
.textbook-chapter .study-quiz,
.textbook-chapter .study-recall { margin: 1.8em 0; padding: 22px 24px; border: 1px solid var(--border2); border-radius: 15px; background: var(--surface); }
.textbook-chapter .study-callout { background: color-mix(in srgb, var(--study-accent) 5%, var(--surface)); }
.textbook-chapter .study-icon { display: inline-block; flex: 0 0 auto; width: 1.15em; height: 1.15em; vertical-align: -.18em; color: var(--study-accent); margin-right: .5em; }
.textbook-chapter .study-summary { background: color-mix(in srgb, var(--study-accent) 8%, var(--surface)); }
.textbook-chapter .study-callout p:last-child,
.textbook-chapter .study-cards p:last-child,
.textbook-chapter .study-process p:last-child { margin-bottom: 0; }
.textbook-chapter .study-card-group { margin: 1.8em 0; }
.textbook-chapter .study-cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.textbook-chapter .study-cards article { padding: 20px; border: 1px solid var(--border2); border-radius: 12px; background: var(--surface); min-width: 0; }
.textbook-chapter .study-process { margin: 2em 0; padding: 24px; border: 1px solid var(--border2); border-radius: 15px; }
.textbook-chapter .study-process ol { margin: 0; padding: 0; list-style: none; }
.textbook-chapter .study-process li { position: relative; margin: 0 0 0 16px; padding: 0 0 24px 32px; border-left: 1px solid var(--border2); }
.textbook-chapter .study-step-number { position: absolute; left: -16px; top: 0; width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: var(--surface2); color: var(--study-accent); font-size: .8em; font-weight: 800; }
.textbook-chapter .study-process li:last-child { padding-bottom: 0; border-color: transparent; }
.textbook-chapter .study-figure { margin: 2em 0; border: 1px solid var(--border2); border-radius: 15px; padding: 18px; overflow: hidden; background: var(--surface); }
.textbook-chapter .study-photo { padding: 0; border: 0; background: transparent; border-radius: 0; }
.textbook-chapter .study-media { margin: 2em 0; }
.textbook-chapter .study-media > .study-figure { margin: 0; min-width: 0; }
.textbook-chapter .study-media-side { display: grid; grid-template-columns: minmax(0, 1fr) minmax(240px, .85fr); align-items: center; gap: 28px; }
.textbook-chapter .study-media-copy { min-width: 0; }
.textbook-chapter .study-media-copy > :last-child { margin-bottom: 0; }
.textbook-chapter .study-media-side .study-svg svg { min-width: 0; max-height: 370px; }
.textbook-chapter .study-media-side .study-diagram { padding: 12px; }
.textbook-chapter .study-figure figcaption { color: var(--text2); font-size: .85em; line-height: 1.6; margin: 14px 0 0; }
.textbook-chapter .study-figure figcaption p { margin: 0 0 .5em; }
.textbook-chapter .study-figure small { display: block; font-size: .83em; }
.textbook-chapter .study-figure img { display: block; width: 100%; height: auto; max-height: 490px; object-fit: contain; border-radius: 9px; }
.textbook-chapter .study-image-open { display: block; width: 100%; border: 0; padding: 0; background: transparent; cursor: zoom-in; }
.textbook-chapter .study-svg { overflow-x: auto; }
.textbook-chapter .study-svg svg { display: block; width: 100%; min-width: 630px; height: auto; max-height: 560px; color: var(--text); }
.textbook-chapter .study-svg text { font-family: inherit; }
.textbook-chapter .study-svg .water { fill: #2487be; }
.textbook-chapter .study-svg .rock { fill: #aa936c; }
.textbook-chapter .study-svg .ice { fill: #b7dceb; }
.textbook-chapter details { margin-top: 1em; }
.textbook-chapter summary { cursor: pointer; color: var(--study-accent); font-weight: 650; padding: 8px 0; }
.textbook-chapter .study-solution { margin-top: 15px; border-top: 1px solid var(--border2); padding-top: 16px; }
.textbook-chapter .study-exercise-prompt .katex-display { padding: 16px; background: var(--surface2); border-radius: 8px; }
.textbook-chapter .study-exercise > .study-eyebrow { margin-bottom: .35em; }
.textbook-chapter button:not(.study-image-open):not(.term-link),
.textbook-chapter select { font: inherit; font-size: .85em; color: var(--text); border: 1px solid var(--border2); background: var(--surface2); padding: 9px 14px; border-radius: 8px; cursor: pointer; }
.textbook-chapter button:hover { border-color: var(--study-accent); }
.textbook-chapter button.term-link { display: inline; padding: 0; margin: 0; border: 0; border-radius: 2px; font: inherit; color: inherit; }
.textbook-chapter :is(button, input, select, summary, a.study-image-open):focus-visible { outline: 2px solid var(--study-accent, var(--accent)); outline-offset: 4px; }
.textbook-chapter .study-question { border: 0; margin: 0; padding: 0; min-width: 0; }
.textbook-chapter .study-question legend { width: 100%; font-weight: 650; line-height: 1.5; }
.textbook-chapter .study-question legend p { margin: 0 0 .8em; }
.textbook-chapter .study-check, .textbook-chapter .study-quiz { padding: 16px 18px; }
.textbook-chapter .study-check .study-eyebrow { margin-bottom: .6em; }
.textbook-chapter .study-choice { display: flex; align-items: flex-start; gap: 9px; padding: 6px 8px; margin: 3px 0; border: 1px solid transparent; border-radius: 7px; cursor: pointer; line-height: 1.5; }
.textbook-chapter .study-choice:hover { background: var(--surface2); }
.textbook-chapter .study-choice p { margin: 0; }
.textbook-chapter .study-choice input { flex: 0 0 auto; margin-top: 5px; width: 18px; height: 18px; accent-color: var(--study-accent); }
.textbook-chapter .study-choice.is-correct { border-color: #399b75; background: color-mix(in srgb, #399b75 8%, var(--surface)); }
.textbook-chapter .study-choice.is-incorrect { border-color: #c56868; }
.textbook-chapter .study-feedback:not(:empty) { margin-top: 9px; padding: 4px 0; font-size: .9em; }
.textbook-chapter .study-feedback-symbol { display: inline-block; margin-right: .45em; font-weight: 800; }
.textbook-chapter .study-feedback.is-correct > strong { color: #399b75; }
.textbook-chapter .study-feedback.is-incorrect > strong { color: #d47c7c; }
.textbook-chapter .study-feedback p { margin: .5em 0 0; }
.textbook-chapter .study-quiz-question + .study-quiz-question { margin-top: 16px; border-top: 1px solid var(--border2); padding-top: 16px; }
.textbook-chapter .study-quiz-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-top: 18px; }
.textbook-chapter .study-quiz-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.textbook-chapter .study-quiz-head .study-panel-title { margin-bottom: 0; }
.textbook-chapter .study-quiz-progress { flex: 0 0 auto; border-radius: 999px; background: var(--surface2); padding: 2px 9px; font-size: .78em; line-height: 1.65; font-weight: 700; font-variant-numeric: tabular-nums; }
.textbook-chapter .study-recall { scroll-margin-top: 100px; }
.textbook-chapter .study-recall > ul { margin-top: .8em; padding-left: 1.6em; }
.textbook-chapter .study-graph-board { height: 340px; width: 100%; border-radius: 8px; overflow: hidden; background: var(--surface2); }
.textbook-chapter .study-graph-board .JXGtext { color: var(--text2) !important; fill: var(--text2) !important; }
.textbook-chapter .study-graph-controls { display: flex; flex-wrap: wrap; gap: 12px 22px; margin-bottom: 14px; }
.textbook-chapter .study-graph-controls label { display: flex; align-items: center; gap: 9px; font-size: .85em; }
.textbook-chapter .study-graph-controls input { width: 100px; accent-color: var(--study-accent); }
.textbook-chapter .study-graph-controls .study-slider { display: grid; grid-template-columns: 7.5ch 100px; gap: 9px; }
.textbook-chapter .study-slider output { width: 7.5ch; white-space: nowrap; font-variant-numeric: tabular-nums; }
.textbook-chapter .study-slider input { min-width: 0; margin: 0; }
.textbook-chapter .study-graph-message { color: var(--text2); font-size: .8em; }
.textbook-chapter .study-molecule svg { width: 100%; max-height: 300px; }
.textbook-chapter .chapter-chart { border-radius: 15px; background: var(--surface); }
.textbook-chapter .mermaid { padding: 22px; border-radius: 15px; background: var(--surface); }
.textbook-chapter .study-heading-alias { display: block; height: 0; scroll-margin-top: 100px; }
.textbook-chapter [hidden] { display: none !important; }
.note-viewer-overlay.chapter-image-viewer .note-viewer-thumb img { aspect-ratio: 3 / 2; object-fit: contain; }
@media (max-width: 640px) {
  .textbook-chapter { font-size: 16px; line-height: 1.7; }
  .textbook-chapter .study-intro { padding: 14px 16px; }
  .textbook-chapter .study-cards { grid-template-columns: 1fr; }
  .textbook-chapter :is(.study-callout, .study-check, .study-exercise, .study-quiz, .study-recall, .study-process) { padding: 17px; }
  .textbook-chapter :is(.study-check, .study-quiz) { padding: 13px 14px; }
  .textbook-chapter .study-figure { padding: 12px; }
  .textbook-chapter .study-photo { padding: 0; }
  .textbook-chapter .study-media-side { grid-template-columns: 1fr; gap: 16px; }
  .textbook-chapter .study-media-side .study-photo { width: min(100%, 360px); justify-self: center; }
  .textbook-chapter .study-graph-board { height: 290px; }
  .textbook-chapter .study-choice { padding: 6px 4px; }
}
@media (prefers-reduced-motion: reduce) { .textbook-chapter * { scroll-behavior: auto !important; animation: none !important; transition: none !important; } }
@media print {
  .textbook-chapter .study-reading[hidden] { display: block !important; }
  .textbook-chapter :is(button, .study-quiz, .study-check) { display: none !important; }
  /* Preserve the reading layout; move compact groups intact to the next page. */
  .textbook-chapter .study-cards {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    break-inside: avoid;
    page-break-inside: avoid;
  }
  .textbook-chapter .study-cards article {
    margin-bottom: 0;
    break-inside: avoid;
    page-break-inside: avoid;
    box-decoration-break: clone;
    -webkit-box-decoration-break: clone;
  }
  .textbook-chapter :is(.study-intro, .study-callout, .study-process li, .study-recall, .study-figure) {
    break-inside: avoid;
    page-break-inside: avoid;
  }
  .textbook-chapter :is(.study-card-title, .study-panel-title, .study-eyebrow) { break-after: avoid; }
  .textbook-chapter :is(.study-figure, .study-svg, .study-table) { overflow: visible; }
  .textbook-chapter .study-svg svg { min-width: 0; max-width: 100%; }
  .textbook-chapter .study-media-side {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, .85fr);
    gap: 28px;
    break-inside: avoid;
    page-break-inside: avoid;
  }
  .textbook-chapter .study-media-side > .study-figure { margin: 0; }
  .textbook-chapter .study-media-side .study-photo { width: auto; justify-self: stretch; }
  .textbook-chapter :is(p, li) { orphans: 3; widows: 3; }
}
