/* The page around the map.
   Palette deliberately matches js/style.js — the chrome is paper the map is
   printed on, not a dark UI wrapped around a light map. */

:root {
  --paper: #f6efe1;
  --paper-solid: #efe6d4;
  --ink: #2c3e45;
  --ink-soft: #5c7079;
  --ink-faint: #8b9aa0;
  --rule: #d8cbb4;
  --accent: #4c7f8c;

  --rail-w: min(30rem, 34vw);
  --panel-w: 21rem;

  --serif: ui-serif, Georgia, "Iowan Old Style", "Times New Roman", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--sans);
  color: var(--ink);
  background: var(--paper-solid);
  -webkit-font-smoothing: antialiased;
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ---------- the map stage ---------- */

/* No z-index here on purpose. Giving #stage its own stacking context buries
   the seam and the era toggle underneath #rail, and no amount of z-index on
   them can climb back out of it. */
#stage {
  position: fixed;
  inset: 0;
}

.map {
  position: absolute;
  inset: 0;
}

/* The 2120 map sits on top and is clipped by compare.js. It must never take a
   pointer event — the map underneath handles all of them, including over the
   half where this one is what you can see. */
#map-2120 {
  pointer-events: none;
  clip-path: inset(0 0 0 50%);
}

/* ---------- the seam ---------- */

#seam {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 2.75rem;
  margin-left: -1.375rem;
  z-index: 5;
  cursor: ew-resize;
  touch-action: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

#seam:focus-visible { outline: none; }
#seam:focus-visible .seam-grip { box-shadow: 0 0 0 3px var(--accent); }

.seam-line {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 2px;
  margin-left: -1px;
  background: var(--paper);
  box-shadow: 0 0 0 1px rgb(44 62 69 / 0.18);
}

.seam-grip {
  position: relative;
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 50%;
  background: var(--paper);
  color: var(--ink-soft);
  display: grid;
  place-items: center;
  box-shadow: 0 1px 3px rgb(44 62 69 / 0.28);
  transition: transform 120ms ease;
}

#seam.is-dragging .seam-grip,
#seam:hover .seam-grip { transform: scale(1.08); }

/* Era labels, so the seam is self-explanatory without a caption. */
.era {
  position: absolute;
  top: 1rem;
  z-index: 4;
  font-size: 0.7rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-soft);
  background: rgb(246 239 225 / 0.82);
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  pointer-events: none;
}
.era-left { left: calc(var(--rail-w) + 1.5rem); }
/* clears the zoom control, which sits top-right */
.era-right { right: 4.6rem; }

.era-toggle { display: none; }

/* ---------- the chapter rail ---------- */

#rail {
  position: relative;
  z-index: 2;
  width: var(--rail-w);
  padding: 0 1.5rem;
  pointer-events: none; /* the map keeps working in the gaps between cards */
}

/* The card takes pointer events; the section around it must not. It is a full
   rail column tall — and the full width of the screen on a phone — so making it
   clickable puts an invisible sheet over the map, the seam and the era toggle. */
.chapter {
  pointer-events: none;
  min-height: 88vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 3rem 0;
}

.chapter-card {
  pointer-events: auto;
  background: rgb(246 239 225 / 0.94);
  backdrop-filter: blur(2px);
  border: 1px solid var(--rule);
  border-radius: 2px;
  padding: 1.6rem 1.7rem 1.5rem;
  box-shadow: 0 2px 14px rgb(44 62 69 / 0.13);
  opacity: 0.42;
  transform: translateY(0.4rem);
  transition: opacity 400ms ease, transform 400ms ease;
}

.chapter.is-active .chapter-card {
  opacity: 1;
  transform: none;
}

.chapter-kicker {
  font-size: 0.68rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 0.6rem;
}

.chapter-title {
  font-family: var(--serif);
  font-weight: 600;
  font-size: clamp(1.45rem, 2.4vw, 1.95rem);
  line-height: 1.15;
  margin: 0 0 0.75rem;
}

.chapter-body {
  margin: 0;
  font-size: 0.95rem;
  line-height: 1.6;
  color: var(--ink-soft);
}

.chapter-note {
  margin: 0.9rem 0 0;
  padding-top: 0.8rem;
  border-top: 1px solid var(--rule);
  font-size: 0.8rem;
  color: var(--ink-faint);
}

/* ---------- panel: sea level + legend ---------- */

#panel {
  position: fixed;
  right: 1.5rem;
  bottom: 3.4rem;
  z-index: 6;
  width: var(--panel-w);
  max-height: calc(100vh - 8rem);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  pointer-events: none;
}
#panel > * { pointer-events: auto; }

