:root {
  --paper: #ffffff;
  --ink: #111111;
  --ink-2: #555555;
  --ink-3: #767676;
  --rule: #111111;
  --rule-soft: #e2e2e2;
  --wash: #f4f4f2;
  --blue: #1f3fd9;
  --hue: #c2410c;
  --sans: "Helvetica Neue", Helvetica, Arial, system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, monospace;
  --side: 300px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.5 var(--sans);
}
a { color: var(--blue); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:focus-visible, button:focus-visible, select:focus-visible, summary:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
h1, h2, h3 { font-weight: 700; letter-spacing: -0.01em; line-height: 1.15; }
h1 { font-size: 2rem; margin: 0 0 0.75rem; }
h2 { font-size: 1.35rem; margin: 0 0 0.35rem; }
h3 { font-size: 1rem; margin: 1.25rem 0 0.4rem; }
p { margin: 0 0 0.8rem; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-2); }
.small { font-size: 0.85rem; }

/* Layout: a narrow reading/controls column, the charts get the rest. */
.layout {
  display: grid;
  grid-template-columns: var(--side) minmax(0, 1fr);
  gap: 0 40px;
  max-width: 1320px;
  margin: 0 auto;
  padding: 24px 24px 64px;
}
.side-inner {
  position: sticky;
  top: calc(var(--appnav-h, 48px) + 16px);
  max-height: calc(100vh - var(--appnav-h, 48px) - 32px);
  overflow-y: auto;
  padding-right: 4px;
}
.lede { color: var(--ink); }
.stamp { font-size: 0.85rem; color: var(--ink-2); border-top: 1px solid var(--rule); padding-top: 8px; margin-top: 12px; }

.labs { list-style: none; margin: 14px 0; padding: 0; }
.labs li { display: flex; align-items: center; gap: 8px; padding: 3px 0; font-size: 0.92rem; }
.labs .sw { width: 10px; height: 10px; border-radius: 2px; flex: none; }
.labs .n { margin-left: auto; color: var(--ink-2); }

.controls { border-top: 1px solid var(--rule-soft); padding-top: 12px; margin-top: 8px; }
.controls label { display: block; font-size: 0.8rem; color: var(--ink-2); margin: 8px 0 3px; }
.controls.inline { border-top: 0; padding-top: 0; margin-top: 4px; display: flex; align-items: center; gap: 8px; }
.controls.inline label { display: inline; margin: 0; }
.controls.inline select { width: auto; }
.controls select { width: 100%; font: inherit; font-size: 0.92rem; padding: 6px 8px; border: 1px solid var(--ink-3); border-radius: 3px; background: var(--paper); color: var(--ink); }
.toc { margin-top: 16px; border-top: 1px solid var(--rule-soft); padding-top: 10px; font-size: 0.9rem; }
.toc a { display: block; padding: 3px 0; color: var(--ink); text-decoration: none; }
.toc a:hover { color: var(--blue); text-decoration: underline; }

main section { border-top: 2px solid var(--rule); padding: 14px 0 34px; }
main section:first-child { border-top: 0; padding-top: 0; }
.sec-note { color: var(--ink-2); max-width: 70ch; }

/* Bar matrix: rows x labs, each cell a share bar. Used for mix, skills, places. */
.matrix { display: grid; gap: 2px 10px; margin-top: 12px; align-items: center; }
.matrix .hd { font-size: 0.8rem; color: var(--ink-2); padding-bottom: 4px; border-bottom: 1px solid var(--rule); align-self: end; }
.matrix .hd.lab { display: flex; align-items: center; gap: 6px; }
.matrix .rl { font-size: 0.9rem; padding: 4px 0; line-height: 1.2; }
.matrix .rl .sub { display: block; font-size: 0.75rem; color: var(--ink-3); }
.matrix .cell { position: relative; height: 22px; background: var(--wash); border-radius: 2px; cursor: default; }
.matrix .cell .bar { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 0 4px 4px 0; }
.matrix .cell .v { position: absolute; left: 4px; top: 50%; transform: translateY(-50%); font-size: 0.78rem; color: var(--ink); white-space: nowrap; font-variant-numeric: tabular-nums; }
.matrix .cell .v.out { color: var(--ink); }
.matrix .cell.zero .v { color: var(--ink-3); }
.matrix .tot { font-size: 0.8rem; color: var(--ink-2); border-top: 1px solid var(--rule); padding-top: 4px; }
.lab-dot { width: 9px; height: 9px; border-radius: 2px; display: inline-block; flex: none; }

.toggle { display: inline-flex; border: 1px solid var(--ink-3); border-radius: 3px; overflow: hidden; margin-top: 6px; }
.toggle button { font: inherit; font-size: 0.82rem; border: 0; background: var(--paper); color: var(--ink); padding: 4px 10px; cursor: pointer; }
.toggle button[aria-pressed="true"] { background: var(--ink); color: var(--paper); }

.chart { width: 100%; margin-top: 10px; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart text { font-family: var(--sans); fill: var(--ink-2); font-size: 11px; }
.chart .axis line, .chart .grid line { stroke: var(--rule-soft); }
.chart .axis path { display: none; }
.chart .lbl { fill: var(--ink); font-size: 12px; }

.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin: 12px 0; }
.stat { border-top: 1px solid var(--rule); padding-top: 6px; }
.stat .big { font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .cap { font-size: 0.8rem; color: var(--ink-2); display: flex; align-items: center; gap: 6px; }

table.list { width: 100%; border-collapse: collapse; font-size: 0.88rem; margin-top: 8px; }
table.list th { text-align: left; font-weight: 600; font-size: 0.78rem; color: var(--ink-2); border-bottom: 1px solid var(--rule); padding: 4px 6px 4px 0; }
table.list td { border-bottom: 1px solid var(--rule-soft); padding: 5px 6px 5px 0; vertical-align: top; }
table.list td.r, table.list th.r { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.more { font: inherit; font-size: 0.85rem; margin-top: 8px; border: 1px solid var(--ink-3); background: var(--paper); color: var(--ink); padding: 4px 10px; border-radius: 3px; cursor: pointer; }
.empty { background: var(--wash); padding: 12px 14px; border-left: 3px solid var(--hue); max-width: 70ch; }

.rules { font-size: 0.85rem; }
.rules code { font-family: var(--mono); font-size: 0.78rem; word-break: break-word; color: var(--ink); }
details { margin-top: 10px; }
summary { cursor: pointer; font-weight: 600; }

.sources ol { padding-left: 1.2rem; font-size: 0.88rem; }
.sources li { margin-bottom: 6px; }

#tip {
  position: fixed; z-index: 4000; pointer-events: none; max-width: 280px;
  background: var(--ink); color: var(--paper); font-size: 0.8rem; line-height: 1.35;
  padding: 6px 8px; border-radius: 3px; opacity: 0; transition: opacity 0.08s;
}
#tip.on { opacity: 1; }

@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); padding: 16px 16px 48px; }
  .side-inner { position: static; max-height: none; overflow: visible; }
  .toc { display: none; }
  main { margin-top: 18px; }
  h1 { font-size: 1.65rem; }
}
@media (max-width: 600px) {
  .matrix .rl { grid-column: 1 / -1; padding-bottom: 0; }
  .matrix .hd.corner { display: none; }
  .matrix .hd.lab span.name { display: none; }
  .matrix .cell { height: 20px; }
  .matrix .cell .v { font-size: 0.72rem; left: 3px; }
  table.list .hide-sm { display: none; }
}
