/* the world timeline's old printed atlas: paper, blue ink for water and accents, and the
   controls floating over the globe on soft paper panels */
:root {
  --bg: #dae3df; --ink: #2b261e; --muted: #7c7466;
  --line: rgba(74, 58, 38, .3); --accent: #1f4e9c;
  --panel: rgba(248, 243, 232, .97); --space: #ebe5d7; --badge: #f8f3e8;
  --serif: "EB Garamond", "Iowan Old Style", Georgia, serif;
  /* how close a guess was: the dots on the panel */
  --good: #2f7d3b; --close: #a77408; --far: #c2531c; --off: #9b2a2a;
  /* the eras along the timeline: bronze, iron, terracotta, olive, sea blue, plum, rose */
  --era-0: #b07d34; --era-1: #6f7c88; --era-2: #b5553a; --era-3: #5f7d3a; --era-4: #2e6e93; --era-5: #7b4f8e; --era-6: #b8436a;
  --edge: rgba(74, 58, 38, .14); --hover: rgba(74, 58, 38, .07); --on-accent: #fbf8f1;
  --lift: 0 1px 2px rgba(60, 40, 15, .07), 0 6px 18px rgba(60, 40, 15, .1);
  --float: 0 2px 6px rgba(60, 40, 15, .08), 0 16px 40px rgba(60, 40, 15, .17);
  /* where the panel stands: on the dock */
  --stack: 112px; --head: 72px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #172025; --ink: #ece2cd; --muted: #928a7a;
    --line: rgba(236, 226, 205, .2); --accent: #86abe6;
    --panel: rgba(31, 28, 23, .97); --space: #12110f; --badge: #172025;
    --good: #86c98f; --close: #e6bd5c; --far: #f0995e; --off: #e07a72;
    --era-0: #d9a55a; --era-1: #a3afba; --era-2: #e08466; --era-3: #9cb86c; --era-4: #6ba9cf; --era-5: #b590c8; --era-6: #e28aa8;
    --edge: rgba(236, 226, 205, .12); --hover: rgba(236, 226, 205, .07); --on-accent: #121a22;
    --lift: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 18px rgba(0, 0, 0, .3);
    --float: 0 2px 6px rgba(0, 0, 0, .3), 0 16px 40px rgba(0, 0, 0, .45);
  }
}
* { box-sizing: border-box; }
.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; border: 0;
  overflow: hidden; clip-path: inset(50%); white-space: nowrap;
}
.noscript { position: fixed; inset: 40% 16px auto; text-align: center; font-size: 18px; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  background: var(--space); color: var(--ink);
  font: 15px/1.4 var(--serif);
  -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%; pointer-events: none; }
body.no-globe canvas#globe { display: none; }

/* paper grain and a printer's vignette over the globe, 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; }
}
#top, #quiz, footer { z-index: 2; }

/* --- the top: the name, and the timeline it comes from ------------------------------ */
#top {
  position: fixed; top: max(16px, env(safe-area-inset-top)); left: max(16px, env(safe-area-inset-left)); right: max(16px, env(safe-area-inset-right));
  display: flex; justify-content: space-between; gap: 8px; pointer-events: none;
}
.bar {
  display: flex; background: var(--panel); border: 1px solid var(--edge); border-radius: 999px;
  box-shadow: var(--lift); overflow: hidden; pointer-events: auto;
}
.bar > a, .bar > span {
  height: 38px; padding: 0 15px; display: flex; align-items: center; gap: 7px;
  color: var(--ink); text-decoration: none; font: 500 15.5px/1 var(--serif); letter-spacing: .01em;
}
.bar > a:hover { background: var(--hover); }
.bar > a:focus-visible { outline: 2px solid var(--accent); outline-offset: -3px; border-radius: 999px; }
.bar svg { width: 17px; height: 17px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.brand b { font-size: 17px; font-weight: 600; letter-spacing: .03em; }

/* --- the panel: the puzzle, bottom left on the dock, joined to its pin by a line ------- */
#quiz {
  -webkit-user-select: text; user-select: text;
  position: fixed; left: max(16px, env(safe-area-inset-left)); bottom: var(--stack); width: min(345px, calc(100vw - 32px));
  max-height: calc(100vh - var(--stack) - var(--head)); max-height: calc(100dvh - var(--stack) - var(--head)); overflow: auto; overscroll-behavior: contain;
  background: var(--panel); border: 1px solid var(--edge); border-radius: 16px; box-shadow: var(--float);
}
#quiz .body { padding: 16px 20px 18px; }
#quiz .body > :last-child { margin-bottom: 0; }
#quiz h2 { margin: 0 0 4px; font-size: 25px; font-weight: 500; line-height: 1.12; text-wrap: balance; }
#quiz p { margin: 0 0 12px; font-size: 16px; line-height: 1.45; }
#quiz b { font-weight: 500; }
#quiz .eyebrow { margin-bottom: 6px; color: var(--muted); font-size: 12.5px; letter-spacing: .13em; text-transform: uppercase; }
#quiz .muted { color: var(--muted); font-style: italic; }
#quiz .muted b { color: var(--ink); font-style: normal; font-feature-settings: "lnum", "tnum"; }
#quiz .place { color: var(--muted); font-style: italic; }
#quiz .hint { color: color-mix(in srgb, var(--ink) 82%, transparent); }

