/* DDIA ch.8 — Transactions explainer. Plain, readable, information-first. */
:root {
  --bg: #fafaf9; --fg: #1c1f24; --muted: #5b6370; --faint: #8a909b;
  --line: #e1e3e7; --panel: #f1f2f4; --card: #ffffff;
  --accent: #1d4ed8; --accent-bg: #e6edfc;
  --ok: #15803d; --ok-bg: #e5f4ea; --bad: #c81e1e; --bad-bg: #fcebeb;
  --wait: #9a5b06; --wait-bg: #fcf1dc; --held: rgba(202, 138, 4, .16);
  --t1: #1d4ed8; --t2: #0f766e; --t3: #7c3aed; --db: #4b5563; --co: #9d174d;
  --code-bg: #eceef1;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --r: 7px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #111317; --fg: #e3e5e9; --muted: #a2a9b4; --faint: #737a86;
  --line: #2a2e35; --panel: #191c21; --card: #1f2329;
  --accent: #82a8ff; --accent-bg: #1c2944;
  --ok: #4ade80; --ok-bg: #12291b; --bad: #f87171; --bad-bg: #351818;
  --wait: #fbbf24; --wait-bg: #33290f; --held: rgba(251, 191, 36, .13);
  --t1: #82a8ff; --t2: #2dd4bf; --t3: #c4a5ff; --db: #9ca3af; --co: #f472b6;
  --code-bg: #252a31;
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111317; --fg: #e3e5e9; --muted: #a2a9b4; --faint: #737a86;
    --line: #2a2e35; --panel: #191c21; --card: #1f2329;
    --accent: #82a8ff; --accent-bg: #1c2944;
    --ok: #4ade80; --ok-bg: #12291b; --bad: #f87171; --bad-bg: #351818;
    --wait: #fbbf24; --wait-bg: #33290f; --held: rgba(251, 191, 36, .13);
    --t1: #82a8ff; --t2: #2dd4bf; --t3: #c4a5ff; --db: #9ca3af; --co: #f472b6;
    --code-bg: #252a31;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { scroll-padding-top: 16px; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font: 16px/1.6 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre, .mono { font-family: var(--mono); font-size: .86em; }
code { background: var(--code-bg); padding: .08em .35em; border-radius: 4px; }
pre { background: var(--code-bg); padding: 12px 14px; border-radius: var(--r); overflow-x: auto; line-height: 1.5; margin: 12px 0; }
pre code { background: none; padding: 0; font-size: .84rem; }
.kw { color: var(--accent); font-weight: 600; }
.cm { color: var(--faint); }
button { font: inherit; }

/* ---------- layout ---------- */
.layout { display: grid; grid-template-columns: 260px minmax(0, 1fr); max-width: 1240px; margin: 0 auto; }
.toc {
  position: sticky; top: 0; align-self: start; height: 100vh; overflow-y: auto;
  padding: 20px 14px 40px 20px; border-right: 1px solid var(--line); font-size: .86rem;
}
.toc .brand { font-weight: 700; font-size: .95rem; margin-bottom: 2px; }
.toc .brand-sub { color: var(--muted); font-size: .8rem; margin-bottom: 14px; }
.toc ol { list-style: none; margin: 0; padding: 0; }
.toc li { margin: 0; }
.toc a { display: block; color: var(--muted); padding: 3px 8px; border-radius: 5px; line-height: 1.35; }
.toc a:hover { background: var(--panel); color: var(--fg); text-decoration: none; }
.toc a.active { background: var(--accent-bg); color: var(--accent); font-weight: 600; }
.toc > ol > li > a { color: var(--fg); font-weight: 600; margin-top: 8px; }
.toc ol ol a { padding-left: 18px; font-size: .82rem; }
.toc .tools { display: flex; gap: 6px; margin-top: 18px; }

main { padding: 28px 40px 120px; min-width: 0; }
.content { max-width: 880px; }

.mobilebar { display: none; }
@media (max-width: 960px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .toc {
    position: fixed; z-index: 50; left: 0; top: 0; width: min(320px, 86vw); background: var(--bg);
    transform: translateX(-102%); transition: transform .18s ease, visibility .18s; visibility: hidden;
  }
  .toc.open { transform: none; visibility: visible; box-shadow: 0 0 30px rgba(0,0,0,.18); }
  html { scroll-padding-top: 64px; }

  main { padding: 64px 16px 100px; }
  .mobilebar {
    display: flex; align-items: center; gap: 10px; position: fixed; z-index: 40; top: 0; left: 0; right: 0;
    background: var(--bg); border-bottom: 1px solid var(--line); padding: 8px 12px; font-size: .9rem;
  }
  .mobilebar .where { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .scrim { position: fixed; inset: 0; z-index: 45; background: rgba(0,0,0,.3); display: none; }
  .scrim.open { display: block; }
}

/* ---------- typography ---------- */
h1 { font-size: 2rem; line-height: 1.2; margin: 0 0 6px; letter-spacing: -.01em; }
.lede { color: var(--muted); font-size: 1.05rem; margin: 0 0 18px; max-width: 760px; }
h2 { font-size: 1.55rem; line-height: 1.25; margin: 64px 0 10px; padding-top: 18px; border-top: 2px solid var(--line); }
h2 .num { color: var(--faint); font-weight: 500; margin-right: 6px; }
h3 { font-size: 1.18rem; margin: 36px 0 6px; }
h4 { font-size: 1rem; margin: 22px 0 4px; }
p { margin: 10px 0; }
ul, ol { padding-left: 1.3em; margin: 8px 0; }
li { margin: 3px 0; }
.muted { color: var(--muted); }
.small { font-size: .86rem; }
.tag { display: inline-block; font-size: .74rem; padding: 0 6px; border-radius: 4px; background: var(--panel); color: var(--muted); vertical-align: 1px; }
.fig { color: var(--faint); font-size: .8rem; font-weight: 500; }

/* callouts */
.key, .warn, .note {
  border-left: 3px solid var(--accent); background: var(--accent-bg); padding: 10px 14px; border-radius: 0 var(--r) var(--r) 0; margin: 14px 0;
}
.warn { border-color: var(--bad); background: var(--bad-bg); }
.note { border-color: var(--faint); background: var(--panel); }
.key > :first-child, .warn > :first-child, .note > :first-child { margin-top: 0; }
.key > :last-child, .warn > :last-child, .note > :last-child { margin-bottom: 0; }
.key b.lab, .warn b.lab, .note b.lab { display: block; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; margin-bottom: 2px; }

/* tables */
.tbl { width: 100%; border-collapse: collapse; margin: 12px 0; font-size: .9rem; }
.tbl th, .tbl td { border-bottom: 1px solid var(--line); padding: 7px 9px; text-align: left; vertical-align: top; }
.tbl th { font-weight: 600; background: var(--panel); }
.tblwrap { overflow-x: auto; }
.yes { color: var(--ok); font-weight: 600; }
.no { color: var(--bad); font-weight: 600; }
.dep { color: var(--wait); font-weight: 600; }

/* 2-col / grid helpers */
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; margin: 12px 0; }
.cell { background: var(--panel); border-radius: var(--r); padding: 12px 14px; }
.cell h4 { margin: 0 0 4px; }
.sim .cell { background: var(--card); }
.cell p, .cell ul { margin: 4px 0; font-size: .92rem; }

/* ---------- chapter map ---------- */
.map { margin: 18px 0 8px; display: grid; gap: 8px; }
.track { display: grid; grid-template-columns: 110px minmax(0, 1fr); gap: 10px; align-items: start; }
.track .tname { font-weight: 700; font-size: .85rem; padding-top: 5px; }
.track .chain { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 2px; }
.chip {
  display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: .84rem; background: var(--panel);
  color: var(--fg); border: 1px solid var(--line); white-space: nowrap;
}
a.chip:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }
.chain .arr { color: var(--faint); padding: 0 3px; font-size: .9rem; }
@media (max-width: 600px) { .track { grid-template-columns: 1fr; gap: 2px; } }

