/* Novelmaps — Victorian editorial styling.
   Palette echoes styles/victorian.json: parchment, ink, celadon water. */

@font-face {
  font-family: 'EB Garamond';
  src: url('../assets/fonts/EBGaramond.woff2') format('woff2');
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'EB Garamond';
  src: url('../assets/fonts/EBGaramond-italic.woff2') format('woff2');
  font-weight: 400 700;
  font-style: italic;
  font-display: swap;
}
@font-face {
  font-family: 'IM Fell English';
  src: url('../assets/fonts/IMFellEnglish.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'IM Fell English';
  src: url('../assets/fonts/IMFellEnglish-italic.woff2') format('woff2');
  font-weight: 400;
  font-style: italic;
  font-display: swap;
}

:root {
  --paper: #f3ead7;
  --paper-bright: #f9f2e2;
  --paper-deep: #e7dbc0;
  --ink: #2e2417;
  --ink-soft: #6b5a42;
  --rule: #c8b896;
  --accent: #a63d33; /* madder */
  --shadow: 0 2px 8px rgba(46, 36, 23, 0.25);
  --serif: 'EB Garamond', 'Iowan Old Style', Georgia, 'Times New Roman', serif;
  --display: 'IM Fell English', 'EB Garamond', Georgia, serif;
}

* { box-sizing: border-box; }

/* Panels use display:flex, which would otherwise defeat the hidden
   attribute the mode switch relies on. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  /* stop iOS Safari inflating text in landscape (it was blowing up the
     map attribution to giant size) */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* the mobile "end the journey" button — hidden entirely off touch devices */
#mobile-stop { display: none; }

body {
  font-family: var(--serif);
  font-size: 16px; /* 12px absolute floor everywhere on mobile */
  color: var(--ink);
  background: var(--paper);
  overflow: hidden; /* the map page never scrolls; panels manage their own */
}

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

.noscript {
  padding: 2rem;
  font-size: 1.1rem;
}

/* ---- shared panel chrome ---- */

.panel {
  position: absolute;
  z-index: 10;
  background: var(--paper-bright);
  border: 1px solid var(--rule);
  box-shadow: var(--shadow);
  border-radius: 3px;
}

/* ---- the left rail: masthead, legend, places stack and flow ----
   (pinning each at fixed offsets broke the moment a long title
   wrapped: the legend slid up over the masthead's buttons) */

#rail {
  position: absolute;
  z-index: 10;
  top: 12px;
  left: 12px;
  width: 250px;
  max-height: calc(100vh - 24px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none; /* gaps click through to the map */
}
#rail > * { pointer-events: auto; }

/* ---- masthead ---- */

#masthead {
  position: static;
  padding: 10px 16px 12px;
  border-top: 3px double var(--rule);
  border-bottom: 3px double var(--rule);
}

.masthead-kicker {
  display: inline-flex;
  align-items: baseline;
  gap: 0.35em;
  margin: 0;
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent);
  text-decoration: none;
  transition: color 0.15s;
}
.masthead-kicker .kicker-arrow {
  font-size: 12px;
  transition: transform 0.15s;
}
.masthead-kicker .kicker-word {
  border-bottom: 1px solid transparent;
  transition: border-color 0.15s;
}
a.masthead-kicker:hover .kicker-word { border-bottom-color: currentColor; }
a.masthead-kicker:hover .kicker-arrow { transform: translateX(-2px); }
a.masthead-kicker:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 2px;
}

.masthead-title {
  margin: 2px 0 0;
  font-family: var(--display);
  font-weight: normal;
  font-size: 30px;
  line-height: 1.05;
}

.masthead-byline {
  margin: 2px 0 0;
  font-style: italic;
  font-size: 14px;
  color: var(--ink-soft);
}

/* ---- legend ---- */

#legend {
  position: static;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 4px 8px;
  border: 0;
  border-radius: 3px;
  background: transparent;
  font: inherit;
  color: inherit;
  text-align: left;
  cursor: pointer;
}
.legend-item:hover { background: var(--paper-deep); }
.legend-item[aria-pressed='true'] { background: var(--paper-deep); box-shadow: inset 2px 0 0 var(--accent); }
#legend.has-selection .legend-item[aria-pressed='false'] { opacity: 0.5; }

.legend-swatch {
  flex: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--paper-bright);
  box-shadow: 0 0 0 1px var(--rule);
}

