/* ==========================================================================
   Cacao & Empire: antique-map styles
   Colors are defined once here as variables so they are easy to change.
   ========================================================================== */

:root {
  --parchment: #f1e4c6;
  --parchment-dark: #dcc79c;
  --land: #ead8ae;
  --land-stroke: #8b6b3e;
  --border-stroke: #b59a6c;
  --sea: #a4b7b7;
  --sea-edge: #7f9796;
  --graticule: rgba(80, 60, 30, 0.16);

  --ink: #2b1a10;
  --ink-soft: #5b4330;
  --choc: #3b2314;
  --choc-2: #5a3620;
  --gold: #b8892b;
  --gold-light: #e0bd6a;
  --cream: #f8efd9;
  --todo-bg: rgba(184, 137, 43, 0.18);

  --route-ocean: #7a2f14;
  --route-land: #8a5a1f;

  --font-display: "IM Fell English", "Iowan Old Style", Georgia, serif;
  --font-sc: "IM Fell English SC", "IM Fell English", Georgia, serif;
  --font-body: "EB Garamond", Garamond, Georgia, "Times New Roman", serif;

  --topbar-h: 56px;
  --panel-w: min(440px, 42vw);
  --sheet-h: 58dvh;
  --ease: cubic-bezier(0.22, 0.8, 0.26, 1);
}

*,
*::before,
*::after { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #cdb88c;
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 18px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; color: inherit; }

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

[hidden] { display: none !important; }

/* ---------- Map ---------- */

.map {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse at center, rgba(0, 0, 0, 0) 55%, rgba(60, 35, 15, 0.35) 100%),
    #cdb88c;
}

.map-svg,
.routes-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* Detailed map, drawn when the camera is still. Fades in over the base map. */
.detail-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.25s ease;
}
.detail-canvas.is-ready { opacity: 1; transition-duration: 0.7s; }

.labels {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.25s ease;
}
.labels.is-ready { opacity: 1; transition-duration: 0.9s; transition-delay: 0.15s; }