.sea, .legend {
  background: rgb(246 239 225 / 0.94);
  border: 1px solid var(--rule);
  border-radius: 2px;
  padding: 0.85rem 1rem;
  box-shadow: 0 2px 10px rgb(44 62 69 / 0.12);
}

.sea-label {
  display: block;
  font-size: 0.78rem;
  color: var(--ink-soft);
  margin-bottom: 0.5rem;
}
.sea-label output { font-weight: 600; color: var(--ink); }
.sea-datum { color: var(--ink-faint); }

#sea-input {
  width: 100%;
  accent-color: var(--accent);
}

.legend-row {
  display: flex;
  gap: 0.6rem;
  align-items: flex-start;
  padding: 0.45rem 0;
  border-bottom: 1px solid rgb(216 203 180 / 0.6);
  width: 100%;
  text-align: left;
  font: inherit;
  color: inherit;
  background: none;
  border-left: 0; border-right: 0; border-top: 0;
}
.legend-row:last-child { border-bottom: 0; }
button.legend-row { cursor: pointer; }
button.legend-row.is-off { opacity: 0.42; }

.legend-swatch {
  flex: 0 0 auto;
  width: 0.9rem;
  height: 0.9rem;
  margin-top: 0.15rem;
  border-radius: 2px;
  box-shadow: inset 0 0 0 1px rgb(44 62 69 / 0.2);
}

.legend-text { display: flex; flex-direction: column; gap: 0.15rem; }

/* Explore mode: one line per layer, provenance in the disclosure below. */
.legend.is-compact .legend-row { padding: 0.3rem 0; border-bottom: 0; align-items: center; }
.legend.is-compact .legend-swatch { margin-top: 0; }

.legend-sources {
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--rule);
  font-size: 0.72rem;
  line-height: 1.45;
  color: var(--ink-soft);
}
.legend-sources summary { cursor: pointer; color: var(--accent); font-size: 0.75rem; }
.legend-sources p { margin: 0.5rem 0 0; }
.legend-sources em { color: var(--ink-faint); font-style: normal; }
.legend-label { font-size: 0.82rem; font-weight: 600; }
.legend-caption { font-size: 0.76rem; line-height: 1.4; color: var(--ink-soft); }
.legend-source { font-size: 0.68rem; color: var(--ink-faint); }

/* ---------- credits ---------- */

#credits {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 3;
  background: rgb(246 239 225 / 0.9);
  border-top: 1px solid var(--rule);
  font-size: 0.68rem;
  line-height: 1.5;
  color: var(--ink-faint);
}
#credits p { margin: 0; padding: 0.4rem 1.5rem; }
#credits a { color: var(--ink-soft); }
.build { color: var(--rule); }

.noscript {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: var(--paper-solid);
  z-index: 99;
  font-size: 1rem;
  padding: 2rem;
  text-align: center;
}

/* ---------- narrow screens ---------- */

/* A 50 px drag is not a comparison gesture. Below this width the seam goes away
   and the two eras become a button you press, which is the same idea with a
   target you can actually hit. */
@media (max-width: 46rem) {
  :root { --rail-w: 100%; }

  #seam { display: none; }
  #map-2120 { clip-path: inset(0 0 0 100%); }
  body.show-2120 #map-2120 { clip-path: inset(0); }

  .era { display: none; }

  .era-toggle {
    display: block;
    position: absolute;
    top: 0.9rem;
    left: 0.9rem;   /* the zoom control owns the top-right corner */
    z-index: 6;
    font: inherit;
    font-size: 0.78rem;
    font-weight: 600;
    padding: 0.5rem 0.9rem;
    border-radius: 999px;
    border: 1px solid var(--rule);
    background: rgb(246 239 225 / 0.94);
    color: var(--ink);
    box-shadow: 0 1px 4px rgb(44 62 69 / 0.2);
    cursor: pointer;
  }

  #rail { padding: 0 1rem; }

  /* The card sits at the bottom so the map above it stays visible while reading. */
  .chapter {
    min-height: 100vh;
    justify-content: flex-end;
    padding-bottom: 4.5rem;
  }

  /* The panel cannot go into the page flow here: it would sit below eight
     screens of chapters, and "drag to raise the sea" would be an instruction
     about a control nobody can reach while reading the chapter that says it.
     So it stays fixed, at the top, where the card is not. */
  #panel {
    top: 3.7rem;
    left: 0.9rem;
    right: 0.9rem;
    bottom: auto;
    width: auto;
    max-height: 42vh;
    z-index: 7;
  }

  .chapter-title { font-size: 1.5rem; }
  .chapter-body { font-size: 0.92rem; }

  #credits { position: static; }
  #credits p { padding: 0.8rem 1rem 1rem; }
}
