:root {
  --ink: #1d2733;
  --muted: #5b6876;
  --line: #d5dce4;
  --paper: #ffffff;
  --ground: #f3f6f9;
  --accent: #0b6e99;
  --accent-soft: #e3f1f7;
  --ok: #1a7f4b;
  --ok-soft: #e4f5ec;
  --bad: #b3261e;
  --bad-soft: #fbe9e7;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  font: 17px/1.55 "Segoe UI", "Noto Sans", "DejaVu Sans", Arial, sans-serif;
  color: var(--ink);
  background: var(--ground);
}

main { max-width: 820px; margin: 0 auto; padding: 16px 20px 80px; }
h1 { font-size: 2em; line-height: 1.2; margin: 0.2em 0 0.4em; }
h2 { font-size: 1.45em; margin: 0 0 0.2em; color: var(--accent); }
h3 { font-size: 1.1em; margin: 1.4em 0 0.4em; }
a { color: var(--accent); }
.meta { color: var(--muted); font-size: 0.9em; margin: 0; }
.print-only { display: none; }

nav.top {
  position: sticky; top: 0; z-index: 1;
  display: flex; flex-wrap: wrap; gap: 4px 14px;
  padding: 10px 20px; background: var(--paper); border-bottom: 1px solid var(--line);
}
nav.top a { text-decoration: none; font-weight: 600; }

section, header.chapter {
  background: var(--paper); border: 1px solid var(--line); border-radius: 10px;
  padding: 20px 24px; margin: 18px 0;
}
section { scroll-margin-top: 60px; }

.goals { background: var(--accent-soft); border-radius: 8px; padding: 10px 16px; margin: 12px 0; }
.goals ul { margin: 4px 0; }

table { border-collapse: collapse; width: 100%; }
table.terms th, table.terms td, table.data th, table.data td {
  border: 1px solid var(--line); padding: 6px 10px; text-align: left; vertical-align: top;
}
table.terms th { width: 30%; background: var(--ground); }
table.data th { background: var(--ground); }

figure { margin: 16px 0; text-align: center; }
figure svg { max-width: 100%; height: auto; }
figcaption { color: var(--muted); font-size: 0.9em; }
.note { border-left: 4px solid var(--accent); padding: 4px 14px; background: var(--accent-soft); }

ul.tree, ul.tree ul { list-style: none; padding-left: 1.4em; }
ul.tree li { border-left: 2px solid var(--line); padding: 3px 0 3px 10px; }
ul.tree { padding-left: 0; }

.nuc .az { display: inline-block; vertical-align: middle; font-size: 0.7em; line-height: 1.05; text-align: right; margin-right: 1px; }
.nuc .az span { display: block; }
table.pse { width: auto; margin: 0 auto; }
table.pse td, table.pse th { border: 1px solid var(--line); padding: 4px 9px; text-align: center; }
table.pse th { background: var(--ground); font-weight: 600; font-size: 0.85em; }
table.pse small { display: block; color: var(--muted); line-height: 1; }
table.pse .m { background: #dbe9f6; }
table.pse .pm { background: #e6def3; }
table.pse .nm { background: #fdf0cf; }
table.pse .none { border: 0; }

ol.questions { padding-left: 1.4em; }
.q { margin: 0 0 18px; padding: 8px 12px; border-radius: 8px; border: 1px solid transparent; }
.q.ok { background: var(--ok-soft); border-color: var(--ok); }
.q.bad { background: var(--bad-soft); border-color: var(--bad); }
.qt { margin: 0 0 6px; font-weight: 600; }
ol.opts { list-style: none; margin: 0; padding-left: 0.6em; }
ol.opts label { cursor: pointer; }
.ans { margin: 6px 0; }
.fb { margin: 6px 0 0; font-weight: 700; }
.q.ok .fb { color: var(--ok); }
.q.bad .fb { color: var(--bad); }
.why { margin: 4px 0 0; color: var(--muted); }
table.match td { padding: 4px 8px 4px 0; vertical-align: middle; }

input[type="text"], select, textarea {
  font: inherit; padding: 5px 8px; border: 1px solid var(--muted); border-radius: 6px;
  max-width: 100%; background: var(--paper); color: var(--ink);
}
input[type="text"] { width: 11em; }
textarea { width: 100%; }
button {
  font: inherit; font-weight: 600; padding: 6px 14px; border-radius: 6px; cursor: pointer;
  border: 1px solid var(--accent); background: var(--accent); color: #fff;
}
button.reveal, button.reset, button[data-act="again"], button[data-act="flip"] {
  background: var(--paper); color: var(--accent);
}
.score { font-size: 1.15em; font-weight: 700; padding: 12px 16px; background: var(--accent-soft); border-radius: 8px; }

.fc { display: table; width: 100%; table-layout: fixed; border: 1px dashed var(--muted); margin-top: -1px; }
.fc .f, .fc .b { display: table-cell; width: 50%; padding: 10px 14px; vertical-align: middle; }
.fc .f { font-weight: 600; border-right: 1px dashed var(--muted); }
.deck.js .fc { display: none; }
.deck.js .fc.cur {
  display: block; border: 2px solid var(--accent); border-radius: 12px; min-height: 170px;
  padding: 18px; text-align: center; cursor: pointer;
}
.deck.js .fc.cur .f, .deck.js .fc.cur .b { display: block; width: auto; border: 0; font-size: 1.15em; }
.deck.js .fc.cur .b { display: none; border-top: 1px solid var(--line); margin-top: 10px; color: var(--ok); }
.deck.js .fc.cur.flipped .b { display: block; }
.deck-controls .left { font-weight: 600; margin-right: 8px; }

ul.chapters { list-style: none; padding: 0; }
ul.chapters li { background: var(--paper); border: 1px solid var(--line); border-radius: 10px; padding: 14px 18px; margin: 10px 0; }
ul.chapters .meta { display: block; }

@media screen and (max-width: 520px) {
  section, header.chapter { padding: 14px; }
  table.match td { display: block; }
}

@page {
  size: A4;
  margin: 18mm 16mm 20mm;
  @bottom-center { content: counter(page); font: 9pt "DejaVu Sans", Arial, sans-serif; color: #555; }
}

@media print {
  body { background: #fff; font-size: 10.5pt; }
  main { max-width: none; padding: 0; }
  nav.top, .screen-only, input, select, textarea, button, .fb, .why, .deck-controls { display: none !important; }
  .print-only { display: block; }
  ol.print-only { display: block; }
  section, header.chapter { border: 0; padding: 0; margin: 0 0 12pt; }
  section { break-before: page; }
  main > section:first-of-type { break-before: auto; }
  h2, h3, .qt { break-after: avoid; }
  .q, .fc, figure, tr { break-inside: avoid; }
  .q { padding: 0; margin-bottom: 10pt; }
  .blank { display: inline-block; width: 11em; border-bottom: 1px solid #000; height: 1.2em; vertical-align: bottom; }
  .blank.short { width: 3em; }
  .lines i { display: block; height: 1.8em; border-bottom: 1px solid #888; }
  table.match { width: auto; }
  table.match td { padding: 2pt 14pt 2pt 0; }
  .fc .f, .fc .b { padding: 9pt 12pt; }
  .key ol { columns: 2; column-gap: 24pt; margin-top: 4pt; }
  .key li { break-inside: avoid; }
  a { color: inherit; text-decoration: none; }
}
