:root {
  --parchment: #f4ecdc;
  --parchment-deep: #e6d9c2;
  --ink: #1d1914;
  --ink-soft: #5c5348;
  --rule: #c9b89a;
  --sea: #d7ddd6;
  --wax: #8d2f2b;
  --gold: #8d6b32;
  --card: rgba(255, 250, 242, 0.96);
  --shadow: 0 16px 40px rgba(48, 32, 12, 0.12);
  --sans: "Avenir Next", "Segoe UI", sans-serif;
  --serif: "Iowan Old Style", Palatino, "Palatino Linotype", Georgia, serif;
  color-scheme: light;
}

[data-theme="dark"] {
  --parchment: #14120e;
  --parchment-deep: #211c16;
  --ink: #f4ecdc;
  --ink-soft: #cbbfa6;
  --rule: #3a3228;
  --sea: #1a2226;
  --wax: #e07a64;
  --gold: #e0c48a;
  --card: rgba(24, 20, 16, 0.96);
  --shadow: 0 16px 40px rgba(0, 0, 0, 0.4);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  min-height: 100%;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  background:
    radial-gradient(circle at 12% 0%, rgba(141, 107, 50, 0.08), transparent 28%),
    var(--parchment);
  color: var(--ink);
  font-family: var(--serif);
}

button, input {
  font: inherit;
  color: inherit;
}

.top, .banner, .scrubber, .panel {
  padding-left: 1.1rem;
  padding-right: 1.1rem;
}

.top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.7rem 1rem;
  padding-top: 0.75rem;
  padding-bottom: 0.15rem;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  color: inherit;
  text-decoration: none;
  font-family: var(--sans);
  font-weight: 650;
  letter-spacing: 0.02em;
}

.mark { width: 1.45rem; height: 1.45rem; display: block; }

.title-block { flex: 1 1 18rem; min-width: 14rem; }

.atlas-title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: 0;
}

.presets {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  flex: 1 1 100%;
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
}

.pill, .presets button {
  border: 1px solid var(--rule);
  background: transparent;
  border-radius: 999px;
  padding: 0.32rem 0.72rem;
  text-decoration: none;
  color: inherit;
  font-family: var(--sans);
  font-size: 0.82rem;
  cursor: pointer;
}

.pill:hover, .presets button:hover { border-color: var(--gold); }

.chronicles-bar { flex: 1 1 100%; }

.chronicles-label {
  margin: 0.1rem 0 0.2rem;
  font-family: var(--sans);
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--gold);
}

#ports-toggle {
  margin-top: 0.7rem;
  border: 1px solid var(--rule);
  background: transparent;
  border-radius: 999px;
  padding: 0.32rem 0.72rem;
  font-family: var(--sans);
  font-size: 0.82rem;
  color: inherit;
  cursor: pointer;
}

#ports-toggle[aria-pressed="true"] { border-color: var(--gold); }

.atto-cta {
  margin-top: 1rem;
  padding: 0.75rem 0.85rem;
  border: 1px solid var(--rule);
  border-radius: 14px;
}

.atto-cta p:first-child { margin-top: 0; }

.kicker {
  margin: 0;
  font-family: var(--sans);
  font-size: 0.78rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--gold);
}

.badge {
  margin: 0.2rem 0 0;
  max-width: 46rem;
  font-size: 0.98rem;
}

.top-actions button, .scrubber button, .route-buttons button {
  border: 1px solid var(--rule);
  background: transparent;
  border-radius: 999px;
  padding: 0.35rem 0.8rem;
  cursor: pointer;
}

.top-actions button[aria-pressed="true"] {
  background: var(--ink);
  color: var(--parchment);
}

.banner {
  margin: 0.45rem 0 0;
  color: var(--ink-soft);
  font-size: 0.95rem;
}

.shell {
  min-height: 0;
  display: grid;
  grid-template-columns: 18rem minmax(0, 1fr) 22rem;
  gap: 0.75rem;
  padding: 0.75rem;
}

.panel {
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: 18px;
  box-shadow: var(--shadow);
  overflow: auto;
}

.search-panel, .card { padding: 0.9rem 1rem 1rem; }

label, .mesh-note, .legend, .results {
  font-family: var(--sans);
}

.search-panel label {
  display: block;
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

#search-input {
  width: 100%;
  margin-top: 0.35rem;
  padding: 0.65rem 0.7rem;
  border-radius: 12px;
  border: 1px solid var(--rule);
  background: transparent;
}

.results {
  list-style: none;
  margin: 0.6rem 0 0;
  padding: 0;
}

.results button {
  width: 100%;
  text-align: left;
  border: 0;
  border-bottom: 1px solid var(--rule);
  background: transparent;
  padding: 0.45rem 0;
  cursor: pointer;
}

.results small { color: var(--ink-soft); }

