:root {
  --bg: #0b1020;
  --panel: #141b30;
  --line: #232c4a;
  --ink: #e8ecf8;
  --muted: #8b93ad;
  --accent: #5eead4;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  overflow: hidden;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  display: flex;
  flex-direction: column;
}
#topbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 16px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; letter-spacing: .02em; color: var(--accent); }
.lbl {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .08em;
  margin-right: 4px;
}
.ctl { display: inline-flex; align-items: center; gap: 6px; }
.time-ctl { flex: 1 1 260px; min-width: 220px; }
#current-year {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  min-width: 46px;
  text-align: right;
  color: var(--accent);
}
#time-slider { flex: 1; accent-color: var(--accent); }
.btn {
  background: #1d2743;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
  font: inherit;
}
.btn:hover { border-color: var(--accent); }
.btn.active { background: var(--accent); color: #06281f; }
select, #add-category {
  background: #1d2743;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 8px;
  font: inherit;
}
#add-category { width: 130px; }
#categories {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 12px;
  min-height: 20px;
}
.chip {
  background: #1d2743;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 12px;
  cursor: pointer;
  font-size: 13px;
}
.chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #06281f;
  font-weight: 600;
}
.hint { color: var(--muted); font-size: 12px; flex-basis: 100%; }
main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 10px 16px 14px;
  gap: 8px;
}
.section-label {
  font-size: 11px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--muted);
}
#map-section {
  flex: 3;
  display: flex;
  flex-direction: column;
  min-height: 0;
  position: relative;
  gap: 4px;
}
#map { flex: 1; min-height: 0; position: relative; }
#map svg {
  width: 100%;
  height: 100%;
  display: block;
  background: #0a1738;
  border-radius: 12px;
  border: 1px solid var(--line);
}
#map svg.draw { cursor: crosshair; }
.ocean { fill: #0a1738; }
.graticule line { stroke: #16203f; stroke-width: .5; }
.land { fill: #22304f; stroke: #3a4a75; stroke-width: .6; }
#region-rect {
  fill: rgba(94, 234, 212, .1);
  stroke: var(--accent);
  stroke-width: 1;
  stroke-dasharray: 5 3;
  pointer-events: none;
}
.event-marker {
  cursor: pointer;
  stroke: #ffffff;
  stroke-width: .5;
  fill: #f97316;
  fill-opacity: .9;
  transform-box: fill-box;
  transform-origin: center;
  animation: pulse 1.6s ease-in-out infinite;
}
.event-marker.cat-science { fill: #5eead4; }
.event-marker.cat-economy { fill: #facc15; }
.event-marker.cat-religion { fill: #c084fc; }
.event-marker.cat-politics { fill: #60a5fa; }
.event-marker.cat-wars { fill: #f87171; }
@keyframes pulse {
  0%, 100% { opacity: .55; transform: scale(.75); }
  50% { opacity: 1; transform: scale(1.4); }
}
#event-detail {
  display: none;
  position: absolute;
  top: 34px;
  right: 12px;
  z-index: 10;
  width: min(400px, 85%);
  max-height: 82%;
  overflow: auto;
  background: rgba(13, 19, 38, .97);
  border: 1px solid var(--accent);
  border-radius: 12px;
  padding: 14px 16px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .5);
}
#event-detail.open { display: block; }
#event-detail h3 { margin: 2px 24px 6px 0; font-size: 17px; }
#event-detail .meta { color: var(--accent); font-size: 13px; margin: 0 0 8px; }
#event-detail .close {
  position: absolute;
  top: 8px;
  right: 10px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 18px;
  cursor: pointer;
}
#wiki-article p { color: #cdd5ec; font-size: 14px; line-height: 1.5; }
#headlines-section {
  flex: 2;
  min-height: 130px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
#headlines {
  flex: 1;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.headline {
  display: flex;
  gap: 10px;
  align-items: baseline;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 14px;
}
.hl-year {
  color: var(--accent);
  font-weight: 700;
  min-width: 44px;
  font-variant-numeric: tabular-nums;
}
.hl-cat { color: var(--muted); font-size: 12px; white-space: nowrap; }
.quiet { color: var(--muted); font-style: italic; }
.loading { color: var(--muted); }
