/* The Journal of John Wesley, 1738 — chart-first visual system.
   Palette: Lamp Black #171E28 · Chart Linen #EFE6D0 · Candle #D9A441
            Oxblood #8C3B34 · Sea Grey #7C8B96
   Type: EB Garamond (display + entry prose) / Inter (chrome) — per HANDOFF.
   The map is the page; panels are ink glass laid over the chart. */

:root {
  --ink: #171E28;
  --ink-2: #232D3A;
  --glass: rgba(17, 22, 30, 0.90);
  --glass-soft: rgba(17, 22, 30, 0.72);
  --linen: #EFE6D0;
  --linen-dim: #B9AD92;
  --candle: #D9A441;
  --oxblood: #8C3B34;
  --sea: #7C8B96;
  --hairline: rgba(239, 230, 208, 0.16);
  --serif: "EB Garamond", Georgia, serif;
  --sans: "Inter", system-ui, sans-serif;
}

* { box-sizing: border-box; }

/* display:flex on components must not defeat the hidden attribute */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--ink);
  color: var(--linen);
  font-family: var(--serif);
  overflow: hidden;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
}

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

/* ---------- the chart ---------- */

#map {
  position: fixed;
  inset: 0;
  z-index: 0;
  background: var(--ink);
}

/* Voyager tiles toned to an aged chart; night falls for Aldersgate. */
#map .leaflet-tile-pane {
  filter: saturate(0.5) sepia(0.30) brightness(0.92) contrast(1.02);
  transition: filter 1.6s ease;
}
body.night #map .leaflet-tile-pane {
  filter: saturate(0.22) sepia(0.32) brightness(0.42) hue-rotate(-12deg) contrast(1.12);
}

.leaflet-container { font-family: var(--sans); }

.leaflet-control-attribution {
  background: var(--glass-soft) !important;
  color: var(--linen-dim) !important;
  font-size: 9.5px;
}
.leaflet-control-attribution a { color: var(--sea) !important; }

.leaflet-control-zoom a {
  background: var(--glass) !important;
  color: var(--linen) !important;
  border-color: var(--hairline) !important;
}

.chart-tip {
  background: var(--glass);
  border: 1px solid var(--hairline);
  color: var(--linen);
  font-family: var(--sans);
  font-size: 11px;
  letter-spacing: 0.04em;
  border-radius: 2px;
  padding: 3px 8px;
  box-shadow: none;
}
.chart-tip::before { display: none; }

/* The traveller: a candle-lit point moving along the inked route. */
.traveller {
  border-radius: 50%;
  background: var(--candle);
  border: 2px solid rgba(23, 30, 40, 0.85);
  box-shadow: 0 0 0 3px rgba(217, 164, 65, 0.35), 0 0 18px 4px rgba(217, 164, 65, 0.45);
}
@media (prefers-reduced-motion: no-preference) {
  .traveller { animation: breathe 3.2s ease-in-out infinite; }
  @keyframes breathe {
    0%, 100% { box-shadow: 0 0 0 3px rgba(217,164,65,.35), 0 0 14px 3px rgba(217,164,65,.4); }
    50%      { box-shadow: 0 0 0 4px rgba(217,164,65,.25), 0 0 24px 7px rgba(217,164,65,.55); }
  }
}

/* Lift the inked route off the chart when the knots get dense. */
.route-toggle {
  position: fixed;
  top: 60px;
  right: 20px;
  z-index: 15;
  font-family: var(--sans);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--linen-dim);
  background: var(--glass-soft);
  border: 1px solid var(--hairline);
  border-radius: 999px;
  padding: 7px 14px;
  backdrop-filter: blur(3px);
}
.route-toggle:hover { color: var(--candle); border-color: var(--candle); }
body.read .route-toggle { display: none; }

/* ---------- top bar ---------- */

.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 20;
  display: flex;
  align-items: baseline;
  gap: 14px;
  padding: 14px 20px 26px;
  background: linear-gradient(rgba(17,22,30,.82), rgba(17,22,30,0));
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }

.wordmark {
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--linen);
  margin: 0;
}
.wordmark .year {
  font-family: var(--serif);
  font-style: italic;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0.02em;
  font-size: 17px;
  color: var(--candle);
  margin-left: 10px;
}
.wordmark:hover .year { color: #E4B45C; }
.wordmark:hover { color: #FFF8E7; }

.topbar .spacer { flex: 1; }

.bar-btn {
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--linen-dim);
  padding: 6px 2px;
  border-bottom: 1px solid transparent;
}
.bar-btn:hover { color: var(--linen); border-bottom-color: var(--candle); }
a.bar-btn { text-decoration: none; }

/* ---------- reading drawer ---------- */

.drawer {
  position: fixed;
  top: 64px;
  left: 20px;
  width: min(408px, calc(100vw - 40px));
  /* Height follows the entry: short days leave the chart open; long days
     cap above the voyage bar and scroll, footer pinned. */
  max-height: calc(100vh - 64px - 108px);
  z-index: 10;
  background: var(--glass);
  border: 1px solid var(--hairline);
  border-radius: 3px;
  padding: 26px 28px 22px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--ink-2) transparent;
  backdrop-filter: blur(3px);
}

