* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
  --red: #E60023;
  --navy: #0a3069;
  --ink: #0f172a;
  --slate: #64748b;
  --bg: #ffffff;
  --line: #e2e8f0;
}
body {
  font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  background: var(--bg);
  color: var(--ink);
}
a { color: inherit; text-decoration: none; }
header.site {
  padding: 20px 24px 12px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: baseline;
  gap: 14px;
  flex-wrap: wrap;
}
header.site h1 { font-size: 17px; font-weight: 600; }
header.site h1 .proto { color: var(--red); }
header.site .tag { font-size: 12px; color: var(--slate); }
.controls {
  display: flex;
  gap: 8px;
  padding: 10px 24px;
  align-items: center;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--line);
}
.controls button {
  font: inherit;
  font-size: 12px;
  padding: 5px 10px;
  border: 1px solid var(--line);
  background: #fff;
  cursor: pointer;
  border-radius: 4px;
  color: var(--ink);
}
.controls button.on { border-color: var(--red); color: var(--red); }
.controls .meta { font-size: 12px; color: var(--slate); margin-left: auto; }
#stage { position: relative; width: 100%; height: calc(100vh - 110px); }
#stage canvas { display: block; cursor: grab; }
#tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--ink);
  color: #fff;
  font-size: 12px;
  padding: 6px 9px;
  border-radius: 4px;
  display: none;
  white-space: nowrap;
  z-index: 5;
}
#tooltip .v { color: #fca5a5; }
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
  padding: 24px;
}
.card {
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
  transition: border-color .15s;
}
.card:hover { border-color: var(--red); }
.card canvas { display: block; width: 100%; height: 160px; }
.card .info { padding: 10px 12px; }
.card .info .t { font-size: 14px; font-weight: 600; }
.card .info .s { font-size: 11px; color: var(--slate); margin-top: 3px; }
footer { padding: 16px 24px; font-size: 11px; color: var(--slate); border-top: 1px solid var(--line); }

#legend { display: flex; gap: 10px; flex-wrap: wrap; font-size: 11px; color: var(--slate); align-items: center; }
#legend .lg { display: inline-flex; align-items: center; gap: 4px; }
#legend .sw { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
#tooltip .k { color: #94a3b8; display: inline-block; min-width: 52px; }

