/* toxage-sim explorer. Colours are tokens with a light and a dark value;
   the chart series follow a colour-blind-checked palette. */
:root {
  color-scheme: light dark;
  --bg: light-dark(#f6f6f4, #121211);
  --surface: light-dark(#fcfcfb, #1a1a19);
  --border: light-dark(#dcdbd6, #34332f);
  --text: light-dark(#0b0b0b, #f0efec);
  --muted: light-dark(#52514e, #a9a8a0);
  --grid: light-dark(#e6e5e0, #2c2b28);
  --accent: light-dark(#1c5cab, #6da7ec);
  --event: light-dark(#eb6834, #d95926);
  --none: light-dark(#b3b2ab, #5f5e58);
  --obs: light-dark(#eb6834, #d95926);
  --pred: light-dark(#2a78d6, #3987e5);
  --t1: light-dark(#86b6ef, #9ec5f4);
  --t2: light-dark(#2a78d6, #3987e5);
  --t3: light-dark(#104281, #184f95);
  --hl: light-dark(#0b0b0b, #ffffff);
  --hl-band: light-dark(#fff1c2, #3d3420);
  --error: light-dark(#b42318, #f97066);
  font-size: 15px;
}
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }
:root[data-textsize="large"] { font-size: 18px; }

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 1rem/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-variant-numeric: tabular-nums;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
main { flex: 1; padding: 16px; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.error { color: var(--error); }
pre { background: var(--surface); border: 1px solid var(--border); padding: 8px 12px; overflow-x: auto; }

button, .button, input, select {
  font: inherit;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 10px;
}
button, .button { cursor: pointer; text-decoration: none; display: inline-block; }
button:hover, .button:hover { border-color: var(--accent); }
.primary { background: var(--accent); border-color: var(--accent); color: var(--surface); }
button.link { border: 0; background: none; color: var(--accent); padding: 0; text-decoration: underline; }

/* Header */
.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 8px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 1.1rem; color: var(--text); text-decoration: none; margin-right: auto; }
.brand span { font-weight: 400; color: var(--muted); }
.search { display: flex; gap: 6px; }
.search input { width: 13em; }

.menu { position: relative; margin-left: auto; }
.menu summary { list-style: none; cursor: pointer; padding: 6px; border: 1px solid var(--border); border-radius: 4px; }
.menu summary::-webkit-details-marker { display: none; }
.burger, .burger::before, .burger::after {
  display: block; width: 18px; height: 2px; background: var(--text); position: relative; content: "";
}
.burger { margin: 6px 0; }
.burger::before { position: absolute; top: -6px; }
.burger::after { position: absolute; top: 6px; }
.menu-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 10;
  width: 270px;
  max-width: calc(100vw - 32px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 6px 24px rgb(0 0 0 / .15);
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.menu-panel h3 { margin: 8px 0 0; font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.setting { border: 0; padding: 0; margin: 0; display: flex; gap: 10px; flex-wrap: wrap; }
.setting legend { padding: 0; margin-bottom: 2px; }

/* Status bars */
.statusbar {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 18px;
  padding: 6px 16px;
  font-size: .87rem;
  color: var(--muted);
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.statusbar.top { border-top: 0; border-bottom: 1px solid var(--border); }
.statusbar b { color: var(--text); }
.statusbar .focus { color: var(--text); }
.patient-tag { color: var(--text); font-weight: 600; border-left: 3px solid var(--hl); padding-left: 6px; }

/* Layout */
.layout { display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 800px) { .layout { grid-template-columns: minmax(0, 1fr); } }
.panel, .filters, .charts {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 14px 16px;
  margin-bottom: 16px;
}
.narrow { max-width: 760px; margin: 24px auto; }
.lead { font-size: 1.05rem; }
.notice { padding: 8px 12px; border: 1px solid currentColor; border-radius: 4px; }

/* Disclaimer */
.disclaimer h2 { margin-top: 1.2em; }
.accept { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--border); }
.accept button { align-self: flex-start; }

/* Filters */
.filters details { border-top: 1px solid var(--border); padding: 6px 0; }
.filters summary { cursor: pointer; font-weight: 600; }
.filters fieldset { border: 0; margin: 8px 0 0; padding: 0 0 0 8px; border-left: 3px solid transparent; }
.filters fieldset.active { border-left-color: var(--accent); }
.filters legend { font-size: .87rem; color: var(--muted); padding: 0; }
.filters label { display: block; font-size: .9rem; }
.range { display: flex; gap: 4px; align-items: center; }
.range input { width: 100%; min-width: 0; }
.actions { display: flex; gap: 8px; margin-top: 12px; }

/* Patient */
.tag { font-size: .8rem; font-weight: 400; color: var(--muted); border: 1px solid var(--border); border-radius: 10px; padding: 1px 8px; margin-left: 8px; }
.patient { border-left: 4px solid var(--hl); }
.patient-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; }
.facts, .factors { border-collapse: collapse; width: 100%; font-size: .9rem; }
.facts th, .facts td, .factors th, .factors td { text-align: left; padding: 2px 6px 2px 0; vertical-align: middle; }
.facts th { font-weight: 400; color: var(--muted); }
.facts th.group { color: var(--text); font-weight: 600; padding-top: 8px; }
.riskcard { border: 1px solid var(--border); border-radius: 6px; padding: 10px 12px; }
.riskcard.focus { border-color: var(--accent); }
.riskcard .big { font-size: 2rem; font-weight: 700; margin: 0; }
.riskcard p { margin: 4px 0; }
.event-text { color: var(--event); }
.factors caption { text-align: left; font-size: .8rem; color: var(--muted); padding: 6px 0 2px; }
.factors th { font-weight: 400; }
.factors td:last-child { text-align: right; width: 3.5em; }
.fbar { width: 35%; position: relative; height: 14px; }
.fbar::before { content: ""; position: absolute; left: 50%; top: 0; bottom: 0; border-left: 1px solid var(--muted); }
.fbar span { position: absolute; top: 3px; height: 8px; border-radius: 2px; }
.fbar .up { left: 50%; background: var(--event); }
.fbar .down { right: 50%; background: var(--pred); }

/* Charts */
.tabs { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-bottom: 4px; }
.tabs span { color: var(--muted); margin-right: 4px; }
.tabs a { padding: 4px 12px; border: 1px solid var(--border); border-radius: 16px; text-decoration: none; color: var(--text); background: var(--surface); }
.tabs a.active { background: var(--accent); border-color: var(--accent); color: var(--surface); }
.model-info { font-size: .85rem; margin: 0 0 12px; }
.note { color: var(--muted); font-size: .87rem; margin-top: -4px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(360px, 1fr)); gap: 20px; }
tox-chart { display: block; min-width: 0; }
tox-chart figure { margin: 0; }
tox-chart figcaption { font-weight: 600; font-size: .92rem; margin-bottom: 4px; }
tox-chart svg { width: 100%; height: auto; display: block; overflow: visible; }
tox-chart .empty { color: var(--muted); }
tox-chart text { fill: var(--muted); font-size: 12.5px; }
tox-chart text.cat { fill: var(--text); }
tox-chart text.hl-text { fill: var(--hl); font-weight: 700; }
tox-chart .grid { stroke: var(--grid); stroke-width: 1; }
tox-chart .axisline { stroke: var(--muted); }
tox-chart .diagonal { stroke: var(--muted); stroke-dasharray: 4 4; }
tox-chart .marker { stroke: var(--hl); stroke-width: 1.5; stroke-dasharray: 3 3; }
tox-chart .hit { fill: transparent; }
tox-chart .hl-band { fill: var(--hl-band); }
tox-chart .cat-group.link { cursor: pointer; }
tox-chart .cat-group.link:hover .hit { fill: var(--grid); }
tox-chart .ln { fill: none; stroke-width: 2; }
tox-chart .pt { fill-opacity: .55; cursor: pointer; }
tox-chart .pt:hover { fill-opacity: 1; stroke: var(--hl); }
tox-chart .hl-point { fill: none; stroke: var(--hl); stroke-width: 2.5; }
tox-chart .dot { stroke: var(--surface); stroke-width: 2; }
.s-event { fill: var(--event); background: var(--event); }
.s-none { fill: var(--none); background: var(--none); }
.s-obs { fill: var(--obs); stroke: var(--obs); background: var(--obs); }
.s-pred { fill: var(--pred); background: var(--pred); }
.s-t1 { stroke: var(--t1); background: var(--t1); }
.s-t2 { stroke: var(--t2); background: var(--t2); }
.s-t3 { stroke: var(--t3); background: var(--t3); }
.ln.s-obs { fill: none; }
/* Two scenarios side by side: selected (sa) and comparison (sb, dashed). */
.s-sa { fill: var(--pred); stroke: var(--pred); background: var(--pred); }
.s-sb { fill: var(--none); stroke: var(--muted); background: var(--none); }
.ln.s-sa, .ln.s-sb, .ln.s-pred, .ln.s-t1, .ln.s-t2, .ln.s-t3 { fill: none; }
.ln.s-pred { stroke: var(--pred); }
.ln.dash { stroke-dasharray: 6 4; }
.s-g1 { fill: var(--t1); background: var(--t1); }
.s-g2 { fill: var(--t2); background: var(--t2); }
.s-g3 { fill: var(--event); background: var(--event); }
.s-g5 { fill: var(--hl); background: var(--hl); }
tox-chart .mk { stroke-width: 2; cursor: help; }
tox-chart .mk-ev { stroke: var(--event); }
tox-chart .mk-al { stroke: var(--muted); stroke-dasharray: 2 3; stroke-width: 1.5; }
tox-chart .mk-end { stroke: var(--hl); stroke-dasharray: 5 3; stroke-width: 1.5; }
.legend .s-mk-ev { background: var(--event); width: 3px; }
.legend .s-mk-al { background: var(--muted); width: 3px; }
.legend .s-mk-end { background: var(--hl); width: 3px; }
/* Scenario choice and tables of the time and intervention views. */
.scenario { display: flex; gap: 6px 14px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.scenario label { color: var(--muted); }
.scenario-note { margin: 0 0 10px; }
table.numbers { border-collapse: collapse; width: 100%; font-size: .87rem; margin-bottom: 14px; }
table.numbers th, table.numbers td { padding: 4px 8px; border-bottom: 1px solid var(--border); text-align: right; white-space: nowrap; }
table.numbers th:first-child, table.numbers td:first-child { text-align: left; white-space: normal; }
table.numbers thead th { color: var(--muted); font-weight: 600; vertical-align: bottom; white-space: normal; }
table.numbers tr.selected td { background: var(--hl-band); font-weight: 600; }
.scroll { overflow-x: auto; }
.columns { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: .8rem; color: var(--muted); margin-top: 4px; }
.legend .sw { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
.legend .s-hl { background: none; border: 2px solid var(--hl); border-radius: 50%; }

/* Main navigation and pages next to the explorer. */
.mainnav { display: flex; gap: 2px; flex-wrap: wrap; margin-right: auto; }
.brand { margin-right: 12px; }
.mainnav a { padding: 4px 10px; border-radius: 4px; text-decoration: none; color: var(--text); }
.mainnav a:hover { background: var(--grid); }
.mainnav a.active { background: var(--accent); color: var(--surface); }
.page { max-width: 900px; margin: 0 auto; display: flex; flex-direction: column; gap: 14px; }
.page.wide { max-width: 1300px; }
.page > h1, .page > p { margin: 0; }
.dataset { border: 1px solid var(--border); border-radius: 6px; padding: 10px 14px; margin-bottom: 12px; }
.dataset.active { border-left: 4px solid var(--accent); }
.dataset header h3 { margin: 0; }
.dataset header p { margin: 2px 0 8px; }
.tag { font-size: .75rem; font-weight: 400; border: 1px solid var(--border); border-radius: 10px; padding: 1px 8px; color: var(--muted); }
form.inline { display: inline; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
progress { width: 220px; vertical-align: middle; accent-color: var(--accent); }
.form { display: flex; flex-direction: column; gap: 12px; max-width: 640px; }
.form label { display: flex; flex-direction: column; gap: 2px; }
.form label.check { display: block; }
.form small, .paramtable small { display: block; color: var(--muted); font-size: .82rem; font-weight: 400; }
.form fieldset { border: 1px solid var(--border); border-radius: 6px; display: flex; flex-direction: column; gap: 6px; }
.form input[type="text"], .form input[type="number"] { max-width: 260px; }
.notice { border: 1px solid var(--border); border-left: 4px solid var(--accent); padding: 6px 10px; border-radius: 4px; background: var(--surface); }
.notice.error { border-left-color: var(--error); }
.count { font-size: .75rem; background: var(--hl-band); color: var(--text); border-radius: 10px; padding: 1px 7px; }
.params details { border: 1px solid var(--border); border-radius: 6px; background: var(--surface); padding: 6px 12px; margin-bottom: 8px; }
.params summary { cursor: pointer; font-weight: 600; text-transform: capitalize; }
.params .sticky { position: sticky; top: 0; z-index: 5; background: var(--bg); padding: 8px 0; }
.paramtable { border-collapse: collapse; width: 100%; font-size: .9rem; margin: 6px 0; }
.paramtable th, .paramtable td { text-align: left; padding: 3px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
.paramtable tbody th { font-weight: 400; width: 46%; }
.paramtable thead th { color: var(--muted); font-size: .8rem; }
.paramtable input, .paramtable select { width: 100%; min-width: 9em; }
.paramtable td.muted { overflow-wrap: anywhere; max-width: 18em; }
.paramtable tr.changed th, .paramtable tr.changed td { background: var(--hl-band); }
table.records td, table.schema td { text-align: left; white-space: nowrap; }
table.schema td:last-child { white-space: normal; min-width: 22em; }
ul.plain { list-style: none; padding: 0; margin: 0 0 8px; display: flex; flex-direction: column; gap: 3px; }
.docnav a.current { font-weight: 700; color: var(--text); }
.docnav h3 { margin: 10px 0 4px; font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.doc { max-width: 980px; line-height: 1.55; }
.doc h1 { margin-top: 0; }
.doc h2 { margin-top: 1.6em; padding-top: .4em; border-top: 1px solid var(--border); }
.doc h3 { margin-top: 1.2em; }
.doc table { border-collapse: collapse; font-size: .9rem; margin: 8px 0; }
.doc th, .doc td { border: 1px solid var(--border); padding: 4px 8px; text-align: left; vertical-align: top; }
.doc th { background: var(--bg); }
.doc code, code { font-size: .9em; background: var(--grid); padding: 0 3px; border-radius: 3px; }
.doc pre { white-space: pre-wrap; }
.doc li { margin: 2px 0; }

/* Tutorial and demo. */
.tour {
  position: fixed; z-index: 1000; width: min(420px, calc(100vw - 16px)); max-height: calc(100vh - 16px); overflow: auto;
  background: var(--surface); color: var(--text); border: 2px solid var(--accent); border-radius: 8px;
  box-shadow: 0 8px 30px rgb(0 0 0 / .3); padding: 10px 14px; font-size: .92rem;
}
.tour::before {
  content: ""; position: absolute; left: var(--arrow, 50%); width: 14px; height: 14px; margin-left: -7px;
  background: var(--surface); border: 2px solid var(--accent); transform: rotate(45deg); display: none;
}
.tour[data-side="below"]::before { display: block; top: -9px; border-right: 0; border-bottom: 0; }
.tour[data-side="above"]::before { display: block; bottom: -9px; border-left: 0; border-top: 0; }
.tour header { color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; }
.tour h2 { margin: 2px 0 6px; font-size: 1.05rem; }
.tour p { margin: 0 0 8px; }
.tour-do { border-left: 3px solid var(--accent); padding-left: 8px; }
.tour-note { color: var(--muted); font-style: italic; }
.tour-buttons { display: flex; gap: 6px; flex-wrap: wrap; }
.tour-speed { display: grid; gap: 4px; margin-top: 8px; font-size: .82rem; color: var(--muted); }
.tour-speed label { display: grid; }
.tour-speed input { padding: 0; border: 0; accent-color: var(--accent); }
.tour-ring {
  position: fixed; z-index: 999; pointer-events: none; border: 3px solid var(--accent); border-radius: 6px;
  box-shadow: 0 0 0 4px rgb(28 92 171 / .25); transition: all .15s;
}
.tour-dialog { max-width: min(560px, calc(100vw - 32px)); border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text); padding: 18px 22px; }
.tour-dialog::backdrop { background: rgb(0 0 0 / .45); }
.tour-choice { display: grid; grid-template-columns: auto 1fr; gap: 10px 14px; align-items: start; margin: 12px 0; }
.tour-choice p { margin: 0; }
.tour-dialog .check { display: block; margin: 12px 0; }
.tour-dialog small { display: block; color: var(--muted); }
.tour-unfinished { background: var(--hl-band); padding: 8px 16px; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
