:root {
  color-scheme: light;
  --paper: #fbfcfe;
  --grid: #e4ebf4;
  --surface: #ffffff;
  --ink: #1b2a4a;
  --ink-soft: #5a6782;
  --line: #cfd8e6;
  --sel: #3346c8;
  --ins: #b7790b;
  --bub: #0f7a69;
  --theory: #8a93a6;
  --err: #c2352b;
  --err-bg: #fbe3e1;
  --warn: #9a6a00;
  --warn-bg: #fff1c9;
  --ok-bg: #e3f4ec;
  --focus: #3346c8;
  --serif: "Iowan Old Style", "Charter", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --paper: #121722;
    --grid: #1b2231;
    --surface: #182030;
    --ink: #e6ebf5;
    --ink-soft: #9aa6bd;
    --line: #2c374c;
    --sel: #8b98f5;
    --ins: #e9ad3e;
    --bub: #45c4aa;
    --theory: #7d879b;
    --err: #ff8a80;
    --err-bg: #4a1f1d;
    --warn: #ffd166;
    --warn-bg: #43361a;
    --ok-bg: #173a2e;
    --focus: #8b98f5;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--sans);
  color: var(--ink);
  background-color: var(--paper);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 24px 24px;
  line-height: 1.5;
  font-variant-numeric: tabular-nums;
}
h1, h2, h3 { font-family: var(--serif); font-weight: 600; line-height: 1.2; margin: 0 0 .5rem; }
h1 { font-size: clamp(1.6rem, 3vw, 2.3rem); }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 .75rem; }
.muted { color: var(--ink-soft); }
.small { font-size: .85rem; }

.wrap { max-width: 1240px; margin: 0 auto; padding: 1.5rem 1rem 4rem; }
.narrow { max-width: 760px; }

.sheet {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}

.scroll { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
th, td { padding: .4rem .55rem; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
th { font-weight: 600; font-size: .9rem; }
th:first-child, td:first-child { text-align: left; }
thead th { border-bottom: 2px solid var(--ink); }
td.theory, th.theory { color: var(--theory); }
.sub { display: block; font-size: .75rem; color: var(--ink-soft); font-weight: 400; }

.c-sel { color: var(--sel); }
.c-ins { color: var(--ins); }
.c-bub { color: var(--bub); }
.dot { display: inline-block; width: .7em; height: .7em; border-radius: 50%; margin-right: .35em; vertical-align: baseline; }
.dot.sel { background: var(--sel); } .dot.ins { background: var(--ins); } .dot.bub { background: var(--bub); }

input[type=text], input[type=password], input[inputmode=numeric], select {
  font: inherit;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: .45rem .55rem;
}
input[inputmode=numeric] { width: 7.5rem; text-align: right; font-variant-numeric: tabular-nums; }
input:focus-visible, button:focus-visible, select:focus-visible { outline: 3px solid var(--focus); outline-offset: 1px; }

button {
  font: inherit;
  cursor: pointer;
  border-radius: 4px;
  border: 1px solid var(--ink);
  background: var(--ink);
  color: var(--paper);
  padding: .5rem 1rem;
}
button.ghost { background: transparent; color: var(--ink); border-color: var(--line); }
button.danger { background: transparent; color: var(--err); border-color: var(--err); }
button:disabled { opacity: .5; cursor: not-allowed; }

.msg { margin-top: .75rem; padding: .5rem .75rem; border-radius: 4px; display: none; }
.msg.show { display: block; }
.msg.ok { background: var(--ok-bg); }
.msg.bad { background: var(--err-bg); color: var(--err); }

.lvl-err { background: var(--err-bg); color: var(--err); font-weight: 600; }
.lvl-warn { background: var(--warn-bg); color: var(--warn); }
td[title] { cursor: help; }

.toggles { display: flex; flex-wrap: wrap; gap: .5rem 1.25rem; align-items: center; }
.toggles label { display: inline-flex; gap: .4rem; align-items: center; cursor: pointer; }
.toggles input[type=checkbox] { width: 1.1rem; height: 1.1rem; accent-color: var(--ink); }

.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 520px), 1fr)); gap: 1.25rem; }
.grid2 > .sheet { margin-bottom: 0; }
.chartbox { position: relative; height: 380px; }

.issues { list-style: none; padding: 0; margin: 0; }
.issues li { padding: .45rem .6rem; border-left: 4px solid var(--warn); margin-bottom: .4rem; background: var(--warn-bg); border-radius: 0 4px 4px 0; }
.issues li.err { border-left-color: var(--err); background: var(--err-bg); }
.issues b { font-weight: 600; }

.topbar { display: flex; flex-wrap: wrap; gap: 1rem; align-items: end; justify-content: space-between; margin-bottom: 1.25rem; }
.count { font-family: var(--serif); font-size: 2.6rem; line-height: 1; }

.hidden { display: none !important; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

#medA2 th, #medA2 td { padding: .35rem .4rem; }