/* ---------- buttons ---------- */
.btn {
  border: 1px solid var(--line); background: var(--card); color: var(--fg); border-radius: 6px;
  padding: 5px 11px; font-size: .86rem; cursor: pointer; line-height: 1.35;
}
.btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.btn:disabled { opacity: .4; cursor: default; }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.primary:hover:not(:disabled) { color: #fff; filter: brightness(1.08); }
:root[data-theme="dark"] .btn.primary { color: #0d1320; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn.primary { color: #0d1320; } }
.btn.sm { padding: 2px 8px; font-size: .8rem; }
.btn.danger { color: var(--bad); }
.btn.danger:hover:not(:disabled) { border-color: var(--bad); color: var(--bad); }
.seg { display: inline-flex; flex-wrap: wrap; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; background: var(--card); }
.seg button { border: 0; border-right: 1px solid var(--line); background: none; color: var(--muted); padding: 4px 10px; font-size: .82rem; cursor: pointer; }
.seg button:last-child { border-right: 0; }
.seg button[aria-pressed="true"] { background: var(--accent-bg); color: var(--accent); font-weight: 600; }
.seg button:hover { color: var(--fg); }

/* ---------- simulation shell ---------- */
.sim { background: var(--panel); border-radius: 10px; padding: 14px 16px 16px; margin: 18px 0 22px; outline: none; }
.sim:focus-visible { box-shadow: 0 0 0 2px var(--accent); }
.sim-title { font-weight: 700; font-size: .98rem; margin-bottom: 2px; display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.sim-title .fig { font-weight: 500; }
.sim-opts { display: flex; flex-wrap: wrap; gap: 8px 16px; margin: 10px 0 8px; align-items: center; }
.sim-opt { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.sim-opt > span { font-size: .78rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.sim-ctrl { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin: 8px 0; }
.sim-ctrl .count { font-size: .82rem; color: var(--muted); margin-left: 4px; font-variant-numeric: tabular-nums; }
.sim-ctrl .hint { font-size: .76rem; color: var(--faint); margin-left: auto; }
.caption {
  background: var(--card); border-radius: var(--r); padding: 9px 12px; font-size: .9rem; min-height: 2.6em;
  border-left: 3px solid var(--accent); margin: 6px 0 10px;
}
.caption.k-bad, .caption.k-abort, .caption.k-crash { border-left-color: var(--bad); }
.caption.k-ok, .caption.k-commit { border-left-color: var(--ok); }
.caption.k-wait { border-left-color: var(--wait); }
.sim-body { display: grid; grid-template-columns: minmax(0, 1.75fr) minmax(210px, 1fr); gap: 12px; align-items: start; }
.sim-body.narrow-state { grid-template-columns: minmax(0, 2.2fr) minmax(190px, 1fr); }
@media (max-width: 760px) { .sim-body, .sim-body.narrow-state { grid-template-columns: minmax(0, 1fr); } }
.outcome { margin-top: 10px; padding: 9px 12px; border-radius: var(--r); font-size: .92rem; font-weight: 500; }
.outcome.ok { background: var(--ok-bg); color: var(--ok); }
.outcome.bad { background: var(--bad-bg); color: var(--bad); }
.outcome.neutral { background: var(--card); color: var(--fg); }
.outcome b { font-weight: 700; }

/* timeline (sequence-diagram style) */
.tl { background: var(--card); border-radius: var(--r); padding: 6px 4px 8px; overflow: hidden; }
.tl-row { display: grid; grid-template-columns: 24px repeat(var(--n), minmax(0, 1fr)); position: relative; min-height: 36px; }
.tl-row.cur { background: var(--accent-bg); border-radius: 5px; }
.tl-head { min-height: 0; margin-bottom: 4px; }
.tl-head .lane { text-align: center; font-weight: 700; font-size: .8rem; padding: 2px 4px 4px; border-bottom: 2px solid currentColor; margin: 0 6px; line-height: 1.25; }
.tl-num { font-size: .7rem; color: var(--faint); text-align: right; padding: 10px 4px 0 0; font-variant-numeric: tabular-nums; }
.tl-cell { background: linear-gradient(var(--line), var(--line)) center / 2px 100% no-repeat; }
.tl-cell.held { background: linear-gradient(var(--line), var(--line)) center / 2px 100% no-repeat, linear-gradient(var(--held), var(--held)) center / 34% 100% no-repeat; }
.tl-act {
  position: relative; z-index: 1; align-self: center; margin: 4px 5px; padding: 4px 8px; border-radius: 6px;
  background: var(--card); border: 1px solid var(--line); border-left: 3px solid var(--lc, var(--db));
  font-size: .8rem; line-height: 1.35; overflow-wrap: break-word; hyphens: auto;
}
.tl-msg { position: relative; z-index: 1; align-self: end; padding: 3px 0 13px; font-size: .78rem; line-height: 1.3; }
.tl-msg .lab { text-align: center; padding: 0 4px; overflow-wrap: break-word; position: relative; }
.tl-msg .lab span.bg { background: var(--card); padding: 0 3px; border-radius: 3px; }
.tl-row.cur .tl-msg .lab span.bg { background: var(--accent-bg); }
.tl-row.cur .tl-act { box-shadow: 0 1px 4px rgba(0,0,0,.08); }
.tl-msg .line { position: absolute; bottom: 6px; height: 2px; background: var(--lc, var(--db)); }
.tl-msg .line::after { content: ""; position: absolute; top: -4px; border: 5px solid transparent; }
.tl-msg.rt .line::after { right: -6px; border-left: 7px solid var(--lc, var(--db)); border-right: 0; }
.tl-msg.lt .line::after { left: -6px; border-right: 7px solid var(--lc, var(--db)); border-left: 0; }
.tl-msg.lost .line { background: repeating-linear-gradient(90deg, var(--bad) 0 6px, transparent 6px 10px); }
.tl-msg.lost .line::after { display: none; }
.tl-msg.lost .line::before { content: "✕"; position: absolute; left: 50%; top: -9px; transform: translateX(-50%); color: var(--bad); font-size: .8rem; font-weight: 700; }
.k-bad.tl-act, .k-abort.tl-act, .k-crash.tl-act { border-color: var(--bad); background: var(--bad-bg); }
.k-ok.tl-act, .k-commit.tl-act { border-color: var(--ok); background: var(--ok-bg); }
.k-wait.tl-act { border-color: var(--wait); background: var(--wait-bg); }
.k-note.tl-act { border-style: dashed; color: var(--muted); }
.tl-msg.k-bad .lab, .tl-msg.k-abort .lab { color: var(--bad); font-weight: 600; }
.tl-msg.k-ok .lab, .tl-msg.k-commit .lab { color: var(--ok); font-weight: 600; }
.tl-msg.k-wait .lab { color: var(--wait); font-weight: 600; }
.tl-empty { text-align: center; color: var(--faint); font-size: .82rem; padding: 14px 6px; }
.tl-legend { font-size: .74rem; color: var(--muted); padding: 4px 8px 0; }
.tl-legend i { display: inline-block; width: 14px; height: 10px; background: var(--held); vertical-align: -1px; margin-right: 4px; border-radius: 2px; }

/* state panel */
.state { display: grid; gap: 8px; }
.st { background: var(--card); border-radius: var(--r); padding: 7px 10px 8px; }
.st-name { font-size: .74rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-bottom: 3px; }
.st table { width: 100%; border-collapse: collapse; font-size: .82rem; }
.st td { padding: 2px 0; vertical-align: top; border-bottom: 1px dashed var(--line); }
.st tr:last-child td { border-bottom: 0; }
.st td:first-child { color: var(--muted); padding-right: 8px; width: 46%; }
.st td:last-child { font-family: var(--mono); font-size: .8rem; overflow-wrap: anywhere; }
.st .t { display: block; font-family: system-ui, sans-serif; font-size: .7rem; color: var(--faint); }
.st .dirty { color: var(--wait); }
.st .bad { color: var(--bad); font-weight: 700; }
.st .good { color: var(--ok); font-weight: 700; }
.st .gone { color: var(--faint); text-decoration: line-through; }
.st .empty { color: var(--faint); font-style: italic; font-size: .8rem; }
.st tr.chg td { animation: flash 1.2s ease-out; }
@keyframes flash { from { background: var(--accent-bg); } to { background: transparent; } }

/* ---------- labs (custom widgets) ---------- */
.lab-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 8px 0; }
.lab-row > .lbl { font-size: .78rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; margin-right: 2px; }
.panel { background: var(--card); border-radius: var(--r); padding: 10px 12px; }
.panel h5 { margin: 0 0 6px; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.grid2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
@media (max-width: 700px) { .grid2 { grid-template-columns: minmax(0, 1fr); } }
.log { font-size: .8rem; max-height: 180px; overflow-y: auto; margin: 0; padding-left: 0; list-style: none; }
.log li { padding: 3px 0; border-bottom: 1px dashed var(--line); }
.log li:first-child { font-weight: 600; }
.log .bad { color: var(--bad); } .log .ok { color: var(--ok); } .log .wait { color: var(--wait); }
.mtbl { width: 100%; border-collapse: collapse; font-size: .84rem; }
.mtbl th, .mtbl td { padding: 5px 7px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.mtbl th { font-size: .74rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; font-weight: 700; }
.mtbl td.num, .mtbl td.mono { font-family: var(--mono); font-size: .8rem; }
.mtbl tr.invisible td { color: var(--faint); }
.mtbl tr.invisible td.val { text-decoration: line-through; }
.vis-yes { color: var(--ok); font-weight: 700; }
.vis-no { color: var(--bad); font-weight: 700; }
.why { font-size: .76rem; color: var(--muted); display: block; font-weight: 400; }
.txchips { display: flex; flex-wrap: wrap; gap: 6px; }
.txchip { border: 1px solid var(--line); background: var(--card); border-radius: 6px; padding: 4px 9px; font-size: .8rem; cursor: pointer; text-align: left; color: var(--fg); line-height: 1.3; }
.txchip small { display: block; color: var(--muted); font-size: .72rem; }
.txchip[aria-pressed="true"] { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.txchip.committed { border-left: 3px solid var(--ok); }
.txchip.aborted { border-left: 3px solid var(--bad); opacity: .75; }
.txchip.active { border-left: 3px solid var(--wait); }
.txchip.waiting { border-left: 3px solid var(--wait); background: var(--wait-bg); }
.status-line { font-size: .9rem; padding: 8px 12px; border-radius: var(--r); background: var(--card); margin-top: 8px; }
.status-line.ok { background: var(--ok-bg); color: var(--ok); }
.status-line.bad { background: var(--bad-bg); color: var(--bad); }
.status-line.wait { background: var(--wait-bg); color: var(--wait); }

/* pipeline (durability) */
.pipe { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; margin: 10px 0; }
@media (max-width: 640px) { .pipe { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.pbox { background: var(--card); border-radius: var(--r); padding: 8px 10px; font-size: .82rem; border: 1px solid var(--line); min-height: 86px; }
.pbox .pt { font-weight: 700; font-size: .8rem; }
.pbox .pk { font-size: .72rem; color: var(--faint); }
.pbox .pv { margin-top: 6px; font-family: var(--mono); font-size: .78rem; }
.pbox.has { border-color: var(--accent); }
.pbox.lost { border-color: var(--bad); background: var(--bad-bg); }
.pbox.dead { opacity: .55; }

/* steps strip (single node commit) */
.strip { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; margin: 10px 0; }
@media (max-width: 640px) { .strip { grid-template-columns: minmax(0, 1fr); } }
.sbox { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 8px 10px; font-size: .82rem; cursor: pointer; text-align: left; color: var(--fg); }
.sbox b { display: block; font-size: .72rem; color: var(--faint); text-transform: uppercase; }
.sbox.done { border-color: var(--accent); }
.sbox.crash { border-color: var(--bad); background: var(--bad-bg); }
.sbox.after { opacity: .45; }

/* lock lab */
.locktx { display: grid; gap: 8px; }
.ltx { background: var(--card); border-radius: var(--r); padding: 8px 10px; display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: 8px; align-items: center; border-left: 3px solid var(--lc); }
@media (max-width: 640px) { .ltx { grid-template-columns: minmax(0, 1fr); } }
.ltx .nm { font-weight: 700; font-size: .9rem; }
.ltx .st2 { font-size: .76rem; color: var(--muted); }
.ltx .st2.wait { color: var(--wait); font-weight: 600; }
.ltx .st2.bad { color: var(--bad); font-weight: 600; }
.ltx .st2.ok { color: var(--ok); font-weight: 600; }
.ltx .ops { display: flex; flex-wrap: wrap; gap: 4px; }
.lockgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 8px; }
.lk { font-family: var(--mono); font-size: .78rem; padding: 1px 6px; border-radius: 4px; display: inline-block; margin: 1px 2px 1px 0; }
.lk.S { background: var(--accent-bg); color: var(--accent); }
.lk.X { background: var(--bad-bg); color: var(--bad); }
.lk.Q { background: var(--wait-bg); color: var(--wait); }
.compat { border-collapse: collapse; font-size: .86rem; margin: 10px 0; }
.compat th, .compat td { border: 1px solid var(--line); padding: 6px 12px; text-align: center; }
.compat th { background: var(--panel); }

/* predicate explorer grid */
.pgrid { display: grid; gap: 3px; font-size: .74rem; margin: 10px 0; }
.pgrid .hd { color: var(--muted); text-align: center; font-weight: 600; padding: 2px 0; }
.pgrid .rh { color: var(--muted); font-weight: 600; display: flex; align-items: center; }
.pc { height: 34px; border-radius: 4px; background: var(--card); border: 1px solid var(--line); cursor: pointer; position: relative; font-size: .7rem; color: var(--faint); padding: 0; }
.pc:hover { border-color: var(--accent); }
.pc.lock { background: repeating-linear-gradient(135deg, var(--held) 0 6px, transparent 6px 10px), var(--card); border-color: var(--wait); }
.pc.exact { box-shadow: inset 0 0 0 2px var(--bad); }
.pc.booked { background: var(--panel); color: var(--muted); }
.pc.pick { outline: 2px solid var(--accent); outline-offset: 1px; }

/* CoW tree */
.trees { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
@media (max-width: 640px) { .trees { grid-template-columns: minmax(0, 1fr); } }
.trees svg { width: 100%; height: auto; display: block; }
.trees text { font-family: var(--mono); font-size: 11px; fill: var(--fg); }
.trees .pg { font-size: 9px; fill: var(--faint); }
.trees rect { stroke-width: 1.4; rx: 5; }
.nd-shared rect { fill: var(--card); stroke: var(--line); }
.nd-new rect { fill: var(--accent-bg); stroke: var(--accent); }
.nd-old rect { fill: var(--wait-bg); stroke: var(--wait); }
.trees line { stroke: var(--faint); stroke-width: 1.2; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: .76rem; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -2px; margin-right: 4px; border: 1.4px solid; }

/* calculators */
.calc label { display: grid; grid-template-columns: 200px minmax(0, 1fr) 80px; gap: 10px; align-items: center; font-size: .86rem; margin: 6px 0; }
@media (max-width: 640px) { .calc label { grid-template-columns: minmax(0, 1fr) 70px; } .calc label input { grid-column: 1 / -1; grid-row: 2; } }
.calc input[type=range] { width: 100%; accent-color: var(--accent); }
.calc output { font-family: var(--mono); font-size: .82rem; text-align: right; }
.bar { height: 22px; border-radius: 4px; background: var(--card); display: flex; overflow: hidden; border: 1px solid var(--line); }
.bar > div { height: 100%; }
.bar .busy { background: var(--accent); }
.bar .idle { background: repeating-linear-gradient(135deg, var(--line) 0 4px, transparent 4px 8px); }
.barlab { font-size: .8rem; color: var(--muted); margin: 10px 0 3px; display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.barlab b { color: var(--fg); }
.big { font-size: 1.05rem; font-weight: 700; font-variant-numeric: tabular-nums; }

/* matrix */
.matrix { width: 100%; border-collapse: separate; border-spacing: 3px; font-size: .86rem; }
.matrix th { font-size: .78rem; color: var(--muted); font-weight: 700; text-align: center; padding: 4px; }
.matrix th.lv { text-align: left; color: var(--fg); font-size: .86rem; }
.matrix td button { width: 100%; border: 1px solid var(--line); border-radius: 5px; padding: 7px 4px; cursor: pointer; font-size: .82rem; font-weight: 600; background: var(--card); }
.matrix td button.p { color: var(--bad); background: var(--bad-bg); border-color: transparent; }
.matrix td button.v { color: var(--ok); background: var(--ok-bg); border-color: transparent; }
.matrix td button.d { color: var(--wait); background: var(--wait-bg); border-color: transparent; }
.matrix td button[aria-pressed="true"] { outline: 2px solid var(--accent); outline-offset: 1px; }

/* quiz */
.q { background: var(--panel); border-radius: var(--r); padding: 12px 14px; margin: 10px 0; }
.q .qt { font-weight: 600; margin-bottom: 6px; }
.q .opts { display: grid; gap: 5px; }
.q .opts button { text-align: left; border: 1px solid var(--line); background: var(--card); border-radius: 6px; padding: 6px 10px; cursor: pointer; font-size: .9rem; color: var(--fg); }
.q .opts button:hover:not(:disabled) { border-color: var(--accent); }
.q .opts button.right { border-color: var(--ok); background: var(--ok-bg); color: var(--ok); font-weight: 600; }
.q .opts button.wrong { border-color: var(--bad); background: var(--bad-bg); color: var(--bad); }
.q .opts button:disabled { cursor: default; }
.q .ex { font-size: .88rem; margin-top: 8px; color: var(--muted); display: none; }
.q.answered .ex { display: block; }
.score { font-weight: 700; }

/* glossary */
.gloss-search { width: 100%; padding: 8px 11px; border: 1px solid var(--line); border-radius: 6px; background: var(--card); color: var(--fg); font: inherit; font-size: .92rem; }
.gloss { display: grid; grid-template-columns: minmax(150px, 220px) minmax(0, 1fr); gap: 0; margin-top: 10px; font-size: .9rem; }
.gloss dt, .gloss dd { padding: 6px 8px; border-bottom: 1px solid var(--line); margin: 0; }
.gloss dt { font-weight: 600; }
@media (max-width: 600px) { .gloss { grid-template-columns: minmax(0, 1fr); } .gloss dt { border-bottom: 0; padding-bottom: 0; } }

/* XA diagram */
.xa { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 14px; align-items: center; margin: 12px 0; }
@media (max-width: 640px) { .xa { grid-template-columns: minmax(0, 1fr); } }
.xa .box { border: 1.5px solid var(--line); border-radius: var(--r); padding: 10px; background: var(--card); font-size: .84rem; }
.xa .box .bt { font-weight: 700; font-size: .82rem; margin-bottom: 6px; }
.xa .inner { border: 1px dashed var(--faint); border-radius: 6px; padding: 6px 8px; margin: 5px 0; }
.xa .inner.co { border-color: var(--co); }
.xa .parts { display: grid; gap: 8px; }

.foot { margin-top: 80px; padding-top: 14px; border-top: 1px solid var(--line); font-size: .82rem; color: var(--muted); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

@media (max-width: 960px) {
  .sim-ctrl .hint { display: none; }
}
@media (max-width: 520px) {
  .sim { padding: 12px 10px 14px; margin-left: -6px; margin-right: -6px; }
  .tl-act { font-size: .74rem; padding: 4px 6px; margin: 4px 3px; }
  .tl-msg { font-size: .72rem; }
  .tl-row { grid-template-columns: 18px repeat(var(--n), minmax(0, 1fr)); }
}