/* where the day stands: a dot a round, in the colour of how close it was */
#quiz .progress { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; color: var(--muted); font-size: 14px; font-style: italic; font-feature-settings: "lnum"; }
.dots { display: flex; gap: 6px; }
.dots i { width: 8px; height: 8px; border-radius: 50%; border: 1.5px solid var(--line); }
.dots i.now { border-color: var(--accent); background: var(--accent); }
.dots i.good { border: 0; background: var(--good); }
.dots i.close { border: 0; background: var(--close); }
.dots i.far { border: 0; background: var(--far); }
.dots i.off { border: 0; background: var(--off); }
#quiz .dots.big { gap: 8px; margin: 4px 0 14px; }
#quiz .dots.big i { width: 14px; height: 14px; }

#quiz .primary {
  height: 46px; padding: 0 22px; flex: none; border: 0; border-radius: 999px; background: var(--accent); color: var(--on-accent);
  font: 500 17px/1 var(--serif); cursor: pointer; box-shadow: 0 2px 10px color-mix(in srgb, var(--accent) 35%, transparent);
}
#quiz .primary:hover { filter: brightness(1.08); }
#quiz .primary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
#quiz .body > .primary, #quiz .guess .primary:only-child { width: 100%; }
#quiz .guess { display: flex; gap: 8px; margin-top: 4px; }
#quiz .guess input {
  width: 0; flex: 1; height: 46px; padding: 0 16px; border: 1px solid var(--edge); border-radius: 999px;
  background: color-mix(in srgb, var(--ink) 4%, transparent); color: var(--ink); outline: none;
  font: 20px/1 var(--serif); font-feature-settings: "lnum", "tnum";
}
#quiz .guess input:focus { border-color: color-mix(in srgb, var(--accent) 60%, transparent); }

/* the answer: the year, big, and how close */
#quiz h2 a { color: inherit; text-decoration: none; }
#quiz h2 a:hover { color: var(--accent); }
#quiz h2 .last { white-space: nowrap; }
#quiz h2 .out { width: .55em; height: .55em; margin-left: .2em; vertical-align: .32em; fill: none; stroke: var(--muted); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
#quiz h2 a:hover .out { stroke: var(--accent); }
#quiz .verdict { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 10px 0 2px; }
#quiz .verdict b { font-size: 32px; font-feature-settings: "lnum"; }
#quiz .verdict span { color: var(--accent); font-size: 17px; font-feature-settings: "lnum"; }
#quiz .body > .primary { margin-top: 4px; }

/* the score */
#quiz .final { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
#quiz .score { margin: 0; font-size: 40px; font-feature-settings: "lnum"; }
#quiz .score small { color: var(--muted); font-size: 19px; }
#quiz .rounds { margin: 0; padding: 0; list-style: none; border-top: 1px solid var(--line); }
#quiz .rounds li + li { border-top: 1px solid var(--line); }
#quiz .rounds button {
  display: flex; align-items: flex-start; gap: 10px; width: 100%; padding: 8px 0; border: 0; background: none; text-align: left;
  color: var(--ink); font: 15.5px/1.3 var(--serif); cursor: pointer;
}
#quiz .rounds button:hover b { color: var(--accent); }
#quiz .rounds span { flex: 1; min-width: 0; }
#quiz .rounds b { display: block; font-weight: 400; }
#quiz .rounds small { display: block; color: var(--muted); font-size: 13px; font-style: italic; font-feature-settings: "onum"; }
#quiz .rounds em { color: var(--muted); font-style: normal; font-feature-settings: "lnum", "tnum"; }
#quiz .stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 12px 0; padding-top: 12px; border-top: 1px solid var(--line); text-align: center; }
#quiz .stats dt { color: var(--muted); font-size: 11.5px; letter-spacing: .12em; text-transform: uppercase; }
#quiz .stats dd { margin: 0; font-size: 22px; font-feature-settings: "lnum", "tnum"; }
#quiz .next { text-align: center; font-size: 14.5px; }

/* --- the dock: the year and the timeline ---------------------------------------------- */
footer {
  position: fixed; left: max(16px, env(safe-area-inset-left)); right: max(16px, env(safe-area-inset-right));
  bottom: max(16px, env(safe-area-inset-bottom));
  display: flex; align-items: center; gap: 16px; padding: 10px 14px;
  background: var(--panel); border: 1px solid var(--edge); border-radius: 20px; box-shadow: var(--float);
}
#setter { display: flex; align-items: center; gap: 2px; }
.step {
  display: none; width: 38px; height: 38px; flex: none; place-items: center; padding: 0;
  border: 1px solid var(--edge); border-radius: 50%; background: none; color: var(--ink); cursor: pointer; touch-action: manipulation;
}
.step:active { background: var(--hover); }
.step svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
footer.locked .step { opacity: .3; pointer-events: none; }
#year {
  min-width: 3.7em; font-size: 30px; font-weight: 400; line-height: 1; white-space: nowrap;
  font-feature-settings: "lnum", "tnum"; letter-spacing: .01em;
}
#year small { margin-left: 5px; color: var(--muted); font-size: 19px; font-variant-caps: all-small-caps; letter-spacing: .06em; }

