.history-page {
  color-scheme: light;
  --surface: #ffffff;
  --surface-soft: #f8faf8;
  --border: #dfe8e2;
  --border-strong: #b9ccc0;
  --ink: #172420;
  --muted: #65766d;
  --accent: #176249;
  --accent-soft: #eaf4ee;
  margin: 0;
  color: var(--ink);
  background: #ffffff;
}

.history-page .atlas-header {
  background: #ffffff;
}

.history-page .atlas-main {
  padding-top: 34px;
}

.map-title {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: end;
  margin-bottom: 22px;
}

.map-title h1 {
  margin: 7px 0 0;
  font-size: clamp(28px, 4vw, 46px);
  letter-spacing: -0.04em;
}

.map-title > p {
  max-width: 360px;
  margin: 0 0 4px;
  color: var(--muted);
  line-height: 1.8;
}

.timeline-control {
  padding: 17px 19px 14px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: 0 8px 28px rgba(43, 74, 59, 0.05);
}

.timeline-meta {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
}

.timeline-meta .eyebrow {
  margin: 0;
}

#timelineValue {
  color: var(--accent);
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.timeline-track-wrap {
  padding: 4px 2px 0;
}

#timelineRange {
  display: block;
  width: 100%;
  margin: 8px 0 0;
  accent-color: var(--accent);
  cursor: ew-resize;
}

.timeline-ticks {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: #73827b;
  font-size: 11px;
  line-height: 1.4;
}

.timeline-ticks span {
  min-width: 0;
  white-space: nowrap;
}

.timeline-ticks span:last-child {
  text-align: right;
}

.timeline-help {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.periods {
  display: flex;
  flex-wrap: nowrap;
  gap: 8px;
  overflow-x: auto;
  overflow-y: hidden;
  margin: 12px 0 18px;
  padding-bottom: 4px;
}

.periods button {
  min-height: 32px;
  padding: 5px 11px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  background: #ffffff;
  cursor: pointer;
  transition: border-color 180ms ease, color 180ms ease, background 180ms ease;
}

.periods button:hover,
.periods button:focus-visible {
  border-color: var(--border-strong);
  color: var(--accent);
  outline: none;
}

.periods button.active {
  border-color: #b5d3c1;
  color: var(--accent);
  background: var(--accent-soft);
  font-weight: 700;
}

.history-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.68fr) minmax(300px, 0.72fr);
  gap: 18px;
  align-items: start;
}

.map-panel,
.event-panel {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: 0 10px 30px rgba(43, 74, 59, 0.05);
}

.map-panel {
  overflow: hidden;
}

.map-scroll {
  overflow: auto;
  background: var(--surface-soft);
  border-bottom: 1px solid var(--border);
}

#historyMap {
  display: block;
  width: 100%;
  min-width: 760px;
  height: auto;
}

.map-canvas {
  fill: #fbfcfb;
}

.historical-polity {
  fill-opacity: 0.28;
  stroke-width: 1.45;
  vector-effect: non-scaling-stroke;
  transition: opacity 320ms ease, fill 320ms ease;
}

.historical-polity.main {
  fill: #5d8876;
  stroke: #35624f;
}

.historical-polity.rival {
  fill: #d38778;
  stroke: #a95f52;
  stroke-dasharray: 5 2;
}

.historical-polity.protectorate {
  fill: #c2a05a;
  stroke: #977a38;
  stroke-dasharray: 2 3;
}

.historical-region {
  fill: rgba(255, 255, 255, 0.24);
  stroke: #60766b;
  stroke-width: 0.95;
  vector-effect: non-scaling-stroke;
  transition: opacity 320ms ease, fill 320ms ease, stroke 320ms ease;
}

.historical-region:hover,
.historical-region:focus-visible {
  fill: #e7f2eb;
  stroke: var(--accent);
  stroke-width: 1.5;
  outline: none;
}

.region-label {
  fill: #30483d;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.02em;
  paint-order: stroke;
  stroke: rgba(255, 255, 255, 0.92);
  stroke-width: 3px;
  stroke-linejoin: round;
  pointer-events: none;
}

.polity-label {
  pointer-events: none;
}

.polity-label rect {
  fill: rgba(255, 255, 255, 0.96);
  stroke-width: 1.2;
  vector-effect: non-scaling-stroke;
}

.polity-label.main rect {
  stroke: #35624f;
}

.polity-label.rival rect {
  stroke: #a95f52;
}

.polity-label.protectorate rect {
  stroke: #977a38;
}

.polity-label-role {
  fill: #687870;
  font-size: 8px;
  font-weight: 700;
}

.polity-label-name {
  fill: #1f3028;
  font-size: 10px;
  font-weight: 800;
}

