:root {
  color-scheme: dark;
  --bg: #0a0a0a;
  --surface: #141414;
  --border: #2a2a2a;
  --ink: #eaeaea;
  --ink-2: #b9b9b9;
  --ink-3: #888;
  --allies: #3f87e0;
  --axis: #e0563b;
}
* { box-sizing: border-box; }
body {
  margin: 0; min-height: 100vh; padding: 1.5rem;
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--bg); color: var(--ink);
}
.wrap { max-width: 1100px; margin: 0 auto; }

header h1 { margin: 0 0 .25rem; font-size: 1.5rem; }
header .sub { color: var(--ink-3); margin: 0 0 1.25rem; font-size: .9rem; line-height: 1.5; }

/* Date + event readout */
.readout { display: flex; align-items: baseline; gap: 1rem; flex-wrap: wrap; margin-bottom: .75rem; }
.readout .date { font-size: 1.9rem; font-weight: 700; font-variant-numeric: tabular-nums; min-width: 12ch; }
.readout .event { color: var(--ink-2); font-size: .95rem; }

/* Controls */
.controls { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin-bottom: .6rem; }
.controls button {
  background: var(--surface); color: var(--ink); border: 1px solid var(--border);
  border-radius: 8px; padding: .45rem .9rem; font-size: .9rem; cursor: pointer;
}
.controls button:hover { border-color: #444; }
.controls button.primary { background: #1d2a3f; border-color: #2e4468; }
.controls .spacer { flex: 1; }

/* Timeline */
.timeline {
  position: relative; height: 46px; margin: 0 0 1.25rem; cursor: pointer;
  touch-action: none; user-select: none;
}
.timeline .track {
  position: absolute; left: 0; right: 0; top: 14px; height: 8px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 4px;
}
.timeline .fill {
  position: absolute; left: 0; top: 14px; height: 8px;
  background: linear-gradient(90deg, #2e4468, #3f87e0); border-radius: 4px;
  pointer-events: none;
}
.timeline .thumb {
  position: absolute; top: 8px; width: 20px; height: 20px; margin-left: -10px;
  background: var(--ink); border-radius: 50%; border: 3px solid var(--bg);
  box-shadow: 0 0 0 1px var(--border); pointer-events: none;
}
.timeline:focus-visible { outline: 2px solid var(--allies); outline-offset: 4px; border-radius: 6px; }
.timeline .tick {
  position: absolute; top: 26px; color: var(--ink-3); font-size: .7rem;
  transform: translateX(-50%); pointer-events: none;
}
.timeline .tickmark {
  position: absolute; top: 22px; width: 1px; height: 5px; background: var(--border);
  pointer-events: none;
}
.timeline .evdot {
  position: absolute; top: 10px; width: 4px; height: 4px; margin-left: -2px;
  border-radius: 50%; background: var(--ink-3); pointer-events: none;
}

/* Butterfly chart: Allies grow leftward, Axis rightward, from a center spine. */
.duo-card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 1.1rem 1.25rem 1.25rem; }
.duo-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 1rem; }
.side-label h2 { margin: 0; font-size: 1rem; display: flex; align-items: center; gap: .5rem; }
.side-label .dot { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.side-label.allies .dot { background: var(--allies); }
.side-label.axis .dot { background: var(--axis); }
.side-label.axis { text-align: right; }
.side-label.axis h2 { justify-content: flex-end; }
.side-label .total { font-size: 1.7rem; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: .2rem; }
.side-label .total small { font-size: .8rem; font-weight: 400; color: var(--ink-3); margin-left: .4rem; }

.duo { position: relative; transition: height .55s ease; }
.duo::before {
  content: ''; position: absolute; left: 50%; top: -6px; bottom: -6px; width: 2px;
  margin-left: -1px; background: var(--border);
}
.half {
  position: absolute; height: 30px;
  display: flex; align-items: flex-start; gap: .45rem;
  transition: top .55s ease, opacity .35s ease;
}
.half .id, .half .track { height: 16px; }
.half.allies { left: 0; right: 50%; }
.half.axis { left: 50%; right: 0; }
.half.off { opacity: 0; pointer-events: none; }
/* While scrubbing the timeline, follow the pointer instantly. */
.duo-card.scrub .half, .duo-card.scrub .half .bar, .duo-card.scrub .tb, .duo-card.scrub .duo { transition: none; }
.half .id { display: flex; align-items: center; gap: .45rem; min-width: 0; }
.half .name {
  position: absolute; top: 15px; max-width: 92%;
  font-size: .68rem; color: var(--ink-3);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.half.allies .name { right: 5px; }
.half.axis .name { left: 5px; }
.half .val { font-size: .76rem; color: var(--ink-2); font-variant-numeric: tabular-nums; white-space: nowrap; }
.half .track { flex: 1; display: flex; align-items: center; min-width: 0; }
.half .bar { height: 12px; min-width: 2px; transition: width .18s linear; }

/* Allies half (DOM: flag·name | value·bar): bar hugs the center spine, grows left */
.half.allies { padding-right: 5px; }
.half .bar { transition: width .18s linear; }
.half.allies .track { justify-content: flex-end; }
.half.allies .bar { background: var(--allies); border-radius: 4px 0 0 4px; }
.half.allies .val { margin-right: .45rem; }
/* Axis half (DOM: bar·value | name·flag): mirrored */
.half.axis { padding-left: 5px; }
.half.axis .bar { background: var(--axis); border-radius: 0 4px 4px 0; }
.half.axis .val { margin-left: .45rem; }

.flag { width: 21px; height: 14px; flex: none; border-radius: 2px; outline: 1px solid rgba(255,255,255,.18); }

/* Bottom tug-of-war bar: side totals set against each other */
.totalbar { display: flex; margin-top: 1.25rem; height: 32px; border-radius: 8px; overflow: hidden; }
.tb {
  display: flex; align-items: center; min-width: 0; white-space: nowrap;
  font-size: .82rem; font-weight: 600; color: #fff;
  font-variant-numeric: tabular-nums;
}
.tb.allies { background: var(--allies); justify-content: flex-start; padding-left: .7rem; border-right: 2px solid var(--surface); transition: width .55s ease; }
.tb.axis { background: var(--axis); justify-content: flex-end; padding-right: .7rem; flex: 1; }

@media (max-width: 640px) {
  .half .name { display: none; } /* flags only on small screens */
  .flag { width: 18px; height: 12px; }
  .half .val { font-size: .68rem; }
}

/* Tooltip */
#tooltip {
  position: fixed; z-index: 10; pointer-events: none; max-width: 280px;
  background: #1d1d1d; border: 1px solid #3a3a3a; border-radius: 8px;
  padding: .5rem .7rem; font-size: .8rem; line-height: 1.45; color: var(--ink);
  box-shadow: 0 6px 20px rgba(0,0,0,.5); display: none;
}
#tooltip .t-name { font-weight: 600; }
#tooltip .t-note { color: var(--ink-3); }

/* Table view */
#tablewrap { margin-top: 1.25rem; overflow-x: auto; }
#tablewrap table { border-collapse: collapse; width: 100%; font-size: .85rem; }
#tablewrap th, #tablewrap td { text-align: left; padding: .4rem .7rem; border-bottom: 1px solid var(--border); }
#tablewrap td.num { text-align: right; font-variant-numeric: tabular-nums; }
#tablewrap th { color: var(--ink-3); font-weight: 600; }
.hidden { display: none; }

/* About / sources */
.about {
  margin-top: 2rem; color: var(--ink-2); font-size: .88rem; line-height: 1.65;
  border-top: 1px solid var(--border); padding-top: 1.25rem; max-width: 62rem;
}
.about h2 { font-size: 1.1rem; color: var(--ink); margin: 0 0 .5rem; }
.about h3 { font-size: .95rem; color: var(--ink); margin: 1.25rem 0 .4rem; }
.about ul { margin: .4rem 0 0; padding-left: 1.2rem; }
.about li { margin-bottom: .55rem; }
.about strong { color: var(--ink); }
.about a { color: #6ea8ea; text-decoration: none; }
.about a:hover { text-decoration: underline; }
.about .src-what { color: var(--ink-3); }
