/* ── Book of Mormon History ─────────────────────────────────────────────────
   A dark, quiet interface. The map is the brightest thing on screen and
   everything else gets out of its way.                                      */

:root {
  --bg:        #0f1115;
  --bg-2:      #14161b;
  --bg-3:      #1a1d24;
  --line:      #262a33;
  --line-2:    #333844;
  --ink:       #e6e8ec;
  --ink-2:     #a2a8b4;
  --ink-3:     #6f7684;
  --gold:      #c9a227;
  --gold-soft: #e0bd4a;
  --blue:      #4a9ecf;
  --sea:       #10161d;
  --land:      #232830;
  --rail-w:    306px;
  --card-w:    390px;
  --head-h:    50px;
  --tl-h:      132px;
  --r:         7px;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
}

* { box-sizing: border-box; }

/* Our own, rather than relying on Bootstrap's reboot: several elements here are
   toggled with the `hidden` attribute and their class rules set a display. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Header ── */
.site-head {
  height: var(--head-h);
  display: flex; align-items: center; gap: 22px;
  padding: 0 16px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--line);
  position: relative; z-index: 40;
}
.brand { display: flex; align-items: center; gap: 9px; color: var(--ink); font-size: 14.5px; letter-spacing: .2px; }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 17px; height: 17px; border-radius: 3px; flex: none;
  background:
    linear-gradient(var(--gold), var(--gold)) 0 2px / 100% 2.5px no-repeat,
    linear-gradient(var(--gold), var(--gold)) 0 7.5px / 100% 2.5px no-repeat,
    linear-gradient(var(--gold), var(--gold)) 0 13px / 100% 2.5px no-repeat,
    var(--bg-3);
}
.brand-text b { color: var(--gold-soft); font-weight: 600; }
.site-nav { display: flex; gap: 18px; }
.site-nav a { color: var(--ink-2); font-size: 13px; padding: 3px 0; border-bottom: 1.5px solid transparent; }
.site-nav a:hover { color: var(--ink); text-decoration: none; }
.site-nav a.on { color: var(--ink); border-bottom-color: var(--gold); }
.site-account { margin-left: auto; display: flex; align-items: center; gap: 12px; font-size: 12.5px; color: var(--ink-3); }
.site-account form { margin: 0; }
.linkish { background: none; border: 0; color: var(--ink-2); font-size: 12.5px; cursor: pointer; padding: 0; font-family: inherit; }
.linkish:hover { color: var(--ink); }
.who { color: var(--ink-3); }

/* ── App shell ── */
body.app-shell { height: 100dvh; display: grid; grid-template-rows: var(--head-h) 1fr var(--tl-h); overflow: hidden; }
.atlas { display: grid; grid-template-columns: var(--rail-w) 1fr; min-height: 0; position: relative; }
.atlas.rail-closed { grid-template-columns: 0 1fr; }

/* ── Left rail ── */
.rail {
  background: var(--bg-2); border-right: 1px solid var(--line);
  overflow-y: auto; overflow-x: hidden; padding: 14px 14px 22px;
  position: relative;
}
.atlas.rail-closed .rail { padding-left: 0; padding-right: 0; overflow: hidden; }
.atlas.rail-closed .rail > *:not(.rail-toggle) { display: none; }
.rail-toggle {
  position: absolute; top: 8px; right: 8px; z-index: 3;
  width: 24px; height: 24px; border-radius: 5px;
  background: var(--bg-3); border: 1px solid var(--line-2); color: var(--ink-3); cursor: pointer;
  display: grid; place-items: center; font-size: 12px;
}
.rail-toggle:hover { color: var(--ink); }
.atlas.rail-closed .rail-toggle { right: -30px; background: var(--bg-2); }
.atlas.rail-closed .rail-toggle i { transform: rotate(180deg); }

.rail-year { padding: 2px 0 16px; border-bottom: 1px solid var(--line); margin-bottom: 14px; }
.rail-year-main { font-family: var(--mono); font-size: 30px; letter-spacing: -.6px; color: var(--gold-soft); line-height: 1.1; }
.rail-year-alt { font-size: 12.5px; color: var(--ink-2); margin-top: 3px; min-height: 19px; }
.rail-era { font-size: 12px; color: var(--ink-3); margin-top: 6px; font-style: italic; }

