/* PathThruMath. Colours come from Lectio's themes (themes.css); this file is layout and components. */

:root {
  --topbar-height: 56px;
  --radius: 8px;
  --serif: "Iowan Old Style", Palatino, Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, sans-serif;
  /* One colour per subject: muted, distinct, readable on light and dark grounds. */
  --s-foundations: #7a6a9b; --s-algebra: #2f6b9a; --s-analysis: #b5603c; --s-geometry: #3f7a4c;
  --s-number-theory: #b08428; --s-probability: #a8475f; --s-discrete: #4f7f8c; --s-applied: #8a6f3d; --s-none: var(--muted);
}
[data-dark="true"] {
  --s-foundations: #a998c9; --s-algebra: #7fb0d8; --s-analysis: #df9a7c; --s-geometry: #86c194;
  --s-number-theory: #d9b768; --s-probability: #d88aa0; --s-discrete: #8cbcc8; --s-applied: #c9ab78;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 15px/1.55 var(--sans); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { font-family: var(--serif); font-weight: 400; margin: 0; }
h1 { font-size: 34px; line-height: 1.15; letter-spacing: -.4px; }
h2 { font-size: 22px; line-height: 1.25; }
h3 { font-size: 13px; font-family: var(--sans); font-weight: 600; letter-spacing: .3px; color: var(--muted); text-transform: uppercase; margin: 22px 0 8px; }
p { margin: 0 0 14px; }
button, input, select { font: inherit; color: inherit; }
button, .button {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 13px; border: 1px solid var(--border);
  border-radius: 6px; background: var(--surface); color: var(--fg); cursor: pointer; font-size: 13.5px; line-height: 1.3; white-space: nowrap;
}
button:hover, .button:hover { background: var(--surface-2); text-decoration: none; }
.primary, .button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.primary:hover, .button.primary:hover { background: var(--accent); filter: brightness(.93); }
button.small { padding: 3px 9px; font-size: 12px; }
.link-button { border: 0; background: none; padding: 0; color: var(--accent); }
.link-button:hover { background: none; text-decoration: underline; }
.icon-button { border: 0; background: none; font-size: 22px; line-height: 1; padding: 4px 8px; color: var(--muted); }
input[type=search], input:not([type]), select { padding: 8px 11px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); max-width: 100%; }
input[type=checkbox] { accent-color: var(--accent); }
:focus-visible { outline: 2px solid var(--style, var(--accent)); outline-offset: 2px; }
.muted { color: var(--muted); }
.kicker { font-size: 11px; letter-spacing: 1.2px; text-transform: uppercase; color: var(--muted); margin: 0 0 4px; }
.count { color: var(--muted); font-weight: 400; font-size: 12px; }
.check { display: inline-flex; align-items: center; gap: 7px; font-size: 13.5px; cursor: pointer; }
.field { display: grid; grid-template-columns: 180px 1fr auto; align-items: center; gap: 4px 14px; margin: 14px 0; font-size: 14px; }
.field .muted { grid-column: 1; grid-row: 2; font-size: 12px; }
.field input, .field select { grid-row: 1 / 3; }
.skip { position: absolute; left: -999px; }
.skip:focus { left: 12px; top: 12px; z-index: 99; background: var(--surface); padding: 8px; }
.empty { text-align: center; padding: 60px 20px; color: var(--muted); }

/* Shell */
.topbar { position: relative; z-index: 30; height: var(--topbar-height); display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 16px; padding: 0 20px; border-bottom: 1px solid var(--border); background: var(--bg); color: var(--muted); font-size: 13px; }
.menu-wrap { position: relative; }
.brand { border: 0; background: none; padding: 6px 10px 6px 6px; gap: 10px; border-radius: 8px; color: var(--fg); }
.brand:hover, .brand[aria-expanded=true] { background: var(--surface-2); }
.brand-mark { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 8px 8px 3px 8px; background: var(--accent); color: var(--accent-fg); }
.brand-mark svg { width: 22px; height: 22px; }
.brand-name { font: 19px var(--serif); }
.brand-thru { font-style: italic; color: var(--muted); padding: 0 1px; }
.brand::after { content: "▾"; font-size: 10px; color: var(--muted); margin-left: -2px; }
.menu { position: absolute; top: calc(100% + 6px); left: 0; width: 220px; display: grid; gap: 1px; padding: 6px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); box-shadow: var(--shadow); animation: drop .12s ease-out; }
.menu[hidden] { display: none; }
@keyframes drop { from { transform: translateY(-4px); opacity: .5; } to { transform: none; opacity: 1; } }
.menu a, .menu > button { display: block; width: 100%; text-align: left; padding: 8px 10px; border: 0; border-radius: 6px; background: none; color: var(--fg); font-size: 14px; }
.menu a:hover, .menu > button:hover { background: var(--surface-2); text-decoration: none; }
.menu a.active { font-weight: 600; background: var(--surface-2); }
.menu hr { border: 0; border-top: 1px solid var(--border); margin: 5px 4px; }
#account { padding: 6px 10px; font-size: 12px; color: var(--muted); }
#account:empty { display: none; }
#account button { padding: 0; border: 0; background: none; color: var(--muted); }
.dictionary-button { justify-self: end; grid-column: 3; border-radius: 20px; padding: 6px 14px; }
.dictionary-button::before { content: "⌕"; font-size: 15px; }
main { max-width: 1280px; margin: 0 auto; padding: 32px 28px 80px; }
body[data-page=read] main { max-width: none; padding-top: 0; overflow-anchor: none; }
body[data-page=tree] main, body[data-page=courses] main { max-width: 1600px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 20px; margin-bottom: 26px; }
.page-head p { color: var(--muted); margin: 8px 0 0; max-width: 640px; }
.head-actions { display: flex; gap: 8px; }
#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--fg); color: var(--bg); padding: 10px 16px; border-radius: 6px; font-size: 13px; z-index: 90; display: none; }
#toast.show { display: block; }
dialog { border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--fg); padding: 26px 28px; width: min(560px, calc(100% - 32px)); max-height: 86vh; box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(0, 0, 0, .35); }
dialog h2 { margin-bottom: 12px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.guide li { margin: 10px 0; }
kbd { border: 1px solid var(--border); border-radius: 4px; padding: 0 5px; font-size: 12px; }

/* Drawers */
.drawer { position: fixed; top: 0; bottom: 0; background: var(--surface); box-shadow: var(--shadow); z-index: 40; display: flex; flex-direction: column; animation: slide-in .16s ease-out; }
.drawer[hidden] { display: none; }
.drawer-right { right: 0; width: min(460px, 100vw); border-left: 1px solid var(--border); }
@keyframes slide-in { from { transform: translateX(var(--from, 12px)); opacity: .4; } to { transform: none; opacity: 1; } }
.drawer-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px 10px 20px; border-bottom: 1px solid var(--border); min-height: var(--topbar-height); }
.drawer-body { padding: 16px 20px 40px; overflow-y: auto; overscroll-behavior: contain; flex: 1; }
.drawer-body > input[type=search] { width: 100%; position: sticky; top: -16px; z-index: 2; box-shadow: 0 -16px 0 var(--surface), 0 8px 8px -4px var(--surface); }