.polity-connector {
  fill: none;
  stroke-width: 1.15;
  stroke-dasharray: 5 4;
  vector-effect: non-scaling-stroke;
}

.polity-connector.main {
  stroke: #35624f;
}

.polity-connector.rival {
  stroke: #a95f52;
}

.polity-connector.protectorate {
  stroke: #977a38;
  stroke-dasharray: 2 3;
}

#polities,
#areas,
#regionLabels,
#polityLabels,
#places {
  transform-box: fill-box;
  transform-origin: center;
  transition: opacity 220ms ease, transform 220ms ease;
}

#polities.is-swapping,
#areas.is-swapping,
#regionLabels.is-swapping,
#polityLabels.is-swapping,
#places.is-swapping {
  opacity: 0;
  transform: scale(0.985);
}

.place {
  cursor: pointer;
  outline: none;
}

.place circle {
  fill: #ffffff;
  stroke: var(--accent);
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
  transition: fill 180ms ease, stroke 180ms ease, r 180ms ease;
}

.place-label-bg {
  fill: rgba(255, 255, 255, 0.94);
  stroke: #cddbd2;
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}

.place text {
  fill: #22352d;
  font-size: 13px;
  font-weight: 700;
  paint-order: stroke;
  stroke: #ffffff;
  stroke-width: 3px;
  stroke-linejoin: round;
}

.place.selected circle,
.place:hover circle,
.place:focus-visible circle {
  fill: #f4c76d;
  stroke: #26392f;
  stroke-width: 2.5;
}

.place.selected text {
  fill: var(--accent);
}

.map-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 9px 16px;
  margin: 0;
  padding: 14px 18px 4px;
  list-style: none;
}

.map-legend li {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
}

.legend-swatch {
  width: 10px;
  height: 10px;
  border-radius: 3px;
}

.legend-swatch.main {
  background: #5d8876;
}

.legend-swatch.rival {
  background: #d38778;
}

.legend-swatch.protectorate {
  background: #c2a05a;
}

.map-note,
#mapStatus {
  margin: 10px 18px 16px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.7;
}

#mapStatus:empty {
  display: none;
}

.map-note a,
.history-source,
.event-detail a {
  color: var(--accent);
}

.event-panel {
  padding: 22px;
}

.period-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.period-head .eyebrow {
  margin: 0;
}

.year-nav {
  display: flex;
  gap: 6px;
}

.year-nav button {
  padding: 6px 9px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--accent);
  background: #ffffff;
  font-size: 12px;
  cursor: pointer;
  transition: border-color 180ms ease, background 180ms ease, opacity 180ms ease;
}

.year-nav button:hover:not(:disabled),
.year-nav button:focus-visible {
  border-color: var(--border-strong);
  background: var(--accent-soft);
  outline: none;
}

.year-nav button:disabled {
  cursor: not-allowed;
  opacity: 0.4;
}

.event-panel h2 {
  margin: 6px 0 8px;
  font-size: 25px;
  letter-spacing: -0.03em;
}

.event-panel > .muted {
  margin: 0;
  color: var(--muted);
  line-height: 1.75;
}

.event-list {
  display: grid;
  gap: 8px;
  margin: 21px 0;
}

.event-list button {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--muted);
  background: #ffffff;
  text-align: left;
  cursor: pointer;
  transition: border-color 180ms ease, color 180ms ease, background 180ms ease, transform 180ms ease;
}

.event-list button:hover,
.event-list button:focus-visible {
  border-color: var(--border-strong);
  color: var(--ink);
  outline: none;
  transform: translateX(2px);
}

.event-list button.active {
  border-color: #b5d3c1;
  color: var(--accent);
  background: var(--accent-soft);
  font-weight: 700;
}

.event-detail {
  margin-top: 8px;
  padding: 17px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-soft);
}

.event-detail h3 {
  margin: 6px 0 8px;
  font-size: 18px;
}

.event-detail p:not(.eyebrow) {
  margin: 0 0 13px;
  color: var(--muted);
  line-height: 1.75;
}

.event-detail a {
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
}

.history-source {
  display: inline-block;
  margin-top: 17px;
  font-size: 12px;
}

@media (max-width: 900px) {
  .map-title {
    display: block;
  }

  .map-title > p {
    margin-top: 10px;
  }

  .history-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .history-page .atlas-main {
    padding-top: 24px;
  }

  .map-title h1 {
    font-size: 30px;
  }

  .timeline-ticks {
    font-size: 10px;
  }

  .timeline-ticks span:nth-child(even) {
    display: none;
  }

  .event-panel {
    padding: 18px;
  }
}