.srclink { color: var(--navy); text-decoration: underline; text-underline-offset: 2px; }
.srclink:hover { color: var(--red); }
.card .src { font-size: 10px; color: var(--slate); margin-top: 4px; line-height: 1.4; }
footer#sources { line-height: 1.9; }
footer .srcrow { font-size: 11px; }
footer .add { margin-top: 10px; color: #94a3b8; }

.chips { display: flex; gap: 8px; padding: 14px 24px 0; flex-wrap: wrap; }
.chip { font: inherit; font-size: 12px; padding: 5px 11px; border: 1px solid var(--line); background: #fff; cursor: pointer; border-radius: 999px; color: var(--slate); }
.chip.on { border-color: var(--red); color: var(--red); }
.card .cat { color: var(--red); }

#tablewrap { height: 100%; overflow: auto; padding: 0 24px 24px; }
table.dt { border-collapse: collapse; width: 100%; font-size: 12px; margin-top: 12px; }
table.dt th { text-align: left; padding: 7px 12px; border-bottom: 2px solid var(--ink); cursor: pointer; user-select: none; position: sticky; top: 0; background: #fff; }
table.dt th:hover { color: var(--red); }
table.dt td { padding: 5px 12px; border-bottom: 1px solid var(--line); }
table.dt td:nth-child(1) { color: var(--slate); width: 40px; }
table.dt td:nth-child(3), table.dt td:nth-child(4) { font-variant-numeric: tabular-nums; }
table.dt tr:hover td { background: #fef2f2; }

#timebar { padding-top: 8px; padding-bottom: 8px; }
#yslider { flex: 1; max-width: 480px; accent-color: var(--red); }
#ylabel { min-width: 46px; margin-left: 0; color: var(--ink); font-weight: 600; }

#stage { position: relative; }
#yearoverlay { position: absolute; bottom: 10px; right: 12px; font-size: 18px; font-weight: 700; color: var(--ink); background: rgba(255,255,255,0.88); border: 1px solid var(--line); border-radius: 4px; padding: 2px 8px; pointer-events: none; z-index: 4; }
#yearoverlay:empty { display: none; }
#legend .lp { color: #94a3b8; }
#caption { padding: 12px 24px 20px; font-size: 13px; color: var(--ink); border-top: 1px solid var(--line); line-height: 1.6; }
#caption b { font-weight: 600; }
html, body { height: 100%; }
body { display: flex; flex-direction: column; }
#stage { flex: 1; min-height: 0; height: auto; }
body:has(.grid) { display: block; height: auto; }

.cgroup { display: inline-flex; align-items: center; gap: 7px; margin-right: 14px; }
.clabel { font-size: 10px; text-transform: uppercase; letter-spacing: 1px; color: #94a3b8; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 5px; overflow: hidden; }
.seg button { border: none; border-radius: 0; padding: 5px 10px; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--red); color: #fff; border-color: var(--red); }
.seg button:disabled { opacity: 0.4; cursor: default; }
.cgroup.nav { margin-left: auto; margin-right: 0; }
.cgroup.nav .meta { margin-left: 0; }

header.site h2#dstitle { flex-basis: 100%; font-size: 21px; font-weight: 700; margin-top: 6px; letter-spacing: -0.2px; }

header.site { display: block; }
header.site .row1 { margin-bottom: 4px; }
header.site .row2 { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
header.site h2#dstitle { font-size: 21px; font-weight: 700; margin: 0; letter-spacing: -0.2px; flex-basis: auto; }

#barswrap { height: 100%; overflow: auto; padding: 12px 24px 24px; }
.barrow { display: flex; align-items: center; gap: 10px; padding: 3px 0; font-size: 12px; }
.bname { width: 230px; min-width: 230px; text-align: right; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.btrack { flex: 1; background: #f1f5f9; border-radius: 3px; height: 15px; overflow: hidden; }
.bfill { display: block; height: 100%; width: 0; transition: width 0.5s cubic-bezier(0.65,0,0.35,1); }
.bval { width: 130px; min-width: 130px; color: var(--slate); font-variant-numeric: tabular-nums; }
#howto { display: inline-flex; align-items: center; justify-content: center; width: 16px; height: 16px; border: 1px solid var(--line); border-radius: 50%; font-size: 10px; color: var(--ink); opacity: 0.6; cursor: help; margin-left: 8px; }
#legend { flex-basis: 100%; padding-left: 2px; }
.cgroup:has(#legend) { flex-wrap: wrap; }

@media (max-width: 640px) {
  header.site { padding: 10px 12px 6px; }
  header.site h1 { font-size: 15px; }
  header.site .tag { font-size: 11px; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .controls { padding: 6px 12px; gap: 6px; }
  .controls button, .seg button { font-size: 11px; padding: 4px 8px; }
  .cgroup { margin-right: 8px; gap: 5px; }
  .clabel { display: none; }
  #legend { flex-wrap: nowrap; overflow-x: auto; white-space: nowrap; scrollbar-width: none; padding-bottom: 2px; }
  #legend::-webkit-scrollbar { display: none; }
  #legend .lg { flex: 0 0 auto; }
  #howto { display: none; }
  #timebar { gap: 6px; }
  #yslider { min-width: 0; flex: 1; }
  #ylabel { min-width: 40px; }
  #caption { display: none; }
  #yearoverlay { font-size: 13px; padding: 1px 6px; bottom: 6px; right: 6px; }
  .grid { grid-template-columns: 1fr; gap: 12px; padding: 12px; }
  .chips { padding: 10px 12px 0; }
  .bname { width: 110px; min-width: 110px; }
  .bval { width: 90px; min-width: 90px; font-size: 11px; }
}