/* Dictionary */
.results { list-style: none; margin: 10px 0 0; padding: 0; }
.results button { width: 100%; justify-content: space-between; border: 0; border-radius: 6px; background: none; padding: 9px 10px; font-size: 14.5px; }
.results button:hover { background: var(--surface-2); }
.results small { color: var(--muted); font-size: 11.5px; }
.results-label, .results-empty { color: var(--muted); font-size: 12px; padding: 10px 10px 4px; }
.card-title { font-size: 30px; margin-bottom: 14px; }
.card-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.card-actions .check { margin-left: 4px; }
.card-section { margin-top: 6px; }
.mini-graph { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); padding: 10px; background: var(--bg); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { padding: 4px 10px; border: 1px solid var(--border); border-radius: 14px; font-size: 12.5px; background: var(--surface); color: var(--fg); }
.chip:hover { border-color: var(--accent); text-decoration: none; background: var(--surface); }
.definition { padding: 14px 0; border-top: 1px solid var(--border); }
.definition header { margin-bottom: 8px; font-size: 13px; }
.definition .author { font-weight: 600; color: var(--fg); }
.definition .title { color: var(--muted); font-style: italic; }
.definition-body { position: relative; max-height: 170px; overflow: hidden; border-radius: 6px; padding: 6px 8px; margin: 0 -8px;
  font-family: var(--serif); font-size: 15px; line-height: 1.55; -webkit-mask-image: linear-gradient(#000 70%, transparent); mask-image: linear-gradient(#000 70%, transparent); transition: background .12s; }
.definition-body.expanded { max-height: none; -webkit-mask-image: none; mask-image: none; background: var(--surface-2); }
.definition-body .math-block { margin: 0; padding: 0; background: none; border: 0; }
.definition-body .eyebrow { display: none; }
.definition-crop { display: block; width: 100%; height: auto; }
.defined-term { color: var(--accent); }
.definition .more summary { font-size: 12.5px; color: var(--muted); cursor: pointer; margin-top: 8px; }
.definition .more .definition-body { margin-top: 8px; }

/* Reader: one card holding the toolbar, contents, pages and section navigation */
.reader { max-width: calc(var(--page-width) + 540px); margin: 24px auto 0; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; }
.reader:has(.contents-panel:not([hidden])) { max-width: calc(var(--page-width) + 880px); }
.reader-head { position: sticky; top: 0; z-index: 15; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px;
  padding: 8px 12px; background: var(--surface); border-bottom: 1px solid var(--border); border-radius: 12px 12px 0 0; }
.reader-title { display: flex; flex-direction: column; align-items: center; min-width: 0; text-align: center; }
.reader-title .book-title { font-size: 11.5px; color: var(--muted); max-width: 52ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reader-title .section-title { font: 16px var(--serif); max-width: 52ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reader-tools { display: flex; gap: 4px; justify-content: flex-end; }
.tool { display: inline-grid; place-items: center; width: 34px; height: 34px; padding: 0; border-radius: 8px; color: var(--muted); }
.tool:hover, .tool[aria-expanded=true] { background: var(--surface-2); color: var(--fg); text-decoration: none; }
.tool svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.tool-text { border: 0; background: none; color: var(--muted); padding: 7px 10px; border-radius: 8px; }
.tool-text:hover { background: var(--surface-2); color: var(--fg); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.return-pill { position: sticky; top: 60px; z-index: 14; display: flex; margin: 12px auto 0; border-radius: 20px; box-shadow: var(--shadow); }
.reader-columns { display: flex; align-items: flex-start; }
.reader-columns > .reader-body { flex: 1; min-width: 0; }
.contents-panel { position: sticky; top: 51px; flex: 0 0 300px; max-height: calc(100vh - 51px); display: flex; flex-direction: column; border-right: 1px solid var(--border); }
.contents-panel[hidden] { display: none; }
/* The dictionary, beside the page inside the reader card. */
.dictionary-panel { position: sticky; top: 51px; flex: 0 0 420px; max-height: calc(100vh - 51px); overflow-y: auto; overscroll-behavior: contain; border-left: 1px solid var(--border); }
.dictionary-idle { padding-top: 24px; }
.panel-head { position: sticky; top: 0; z-index: 3; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 12px 10px 18px; border-bottom: 1px solid var(--border); background: var(--surface); }
.panel-head h2 { font-size: 18px; margin: 0; }
.panel-body { padding: 14px 18px 32px; }
.panel-body > input[type=search] { width: 100%; }
.vocab-dictionary { border: 1px solid var(--border); border-radius: 12px; background: var(--surface); min-height: 420px; overflow: clip; }
.list-tabs-label { color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; padding: 14px 10px 4px; }
.contents-body { position: relative; overflow-y: auto; overscroll-behavior: contain; padding: 12px 10px 24px; }
.contents-body > input[type=search] { width: 100%; position: sticky; top: -12px; z-index: 2; box-shadow: 0 -12px 0 var(--surface), 0 8px 8px -4px var(--surface); }
.reader-body.pages { padding: 28px 60px 8px; }
.page { position: relative; max-width: var(--page-width); margin: 0 auto 20px; background: #fff; border: 1px solid var(--border); border-radius: 2px; }
.page img { display: block; width: 100%; height: 100%; }
.page figcaption { position: absolute; right: -40px; bottom: 2px; width: 32px; font-size: 11px; color: var(--muted); }
[data-dark="true"] .page img, [data-dark="true"] .definition-crop { filter: invert(.9) hue-rotate(180deg); }
[data-dark="true"] .page { background: #1a1a1a; }
.highlight { position: absolute; left: -10px; right: -10px; border-left: 3px solid var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); pointer-events: none; }
.highlight-block { background: color-mix(in srgb, var(--accent) 14%, transparent); box-shadow: 0 0 0 8px color-mix(in srgb, var(--accent) 14%, transparent); border-radius: 4px; }
.reader-find { flex: none; display: flex; align-items: center; gap: 8px; padding: 8px 18px; border-bottom: 1px solid var(--border); }
.reader-find[hidden] { display: none; }
.reader-find input { flex: 1; min-width: 100px; }
.reader-find output { min-width: 7ch; font-size: 12px; color: var(--muted); }
.find-box { position: absolute; background: #ffdb4d66; pointer-events: none; }
.find-mark { background: #ffdb4d66; color: inherit; }
.find-current { background: #ff9a4499; outline: 2px solid #cf6419; }
.defined-search { margin: -8px 0 18px; font-size: 14px; }
#mention-search > h2 { margin-top: 28px; }
.search-book { padding: 18px 0; border-bottom: 1px solid var(--border); }
.search-book h3 { margin: 0; }
.search-book h3 span, .search-section > span { font: 12px var(--sans); }
.search-section { display: block; padding: 10px 12px; margin: 8px 0; border-radius: 6px; color: var(--fg); background: var(--surface); }
.search-section p { margin: 5px 0; font-size: 14px; white-space: pre-line; }
.search-section mark { background: #ffdb4d66; color: inherit; }
.reader-body.typeset { max-width: 780px; margin: 0 auto; padding: 40px 56px 16px; }
.typeset-title { font-size: 32px; margin-bottom: 24px; }
.reader-foot { display: grid; grid-template-columns: 1fr auto 1fr; gap: 16px; align-items: center; padding: 14px 18px; border-top: 1px solid var(--border); }
.nav-link { display: flex; flex-direction: column; gap: 1px; min-width: 0; color: var(--fg); font: 15px var(--serif); padding: 6px 10px; border-radius: 8px; }
.nav-link:hover { background: var(--surface-2); text-decoration: none; }
.nav-link small { font: 11px var(--sans); color: var(--muted); }
.nav-link.prev { justify-self: start; }
.nav-link.next { justify-self: end; text-align: right; }
#mark-read { border-radius: 20px; }
#mark-read.done { color: var(--good); border-color: color-mix(in srgb, var(--good) 40%, var(--border)); }
.toc { display: grid; margin-top: 10px; }
.toc a { display: flex; justify-content: space-between; gap: 10px; padding: 6px 8px; border-radius: 5px; color: var(--fg); font-size: 13.5px; line-height: 1.35; }
.toc a:hover { background: var(--surface-2); text-decoration: none; }
.toc a.current { background: var(--surface-2); color: var(--accent); font-weight: 600; }
.toc a.depth-0 { font-weight: 600; margin-top: 8px; }
.toc a.depth-1 { padding-left: 20px; }
.toc a.depth-2 { padding-left: 34px; font-size: 13px; color: var(--muted); }
.toc a.depth-3 { padding-left: 48px; font-size: 12.5px; color: var(--muted); }
.toc-page { color: var(--muted); font-size: 11.5px; font-weight: 400; }
.toc-part { padding: 14px 8px 4px; font-size: 11px; letter-spacing: 1px; text-transform: uppercase; color: var(--muted); }
.term-list { list-style: none; padding: 0; margin: 0; max-height: 50vh; overflow: auto; }
.term-list li { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--border); }

/* Typeset books (source editions) */
.reading-body { font-family: var(--reader-font); font-size: var(--reader-size); line-height: 1.75; overflow-wrap: anywhere; }
.reading-body .paragraph, .reading-body p { margin: 0 0 1em; }
.reading-body h2 { font-size: 1.35em; margin: 1.6em 0 .7em; }
.reading-body h3 { font: 600 1em var(--reader-font); text-transform: none; letter-spacing: 0; color: var(--fg); margin: 1.4em 0 .6em; }
.reading-body section > h2 { padding-top: .6em; border-top: 1px solid var(--border); }
.math-block { margin: 1.2em 0; padding: 14px 18px; background: var(--surface-2); border-left: 3px solid var(--accent); border-radius: 0 6px 6px 0; }
.math-block.proof { background: none; border-left-color: var(--border); }
.math-block .eyebrow { display: block; font: 600 11px var(--sans); letter-spacing: 1px; text-transform: uppercase; color: var(--accent); margin-bottom: 6px; }
.math-block .env-title { text-transform: none; letter-spacing: 0; font-weight: 400; }
.display-math { margin: 1em 0; overflow-x: auto; overflow-y: hidden; }
mjx-container { max-width: 100%; overflow-x: auto; overflow-y: hidden; }
.reading-body figure { margin: 1.4em 0; text-align: center; }
.reading-body figcaption { font: 13px/1.5 var(--sans); color: var(--muted); margin-top: 8px; }
.source-figure { max-width: 100%; height: auto; background: #fff; border-radius: 4px; padding: 8px; }
[data-dark="true"] .source-figure { filter: invert(.9) hue-rotate(180deg); }
.reading-body table { border-collapse: collapse; margin: 1em auto; display: block; overflow-x: auto; }
.reading-body td { padding: 4px 10px; border: 1px solid var(--border); }
.reading-body pre { font-size: .8em; overflow-x: auto; background: var(--surface-2); padding: 10px; border-radius: 4px; }
details.solution { border-top: 1px solid var(--border); margin-top: 10px; padding-top: 6px; font-size: .92em; }
details.solution summary { cursor: pointer; color: var(--accent); font: 13px var(--sans); }
.exercise-check { display: flex; align-items: center; gap: 8px; margin-top: 10px; font: 12.5px var(--sans); color: var(--muted); }
.footnotes { margin-top: 2em; padding-top: .8em; border-top: 1px solid var(--border); font-size: .86em; }
.fn-ref a { text-decoration: none; }
ul.tagged { list-style: none; padding-left: .3em; }
.item-tag { font-weight: 600; margin-right: .4em; }
.item-tag + div { display: inline; }

/* Library */
.continue { display: inline-flex; flex-direction: column; gap: 2px; padding: 12px 16px; margin-bottom: 22px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--fg); }
.continue:hover { border-color: var(--accent); text-decoration: none; }
.continue strong { font: 400 17px var(--serif); }
.filters { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 22px; }
.filters input[type=search] { flex: 1; min-width: 220px; }
.book-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.book { display: flex; flex-direction: column; gap: 4px; min-height: 150px; padding: 16px 18px; border: 1px solid var(--border); border-top: 3px solid var(--subject); border-radius: var(--radius); background: var(--surface); color: var(--fg); transition: box-shadow .15s, transform .15s; }
.book:hover { text-decoration: none; transform: translateY(-2px); box-shadow: var(--shadow); }
.book-subject { font-size: 11px; letter-spacing: .8px; text-transform: uppercase; color: var(--subject); }
.book-title { font: 18px/1.25 var(--serif); }
.book-author { font-size: 13px; color: var(--muted); }
.book-level { margin-top: auto; font-size: 12px; color: var(--muted); }

/* Subject colours on books and graph nodes */
.s-foundations { --subject: var(--s-foundations); } .s-algebra { --subject: var(--s-algebra); } .s-analysis { --subject: var(--s-analysis); }
.s-geometry { --subject: var(--s-geometry); } .s-number-theory { --subject: var(--s-number-theory); } .s-probability { --subject: var(--s-probability); }
.s-discrete { --subject: var(--s-discrete); } .s-applied { --subject: var(--s-applied); } .s-none { --subject: var(--s-none); }

/* Graphs */
.graph-frame { overflow: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); padding: 18px; }
.graph-frame.canvas { position: relative; overflow: hidden; padding: 0; cursor: grab; touch-action: pan-y; user-select: none;
  background-image: radial-gradient(var(--border) .7px, transparent .7px); background-size: 20px 20px; }
.graph-frame.canvas.dragging { cursor: grabbing; }
.graph-frame.canvas svg { position: absolute; left: 0; top: 0; transform-origin: 0 0; margin: 0; }
.graph-frame svg, .tree-right { display: flex; gap: 10px; align-items: center; }
.zoom { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.zoom button { border: 0; border-radius: 0; padding: 6px 11px; }
.zoom button + button { border-left: 1px solid var(--border); }
.graph-caption { color: var(--muted); font-size: 13px; margin: 0 0 8px; }
.graph .edge { fill: none; stroke: var(--border-strong); stroke-opacity: .22; stroke-width: 1.2; }
.graph .edge.on { stroke: var(--accent); stroke-opacity: .85; stroke-width: 2; }
.graph .edge.dim { stroke-opacity: .1; }
.graph .edge.soft { stroke-dasharray: 5 4; }
.graph-frame .band-tag { position: absolute; left: 10px; z-index: 1; pointer-events: none; padding: 2px 7px; border-radius: 5px;
  background: color-mix(in srgb, var(--bg) 85%, transparent); color: var(--muted); font: 600 11px var(--sans); letter-spacing: .05em; text-transform: uppercase; }
.graph .band-rule { stroke: var(--border); stroke-dasharray: 2 6; }
.graph .node .books { fill: var(--muted); font-size: 11px; }
.graph .node .books.none { fill: var(--bad); }
.graph .node .ready-dot { fill: var(--accent); }
.graph .node.next rect:first-of-type { stroke-dasharray: 2 3; }
.graph .node { cursor: pointer; }
.graph .node rect:first-of-type { fill: var(--surface); stroke: var(--border); stroke-width: 1.2; transition: stroke .12s; }
.graph .node .bar { fill: var(--subject); }
.graph .node text { fill: var(--fg); font: 15px var(--sans); }
.graph.compact .node text { font-size: 12px; }
.graph .node .tick { fill: var(--good); font-weight: 700; }
.graph .node:hover rect:first-of-type, .graph .node:focus rect:first-of-type { stroke: var(--subject); stroke-width: 2; }
.graph .node.known rect:first-of-type { fill: color-mix(in srgb, var(--good) 10%, var(--surface)); }
.graph .node.selected rect:first-of-type { stroke: var(--accent); stroke-width: 2.4; fill: color-mix(in srgb, var(--accent) 10%, var(--surface)); }
.graph .node.ghost rect:first-of-type { fill: var(--bg); stroke-dasharray: 4 3; }
.graph .node.ghost text { fill: var(--muted); }
.graph .node.dim { opacity: .5; }
.graph .node:focus { outline: none; }
.subjects .subject-card { cursor: pointer; }
.subjects .subject-card rect:first-child { fill: var(--surface); stroke: var(--border); stroke-width: 1.2; transition: transform .15s; }
.subjects .subject-card:hover rect:first-child, .subjects .subject-card:focus rect:first-child { stroke: var(--subject); stroke-width: 2; }
.subjects .subject-card .bar { fill: var(--subject); }
.subjects .subject-name { font: 18px var(--serif); fill: var(--fg); }
.subjects .subject-meta { font: 12.5px var(--sans); fill: var(--muted); }
.subjects .progress-track { fill: var(--surface-2); }
.subjects .progress { fill: var(--good); }
.subjects .subject-edge { stroke-opacity: .2; }
.subjects-frame { background-image: radial-gradient(var(--border) .7px, transparent .7px); background-size: 18px 18px; }
/* The concept tree: one card holding the controls, the canvas and the finder bar. */
.tree-card { border: 1px solid var(--border); border-radius: 12px; background: var(--surface); overflow: clip; }
.tree-toolbar { position: sticky; top: 0; z-index: 3; background: var(--surface); display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 16px 10px; }
.tree-card .graph-caption { padding: 0 16px 12px; margin: 0; border-bottom: 1px solid var(--border); }
.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface); }
.segmented button, .segmented select { border: 0; border-radius: 0; background: none; padding: 7px 14px; font-size: 14px; }
.segmented > * + * { border-left: 1px solid var(--border) !important; }
.segmented [aria-selected=true], .segmented [aria-pressed=true], .segmented select.active { background: var(--surface-2); font-weight: 600; }
.find-button { display: inline-flex; align-items: center; gap: 8px; padding: 7px 14px; font-size: 14px; }
.find-button[aria-expanded=true] { background: var(--surface-2); border-color: var(--border-strong); }
.tree-stage { --side: 340px; display: flex; align-items: stretch; background: var(--bg); }
.tree-stage > .graph-frame { flex: 1; min-width: 0; border: 0; border-radius: 0; }
.tree-side { flex: none; width: 0; overflow: clip; background: var(--surface); border-left: 0 solid var(--border); }
.tree-stage.animate .tree-side { transition: width .18s ease-out; }
.tree-stage.side-open .tree-side { width: var(--side); border-left-width: 1px; }
.tree-side-inner { width: var(--side); position: sticky; top: 0; max-height: 100vh; overflow-y: auto; overscroll-behavior: contain; padding: 16px 18px 24px; box-sizing: border-box; }
.concept-finder { display: flex; gap: 8px; align-items: center; position: sticky; top: -16px; background: var(--surface); padding-bottom: 12px; }
.tree-search { flex: 1; min-width: 0; font-size: 15px; }
.tree-search::-webkit-search-cancel-button { display: none; }
.icon-button { flex: none; width: 34px; height: 34px; padding: 0; justify-content: center; font-size: 20px; line-height: 1; border-color: transparent; background: none; color: var(--muted); }
.icon-button:hover { color: var(--fg); background: var(--surface-2); }
.finder-results { list-style: none; margin: 0; padding: 0; }
.finder-results[hidden] { display: none; }
.finder-results button { width: 100%; justify-content: space-between; gap: 10px; border: 0; background: none; padding: 9px 10px; font-size: 14.5px; text-align: left; }
.finder-results button:hover, .finder-results button.active { background: var(--surface-2); }
.finder-results span { min-width: 0; }
.finder-results small { flex: none; max-width: 48%; overflow: hidden; text-overflow: ellipsis; color: var(--muted); font-size: 12px; white-space: nowrap; }
.finder-results .results-empty { color: var(--muted); padding: 8px 10px; }
.tree-panel[hidden] { display: none; }
.tree-panel h2 { margin-bottom: 12px; }
.tree-panel .topic-description { margin: -4px 0 14px; color: var(--fg); font-size: 14px; line-height: 1.45; }
.tree-panel .road { margin: 6px 0 12px; padding-left: 22px; font-size: 14px; line-height: 1.6; }
.tree-panel .road a { color: inherit; }
.tree-panel .road li.later { display: none; }
.tree-panel .road.all li.later { display: list-item; }
.tree-panel .road-more { margin: -6px 0 12px; padding: 4px 10px; font-size: 13px; }
.tree-panel .road-ready { font-size: 14px; color: var(--good); }
.tree-panel .chip.known::after { content: ' ✓'; color: var(--good); }
.panel-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* Courses */
.course-map { margin-bottom: 18px; }
.course-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 16px; }
.course-card, .course-summary { padding: 18px 20px; border: 1px solid var(--border); border-top: 3px solid var(--subject); border-radius: 12px; background: var(--surface); }
.course-card h2 { font-size: 22px; margin: 2px 0 14px; }
.course-card h2 a { color: var(--fg); }
.course-summary { margin-bottom: 18px; }
.course-progress { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.course-progress span { display: block; height: 100%; background: var(--good); }
.course-count { margin: 6px 0 12px; font-size: 13px; color: var(--muted); }
.course-next { display: flex; flex-direction: column; gap: 2px; margin: 0 0 14px; }
.course-next small { color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; }
.course-next span { color: var(--muted); font-size: 13.5px; }
.course-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.course-actions > .link-button { margin-left: auto; color: var(--muted); }
.course-empty { max-width: 560px; }
.step-section { margin: 4px 0 0; font-size: 13px; color: var(--muted); }
.course-steps { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.course-step { display: grid; grid-template-columns: 36px 1fr auto; gap: 14px; align-items: center; padding: 16px 18px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.course-step.done { opacity: .62; }
.step-number { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: var(--surface-2); color: var(--accent); font: 15px var(--serif); }
.course-step.done .step-number { color: var(--good); }
.step-main h3 { font: 19px var(--serif); text-transform: none; letter-spacing: 0; color: var(--fg); margin: 0 0 6px; }
.step-book { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.step-book select { max-width: 460px; font-size: 13px; padding: 5px 8px; }
.known-grid { max-height: 42vh; overflow: auto; border-block: 1px solid var(--border); padding: 12px 0; }
.known-grid fieldset { border: 0; padding: 0; margin: 0 0 14px; break-inside: avoid; }
.known-grid legend { font-weight: 600; font-size: 13px; margin-bottom: 4px; }
.known-grid .check { display: flex; font-size: 13px; padding: 2px 0; }

/* Vocabulary */
.vocab { display: grid; grid-template-columns: 220px 1fr; gap: 24px; }
.list-tabs { display: grid; align-content: start; gap: 2px; }
.list-tabs a { display: flex; justify-content: space-between; padding: 8px 10px; border-radius: 6px; color: var(--fg); font-size: 14px; }
.list-tabs a.current { background: var(--surface-2); font-weight: 600; }
.vocab-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.vocab-items { list-style: none; padding: 0; margin: 0; border-top: 1px solid var(--border); }
.vocab-items li { display: grid; grid-template-columns: 1fr auto auto auto; gap: 12px; align-items: center; padding: 10px 2px; border-bottom: 1px solid var(--border); }
.vocab-items .link-button { justify-self: start; font: 17px var(--serif); }
.tag { font-size: 11px; color: var(--good); border: 1px solid currentColor; border-radius: 10px; padding: 1px 7px; }

/* Settings */
.settings { max-width: 760px; padding: 4px 0 22px; border-bottom: 1px solid var(--border); margin-bottom: 22px; }
.settings h2 { margin-bottom: 14px; }
.themes { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; margin-top: 14px; }
.theme { flex-direction: column; align-items: flex-start; padding: 10px; font-size: 12.5px; }
.theme.selected { outline: 2px solid var(--accent); }
.swatches { display: flex; }
.swatches i { width: 18px; height: 16px; }

/* With room to spare, the page makes space for the dictionary instead of sitting under it. */
@media (min-width: 1280px) {
}

/* Vocabulary lookup and practice */
.vocab > * { min-width: 0; }
.dictionary-searchbar { display: flex; flex: 1; flex-wrap: wrap; gap: 12px; align-items: center; min-width: 0; }
.dictionary-searchbar input[type=search] { flex: 1 1 180px; min-width: 0; width: 100%; }
.search-status { font-size: 12px; margin: 0; min-height: 1.55em; }
.results button { text-align: left; gap: 12px; white-space: normal; }
.results small { text-align: right; }
.context-section { border-top: 1px solid var(--border); padding: 14px 0; margin-top: 12px; }
.context-section > summary { cursor: pointer; font-weight: 600; font-size: 13px; }
.context-section .chips, .context-section .mini-graph { margin-top: 12px; }
.definition-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 14px; margin-top: 12px; font-size: 12px; }
.list-tabs-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 14px; }
.list-tabs-heading .list-tabs-label { padding: 4px 10px; }
.list-tabs a { gap: 10px; overflow-wrap: anywhere; }
.vocab-head { gap: 16px; align-items: flex-start; }
.vocab-head h2 { overflow-wrap: anywhere; }
.vocab-head p { margin: 4px 0 0; font-size: 13px; }
.list-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.list-options { position: relative; font-size: 13px; }
.list-options summary { cursor: pointer; padding: 8px; white-space: nowrap; }
.list-options > div { position: absolute; z-index: 5; right: 0; min-width: 140px; padding: 6px; display: grid; gap: 4px; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow); }
.list-options button { width: 100%; margin: 0; justify-content: flex-start; text-align: left; padding: 8px 10px; }
.list-empty { padding: 28px; border: 1px dashed var(--border); border-radius: 10px; margin-top: 20px; }
.list-empty h3 { text-transform: none; font: 22px var(--serif); color: var(--fg); margin: 0 0 12px; }
.find-terms { margin-top: 18px; }
.list-name-field { display: grid; gap: 6px; margin-top: 18px; }
.review-progress { width: 100%; height: 6px; accent-color: var(--accent); margin-bottom: 16px; }
.dialog-actions { flex-wrap: wrap; }
[hidden] { display: none !important; }

/* Cards own their scroll position; reaching an edge never scrolls the page behind them. */
body[data-page=read] main { padding-bottom: 24px; }
.reader { height: calc(100dvh - var(--topbar-height) - 48px); display: flex; flex-direction: column; overflow: hidden; }
.reader-head, .reader-foot { flex: none; }
.reader-columns { flex: 1; min-height: 0; align-items: stretch; overflow: hidden; }
.reader-columns > .reader-body { min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
.contents-panel, .dictionary-panel { position: relative; top: auto; height: 100%; max-height: none; min-height: 0; }
.contents-body { flex: 1; min-height: 0; }
.return-pill { position: static; flex: none; margin: 8px auto; }
.vocab-dictionary, .vocab-list, .tree-card { max-height: calc(100dvh - 220px); overflow-y: auto; overscroll-behavior: contain; }
.tree-side-inner { max-height: calc(100dvh - 320px); }
dialog, .drawer-body, .contents-body, .dictionary-panel, .tree-side-inner,
.term-list, .known-grid, .graph-frame:not(.canvas), .mini-graph { overscroll-behavior: contain; }
/* Horizontal formula and code scrolling stays horizontal; vertical gestures reach the card. */
.display-math, mjx-container, .reading-body table, .reading-body pre { overscroll-behavior-x: contain; }

.course-map.canvas { max-height: calc(100dvh - 220px); overflow-y: auto; overscroll-behavior: contain; }

/* Search keeps the existing cards and reading pane, with independently expanded groups. */
#library-search { min-height: 22rem; }
#library-search > section { margin-bottom: 24px; }
.search-loading { min-height: 22rem; background: var(--surface); border-radius: 6px; padding: 18px; }
.term-preview .definition-crop { display: block; max-width: 100%; max-height: 180px; object-fit: contain; object-position: left top; margin-top: 10px; }
.index-page-preview { max-height: 180px; max-width: 100%; display: block; object-fit: contain; }
.term-preview > strong { margin-left: 8px; }
.search-snippet { display: block; color: inherit; }
.find-topics { flex: none; display: flex; gap: 20px; max-height: 180px; overflow: auto; padding: 10px 18px; border-bottom: 1px solid var(--border); }
.find-topics[hidden] { display: none; }
.find-topics section { flex: 1; min-width: 180px; }
.find-topics a { display: block; padding: 5px 0; font-size: 13px; }
.find-topics small { display: block; color: var(--muted); max-height: 3em; overflow: hidden; }

/* The dictionary is a permanent column beside the page; hovering only changes what it shows. */
.page { position: relative; }
.dictionary-underline { position: absolute; inset: 0; pointer-events: none; }
.dictionary-underline i { position: absolute; height: 0; border-bottom: 2px solid var(--accent); }
.dictionary-word-active { text-decoration: underline; text-decoration-color: var(--accent); text-underline-offset: 3px; cursor: pointer; }
#toggle-hover[aria-pressed=true] { color: var(--accent); }

/* Reference definitions (ProofWiki, Wikidata): credited, outside the library. */
.reference-note { font-size: 12.5px; margin: -4px 0 4px; }
.reference .definition-body.expanded { background: none; }
.reference .definition-body h4 { font: 600 13px var(--sans); margin: 10px 0 4px; }
.reference .definition-body ul { padding-left: 1.2em; margin: 4px 0; }
.results-label small { margin-left: 6px; font-size: 11.5px; }

/* Batch D: library search correctness */
.search-types { display: flex; gap: 8px; margin: 0 0 20px; }
.search-types button[aria-pressed="true"] { color: var(--accent); border-color: var(--accent); background: var(--surface); }
.term-more { margin: 12px 0; }
.term-more summary { cursor: pointer; color: var(--accent); }
/* Batch A: the hover card. One title, a pin control, quiet section headings, a fade below. */
.panel-tools { display: flex; align-items: center; gap: 2px; }
.panel-head [data-pin] svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linejoin: round; }
.panel-head [data-pin][aria-pressed=true] { color: var(--accent); }
.panel-head [data-pin][aria-pressed=true] svg { fill: currentColor; }
.dictionary-panel .card > h2 { margin-bottom: 2px; }
.as-written { font-size: 12.5px; margin: 0 0 6px; }
.hover-tip { font-size: 12.5px; color: var(--muted); background: var(--surface-2); border-radius: 6px; padding: 6px 10px; margin: 8px 0; }
.dictionary-panel .card-section h3 { text-transform: none; letter-spacing: 0; font-size: 13px; font-weight: 600; color: var(--fg); margin: 18px 0 6px; }
.local-link { margin: 4px 0; }
.local-link .tag { font-size: 11px; color: var(--muted); border: 1px solid var(--border); border-radius: 10px; padding: 0 6px; margin-left: 4px; }
.reference-credit { font-size: 12px; color: var(--muted); }
.reference-credit a { color: var(--accent); }
.reference-more > summary { font-size: 12.5px; color: var(--muted); cursor: pointer; margin: 6px 0 2px; }
.dictionary-panel.more-below::after { content: ''; position: sticky; bottom: 0; display: block; height: 24px; margin-top: -24px; pointer-events: none;
  background: linear-gradient(to bottom, transparent, var(--surface)); }
.dictionary-panel > .to-top { position: sticky; bottom: 12px; display: block; margin: -36px 12px 12px auto; z-index: 4; box-shadow: var(--shadow); }

/* Batch B: the dictionary column's width, its handle, and its idle lists. */
.reader { max-width: calc(var(--page-width) + 120px + var(--dictionary-width, 420px)); }
.reader:has(.contents-panel:not([hidden])) { max-width: calc(var(--page-width) + 460px + var(--dictionary-width, 420px)); }
.reader-columns > .dictionary-panel { flex: 0 0 var(--dictionary-width, 420px); width: var(--dictionary-width, 420px); }
.column-handle { flex: 0 0 6px; margin: 0 -3px; z-index: 5; cursor: col-resize; position: relative; align-self: stretch; }
.column-handle:hover, .column-handle:focus-visible { background: var(--border); outline: none; }
.dictionary-idle h3 { text-transform: none; letter-spacing: 0; font-size: 13px; font-weight: 600; color: var(--fg); margin: 18px 0 8px; }

/* Batch C: the reader's frame. The site's top bar stays as on every page (owner, 2026-10-20). */
.reader { position: relative; }
.reader-left { display: flex; align-items: center; gap: 4px; }
.fit-control { display: inline-flex; margin-left: 6px; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.fit-control button { border: 0; border-radius: 0; background: none; color: var(--muted); padding: 5px 9px; font-size: 12.5px; }
.fit-control button + button { border-left: 1px solid var(--border); }
.fit-control button[aria-pressed=true] { background: var(--surface-2); color: var(--fg); font-weight: 600; }
.reader-tools { align-items: center; gap: 0; }
.tool-group { display: inline-flex; align-items: center; gap: 2px; }
.tool-group + .tool-group { margin-left: 6px; padding-left: 6px; border-left: 1px solid var(--border); }
.tool-text { display: inline-flex; align-items: center; gap: 6px; }
.tool-text svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; }
.hover-toggle .switch { position: relative; width: 26px; height: 15px; border-radius: 8px; background: var(--border); }
.hover-toggle .switch::after { content: ''; position: absolute; top: 2px; left: 2px; width: 11px; height: 11px; border-radius: 50%; background: var(--surface); }
.hover-toggle[aria-pressed=true] { color: var(--fg); }
.hover-toggle[aria-pressed=true] .switch { background: var(--accent); }
.hover-toggle[aria-pressed=true] .switch::after { left: 13px; }
.reader-head { position: relative; }
.reader-progress { position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; }
.reader-progress i { display: block; height: 100%; width: 0; background: var(--accent); }
.page-of { font-size: 11.5px; color: var(--muted); }
/* PDF sizing follows the pane width or fits a whole page in view. */
.reader-body.pages[data-fit=width] { padding-left: 24px; padding-right: 24px; }
.reader-body.pages[data-fit=width] .page { max-width: none; }
.reader-body.pages[data-fit=page] .page { max-width: min(var(--page-width-fit, 100%), calc((var(--pane-h, 800px) - 48px) * var(--ratio, .77))); }
.reader-body.pages[data-fit=width] .page figcaption { right: 4px; }
/* A page still loading shows its number, not a blank sheet. */
.page::before { content: 'Page ' attr(data-n); position: absolute; inset: 0; display: grid; place-items: center; color: var(--faint); font-size: 13px; }
[data-dark="true"] .page::before { color: #777; }
.page img { position: relative; }
/* The footer comes up near the end of a section, over the pane, which leaves room for it. */
.reader-body.pages, .reader-body.typeset { padding-bottom: 80px; }
.reader-foot { position: absolute; left: 0; right: 0; bottom: 0; z-index: 12; background: var(--surface); border-radius: 0 0 12px 12px; visibility: hidden; }
.reader-foot.shown { visibility: visible; }

/* Batch E: grouped library shelf */
.resume-section { margin-bottom: 24px; }
.resume-section h2 { margin-bottom: 10px; }
.resume-books { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 12px; }
.resume-books .continue { display: flex; flex-direction: column; gap: 8px; margin: 0; min-width: 0; }
.shelf-subject { margin-bottom: 24px; }
.shelf-subject > summary { cursor: pointer; font: 22px var(--serif); margin-bottom: 12px; }
.library-shelf .book { justify-content: flex-start; gap: 8px; min-height: 170px; }
.library-shelf .book-author { margin: 0; }
.book-progress { display: block; height: 3px; background: var(--border); margin-top: auto; overflow: hidden; }
.book-progress i { display: block; height: 100%; background: var(--accent); }
.library-shelf .book > .muted { font-size: 12px; }

/* Batch G: stable concept selection and readable edges */
.tree-card { overflow-anchor: none; }
.tree-stage { position: relative; }
.tree-stage > .graph-frame { width: 100%; }
.tree-stage .tree-side { position: absolute; right: 0; top: 0; bottom: 0; width: var(--side); visibility: hidden; }
.tree-stage.side-open .tree-side { visibility: visible; }
.tree-stage .graph .edge { stroke-opacity: .16; }
.tree-stage .graph .edge.on { stroke-opacity: .95; stroke-width: 2; }
.tree-stage .graph .edge.dim { stroke-opacity: .045; }
.tree-stage .graph .node.dim { opacity: .4; }
.ready-badge { display: inline-block; font-size: 12px !important; padding: 4px 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface-2); }

/* Batch H: courses point at the next reading */
.course-cards { display: flex; flex-wrap: wrap; align-items: stretch; gap: 16px; }
.course-cards .course-card { flex: 0 0 360px; width: 360px; display: flex; flex-direction: column; }
.course-card h2 { font: 16px var(--sans); margin-bottom: 16px; }
.course-card .course-card-body { flex: 1; display: flex; flex-direction: column; }
.course-card .course-next b { display: block; font: 25px/1.2 var(--serif); margin: 4px 0 8px; }
.course-card .course-next span { display: block; font-size: 14px; }
.course-card .course-last { margin: auto 0 12px; padding-top: 12px; font-size: 12px; }
.course-card .course-actions { justify-content: space-between; }
.course-menu { position: relative; }
.course-menu summary { cursor: pointer; list-style: none; font-size: 22px; padding: 0 10px; border: 1px solid var(--border); border-radius: 6px; }
.course-menu summary::-webkit-details-marker { display: none; }
.course-menu > div { display: grid; gap: 2px; position: absolute; z-index: 4; right: 0; top: 100%; min-width: 130px; padding: 10px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); }
.course-menu a, .course-menu button { display: flex; align-items: center; justify-content: flex-start; width: 100%; margin: 0; padding: 8px 10px; border: 0; border-radius: 4px; background: none; text-align: left; font: 13.5px/1.3 var(--sans); color: var(--fg); }
.course-menu a:hover, .course-menu button:hover { background: var(--surface-2); text-decoration: none; }

/* Batch F: Vocabulary. Crops at text size, a page that scrolls, one style of side navigation. */
.definition-crop { width: auto; max-width: 100%; }
.vocab-dictionary { max-height: none; overflow: visible; }
.list-tabs > .list-tab { display: flex; justify-content: space-between; gap: 10px; width: 100%; padding: 8px 10px; border: 0; border-radius: 6px; background: none; color: var(--fg); font-size: 14px; text-align: left; }
.list-tabs > .list-tab:hover, .list-tabs a:hover { background: var(--surface-2); text-decoration: none; }
.subject-chips { padding: 4px 10px 10px; }
.results .subject-chips .chip { width: auto; padding: 4px 10px; border: 1px solid var(--border); border-radius: 14px; font-size: 12.5px; background: var(--surface); }
.results .subject-chips .chip:hover { background: var(--surface-2); }
.placement-description { margin: 4px 0 10px; }
.placement-needs { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 13px; }
.placement-needs .chip { cursor: default; }
.placement-needs .chip.known { border-color: color-mix(in srgb, var(--good) 40%, var(--border)); }
.placement-keys { font-size: 12px; margin: 8px 0 0; }

/* Batch I: settings, live preview and shared navigation */
:root { --content-width: 1280px; }
body[data-page=library] main, body[data-page=vocabulary] main, body[data-page=courses] main, body[data-page=settings] main { max-width: var(--content-width); }
input[type=range] { accent-color: var(--accent); width: 100%; margin: 0; }
body[data-page=settings] .settings { max-width: none; }
.settings-row { display: grid; grid-template-columns: 180px minmax(180px,1fr) 90px; align-items: center; gap: 14px; margin: 16px 0; width: 560px; max-width: 100%; font-size: 14px; }
.settings-row small { display: block; color: var(--muted); font-size: 12px; }
.settings-row input, .settings-row select { grid-column: 2; min-width: 0; }
.settings-row output { grid-column: 3; color: var(--muted); font-size: 12px; text-align: right; overflow-wrap: anywhere; }
.settings-row input[type=checkbox] { justify-self: start; }
.reading-settings { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 400px), 1fr)); gap: 24px; align-items: start; }
.reading-settings > * { min-width: 0; }
.reading-preview { padding: 18px; border: 1px solid var(--border); background: var(--surface-2); border-radius: 8px; }
.reading-preview h3 { margin: 0 0 14px; }
.preview-page { margin: 0 auto 14px; padding: 22px; min-height: 240px; border: 1px solid var(--border-strong); background: var(--surface); }
.preview-sample { font: var(--reader-size)/1.65 var(--reader-font); overflow-wrap: anywhere; }
.reading-preview > .muted { font-size: 12px; margin-bottom: 0; }
.brand { border: 1px solid var(--border); }
.brand::after { content: none; }
.brand-caret { color: var(--muted); font-size: 11px; }
.tree-back { margin-right: auto; }

/* Textbook choices remain scoped to a course topic. */
.change-textbook { align-self: flex-start; margin-top: .35rem; font-size: .8rem; }
#textbook-choice { width: 100%; max-width: 100%; }
#textbook-section { color: var(--muted); }

.textbook-field { display: grid; gap: .5rem; margin: 1rem 0; font-size: .875rem; }

/* Guided course reading: tint the frame, keeping book pages and the site bar familiar. */
body[data-page=read]:has(.course-reader) { background: color-mix(in srgb, var(--accent) 13%, var(--bg)); }
.course-reader { border-color: color-mix(in srgb, var(--accent) 42%, var(--border)); }
.course-reading-strip { display: flex; flex: none; align-items: center; gap: 16px; padding: 9px 16px;
  background: color-mix(in srgb, var(--accent) 11%, var(--surface)); border-bottom: 1px solid var(--border); font-size: 12px; }
.course-reading-strip > a:first-child { font-weight: 700; }
.course-reading-strip > span:nth-child(2) { border-left: 1px solid var(--border); padding-left: 16px; }
.course-reading-count { color: var(--muted); }
.course-exit { margin-left: auto; color: var(--muted); }
.course-reader .reader-head { border-radius: 0; }
.course-reader .reader-body { background: color-mix(in srgb, var(--accent) 5%, var(--surface)); }
.course-reader .reader-body.pages .page { background: white; }
.course-reading-foot { visibility: visible; background: color-mix(in srgb, var(--accent) 9%, var(--surface)); min-height: 90px; }
.course-reader:has(.course-reading-foot) .reader-body { padding-bottom: 120px; }
.course-next-assignment { justify-self: end; text-align: right; min-width: 0; font-size: 12px; }
.course-next-reading { display: grid; gap: 2px; text-align: left; white-space: normal; max-width: 330px; }
.course-next-reading small { font-size: 10px; }
.course-next-reading strong { font-size: 14px; }
.course-next-reading span { font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.course-plan-link { font-size: 12px; }

/* A topic contains readings, goals, practice and an explicit understanding assessment. */
.course-lessons, .course-goals { margin: 12px 0; font-size: 13px; }
.course-lessons summary, .course-goals summary { cursor: pointer; color: var(--accent); }
.lesson-list { list-style: none; padding: 0; margin: 10px 0; display: grid; gap: 8px; }
.lesson-list li { display: flex; align-items: baseline; gap: 9px; }
.lesson-list .reading-done { color: var(--good); }
.course-goals h4 { margin: 12px 0 4px; }
.course-goals ul { padding-left: 20px; }
.coverage-note { padding: 10px 12px; border-left: 3px solid var(--bad); background: var(--surface-2); font-size: 13px; }
.course-lesson-goals { font-size: 12px; padding: 0; }
.course-lesson-focus { outline: 2px solid color-mix(in srgb, var(--accent) 35%, transparent); outline-offset: 10px; }
.course-next-assignment > button { margin-left: 10px; }
#understanding-content .check { display: flex; align-items: start; gap: 10px; margin: 16px 0; }
#understanding-content input { margin-top: 5px; flex: none; }
.course-reading-strip { flex-wrap: wrap; gap: 8px 14px; }
.course-reading-foot { gap: 12px; }
.lesson-outcome { display: block; color: var(--muted); font-size: 12px; margin-top: 3px; max-width: 75ch; }

/* The continuous reader: one scroll (or one page at a time) through the whole book. */
.reader-columns > .reader-body { position: relative; }
.reader-title .section-title { max-width: 60ch; }
.turn-control { margin-right: 4px; }
.page-turn .tool svg { stroke-width: 2; }
.text-block { position: relative; }
.text-block + .text-block { margin-top: 1.2em; }
.text-block .typeset-title { margin: .2em 0 .7em; }
.text-block .typeset-title.depth-0 { font-size: 34px; padding-top: 1.4em; border-top: 1px solid var(--border); }
.text-block:first-child .typeset-title.depth-0 { padding-top: 0; border-top: 0; }
.text-block .typeset-title.depth-1 { font-size: 27px; }
.text-block .typeset-title.depth-2 { font-size: 22px; }
.text-block:not(.loaded):not(.stub) .reading-body::before { content: 'Loading…'; color: var(--faint); font: 13px var(--sans); }
.text-block.stub + .text-block .typeset-title { padding-top: 0; }
/* Pages: PDF pages one at a time (two side by side when they fit); text a screen at a time. */
.reader-body[data-turn=pages] { overflow-y: hidden !important; }
.reader-body.pages[data-turn=pages] { display: flex; justify-content: center; align-items: flex-start; gap: 16px; padding: 20px 24px; }
.reader-body.pages[data-turn=pages] .page { display: none; margin: 0; max-width: min(100%, calc((var(--pane-h, 800px) - 44px) * var(--ratio, .77))); flex: 0 1 auto; width: 100%; }
.reader-body.pages[data-turn=pages][data-spread] .page { max-width: min(calc(50% - 8px), calc((var(--pane-h, 800px) - 44px) * var(--ratio, .77))); }
.reader-body.pages[data-turn=pages] .page.shown { display: block; }
.reader-body.pages[data-turn=pages] .page figcaption { right: 4px; bottom: -18px; }
.reader[data-turn=pages] .reader-body { cursor: default; }
/* The contents as a tree with checkboxes. */
.contents-top { position: sticky; top: -12px; z-index: 2; display: grid; gap: 6px; padding-bottom: 8px; background: var(--surface); }
.contents-top input[type=search] { width: 100%; }
.contents-progress { font-size: 12px; padding-left: 2px; }
.toc-tree, .toc-tree ul { list-style: none; margin: 0; padding: 0; }
.toc-tree ul { padding-left: 14px; }
.toc-tree li[aria-expanded=false] > ul { display: none; }
.toc-tree li[hidden] { display: none; }
.toc-row { display: grid; grid-template-columns: 18px 20px 1fr auto; align-items: center; gap: 2px; border-radius: 5px; position: relative; }
.toc-row:hover { background: var(--surface-2); }
.toc-row.current { background: var(--surface-2); }
.toc-row.current a { color: var(--accent); font-weight: 600; }
.toc-row.suggest { box-shadow: inset 0 0 0 1px var(--accent); }
.toc-row.suggest::after { content: 'Mark read?'; position: absolute; right: 6px; top: -9px; font-size: 10px; padding: 0 5px; border-radius: 6px; background: var(--accent); color: var(--surface); }
.toc-row.in-plan::before { content: ''; position: absolute; left: -6px; top: 4px; bottom: 4px; width: 3px; border-radius: 2px; background: var(--good); }
.toc-row a { display: block; padding: 5px 4px; color: var(--fg); font-size: 13.5px; line-height: 1.35; }
.toc-row a:hover { text-decoration: none; }
.toc-tree li.depth-0 > .toc-row a { font-weight: 600; }
.toc-tree li.depth-2 > .toc-row a, .toc-tree li.depth-3 > .toc-row a { font-size: 13px; color: var(--muted); }
.toc-intro a { font-style: italic; color: var(--muted); }
.toc-row a.toc-part { font-size: 11px; letter-spacing: 1px; text-transform: uppercase; color: var(--muted); padding-top: 10px; }
.toc-row input[type=checkbox] { margin: 0; width: 15px; height: 15px; accent-color: var(--good); }
.toc-toggle { width: 18px; height: 22px; padding: 0; border: 0; background: none; color: var(--muted); cursor: pointer; }
.toc-toggle::before { content: '▸'; display: inline-block; transition: transform .12s; }
.toc-toggle[aria-expanded=true]::before { transform: rotate(90deg); }
.toc-spacer { display: block; }
.toc-row .toc-page { padding-right: 4px; }
/* "Finished this section?" at the foot of the card. */
.reader-foot#read-prompt { display: flex; justify-content: center; align-items: center; gap: 10px; font-size: 13.5px; }
#toast .toast-action { margin-left: 10px; padding: 2px 10px; border-radius: 4px; border: 1px solid currentColor; background: none; color: inherit; cursor: pointer; }
.plan-next { display: inline-flex; align-items: center; gap: 6px; max-width: 260px; padding: 5px 10px; border-radius: 16px; font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.read-note { margin: -4px 0 10px; font-size: 12.5px; color: var(--muted); }
.read-note:empty { display: none; }
.read-note .tag { font-size: 11px; }

/* Study plans */
.plan-steps .step-main h3 { margin-bottom: 6px; }
.sub-chips { margin: 4px 0 10px; }
.sub-chip { font-size: 12px; cursor: default; }
.sub-chip.read { border-color: color-mix(in srgb, var(--good) 45%, var(--border)); }
.sub-chip.recalled { background: color-mix(in srgb, var(--good) 14%, var(--surface)); border-color: var(--good); }
.sub-chip.unlocated { opacity: .55; border-style: dashed; }
.sub-chip.extension { font-style: italic; }
.plan-book { margin: 4px 0; font-size: 14px; }
.gap-fill { margin: 10px 0 4px; font-size: 13px; }
.plan-alternatives, .plan-others { margin: 8px 0; font-size: 13px; }
.plan-alternatives summary, .plan-others summary { cursor: pointer; color: var(--accent); }
.plan-alternatives li { margin: 6px 0; }
.gap-analysis, .plan-final { margin: 18px 0; padding: 16px 20px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); }
.gap-analysis h2, .plan-final h2 { font-size: 18px; margin: 0 0 8px; }
.chip.known { opacity: .6; }
.literature { padding-left: 20px; }
.literature li { margin: 10px 0; }
.area-list { list-style: none; padding: 0; max-height: 55vh; overflow: auto; }
.area-list li { display: grid; gap: 2px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.arxiv-form { display: flex; gap: 8px; align-items: end; }
.arxiv-form .field { flex: 1; }
.elsewhere { list-style: none; padding: 0; margin: 0 0 14px; }
.elsewhere li { display: grid; gap: 1px; padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.elsewhere small { color: var(--muted); font-size: 11.5px; }

/* Resizing. Desktop windows from about 700px wide upwards: nothing overflows, toolbars wrap or
   drop their labels, card grids reflow, and the reader's side columns narrow and then sit over the
   page instead of squeezing it. */
main { width: 100%; }
.page-head { flex-wrap: wrap; }
.page-head > div { min-width: 0; flex: 1 1 320px; }
.page-head h1 { overflow-wrap: anywhere; }
.head-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.resume-books { grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); }
.resume-books .continue strong { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; line-height: 1.3; }
.resume-books .continue span { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; font-size: 13px; }
.filters > select { flex: 1 1 150px; }
.filters > input[type=search] { flex: 3 1 240px; }
.book-grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.book-title, .book-author { overflow-wrap: anywhere; }
.course-cards .course-card { flex: 1 1 320px; width: auto; max-width: 520px; min-width: 0; }
.course-step { grid-template-columns: 36px minmax(0, 1fr) auto; }
.step-main { min-width: 0; }
.plan-book, .gap-fill, .plan-alternatives li { overflow-wrap: anywhere; }
.field { grid-template-columns: minmax(110px, 180px) minmax(0, 1fr) auto; }
.vocab-items li { grid-template-columns: minmax(0, 1fr) auto auto auto; }
.term-branch { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 28ch; }
.reader-head { grid-template-columns: auto minmax(0, 1fr) auto; }
.reader-title { min-width: 0; }
.reader-title > span { max-width: 100% !important; }
.reader-tools, .reader-left { flex-wrap: nowrap; min-width: 0; }
.find-topics { flex-wrap: wrap; }
@media (max-width: 1360px) {
  .reader-columns > .dictionary-panel { flex-basis: min(var(--dictionary-width, 420px), 30vw); width: min(var(--dictionary-width, 420px), 30vw); min-width: 280px; }
  .contents-panel { flex-basis: 260px; }
}
@media (max-width: 1240px) {
  /* Toolbar labels give way to their icons; titles keep them. */
  .reader-tools .tool-text > span:not(.count) { display: none; }
  .reader-tools .tool-text { padding: 7px 8px; }
  .fit-control button { padding: 5px 7px; }
}
@media (max-width: 1100px) {
  .reader-columns { position: relative; }
  .contents-panel { position: absolute !important; left: 0; top: 0; bottom: 0; z-index: 16; width: min(320px, 85%); background: var(--surface); box-shadow: var(--shadow); }
  .reader-columns > .dictionary-panel { position: absolute; right: 0; top: 0; bottom: 0; z-index: 16; width: min(420px, 90%); flex-basis: auto;
    background: var(--surface); box-shadow: var(--shadow); visibility: hidden; transform: translateX(16px); opacity: 0; transition: opacity .12s, transform .12s, visibility 0s .12s; }
  .reader.dictionary-open .reader-columns > .dictionary-panel { visibility: visible; transform: none; opacity: 1; transition: opacity .12s, transform .12s; }
  .column-handle { display: none; }
  .reader-body.pages { padding-left: 20px; padding-right: 20px; }
  .reader-body.typeset { padding: 28px 24px 80px; }
  .reader-title .book-title { display: none; }
}
@media (max-width: 900px) {
  main { padding: 22px 16px 60px; }
  .vocab { grid-template-columns: 1fr; }
  .list-tabs { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  .course-step { grid-template-columns: 30px minmax(0, 1fr); }
  .course-step > .button, .course-step > button { grid-column: 2; justify-self: start; }
  .field { grid-template-columns: minmax(0, 1fr); }
  .field input, .field select { grid-row: auto; }
  .field .muted { grid-row: auto; }
  .tree-stage { --side: min(340px, 80vw); }
  .reader-left #fit-control { flex-wrap: wrap; }
  .page-of { display: none; }
}

/* Pages whose card scrolls on its own (the tree, Vocabulary) fill the window to its bottom edge at
   any size: the page is exactly the window's height and the card takes whatever the heading leaves. */
body[data-page=tree] main, body[data-page=vocabulary] main { height: calc(100dvh - var(--topbar-height)); min-height: 520px; display: flex; flex-direction: column; padding-bottom: 20px; }
body[data-page=tree] main > .page-head, body[data-page=vocabulary] main > .page-head { flex: none; }
#tree { flex: 1; min-height: 0; display: flex; flex-direction: column; }
#tree > .tree-card { flex: 1; min-height: 0; max-height: none; container-type: size; }
/* The topic panel stays within the card's visible height, below its toolbar. */
#tree .tree-side-inner { max-height: calc(100cqh - 110px); }
body[data-page=vocabulary] .vocab { flex: 1; min-height: 0; }
.vocab > .list-tabs { min-height: 0; overflow-y: auto; }
.vocab-dictionary, .vocab-list { max-height: none; height: 100%; min-height: 0; }
@media (max-width: 900px) {
  body[data-page=vocabulary] .vocab { grid-template-rows: auto minmax(0, 1fr); }
  .vocab > .list-tabs { max-height: 160px; }
  .list-tabs-heading { grid-column: 1 / -1; margin-top: 4px; }
}
.tree-stage .tree-side { z-index: 3; }
/* The reader's header wraps rather than overlapping: controls, then the title, then the tools,
   each moving to a new row only when the window is too narrow for them side by side. */
.reader-head { display: flex; flex-wrap: wrap; align-items: center; column-gap: 12px; row-gap: 6px; }
.reader-head > .reader-left { flex: none; }
.reader-head > .reader-title { flex: 1 1 220px; min-width: 0; }
.reader-head > .reader-tools { flex: none; margin-left: auto; }
.reader-head > .reader-progress { flex-basis: 100%; }
.course-step { align-items: start; } .course-step > .button, .course-step > button { align-self: start; }

/* Knowledge editing and placement share a compact, readable dialog layout. */
.knowledge-filters { display: grid; gap: 10px; margin: 16px 0; }
.knowledge-filters .field { margin: 0; }
.known-grid .known-topic { gap: 10px; align-items: flex-start; padding: 9px 4px; }
.known-topic input { flex-shrink: 0; margin-top: 4px; }
.known-topic small { display: block; font-size: 13px; line-height: 1.45; margin-top: 3px; }
.placement-checks { padding: 14px 18px; border: 1px solid var(--border); border-radius: 8px; margin: 16px 0; }
.placement-checks ul { padding-left: 20px; margin: 8px 0 0; }
.placement-checks li { margin: 6px 0; }
.placement-answers { display: grid; gap: 8px; margin: 16px 0; }
.placement-answers button { display: block; text-align: left; white-space: normal; padding: 12px; }
.placement-answers small { display: block; font-weight: normal; margin-top: 3px; }
dialog .dialog-actions { flex-wrap: wrap; }

/* Align section controls, metadata and menus to the same content edges. */
body[data-page=courses] .page-head { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
body[data-page=courses] .head-actions { justify-content: flex-start; align-items: center; }
.course-card .course-progress { margin-top: auto; flex-shrink: 0; }
.course-card .course-last { margin: 0 0 12px; }
.course-menu summary { display: grid; place-items: center; width: 34px; height: 34px; padding: 0; line-height: 1; }
.course-steps .step-number { margin-top: 2px; }
.plan-alternatives > ul { list-style: none; margin: 8px 0; padding: 0; }
.plan-alternatives > ul > li { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 16px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.plan-alternatives > ul > li > .muted { grid-column: 1; }
.plan-alternatives > ul > li > button { grid-column: 2; grid-row: 1 / 3; align-self: center; }
.lesson-list li { display: grid; grid-template-columns: 18px minmax(0, 1fr); align-items: start; gap: 10px; }
.lesson-list .check { margin-top: 4px; }
.lesson-list input { margin: 0; }
.vocab .list-tabs { align-items: start; }
.vocab .list-tabs > a, .vocab .list-tabs > button { min-height: 38px; align-items: center; line-height: 1.4; }
.vocab .list-tabs-heading { padding-inline: 10px; }
.vocab .list-tabs-heading .list-tabs-label { padding: 0; }
.vocab-head { flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.vocab-head > div:first-child { min-width: 0; flex: 1 1 200px; }
.vocab-head h2 { margin: 0; }
.vocab-head .list-actions { gap: 8px; }
.vocab-items li { grid-template-columns: minmax(0, 1fr) minmax(110px, .6fr) 100px 64px; gap: 16px; padding: 12px 0; }
.vocab-items .link-button { white-space: normal; text-align: left; line-height: 1.4; }
.vocab-items .term-branch { max-width: none; white-space: normal; overflow-wrap: anywhere; font-size: 13px; }
.vocab-items .term-status { font-size: 12px; }
.vocab-items [data-remove] { justify-content: center; width: 64px; }
.vocab .panel-head { padding: 16px 18px; }
.vocab .dictionary-searchbar { gap: 16px; }
.knowledge-filters .field, #placement-subject { width: 100%; }
@media (max-width: 650px) {
  .vocab-items li { grid-template-columns: minmax(0, 1fr) 100px 64px; gap: 4px 12px; }
  .vocab-items .term-branch { grid-column: 1; grid-row: 2; }
  .vocab-items .term-status { grid-column: 2; grid-row: 1 / 3; align-self: center; }
  .vocab-items [data-remove] { grid-column: 3; grid-row: 1 / 3; }
  .plan-alternatives > ul > li { grid-template-columns: minmax(0, 1fr); }
  .plan-alternatives > ul > li > button { grid-column: 1; grid-row: auto; justify-self: start; }
  dialog .field { grid-template-columns: minmax(0, 1fr); }
  dialog .field input, dialog .field select { grid-row: auto; }
}

.topic-plan-results { list-style: none; margin: 0; padding: 0; max-height: 45vh; overflow-y: auto; }
.topic-plan-results button { display: grid; gap: 4px; width: 100%; padding: 12px; text-align: left; white-space: normal; border-width: 0 0 1px; border-radius: 0; }
.topic-plan-results small { font-size: 12px; }
.topic-plan-results span { font-size: 13px; line-height: 1.45; }
/* Keep the knowledge editor's actions visible while its topic list scrolls. */
dialog[open]:has(#known-list) { display: flex; flex-direction: column; overflow: hidden; }
dialog:has(#known-list) > :not(#known-list) { flex-shrink: 0; }
dialog #known-list { flex: 1 1 auto; min-height: 80px; }

/* Opening a book gets its own screen until the first readable content is ready. */
.book-loading { position: fixed; inset: var(--topbar-height) 0 0; z-index: 20; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; padding: 32px; background: var(--bg); text-align: center; }
.book-loading h1 { font-size: 26px; }
.book-loading p { max-width: 540px; margin: 0; color: var(--muted); overflow-wrap: anywhere; }
.book-loading .button { margin-top: 8px; }
.book-loading-spinner { width: 46px; height: 46px; border: 4px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: book-opening-spin .8s linear infinite; }
.reader-opening { visibility: hidden; }
@keyframes book-opening-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .book-loading-spinner { animation: none; } }

/* Let each palette's four colors have distinct jobs across the application. */
body[data-colorful="true"] {
  background-color: var(--bg);
  background-image: radial-gradient(ellipse at 0 0, var(--c2-tint), transparent 65%), radial-gradient(ellipse at 100% 12%, var(--c3-tint), transparent 65%), linear-gradient(135deg, var(--c1-tint), var(--bg) 55%, var(--c4-tint));
  background-attachment: fixed;
}
[data-colorful="true"] .topbar {
  background: linear-gradient(110deg, var(--c1-tint), var(--c2-tint) 65%, var(--c3-tint));
  border-bottom-color: var(--line);
}
[data-colorful="true"] .brand-mark { background: var(--theme-action); }
[data-colorful="true"] .page-head h1 { color: var(--c1-deep); }
[data-colorful="true"] :is(.settings, .vocab-head, .gap-analysis, .plan-final) h2 { color: var(--c2-deep); }
[data-colorful="true"] .settings {
  padding: 22px; margin-bottom: 18px; border: 1px solid var(--border); border-top: 3px solid var(--c2); border-radius: 12px;
  background: linear-gradient(115deg, color-mix(in srgb, var(--c2-tint) var(--theme-wash), var(--surface)), var(--surface) 70%);
}
[data-colorful="true"] .settings:nth-of-type(2n) {
  border-top-color: var(--c3);
  background: linear-gradient(115deg, color-mix(in srgb, var(--c3-tint) var(--theme-wash), var(--surface)), var(--surface) 70%);
}
[data-colorful="true"] .settings:nth-of-type(3n) { border-top-color: var(--c4); background: linear-gradient(115deg, var(--c4-tint), var(--surface) 70%); }
[data-colorful="true"] :is(.primary, .button.primary) { background: var(--theme-action); border-color: var(--theme-action); color: var(--accent-fg); }
[data-colorful="true"] :is(.head-actions, .course-actions, .dialog-actions) > :is(button, .button):not(.primary):not(.link-button),
[data-colorful="true"] .list-options > summary {
  background: var(--c2-tint); color: var(--c2-deep); border-color: color-mix(in srgb, var(--c2) 45%, var(--border));
}
[data-colorful="true"] :is(.head-actions, .course-actions, .dialog-actions) > :is(button, .button):hover { filter: brightness(.96); }
[data-colorful="true"] :is(#review, #retry-missed) { background: var(--theme-secondary-action); border-color: var(--theme-secondary-action); color: var(--accent-fg); }
[data-colorful="true"] :is(.menu a.active, .list-tabs a.current, .segmented [aria-pressed=true]) { background: var(--c2-tint); color: var(--c2-deep); }
[data-colorful="true"] .course-summary { background: linear-gradient(110deg, var(--c1-tint), var(--c4-tint)); border-top-color: var(--c1); }
[data-colorful="true"] .course-card { background: linear-gradient(145deg, var(--surface) 50%, var(--c3-tint)); border-top-color: var(--c3); }
[data-colorful="true"] .course-card:nth-child(3n + 2) { background: linear-gradient(145deg, var(--surface) 50%, var(--c2-tint)); border-top-color: var(--c2); }
[data-colorful="true"] .course-card:nth-child(3n) { background: linear-gradient(145deg, var(--surface) 50%, var(--c4-tint)); border-top-color: var(--c4); }
[data-colorful="true"] .gap-analysis { background: linear-gradient(110deg, var(--c2-tint), var(--surface)); }
[data-colorful="true"] .plan-final { background: linear-gradient(110deg, var(--c4-tint), var(--surface)); }
[data-colorful="true"] .course-progress > span { background: linear-gradient(90deg, var(--c1), var(--c4)); }
[data-colorful="true"] .step-number { background: var(--c3-tint); color: var(--c1-deep); border: 1px solid var(--c3); }
[data-colorful="true"] .panel-head { background: linear-gradient(110deg, var(--c1-tint), var(--c4-tint)); }
[data-colorful="true"] .reader-head { background: linear-gradient(110deg, var(--c1-tint), var(--surface) 55%, var(--c2-tint)); }
[data-colorful="true"] .reading-preview { background: linear-gradient(135deg, var(--c3-tint), var(--c4-tint)); }
[data-colorful="true"] .shelf-subject > summary { color: var(--c2-deep); }
[data-colorful="true"] .book-loading { background: linear-gradient(130deg, var(--c1-tint), var(--bg) 55%, var(--c2-tint)); }
[data-colorful="true"] .book-loading-spinner { border-color: var(--c3); border-top-color: var(--c1); border-right-color: var(--c2); }
.theme { min-width: 0; align-items: stretch; gap: 10px; text-align: left; }
.theme .swatches { width: 100%; overflow: hidden; border-radius: 5px; }
.theme .swatches i { flex: 1; height: 26px; }
.theme.selected { outline: 2px solid var(--accent); outline-offset: 2px; }
.theme small { color: var(--muted); font-size: 11px; line-height: 1.45; white-space: normal; }

@media (max-width: 1100px) { .reading-settings { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 650px) {
  .settings-row { grid-template-columns: minmax(100px, 160px) minmax(0, 1fr) 54px; gap: 10px; }
}

/* The palette remains multicolor when blended backgrounds are turned off. */
body[data-colorful="true"][data-gradients="false"] { background-image: none; }
[data-colorful="true"][data-gradients="false"] :is(.topbar, .settings, .course-summary, .course-card, .gap-analysis, .plan-final, .panel-head, .reader-head, .reading-preview, .book-loading, .course-progress > span) { background-image: none; }
[data-colorful="true"][data-gradients="false"] :is(.topbar, .panel-head, .reader-head, .course-summary) { background-color: var(--c1-tint); }
[data-colorful="true"][data-gradients="false"] :is(.settings, .gap-analysis) { background-color: color-mix(in srgb, var(--c2-tint) var(--theme-wash), var(--surface)); }
[data-colorful="true"][data-gradients="false"] :is(.settings:nth-of-type(2n), .reading-preview, .course-card) { background-color: color-mix(in srgb, var(--c3-tint) var(--theme-wash), var(--surface)); }
[data-colorful="true"][data-gradients="false"] .course-card:nth-child(3n + 2) { background-color: var(--c2-tint); }
[data-colorful="true"][data-gradients="false"] :is(.settings:nth-of-type(3n), .plan-final, .course-card:nth-child(3n)) { background-color: var(--c4-tint); }
[data-colorful="true"][data-gradients="false"] .course-progress > span { background-color: var(--c1); }
[data-colorful="true"][data-gradients="false"] .book-loading { background-color: var(--bg); }

/* Search results scroll inside a stable dialog, including before a query is entered. */
dialog[open]:has(#topic-plan-form) {
  display: flex; flex-direction: column; width: min(680px, calc(100% - 32px));
  height: min(720px, 86dvh); overflow: hidden;
}
dialog:has(#topic-plan-form) > :not(.topic-plan-results) { flex-shrink: 0; }
#topic-plan-form { display: grid; gap: 6px; margin: 12px 0; font-size: 14px; }
#topic-plan-search { width: 100%; min-width: 0; }
#topic-plan-status { flex: 0 0 3.1em; margin: 0 0 12px; font-size: 13px; }
dialog .topic-plan-results { flex: 1 1 auto; min-height: 0; max-height: none; border-block: 1px solid var(--border); scrollbar-gutter: stable; overscroll-behavior: contain; }

/* Finished topics remain part of the complete plan and stay readable. */
.plan-step.done { opacity: 1; border-color: color-mix(in srgb, var(--good) 45%, var(--border)); }
[data-plan-next] { display: contents; }

/* Placement records independent answers rather than one verdict for a bundle. */
.placement-skill-list { margin: 16px 0; }
.placement-skill { min-width: 0; margin: 12px 0; padding: 10px 12px 12px; border: 1px solid var(--border); border-radius: 8px; }
.placement-skill legend { padding: 0 5px; font-weight: 600; }
.placement-skill-options { display: flex; flex-wrap: wrap; gap: 8px; }
.placement-skill-options label { display: flex; align-items: center; gap: 5px; padding: 8px; cursor: pointer; border: 1px solid var(--border); border-radius: 6px; }
.placement-skill-options label:has(input:checked) { background: var(--bg); border-color: var(--accent); }
.placement-skill-options label:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.placement-bulk { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 14px 0; }
.placement-next-subject { margin-top: 12px; white-space: normal; }
.placement-plan-summary { margin: 10px 0; }
@media (max-width: 540px) { .placement-skill-options { flex-direction: column; } }

/* Zoom belongs to the book, with normal scrolling available over enlarged pages. */
.reader-columns > .reader-body { touch-action: pan-x pan-y; }
.reader-columns > .reader-body.pages[data-turn=pages] { overflow: auto !important; justify-content: flex-start; }
.reader-body.pages .page,
.reader-body.pages[data-fit=page] .page,
.reader-body.pages[data-turn=pages] .page,
.reader-body.pages[data-turn=pages][data-spread] .page { max-width: none; flex: 0 0 auto; }
.reader-body.pages[data-turn=pages] .page.shown { margin-left: auto; margin-right: auto; }
.reader-body.typeset .reading-body { font-size: calc(var(--reader-size) * var(--reader-zoom, 1)); }
.reader-body.typeset .typeset-title { font-size: calc(28px * var(--reader-zoom, 1)); }
.reader-zoom { display: inline-flex; gap: 2px; }
.reader-zoom button { padding: 5px 8px; }
#reader-zoom-reset { min-width: 52px; font-variant-numeric: tabular-nums; }
/* Keep placement navigation visible while a longer skill list scrolls. */
dialog[open]:has(#placement-prompt) { display: flex; flex-direction: column; width: min(800px, calc(100% - 32px)); height: min(900px, 90vh); box-sizing: border-box; }
dialog:has(#placement-prompt) > :not(.placement-skill-list) { flex-shrink: 0; }
dialog:has(#placement-prompt) .placement-skill-list { flex: 1; min-height: 100px; overflow-y: auto; margin: 4px 0; padding: 0 8px 0 0; }
dialog:has(#placement-prompt) .placement-skill { margin: 4px 0 10px; }
dialog:has(#placement-prompt) .dialog-actions { flex-wrap: wrap; }
dialog:has(#placement-prompt) .placement-keys { margin-bottom: 0; }
@media (min-width: 650px) {
  .placement-skill legend { float: left; width: 35%; padding: 9px 0 0; font-size: 14px; }
  .placement-skill-options { margin-left: 37%; flex-wrap: nowrap; gap: 5px; }
  .placement-skill-options label { font-size: 13px; padding: 7px 5px; }
}

.reader-body.pages { overflow-anchor: none; }
.reader-body.pages .page,
.reader-body.pages[data-turn=pages] .page {
  width: calc(var(--pdf-available, 800px) * var(--reader-zoom, 1));
}
.reader-body.pages[data-fit=page] .page,
.reader-body.pages[data-spread] .page {
  width: calc(min(var(--pdf-available, 800px), (var(--pane-h, 800px) - 48px) * var(--ratio, .77)) * var(--reader-zoom, 1));
}
#reader-zoom-value { align-self: center; min-width: 45px; text-align: center; font-variant-numeric: tabular-nums; font-size: 13px; }
#reader-zoom-reset { min-width: auto; }
.reader-columns > .reader-body { scrollbar-gutter: stable; }

/* Signed-out visitors to the hosted site see only this. */
.signin { max-width: 520px; margin: 12vh auto; padding: 36px 32px; text-align: center; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); }
.signin h1 { font-size: 34px; margin-bottom: 14px; }
.signin p { line-height: 1.6; }
.signin-links { margin: 22px 0 0; font-size: 13px; color: var(--muted); }
.signin .button { display: inline-block; margin: 14px 0 4px; padding: 10px 18px; border-radius: 8px; text-decoration: none; }
.brand:disabled { cursor: default; opacity: 1; }
.brand:disabled .brand-caret { display: none; }

/* Adaptive placement stays a short assessment; suggestions live on Study plans. */
.placement-setting { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin: 12px 0; }
.placement-setting select { flex: 1; min-width: 200px; }
.placement-profile { padding-left: 22px; }
.placement-profile li { margin: 10px 0; }
.next-learning { margin-top: 30px; }
dialog[open]:has(#placement-prompt) { height: fit-content; max-height: 90vh; }
dialog:has(#placement-prompt) .placement-skill-list { flex: 0 1 auto; min-height: 0; max-height: 45vh; }
