/* History: a timeline beside a map that grows as you scroll. */

.history-head { padding-bottom: 28px; }
@media (min-width: 900px) { .history-head { padding-bottom: 48px; } }

:root {
  --map-bg: #fbf9f4;
  --map-grid: rgb(20 24 58 / 0.05);
  --map-river: #5c8fe6;
  --map-area: rgb(255 181 71 / 0.16);
  --map-area-line: rgb(214 128 20 / 0.32);
  --map-quarter: #e8963a;
  --map-road: #3b4063;
  --map-rail: #7b809c;
  --map-label: #464b69;
  --map-l1: #2d5bff;
  --map-l3: #1f9d5a;
  --map-ash: rgb(120 112 104 / 0.24);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --map-bg: #0f1a40;
    --map-grid: rgb(195 203 232 / 0.05);
    --map-river: #3de0ff;
    --map-area: rgb(255 181 71 / 0.1);
    --map-area-line: rgb(255 181 71 / 0.3);
    --map-quarter: #ffb547;
    --map-road: #dfe4f7;
    --map-rail: #8d97c2;
    --map-label: #c3cbe8;
    --map-l1: #6f8dff;
    --map-l3: #4ade80;
    --map-ash: rgb(160 150 140 / 0.16);
  }
}
:root[data-theme="dark"] {
  --map-bg: #0f1a40;
  --map-grid: rgb(195 203 232 / 0.05);
  --map-river: #3de0ff;
  --map-area: rgb(255 181 71 / 0.1);
  --map-area-line: rgb(255 181 71 / 0.3);
  --map-quarter: #ffb547;
  --map-road: #dfe4f7;
  --map-rail: #8d97c2;
  --map-label: #c3cbe8;
  --map-l1: #6f8dff;
  --map-l3: #4ade80;
  --map-ash: rgb(160 150 140 / 0.16);
}

.history-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  padding-bottom: 40px;
}
@media (min-width: 960px) {
  .history-body {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr);
    column-gap: clamp(40px, 6vw, 96px);
  }
}

/* ---------- the map panel ---------- */