.panel-head { margin-bottom: 14px; }

.eyebrow {
  font-family: var(--sans);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--sea);
  margin: 0 0 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.badge {
  font-family: var(--sans);
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.14em;
  padding: 2px 6px;
  border-radius: 2px;
  border: 1px solid var(--hairline);
}
.coda-badge { color: var(--candle); border-color: rgba(217,164,65,.5); }
.ocr-badge  { color: var(--sea); }

.drawer .date {
  font-family: var(--serif);
  font-style: italic;
  font-weight: 400;
  font-size: 27px;
  line-height: 1.15;
  color: var(--candle);
  margin: 0 0 6px;
}
body.night .drawer .date { color: #E0B563; }

.place-link {
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--linen-dim);
  border-bottom: 1px solid var(--hairline);
  padding-bottom: 1px;
}
.place-link:hover { color: var(--linen); border-bottom-color: var(--candle); }

.setpiece-note {
  font-family: var(--serif);
  font-style: italic;
  font-size: 15px;
  color: #C4685F;
  margin: 0 0 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid rgba(140, 59, 52, 0.55);
}

.entry-text p {
  font-size: 17px;
  line-height: 1.68;
  margin: 0 0 1em;
  color: var(--linen);
}
.entry-text p:first-child::first-letter {
  font-size: 1.65em;
  line-height: 1;
  color: var(--candle);
}
body.night .entry-text p:first-child::first-letter { color: #C4685F; }

.people-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 14px 0 4px;
  padding-top: 14px;
  border-top: 1px solid var(--hairline);
}

.person-ref {
  font-family: var(--sans);
  font-size: 11px;
  letter-spacing: 0.05em;
  color: var(--linen-dim);
  border: 1px solid var(--hairline);
  border-radius: 999px;
  padding: 4px 11px;
}
.person-ref:hover { color: var(--linen); border-color: var(--candle); }

.source-line {
  font-family: var(--sans);
  font-size: 10px;
  letter-spacing: 0.06em;
  color: var(--sea);
  margin: 16px 0 0;
}

/* The page-turn: pinned to the drawer's foot, dates in hand. */
.day-nav {
  position: sticky;
  bottom: -22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 18px -28px -22px;
  padding: 10px 16px;
  background: rgba(14, 18, 25, 0.97);
  border-top: 1px solid var(--hairline);
}

.day-btn {
  font-family: var(--serif);
  font-style: italic;
  font-size: 16.5px;
  color: var(--candle);
  padding: 8px 12px;
  border-radius: 2px;
  white-space: nowrap;
}
.day-btn:hover { background: rgba(217, 164, 65, 0.12); }
.day-btn.ghost { visibility: hidden; }

.day-hint {
  font-family: var(--sans);
  font-size: 9.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--sea);
  white-space: nowrap;
}
@media (max-width: 880px) {
  .day-nav { margin: 18px -20px -16px; bottom: -16px; }
  .day-hint { display: none; }
}

/* place drawer specifics */
.modern-name {
  font-family: var(--sans);
  font-size: 11px;
  letter-spacing: 0.05em;
  color: var(--sea);
  margin: 2px 0 0;
}
.place-note {
  font-size: 15px;
  font-style: italic;
  line-height: 1.55;
  color: var(--linen-dim);
  margin: 0 0 14px;
}
.visit-count {
  font-family: var(--sans);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--sea);
  margin: 0 0 8px;
}
.visit-list { list-style: none; margin: 0; padding: 0; }
.visit-list li + li { border-top: 1px solid var(--hairline); }
.visit {
  display: block;
  width: 100%;
  text-align: left;
  padding: 10px 2px;
}
.visit:hover .v-date { color: var(--candle); }
.v-date {
  display: block;
  font-family: var(--serif);
  font-style: italic;
  font-size: 16px;
  color: var(--linen);
}
.v-snip {
  display: block;
  font-size: 13.5px;
  line-height: 1.45;
  color: var(--linen-dim);
  margin-top: 2px;
}

/* ---------- voyage bar ---------- */

.voyage {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 20;
  display: flex;
  align-items: stretch;
  gap: 0;
  background: var(--glass);
  border-top: 1px solid var(--hairline);
  backdrop-filter: blur(3px);
}