.map-key {
  margin-top: 4px;
  padding: 8px 8px 4px;
  border-top: 1px solid var(--rule);
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--ink-soft);
}
.key-item { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.key-item svg { flex: none; color: var(--ink); }

.legend-text { display: flex; flex-direction: column; min-width: 0; }
.legend-name { font-size: 15px; }
.legend-role {
  font-size: 12px;
  font-style: italic;
  color: var(--ink-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---- mode tabs ---- */

.mode-tabs {
  display: flex;
  margin: 10px 0 6px;
  border: 1px solid var(--rule);
  border-radius: 3px;
  overflow: hidden;
}
.mode-tabs button {
  flex: 1;
  min-height: 40px;
  border: 0;
  background: transparent;
  font: inherit;
  font-size: 14px;
  color: var(--ink-soft);
  cursor: pointer;
}
.mode-tabs button + button { border-left: 1px solid var(--rule); }
.mode-tabs button[aria-pressed='true'] {
  background: var(--ink);
  color: var(--paper-bright);
}

/* ---- places gazetteer (explore mode) ---- */

#places {
  position: static;
  min-height: 0; /* let the rail's max-height squeeze it */
  padding: 0 0 6px;
  font-size: 14px;
  display: flex;
  flex-direction: column;
}
#places[hidden] { display: none; }

.places-title {
  margin: 0;
  padding: 12px 14px 10px;
  font-family: var(--display);
  font-weight: normal;
  font-size: 18px;
  border-bottom: 1px solid var(--rule);
}

.places-groups {
  overflow-y: auto;
  padding: 4px 6px;
}

.places-group h3 {
  margin: 10px 8px 2px;
  font-size: 11px;
  font-weight: 400;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.places-group ul { margin: 0; padding: 0; list-style: none; }

.places-item {
  display: block;
  width: 100%;
  min-height: 40px;
  padding: 6px 10px;
  border: 0;
  border-radius: 3px;
  background: transparent;
  font: inherit;
  color: inherit;
  text-align: left;
  cursor: pointer;
}
.places-item:hover { background: var(--paper-deep); }
.places-certainty {
  font-size: 12px;
  font-style: italic;
  color: var(--ink-soft);
}

/* ---- location tile (who you're watching, and where) ---- */

#locationtile {
  position: absolute;
  z-index: 11;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  max-width: min(440px, calc(100vw - 24px));
  display: none;
}
#locationtile.is-visible {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 16px 6px 7px;
  background: rgba(46, 36, 23, 0.9);
  color: var(--paper-bright);
  border-radius: 999px;
  box-shadow: var(--shadow);
}
body.is-overture #locationtile { display: none !important; }

.loc-tile-disc {
  flex: none;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--paper-bright);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: -0.02em;
  box-shadow: 0 0 0 2px rgba(249, 242, 226, 0.45);
}

.loc-tile-body { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.loc-tile-name { font-size: 14px; }
.loc-tile-where {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-style: italic;
  opacity: 0.9;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.loc-tile-where .mode-icon { flex: none; vertical-align: -2px; }

/* travel-mode icon, shared by tile and captions */
.mode-icon { display: inline-block; }
.caption-line .mode-icon { flex: none; align-self: center; opacity: 0.9; }

/* ---- captions ---- */

#captions {
  position: absolute;
  z-index: 10;
  left: 50%;
  bottom: 122px; /* a clear gap above the controls bar */
  transform: translateX(-50%);
  max-width: min(620px, calc(100vw - 24px));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  text-align: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.5s ease;
}
#captions.is-visible { opacity: 1; }

/* ---- the story card (scripted story mode) ---- */
/* The narrative surface: one beat at a time, text given the time it
   needs. Sits where the captions live; in scripted mode this card IS the
   narration, so it takes the spot with room to breathe. */
#storycard {
  position: absolute;
  z-index: 11;
  left: 50%;
  bottom: 122px;
  transform: translateX(-50%);
  width: min(640px, calc(100vw - 20px));
  display: flex;
  align-items: stretch;
  gap: 8px;
  opacity: 0;
  transition: opacity 0.35s ease;
  pointer-events: none;
}
#storycard.is-visible { opacity: 1; pointer-events: auto; }
body.is-overture #storycard { display: none !important; }

.story-body {
  flex: 1;
  min-width: 0;
  background: var(--paper-bright);
  border: 1px solid var(--rule);
  border-radius: 3px;
  box-shadow: var(--shadow);
  padding: 12px 18px 10px;
  text-align: center;
}
.story-kicker {
  margin: 0 0 2px;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  font-size: 11.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.story-subject { display: inline-flex; align-items: center; gap: 6px; }
.story-mode {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  text-transform: none;
  letter-spacing: 0;
  font-style: italic;
  color: var(--ink-soft);
}
.story-mode[hidden] { display: none; }
.story-mode .mode-icon { width: 18px; height: 18px; opacity: 0.85; }
#storycard.is-interstitial .story-mode { color: var(--paper); }
/* The character disc: the story card's echo of their circle on the map —
   a filled colour circle with the same light ring the marker carries. */
.story-swatch {
  flex: none;
  box-sizing: border-box;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 1.5px solid var(--paper-bright);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--paper-bright);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.story-title {
  margin: 4px 0 0;
  font-family: var(--display);
  font-size: 18px;
  line-height: 1.2;
}
.story-narration {
  margin: 6px 0 4px;
  font-size: 16px;
  line-height: 1.5;
}
.story-progress {
  margin: 2px 0 0;
  font-size: 10.5px;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
  opacity: 0.8;
}
.story-step {
  flex: none;
  align-self: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid var(--rule);
  background: var(--paper-bright);
  color: var(--ink);
  font-size: 18px;
  cursor: pointer;
  box-shadow: var(--shadow);
}
.story-step:hover:not(:disabled) { background: var(--paper); }
.story-step:disabled { opacity: 0.35; cursor: default; }

/* Interstitials (meanwhile, handoff) own the moment: a darker, weightier
   card, so the change of thread or of time reads as a deliberate turn. */
#storycard.is-interstitial .story-body {
  background: rgba(46, 36, 23, 0.92);
  border-color: rgba(46, 36, 23, 0.92);
  color: var(--paper-bright);
}
#storycard.is-interstitial .story-kicker { color: var(--paper); }
#storycard.is-interstitial .story-narration { font-style: italic; }
#storycard.is-done .story-kicker { color: var(--accent); }

@media (max-width: 720px) {
  #storycard { bottom: 158px; }
  .story-narration { font-size: 14.5px; }
  .story-step { width: 40px; height: 40px; }
}