.rail-block { margin-bottom: 18px; }
.rail-block h3 {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .1em;
  color: var(--ink-3); font-weight: 600; margin: 0 0 8px;
}
.rail-note { font-size: 11.5px; color: var(--ink-3); margin: 8px 0 0; line-height: 1.5; }
.rail-foot { font-size: 11.5px; color: var(--ink-3); border-top: 1px solid var(--line); padding-top: 12px; margin: 22px 0 0; line-height: 1.55; }

.seg { display: flex; flex-wrap: wrap; gap: 4px; }
.seg button {
  background: var(--bg-3); border: 1px solid var(--line); color: var(--ink-2);
  font: inherit; font-size: 11.5px; padding: 4px 9px; border-radius: 5px; cursor: pointer;
}
.seg button:hover { color: var(--ink); border-color: var(--line-2); }
.seg button.on { background: #23303c; border-color: #3a5a72; color: #cfe6f5; }
.seg button:disabled { opacity: .32; cursor: not-allowed; }

.chk { display: flex; align-items: center; gap: 8px; padding: 3px 0; cursor: pointer; font-size: 13px; color: var(--ink-2); }
.chk:hover { color: var(--ink); }
.chk input { accent-color: var(--blue); width: 14px; height: 14px; }
.chk em { margin-left: auto; font-style: normal; font-family: var(--mono); font-size: 11px; color: var(--ink-3); }

.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--bg-3); border: 1px solid var(--line); color: var(--ink-2);
  font-size: 11.5px; padding: 3px 8px; border-radius: 20px; cursor: pointer;
}
.chip .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.chip.off { opacity: .38; }
.chip:hover { border-color: var(--line-2); }

.legend { display: grid; gap: 5px; }
.legend-row { display: flex; align-items: flex-start; gap: 8px; font-size: 11.5px; color: var(--ink-2); }
.legend-row .sw { width: 11px; height: 11px; border-radius: 2.5px; flex: none; margin-top: 3px; border: 1px solid rgba(255,255,255,.14); }
.legend-row.dim { opacity: .4; }
.legend-row b { color: var(--ink); font-weight: 500; }

.saved-list { display: grid; gap: 4px; }
.saved-item { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--ink-2); cursor: pointer; }
.saved-item:hover { color: var(--ink); }
.saved-item .yr { font-family: var(--mono); font-size: 10.5px; color: var(--ink-3); margin-left: auto; }

/* ── Stage ── */
.stage { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--sea); }
.scene-bar {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px;
  border-bottom: 1px solid var(--line); background: var(--bg-2); flex: none;
}
.seg.scenes button { padding: 5px 12px; font-size: 12px; }
.model-pick {
  background: var(--bg-3); color: var(--ink); border: 1px solid var(--line-2);
  border-radius: 5px; padding: 5px 8px; font: inherit; font-size: 12px; max-width: 260px;
}
.stage-tools { margin-left: auto; display: flex; gap: 5px; }
.tool {
  background: var(--bg-3); border: 1px solid var(--line); color: var(--ink-2);
  border-radius: 5px; padding: 5px 10px; font: inherit; font-size: 12px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
}
.tool:hover { color: var(--ink); border-color: var(--line-2); }
.tool.icon { width: 30px; justify-content: center; padding: 5px 0; font-size: 14px; }

.map-wrap { position: relative; flex: 1; min-height: 0; overflow: hidden; }
#map { width: 100%; height: 100%; display: block; cursor: grab; touch-action: none; }
#map.dragging { cursor: grabbing; }
/* z-index here is load-bearing: it makes #realmap its own stacking context, so
   Leaflet's panes (which sit at 400-1000) stay under the record card rather
   than covering it. */
#realmap { position: absolute; inset: 0; z-index: 1; }
#realmap .leaflet-container { background: #0d1218; }
#realmap .dark-tiles { filter: grayscale(.85) invert(1) contrast(.9) hue-rotate(180deg) brightness(.92) saturate(.7); }
#realmap .leaflet-control-zoom a { background: var(--bg-3); color: var(--ink-2); border-color: var(--line); }
#realmap .leaflet-control-zoom a:hover { background: var(--line); color: var(--ink); }
#realmap .leaflet-control-attribution { background: rgba(15,17,21,.8); color: var(--ink-3); font-size: 10.5px; }
#realmap .leaflet-control-attribution a { color: var(--ink-2); }
#realmap .leaflet-tooltip { background: var(--bg-2); border: 1px solid var(--line-2); color: var(--ink); box-shadow: none; }
#realmap .leaflet-tooltip-top::before { border-top-color: var(--line-2); }

