/* Mobile first. System fonts only: no web fonts, no third-party requests. */
:root {
  --text: #1d1d1f;
  --muted: #5f6368;
  --accent: #1a5fb4;
  --line: #e3e3e8;
  --soft: #f4f6fa;
  --measure: 52rem;
  --sidebar: 17rem;
}

* { box-sizing: border-box; }

/* Elements that set their own display would otherwise ignore the hidden attribute. */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 1.125rem;
  line-height: 1.65;
  color: var(--text);
  background: #fff;
}

main, .site-footer { max-width: var(--measure); margin: 0 auto; padding: 0 1rem; }

.site-header {
  position: relative; display: flex; align-items: center; gap: 1rem;
  padding: .6rem 1rem; border-bottom: 1px solid var(--line); background: #fff;
}
.site-name { font-weight: 700; text-decoration: none; color: var(--text); margin-right: auto; }
.site-nav { display: flex; align-items: center; gap: 1rem; font-size: 1rem; }
.site-nav ul { list-style: none; margin: 0; padding: 0; }
.nav-menu summary { display: block; white-space: nowrap; list-style: none; cursor: pointer; color: var(--accent); padding: .35rem .8rem; border: 1px solid var(--accent); border-radius: .5rem; user-select: none; }
.nav-menu summary::-webkit-details-marker { display: none; }
.nav-menu summary::after { content: " ▾"; }
.nav-menu[open] summary::after { content: " ▴"; }
.nav-panel {
  position: absolute; z-index: 10; top: 100%; left: 0; right: 0;
  padding: .75rem 1rem 1rem; background: #fff; border-bottom: 1px solid var(--line);
  box-shadow: 0 .5rem 1rem rgb(0 0 0 / .08);
}
.nav-title { margin: 0 0 .25rem; color: var(--muted); font-size: .9rem; }
.nav-subjects { display: grid; grid-template-columns: repeat(auto-fill, minmax(9rem, 1fr)); }
.nav-panel a { display: block; padding: .5rem 0; }
.nav-panel .nav-more { display: block; margin-top: .5rem; padding-top: .5rem; border-top: 1px solid var(--line); }
.nav-more { display: flex; gap: 1rem; }
.search-link { display: flex; order: 1; color: var(--accent); padding: .3rem; }
.site-nav { order: 2; }
.site-search, .page-search { display: flex; gap: .5rem; }
.site-search { flex: 0 1 20rem; }
.page-search { margin: 1rem 0; }
.site-search input, .page-search input { flex: 1; min-width: 0; font: inherit; font-size: 1rem; padding: .3rem .6rem; border: 1px solid var(--line); border-radius: .5rem; }
.site-search button, .page-search button { font: inherit; font-size: 1rem; padding: .3rem .9rem; border: 1px solid var(--accent); border-radius: .5rem; background: #fff; color: var(--accent); cursor: pointer; }
.site-header .wide-only { display: none; }
@media (min-width: 48rem) {
  .narrow-only, .nav-panel .nav-more.narrow-only, .site-header .search-link, .page-search { display: none; }
  .site-header .wide-only { display: inline; }
  .site-header .nav-more.wide-only, .site-header .site-search.wide-only { display: flex; }
  .site-name { margin-right: 0; }
  .site-nav { order: 0; }
  .site-search { order: 1; margin-left: auto; }
  .nav-menu { position: relative; }
  .nav-panel { left: 0; right: auto; top: calc(100% + .5rem); width: max-content; border: 1px solid var(--line); border-radius: .5rem; }
  .nav-subjects { grid-template-columns: repeat(3, 10rem); column-gap: 1rem; }
}
.search-count { color: var(--muted); }

a { color: var(--accent); text-underline-offset: .15em; }

h1, h2, h3 { line-height: 1.25; }
h1 { font-size: 1.85rem; margin: 1rem 0 .5rem; }
h2 { font-size: 1.4rem; margin-top: 2rem; }
h3 { font-size: 1.15rem; }

.body p, .body li { hyphens: auto; overflow-wrap: break-word; }
.body table { display: block; overflow-x: auto; border-collapse: collapse; }
/* Formulas: MathML from the server. A long block formula scrolls on a phone. */
.math.block { overflow-x: auto; overflow-y: hidden; margin: 1rem 0; }
/* In an answer tile the formula is the answer: full-size fractions, as in a block. */
.quiz-choices math { math-style: normal; }
.body th, .body td { border: 1px solid var(--line); padding: .35rem .6rem; text-align: left; }

.breadcrumbs ol { display: flex; flex-wrap: wrap; list-style: none; padding: 0; margin: 1rem 0 0; font-size: .9rem; color: var(--muted); }
.breadcrumbs li + li::before { content: "›"; margin: 0 .4rem; }

.tags { display: flex; flex-wrap: wrap; gap: .4rem; list-style: none; padding: 0; margin: 0 0 .75rem; font-size: .9rem; }
.tags a { display: inline-block; padding: .1rem .7rem; border-radius: 1rem; background: var(--soft); text-decoration: none; }
.tags a:hover { text-decoration: underline; }
.other-level { margin: 0 0 .75rem; font-size: .95rem; }

.facts { display: grid; grid-template-columns: max-content 1fr; gap: .25rem 1rem; padding: .75rem 1rem; background: var(--soft); border-radius: .5rem; }
.facts dt { font-weight: 600; }
.facts dd { margin: 0; }

.summary, .toc { margin: 1.25rem 0; padding: .75rem 1rem; border-left: 4px solid var(--accent); background: var(--soft); }
.summary h2, .toc h2 { margin: 0 0 .25rem; font-size: 1.1rem; }
.summary ul, .toc ol { margin: 0; padding-left: 1.25rem; }

.quick-answers h3 { margin: 1.25rem 0 .25rem; font-size: 1.05rem; }
.quick-answers p { margin: 0; }

.quiz { margin: 2.5rem 0 1.5rem; }
.quiz-card { padding: 1rem; border: 1px solid var(--line); border-radius: .75rem; background: var(--soft); }
.quiz ol { list-style: none; margin: 0; padding: 0; }
.quiz li { margin-bottom: 1.5rem; }
/* min-width: 0, because a fieldset is never narrower than its content by default. */
.quiz fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
.quiz legend { font-weight: 600; margin-bottom: .6rem; padding: 0; }
.quiz-number { color: var(--accent); margin-right: .25rem; }
/* Answer tiles: 2×2 when every choice is short (set by the server), else one per row. */
.quiz-choices { display: grid; gap: .5rem; }
.quiz-choices.is-grid { grid-template-columns: 1fr 1fr; }
.quiz label { position: relative; display: flex; align-items: center; min-height: 3.25rem; padding: .6rem .8rem; border: 1px solid var(--line); border-radius: .6rem; background: #fff; font-size: 1rem; line-height: 1.35; overflow-wrap: anywhere; hyphens: auto; cursor: pointer; }
/* The radio stays for the keyboard and screen readers; the tile shows its state. */
.quiz label input { position: absolute; opacity: 0; }
.quiz label:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.quiz label:has(input:enabled):hover, .quiz label:has(input:checked:enabled) { border-color: var(--accent); }
.quiz label:has(input:disabled) { cursor: default; }
.quiz .is-correct { border-color: #2e7d32; background: #e8f5e9; }
.quiz .is-wrong { border-color: #c62828; background: #fdecea; }
.quiz details { margin-top: .5rem; font-size: 1rem; }
.quiz summary { color: var(--accent); cursor: pointer; }
.quiz button, .problem button, a.button { font: inherit; padding: .5rem 1.25rem; border: 1px solid var(--accent); border-radius: .5rem; background: #fff; color: var(--accent); cursor: pointer; text-decoration: none; }
.quiz-teaser-levels { padding-left: 1.25rem; }
.quiz-picker { display: grid; gap: .6rem; }
.quiz .quiz-picker button { display: flex; flex-direction: column; align-items: flex-start; padding: .75rem 1rem; text-align: left; color: var(--text); font-size: 1rem; }
.quiz-saved { color: var(--muted); font-size: .9rem; }
.quiz-progress { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: .75rem; color: var(--muted); font-weight: 600; }
.quiz-progress progress { flex: 0 1 10rem; height: .5rem; appearance: none; border: 0; border-radius: 1rem; background: var(--line); overflow: hidden; }
.quiz-progress progress::-webkit-progress-bar { background: var(--line); }
.quiz-progress progress::-webkit-progress-value { background: var(--accent); }
.quiz-progress progress::-moz-progress-bar { background: var(--accent); }
.quiz-score { margin-top: 0; font-size: 1.25rem; font-weight: 700; }
.quiz-actions { display: flex; flex-wrap: wrap; gap: .5rem; margin: 0; }
.quiz-next { justify-content: flex-end; }
/* With JS: one question at a time, the level heading is in the progress line. */
.quiz.is-stepper .quiz-level h3, .quiz.is-stepper li[data-correct]:not(.is-current) { display: none; }
.quiz.is-stepper li { margin-bottom: 1rem; }
@media (min-width: 40rem) {
  .quiz-card { padding: 1.25rem 1.5rem; }
  .quiz-picker { grid-template-columns: 1fr 1fr; }
}

.updated, .report { color: var(--muted); font-size: .95rem; }
.site-footer nav { display: flex; flex-wrap: wrap; gap: .25rem 1rem; }
.sources ul { padding-left: 1.25rem; font-size: .95rem; overflow-wrap: anywhere; }

/* List pages fill the page width with columns; lists inside an article stay one column. */
.entries ul { list-style: none; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(min(22rem, 100%), 1fr)); column-gap: 2rem; }
.layout-main .entries ul { display: block; }
.entries li { padding: .6rem 0; border-bottom: 1px solid var(--line); }
.entries li p { margin: .2rem 0 0; color: var(--muted); font-size: 1rem; }
.entries h2 a { color: inherit; text-decoration: none; }
.entries h2 a:hover { color: var(--accent); }
.entry-links { display: inline-flex; flex-wrap: wrap; gap: .4rem; margin-left: .5rem; vertical-align: middle; }
.entry-links a { padding: 0 .55rem; border-radius: 1rem; background: var(--soft); font-size: .85rem; text-decoration: none; }

.sidebar { display: none; }
.sidebar-box h2, .sidebar .toc h2 { margin: 0 0 .4rem; font-size: 1rem; }
.sidebar-box { margin-bottom: 1.25rem; font-size: 1rem; }
.sidebar-box p { margin: 0; }
.sidebar .toc { margin: 0; font-size: .95rem; }

/* Wide screens: every page has the same width. On article pages the text column keeps its
   width and the sidebar comes next to it. */
@media (min-width: 72rem) {
  main, .site-footer { max-width: calc(var(--measure) + var(--sidebar) + 2rem); }
  .layout { display: grid; grid-template-columns: minmax(0, 1fr) var(--sidebar); gap: 2rem; }
  .sidebar { display: block; position: sticky; top: 1rem; align-self: start; max-height: calc(100vh - 2rem); overflow-y: auto; margin-top: 2.5rem; }
  .toc-inline { display: none; }
}

.site-footer { margin-top: 3rem; padding-top: 1rem; padding-bottom: 2rem; border-top: 1px solid var(--line); color: var(--muted); font-size: .95rem; }

@media print {
  .site-header, .site-footer, .breadcrumbs, .toc, .report, .entries, .quiz, .sidebar { display: none; }
  body { font-size: 11pt; }
  a { color: inherit; text-decoration: none; }
}

/* Generated problems (problem.js) */
.problem-statement { margin-top: 0; font-size: 1.1rem; }
.problem-statement:focus, .problem-result:focus { outline: none; }
.problem-inputs { display: flex; flex-wrap: wrap; gap: .75rem; }
.problem-inputs label { display: grid; gap: .25rem; }
.problem-inputs input { width: 9rem; padding: .5rem; font: inherit; border: 1px solid var(--line); border-radius: .5rem; }
.problem-hint { margin: .5rem 0 0; color: var(--muted); font-size: .9rem; }
.problem-result { padding: .5rem .75rem; border-radius: .5rem; background: #fff; }
.problem-result.is-correct { border-left: 4px solid #2e7d32; }
.problem-result.is-wrong { border-left: 4px solid #c62828; }