.caption-line {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin: 0;
  padding: 7px 16px;
  background: rgba(46, 36, 23, 0.85);
  color: var(--paper-bright);
  font-size: 15px;
  border-radius: 3px;
  transition: opacity 0.5s ease;
}
.caption-line.is-arrival { background: rgba(46, 36, 23, 0.68); font-style: italic; }
/* A staging post ticking by as you ride along — lighter and quieter than
   a full journey line, a passing whisper. */
.caption-line.is-passing {
  background: rgba(46, 36, 23, 0.6);
  font-size: 13px;
  font-style: italic;
  padding: 4px 14px;
  align-self: flex-start;
}
.caption-line.is-passing .caption-swatch { width: 7px; height: 7px; }
/* "the years pass…" — a quiet interlude while the map sweeps empty time. */
.caption-line.is-interlude {
  background: rgba(46, 36, 23, 0.5);
  justify-content: center;
  font-style: italic;
  letter-spacing: 0.04em;
  color: var(--paper);
}
.caption-line.is-retiring { opacity: 0; }

.caption-swatch {
  flex: none;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  align-self: center;
  box-shadow: 0 0 0 1.5px var(--paper-bright);
}
.caption-swatch + .caption-swatch { margin-left: -6px; }
.caption-text { min-width: 0; }
.caption-note { font-style: italic; opacity: 0.85; }

/* ---- controls / scrubber ---- */

#controls {
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  width: min(720px, calc(100vw - 24px));
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
}

.play-btn {
  flex: none;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--rule);
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
  display: grid;
  place-items: center;
}
.play-btn:hover { background: var(--paper-deep); }
.speed-btn {
  flex: none;
  min-width: 40px;
  height: 40px;
  border-radius: 3px;
  border: 1px solid var(--rule);
  background: transparent;
  color: var(--ink-soft);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}
.speed-btn:hover { background: var(--paper-deep); color: var(--ink); }

.play-btn .icon-pause { display: none; }
.play-btn[aria-pressed='true'] .icon-play { display: none; }
.play-btn[aria-pressed='true'] .icon-pause { display: block; }

.scrub-body { flex: 1; min-width: 0; }

.chapter-heading {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
}
/* the story clock — the date/season ticking, made the hero */
.story-clock {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex: none;
}
.clock-date {
  font-family: var(--display);
  font-size: 19px;
  color: var(--ink);
}
.clock-elapsed {
  font-size: 12px;
  font-style: italic;
  color: var(--ink-soft);
}
.clock-elapsed:empty { display: none; }
/* the chapter reference — now secondary, pushed to the right */
.chapter-ref {
  margin-left: auto;
  display: flex;
  align-items: baseline;
  gap: 6px;
  min-width: 0;
  color: var(--ink-soft);
}
.chapter-numeral { font-size: 13px; letter-spacing: 0.04em; }
.chapter-title {
  font-style: italic;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* One bar, not two. The activity band is the only visible track; the range
   input rides on top of it, its own track made transparent so the handle
   travels along the band — density ribbon in clock mode, progress fill in
   scripted mode. */
.scrub-track {
  position: relative;
  height: 20px;
  display: flex;
  align-items: center;
}
.scrub-activity {
  position: absolute;
  left: 1px;
  right: 1px;
  top: 50%;
  transform: translateY(-50%);
  height: 8px;
  border-radius: 4px;
  border: 1px solid var(--rule);
  box-shadow: inset 0 1px 2px rgba(46, 36, 23, 0.15);
}

.scrub-range {
  position: relative;
  width: 100%;
  height: 20px;
  margin: 0;
  background: transparent;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
}
.scrub-range::-webkit-slider-runnable-track { background: transparent; height: 20px; }
.scrub-range::-moz-range-track { background: transparent; height: 20px; }
.scrub-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  margin-top: 2px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--paper-bright);
  box-shadow: 0 1px 3px rgba(46, 36, 23, 0.4);
  cursor: pointer;
}
.scrub-range::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--paper-bright);
  box-shadow: 0 1px 3px rgba(46, 36, 23, 0.4);
  cursor: pointer;
}

/* ---- recentre / frame-the-story (lives in the controls bar) ---- */

#recentre {
  flex: none;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--rule);
  border-radius: 3px;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
}
#recentre:hover { color: var(--accent); background: var(--paper-deep); }

/* ---- intro title card ---- */

#intro:empty { display: none; }
#intro.is-leaving { opacity: 0; transition: opacity 0.45s ease; }

.intro-scrim {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(46, 36, 23, 0.45);
}

.intro-card {
  position: fixed;
  z-index: 41;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(460px, calc(100vw - 32px));
  padding: 34px 38px 26px;
  background: var(--paper-bright);
  border: 1px solid var(--rule);
  border-top: 4px double var(--rule);
  border-bottom: 4px double var(--rule);
  box-shadow: 0 12px 48px rgba(46, 36, 23, 0.45);
  border-radius: 3px;
  text-align: center;
}