.nav-cluster {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 0 10px 0 14px;
  border-right: 1px solid var(--hairline);
}

.nav-btn {
  font-size: 20px;
  line-height: 1;
  color: var(--linen-dim);
  padding: 10px 8px;
}
.nav-btn:hover:not(:disabled) { color: var(--candle); }
.nav-btn:disabled { opacity: 0.3; cursor: default; }

#readout {
  font-family: var(--serif);
  font-style: italic;
  font-size: 15px;
  color: var(--linen);
  min-width: 190px;
  padding: 0 12px;
  display: flex;
  align-items: center;
  border-right: 1px solid var(--hairline);
  white-space: nowrap;
}

#segments {
  flex: 1;
  display: flex;
  min-width: 0;
}

.segment {
  flex-basis: 0;
  min-width: 0;
  padding: 9px 12px 11px;
  border-right: 1px solid var(--hairline);
  overflow: hidden;
}
.segment:last-child { border-right: none; }
/* Aldersgate is five entries wide but must keep its name */
.segment[data-mv="3"] { flex-shrink: 0; min-width: 134px; }

.seg-label {
  display: block;
  font-family: var(--sans);
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--sea);
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
  margin-bottom: 7px;
}
.seg-num { color: var(--candle); margin-right: 4px; }

.ticks {
  display: flex;
  align-items: flex-end;
  gap: 3px;
}

.tick {
  width: 4px;
  height: 12px;
  background: rgba(124, 139, 150, 0.55);
  border-radius: 1px;
  flex: none;
  transition: background 0.2s, height 0.2s;
}
.tick:hover { background: var(--linen); }
.tick.current { background: var(--candle); height: 17px; }
.tick.flame { background: var(--oxblood); height: 15px; }
.tick.flame.current { background: #C4685F; height: 19px; }
.tick.coda { background: rgba(217, 164, 65, 0.6); }
.tick.coda.current { background: var(--candle); height: 17px; }

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

.overture {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  background:
    radial-gradient(ellipse at 50% 42%, rgba(23,30,40,.55) 0%, rgba(17,22,30,.94) 78%);
  transition: opacity 0.9s ease;
}
.overture.gone { opacity: 0; pointer-events: none; }

.overture .ov-eyebrow {
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--sea);
  margin: 0 0 18px;
}

.overture h1 {
  font-family: var(--serif);
  font-weight: 400;
  font-size: clamp(44px, 7vw, 76px);
  line-height: 1.04;
  margin: 0 0 8px;
  color: var(--linen);
}
.overture h1 .yr {
  display: block;
  font-style: italic;
  color: var(--candle);
}

.overture .invitation {
  max-width: 34em;
  font-size: 18px;
  line-height: 1.6;
  font-style: italic;
  color: var(--linen-dim);
  margin: 18px 0 34px;
}

.ov-actions { display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; }

.ov-btn {
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  padding: 13px 26px;
  border: 1px solid var(--candle);
  border-radius: 2px;
  color: var(--candle);
  transition: background 0.2s, color 0.2s;
}
.ov-btn.primary { background: var(--candle); color: var(--ink); }
.ov-btn.primary:hover { background: #E4B45C; }
.ov-btn.quiet { border-color: var(--hairline); color: var(--linen-dim); }
.ov-btn.quiet:hover { color: var(--linen); border-color: var(--linen-dim); }

.ov-colophon {
  position: absolute;
  bottom: 20px;
  font-family: var(--sans);
  font-size: 10px;
  letter-spacing: 0.06em;
  color: var(--sea);
}
.ov-colophon a { color: var(--sea); }

/* ---------- person dossier ---------- */

.person-pop {
  position: fixed;
  z-index: 50;
  width: min(400px, calc(100vw - 24px));
  background: var(--glass);
  border: 1px solid var(--hairline);
  border-top: 2px solid var(--candle);
  border-radius: 2px;
  padding: 18px 20px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}
.person-pop h3 {
  font-family: var(--serif);
  font-style: italic;
  font-weight: 400;
  font-size: 21px;
  color: var(--candle);
  margin: 0 0 2px;
}
.person-pop .dates {
  font-family: var(--sans);
  font-size: 10.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--sea);
  margin: 0 0 10px;
}
.person-pop .ident {
  font-size: 14.5px;
  line-height: 1.55;
  color: var(--linen);
  margin: 0;
  max-height: 180px;
  overflow-y: auto;
}
.person-pop .more { margin: 10px 0 0; font-family: var(--sans); font-size: 11px; }
.person-pop .more a { color: var(--candle); }

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