.legend {
  display: grid;
  gap: 0.28rem;
  margin-top: 1rem;
  font-size: 0.82rem;
}

.legend div {
  display: flex;
  gap: 0.45rem;
  align-items: center;
}

.swatch {
  width: 0.85rem;
  height: 0.85rem;
  border-radius: 2px;
  border: 1px solid rgba(0, 0, 0, 0.2);
  flex: none;
}

.mesh-note {
  color: var(--ink-soft);
  font-size: 0.78rem;
  line-height: 1.4;
}

.map-wrap {
  position: relative;
  min-height: 0;
  border: 1px solid var(--rule);
  border-radius: 18px;
  overflow: hidden;
  background: var(--sea);
}

#map { width: 100%; height: 100%; display: block; }

#sea { fill: var(--sea); }

.province {
  stroke: rgba(29, 25, 20, 0.35);
  stroke-width: 0.6;
  cursor: pointer;
}

[data-theme="dark"] .province { stroke: rgba(244, 236, 220, 0.28); }

.province.is-modern { stroke: var(--ink); stroke-width: 1.6; }
.province.is-historical { stroke: var(--wax); stroke-width: 2; stroke-dasharray: 4 3; }

.arc {
  fill: none;
  stroke: var(--wax);
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-dasharray: 7 6;
  animation: march 1.1s linear infinite;
}

.arc.is-active { stroke-width: 3.4; }

.pin-dot { fill: var(--wax); stroke: var(--parchment); stroke-width: 1.5; }
.port-dot { fill: var(--gold); stroke: var(--ink); stroke-width: 1.4; cursor: pointer; }
.port-label { font-size: 10px; }
.pin-label {
  font-family: var(--sans);
  font-size: 11px;
  fill: var(--ink);
}

.year-stamp {
  position: absolute;
  top: 0.8rem;
  left: 0.9rem;
  font-size: 2.4rem;
  line-height: 1;
  letter-spacing: -0.04em;
  pointer-events: none;
}

.hover-tip, .route-bar {
  position: absolute;
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: 12px;
  padding: 0.45rem 0.6rem;
  font-family: var(--sans);
  font-size: 0.82rem;
  box-shadow: var(--shadow);
}

.hover-tip { pointer-events: none; }

.route-bar {
  left: 0.8rem;
  right: 0.8rem;
  bottom: 0.8rem;
}

.route-bar p { margin: 0 0 0.35rem; }

.route-buttons { display: flex; gap: 0.4rem; flex-wrap: wrap; }

#route-stops {
  display: flex;
  gap: 0.5rem;
  overflow: auto;
  margin: 0.45rem 0 0;
  padding: 0;
  list-style: none;
}

#route-stops button {
  border: 1px solid var(--rule);
  background: transparent;
  border-radius: 999px;
  cursor: pointer;
  padding: 0.25rem 0.55rem;
}

#route-stops .is-current button {
  background: var(--wax);
  color: white;
  border-color: var(--wax);
}

.card h2 { margin: 0 0 0.2rem; font-size: 1.55rem; }
.card h3 {
  margin: 1rem 0 0.3rem;
  font-family: var(--sans);
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--gold);
}
.card p, .card li { margin: 0.25rem 0; }
.card a { color: var(--wax); }
.card .warn {
  border-left: 3px solid var(--gold);
  padding-left: 0.6rem;
}

.office-box, .parish-box {
  margin-top: 0.85rem;
  padding: 0.7rem 0.75rem;
  border: 1px solid var(--rule);
  border-radius: 14px;
}

.office-box h3, .parish-box h3 { margin-top: 0; }

.parish-badge {
  margin: 0 0 0.45rem;
  padding: 0.45rem 0.6rem;
  border-left: 3px solid var(--wax);
  font-weight: 650;
}
.timeline { padding-left: 1.1rem; }
.timeline li { margin: 0.35rem 0; }

.scrubber {
  display: grid;
  grid-template-columns: auto auto 1fr auto auto;
  gap: 0.6rem;
  align-items: center;
  padding-top: 0.4rem;
  padding-bottom: 0.7rem;
}

.slider-label { font-family: var(--sans); font-size: 0.85rem; white-space: nowrap; }

#year-slider { width: 100%; accent-color: var(--wax); }

.boot-error {
  margin: 0;
  padding: 0.8rem 1.1rem 1rem;
  color: var(--wax);
}

@keyframes march { to { stroke-dashoffset: -26; } }

@media (prefers-reduced-motion: reduce) {
  .arc { animation: none; }
}

@media (max-width: 980px) {
  body { height: auto; }
  .shell { grid-template-columns: 1fr; }
  .map-wrap { min-height: 70vh; }
  .scrubber { grid-template-columns: auto 1fr auto; }
  #play-years, .slider-label { grid-column: 1 / -1; }
}