.intro-kicker {
  margin: 0;
  font-size: 12px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.intro-title {
  margin: 8px 0 0;
  font-family: var(--display);
  font-weight: normal;
  font-size: 54px;
  line-height: 1;
}

.intro-byline {
  margin: 6px 0 0;
  font-style: italic;
  font-size: 16px;
  color: var(--ink-soft);
}

.intro-blurb {
  margin: 18px 0 0;
  font-size: 16px;
  line-height: 1.5;
}

.intro-actions {
  margin-top: 22px;
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

.intro-begin, .intro-explore {
  min-height: 44px;
  padding: 8px 22px;
  border-radius: 3px;
  font: inherit;
  font-size: 16px;
  cursor: pointer;
}
.intro-begin {
  background: var(--accent);
  border: 1px solid var(--accent);
  color: var(--paper-bright);
}
.intro-begin:hover { background: #8e332b; }
.intro-explore {
  background: transparent;
  border: 1px solid var(--rule);
  color: var(--ink-soft);
}
.intro-explore:hover { background: var(--paper-deep); }

.intro-hints {
  margin: 20px 0 0;
  font-size: 13px;
  font-style: italic;
  color: var(--ink-soft);
}

/* Gentle pulse on play until first pressed (skipped under reduced motion) */
@keyframes play-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(166, 61, 51, 0.45); }
  50% { box-shadow: 0 0 0 9px rgba(166, 61, 51, 0); }
}
#controls:not(.has-played) .play-btn { animation: play-pulse 2.2s ease infinite; }
@media (prefers-reduced-motion: reduce) {
  #controls:not(.has-played) .play-btn { animation: none; }
}

/* ---- location cards (hover popup) ---- */

.loc-card .maplibregl-popup-content {
  font-family: var(--serif);
  background: var(--paper-bright);
  color: var(--ink);
  border: 1px solid var(--rule);
  border-radius: 3px;
  box-shadow: var(--shadow);
  padding: 12px 14px;
}
.loc-card .maplibregl-popup-tip { border-top-color: var(--rule); }

.card-novel-name {
  margin: 0;
  font-family: var(--display);
  font-size: 18px;
  line-height: 1.15;
}
.card-real-name {
  margin: 1px 0 0;
  font-size: 13px;
  font-style: italic;
  color: var(--ink-soft);
}
.card-real-name:empty { display: none; }

.card-story {
  margin: 8px 0 0;
  font-size: 14px;
  line-height: 1.45;
}

.card-quote {
  margin: 8px 0 0;
  padding-left: 10px;
  border-left: 2px solid var(--rule);
  font-size: 14px;
  line-height: 1.4;
}
.card-quote cite {
  display: block;
  margin-top: 2px;
  font-size: 12px;
  font-style: italic;
  color: var(--ink-soft);
}

.badge {
  display: inline-block;
  margin: 8px 0 0;
  padding: 1px 8px 2px;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border-radius: 2px;
  border: 1px solid var(--rule);
  color: var(--ink-soft);
}
.badge-conjectured {
  border-color: var(--accent);
  color: var(--accent);
  border-style: dashed;
}

.card-note {
  margin: 6px 0 0;
  font-size: 13px;
  font-style: italic;
  color: var(--ink-soft);
  line-height: 1.35;
}

/* ---- route + staging-post hover cards ---- */
.route-card-leg {
  margin: 0;
  font-family: var(--display);
  font-size: 15px;
  line-height: 1.2;
}
.route-card-note {
  margin: 6px 0 0;
  font-size: 13.5px;
  line-height: 1.4;
}
.route-card-note:empty { display: none; }
.route-card-source {
  margin: 6px 0 0;
  font-size: 12px;
  font-style: italic;
  color: var(--ink-soft);
  line-height: 1.35;
}
.route-card-source:empty { display: none; }
/* Top tier: the author names the road. A filled badge, so it reads as
   the gold standard at a glance. */
.badge-route-novel {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--paper-bright);
}
.badge-route-documented { border-color: var(--rule); color: var(--ink-soft); }
.badge-route-reconstructed,
.badge-route-illustrative {
  border-color: var(--accent);
  color: var(--accent);
  border-style: dashed;
}
.stop-card-name { font-size: 14px; }
.stop-card-note { font-style: italic; }

/* ---- place image (sheet only) ---- */
.card-figure {
  position: relative;
  margin: 0 0 12px;
}
.card-img {
  display: block;
  width: 100%;
  max-height: 220px;
  object-fit: cover;
  border-radius: 3px;
  border: 1px solid var(--rule);
  background: var(--paper);
}
/* A period painting standing in for an imagined place is flagged, so it
   reads as evocation of the setting, never a record of the place. */
.card-img-indicative {
  position: absolute;
  top: 8px;
  left: 8px;
  padding: 1px 7px 2px;
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--paper-bright);
  background: rgba(46, 36, 23, 0.82);
  border-radius: 2px;
}
.card-figcaption {
  margin-top: 5px;
  font-size: 12px;
  line-height: 1.35;
  color: var(--ink-soft);
}
.card-img-caption { font-style: italic; }
.card-img-credit { display: block; font-size: 11px; opacity: 0.8; }
.card-img-credit:empty { display: none; }

/* ---- bottom sheet ---- */

#sheet { display: none; }
#sheet.is-open { display: block; }

.sheet-scrim {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(46, 36, 23, 0.35);
}

.sheet-panel {
  position: fixed;
  z-index: 31;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 60vh;
  overflow-y: auto;
  background: var(--paper-bright);
  border-top: 3px double var(--rule);
  padding: 16px 20px 24px;
  box-shadow: 0 -4px 16px rgba(46, 36, 23, 0.3);
}

.sheet-close {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 44px;
  height: 44px;
  border: 0;
  background: transparent;
  font-size: 26px;
  color: var(--ink-soft);
  cursor: pointer;
}

/* ---- settings cog + pane ---- */