.map-label {
  position: absolute;
  left: 0;
  top: 0;
  white-space: nowrap;
  line-height: 1.1;
  font-family: var(--font-display);
  font-style: italic;
  color: var(--ink-soft);
  text-shadow: 0 0 3px var(--parchment), 0 0 6px var(--parchment), 0 0 2px var(--parchment);
}
.label-ocean {
  font-size: 24px;
  letter-spacing: 0.42em;
  text-transform: uppercase;
  color: rgba(52, 78, 90, 0.72);
  text-shadow: none;
}
.label-sea {
  font-size: 18px;
  letter-spacing: 0.34em;
  text-transform: uppercase;
  color: rgba(52, 78, 90, 0.72);
  text-shadow: none;
}
.label-island,
.label-region { font-size: 15px; letter-spacing: 0.08em; color: var(--choc); }
.label-mountain { font-size: 14px; color: var(--choc-2); }
.label-mountain::before { content: "\25B2\00a0"; font-style: normal; font-size: 0.8em; color: var(--land-stroke); }
.label-river { font-size: 13px; letter-spacing: 0.06em; color: #2f6072; }
.label-place { font-size: 14px; color: var(--ink); }

.map-svg { cursor: grab; touch-action: none; }
.map-svg:active { cursor: grabbing; }
.routes-svg { pointer-events: none; overflow: visible; }

.sphere {
  fill: var(--sea);
  stroke: var(--sea-edge);
  stroke-width: 1.5;
  vector-effect: non-scaling-stroke;
}
.graticule {
  fill: none;
  stroke: var(--graticule);
  stroke-width: 0.7;
  vector-effect: non-scaling-stroke;
}
.land {
  fill: var(--land);
  stroke: var(--land-stroke);
  stroke-width: 0.9;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}
.borders {
  fill: none;
  stroke: var(--border-stroke);
  stroke-width: 0.6;
  stroke-dasharray: 2 2;
  vector-effect: non-scaling-stroke;
}

.paper-texture {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 5;
  opacity: 0.35;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0.45 0 0 0 0 0.33 0 0 0 0 0.18 0 0 0 0.35 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

.compass {
  position: fixed;
  right: 18px;
  bottom: 18px;
  width: 96px;
  height: 96px;
  z-index: 6;
  pointer-events: none;
  opacity: 0.8;
  transition: transform 0.5s var(--ease);
}
.compass-ring { fill: none; stroke: var(--choc-2); stroke-width: 1.4; }
.compass-ring.thin { stroke-width: 0.6; }
.compass-star { fill: var(--gold); stroke: var(--choc-2); stroke-width: 0.8; }
.compass-star.dark { fill: var(--choc-2); }
.compass-n {
  font-family: var(--font-display);
  font-size: 12px;
  fill: var(--choc);
  text-anchor: middle;
}
body.panel-open .compass { transform: translateX(calc(-1 * var(--panel-w))); }

/* ---------- Routes ---------- */

.route { transition: opacity 0.6s ease; }
.route.is-hidden { display: none; }
.route.is-dim { opacity: 0.35; }

.route-halo {
  fill: none;
  stroke: rgba(248, 239, 217, 0.75);
  stroke-width: 6;
  stroke-linecap: round;
}
.route-line {
  fill: none;
  stroke-width: 2.6;
  stroke-linecap: round;
}
.route.ocean .route-line { stroke: var(--route-ocean); }
.route.land .route-line { stroke: var(--route-land); stroke-width: 3; }

.route.ocean .route-line.flow {
  stroke-dasharray: 9 6;
  animation: flow-ocean 1.1s linear infinite;
}
.route.land .route-line.flow {
  stroke-dasharray: 0.1 7;
  animation: flow-land 0.9s linear infinite;
}
@keyframes flow-ocean { to { stroke-dashoffset: -15; } }
@keyframes flow-land { to { stroke-dashoffset: -7.1; } }

.arrow-ocean { fill: var(--route-ocean); }
.arrow-land { fill: var(--route-land); }

.ship { transition: opacity 0.6s ease; }
.ship-bob {
  transform-box: fill-box;
  transform-origin: 50% 88%;
  animation: bob 2.6s ease-in-out infinite;
}
@keyframes bob {
  0%, 100% { transform: translateY(0) rotate(-1.4deg); }
  50% { transform: translateY(-1.4px) rotate(1.4deg); }
}
.ship-hull { fill: #6d4528; stroke: #2b1a10; stroke-width: 0.9; stroke-linejoin: round; }
.ship-lower { fill: #2f1d12; }
.ship-wale { fill: none; stroke: #c9a043; stroke-width: 1.2; stroke-linecap: round; }
.ship-plank { fill: none; stroke: rgba(20, 10, 4, 0.4); stroke-width: 0.5; }
.ship-port { fill: #1d120b; }
.ship-window { fill: #ecd9a2; }
.ship-sail { fill: #f4ead0; stroke: #5b4330; stroke-width: 0.7; stroke-linejoin: round; }
.ship-spar { fill: none; stroke: #3a2616; stroke-width: 1.1; stroke-linecap: round; }
.ship-rig { fill: none; stroke: #3a2616; stroke-width: 0.45; opacity: 0.75; }
.ship-ensign { fill: #fbf8ee; stroke: #5b4330; stroke-width: 0.5; stroke-linejoin: round; }
.ship-pennant { fill: #9c2a1a; }
.ship-wake { fill: none; stroke: rgba(255, 255, 255, 0.9); stroke-width: 1.3; stroke-linecap: round; }
.ship-foam { fill: none; stroke: rgba(255, 255, 255, 0.95); stroke-width: 1.2; stroke-linecap: round; }

/* ---------- Stop markers ---------- */

.markers {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.marker {
  position: absolute;
  left: 0;
  top: 0;
  width: 32px;
  height: 32px;
  margin: -16px 0 0 -16px;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  pointer-events: auto;
  will-change: transform;
}
.marker:focus-visible { outline: none; }

.marker-dot {
  position: absolute;
  inset: 8px;
  border-radius: 50%;
  background: var(--choc-2);
  border: 2px solid var(--gold-light);
  box-shadow: 0 1px 3px rgba(40, 20, 5, 0.5);
  transition: transform 0.3s var(--ease), background 0.3s;
}
.marker:hover .marker-dot { transform: scale(1.2); }
.marker:focus-visible .marker-dot {
  box-shadow: 0 0 0 3px var(--cream), 0 0 0 6px var(--choc);
}

.marker.is-locked { cursor: default; opacity: 0.55; }
.marker.is-locked .marker-dot {
  background: #9e8a68;
  border-color: #cdbb95;
  transform: scale(0.75);
}

.marker.is-next .marker-dot {
  background: var(--gold);
  border-color: var(--cream);
  animation: glow 1.6s ease-in-out infinite;
}
.marker.is-next::before,
.marker.is-next::after {
  content: "";
  position: absolute;
  inset: 8px;
  border-radius: 50%;
  border: 2px solid var(--gold);
  animation: ripple 1.8s ease-out infinite;
  pointer-events: none;
}
.marker.is-next::after { animation-delay: 0.9s; }

.marker.is-current .marker-dot {
  background: var(--gold-light);
  border-color: var(--choc);
  transform: scale(1.3);
}

@keyframes ripple {
  from { transform: scale(1); opacity: 0.9; }
  to { transform: scale(3.2); opacity: 0; }
}
@keyframes glow {
  0%, 100% { box-shadow: 0 0 4px 1px rgba(224, 189, 106, 0.6); }
  50% { box-shadow: 0 0 14px 6px rgba(224, 189, 106, 0.95); }
}

.marker-label {
  position: absolute;
  top: 50%;
  left: 100%;
  transform: translateY(-50%);
  white-space: nowrap;
  font-family: var(--font-display);
  font-size: 16px;
  line-height: 1.1;
  color: var(--ink);
  padding: 2px 6px;
  border-radius: 3px;
  background: rgba(241, 228, 198, 0.88);
  box-shadow: 0 1px 2px rgba(40, 20, 5, 0.25);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
}
.label-left .marker-label { left: auto; right: 100%; }
.label-top .marker-label { top: auto; bottom: 100%; left: 50%; transform: translateX(-50%); }
.label-bottom .marker-label { top: 100%; left: 50%; transform: translateX(-50%); }

/* Every stop reached so far keeps its name beside its pin, at any zoom. */
.marker.is-visited .marker-label,
.marker.is-next .marker-label,
.marker.is-current .marker-label,
.marker:hover .marker-label,
.marker:focus-visible .marker-label { opacity: 1; }
.marker.label-hidden:not(:hover):not(:focus-visible) .marker-label { opacity: 0; }

/* ---------- Top bar ---------- */

.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--topbar-h);
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 14px;
  padding-top: env(safe-area-inset-top);
  background: linear-gradient(180deg, var(--choc) 0%, #2c190d 100%);
  border-bottom: 2px solid var(--gold);
  color: var(--cream);
  box-shadow: 0 2px 10px rgba(30, 15, 5, 0.35);
}

.topbar-title {
  flex: 1;
  margin: 0;
  font-family: var(--font-display);
  font-size: 22px;
  letter-spacing: 0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--gold-light);
}

.topbar-actions { display: flex; gap: 8px; }

.year-badge {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 88px;
  padding: 2px 10px;
  border: 1.5px solid var(--gold);
  border-radius: 999px;
  background: rgba(248, 239, 217, 0.08);
  line-height: 1.05;
}
.year-badge-label {
  font-family: var(--font-sc);
  font-size: 11px;
  letter-spacing: 0.12em;
  color: var(--gold-light);
}
.year-badge-value {
  font-family: var(--font-display);
  font-size: 19px;
  color: var(--cream);
}
.year-badge-value.flip { animation: flip 0.6s var(--ease); }
@keyframes flip {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

/* ---------- Buttons ---------- */

.btn {
  cursor: pointer;
  border-radius: 4px;
  padding: 7px 14px;
  font-family: var(--font-display);
  font-size: 17px;
  line-height: 1.1;
  transition: background 0.2s, color 0.2s, transform 0.15s;
}
.btn:active { transform: translateY(1px); }

.btn-ghost {
  background: transparent;
  color: var(--gold-light);
  border: 1.5px solid var(--gold);
}
.btn-ghost:hover { background: var(--gold); color: var(--choc); }

.btn-primary {
  background: var(--choc);
  color: var(--gold-light);
  border: 1.5px solid var(--gold);
  box-shadow: 0 2px 0 var(--gold), 0 3px 8px rgba(40, 20, 5, 0.3);
}
.btn-primary:hover { background: var(--choc-2); color: var(--cream); }
.btn-primary:disabled { opacity: 0.6; cursor: wait; }

.btn-secondary {
  background: transparent;
  color: var(--choc);
  border: 1.5px solid var(--choc-2);
}
.btn-secondary:hover { background: rgba(90, 54, 32, 0.1); }

.btn-large { font-size: 22px; padding: 12px 28px; }

/* ---------- Legend and hint ---------- */

.legend {
  position: fixed;
  left: 14px;
  bottom: 14px;
  z-index: 6;
  padding: 8px 12px;
  font-size: 14px;
  line-height: 1.6;
  background: rgba(241, 228, 198, 0.9);
  border: 1px solid var(--land-stroke);
  border-radius: 4px;
  box-shadow: 0 2px 6px rgba(40, 20, 5, 0.2);
}
.legend-row { display: flex; align-items: center; gap: 8px; }
.legend-ocean { stroke: var(--route-ocean); stroke-width: 2.6; stroke-dasharray: 7 5; fill: none; }
.legend-land { stroke: var(--route-land); stroke-width: 3; stroke-dasharray: 0.1 6; stroke-linecap: round; fill: none; }
.legend-dot {
  display: inline-block;
  width: 14px;
  height: 14px;
  margin: 0 10px;
  border-radius: 50%;
  border: 2px solid var(--gold-light);
  background: var(--choc-2);
}
.legend-dot.next { background: var(--gold); border-color: var(--cream); box-shadow: 0 0 6px 2px rgba(224, 189, 106, 0.9); }

.hint {
  position: fixed;
  left: 50%;
  bottom: 22px;
  z-index: 7;
  transform: translateX(-50%);
  max-width: min(560px, calc(100vw - 32px));
  margin: 0;
  padding: 8px 16px;
  text-align: center;
  font-size: 17px;
  color: var(--cream);
  background: rgba(59, 35, 20, 0.92);
  border: 1px solid var(--gold);
  border-radius: 999px;
  box-shadow: 0 3px 10px rgba(30, 15, 5, 0.35);
  animation: hint-in 0.5s var(--ease);
}
@keyframes hint-in {
  from { opacity: 0; transform: translate(-50%, 10px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* ---------- Side panel ---------- */

.panel {
  position: fixed;
  z-index: 15;
  top: var(--topbar-h);
  right: 0;
  bottom: 0;
  width: var(--panel-w);
  display: flex;
  flex-direction: column;
  background:
    linear-gradient(90deg, rgba(90, 54, 32, 0.12), rgba(0, 0, 0, 0) 14px),
    var(--parchment);
  border-left: 3px double var(--gold);
  box-shadow: -6px 0 18px rgba(30, 15, 5, 0.3);
  transform: translateX(105%);
  visibility: hidden;
  transition: transform 0.55s var(--ease), visibility 0s linear 0.55s;
}
.panel.is-open {
  transform: none;
  visibility: visible;
  transition: transform 0.55s var(--ease), visibility 0s;
}

.panel-handle { display: none; }

.panel-close {
  position: absolute;
  top: 8px;
  right: 10px;
  z-index: 2;
  width: 36px;
  height: 36px;
  border: 1px solid transparent;
  border-radius: 50%;
  background: transparent;
  color: var(--choc-2);
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
}
.panel-close:hover { border-color: var(--choc-2); background: rgba(90, 54, 32, 0.08); }
.panel-close.static { position: static; }

.panel-body {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 22px 26px 26px;
  -webkit-overflow-scrolling: touch;
}

.panel-footer {
  display: flex;
  gap: 10px;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  padding: 12px 20px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--parchment-dark);
  background: rgba(220, 199, 156, 0.4);
}
.panel-footer .btn-primary { margin-left: auto; }

.panel-kicker {
  margin: 0 40px 2px 0;
  font-family: var(--font-sc);
  font-size: 14px;
  letter-spacing: 0.1em;
  color: var(--gold);
}
.panel-title {
  margin: 0 40px 6px 0;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 30px;
  line-height: 1.15;
  color: var(--choc);
}
.panel-title:focus { outline: none; }
.panel-title:focus-visible { outline: 2px dashed var(--gold); }

.panel-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  margin: 0 0 14px;
  font-style: italic;
  color: var(--ink-soft);
}
.panel-meta > span::before { content: "\25C6\00a0"; font-style: normal; color: var(--gold); font-size: 0.8em; }

.panel-rule {
  height: 8px;
  margin: 6px 0 16px;
  background:
    linear-gradient(var(--gold), var(--gold)) center 2px / 100% 1px no-repeat,
    linear-gradient(var(--gold), var(--gold)) center 6px / 100% 1px no-repeat;
}

.narrative p { margin: 0 0 0.85em; }

.panel h3 {
  margin: 20px 0 8px;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 21px;
  color: var(--choc);
}
.panel h4 {
  margin: 0 0 4px;
  font-family: var(--font-sc);
  font-weight: 400;
  font-size: 15px;
  letter-spacing: 0.06em;
  color: var(--choc-2);
}

.figures { display: grid; gap: 14px; margin: 16px 0; }
.figure {
  margin: 0;
  padding: 8px;
  background: #fbf5e6;
  border: 1px solid var(--parchment-dark);
  box-shadow: 0 1px 4px rgba(40, 20, 5, 0.15);
}
.figure img {
  display: block;
  width: 100%;
  max-height: 340px;
  object-fit: contain;
  background: var(--parchment);
}
.figure figcaption { margin-top: 6px; font-size: 15px; line-height: 1.35; }
.figure .credit { display: block; margin-top: 3px; font-size: 13px; color: var(--ink-soft); }
.img-missing {
  padding: 30px 12px;
  text-align: center;
  font-size: 14px;
  color: var(--ink-soft);
  border: 1px dashed var(--land-stroke);
}

.traded-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.traded-col {
  padding: 10px 12px;
  background: rgba(220, 199, 156, 0.35);
  border-left: 3px solid var(--gold);
}
.traded-col ul { margin: 0; padding-left: 1.1em; }
.traded-col li { margin: 2px 0; }

.route-list { margin: 0; padding: 0; list-style: none; }
.route-list li {
  margin: 0 0 8px;
  padding: 6px 10px;
  font-size: 16px;
  border: 1px solid var(--parchment-dark);
  border-radius: 3px;
}
.route-list .route-name { font-weight: 600; }
.route-type {
  display: inline-block;
  margin-left: 6px;
  padding: 0 6px;
  font-size: 13px;
  border-radius: 3px;
  color: var(--cream);
  background: var(--route-ocean);
}
.route-type.land { background: var(--route-land); }

.firsthand { margin: 20px 0 4px; }
.firsthand blockquote {
  margin: 0 0 8px;
  padding: 4px 0 4px 14px;
  border-left: 3px solid var(--gold);
  font-style: italic;
}
.firsthand blockquote p { margin: 0 0 0.5em; }
.firsthand-source { margin: 0 0 10px; font-size: 15px; color: var(--ink-soft); }
.firsthand h4 { margin: 12px 0 4px; font-size: 16px; }
.firsthand > p { margin: 0 0 0.6em; }

.callout {
  margin: 22px 0 8px;
  padding: 14px 16px 16px;
  color: var(--cream);
  background: linear-gradient(160deg, var(--choc-2), var(--choc));
  border: 1px solid var(--gold);
  outline: 1px solid var(--gold);
  outline-offset: -6px;
  border-radius: 3px;
}
.panel .callout h3 { margin-top: 0; color: var(--gold-light); }
.callout p { margin: 0; }
.callout .todo { background: rgba(224, 189, 106, 0.25); color: var(--cream); }

.source-list { margin: 0; padding-left: 1.3em; font-size: 15px; line-height: 1.4; }
.source-list li { margin: 0 0 6px; overflow-wrap: anywhere; }
.source-list a { color: var(--choc-2); }
/* MLA style: no bullets, hanging indent. */
.works-cited { list-style: none; padding-left: 0; }
.works-cited li { padding-left: 2em; text-indent: -2em; margin-bottom: 10px; }
.cited-stop { margin: 16px 0 6px; }

.todo {
  background: var(--todo-bg);
  border-radius: 2px;
  font-style: italic;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}

/* ---------- Title card ---------- */

.title-card {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
  overflow-y: auto;
  background:
    radial-gradient(ellipse at center, rgba(241, 228, 198, 0.96) 0%, rgba(220, 199, 156, 0.96) 60%, rgba(90, 54, 32, 0.96) 130%);
  transition: opacity 0.9s ease, visibility 0s linear 0.9s;
}
.title-card.is-leaving { opacity: 0; visibility: hidden; }

.title-card-inner {
  max-width: 680px;
  width: 100%;
  padding: 44px 36px 40px;
  text-align: center;
  background: rgba(248, 239, 217, 0.7);
  border: 3px double var(--choc-2);
  outline: 1px solid var(--gold);
  outline-offset: 6px;
  box-shadow: 0 10px 40px rgba(40, 20, 5, 0.35);
}
.title-ornament { font-size: 34px; color: var(--gold); line-height: 1; }
.title-card-title {
  margin: 10px 0 6px;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: clamp(38px, 8vw, 64px);
  line-height: 1.05;
  color: var(--choc);
}
.title-card-subtitle {
  margin: 0 0 18px;
  font-family: var(--font-display);
  font-style: italic;
  font-size: clamp(18px, 3.2vw, 22px);
  color: var(--ink-soft);
}
.title-card-rule {
  width: 60%;
  height: 8px;
  margin: 0 auto 18px;
  background:
    linear-gradient(var(--gold), var(--gold)) center 2px / 100% 1px no-repeat,
    linear-gradient(var(--gold), var(--gold)) center 6px / 100% 1px no-repeat;
}
.title-card-question {
  margin: 0 0 16px;
  font-size: clamp(19px, 3.4vw, 23px);
  font-style: italic;
  color: var(--choc);
}
.title-card-authors { margin: 0 0 26px; font-size: 16px; color: var(--ink-soft); }

.error-box {
  margin: 0 0 20px;
  padding: 12px 14px;
  text-align: left;
  font-size: 16px;
  color: #5c1409;
  background: #f6dcd2;
  border: 1px solid #a2412c;
  border-radius: 4px;
}
.error-box code { font-size: 14px; }

/* ---------- Sources dialog ---------- */

.sources-dialog {
  width: min(760px, calc(100vw - 24px));
  max-height: min(84dvh, 900px);
  padding: 0;
  color: var(--ink);
  background: var(--parchment);
  border: 3px double var(--choc-2);
  box-shadow: 0 10px 40px rgba(30, 15, 5, 0.5);
}
.sources-dialog[open] { display: flex; flex-direction: column; }
.sources-dialog::backdrop { background: rgba(30, 15, 5, 0.55); }
.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--parchment-dark);
}
.dialog-head h2 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 26px;
  color: var(--choc);
}
.dialog-body { overflow-y: auto; padding: 6px 22px 22px; }
.dialog-body h3 {
  margin: 20px 0 8px;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 20px;
  color: var(--choc);
  border-bottom: 1px solid var(--gold);
}
.dialog-body h4 {
  margin: 12px 0 6px;
  font-family: var(--font-sc);
  font-weight: 400;
  font-size: 15px;
  color: var(--choc-2);
}

.noscript {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 60;
  margin: 0;
  padding: 12px;
  text-align: center;
  background: var(--choc);
  color: var(--cream);
}

/* ---------- Phones and narrow screens: panel becomes a bottom sheet ---------- */

@media (max-width: 720px) {
  :root { --topbar-h: 52px; }
  html, body { font-size: 17px; }

  .topbar { gap: 8px; padding: 0 8px; }
  .topbar-title { font-size: 17px; }
  .year-badge { min-width: 70px; padding: 1px 8px; }
  .year-badge-value { font-size: 16px; }
  .btn-ghost { padding: 6px 10px; font-size: 15px; }

  .legend,
  .compass { display: none; }

  .hint { bottom: calc(16px + env(safe-area-inset-bottom)); font-size: 15px; border-radius: 12px; }

  .panel {
    top: auto;
    left: 0;
    right: 0;
    width: auto;
    height: var(--sheet-h);
    max-height: calc(100dvh - var(--topbar-h) - 20px);
    border-left: 0;
    border-top: 3px double var(--gold);
    border-radius: 14px 14px 0 0;
    box-shadow: 0 -6px 18px rgba(30, 15, 5, 0.3);
    transform: translateY(105%);
  }
  .panel.is-dragging { transition: none; }

  .panel-handle {
    display: flex;
    justify-content: center;
    align-items: center;
    flex: none;
    width: 100%;
    height: 22px;
    padding: 0;
    border: 0;
    background: transparent;
    cursor: ns-resize;
    touch-action: none;
  }
  .panel-handle span {
    width: 44px;
    height: 5px;
    border-radius: 3px;
    background: var(--land-stroke);
  }
  .panel-close { top: 10px; }
  .panel-body { padding: 4px 18px 18px; }
  .panel-title { font-size: 25px; }
  .panel-footer { padding: 10px 14px calc(10px + env(safe-area-inset-bottom)); }
  .traded-cols { grid-template-columns: 1fr; }
  .title-card-inner { padding: 32px 20px 28px; }
}

@media (max-width: 480px) {
  .topbar-title { display: none; }
  .topbar-actions { margin-left: auto; }
}

/* ---------- Reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
  .ship-bob { animation: none; }
  .marker.is-next::before,
  .marker.is-next::after { display: none; }
  .marker.is-next .marker-dot { box-shadow: 0 0 10px 4px rgba(224, 189, 106, 0.9); }
}

/* ---------- Scene: a period picture the camera dives into ---------- */

.scene {
  position: fixed;
  inset: 0;
  z-index: 12;                 /* above the map and legend, below the panel and top bar */
  overflow: hidden;
  background: #1f1510;
  opacity: 0;
  visibility: hidden;
  transform-origin: 50% 50%;
  will-change: transform, opacity;
}
.scene.is-active { opacity: 1; visibility: visible; }
.scene.is-diving { background: transparent; }
/* The dark surround and the controls don't fly in with the picture. */
.scene.is-diving .scene-back,
.scene.is-diving .scene-info,
.scene.is-diving .scene-caption { opacity: 0; transition: none; }
.scene-back,
.scene-info,
.scene-caption { transition: opacity 0.5s ease; }

.dive-mist {
  position: fixed;
  inset: -20%;
  z-index: 13;
  pointer-events: none;
  opacity: 0;
  will-change: transform, opacity;
  background:
    radial-gradient(closest-side at 38% 46%, rgba(250, 247, 238, 0.95), rgba(250, 247, 238, 0) 100%),
    radial-gradient(closest-side at 62% 54%, rgba(244, 240, 230, 0.85), rgba(244, 240, 230, 0) 100%),
    radial-gradient(closest-side at 50% 38%, rgba(255, 252, 244, 0.8), rgba(255, 252, 244, 0) 100%),
    radial-gradient(closest-side at 45% 62%, rgba(236, 232, 222, 0.7), rgba(236, 232, 222, 0) 100%);
  background-size: 55% 45%, 60% 50%, 50% 40%, 65% 45%;
  background-repeat: no-repeat;
  background-position: 30% 40%, 70% 55%, 50% 30%, 40% 70%;
  filter: blur(8px);
}
/* The nearer bank: bigger, softer puffs that sweep past faster. */
.dive-mist-near {
  z-index: 14;
  background:
    radial-gradient(closest-side at 20% 30%, rgba(255, 253, 248, 0.9), rgba(255, 253, 248, 0) 100%),
    radial-gradient(closest-side at 80% 35%, rgba(250, 247, 240, 0.85), rgba(250, 247, 240, 0) 100%),
    radial-gradient(closest-side at 25% 75%, rgba(246, 243, 235, 0.8), rgba(246, 243, 235, 0) 100%),
    radial-gradient(closest-side at 75% 78%, rgba(252, 250, 244, 0.85), rgba(252, 250, 244, 0) 100%),
    radial-gradient(closest-side at 50% 50%, rgba(255, 255, 252, 0.6), rgba(255, 255, 252, 0) 100%);
  background-size: 60% 55%, 55% 50%, 60% 55%, 55% 50%, 70% 60%;
  background-position: 5% 15%, 95% 20%, 10% 85%, 90% 90%, 50% 50%;
  background-repeat: no-repeat;
  filter: blur(14px);
}
/* The heart of the cloud: a soft white-out that hides the hand-over from map to picture. */
.dive-whiteout {
  position: fixed;
  inset: 0;
  z-index: 13;
  pointer-events: none;
  opacity: 0;
  background: radial-gradient(ellipse at var(--wx, 50%) var(--wy, 50%), #fbfaf5 0%, #f4f1e8 55%, #e9e4d6 100%);
}
@media (prefers-reduced-motion: reduce) { .dive-mist, .dive-whiteout { display: none; } }
.scene.is-leaving {
  transition: transform 1.1s cubic-bezier(0.5, 0, 0.8, 0.4), opacity 0.6s ease 0.4s;
}

/* A soft, blurred copy of the picture fills any space the picture itself doesn't. */
.scene-stage {
  position: absolute;
  box-shadow: 0 0 40px rgba(20, 10, 4, 0.6);
  left: 50%;   /* js/main.js moves it to the centre of the visible area */
  top: 50%;
  transform: translate(-50%, -50%) translate(var(--kb-x0, 0px), var(--kb-y0, 0px)) scale(var(--kb-s0, 1));
  transform-origin: 50% 50%;
  will-change: transform;
}
.scene.is-panning .scene-stage {
  animation: kenburns var(--kb-dur, 45s) ease-in-out infinite alternate;
}
@keyframes kenburns {
  from { transform: translate(-50%, -50%) translate(var(--kb-x0, 0px), var(--kb-y0, 0px)) scale(var(--kb-s0, 1)); }
  to   { transform: translate(-50%, -50%) translate(var(--kb-x1, 0px), var(--kb-y1, 0px)) scale(var(--kb-s1, 1)); }
}
/* The living painting (js/scene-anim.js) draws over the still picture. */
.scene-gl,
.scene-fx {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
.scene-stage.is-living .scene-img { visibility: hidden; }
.scene-img {
  display: block;
  width: 100%;
  height: 100%;
  user-select: none;
  -webkit-user-drag: none;
}

.scene-vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse at center, rgba(0, 0, 0, 0) 55%, rgba(40, 24, 10, 0.55) 100%),
    linear-gradient(180deg, rgba(40, 24, 10, 0.35), rgba(0, 0, 0, 0) 18%);
  mix-blend-mode: multiply;
}

.scene-hotspots { position: absolute; inset: 0; }
.hotspot {
  position: absolute;
  width: 34px;
  height: 34px;
  margin: -17px 0 0 -17px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
}
.hotspot::before {
  content: "";
  position: absolute;
  inset: 9px;
  border-radius: 50%;
  background: var(--gold);
  border: 2px solid var(--cream);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
}
.hotspot::after {
  content: "";
  position: absolute;
  inset: 9px;
  border-radius: 50%;
  border: 2px solid var(--gold-light);
  animation: ripple 2s ease-out infinite;
  pointer-events: none;
}
.hotspot:hover::before,
.hotspot.is-open::before { background: var(--cream); border-color: var(--choc); }
.hotspot:focus-visible { outline: 3px solid var(--gold-light); outline-offset: 2px; }
.hotspot-name {
  position: absolute;
  left: 50%;
  top: 100%;
  transform: translateX(-50%);
  margin-top: 2px;
  padding: 2px 8px;
  white-space: nowrap;
  font-family: var(--font-display);
  font-size: 15px;
  color: var(--cream);
  background: rgba(43, 26, 16, 0.78);
  border: 1px solid rgba(224, 189, 106, 0.6);
  border-radius: 3px;
  opacity: 0;
  transition: opacity 0.25s;
  pointer-events: none;
}
.hotspot:hover .hotspot-name,
.hotspot:focus-visible .hotspot-name,
.hotspot.is-open .hotspot-name,
.scene.show-names .hotspot-name { opacity: 1; }

.scene-back,
.scene-info {
  position: absolute;
  top: calc(var(--topbar-h) + 14px);
  left: 14px;
  z-index: 3;
  background: rgba(43, 26, 16, 0.82);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}
/* Brings the information panel back after it was closed inside a scene. */
.scene-info { display: none; left: auto; right: 14px; }
body.in-scene:not(.panel-open) .scene-info { display: inline-flex; }

/* The picture eases into its new size when the panel opens or closes. */
.scene.is-panning .scene-stage {
  transition: left 0.45s ease, top 0.45s ease, width 0.45s ease, height 0.45s ease;
}

.scene-caption {
  position: absolute;
  left: 14px;
  bottom: 14px;
  z-index: 3;
  max-width: min(460px, calc(100vw - 28px));
  padding: 10px 14px 12px;
  color: var(--cream);
  background: rgba(43, 26, 16, 0.82);
  border: 1px solid var(--gold);
  border-radius: 4px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.4);
  font-size: 15px;
  line-height: 1.4;
}
.scene-caption .scene-kicker {
  display: block;
  font-family: var(--font-sc);
  font-size: 13px;
  letter-spacing: 0.1em;
  color: var(--gold-light);
}
.scene-caption .scene-title {
  display: block;
  margin: 2px 0 4px;
  font-family: var(--font-display);
  font-size: 20px;
  line-height: 1.15;
}
.scene-caption .scene-credit { display: block; font-size: 13px; color: rgba(248, 239, 217, 0.8); }
.scene-caption .scene-note {
  display: inline-block;
  margin: 2px 0 4px;
  padding: 1px 7px;
  font-size: 12px;
  letter-spacing: 0.04em;
  color: var(--choc);
  background: var(--gold-light);
  border-radius: 3px;
}
.scene-caption .scene-credit a { color: var(--gold-light); }
.scene-caption .todo { background: rgba(224, 189, 106, 0.25); color: var(--cream); }
body.panel-open .scene-caption { max-width: min(460px, calc(100vw - var(--panel-w) - 28px)); }

.scene-popover {
  position: absolute;
  z-index: 4;
  width: min(320px, calc(100vw - 28px));
  padding: 10px 14px 12px;
  color: var(--ink);
  background: var(--parchment);
  border: 2px solid var(--choc-2);
  outline: 1px solid var(--gold);
  outline-offset: 2px;
  border-radius: 4px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
  font-size: 16px;
  line-height: 1.4;
}
.scene-popover h4 {
  margin: 0 22px 4px 0;
  font-family: var(--font-display);
  font-weight: 400;
  font-size: 19px;
  color: var(--choc);
}
.scene-popover p { margin: 0; }
.scene-popover .panel-close { top: 2px; right: 4px; width: 30px; height: 30px; font-size: 24px; }

.scene-section .btn { margin-top: 4px; }

/* While a scene is showing, hide what belongs to the map. */
body.in-scene .legend,
body.in-scene .compass,
body.in-scene .hint { display: none; }
body.in-scene .map { visibility: hidden; }


@media (max-width: 720px) {
  .scene-back,
  .scene-info { top: calc(var(--topbar-h) + 10px); left: 10px; padding: 5px 10px; font-size: 15px; }
  .scene-info { left: auto; right: 10px; }
  /* A compact strip just above the bottom sheet; the full credit is in the panel and in Sources. */
  .scene-caption {
    left: 10px;
    right: 10px;
    max-width: none;
    padding: 6px 10px 7px;
    font-size: 13px;
    line-height: 1.25;
  }
  body.panel-open .scene-caption { max-width: none; }
  .scene-caption .scene-kicker { display: inline; font-size: 11px; }
  .scene-caption .scene-kicker::after { content: " · "; letter-spacing: 0; }
  .scene-caption .scene-title {
    display: inline;
    margin: 0;
    font-size: 15px;
  }
  .scene-caption .scene-credit {
    margin-top: 2px;
    font-size: 11px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .hotspot-name { font-size: 13px; }
}

@media (prefers-reduced-motion: reduce) {
  .scene.is-panning .scene-stage { animation: none; }
  .hotspot::after { display: none; }
}