.model-banner {
  position: absolute; left: 12px; bottom: 40px; right: 12px; max-width: 620px; z-index: 5;
  background: rgba(16,18,23,.93); border: 1px solid var(--line-2); border-radius: var(--r);
  padding: 10px 13px; font-size: 12px; color: var(--ink-2); line-height: 1.55;
  backdrop-filter: blur(6px);
}
.model-banner b { color: var(--gold-soft); font-weight: 600; }
.empty-note {
  position: absolute; left: 50%; top: 44%; transform: translateX(-50%);
  background: rgba(16,18,23,.9); border: 1px solid var(--line-2); border-radius: var(--r);
  padding: 10px 15px; font-size: 12.5px; color: var(--ink-2); text-align: center; max-width: 400px;
}

/* ── SVG map ── */
.m-sea { fill: var(--sea); }
.m-land { fill: var(--land); stroke: #3a4250; stroke-width: 1.6; }
.m-region { stroke: rgba(0,0,0,.35); stroke-width: 1; transition: fill .28s ease; cursor: pointer; }
.m-region:hover { filter: brightness(1.22); }
.m-region.muted { opacity: .3; }
.m-enclave { stroke: rgba(255,255,255,.4); stroke-width: 1.4; stroke-dasharray: 3 3; cursor: pointer; }
.m-river { fill: none; stroke: #3d7ea8; stroke-width: 3.4; stroke-linecap: round; stroke-linejoin: round; opacity: .85; cursor: pointer; }
.m-route { fill: none; stroke: var(--gold); stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; opacity: .8; }
.m-route.dashed { stroke-dasharray: 7 6; opacity: .55; }
.m-coast-label { fill: #4a6b86; font-size: 15px; letter-spacing: .18em; text-transform: uppercase; text-anchor: middle; pointer-events: none; }
.m-region-label { fill: rgba(255,255,255,.6); font-size: 15px; letter-spacing: .1em; text-anchor: middle; pointer-events: none; font-weight: 600; }
.m-label { fill: var(--ink-2); font-size: 11px; text-anchor: middle; pointer-events: none; paint-order: stroke; stroke: rgba(10,12,16,.85); stroke-width: 3px; stroke-linejoin: round; }
.m-label.major { fill: var(--ink); font-size: 12.5px; }
.m-pin { cursor: pointer; }
.m-pin circle { transition: r .15s ease; }
.m-pin:hover .dot { r: 7; }
.m-pin .dot { fill: var(--ink-2); stroke: rgba(10,12,16,.9); stroke-width: 1.4; }
.m-pin.city .dot { fill: #9fb0c4; }
.m-pin.unfixed .dot { fill: none; stroke: #6f7684; stroke-width: 1.6; stroke-dasharray: 2.5 2; }
.m-pin.event .dot { fill: var(--gold); stroke: #1a1508; }
.m-pin.war .dot { fill: #d0574a; stroke: #1a0d0b; }
.m-pin.person .dot { fill: #57b08a; stroke: #0c1a14; }
.m-pin.on .dot { stroke: #fff; stroke-width: 2; }
.m-pulse { fill: none; stroke: var(--gold); opacity: .5; }
.m-hill { fill: none; stroke: #7b6a4a; stroke-width: 2; }

/* ── Record card ── */
.card-panel {
  position: absolute; top: 0; right: 0; bottom: 0; width: var(--card-w); max-width: 92vw;
  background: var(--bg-2); border-left: 1px solid var(--line);
  overflow-y: auto; z-index: 20; padding: 0 0 26px;
  box-shadow: -18px 0 40px rgba(0,0,0,.45);
}
.card-head { position: sticky; top: 0; background: var(--bg-2); border-bottom: 1px solid var(--line); padding: 13px 16px 11px; z-index: 2; }
.card-kicker { display: flex; align-items: center; gap: 8px; font-size: 10.5px; text-transform: uppercase; letter-spacing: .1em; color: var(--ink-3); }
.card-kicker .kind { color: var(--gold); }
.card-close { margin-left: auto; background: none; border: 0; color: var(--ink-3); font-size: 17px; cursor: pointer; line-height: 1; padding: 0 2px; }
.card-close:hover { color: var(--ink); }
.card-title { font-family: var(--serif); font-size: 21px; line-height: 1.25; margin: 7px 0 0; color: var(--ink); }
.card-when { font-family: var(--mono); font-size: 12px; color: var(--gold-soft); margin-top: 5px; }
.card-body { padding: 14px 16px 0; }
.card-body p { color: var(--ink-2); margin: 0 0 12px; font-size: 13.5px; line-height: 1.62; }
.card-body p.lede { color: var(--ink); font-size: 14.5px; font-family: var(--serif); line-height: 1.6; }
.card-ref {
  display: inline-flex; align-items: center; gap: 6px; font-family: var(--mono); font-size: 11.5px;
  background: var(--bg-3); border: 1px solid var(--line); border-radius: 5px; padding: 4px 9px; color: var(--ink-2);
}
.card-sec { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 13px; }
.card-sec h4 { font-size: 10.5px; text-transform: uppercase; letter-spacing: .1em; color: var(--ink-3); margin: 0 0 8px; font-weight: 600; }
.card-links { display: flex; flex-wrap: wrap; gap: 5px; }
.card-link {
  background: var(--bg-3); border: 1px solid var(--line); border-radius: 5px;
  padding: 4px 9px; font-size: 12px; color: var(--ink-2); cursor: pointer;
}
.card-link:hover { color: var(--ink); border-color: var(--line-2); text-decoration: none; }
.card-flag {
  display: flex; gap: 8px; background: #1d1a12; border: 1px solid #3a3320; border-radius: var(--r);
  padding: 9px 11px; font-size: 12px; color: #d3c48c; line-height: 1.55; margin-top: 13px;
}
.card-flag i { color: var(--gold); margin-top: 1px; }
.card-actions { display: flex; gap: 6px; padding: 14px 16px 0; }
.card-actions button { flex: 1; }
.model-row { display: flex; gap: 9px; padding: 8px 0; border-bottom: 1px dashed var(--line); font-size: 12.5px; }
.model-row:last-child { border-bottom: 0; }
.model-row b { color: var(--ink); font-weight: 500; display: block; }
.model-row span { color: var(--ink-3); font-family: var(--mono); font-size: 11px; }

/* ── Timeline ── */
.timeline {
  background: var(--bg-2); border-top: 1px solid var(--line);
  display: flex; align-items: stretch; gap: 14px; padding: 10px 16px 12px; z-index: 30;
}
.tl-controls { display: flex; align-items: center; gap: 5px; flex: none; }
.tl-btn {
  width: 30px; height: 30px; border-radius: 6px; background: var(--bg-3);
  border: 1px solid var(--line); color: var(--ink-2); cursor: pointer; display: grid; place-items: center; font-size: 13px;
}
.tl-btn:hover { color: var(--ink); border-color: var(--line-2); }
.tl-btn.play { width: 36px; height: 36px; background: #23303c; border-color: #3a5a72; color: #cfe6f5; font-size: 16px; }
.tl-speed { background: var(--bg-3); border: 1px solid var(--line); color: var(--ink-2); border-radius: 6px; padding: 4px 5px; font: inherit; font-size: 11.5px; }

.tl-track { position: relative; flex: 1; min-width: 0; cursor: pointer; outline: none; padding-top: 2px; }
.tl-track:focus-visible { box-shadow: 0 0 0 2px #3a5a72; border-radius: 4px; }
.tl-eras { display: flex; height: 17px; border-radius: 3px; overflow: hidden; }
.tl-era { position: relative; overflow: hidden; opacity: .62; transition: opacity .15s; }
.tl-era:hover { opacity: 1; }
.tl-era span {
  position: absolute; inset: 0; display: flex; align-items: center; padding-left: 6px;
  font-size: 9.5px; letter-spacing: .05em; color: rgba(0,0,0,.72); white-space: nowrap; font-weight: 600;
}
.tl-density { display: block; width: 100%; height: 34px; margin-top: 3px; }
.tl-ticks { position: relative; height: 15px; }
.tl-tick { position: absolute; top: 0; font-family: var(--mono); font-size: 9.5px; color: var(--ink-3); transform: translateX(-50%); white-space: nowrap; }
.tl-tick::before { content: ''; position: absolute; left: 50%; top: -3px; width: 1px; height: 3px; background: var(--line-2); }

.tl-pin { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--gold); pointer-events: none; }
.tl-pin::after {
  content: ''; position: absolute; top: -3px; left: 50%; transform: translateX(-50%);
  width: 9px; height: 9px; background: var(--gold); border-radius: 2px;
}
.tl-pin-label {
  position: absolute; bottom: -2px; left: 50%; transform: translateX(-50%);
  font-family: var(--mono); font-size: 10px; color: #1a1508; background: var(--gold);
  padding: 0 5px; border-radius: 3px; white-space: nowrap;
}

/* ── Jump to ── */
.search-overlay { position: fixed; inset: 0; background: rgba(8,9,12,.72); z-index: 200; display: grid; place-items: start center; padding-top: 12vh; }
.search-box { width: min(640px, 92vw); background: var(--bg-2); border: 1px solid var(--line-2); border-radius: 10px; overflow: hidden; box-shadow: 0 28px 70px rgba(0,0,0,.6); }
#searchInput { width: 100%; background: var(--bg-3); border: 0; border-bottom: 1px solid var(--line); color: var(--ink); font: inherit; font-size: 15px; padding: 14px 16px; outline: none; }
.search-results { max-height: 52vh; overflow-y: auto; }
.sr {
  display: flex; align-items: baseline; gap: 10px; padding: 8px 16px; cursor: pointer; border-bottom: 1px solid rgba(255,255,255,.03);
}
.sr:hover, .sr.on { background: #1c222b; }
.sr-kind { font-size: 9.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-3); width: 46px; flex: none; }
.sr-name { color: var(--ink); font-size: 13.5px; }
.sr-when { margin-left: auto; font-family: var(--mono); font-size: 11px; color: var(--gold-soft); flex: none; }
.search-hint { padding: 8px 16px; font-size: 11px; color: var(--ink-3); border-top: 1px solid var(--line); }

body.app-shell noscript { display: none; }
.noscript { padding: 30px; color: var(--ink-2); text-align: center; }

/* ── Prose pages ── */
.prose-page { max-width: 800px; margin: 0 auto; padding: 40px 22px 70px; }
.prose-page h1 { font-family: var(--serif); font-size: 32px; margin: 0 0 6px; letter-spacing: -.3px; }
.prose-page .sub { color: var(--ink-3); font-size: 14px; margin: 0 0 30px; }
.prose-page h2 { font-family: var(--serif); font-size: 21px; margin: 34px 0 10px; }
.prose-page h3 { font-size: 14px; margin: 22px 0 6px; color: var(--ink); }
.prose-page p, .prose-page li { color: var(--ink-2); font-size: 14.5px; line-height: 1.68; }
.prose-page ul { padding-left: 20px; }
.prose-page code { font-family: var(--mono); font-size: 12.5px; background: var(--bg-3); padding: 1px 5px; border-radius: 4px; color: #cfd6e0; }
.site-foot { border-top: 1px solid var(--line); padding: 20px 22px 40px; }
.site-foot p { max-width: 800px; margin: 0 auto; color: var(--ink-3); font-size: 12.5px; }

.model-card { background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px; padding: 18px 20px; margin-bottom: 16px; }
.model-card h2 { margin-top: 0; }
.model-card .who { color: var(--ink-3); font-size: 12.5px; margin-bottom: 12px; }
.model-card .pillrow { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.pill { font-size: 11px; padding: 3px 9px; border-radius: 20px; border: 1px solid var(--line-2); color: var(--ink-2); }
.pill.yes { border-color: #2f5540; color: #7fc9a2; }
.pill.no { border-color: #3a3a44; color: var(--ink-3); }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-top: 10px; }
.two-col h3 { margin-top: 0; }
.two-col ul { margin: 0; }

@media (max-width: 1100px) { :root { --rail-w: 268px; --card-w: 340px; } }
@media (max-width: 820px) {
  :root { --tl-h: 118px; }
  .atlas { grid-template-columns: 0 1fr; }
  .rail { position: absolute; left: 0; top: 0; bottom: 0; width: 290px; z-index: 25; transform: translateX(-100%); transition: transform .2s; }
  .atlas:not(.rail-closed) .rail { transform: none; }
  .atlas:not(.rail-closed) .rail > * { display: revert; }
  .rail-toggle { right: -30px; }
  .site-nav { display: none; }
  .card-panel { width: 100%; }
  .two-col { grid-template-columns: 1fr; }
  .stage-tools .tool span { display: none; }
}