/* A MapLibre control group for the zoom-button chrome, placed by hand just
   above the transport bar rather than in the map's bottom-right stack. */
.settings-fab {
  position: absolute;
  right: 10px;
  bottom: 84px; /* clears the floating transport bar (~71px) */
  z-index: 5;
  margin: 0;
}
/* Beat MapLibre's own `.maplibregl-ctrl-group button` rule (more specific
   than a lone class) so the flex centring actually applies. */
.settings-fab .settings-cog {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 29px;
  height: 29px;
  padding: 0;
  color: var(--ink);
}
.settings-fab .settings-cog svg { display: block; transition: transform 0.3s ease; }
.settings-fab .settings-cog[aria-expanded='true'] svg { transform: rotate(60deg); }

.settings-pane {
  position: absolute;
  right: 10px;
  bottom: 122px; /* above the cog (84 + 29 + gap) */
  z-index: 6;
  width: 246px;
  max-width: calc(100vw - 20px);
  background: var(--paper-bright);
  border: 1px solid var(--rule);
  border-radius: 3px;
  box-shadow: var(--shadow);
  padding: 14px 16px;
  font-family: var(--serif);
  color: var(--ink);
  animation: settings-rise 0.16s ease-out;
}
@keyframes settings-rise {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

.settings-group { margin-bottom: 12px; }
.settings-title {
  margin: 0 0 3px;
  font-family: var(--display);
  font-weight: normal;
  font-size: 17px;
}
.settings-note {
  margin: 0 0 9px;
  font-size: 12.5px;
  line-height: 1.4;
  color: var(--ink-soft);
}
.settings-slider {
  width: 100%;
  accent-color: var(--accent);
  min-height: 24px;
  display: block;
}
.settings-scale {
  display: flex;
  justify-content: space-between;
  margin-top: 1px;
  font-size: 10.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.settings-links {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-top: 11px;
  border-top: 1px solid var(--rule);
}
/* No rule above the links when they stand alone (a non-British book). */
.settings-overlay + .settings-links { }
.settings-pane > .settings-links:first-child { border-top: 0; padding-top: 0; }
.settings-link {
  font-size: 14px;
  color: var(--accent);
  text-decoration: none;
  padding: 6px 0;
}
.settings-link:hover { text-decoration: underline; }

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---- about page ---- */

.page-about {
  overflow: auto;
  overflow-x: hidden;
}

.about {
  max-width: 42rem;
  margin: 0 auto;
  padding: 2rem 1.25rem 4rem;
}

.about-masthead {
  border-bottom: 3px double var(--rule);
  padding-bottom: 1rem;
  margin-bottom: 1.5rem;
}

.about h1 {
  font-family: var(--display);
  font-weight: normal;
  font-size: 2.2rem;
  margin: 0.5rem 0 0;
}

.about h2 {
  font-family: var(--display);
  font-weight: normal;
  font-size: 1.5rem;
  margin: 2rem 0 0.5rem;
}

.about-back {
  color: var(--ink-soft);
  text-decoration: none;
  font-style: italic;
}
.about-back:hover, .about-back:focus { color: var(--accent); }

.about a { color: var(--accent); }
.about p, .about li { line-height: 1.55; }
.about .lessons { margin: 0.6em 0; }
.about .lessons li { margin-bottom: 0.6em; padding-left: 0.2em; }

.about h3 {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 1.05rem;
  margin: 1.5rem 0 0.25rem;
}

.diary-milestone {
  display: inline-block;
  margin-left: 6px;
  padding: 0 8px 1px;
  font-size: 11px;
  font-weight: 400;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border: 1px solid var(--accent);
  border-radius: 2px;
  color: var(--accent);
  vertical-align: middle;
}

/* ---- the overture ---- */

#overture:empty { display: none; }
#overture.is-leaving .overture-panel { opacity: 0; transition: opacity 0.4s ease; }

/* While the overture holds the stage, the working UI steps aside */
body.is-overture #legend,
body.is-overture #controls,
body.is-overture #captions { display: none !important; }

.overture-panel {
  position: absolute;
  z-index: 20;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  width: min(640px, calc(100vw - 24px));
  padding: 20px 26px 18px;
  background: var(--paper-bright);
  border: 1px solid var(--rule);
  border-top: 3px double var(--rule);
  box-shadow: var(--shadow);
  border-radius: 3px;
  text-align: center;
}

.overture-text {
  margin: 0;
  font-size: 16px;
  line-height: 1.55;
}

.overture-cast {
  margin: 14px 0 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px 14px;
}

.overture-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
}

/* An honesty caption for a book whose action pre-dates any surviving map
   (Henry IV, 1403): the period base is not period-correct, and we say so. */
.overture-note {
  margin: 14px auto 0;
  max-width: 46ch;
  padding-top: 12px;
  border-top: 1px solid var(--paper-deep);
  font-size: 13px;
  font-style: italic;
  line-height: 1.5;
  color: var(--ink-soft);
}

.overture-disc {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--paper-bright);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: -0.02em;
  box-shadow: 0 0 0 2px var(--paper-bright), 0 1px 3px rgba(46, 36, 23, 0.4);
}

