:root {
  --bg: #f6f7f9; --card: #fff; --ink: #1c2330; --muted: #667085; --line: #e3e7ee;
  --accent: #0b6e4f; --accent-ink: #fff; --bar1: #2f7fd3; --bar2: #0b6e4f; --warn: #b54708;
  --T: #7a3fb0; --D: #1d6fa5; --A: #0b7a5a; --B: #a8660b;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0f1319; --card: #171d26; --ink: #e8ecf2; --muted: #98a2b3; --line: #2a3340;
    --accent: #3fb68b; --accent-ink: #0b1210; --bar1: #5aa2ee; --bar2: #3fb68b; --warn: #f79009;
    --T: #b98ae6; --D: #6db6ea; --A: #5fd3a8; --B: #e8a94f; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; }
header, main { max-width: 1060px; margin: 0 auto; padding: 0 16px; }
header { padding-top: 24px; }
h1 { font-size: 1.5rem; margin: 0 0 4px; }
h2 { font-size: 1.05rem; margin: 0; }
.sub { color: var(--muted); margin: 0 0 16px; max-width: 70ch; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px; margin-bottom: 16px; }
.inputs { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; align-items: end; }
.field label { display: block; font-weight: 600; font-size: .85rem; margin-bottom: 4px; }
.hint { color: var(--muted); font-size: .8rem; font-weight: 400; }
input, select, button, textarea { font: inherit; color: inherit; }
input[type=number], select, textarea { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
button { padding: 8px 14px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); cursor: pointer; }
button:hover { border-color: var(--muted); }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.primary:disabled { opacity: .6; cursor: progress; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.tools { display: flex; gap: 8px; flex-wrap: wrap; }
.tools select { width: auto; }
.auto { margin-bottom: 12px; border: 1px dashed var(--line); border-radius: 8px; padding: 8px 12px; }
.auto summary { cursor: pointer; font-weight: 600; font-size: .9rem; }
.autogrid { display: flex; flex-wrap: wrap; gap: 16px; align-items: center; margin-top: 10px; }
.cats { display: flex; gap: 10px; flex-wrap: wrap; }
.cats label { font-size: .85rem; display: flex; gap: 6px; align-items: center; }
.cats input { width: 52px; }
.slider { display: flex; gap: 8px; align-items: center; font-size: .85rem; }
.check { font-size: .85rem; display: flex; gap: 6px; align-items: center; }
.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 720px; }
th { text-align: left; font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; padding: 6px 8px; border-bottom: 1px solid var(--line); }
td { padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr.dragging { opacity: .4; }
tr.over td { border-top: 2px solid var(--accent); }
tr.zero td { opacity: .45; }
.grip { cursor: grab; user-select: none; color: var(--muted); white-space: nowrap; }
.grip button { padding: 0 4px; border: 0; background: none; color: var(--muted); font-size: .7rem; }
.name { font-weight: 600; }
.sub2 { color: var(--muted); font-size: .78rem; }
.badge { display: inline-block; font-size: .68rem; font-weight: 700; padding: 1px 6px; border-radius: 99px; margin-left: 6px; color: #fff; vertical-align: 1px; }
.badge.T { background: var(--T); } .badge.D { background: var(--D); } .badge.A { background: var(--A); } .badge.B { background: var(--B); }
td input[type=number] { width: 64px; padding: 4px 6px; }
td select { width: 56px; padding: 4px; }
.bar { position: relative; height: 22px; min-width: 120px; background: var(--bg); border-radius: 6px; overflow: hidden; }
.bar > i { position: absolute; inset: 0 auto 0 0; background: var(--bar1); opacity: .75; }
.bar.g > i { background: var(--bar2); }
.bar > b { position: relative; padding: 0 8px; line-height: 22px; font-size: .8rem; font-variant-numeric: tabular-nums; }
#summary h2 { margin-bottom: 8px; }
#summary ul { margin: 6px 0 0; padding-left: 18px; }
.warn { color: var(--warn); }
.notes p { max-width: 75ch; }
dialog { border: 1px solid var(--line); border-radius: 12px; background: var(--card); color: var(--ink); width: min(520px, 92vw); }
dialog::backdrop { background: #0008; }
.dlgbtns { display: flex; justify-content: flex-end; gap: 8px; margin-top: 10px; }
code { background: var(--bg); padding: 1px 4px; border-radius: 4px; }
#glossary dl { margin: 8px 0 0; display: grid; gap: 10px; max-width: 75ch; }
#glossary dt { font-weight: 600; }
#glossary dd { margin: 2px 0 0; color: var(--muted); }
.field.wide { grid-column: 1 / -1; }
