/* an old printed atlas: paper sea, muted realm tints, blue ink for water and accents */
:root {
  --bg: #dae3df; --ink: #2b261e; --muted: #7c7466;
  --line: rgba(74, 58, 38, .3); --land: #ece2cc; --accent: #1f4e9c;
  --coast: rgba(36, 82, 128, .42); --river: rgba(36, 82, 128, .6); --halo: rgba(250, 245, 235, .65);
  --panel: rgba(248, 243, 232, .95); --space: #ebe5d7;
  --realm-0: #e7cc9f; --realm-1: #ddbcaa; --realm-2: #c9d3a9; --realm-3: #bfd0cc; --realm-4: #e5d79f;
  --realm-5: #d6c4d4; --realm-6: #cfbd9a; --realm-7: #e7c0a3; --realm-8: #bacbb0; --realm-9: #d9c8a6;
  --serif: "EB Garamond", "Iowan Old Style", Georgia, serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #172025; --ink: #ece2cd; --muted: #928a7a;
    --line: rgba(236, 226, 205, .2); --land: #2e2a22; --accent: #86abe6;
    --coast: rgba(150, 186, 220, .3); --river: rgba(150, 186, 220, .5); --halo: rgba(27, 25, 21, .6);
    --panel: rgba(31, 28, 23, .95); --space: #12110f;
    --realm-0: #5b4a30; --realm-1: #59413b; --realm-2: #46503a; --realm-3: #3b4d4c; --realm-4: #57522f;
    --realm-5: #4c4150; --realm-6: #4e4431; --realm-7: #5c4433; --realm-8: #3d4d3d; --realm-9: #4f4637;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  background: var(--bg); color: var(--ink);
  font: 15px/1.4 var(--serif);
  /* dragging the timeline or the map shouldn't select text; the card is the exception */
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent;
}
canvas { position: fixed; inset: 0; width: 100%; height: 100%; cursor: grab; touch-action: none; }
canvas.dragging { cursor: grabbing; }

/* paper grain and a printer's vignette over the map, under the controls */
body::after {
  content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 1;
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .35 0 0 0 0 .27 0 0 0 0 .17 0 0 0 .55 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E"),
    radial-gradient(ellipse at 50% 45%, transparent 55%, rgba(40, 50, 45, .14));
  opacity: .45;
}
@media (prefers-color-scheme: dark) {
  body::after { opacity: .35; }
}
#notes, #hover, #top, #card, footer { z-index: 2; }

/* the globe (globe.js) is drawn under the map canvas, which carries its labels and pins */
#globe { display: none; }
body.globe #globe { display: block; }
body.globe { background: var(--space); }
body.globe footer { background: linear-gradient(transparent, var(--space) 45%); }

#hover {
  position: fixed; top: 16px; left: 18px; pointer-events: none;
  font-size: 16px; font-style: italic; color: var(--muted);
}

#top {
  position: fixed; top: max(14px, env(safe-area-inset-top)); right: max(16px, env(safe-area-inset-right));
  display: flex; gap: 8px;
}
#top > * {
  height: 34px; padding: 0 14px; display: flex; align-items: center; gap: 8px;
  border: 1px solid var(--line); border-radius: 3px; background: var(--panel); color: var(--ink);
  text-decoration: none; font: 13px/1 var(--serif); letter-spacing: .08em; text-transform: uppercase; cursor: pointer;
}
#top > *:hover { border-color: var(--muted); }
#top > *:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
#top > [hidden] { display: none; }
#top svg { width: 15px; height: 15px; fill: currentColor; }
#globe-toggle svg { fill: none; stroke: currentColor; stroke-width: 1.2; }
#globe-toggle[aria-pressed="true"] { color: var(--accent); border-color: var(--accent); }

#card {
  -webkit-user-select: text; user-select: text;
  position: fixed; top: 60px; right: 16px; width: min(350px, calc(100vw - 32px));
  max-height: calc(100vh - 170px); max-height: calc(100dvh - 170px); overflow: auto; overscroll-behavior: contain;
  background: var(--panel); border: 1px solid var(--line); border-radius: 4px;
  box-shadow: 0 1px 0 var(--line), 0 10px 30px rgba(60, 40, 15, .14);
}
#card img {
  display: block; width: 100%; max-height: 200px; object-fit: cover;
  background: var(--line); border-bottom: 1px solid var(--line); filter: sepia(.15);
}
#card .body { padding: 14px 18px 16px; }
#card h2 { margin: 2px 26px 8px 0; font-size: 23px; font-weight: 500; line-height: 1.15; }
#card .meta { margin: 0; color: var(--muted); font-size: 14px; font-style: italic; }
#card .desc {
  margin: 0 0 10px; font-size: 16px; line-height: 1.45; hyphens: auto;
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 8; line-clamp: 8; overflow: hidden;
}
#card .desc:empty { display: none; }
#card .desc.loading { color: var(--muted); font-style: italic; }
#card .wiki { color: var(--accent); text-decoration: none; font-size: 15px; font-style: italic; }
#card .wiki:hover { text-decoration: underline; }
#card .related-wrap { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); }
#card .related-title { margin: 0 0 4px; color: var(--muted); font-size: 13px; font-style: italic; }
#card .related { margin: 0; padding: 0; list-style: none; }
#card .related button {
  display: block; width: 100%; padding: 4px 0; border: 0; background: none; text-align: left;
  color: var(--ink); font: 15px/1.3 var(--serif); cursor: pointer;
}
#card .related button:hover { color: var(--accent); }
#card .related small { color: var(--muted); font-style: italic; font-size: 13px; margin-right: 4px; font-feature-settings: "onum"; }