.overture-start {
  margin-top: 16px;
  min-height: 44px;
  padding: 8px 26px;
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 3px;
  color: var(--paper-bright);
  font: inherit;
  font-size: 16px;
  cursor: pointer;
}
.overture-start:hover { background: #8e332b; }

@media (max-width: 720px) {
  .overture-panel { bottom: 8px; padding: 14px 14px 12px; }
  .overture-text { font-size: 14px; }
  .overture-chip { font-size: 12px; }
}

/* ---- the library ---- */

#library:empty { display: none; }

.library-scrim {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(46, 36, 23, 0.45);
}

.library-card {
  position: fixed;
  z-index: 41;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  /* Grow with the shelf: wide enough for the books on it, never wider than
     the viewport. Beyond a screenful of spines, the shelf itself scrolls. */
  width: fit-content;
  min-width: min(560px, calc(100vw - 48px));
  max-width: calc(100vw - 48px);
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  padding: 34px 38px 26px;
  background: var(--paper-bright);
  border: 1px solid var(--rule);
  border-top: 4px double var(--rule);
  border-bottom: 4px double var(--rule);
  box-shadow: 0 12px 48px rgba(46, 36, 23, 0.45);
  border-radius: 3px;
  text-align: center;
}

.library-title {
  margin: 8px 0 0;
  font-family: var(--display);
  font-weight: normal;
  font-size: 58px;
  line-height: 1;
}

.library-sub {
  margin: 14px auto 0;
  max-width: 30rem;
  font-size: 16px;
  line-height: 1.5;
}

.library-shelf {
  margin: 26px auto 0;
  /* a case of stacked shelves — rows flow downward, the card scrolls */
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
}

/* each row is a shelf of its own, on its own wooden board */
.shelf-row {
  display: flex;
  /* `safe` centres while there's room, then falls back to the start once
     the row overflows — so the first spine is never scrolled off-screen. */
  justify-content: safe center;
  align-items: flex-end;
  gap: 10px;
  max-width: 100%;
  padding: 0 10px 10px;
  overflow-x: auto;
  /* the shelf board */
  border-bottom: 10px solid #8a6a45;
  box-shadow: inset 0 -13px 0 -10px #6e5335;
}

.library-card:focus { outline: none; }

.library-book {
  /* Full width on a roomy card; shrink toward a floor as the shelf fills,
     so a growing shelf scales to fit rather than scrolling books off-screen.
     Only below the floor (a very narrow window) does overflow-x take over. */
  flex: 0 1 78px;
  min-width: 54px;
  height: 300px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 16px 6px 12px;
  border: 1px solid rgba(46, 36, 23, 0.55);
  border-radius: 3px 6px 1px 1px;
  background:
    linear-gradient(90deg,
      rgba(0, 0, 0, 0.28) 0, rgba(255, 255, 255, 0.12) 7%,
      rgba(0, 0, 0, 0.08) 14%, rgba(0, 0, 0, 0) 30%,
      rgba(0, 0, 0, 0.10) 92%, rgba(0, 0, 0, 0.30) 100%),
    var(--cloth, #4d5661);
  box-shadow: 2px 3px 6px rgba(46, 36, 23, 0.35);
  cursor: pointer;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}
.library-book:hover, .library-book:focus-visible {
  transform: translateY(-8px) rotate(-1.2deg);
  box-shadow: 3px 8px 14px rgba(46, 36, 23, 0.4);
}
@media (prefers-reduced-motion: reduce) {
  .library-book { transition: none; }
  .library-book:hover, .library-book:focus-visible { transform: none; }
}

.book-title {
  writing-mode: vertical-rl;
  max-height: 176px;
  overflow: hidden;
  font-family: var(--display);
  font-size: 14.5px;
  line-height: 1.1;
  letter-spacing: 0.03em;
  color: var(--lettering, #e6d59a);
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.35);
}

.book-author {
  writing-mode: vertical-rl;
  max-height: 74px;
  overflow: hidden;
  font-size: 8.5px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--lettering, #e6d59a);
  opacity: 0.85;
}

/* author (vertical), then a small horizontal date stamped low at the foot */
.book-foot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 13px;
}
.book-year {
  writing-mode: horizontal-tb;
  font-size: 7.5px;
  letter-spacing: 0.14em;
  font-variant-numeric: tabular-nums;
  color: var(--lettering, #e6d59a);
  opacity: 0.5;
}

.library-book-empty {
  background: transparent;
  border: 1px dashed var(--rule);
  box-shadow: none;
  cursor: default;
}
.library-book-empty:hover { transform: none; box-shadow: none; }
.library-book-empty .book-title {
  color: var(--ink-soft);
  opacity: 0.7;
  font-size: 14px;
  text-shadow: none;
}

.intro-back {
  display: inline-block;
  margin-top: 10px;
  font-size: 13px;
  font-style: italic;
  color: var(--ink-soft);
  text-decoration: none;
}
.intro-back:hover { color: var(--accent); text-decoration: underline; }

@media (max-width: 720px) {
  .library-card { padding: 24px 16px 18px; }
  .library-title { font-size: 42px; }
  .shelf-row { justify-content: safe flex-start; }
  .library-book { width: 70px; height: 260px; }
  .book-title { font-size: 15px; max-height: 150px; }
  .book-author { max-height: 82px; }
}

/* ---- boot error ---- */

.boot-error {
  position: absolute;
  z-index: 50;
  left: 50%;
  top: 24px;
  transform: translateX(-50%);
  max-width: min(440px, calc(100vw - 24px));
  padding: 12px 18px;
  background: var(--paper-bright);
  border: 1px solid var(--accent);
  border-left: 4px solid var(--accent);
  border-radius: 3px;
  box-shadow: var(--shadow);
  font-size: 15px;
}
.boot-error p { margin: 0; line-height: 1.5; }
.boot-error-keys { font-style: italic; color: var(--ink-soft); }

/* ---- focus + motion ---- */

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  #captions { transition: none; }
}

/* ---- mobile ---- */

@media (max-width: 720px) {
  body { font-size: 15px; }

  /* the rail dissolves; panels take their own mobile positions */
  #rail { display: contents; }
  #masthead, #legend, #places { position: absolute; }

  #masthead {
    top: 8px;
    left: 8px;
    right: auto;
    max-width: 200px;
    padding: 8px 12px 10px;
  }
  .masthead-title { font-size: 22px; }

  /* legend becomes a horizontal chip strip below the masthead */
  #legend {
    top: auto;
    bottom: 88px;
    left: 8px;
    right: 8px;
    width: auto;
    flex-direction: row;
    overflow-x: auto;
    touch-action: pan-x;
    -webkit-overflow-scrolling: touch;
    gap: 4px;
    scrollbar-width: none;
  }
  #legend::-webkit-scrollbar { display: none; }
  .legend-item { flex: none; min-height: 44px; padding: 4px 10px; }
  .legend-role { display: none; }
  /* No room in the chip strip; cards and the gazetteer carry the
     certainty language on mobile. */
  .map-key { display: none; }

  #places {
    top: auto;
    bottom: 8px;
    left: 8px;
    right: 8px;
    width: auto;
    max-height: 46vh;
    min-height: 0;
  }

  #captions { bottom: 152px; }
  .caption-line { font-size: 13px; }
  #recentre { bottom: 148px; font-size: 13px; }
  .intro-title { font-size: 40px; }
  .intro-card { padding: 26px 22px 20px; }

  #controls {
    bottom: 8px;
    width: calc(100vw - 16px);
    padding: 8px 10px;
    gap: 10px;
  }
  .chapter-title { display: none; }
  .clock-date { font-size: 16px; }
  .chapter-numeral { font-size: 12px; }
}