/* the track: a bar of how much happened when, coloured by era (strong up to the handle),
   the era named over the handle; years under it */
#track { position: relative; flex: 1; align-self: stretch; min-height: 48px; cursor: pointer; outline: none; touch-action: none; }
#track::before { content: ""; position: absolute; left: 0; right: 0; top: 30px; height: 1px; background: var(--line); }
#density { position: absolute; left: 0; top: 4px; width: 100%; height: 26px; pointer-events: none; }
#ticks .era {
  position: absolute; top: 34px; font-size: 13px; font-style: italic; color: var(--muted); white-space: nowrap;
  transform: translateX(-50%); font-feature-settings: "onum";
}
#ticks .era.start { transform: none; }
#ticks .era:last-child { transform: translateX(-75%); }
#handle { position: absolute; top: 0; height: 31px; width: 2px; margin-left: -1px; border-radius: 1px; background: var(--accent); pointer-events: none; }
#handle::after { /* the knob, on the baseline */
  content: ""; position: absolute; left: 50%; top: 30px; width: 13px; height: 13px; transform: translate(-50%, -50%);
  border-radius: 50%; background: var(--accent); border: 2px solid var(--badge); box-shadow: 0 1px 3px rgba(0, 0, 0, .25);
}
#track:focus-visible #handle::after { box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 30%, transparent); }
#era-tag {
  position: absolute; bottom: calc(100% + 4px); left: 0; transform: translateX(-50%); pointer-events: none;
  display: flex; align-items: center; gap: 6px; padding: 3px 9px 4px 8px; white-space: nowrap;
  background: var(--panel); border: 1px solid color-mix(in srgb, var(--era) 45%, var(--edge)); border-radius: 999px;
  font: italic 13.5px/1.1 var(--serif); color: var(--ink); box-shadow: var(--lift);
}
#era-tag i { width: 8px; height: 8px; flex: none; border-radius: 50%; background: var(--era); }
/* the guess, left on the timeline while the answer shows */
#guess-mark { position: absolute; top: 0; height: 31px; width: 0; border-left: 2px dotted color-mix(in srgb, var(--ink) 55%, transparent); margin-left: -1px; pointer-events: none; }
#guess-mark[hidden] { display: none; }
#guess-mark::after {
  content: ""; position: absolute; left: -1px; top: 30px; width: 11px; height: 11px; transform: translate(-50%, -50%);
  border-radius: 50%; background: var(--badge); border: 2px solid color-mix(in srgb, var(--ink) 55%, transparent);
}
/* on a phone: a stretch of the timeline that swipes under a fixed handle (drawRuler in
   timeline.js), fading out at the ends */
#ruler {
  display: none; position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none;
  mask-image: linear-gradient(to right, transparent, #000 14%, #000 86%, transparent);
}
#track.ruler #ruler { display: block; }
#track.ruler::before, #track.ruler > :not(#ruler, #era-tag) { display: none; }

/* --- phones --------------------------------------------------------------------------- */
@media (max-width: 600px) {
  #top { top: max(12px, env(safe-area-inset-top)); left: max(12px, env(safe-area-inset-left)); right: max(12px, env(safe-area-inset-right)); }
  .bar > a, .bar > span { padding: 0 14px; }

  footer {
    left: max(10px, env(safe-area-inset-left)); right: max(10px, env(safe-area-inset-right)); bottom: max(10px, env(safe-area-inset-bottom));
    flex-wrap: wrap; gap: 6px 12px; padding: 9px 12px 4px; border-radius: 18px;
  }
  /* the year in the middle, between ‹ and ›, and the era under it, over the ruler */
  #setter { flex: 1; justify-content: space-between; }
  .step { display: grid; }
  #year { font-size: 28px; line-height: 44px; text-align: center; }
  #year small { font-size: 17px; }
  #track { order: 1; flex-basis: 100%; min-height: 52px; margin-top: 10px; } /* last, full width: a comfortable thumb target */
  #era-tag { left: 50%; bottom: calc(100% - 2px); padding: 0; border: 0; background: none; box-shadow: none; color: var(--muted); font-size: 13px; }
  #ticks .minor { display: none; }

  /* the panel: up to QUIZ_STRIP (globe.js) tall */
  :root { --stack: calc(max(10px, env(safe-area-inset-bottom)) + 138px); }
  #quiz { bottom: var(--stack); left: 10px; right: 10px; width: auto; max-height: 262px; }
  #quiz .body { padding: 13px 16px 15px; }
  #quiz h2 { font-size: 22px; }
  #quiz p { font-size: 15.5px; }
  #quiz .score { font-size: 34px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; }
}