#close {
  position: absolute; top: 8px; right: 8px; width: 28px; height: 28px; border: 0; border-radius: 50%;
  background: var(--panel); color: var(--muted); font: 20px/1 var(--serif); cursor: pointer;
}
#close:hover { color: var(--ink); }

footer {
  position: fixed; left: 0; right: 0; bottom: 0;
  padding: 14px max(18px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
  display: flex; align-items: center; gap: 18px;
  background: linear-gradient(transparent, var(--bg) 45%);
}
#controls { display: flex; gap: 6px; }
#controls button {
  height: 34px; min-width: 34px; padding: 0 10px; display: grid; place-items: center;
  border: 1px solid var(--line); border-radius: 50%; background: var(--panel); color: var(--ink);
  font: italic 15px/1 var(--serif); cursor: pointer;
}
#controls #speed { border-radius: 17px; min-width: 48px; }
#controls button:hover { border-color: var(--muted); }
#controls button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
#play svg { width: 13px; height: 13px; fill: currentColor; }
#play .i-pause, #play[aria-pressed="true"] .i-play { display: none; }
#play[aria-pressed="true"] .i-pause { display: inline; }
#play[aria-pressed="true"] { color: var(--accent); border-color: var(--accent); }

#year {
  min-width: 150px; font-size: 32px; font-weight: 400; line-height: 1;
  font-feature-settings: "onum", "pnum"; letter-spacing: .01em;
}
#track { position: relative; flex: 1; height: 38px; cursor: pointer; outline: none; }
#track::before {
  content: ""; position: absolute; left: 0; right: 0; top: 50%; height: 1px; background: var(--line);
}
#ticks .era {
  position: absolute; bottom: -6px; font-size: 13px; font-style: italic; color: var(--muted);
  transform: translateX(-50%); font-feature-settings: "onum";
}
#ticks .era.start { transform: none; }
#handle {
  position: absolute; top: 5px; bottom: 5px; width: 2px; margin-left: -1px; background: var(--accent);
}
#handle::before { /* a small diamond, like a scale marker */
  content: ""; position: absolute; left: 50%; top: 50%; width: 8px; height: 8px;
  background: var(--accent); transform: translate(-50%, -50%) rotate(45deg);
}
#track:focus-visible #handle { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 30%, transparent); }

/* notifications: a ping on the spot and a bubble near it (placed by placeNotes) */
#notes { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
.note { position: absolute; left: 0; top: 0; transition: opacity .4s; }
.note.out { opacity: 0; }
.note .ping {
  position: absolute; left: -9px; top: -9px; width: 18px; height: 18px; border-radius: 50%;
  border: 1.5px solid var(--accent); animation: ping 1.4s ease-out 3 both;
}
@keyframes ping { from { transform: scale(.4); opacity: 1; } to { transform: scale(2.6); opacity: 0; } }
.note .bubble {
  position: absolute; left: 0; top: 0; max-width: 250px; width: max-content;
  padding: 6px 12px 8px; text-align: left; cursor: pointer; pointer-events: auto;
  background: var(--panel); color: var(--ink); border: 1px solid var(--line);
  border-top: 2px solid var(--accent); border-radius: 3px;
  font: inherit; box-shadow: 0 3px 10px rgba(60, 40, 15, .12);
  animation: appear .3s ease-out both;
}
.note .leader {
  position: absolute; left: 0; top: 0; height: 1px; background: var(--accent); opacity: .5;
  transform-origin: 0 50%; pointer-events: none;
}
.note.paused .ping, .note.paused .bubble { animation-play-state: paused; }
.note .bubble small { display: block; color: var(--muted); font-size: 13px; font-style: italic; }
.note .bubble b { display: block; font-size: 16px; font-weight: 500; line-height: 1.2; }
/* notes grow from their centre, so they never poke past where they'll settle */
@keyframes appear { from { opacity: 0; scale: .96; } }
@media (prefers-reduced-motion: reduce) {
  .note .ping { animation: none; opacity: .6; }
  .note .bubble { animation: none; }
}

@media (max-width: 600px) {
  footer { flex-wrap: wrap; gap: 6px 12px; padding-top: 24px; }
  #track { flex-basis: 100%; height: 44px; } /* a comfortable thumb target */
  #year { font-size: 28px; min-width: 0; }
  #ticks .minor { display: none; }
  #controls button { height: 40px; min-width: 40px; }
  #controls #speed { min-width: 52px; border-radius: 20px; }
  #hover { display: none; } /* hover names don't exist on touch */
  #top > * { height: 32px; padding: 0 10px; font-size: 12px; }
  #card { top: auto; bottom: 150px; left: 12px; right: 12px; width: auto; max-height: 55vh; max-height: 55dvh; }
  #card img { max-height: 150px; }
  #card h2 { font-size: 21px; }
  .note .bubble { max-width: min(230px, 70vw); }
  .note .bubble b { font-size: 15px; }
}
