:root {
  --ink: #2b211b;
  --muted: #6d5a49;
  --paper: rgba(246, 239, 225, 0.93);
  --paper-solid: #f6efe1;
  --line: rgba(120, 80, 50, 0.25);
  --red: #9b2d20;
  --gold: #b8892e;
  --shadow: 0 6px 24px rgba(40, 20, 10, 0.25);
  --page: #cddbd7;
  --sea: #1f4e79;
  --river: #2a7f7a;
  --road: #8b3a1e;
  --serif: 'Cormorant Garamond', 'Georgia', serif;
  --sans: 'Source Sans 3', system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ink: #f1e6d3; --muted: #c4ad92; --paper: rgba(38, 28, 22, 0.92); --paper-solid: #261c16; --line: rgba(230, 190, 140, 0.2);
    --red: #e0735f; --gold: #e2b85c; --page: #1d2526; --sea: #8db8e0; --river: #7cc9c2; --road: #e09a72; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --ink: #f1e6d3; --muted: #c4ad92; --paper: rgba(38, 28, 22, 0.92); --paper-solid: #261c16; --line: rgba(230, 190, 140, 0.2);
  --red: #e0735f; --gold: #e2b85c; --page: #1d2526; --sea: #8db8e0; --river: #7cc9c2; --road: #e09a72; color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none; background: var(--page); color: var(--ink); font: 15px/1.45 var(--sans); }
#map { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
#map.drag { cursor: grabbing; }
#map.hot { cursor: pointer; }
button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: transparent; border-radius: 6px; padding: 3px 9px; }
button:hover { border-color: var(--red); }
.panel { position: fixed; background: var(--paper); backdrop-filter: blur(6px); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); }
.spqr { font: 700 26px/1 var(--serif); letter-spacing: 0.22em; color: var(--red); }
.row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }

