:root {
  --page: #dde3e1;          /* pale slate beyond the known world */
  --page-dark: #b8c2c0;
  --sea: #c8dade;
  --land: #f7f7f2;
  --ink: #1f2a31;
  --ink-soft: #485863;
  --ink-faint: #87949b;
  --coast: #4f626b;
  --water-ink: #3a6478;
  --river: #6c93a4;
  --accent: #2d6a4f;        /* deep pine green */
  --accent-soft: #4f8a6e;
  --gold: #a8832a;
  --panel: rgba(250, 251, 249, 0.95);
  --panel-line: rgba(40, 62, 74, 0.18);
  --tl-bg: #edf1f0;
  --tl-h: 220px;
  --serif: "Alegreya", Georgia, serif;
  --fell: "Alegreya", Georgia, serif;
  --fell-sc: "Alegreya SC", "Alegreya", Georgia, serif;

  --c-law: #c08a3e; --c-history: #5f8a8a; --c-wisdom: #a39a3a; --c-prophets: #8a4f7a;
  --c-gospels: #2d6a4f; --c-letters: #3d5a8a; --c-apocalyptic: #6a4f9a;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--page);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 15px;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; }
a { color: var(--accent); }

#app { display: grid; grid-template-rows: 1fr auto; height: 100vh; height: 100dvh; }
#stage { position: relative; overflow: hidden; min-height: 0; }
#map { position: absolute; inset: 0; }
.map-base { position: absolute; left: 0; top: 0; pointer-events: none; }
.map-base.cached { transform-origin: 0 0; will-change: transform; }
.map-overlay { position: absolute; left: 0; top: 0; }
.routes-layer { pointer-events: none; }
.labels-layer { cursor: grab; touch-action: none; }
.labels-layer:active { cursor: grabbing; }

.paper { position: absolute; inset: 0; pointer-events: none; mix-blend-mode: multiply; opacity: .9; will-change: transform; }
.vignette {
  position: absolute; inset: 0; pointer-events: none;
  box-shadow: inset 0 0 120px 30px rgba(30, 50, 60, 0.35), inset 0 0 18px 2px rgba(25, 40, 50, 0.35);
}

/* ───────── Map layers ───────── */
.sea { fill: var(--sea); }
.graticule { fill: none; stroke: #5f7480; stroke-opacity: 0.18; stroke-width: 0.6px; vector-effect: non-scaling-stroke; stroke-dasharray: 2 3; }
.waterlines use { fill: none; vector-effect: non-scaling-stroke; stroke-linejoin: round; }
.wl-line { stroke: var(--water-ink); }
.wl-sea { stroke: var(--sea); }
.land { fill: var(--land); }
.coast { fill: none; stroke: var(--coast); stroke-width: 1.1px; vector-effect: non-scaling-stroke; stroke-linejoin: round; }
.lakes { fill: var(--sea); stroke: var(--coast); stroke-width: 0.8px; vector-effect: non-scaling-stroke; }
.rivers { fill: none; stroke: var(--river); stroke-width: 1.2px; vector-effect: non-scaling-stroke; stroke-linecap: round; stroke-linejoin: round; }
.power { fill-opacity: 0.16; stroke-opacity: 0.7; stroke-width: 1.4px; stroke-dasharray: 5 3 1 3; vector-effect: non-scaling-stroke; transition: opacity .25s; }
.route { fill: none; stroke: var(--accent); stroke-width: 1.6px; stroke-dasharray: 6 5; vector-effect: non-scaling-stroke; stroke-opacity: 0.55; stroke-linecap: round; }
.route.strong { stroke-width: 2.4px; stroke-opacity: 0.9; animation: march 1.2s linear infinite; }
@keyframes march { to { stroke-dashoffset: -22; } }

.labels text { paint-order: stroke; stroke: var(--land); stroke-width: 3.5px; stroke-linejoin: round; }
.power-label { font-family: var(--fell-sc); letter-spacing: .14em; text-anchor: middle; pointer-events: none; stroke: none !important; font-style: italic; }

.region { cursor: pointer; }
.region text {
  font-family: var(--fell-sc); text-anchor: middle; letter-spacing: .28em;
  fill: var(--ink-soft); fill-opacity: .55; stroke-width: 0;
  transition: fill .2s, fill-opacity .2s;
}
.region.now text { fill: var(--accent); fill-opacity: .72; }
.region.hl text { fill: var(--accent); fill-opacity: 1; }
.region:hover text { fill-opacity: 1; }

.place { cursor: pointer; }
.place .lbl { font-family: var(--fell); fill: var(--ink); }
.place .dot { fill: var(--ink); stroke: var(--land); stroke-width: 1.2px; }
.place.r1 .dot { stroke: var(--ink); fill: var(--land); stroke-width: 1.6px; }
.place .mtn { fill: #7d8a86; stroke: #46545a; stroke-width: 0.8px; }
.place.t-water .lbl, .place.t-river .lbl { font-style: italic; fill: var(--water-ink); letter-spacing: .06em; stroke: var(--sea); }
.place.t-river .lbl { stroke: var(--land); }

.place.s0 .dot { fill: var(--ink-faint); stroke: none; r: 2; opacity: .55; }
.place.s0.r1 .dot { fill: none; stroke: var(--ink-faint); }
.place.s0 .lbl { fill: var(--ink-faint); }
.place.s1 .lbl { fill: var(--ink-soft); }
.place.s2 .lbl { fill: var(--ink); }
.place.s3 .lbl { fill: var(--accent); font-weight: 400; }
.place.s3 .dot { fill: var(--accent); stroke: var(--land); }
.place.s3.r1 .dot { fill: var(--land); stroke: var(--accent); stroke-width: 2px; }
.place.hl .lbl { fill: var(--accent); text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px; }
.place.hl .dot { fill: var(--accent); stroke: #ffffff; stroke-width: 2px; r: 5; }
.place.hl .mtn { fill: var(--accent); }
.place:hover .lbl { fill: var(--accent); }

/* ───────── Ornaments ───────── */
.cartouche {
  position: absolute; left: 18px; top: 16px; padding: 10px 22px 12px;
  background: rgba(250, 251, 249, 0.82); border: 1px solid rgba(40, 62, 74, .45);
  outline: 1px solid rgba(40, 62, 74, .25); outline-offset: 3px;
  border-radius: 2px; box-shadow: 0 4px 16px rgba(25, 45, 55, 0.18);
  pointer-events: none; text-align: center;
}
.cartouche h1 { margin: 0; font-family: var(--fell-sc); font-weight: 400; font-size: 26px; letter-spacing: .12em; color: var(--ink); }
.cartouche .sub { font-family: var(--fell); font-style: italic; font-size: 14px; color: var(--ink-soft); margin-top: 1px; }

.compass { position: absolute; left: 26px; bottom: 58px; width: 84px; height: 84px; opacity: .6; pointer-events: none; }
.c-ring { fill: none; stroke: var(--ink-soft); stroke-width: 1.2; }
.c-ring.thin { stroke-width: .6; stroke-dasharray: 2 2; }
.c-dark { fill: var(--ink-soft); }
.c-light { fill: #f4f6f4; stroke: var(--ink-soft); stroke-width: .6; }
.c-n { font-family: var(--fell-sc); font-size: 11px; text-anchor: middle; fill: var(--ink); }

.map-controls { position: absolute; left: 18px; top: 112px; display: flex; flex-direction: column; gap: 4px; }
.map-controls button {
  width: 32px; height: 32px; border-radius: 3px; border: 1px solid rgba(40, 62, 74, .45);
  background: rgba(250, 251, 249, 0.9); cursor: pointer; font-size: 18px; line-height: 1; color: var(--ink);
}
.map-controls button:hover { background: #ffffff; color: var(--accent); }

.map-options {
  position: absolute; left: 18px; bottom: 12px; display: flex; gap: 14px; align-items: center;
  padding: 5px 14px; font-size: 14px; background: rgba(250, 251, 249, 0.86); border: 1px solid rgba(40, 62, 74, .3);
  border-radius: 20px; white-space: nowrap;
}
.map-options label { display: flex; gap: 5px; align-items: center; cursor: pointer; color: var(--ink-soft); }
.map-options input { accent-color: var(--accent); margin: 0; }
.link-btn { background: none; border: 0; padding: 0; cursor: pointer; color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }

/* ───────── Panel ───────── */
#panel {
  position: absolute; right: 16px; top: 16px; bottom: 16px; width: 360px;
  display: flex; flex-direction: column; pointer-events: none;
  transition: transform .3s ease;
}
#panel-body {
  pointer-events: auto; overflow-y: auto; max-height: 100%;
  background: var(--panel); border: 1px solid var(--panel-line); border-radius: 4px;
  box-shadow: 0 8px 30px rgba(25, 45, 55, 0.22);
  padding: 16px 18px 18px; backdrop-filter: blur(3px);
  scrollbar-width: thin; scrollbar-color: rgba(40, 62, 74, .35) transparent;
}
#panel-toggle {
  pointer-events: auto; position: absolute; left: -42px; top: 0; width: 34px; height: 34px;
  border-radius: 3px; border: 1px solid rgba(40, 62, 74, .45); background: rgba(250, 251, 249, 0.92); cursor: pointer;
}
body.panel-collapsed #panel { transform: translateX(calc(100% + 16px)); }

#panel h2 { margin: 2px 0 2px; font-family: var(--fell); font-weight: 400; font-size: 28px; line-height: 1.1; }
#panel h3 {
  margin: 18px 0 8px; font-family: var(--fell-sc); font-weight: 400; font-size: 15px; letter-spacing: .08em; color: var(--ink-soft);
  border-bottom: 1px solid var(--panel-line); padding-bottom: 3px; display: flex; align-items: baseline; gap: 6px;
}
.count { font-family: var(--serif); font-size: 12px; color: var(--ink-faint); }
.kicker { font-family: var(--fell-sc); font-size: 13px; letter-spacing: .1em; color: var(--accent); }
.alt { font-style: italic; color: var(--ink-soft); }
.desc, .era-desc { line-height: 1.45; margin: 10px 0; }
.era-desc { color: var(--ink-soft); margin-top: 4px; font-style: italic; }
.muted { color: var(--ink-faint); }
.empty { font-style: italic; }
.uncertain-tag { color: var(--gold); }
.panel-top { margin: -4px 0 8px; }
.back { background: none; border: 0; padding: 0; cursor: pointer; color: var(--ink-soft); font-size: 14px; }
.back:hover { color: var(--accent); }

.events { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 2px; }
.ev { padding: 7px 8px 8px; border-radius: 3px; cursor: pointer; border-left: 2px solid transparent; transition: background .15s; }
.ev:hover { background: rgba(45, 106, 79, 0.06); }
.ev.primary { border-left-color: var(--accent); background: rgba(45, 106, 79, 0.04); }
.ev.focus { background: rgba(45, 106, 79, 0.1); border-left-color: var(--accent); }
.ev-head { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.ev-title { font-weight: 500; line-height: 1.25; }
.ev.primary .ev-title { color: var(--accent); }
.ev-date { font-size: 12.5px; color: var(--ink-faint); white-space: nowrap; }
.ev-desc { margin: 4px 0 2px; line-height: 1.4; font-size: 14.5px; color: var(--ink); }
.events.compact .ev { padding: 5px 8px; }

.refs { display: flex; flex-wrap: wrap; gap: 3px 10px; margin-top: 3px; font-size: 13.5px; }
.refs.block { font-size: 14.5px; gap: 4px 12px; }
a.ref { color: var(--accent); text-decoration: none; border-bottom: 1px dotted rgba(45, 106, 79, .5); }
a.ref:hover { border-bottom-style: solid; }
a.ref::after { content: " ↗"; font-size: 10px; opacity: .55; }

.chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.chip {
  border: 1px solid rgba(40, 62, 74, .35); background: rgba(255, 255, 255, .7); border-radius: 12px;
  padding: 1px 9px; font-size: 13px; cursor: pointer; color: var(--ink-soft); line-height: 1.5;
}
.chip:hover { border-color: var(--accent); color: var(--accent); background: #ffffff; }
.book-chip { border-left: 3px solid var(--cat, var(--ink-soft)); }

.row-actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0 4px; }
.btn {
  border: 1px solid rgba(40, 62, 74, .45); background: rgba(255, 255, 255, .8); border-radius: 3px; padding: 4px 12px;
  cursor: pointer; text-decoration: none; color: var(--ink); font-size: 14px;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.primary { background: var(--accent); color: #f4faf7; border-color: var(--accent); }
.btn.primary:hover { background: #3a7d60; color: #fff; }

.c-law { --cat: var(--c-law); } .c-history { --cat: var(--c-history); } .c-wisdom { --cat: var(--c-wisdom); }
.c-prophets { --cat: var(--c-prophets); } .c-gospels { --cat: var(--c-gospels); } .c-letters { --cat: var(--c-letters); }
.c-apocalyptic { --cat: var(--c-apocalyptic); }

/* ───────── Timeline ───────── */
#timeline-wrap {
  position: relative; background: var(--tl-bg);
  border-top: 1px solid rgba(40, 62, 74, .45);
  box-shadow: 0 -6px 18px rgba(25, 45, 55, 0.18);
  user-select: none;
}
#timeline-wrap::before { /* double rule */
  content: ""; position: absolute; left: 0; right: 0; top: 3px; border-top: 1px solid rgba(40, 62, 74, .25);
}
#timeline { position: relative; height: var(--tl-h); cursor: ew-resize; touch-action: none; margin-top: 8px; }
#timeline.dragging { cursor: grabbing; }
.tl-svg { display: block; }
.tl-bg { fill: transparent; }
.group-band { fill: rgba(40, 62, 74, 0.035); }
.group-band.g1 { fill: rgba(70, 110, 120, 0.05); }
.group-label { font-family: var(--fell-sc); font-size: 11px; letter-spacing: .1em; fill: var(--ink-faint); pointer-events: none; paint-order: stroke; stroke: var(--tl-bg); stroke-width: 3px; }

.era rect { fill: rgba(40, 62, 74, .1); stroke: rgba(40, 62, 74, .25); stroke-width: .5px; cursor: pointer; }
.era.e1 rect { fill: rgba(40, 62, 74, .17); }
.era.undated rect { fill: url(#hatch); }
.era.now rect { fill: rgba(45, 106, 79, .2); }
.era text { font-family: var(--fell-sc); font-size: 12px; letter-spacing: .06em; fill: var(--ink-soft); text-anchor: middle; pointer-events: none; }
.era.now text { fill: var(--accent); }
.era:hover rect { fill: rgba(45, 106, 79, .14); }

.axis line { stroke: var(--ink-faint); }
.axis text { font-size: 11.5px; fill: var(--ink-faint); text-anchor: middle; }

.hatch-line { stroke: rgba(40, 62, 74, .22); stroke-width: 2; }
.primeval-hatch { pointer-events: all; }
.primeval-label { font-family: var(--fell); font-style: italic; font-size: 12px; fill: var(--ink-soft); text-anchor: middle; pointer-events: none; }

.tl-ev { cursor: pointer; }
.tl-ev line { stroke: var(--ink-faint); stroke-width: 2px; stroke-opacity: .5; stroke-linecap: round; }
.tl-ev path { fill: var(--ink-faint); stroke: var(--tl-bg); stroke-width: 1px; }
.tl-ev.near path { fill: var(--ink-soft); }
.tl-ev.now path, .tl-ev.focus path { fill: var(--accent); }
.tl-ev.now line { stroke: var(--accent); }
.tl-ev.place-hl path { fill: var(--gold); transform-box: fill-box; transform-origin: center; scale: 1.5; }
.tl-ev.place-hl line { stroke: var(--gold); stroke-opacity: 1; }
.tl-ev:hover path { fill: var(--accent); }

.book { cursor: pointer; }
.book rect { fill: var(--cat); fill-opacity: .2; stroke: var(--cat); stroke-opacity: .6; stroke-width: 1px; transition: fill-opacity .15s; }
.book.uncertain rect { stroke-dasharray: 3 2; }
.book text { font-size: 11.5px; fill: var(--ink); pointer-events: none; }
.book text.outside { fill: var(--ink-soft); }
.book.now rect { fill-opacity: .45; stroke-opacity: 1; }
.book.hl rect, .book:hover rect { fill-opacity: .8; stroke-opacity: 1; }
.book.hl text:not(.outside), .book:hover text:not(.outside) { fill: #ffffff; }
.book.place-hl rect { stroke: var(--gold); stroke-width: 2px; stroke-opacity: 1; }

.needle line { stroke: var(--accent); stroke-width: 1.5px; }
.needle path { fill: var(--accent); }
.needle { pointer-events: none; }
.needle-label {
  position: absolute; left: 50%; top: -44px; transform: translateX(-50%); z-index: 3; text-align: center;
  background: var(--accent); color: #f4faf7; padding: 3px 16px 4px; border-radius: 3px;
  box-shadow: 0 3px 10px rgba(15, 45, 32, .3); pointer-events: none; min-width: 150px;
}
.needle-label::after {
  content: ""; position: absolute; left: 50%; bottom: -6px; transform: translateX(-50%);
  border: 6px solid transparent; border-bottom: 0; border-top-color: var(--accent);
}
#needle-date { font-family: var(--fell); font-size: 19px; line-height: 1.15; }
#needle-era { font-family: var(--fell-sc); font-size: 11.5px; letter-spacing: .1em; opacity: .85; }
.tl-hint { position: absolute; right: 12px; bottom: 3px; font-size: 11.5px; color: var(--ink-faint); font-style: italic; pointer-events: none; }

/* ───────── Tooltip & dialogs ───────── */
#tip {
  position: fixed; left: 0; top: 0; z-index: 50; max-width: 300px; pointer-events: none;
  background: #fbfcfb; border: 1px solid rgba(40, 62, 74, .45); border-radius: 3px;
  padding: 8px 11px; font-size: 14px; line-height: 1.35; box-shadow: 0 6px 20px rgba(20, 35, 45, .25);
}
#tip b { font-weight: 600; }
.tip-title { font-family: var(--fell); font-size: 18px; line-height: 1.15; margin-bottom: 3px; }
.tip-desc { color: var(--ink); }
.tip-now { margin-top: 6px; padding-top: 5px; border-top: 1px solid var(--panel-line); color: var(--accent); }
.tip-k { display: block; font-family: var(--fell-sc); font-size: 12px; letter-spacing: .08em; color: var(--ink-soft); }
.tip-hint { margin-top: 5px; font-size: 12px; font-style: italic; color: var(--ink-faint); }

#about { position: fixed; inset: 0; z-index: 60; background: rgba(20, 35, 45, .35); display: grid; place-items: center; padding: 16px; }
#about[hidden] { display: none; }
.about-card {
  position: relative; max-width: 560px; max-height: 85vh; overflow: auto; background: #f9faf8;
  border: 1px solid rgba(40, 62, 74, .45); outline: 1px solid rgba(40, 62, 74, .25); outline-offset: -6px;
  padding: 22px 28px; border-radius: 3px; line-height: 1.5; box-shadow: 0 12px 40px rgba(20, 35, 45, .35);
}
.about-card h2 { font-family: var(--fell-sc); font-weight: 400; margin: 0 0 8px; letter-spacing: .06em; }
.about-card h3 { font-family: var(--fell-sc); font-weight: 400; margin: 16px 0 4px; color: var(--accent); }
.about-card p { margin: 6px 0; }
.about-card .close { position: absolute; right: 10px; top: 6px; border: 0; background: none; font-size: 24px; cursor: pointer; color: var(--ink-soft); }
.fatal { position: fixed; inset: auto 20px 20px 20px; padding: 14px; background: #e8f3ee; border: 1px solid var(--accent); z-index: 99; }




/* ───────── Small screens ───────── */
@media (max-width: 820px) {
  :root { font-size: 14px; }
  #panel { width: min(360px, calc(100vw - 64px)); top: 72px; bottom: 56px; right: 10px; }
  .cartouche { left: 10px; top: 10px; padding: 6px 12px 7px; }
  .cartouche h1 { font-size: 18px; }
  .cartouche .sub { font-size: 12px; }
  .map-controls { left: 10px; top: 76px; }
  .compass { display: none; }
  .map-options { gap: 10px; font-size: 13px; bottom: 58px; left: 10px; padding: 4px 10px; max-width: calc(100vw - 16px); }
  .tl-hint { display: none; }
}
