:root {
  --night: #0e0c0a;
  --panel: rgba(20, 16, 12, 0.82);
  --line: rgba(214, 177, 96, 0.28);
  --gold: #d6b160;
  --gold-soft: #b8975a;
  --cream: #f1e8d8;
  --muted: #b9ac98;
  --on-gold: #1b140a;
  --gold-hover: #e3c27a;
  --tint: rgba(255, 255, 255, 0.04);
  --wash: rgba(214, 177, 96, 0.12);
  --glow-1: #2a2118;
  --glow-2: #15110d;
  --shadow: rgba(0, 0, 0, 0.5);
  --text-scale: 1;
  color-scheme: dark;
  --panel-w: 400px;
  --gap: 24px;
  --display: "Cormorant Garamond", "Iowan Old Style", Georgia, serif;
  --text: "EB Garamond", "Iowan Old Style", Georgia, serif;
}

:root[data-theme="light"] {
  --night: #e4d9c6;
  --panel: rgba(255, 251, 243, 0.9);
  --line: rgba(128, 94, 30, 0.3);
  --gold: #85601a;
  --gold-soft: #8b6c33;
  --cream: #2a2118;
  --muted: #655948;
  --on-gold: #fffaf0;
  --gold-hover: #6f4f12;
  --tint: rgba(60, 40, 10, 0.05);
  --wash: rgba(133, 96, 26, 0.12);
  --glow-1: #fffaf0;
  --glow-2: #f1e8d8;
  --shadow: rgba(60, 40, 10, 0.22);
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--night);
  color: var(--cream);
  font-family: var(--text);
  font-size: 18px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

body {
  background:
    radial-gradient(ellipse 70% 80% at 62% 45%, var(--glow-1) 0%, var(--glow-2) 55%, var(--night) 100%);
}

button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

/* ---------- viewer ---------- */

#viewer {
  position: fixed !important; /* the map library sets its own inline position */
  inset: 0;
  z-index: 0; /* keeps the map's own layers underneath the panel */
  background: var(--night);
  font: inherit;
}
/* Tint the map to sit with the page: night in the dark theme, parchment in the light one. */
.leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) sepia(0.45) saturate(0.7) brightness(0.82) contrast(0.92); }
:root[data-theme="light"] .leaflet-tile-pane { filter: sepia(0.3) saturate(0.75); }
.leaflet-container .leaflet-control-attribution {
  margin: 0 var(--gap) 8px 0;
  padding: 0 6px;
  border-radius: 3px;
  background: var(--panel);
  color: var(--muted);
  font-family: var(--text);
  font-size: 12.5px;
}
.leaflet-container .leaflet-control-attribution a { color: var(--gold-soft); }
.leaflet-marker-icon.dot:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; border-radius: 50%; }

/* ---------- golden points ---------- */