/* ============================================================
   MOBILE. Landscape is the designed experience; portrait is sent
   to turn. Gated on `html.touch` (set in the head from pointer:coarse
   / maxTouchPoints) so a small desktop window is never affected.
   ============================================================ */

/* ---- the rotate-to-read hint (portrait phones only) ---- */
#rotate-hint {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 200;
  align-items: center;
  justify-content: center;
  text-align: center;
  background: var(--paper);
  padding:
    calc(env(safe-area-inset-top) + 16px) calc(env(safe-area-inset-right) + 24px)
    calc(env(safe-area-inset-bottom) + 16px) calc(env(safe-area-inset-left) + 24px);
}
/* Two independent triggers, so it works even if the JS `.touch` class never
   lands: a real coarse pointer (any iPhone/Android) shows it on its own; the
   `.touch` class is the belt-and-braces (and what the preview can force). */
@media (orientation: portrait) and (max-width: 560px) and (any-pointer: coarse) {
  #rotate-hint:not(.dismissed) { display: flex; }
}
@media (orientation: portrait) and (max-width: 560px) {
  html.touch #rotate-hint:not(.dismissed) { display: flex; }
}
.rotate-inner { max-width: 20rem; }
.rotate-glyph svg { width: 108px; height: 108px; color: var(--ink); display: block; margin: 0 auto; }
.rotate-phone { transform-origin: 60px 60px; animation: rotate-turn 3.4s ease-in-out infinite; }
.rotate-arrow { opacity: 0.5; }
@keyframes rotate-turn {
  0%, 38% { transform: rotate(0deg); }
  58%, 88% { transform: rotate(-90deg); }
  100% { transform: rotate(0deg); }
}
.rotate-title {
  font-family: var(--display); font-weight: normal; font-size: 1.6rem;
  color: var(--ink); margin: 22px 0 6px; line-height: 1.15;
}
.rotate-sub { color: var(--ink-soft); margin: 0 0 24px; font-size: 1.02rem; }
.rotate-dismiss {
  background: none; border: none; color: var(--accent);
  font-family: var(--display); font-style: italic; font-size: 0.98rem;
  text-decoration: underline; cursor: pointer; padding: 12px; min-height: 44px;
}
@media (prefers-reduced-motion: reduce) {
  .rotate-phone { animation: none; transform: rotate(-90deg); }
}

/* ---- landscape phone: the designed layout ---- */
@media (orientation: landscape) and (max-height: 560px) {
  html.touch #rotate-hint { display: none; }

  /* keep every fixed panel clear of the notch */
  html.touch #rail { top: calc(env(safe-area-inset-top) + 8px); left: calc(env(safe-area-inset-left) + 8px); }
  html.touch .maplibregl-ctrl-top-right { margin-top: env(safe-area-inset-top); margin-right: env(safe-area-inset-right); }
  html.touch #controls { left: calc(env(safe-area-inset-left) + 8px); right: calc(env(safe-area-inset-right) + 8px); bottom: calc(env(safe-area-inset-bottom) + 6px); transform: none; width: auto; }
  html.touch #recentre { right: calc(env(safe-area-inset-right) + 10px); }

  /* reclaim height: a slimmer rail that scrolls rather than filling the screen */
  html.touch #rail { width: 200px; max-height: calc(100vh - 210px); overflow-y: auto; gap: 6px; }
  html.touch #rail .panel { padding: 8px 10px; }
  html.touch #masthead h1 { font-size: 26px; }
  html.touch .masthead-kicker, html.touch .masthead-byline { display: none; }
  html.touch #masthead { padding: 8px 12px 10px; }

  /* narration as a caption strip that clears the map's centre, not a floating slab */
  html.touch #storycard { max-width: min(70vw, 560px); }

  /* thumb-friendly controls */
  html.touch .scrub-step, html.touch .story-step,
  html.touch #controls button, html.touch #recentre { min-width: 44px; min-height: 44px; }
}