.about-pop {
  position: fixed;
  top: 52px;
  right: 20px;
  z-index: 45;
  width: min(380px, calc(100vw - 40px));
  background: var(--glass);
  border: 1px solid var(--hairline);
  border-radius: 2px;
  padding: 18px 20px;
}
.about-pop p {
  font-size: 14.5px;
  line-height: 1.55;
  color: var(--linen);
  margin: 0 0 10px;
}
.about-pop p:last-child { margin-bottom: 0; }
.about-pop a { color: var(--candle); }
.about-pop .fine {
  font-family: var(--sans);
  font-size: 10.5px;
  color: var(--sea);
}

/* ---------- empty state ---------- */

.empty-state {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--ink);
  font-size: 16px;
  color: var(--linen-dim);
  padding: 24px;
  text-align: center;
}

/* ---------- read mode: the plain scholarly scroll ---------- */

body.read { overflow: auto; background: #F4EDDD; }
body.read #map,
body.read .drawer,
body.read .voyage { display: none; }
body.read .topbar {
  background: linear-gradient(rgba(244, 237, 221, 0.96), rgba(244, 237, 221, 0));
}
body.read .wordmark { color: #2B2417; }
body.read .wordmark .year { color: #8C6A2F; }
body.read .bar-btn { color: #7A6E55; }
body.read .bar-btn:hover { color: #2B2417; }

#read-view {
  max-width: 660px;
  margin: 0 auto;
  padding: 92px 24px 120px;
  color: #2B2417;
}

#read-view .movement-head {
  font-family: var(--serif);
  font-weight: 400;
  font-style: italic;
  font-size: 34px;
  color: #2B2417;
  margin: 70px 0 8px;
  padding-top: 26px;
  border-top: 2px solid #8C6A2F;
}
#read-view .movement-head:first-child { margin-top: 0; }
#read-view .movement-head .mv-num {
  font-style: normal;
  font-family: var(--sans);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.2em;
  color: #8C6A2F;
  display: block;
  margin-bottom: 6px;
}
#read-view .movement-head .span {
  display: block;
  font-family: var(--sans);
  font-style: normal;
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #7A6E55;
  margin-top: 6px;
}

#read-view .entry { margin: 44px 0; }
#read-view .entry .place {
  font-family: var(--sans);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: #8C6A2F;
  margin: 0 0 2px;
}
#read-view .entry .r-date {
  font-family: var(--serif);
  font-style: italic;
  font-size: 23px;
  margin: 0 0 10px;
  color: #2B2417;
  display: flex;
  align-items: center;
  gap: 8px;
}
#read-view .entry .text {
  font-size: 17.5px;
  line-height: 1.68;
  margin: 0 0 1em;
}
#read-view .entry .with {
  font-family: var(--sans);
  font-size: 12px;
  color: #7A6E55;
}
#read-view .entry .with .person-ref {
  color: #6B5B33;
  border-color: rgba(140, 106, 47, 0.4);
}
#read-view .badge { border-color: rgba(43, 36, 23, 0.25); }
#read-view .coda-badge { color: #8C6A2F; }
#read-view .ocr-badge { color: #7A6E55; }
#read-view .locate { margin: 6px 0 0; }
#read-view .locate .visit {
  font-family: var(--sans);
  font-size: 11.5px;
  letter-spacing: 0.04em;
  color: #8C6A2F;
  padding: 0;
  width: auto;
}
#read-view .locate .visit:hover { text-decoration: underline; }

body.read .person-pop {
  background: #FBF6E9;
  border-color: rgba(43, 36, 23, 0.2);
  color: #2B2417;
}
body.read .person-pop .ident { color: #2B2417; }

/* ---------- small screens ---------- */

@media (max-width: 880px) {
  .drawer {
    top: auto;
    left: 0;
    right: 0;
    bottom: 88px;
    width: 100%;
    max-height: 44vh;
    border-radius: 10px 10px 0 0;
    border-left: none;
    border-right: none;
    padding: 20px 20px 16px;
  }
  #readout { display: none; }
  .seg-label { font-size: 8.5px; letter-spacing: 0.08em; }
  .segment { padding: 8px 7px 9px; }
  .segment[data-mv="3"] { min-width: 88px; }
  .ticks { gap: 2px; }
  .tick { width: 3px; }
  .topbar { padding: 12px 14px 22px; gap: 10px; }
  .wordmark { font-size: 9px; letter-spacing: 0.14em; white-space: nowrap; }
  .wordmark .year { font-size: 14px; margin-left: 7px; }
  .bar-btn { font-size: 10px; letter-spacing: 0.08em; white-space: nowrap; }
  .overture h1 { font-size: clamp(38px, 11vw, 56px); }
}

@media (prefers-reduced-motion: reduce) {
  #map .leaflet-tile-pane { transition: none; }
  .overture { transition: none; }
}