.dot {
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  background: none;
  display: grid;
  place-items: center;
  transition: opacity 0.5s ease;
}
.dot i {
  position: relative;
  display: block;
  width: 19px;
  height: 19px;
  border-radius: 50%;
  background: #e2b84f;
  border: 3px solid #fffaf0;
  box-shadow: 0 0 0 1.5px rgba(0, 0, 0, 0.7), 0 0 12px 3px rgba(255, 226, 150, 0.55), 0 2px 8px rgba(0, 0, 0, 0.7);
  transition: transform 0.2s ease;
}
.dot i::after {
  content: "";
  position: absolute;
  inset: -11px;
  border-radius: 50%;
  border: 2px solid rgba(255, 244, 214, 0.95);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35);
  animation: pulse 2.6s ease-out infinite;
}
.dot:hover i, .dot:focus-visible i { transform: scale(1.3); }
.dot span {
  position: absolute;
  left: 50%;
  bottom: 100%;
  transform: translate(-50%, 4px);
  padding: 2px 10px;
  border-radius: 999px;
  background: rgba(14, 12, 10, 0.9);
  color: #f1e8d8;
  border: 1px solid rgba(214, 177, 96, 0.28);
  font-family: var(--display);
  font-size: 15px;
  letter-spacing: 0.04em;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.dot:hover span, .dot:focus-visible span { opacity: 1; transform: translate(-50%, 0); }
.dot.is-active i { transform: scale(1.35); background: #fffaf0; border-color: #e2b84f; }
body.zoomed .dot:not(.is-active) { opacity: 0.85; }

@keyframes pulse {
  0% { transform: scale(0.6); opacity: 0.9; }
  100% { transform: scale(1.7); opacity: 0; }
}

/* ---------- panel ---------- */

#panel {
  position: fixed;
  z-index: 2;
  top: var(--gap);
  left: var(--gap);
  bottom: var(--gap);
  width: var(--panel-w);
  display: flex;
  flex-direction: column;
  padding: 22px 28px 20px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 20px 60px var(--shadow);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}
.brand {
  margin: 0;
  font-family: var(--display);
  font-size: 15px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--gold);
}
.tools { display: flex; align-items: center; gap: 2px; }
.tool {
  min-width: 28px;
  height: 28px;
  padding: 0 5px;
  display: grid;
  grid-auto-flow: column;
  place-items: center;
  border: 1px solid transparent;
  border-radius: 999px;
  background: none;
  font-family: var(--display);
  font-size: 17px;
  font-weight: 600;
  line-height: 1;
  color: var(--muted);
}
.tool small { font-size: 13px; margin-left: 1px; }
.tool svg { width: 16px; height: 16px; }
.tool:hover:not(:disabled) { color: var(--gold); border-color: var(--line); }
.tool:disabled { opacity: 0.35; cursor: default; }
:root[data-theme="light"] .tool .sun, :root:not([data-theme="light"]) .tool .moon { display: none; }
.lang { display: flex; gap: 2px; margin-left: 6px; padding-left: 8px; border-left: 1px solid var(--line); }
.lang button {
  padding: 2px 9px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: none;
  font-family: var(--display);
  font-size: 14px;
  letter-spacing: 0.12em;
  color: var(--muted);
}
.lang button[aria-pressed="true"] { color: var(--gold); border-color: var(--line); }

#story {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 26px 4px 12px 0;
  font-size: calc(1em * var(--text-scale));
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
  transition: opacity 0.28s ease, transform 0.28s ease;
}
#story.out { opacity: 0; transform: translateY(8px); }

.eyebrow {
  margin: 0 0 6px;
  font-family: var(--display);
  font-size: 0.78em;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--gold-soft);
}
#story h1 {
  margin: 0 0 18px;
  font-family: var(--display);
  font-weight: 600;
  font-size: 2.11em;
  line-height: 1.08;
  text-wrap: balance;
}
#story p { margin: 0 0 14px; text-wrap: pretty; }
#story em { font-style: italic; }

.photo { margin: 0 0 18px; }
.photo img {
  display: block;
  width: 100%;
  max-height: 300px;
  object-fit: cover;
  object-position: 50% 22%;
  border-radius: 4px;
  border: 1px solid var(--line);
}
.photo figcaption { margin-top: 5px; font-size: 0.66em; line-height: 1.3; color: var(--muted); opacity: 0.85; }
.photo figcaption a { color: inherit; }

.links { display: flex; flex-wrap: wrap; gap: 8px; margin: 20px 0 0 !important; }
.links a {
  padding: 4px 14px 5px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--tint);
  font-family: var(--display);
  font-size: 0.9em;
  letter-spacing: 0.03em;
  color: var(--gold);
  text-decoration: none;
}
.links a:hover { background: var(--wash); border-color: var(--gold-soft); }
.quote span { display: block; margin-top: 6px; font-size: 0.62em; font-style: normal; letter-spacing: 0.14em; text-transform: uppercase; color: var(--gold-soft); }

#story h2.sub {
  margin: 24px 0 10px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  font-family: var(--display);
  font-weight: 500;
  font-size: 0.78em;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--gold-soft);
}
#story sup { font-size: 0.62em; line-height: 0; color: var(--gold); padding-left: 1px; }
#story strong { font-weight: 600; color: var(--gold); }
.refs { margin: 0; padding-left: 20px; font-size: 0.8em; line-height: 1.4; color: var(--muted); }
.refs li { margin-bottom: 7px; }
.refs li::marker { color: var(--gold-soft); }
.refs a { color: var(--gold); text-decoration: none; }
.refs a:hover { text-decoration: underline; }