/* landscape phone — the narration as a caption strip along the foot, so the
   map above it stays clean (the camera reserves the same 122px in story.js) */
@media (orientation: landscape) and (max-height: 560px) {
  html.touch #storycard {
    left: calc(env(safe-area-inset-left) + 8px);
    right: calc(env(safe-area-inset-right) + 8px);
    bottom: calc(env(safe-area-inset-bottom) + 74px);
    transform: none;
    width: auto;
    max-width: none;
    gap: 6px;
  }
  html.touch .story-body { padding: 6px 14px 5px; }
  html.touch .story-title { font-size: 17px; margin-top: 1px; }
  html.touch .story-narration { font-size: 14px; line-height: 1.35; margin: 3px 0 0; }
  html.touch .story-kicker { font-size: 11px; }
  html.touch .story-progress { margin-top: 3px; }
}

/* landscape phone — the library shelf must fit a ~390px height, not run off
   the foot showing only the tops of the books */
@media (orientation: landscape) and (max-height: 560px) {
  html.touch .library-card { padding: 12px 18px 10px; max-height: calc(100vh - 12px); }
  html.touch .library-title { font-size: 30px; margin: 0; }
  html.touch .library-sub { font-size: 12px; line-height: 1.4; margin: 5px auto 0; max-width: 36rem; }
  html.touch .intro-kicker, html.touch .intro-hints { display: none; }
  /* On a short phone screen, collapse the stacked bookcase back to one
     horizontally-swiped shelf, so the whole collection sits on a single
     screen rather than scrolling down. The rows dissolve into one flex row
     (display: contents), and the board moves back onto the shelf itself. */
  html.touch .library-shelf {
    margin-top: 12px;
    flex-direction: row;
    align-items: flex-end;
    gap: 10px;
    overflow-x: auto;
    padding: 0 10px 10px;
    border-bottom: 10px solid #8a6a45;
    box-shadow: inset 0 -13px 0 -10px #6e5335;
    /* fade the right edge into the card so a half-cut spine shows there —
       the affordance that says the shelf swipes sideways for more */
    -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 30px), transparent);
    mask-image: linear-gradient(to right, #000 calc(100% - 30px), transparent);
  }
  html.touch .shelf-row { display: contents; }
  html.touch .library-book { height: 150px; }
  html.touch .book-title { font-size: 12px; max-height: 92px; }
  html.touch .book-author { font-size: 9px; max-height: 42px; }
}

/* ---- landscape phone: radical declutter for the journey + fixes ---- */
@media (orientation: landscape) and (max-height: 560px) {
  /* keep the spine text inside the shortened spines (was overflowing).
     The short spine can't carry a date too, so drop it here and give the
     author name the reclaimed room, so long names aren't curtailed. */
  html.touch .library-book { height: 178px; padding: 10px 5px 10px; overflow: hidden; }
  html.touch .book-title { font-size: 11px; max-height: 90px; line-height: 1.05; }
  html.touch .book-foot { gap: 0; }
  html.touch .book-year { display: none; }
  html.touch .book-author { font-size: 7.5px; max-height: 70px; letter-spacing: 0.04em; }

  /* the map attribution is required but must be a whisper, not a banner */
  html.touch .maplibregl-ctrl-attrib { font-size: 9px; line-height: 1.25; padding: 0 4px; }

  /* DURING A JOURNEY (not the overture): give the map the whole screen —
     drop the title/cast pane and the map toggle, offer a back button that
     returns to the top-level view (the overture, with the pane and cast) */
  html.touch body:not(.is-overture) #rail,
  html.touch body:not(.is-overture) .settings-pane { display: none; }
  html.touch body:not(.is-overture) #mobile-stop {
    display: flex; align-items: center; justify-content: center;
    position: absolute; z-index: 12;
    top: calc(env(safe-area-inset-top) + 8px);
    left: calc(env(safe-area-inset-left) + 8px);
    width: 44px; height: 44px; border-radius: 50%; padding: 0;
    background: var(--paper-bright); border: 1px solid var(--rule);
    box-shadow: var(--shadow); color: var(--ink); cursor: pointer;
  }

  /* a slimmer control bar */
  html.touch #controls { gap: 8px; padding: 5px 10px; }
  html.touch #controls .clock-date { font-size: 15px; }

  /* TOP LEVEL (the overture): the framing card must share the screen with the
     masthead nav, not cover it. Centred, it sat on top of Story/Explore/About;
     dock it clear of the left rail and let it scroll if the cast runs long, so
     the nav stays reachable and the back-button state feels like a real home. */
  html.touch body.is-overture .overture-panel {
    left: calc(env(safe-area-inset-left) + 216px);
    right: calc(env(safe-area-inset-right) + 8px);
    bottom: calc(env(safe-area-inset-bottom) + 8px);
    transform: none;
    width: auto;
    max-height: calc(100vh - 16px);
    overflow-y: auto;
  }
  /* keep the nav above the card even if a future layout makes them touch */
  html.touch body.is-overture #rail { z-index: 21; }
}
