* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               Helvetica, Arial, sans-serif;
}

#maps { position: fixed; inset: 0; }
.map-wrap { position: absolute; inset: 0; }
.map { position: absolute; inset: 0; }
.hidden { display: none !important; }

#divider {
  position: absolute; top: 0; bottom: 0; width: 4px; margin-left: -2px;
  background: #222; cursor: ew-resize; z-index: 20; touch-action: none;
}
#divider-handle {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  background: #222; color: #fff; border-radius: 999px;
  padding: 6px 10px; font-size: 14px; user-select: none;
}

#titlebar {
  position: fixed; top: 10px; left: 10px; z-index: 30;
  background: rgba(255, 255, 255, 0.92); border-radius: 6px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
  padding: 8px 14px; max-width: 340px;
}
#titlebar h1 { margin: 0; font-size: 18px; }
#titlebar #title-year { color: #b5432c; }
#titlebar p { margin: 2px 0 0; font-size: 12px; color: #444; }
#titlebar a { color: #2b5fa5; text-decoration: none; }
#titlebar a:hover { text-decoration: underline; }

#controls {
  position: fixed; top: 10px; right: 50px; z-index: 30;
  display: flex; gap: 10px; align-items: center;
  background: rgba(255, 255, 255, 0.92); border-radius: 6px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
  padding: 6px 12px; font-size: 13px;
}
#controls label { display: flex; gap: 6px; align-items: center; color: #333; }
#controls input[type="range"] { width: 110px; }
#compare-btn {
  border: 1px solid #999; background: #fff; border-radius: 4px;
  padding: 3px 10px; font-size: 13px; cursor: pointer;
}
#compare-btn.active { background: #2b5fa5; color: #fff; border-color: #2b5fa5; }

#compare-years {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  z-index: 30; display: flex; gap: 8px; align-items: center;
  background: rgba(255, 255, 255, 0.95); border-radius: 6px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
  padding: 8px 14px; font-size: 14px;
}
#compare-years select { font-size: 15px; padding: 2px 4px; }

#timeline {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%);
  z-index: 30; width: min(860px, 92vw); height: 46px;
  background: rgba(255, 255, 255, 0.92); border-radius: 8px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
}
#timeline::before {
  content: ""; position: absolute; left: 3%; right: 3%; top: 50%;
  border-top: 2px solid #ccc;
}
.tl-dot {
  position: absolute; top: 50%; transform: translate(-50%, -50%);
  width: 13px; height: 13px; border-radius: 50%;
  border: 2px solid #666; background: #fff; cursor: pointer; padding: 0;
}
.tl-dot:hover { border-color: #b5432c; }
.tl-dot.active { background: #b5432c; border-color: #b5432c; }
.tl-dot span {
  position: absolute; top: -20px; left: 50%; transform: translateX(-50%);
  font-size: 11px; color: #555; display: none; white-space: nowrap;
}
.tl-dot.active span, .tl-dot:hover span { display: block; font-weight: 600; }
.tl-dot.active span { color: #b5432c; }

#legend {
  position: fixed; bottom: 82px; left: 10px; z-index: 30;
  background: rgba(255, 255, 255, 0.94); border-radius: 6px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
  max-width: 250px; font-size: 12px;
}
#legend:has(.lg-block:nth-child(2)) { max-width: 400px; }
#legend-head {
  display: block; width: 100%; text-align: left; cursor: pointer;
  border: 0; background: none; font: inherit; font-weight: 600;
  padding: 7px 10px; color: #333;
}
#legend-arrow { float: right; color: #888; }
#legend-body {
  padding: 0 10px 8px; max-height: 42vh; overflow-y: auto;
  display: flex; gap: 14px;
}
#legend.collapsed #legend-body { display: none; }
.lg-block { min-width: 0; }
.lg-year { font-weight: 600; color: #b5432c; margin: 2px 0 4px; }
.lg-block:only-child .lg-year { display: none; }
.lg-row {
  display: flex; align-items: center; gap: 6px;
  padding: 1.5px 0; color: #333; line-height: 1.25;
}
.chip {
  width: 13px; height: 13px; border-radius: 3px; flex: none;
  border: 1px solid rgba(0, 0, 0, 0.25);
}
.chip-none {
  background:
    repeating-linear-gradient(45deg, #eee 0 3px, #ccc 3px 6px);
}

#history {
  position: fixed; top: 70px; right: 10px; bottom: 82px; z-index: 31;
  width: min(320px, 86vw);
  background: rgba(255, 255, 255, 0.97); border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
  display: flex; flex-direction: column;
}
#history-head {
  display: flex; justify-content: space-between; align-items: start;
  padding: 10px 12px 6px; border-bottom: 1px solid #e3e3e3;
}
#history-head strong { font-size: 14px; }
#history-sub { font-size: 11px; color: #777; }
#history-close {
  border: 0; background: none; font-size: 22px; line-height: 1;
  color: #888; cursor: pointer; padding: 0 2px;
}
#history-close:hover { color: #222; }
#history-body { overflow-y: auto; padding: 6px 8px 10px; }
.h-row {
  display: flex; align-items: center; gap: 8px;
  padding: 3px 6px; border-radius: 5px; cursor: pointer;
  font-size: 12.5px; color: #333;
}
.h-row:hover { background: #eef3fb; }
.h-row.current { background: #e4edfb; font-weight: 600; }
.h-year { font-variant-numeric: tabular-nums; color: #666; flex: none; }
.h-row.current .h-year { color: #2b5fa5; }
.h-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

@media (max-width: 700px) {
  #titlebar { max-width: 240px; }
  #titlebar p { display: none; }
  #controls { top: auto; bottom: 80px; right: 10px; }
  #legend { bottom: 130px; max-width: 200px; }
  #history { top: auto; bottom: 130px; max-height: 45vh; }
}