.facts { margin: 22px 0 0; padding: 0; border-top: 1px solid var(--line); }
.facts div {
  display: grid;
  grid-template-columns: 5.3em 1fr;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.facts dt {
  font-family: var(--display);
  font-size: 0.78em;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--gold-soft);
  padding-top: 3px;
}
.facts dd { margin: 0; font-size: 0.94em; line-height: 1.4; }

.quote {
  margin: 24px 0 0 !important;
  font-family: var(--display);
  font-style: italic;
  font-size: 1.28em;
  line-height: 1.25;
  color: var(--gold);
}
.hint { margin-top: 20px !important; font-size: 0.86em; color: var(--muted); }

/* ---------- tour controls ---------- */

.tour {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}
.tour .count {
  margin-left: auto;
  font-family: var(--display);
  font-size: 16px;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.pill, .round {
  height: 40px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--tint);
  font-family: var(--display);
  font-size: 17px;
  letter-spacing: 0.04em;
  transition: background 0.2s ease, border-color 0.2s ease;
}
.pill { padding: 0 16px; white-space: nowrap; }
.round { width: 40px; padding: 0; display: grid; place-items: center; flex: none; }
.pill:hover, .round:hover { background: var(--wash); border-color: var(--gold-soft); }
.pill.primary { background: var(--gold); border-color: var(--gold); color: var(--on-gold); font-weight: 600; }
.pill.primary:hover { background: var(--gold-hover); border-color: var(--gold-hover); }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
[hidden] { display: none !important; }

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 14px;
  max-height: 22vh;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}
.chips button {
  padding: 1px 11px 2px;
  border-radius: 999px;
  border: 1px solid transparent;
  background: var(--tint);
  font-size: 15.5px;
  color: var(--muted);
}
.chips button:hover { color: var(--cream); border-color: var(--line); }
.chips button[aria-current="true"] { color: var(--gold); border-color: var(--gold-soft); background: none; }

/* ---------- zoom buttons & credit ---------- */

.zoomctl {
  position: fixed;
  z-index: 2;
  right: var(--gap);
  bottom: calc(var(--gap) + 22px);
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  overflow: hidden;
}
.zoomctl button {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 0;
  background: none;
}
.zoomctl button + button { border-top: 1px solid var(--line); }
.zoomctl button:hover { background: var(--wash); }

.debug-read {
  position: fixed; top: 8px; right: 8px; padding: 4px 8px;
  background: #000; color: #5ff; font: 12px monospace; z-index: 10;
}

/* ---------- phones & narrow windows: panel becomes a bottom sheet ---------- */

@media (max-width: 860px) {
  html, body { font-size: 16.5px; }
  #panel {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    height: 46dvh;
    padding: 12px 18px calc(12px + env(safe-area-inset-bottom));
    border-radius: 14px 14px 0 0;
    border-width: 1px 0 0;
  }
  .panel-head { padding-bottom: 8px; }
  .brand { font-size: 13px; }
  #story { padding-top: 14px; }
  #story h1 { font-size: 1.76em; margin-bottom: 12px; }
  .facts div { grid-template-columns: 5.1em 1fr; padding: 8px 0; }
  .quote { font-size: 1.21em; }
  .brand { letter-spacing: 0.14em; }
  .tour { padding-top: 10px; }
  .chips { display: none; }
  .zoomctl { top: 12px; right: 12px; bottom: auto; }
  .leaflet-container .leaflet-bottom { bottom: 46dvh; }
  /* Tint the map to sit with the page: night in the dark theme, parchment in the light one. */
.leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) sepia(0.45) saturate(0.7) brightness(0.82) contrast(0.92); }
:root[data-theme="light"] .leaflet-tile-pane { filter: sepia(0.3) saturate(0.75); }
.leaflet-container .leaflet-control-attribution { margin: 0 6px 6px 0; font-size: 11px; }
  .photo img { max-height: 210px; }
  .dot span { display: none; }
  .dot i { width: 13px; height: 13px; border-width: 2px; }
  .dot i::after { inset: -7px; }
}

@media (prefers-reduced-motion: reduce) {
  .dot i::after { animation: none; opacity: 0.6; }
  #story { transition: none; }
}