.map-panel {
  position: sticky;
  top: 60px;
  z-index: 5;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 156px;
  align-items: center;
  gap: 12px;
  margin-inline: calc(var(--gutter) * -1);
  padding: 10px var(--gutter);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.map-now { min-width: 0; }
.map-year {
  font-family: var(--font-head);
  font-weight: 800;
  font-size: 34px;
  line-height: 1;
  letter-spacing: -0.03em;
  color: var(--link);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.map-era {
  margin-top: 8px;
  font-weight: 700;
  font-size: 15px;
  line-height: 1.3;
  color: var(--ink-2);
}
.city-map { width: 100%; height: auto; display: block; overflow: visible; }

@media (max-width: 380px) {
  .map-panel { grid-template-columns: minmax(0, 1fr) 136px; }
  .map-year { font-size: 30px; }
}

@media (min-width: 960px) {
  .map-panel {
    grid-column: 2;
    grid-row: 1;
    align-self: start;
    top: 84px;
    display: block;
    margin: 0;
    padding: 0;
    background: none;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    border: 0;
  }
  .map-now { margin: 0 0 18px 4px; min-height: 96px; }
  .map-year { font-size: 56px; }
  .map-era { font-size: 17px; }
  .city-map {
    max-height: calc(100svh - 240px);
    filter: drop-shadow(0 24px 40px rgb(0 0 0 / 0.18));
  }
}

/* map drawing */
.map-bg { fill: var(--map-bg); stroke: var(--card-line); stroke-width: 1.5; }
.map-grid path { stroke: var(--map-grid); stroke-width: 1; fill: none; }
.area { fill: var(--map-area); stroke: var(--map-area-line); stroke-width: 1; stroke-dasharray: 3 3; }
.river { fill: none; stroke: var(--map-river); stroke-width: 7; stroke-linecap: round; opacity: 0.75; }
.river.small { stroke-width: 3.2; }
.lake { fill: var(--map-river); opacity: 0.55; }
.castle { fill: var(--map-quarter); stroke: var(--map-bg); stroke-width: 1.5; }
.quarter { fill: var(--map-quarter); opacity: 0.55; }
.quarter-hi { fill: none; stroke: var(--map-quarter); stroke-width: 2.5; }
.dot { fill: var(--map-quarter); }
.landmark { fill: var(--map-road); }
.street, .avenue { fill: none; stroke: var(--map-road); stroke-linecap: round; }
.street { stroke-width: 2.4; }
.avenue { stroke-width: 4; }
.rail { fill: none; stroke: var(--map-rail); stroke-width: 2; stroke-dasharray: 1; }
.station { fill: var(--map-road); }
.gates rect { fill: var(--map-road); }
.ring { fill: none; stroke: var(--map-road); stroke-width: 1.6; opacity: 0.5; }
.district rect { fill: var(--map-area-line); }
.metro path { fill: none; stroke-width: 3.6; stroke-linecap: round; stroke-linejoin: round; }
.metro circle { stroke-width: 2; fill: var(--map-bg); }
.l1 path, .l1 circle { stroke: var(--map-l1); }
.l3 path, .l3 circle { stroke: var(--map-l3); }
.library path { fill: var(--cyan); stroke: var(--map-l1); stroke-width: 1; filter: drop-shadow(0 0 5px var(--cyan)); }
.label {
  font-family: var(--font-body);
  font-size: 11px;
  font-weight: 700;
  fill: var(--map-label);
  paint-order: stroke;
  stroke: var(--map-bg);
  stroke-width: 3px;
  stroke-linejoin: round;
}
.river-label { font-style: italic; fill: var(--map-river); }
.metro-label { fill: var(--map-l1); }
.metro-label.l3 { fill: var(--map-l3); stroke: var(--map-bg); }
@media (max-width: 959px) { .map-labels { display: none; } }

/* growth: groups appear once their moment is reached; lines draw themselves */
.js .m { transition: opacity 0.8s var(--ease-out); }
.js .m:not(.on) { opacity: 0; }
.js .draw { stroke-dasharray: 1; stroke-dashoffset: 0; transition: stroke-dashoffset 1.6s var(--ease-out); }
.js .m:not(.on).draw, .js .m:not(.on) .draw { stroke-dashoffset: 1; }
.rail.draw { stroke-dasharray: 0.012 0.008; }
.js .m:not(.on) .rail.draw { stroke-dashoffset: 0; }
.m.now .castle, .castle.m.now, .m.now.dot, .m.now .quarter-hi, .m.now.landmark, .m.now.library, .m.now .library {
  animation: pulse 1.6s ease-in-out 2;
}
@keyframes pulse { 50% { opacity: 0.35; } }
.city-map .area, .city-map .river, .city-map .quarter, .city-map .castle { transition: fill 0.8s ease, stroke 0.8s ease, opacity 0.8s ease; }
.city-map.ash .area { fill: var(--map-ash); stroke: var(--map-ash); }
.city-map.ash .quarter, .city-map.ash .castle, .city-map.ash .dot { fill: var(--map-rail); opacity: 0.35; }
.city-map.ash .street { opacity: 0.3; }
@media (prefers-reduced-motion: reduce) {
  .js .m, .js .draw, .city-map * { transition: none !important; animation: none !important; }
}

/* ---------- the timeline ---------- */

.timeline {
  list-style: none;
  margin: 0;
  padding: 24px 0 0 26px;
  position: relative;
  counter-reset: none;
}
.timeline::before {
  content: "";
  position: absolute;
  left: 5px;
  top: 30px;
  bottom: 0;
  width: 2px;
  border-radius: 2px;
  background: var(--line);
}
.timeline::after {
  content: "";
  position: absolute;
  left: 5px;
  top: 30px;
  width: 2px;
  height: var(--progress, 0px);
  border-radius: 2px;
  background: linear-gradient(var(--link), var(--amber));
  box-shadow: 0 0 10px var(--glow);
}
@media (min-width: 960px) { .timeline { grid-column: 1; grid-row: 1; padding-top: 12px; padding-left: 40px; } .timeline::before, .timeline::after { left: 9px; } }

.moment {
  position: relative;
  padding: 40px 0 44px;
  scroll-margin-top: 280px;
}
@media (min-width: 960px) { .moment { padding: 64px 0 72px; min-height: 52svh; scroll-margin-top: 120px; } }
.moment::before {
  content: "";
  position: absolute;
  left: -26px;
  top: 52px;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--bg);
  border: 2px solid var(--line-strong);
  transition: border-color 0.4s ease, background 0.4s ease, box-shadow 0.4s ease;
}
@media (min-width: 960px) { .moment::before { left: -36px; top: 82px; width: 14px; height: 14px; } }
.moment.passed::before { border-color: var(--link); background: var(--link); }
.moment.active::before { border-color: var(--amber); background: var(--amber); box-shadow: 0 0 0 6px rgb(255 181 71 / 0.18), 0 0 18px var(--amber); }

.moment-year {
  font-family: var(--font-head);
  font-weight: 800;
  font-size: clamp(30px, 8vw, 48px);
  letter-spacing: -0.03em;
  line-height: 1;
  color: var(--link);
  font-variant-numeric: tabular-nums;
  transition: color 0.4s ease;
}
.moment:not(.active):not(.passed) .moment-year { color: var(--ink-3); }
.moment h2 { margin-top: 12px; font-size: clamp(21px, 5.2vw, 30px); line-height: 1.2; }
.moment > p:not(.moment-year):not(.maps-row):not(.moment-src) {
  margin-top: 12px;
  color: var(--ink-2);
  font-size: 17px;
  line-height: 1.6;
  max-width: 56ch;
}
@media (min-width: 960px) { .moment > p:not(.moment-year):not(.maps-row):not(.moment-src) { font-size: 18px; } }
.moment .maps-row { display: flex; flex-wrap: wrap; gap: 8px 20px; margin-top: 16px; }
.moment-src {
  margin-top: 14px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--ink-3);
}
.moment-src span { font-weight: 800; letter-spacing: 0.1em; text-transform: uppercase; font-size: 11px; margin-right: 6px; }
.moment-src a { color: var(--ink-3); text-underline-offset: 2px; }
.moment-src a:hover { color: var(--link); }

.moment-photo { margin: 22px 0 0; max-width: 560px; }
.moment-photo img {
  width: 100%;
  height: auto;
  aspect-ratio: 3 / 2;
  object-fit: cover;
  border-radius: 16px;
  background: var(--bg-sunk);
  box-shadow: var(--shadow);
}

/* hard chapters: told plainly, in a quieter key */
.moment.hard .moment-year { color: var(--ink-2); }
.moment.hard.active::before { border-color: var(--ink-2); background: var(--ink-2); box-shadow: none; }
.moment.hard .moment-photo img { filter: grayscale(1) contrast(1.05); }

.history-end { padding: 72px var(--gutter) 112px; display: grid; gap: 16px; justify-items: start; }
.history-end h2 { font-size: clamp(30px, 7.6vw, 56px); }
.history-end p { color: var(--ink-2); font-size: 18px; max-width: 560px; }
.history-end-actions { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 8px; }