#top { top: 12px; left: 12px; padding: 10px 14px 10px; width: min(440px, calc(100vw - 24px)); display: flex; flex-direction: column; gap: 6px; }
.brand { display: flex; align-items: baseline; gap: 10px; }
.brand button { font-size: 13px; padding: 2px 8px; }
#sub { font: italic 500 17px var(--serif); color: var(--muted); }
#eras { display: flex; gap: 4px; flex-wrap: wrap; }
#eras button { flex: 1 1 0; min-width: 70px; padding: 3px 6px; text-align: left; line-height: 1.15; }
#eras button b { display: block; font: 700 15px var(--serif); }
#eras button span { font-size: 11.5px; color: var(--muted); }
#eras button.on { background: var(--red); border-color: var(--red); color: #fbf3e6; }
#eras button.on span { color: #f3d9c9; }
.steprow { display: flex; align-items: center; gap: 6px; }
.steprow input { flex: 1; min-width: 0; accent-color: var(--red); }
#month { accent-color: var(--sea); }
button.step { width: 28px; height: 28px; flex: none; padding: 0; border-radius: 14px; font: 700 18px/1 var(--serif); }
output { font: 700 17px var(--serif); min-width: 104px; text-align: right; }
#season { font: italic 500 16px/1.2 var(--serif); color: var(--muted); }
#season b { font-style: normal; }
#season.closed b { color: var(--red); }
#season.open b { color: var(--sea); }
.seg { display: flex; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; }
.seg button { border: none; border-radius: 0; padding: 4px 9px; font-size: 14px; }
.seg button.on { background: var(--red); color: #fbf3e6; }
.seg.topics button { flex: 1 1 0; padding: 4px 4px; font-size: 13.5px; }
.overs { font-size: 13px; color: var(--muted); }
.chips { display: flex; gap: 4px; flex-wrap: wrap; }
.chips button { font-size: 13px; padding: 1px 8px; border-radius: 12px; color: var(--ink); }
.chips button.on { background: var(--ink); border-color: var(--ink); color: var(--paper-solid); }
.list button.off { opacity: 0.55; }
#traveller button.on { background: var(--muted); }

#side { right: 12px; top: 12px; width: min(360px, calc(100vw - 24px)); padding: 12px 16px 14px; max-height: calc(100vh - 24px); overflow: auto; }
#side[hidden] { display: none; }
.close { position: absolute; top: 6px; right: 8px; border: none; font-size: 22px; line-height: 1; padding: 0 6px; }
#side h2 { margin: 0 26px 0 0; font: 700 24px/1.1 var(--serif); color: var(--red); font-style: italic; }
#side h3 { margin: 12px 0 4px; font: 700 17px var(--serif); }
.modern { font-weight: 600; }
.meta { font-size: 13px; color: var(--muted); }
#side p { margin: 8px 0; }
.big { display: flex; gap: 16px; margin: 10px 0 4px; }
.big div { flex: 1; border-top: 2px solid var(--line); padding-top: 4px; }
.big b { display: block; font: 700 30px/1 var(--serif); }
.big span { font-size: 12.5px; color: var(--muted); }
.big .out b { color: var(--red); }
ol.legs { list-style: none; padding: 0; margin: 4px 0; font-size: 13.5px; }
ol.legs li { display: flex; gap: 8px; align-items: baseline; padding: 2px 0; border-bottom: 1px dotted var(--line); }
ol.legs li .d { margin-left: auto; white-space: nowrap; font-variant-numeric: tabular-nums; }
.mode { display: inline-block; width: 18px; height: 3px; border-radius: 2px; flex: none; transform: translateY(-3px); }
.mode.sea { background: var(--sea); } .mode.river { background: var(--river); } .mode.road { background: var(--road); }
.list { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; }
.list button { text-align: left; display: flex; justify-content: space-between; gap: 8px; }
.list button.on { border-color: var(--red); background: rgba(155, 45, 32, 0.08); }
.list button span { color: var(--muted); font-size: 13px; }
.list button:disabled { opacity: 0.6; cursor: default; }
blockquote { margin: 10px 0; padding: 0 0 0 10px; border-left: 3px solid var(--gold); }
blockquote .la { font: italic 500 18px/1.25 var(--serif); }
blockquote .tr { font-size: 14px; margin-top: 4px; }
blockquote .ref { font-size: 12.5px; color: var(--red); font-weight: 600; }
.src { font-size: 12px; color: var(--muted); margin-top: 10px; }
a { color: var(--red); }

#legend { left: 12px; bottom: 12px; padding: 8px 12px; font-size: 12.5px; display: flex; flex-direction: column; gap: 4px; }
#legend .bins { display: flex; gap: 0; align-items: center; }
#legend .bins i { width: 26px; height: 10px; display: inline-block; }
#legend .ticks { display: flex; font-size: 11px; color: var(--muted); }
#legend .ticks span { width: 26px; text-align: left; }
#legend .notes { color: var(--muted); max-width: 260px; display: flex; flex-direction: column; gap: 2px; }
#legend .notes span { display: inline; }
.area { display: inline-block; width: 12px; height: 10px; background: rgba(155, 45, 32, 0.2); border: 1.5px solid var(--red); transform: translateY(1px); }
.arrow { font-style: normal; color: var(--sea); font-weight: 700; }
.mode.thin { height: 1.5px; opacity: 0.7; }
#legend .keys { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; color: var(--muted); }
.ring { display: inline-block; width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--red); transform: translateY(1px); }

#tip { position: fixed; pointer-events: none; background: var(--paper-solid); border: 1px solid var(--line); border-radius: 6px; padding: 3px 8px; font-size: 13px; box-shadow: var(--shadow); white-space: nowrap; z-index: 5; }
#tip b { font: italic 700 15px var(--serif); }

@media (max-width: 760px) {
  #top { padding: 8px 10px; gap: 4px; }
  .spqr { font-size: 21px; }
  #eras button span { display: none; }
  #eras button { min-width: 50px; }
  #side { top: auto; bottom: 12px; max-height: 45vh; }
  #legend { display: none; }
}
