/* Layout: an engraved county-map sheet — sidebar "key" on the left, the map plate filling the rest; stacks on phones. */
:root {
  color-scheme: light;
  --paper: #efe5ca;
  --paper-deep: #e3d4ad;
  --ink: #2a2017;
  --ink-soft: #5e4d37;
  --rule: #b9a47c;
  --sea: #cdd0bd;
  --sea-line: #aeb39c;
  --parl: #24508f;   /* Parliament: blue */
  --roy: #b0202e;    /* Royalists: red */
  --scot: #e0ad1f;   /* Scots: yellow */
  --focus: #1f4e79;
  --card: var(--paper);        /* pop-ups and hover labels: same parchment as the map */
  --card-soft: var(--paper-deep);
  --inlay: #f8f2e2;            /* lighter parchment behind the reading text */
  --f-display: "IM Fell English", "Iowan Old Style", Georgia, serif;
  --f-sc: "IM Fell English SC", "IM Fell English", Georgia, serif;
  --f-body: "Alegreya", Georgia, "Times New Roman", serif;
  --f-ui: "Alegreya Sans", "Gill Sans", "Segoe UI", system-ui, sans-serif;
}
html, body { height: 100%; }
body { background: var(--paper); color: var(--ink); font-family: var(--f-body); font-size: 15px; }
* { box-sizing: border-box; }
[hidden] { display: none !important; }
button, input { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.app { display: grid; grid-template-columns: minmax(320px, 400px) 1fr; height: 100%; }
.key {
  overflow-y: auto; border-right: 1px solid var(--rule);
  background: linear-gradient(var(--paper), var(--paper-deep));
  padding-block: 22px 28px;
  padding-left: max(18px, env(safe-area-inset-left, 0px));
  padding-right: 18px;
  display: flex; flex-direction: column; gap: 20px; min-width: 0;
}
.plate { position: relative; min-width: 0; }
#map { position: absolute; inset: 0; }

header .eyebrow { font-family: var(--f-ui); font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--ink-soft); }
header h1 { font-family: var(--f-display); font-weight: 400; font-size: 34px; line-height: 1.02; margin: 4px 0 8px; text-wrap: balance; }
header h1 em { font-style: italic; color: var(--roy); }
header p { margin: 0; color: var(--ink-soft); line-height: 1.45; max-width: 60ch; }

.section-label { font-family: var(--f-sc); font-size: 15px; font-weight: 400; letter-spacing: .04em; margin: 0 0 8px; display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.section-label small { font-family: var(--f-ui); font-size: 12px; color: var(--ink-soft); letter-spacing: 0; }

.topbar { position: sticky; top: -22px; z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: 6px 12px; flex-wrap: wrap;
  border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule); padding-block: 8px; background: var(--paper); box-shadow: 0 6px 8px -8px rgba(40, 28, 10, .35); }
.stats { font-family: var(--f-ui); font-size: 13px; color: var(--ink-soft); display: flex; flex-wrap: wrap; gap: 2px 14px; font-variant-numeric: tabular-nums; min-width: 0; flex: 1 1 180px; }
.reset { flex: none; font-family: var(--f-ui); font-size: 12.5px; font-weight: 700; min-height: 32px; padding: 4px 12px; border: 1px solid var(--ink); border-radius: 999px; background: transparent; color: var(--ink); cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.reset span { font-size: 14px; line-height: 1; }
.reset.active { background: var(--ink); color: var(--paper); }
.reset:hover { background: var(--paper-deep); }
.reset.active:hover { background: #000; }

/* sections of the side panel: each set off by a rule */
.key > section, .key > details { border-top: 1px solid var(--rule); padding-top: 14px; }
.key > .topbar + * { border-top: 0; padding-top: 0; }
.key { gap: 18px; }
/* Stories: a section that drops down */
.stories-sec > summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 10px; }
.stories-sec > summary::-webkit-details-marker { display: none; }
.stories-sec > summary .section-label { flex: 1; margin: 0; min-width: 0; }
.stories-sec > summary .section-label small { font-family: var(--f-display); font-style: italic; font-size: 14px; color: var(--roy); text-align: right; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stories-sec > summary::after { content: ""; flex: none; width: 8px; height: 8px; margin: 0 4px 4px 0; border-right: 1.5px solid var(--ink); border-bottom: 1.5px solid var(--ink); transform: rotate(45deg); transition: transform .2s; }
.stories-sec[open] > summary::after { transform: rotate(-135deg); margin-bottom: -4px; }
.stories-sec[open] > summary { margin-bottom: 8px; }
.stories-sec > summary:hover .section-label { color: var(--roy); }
.stats b { color: var(--ink); font-weight: 700; }

/* stories (the old story-map tabs) */
.stories { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-family: var(--f-ui); font-size: 12.5px; min-height: 30px; padding: 4px 11px; border: 1px solid var(--rule); background: transparent; border-radius: 999px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.chip[aria-pressed="true"] { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.chip .ct { font-size: 11px; opacity: .7; font-variant-numeric: tabular-nums; }

/* year histogram */
.hist { display: grid; grid-template-columns: repeat(15, minmax(0, 1fr)); gap: 3px; align-items: end; height: 92px; }
.hist button { display: flex; flex-direction: column; justify-content: flex-end; align-items: stretch; height: 100%; padding: 0; border: 0; background: none; cursor: pointer; gap: 3px; min-width: 0; }
.hist .bar { background: var(--ink-soft); opacity: .45; border-radius: 1px 1px 0 0; min-height: 1px; transition: opacity .15s; }
.hist .n { font-family: var(--f-ui); font-size: 10px; color: var(--ink-soft); text-align: center; font-variant-numeric: tabular-nums; }
.hist button:hover .bar { opacity: .75; }
.hist button[aria-pressed="true"] .bar { background: var(--ink); opacity: 1; }
.years { display: grid; grid-template-columns: repeat(15, minmax(0, 1fr)); gap: 3px; margin-top: 4px; font-family: var(--f-ui); font-size: 10px; color: var(--ink-soft); text-align: center; font-variant-numeric: tabular-nums; }
.wars { display: grid; grid-template-columns: 2fr 5fr 2fr 3fr 3fr; gap: 3px; margin-top: 6px; font-family: var(--f-ui); font-size: 10.5px; color: var(--ink-soft); text-align: center; }
.wars span { border-top: 1px solid var(--rule); padding-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.year-row { display: flex; gap: 8px; margin-top: 10px; align-items: center; flex-wrap: wrap; }
.undated { font-family: var(--f-ui); font-size: 11.5px; color: var(--ink-soft); }

/* side filter */
.sides { display: flex; flex-wrap: wrap; gap: 6px; }
.side { display: inline-flex; align-items: center; gap: 7px; font-family: var(--f-ui); font-size: 13px; padding: 5px 10px 5px 8px; border: 1px solid var(--rule); border-radius: 3px; cursor: pointer; background: transparent; user-select: none; position: relative; }
.side input { position: absolute; opacity: 0; pointer-events: none; }
.side .sw { width: 12px; height: 12px; border-radius: 50%; border: 1.5px solid var(--ink); }
.side .ct { font-size: 11px; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.side:has(input:not(:checked)) { opacity: .45; text-decoration: line-through; }
.side:has(input:focus-visible) { outline: 2px solid var(--focus); outline-offset: 2px; }
.size-key { display: flex; align-items: flex-end; flex-wrap: wrap; gap: 8px 14px; margin-top: 10px; font-family: var(--f-ui); font-size: 11.5px; color: var(--ink-soft); }
.size-key div { display: flex; flex-direction: column; align-items: center; gap: 3px; }
.size-key i { display: block; border-radius: 50%; border: 1.2px solid var(--ink-soft); }
.size-key i.dash { border-style: dashed; }

/* list */
.list-head { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; }
.search { flex: 1 1 160px; min-width: 0; padding: 6px 10px; border: 1px solid var(--rule); border-radius: 3px; background: color-mix(in srgb, var(--paper) 70%, white); font-family: var(--f-ui); font-size: 13.5px; }
.sort { display: inline-flex; border: 1px solid var(--rule); border-radius: 3px; overflow: hidden; }
.sort button { border: 0; background: none; padding: 5px 9px; font-family: var(--f-ui); font-size: 12px; cursor: pointer; }
.sort button + button { border-left: 1px solid var(--rule); }
.sort button[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
ol.list { list-style: none; padding: 0; margin: 8px 0 0; }
ol.list li button { width: 100%; text-align: left; background: none; border: 0; border-bottom: 1px dotted var(--rule); padding: 8px 2px; cursor: pointer; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 8px; align-items: baseline; }
ol.list li button:hover { background: color-mix(in srgb, var(--paper-deep) 70%, transparent); }
.nm { font-family: var(--f-display); font-size: 17px; line-height: 1.15; min-width: 0; }
.val { font-family: var(--f-ui); font-size: 12.5px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.meta { grid-column: 1 / 3; display: flex; align-items: center; gap: 7px; font-family: var(--f-ui); font-size: 11.5px; color: var(--ink-soft); min-width: 0; }
.meta .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.meta .txt { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.more { margin-top: 8px; }
.empty { font-style: italic; color: var(--ink-soft); padding: 10px 0; }

footer { font-size: 12.5px; color: var(--ink-soft); line-height: 1.45; border-top: 1px solid var(--rule); padding-top: 10px; }

/* map plate */
.leaflet-container {
  background-color: var(--sea);
  background-image: repeating-linear-gradient(0deg, transparent 0 5px, var(--sea-line) 5px 6px);
  font-family: var(--f-body);
}
.plate::after { content: ""; position: absolute; inset: 0; pointer-events: none; z-index: 500; box-shadow: inset 0 0 0 8px var(--paper), inset 0 0 0 9px var(--ink), inset 0 0 0 12px var(--paper), inset 0 0 0 12.5px var(--ink-soft), inset 0 0 60px rgba(90, 64, 30, .28); }
.lbl { font-family: var(--f-sc); color: var(--ink-soft); white-space: nowrap; text-align: center; pointer-events: none; transform: translate(-50%, -50%); width: max-content; }
.lbl.sea { font-family: var(--f-display); font-style: italic; color: #4f5745; font-size: 14px; letter-spacing: .08em; }
.lbl.realm { font-size: 17px; letter-spacing: .32em; opacity: .75; }
.lbl.town { font-family: var(--f-display); font-style: italic; color: var(--ink); font-size: 13px; transform: translate(8px, -50%); text-align: left; position: relative; }
.city { position: relative; transform: translate(8px, -50%); width: max-content; white-space: nowrap; pointer-events: none; font-family: var(--f-display); font-style: italic; font-size: 12.5px; color: var(--ink); text-shadow: 0 0 2px var(--paper), 0 0 3px var(--paper), 0 0 4px var(--paper); }
.city::before { content: ""; position: absolute; left: -10px; top: 50%; width: 5px; height: 5px; margin-top: -4px; border: 1.3px solid var(--ink); border-radius: 50%; background: var(--paper); box-shadow: inset 0 0 0 1.4px var(--paper), inset 0 0 0 3px var(--ink); }
.city.major { font-family: var(--f-sc); font-style: normal; font-size: 14px; letter-spacing: .04em; }
.city.major::before { width: 7px; height: 7px; left: -12px; margin-top: -5px; }
.city.capital { font-family: var(--f-sc); font-style: normal; font-size: 17px; letter-spacing: .06em; }
.city.capital::before { width: 9px; height: 9px; left: -13px; margin-top: -6px; background: var(--ink); box-shadow: inset 0 0 0 2px var(--paper); }
.leaflet-container.far .city.minor { display: none; }
.lbl.town::before { content: ""; position: absolute; left: -9px; top: 50%; width: 5px; height: 5px; margin-top: -2.5px; border: 1.2px solid var(--ink); background: var(--paper); transform: rotate(45deg); }
.compass { position: absolute; right: 26px; top: 24px; width: 92px; z-index: 450; pointer-events: none; opacity: .85; transition: opacity .2s; }
/* The compass and title box sit above the map's own layers, so they step aside while a pop-up is open. */
.plate.popup-open .compass, .plate.popup-open .cartouche { opacity: 0; }
.cartouche { position: absolute; left: 26px; bottom: 26px; z-index: 450; pointer-events: none; transition: opacity .2s; background: color-mix(in srgb, var(--paper) 88%, transparent); border: 1px solid var(--ink); outline: 1px solid var(--ink); outline-offset: 3px; padding: 8px 14px; font-family: var(--f-display); text-align: center; max-width: calc(100% - 52px); }
.cartouche .t { font-size: 17px; }
.cartouche .s { font-family: var(--f-ui); font-size: 11px; color: var(--ink-soft); letter-spacing: .06em; }
.leaflet-control-scale { margin-bottom: 26px !important; margin-right: 26px !important; }
.leaflet-control-scale-line { background: color-mix(in srgb, var(--paper) 80%, transparent); border-color: var(--ink); color: var(--ink); font-family: var(--f-ui); }
.leaflet-bar a { background: var(--paper); color: var(--ink); border-bottom-color: var(--rule); font-family: var(--f-display); }
.leaflet-bar { border: 1px solid var(--ink) !important; box-shadow: none !important; }
.leaflet-top.leaflet-left { margin: 18px 0 0 18px; }
.leaflet-tooltip.tip { background: var(--card); border: 1px solid var(--ink); color: var(--ink); font-family: var(--f-display); font-size: 14px; box-shadow: 0 1px 4px rgba(40, 28, 10, .25); padding: 2px 8px; border-radius: 2px; }
.leaflet-tooltip.tip::before { display: none; }

.leaflet-popup-content-wrapper { background: var(--card); color: var(--ink); border: 1px solid var(--ink); border-radius: 2px; box-shadow: 0 3px 14px rgba(40, 28, 10, .35); }
.leaflet-popup-tip { background: var(--card); border: 1px solid var(--ink); }
.leaflet-popup-content { margin: 14px 18px 14px 16px; width: 330px !important; max-width: calc(100vw - 90px); }
.leaflet-container a.leaflet-popup-close-button { color: var(--ink); background: var(--card); border-left: 1px solid var(--ink); border-bottom: 1px solid var(--ink); width: 26px; height: 26px; font-size: 18px; line-height: 24px; top: 0; right: 0; z-index: 2; box-sizing: border-box; border: 1px solid var(--ink); border-radius: 0 2px 0 3px; text-align: center; padding: 0; }
.pop figure { margin: -14px -18px 12px -16px; position: relative; background: var(--card-soft); }
.pop figure img { display: block; width: 100%; max-height: 210px; object-fit: cover; border-bottom: 1px solid var(--ink); filter: sepia(.12) saturate(.92); }
.pop figure figcaption { font-family: var(--f-ui); font-size: 11px; line-height: 1.35; color: var(--ink-soft); padding: 5px 16px 0; white-space: pre-line; }
.pop figure.loading img { min-height: 120px; }
.tip-img { display: block; width: 160px; height: 100px; object-fit: cover; margin: 4px 0 2px; border: 1px solid var(--ink); }
.pop h3 { font-family: var(--f-display); font-weight: 400; font-size: 22px; margin: 0; line-height: 1.1; padding-right: 12px; }
.pop .where { font-family: var(--f-ui); font-size: 12px; color: var(--ink-soft); margin-top: 2px; }
.pop .when { font-family: var(--f-ui); font-size: 12.5px; color: var(--ink); font-variant-numeric: tabular-nums; margin-top: 6px; }
.pop .read { margin: 12px -6px 0; padding: 10px 12px 4px; background: var(--inlay); border: 1px solid color-mix(in srgb, var(--rule) 70%, transparent); border-radius: 2px; box-shadow: inset 0 1px 0 #fffaf0; }
.pop .headline { margin: 0 0 8px; font-size: 15px; line-height: 1.4; font-style: italic; }
.pop .body { max-height: 190px; overflow-y: auto; font-size: 14px; line-height: 1.5; padding-right: 6px; border-top: 1px solid var(--rule); padding-top: 8px; scrollbar-color: var(--rule) transparent; }
.pop .body p { margin: 0 0 .7em; }
.pop .tags { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 8px; font-family: var(--f-ui); font-size: 12px; }
.pop .sides { display: block; font-family: var(--f-ui); font-size: 12.5px; margin-top: 6px; color: var(--ink-soft); }
.pop .story { border: 1px solid var(--ink-soft); padding: 1px 8px; border-radius: 999px; }
.pop .visit { display: inline-block; margin-top: 8px; font-family: var(--f-ui); font-size: 13px; color: var(--roy); }
/* siege markers (divIcons, so several sieges at one place can share one marker) */
.sg { position: absolute; border-radius: 50%; border: 1px solid var(--ink); box-sizing: border-box; opacity: .9; transition: transform .12s; }
.sg.unknown { border: 1.6px dashed var(--c); background: color-mix(in srgb, var(--paper) 60%, transparent) !important; opacity: 1; }
.sg.multi { border-width: 1.5px; opacity: .95; }
.sg .badge { position: absolute; right: -7px; top: -7px; min-width: 17px; height: 17px; padding: 0 4px; box-sizing: border-box; border-radius: 9px; background: var(--ink); color: var(--paper); font: 700 10.5px/17px var(--f-ui); text-align: center; }
.leaflet-marker-icon:hover .sg, .leaflet-marker-icon:focus-visible .sg { transform: scale(1.12); }
.leaflet-marker-icon:focus-visible { outline: none; }
.leaflet-marker-icon:focus-visible .sg { outline: 2px solid var(--focus); outline-offset: 3px; }
.key-multi { position: relative; display: inline-block; }
.key-multi i { border: 1.5px solid var(--ink) !important; }
.key-multi b { position: absolute; right: -8px; top: -7px; min-width: 14px; height: 14px; border-radius: 7px; background: var(--ink); color: var(--paper); font: 700 9px/14px var(--f-ui); text-align: center; }
.here { margin: 8px 0 2px; border-top: 1px solid var(--rule); padding-top: 8px; }
.here-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-family: var(--f-ui); font-size: 12px; color: var(--ink-soft); }
.here-top .nav { display: inline-flex; gap: 4px; }
.here-top .nav button { width: 28px; height: 28px; border: 1px solid var(--rule); border-radius: 3px; background: transparent; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; padding: 0; }
.here-top .nav button:disabled { opacity: .35; cursor: default; }
.here-chips { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 6px; }
.here-chips button { display: inline-flex; align-items: center; gap: 5px; min-height: 28px; padding: 2px 9px 2px 7px; border: 1px solid var(--rule); border-radius: 999px; background: transparent; cursor: pointer; font-family: var(--f-ui); font-size: 12px; font-variant-numeric: tabular-nums; }
.here-chips button i { width: 8px; height: 8px; border-radius: 50%; }
.here-chips button[aria-pressed="true"] { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.pill { display: inline-flex; align-items: center; gap: 5px; font-family: var(--f-ui); font-size: 12px; font-weight: 500; padding: 1px 8px 1px 6px; border-radius: 999px; border: 1px solid currentColor; }
.pill i { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }

@media (max-width: 820px) {
  .app { display: flex; flex-direction: column; height: auto; }
  html, body { height: auto; }
  .plate { height: 64svh; min-height: 380px; order: -1; }
  .key { border-right: 0; border-top: 1px solid var(--rule); overflow: visible; padding-right: max(16px, env(safe-area-inset-right, 0px)); padding-left: max(16px, env(safe-area-inset-left, 0px)); }
  .compass { width: 64px; right: 20px; top: 18px; }
  .cartouche { display: none; }
  header h1 { font-size: 30px; }
  .topbar { top: env(safe-area-inset-top, 0px); }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* Shown only if the settings file or spreadsheet can't be read */
.notice { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 900; max-width: min(460px, 86%); padding: 14px 18px; background: var(--paper); border: 1px solid var(--ink); box-shadow: 0 3px 14px rgba(40, 28, 10, .35); font-family: var(--f-ui); font-size: 14px; line-height: 1.45; }
.pop figure img:not(.ok) { min-height: 140px; background: var(--paper-deep); }

/* 17th-century market towns: shown from config map.townsFromZoom */
.city.town { font-size: 11.5px; color: var(--ink-soft); }
.city.town::before { width: 4px; height: 4px; left: -8px; margin-top: -3px; box-shadow: none; background: var(--ink-soft); border-color: var(--ink-soft); }
.leaflet-container.no-towns .city.town { display: none; }

/* Siege names under the markers: shown from config map.siegeNamesFromZoom */
.sg-name { position: absolute; left: 50%; top: 100%; transform: translateX(-50%); margin-top: 2px; white-space: nowrap; pointer-events: none;
  font-family: var(--f-display); font-style: italic; font-size: 12px; line-height: 1.1; color: var(--ink);
  text-shadow: 0 0 2px var(--paper), 0 0 3px var(--paper), 0 0 4px var(--paper), 0 0 5px var(--paper); }
.leaflet-container.no-siege-names .sg-name { display: none; }
.sg.unknown .sg-name { color: var(--ink); }

/* ---- Emphasis: sieges lead, towns recede ---- */
/* Siege circles: solid colour, dark outline, a parchment ring and a soft shadow */
.sg.siege { border: 0; border-radius: 50%; background: none !important; opacity: 1; overflow: visible; }
.sg.siege .dot { display: block; box-sizing: border-box; border-radius: 50%; border: 1.4px solid var(--ink);
  box-shadow: 0 0 0 1.5px var(--paper), 0 1px 3px 1px rgba(40, 28, 10, .35); }
.sg.siege .dot.unknown { border: 1.6px dashed var(--c); background: var(--paper); box-shadow: 0 0 0 1.5px var(--paper); }
.sg.siege .badge { right: -7px; top: -7px; }
.sg .sg-name { margin-top: 3px; font-family: var(--f-sc); font-style: normal; font-size: 13px; letter-spacing: .03em; color: var(--ink); -webkit-text-stroke: .25px var(--ink);
  text-shadow: 0 0 2px var(--paper), 0 0 3px var(--paper), 0 0 4px var(--paper), 0 0 6px var(--paper); }
.size-key > div { display: flex; flex-direction: column; align-items: center; gap: 3px; }
.size-key .dot { display: block; box-sizing: border-box; border-radius: 50%; border: 1.3px solid var(--ink); }
.size-key .dot.unknown { border: 1.4px dashed var(--c); background: var(--paper); }
.key-multi { position: relative; display: inline-block; }
.key-multi b { right: -8px; top: -6px; }

/* "Towns" switch on the map */
.town-switch { background: var(--paper); padding: 0; }
.town-switch label { display: flex; align-items: center; gap: 6px; padding: 5px 9px; font-family: var(--f-ui); font-size: 12.5px; color: var(--ink); cursor: pointer; user-select: none; }
.town-switch input { margin: 0; accent-color: var(--ink); }
.town-switch label + label { border-top: 1px solid var(--rule); }
.leaflet-container.cities-off .city:not(.town) { display: none; }
.leaflet-container.towns-off .city.town { display: none; }
.city { transition: opacity .25s; }
.leaflet-container.towns-faded .city { opacity: .35; }

/* Cities (capital, major, minor): larger names in mid-brown ink, so they read as the main places.
   Towns: small, faint, no dot. Both are drawn under the siege circles. */
.city { color: #5e4d37; }
.city.capital { color: var(--ink-soft); font-size: 19px; letter-spacing: .06em; }
.city.capital::before { width: 8px; height: 8px; left: -12px; margin-top: -5px; background: var(--ink-soft); border-color: var(--ink-soft); box-shadow: inset 0 0 0 1.5px var(--paper); }
.city.major { color: #5e4d37; font-size: 16px; letter-spacing: .04em; }
.city.major::before { width: 6px; height: 6px; left: -10px; margin-top: -4px; border-color: #5e4d37; box-shadow: none; }
.city.minor { color: #6f604b; font-size: 14px; }
.city.minor::before { width: 5px; height: 5px; left: -9px; margin-top: -3.5px; border-color: #6f604b; box-shadow: none; }
.city.town { color: #8f7f64; font-size: 11px; transform: translate(-50%, -50%); }
.city.town::before { display: none; }

/* Siege name positions, chosen by the label placer */
.sg .sg-name.pos-top { top: auto; bottom: 100%; margin: 0 0 3px; }
.sg .sg-name.pos-right { left: 100%; top: 50%; transform: translateY(-50%); margin: 0 0 0 4px; }
.sg .sg-name.pos-left { left: auto; right: 100%; top: 50%; transform: translateY(-50%); margin: 0 4px 0 0; }

/* "Size circles by length" switch in the side panel */
.size-toggle { display: inline-flex; align-items: center; gap: 7px; margin-top: 10px; font-family: var(--f-ui); font-size: 13px; cursor: pointer; user-select: none; }
.size-toggle input { margin: 0; accent-color: var(--ink); width: 15px; height: 15px; }
.leaflet-container .city.gives-way { visibility: hidden; }

/* ---- Stories: the picker, the story panel and the tour ---- */
.explain { margin: 0 0 10px; font-size: 13.5px; line-height: 1.45; color: var(--ink-soft); max-width: 60ch; }
.story-groups { display: flex; flex-wrap: wrap; gap: 0; margin-bottom: 8px; border-bottom: 1px solid var(--rule); }
.story-groups button { border: 0; background: none; padding: 6px 9px 7px; margin-bottom: -1px; font-family: var(--f-ui); font-size: 12.5px; color: var(--ink-soft); cursor: pointer; border-bottom: 2px solid transparent; }
.story-groups button:hover { color: var(--ink); }
.story-groups button[aria-pressed="true"] { color: var(--ink); border-bottom-color: var(--ink); font-weight: 700; }
.story-card { margin-top: 12px; padding: 12px 14px 10px; background: var(--inlay); border: 1px solid var(--ink); outline: 1px solid var(--rule); outline-offset: 2px; border-radius: 1px; }
.story-card .sc-group { font-family: var(--f-ui); font-size: 10.5px; letter-spacing: .14em; text-transform: uppercase; color: var(--ink-soft); }
.story-card h3 { font-family: var(--f-display); font-weight: 400; font-size: 23px; line-height: 1.1; margin: 2px 0 2px; text-wrap: balance; }
.story-card .sc-meta { font-family: var(--f-ui); font-size: 12px; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.story-card .fewer { color: var(--roy); }
.story-card .sc-sum { margin: 8px 0 0; font-style: italic; font-size: 15px; line-height: 1.4; }
.story-card .sc-story { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--rule); font-size: 14.5px; line-height: 1.55; }
.story-card .sc-story p { margin: 0 0 .7em; }
.story-card .sc-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.chip.go { background: var(--roy); border-color: var(--roy); color: #fff8ec; font-weight: 700; }
.chip.go:hover { background: #8f1824; }
.chip:disabled { opacity: .45; cursor: default; }
.story-card .sc-how { margin: 8px 0 0; font-family: var(--f-ui); font-size: 11.5px; color: var(--ink-soft); }

.pop .in-stories { display: flex; flex-wrap: wrap; gap: 5px; align-items: center; margin-top: 10px; padding-top: 8px; border-top: 1px solid var(--rule); }
.pop .in-stories .lab { font-family: var(--f-sc); font-size: 13px; margin-right: 2px; }
.pop .in-stories button { font-family: var(--f-ui); font-size: 11.5px; min-height: 24px; padding: 1px 8px; border: 1px solid var(--rule); border-radius: 999px; background: transparent; cursor: pointer; }
.pop .in-stories button:hover { border-color: var(--ink-soft); }
.pop .in-stories button[aria-pressed="true"] { background: var(--ink); color: var(--paper); border-color: var(--ink); }

.tour { position: absolute; z-index: 1001; left: 50%; transform: translateX(-50%); bottom: 26px; width: min(520px, calc(100% - 52px));
  background: var(--paper); border: 1px solid var(--ink); outline: 1px solid var(--ink); outline-offset: 3px; box-shadow: 0 4px 16px rgba(40, 28, 10, .35); padding: 10px 14px 10px; }
.tour-top { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; font-family: var(--f-ui); font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-soft); }
.tour-title { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tour-step { font-variant-numeric: tabular-nums; letter-spacing: .04em; white-space: nowrap; }
.tour-step .of { text-transform: none; font-size: .8em; letter-spacing: 0; margin: 0 .1em; }
.tour-x { flex: none; width: 26px; height: 26px; margin: -2px -4px 0 0; border: 1px solid var(--ink); background: var(--paper); cursor: pointer; font-size: 17px; line-height: 22px; padding: 0; }
.tour-leg { margin: 4px 0 6px; padding: 5px 9px; font-family: var(--f-ui); font-size: 13px; line-height: 1.35; color: #7a1622; background: color-mix(in srgb, #9a1c2c 8%, var(--paper)); border-left: 3px solid #9a1c2c; }
.tour-place { font-family: var(--f-display); font-size: 21px; line-height: 1.15; }
.tour-when { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; margin-top: 3px; font-family: var(--f-ui); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.tour-head { margin: 6px 0 9px; font-size: 14.5px; line-height: 1.4; max-height: 5.7em; overflow-y: auto; }
.tour-head:empty { display: none; }
.tour-nav #tourRead { margin-inline: auto; }
.leaflet-interactive.tour-ring, path.tour-ring { animation: tour-pulse 1.6s ease-out infinite; transform-origin: center; transform-box: fill-box; }
@keyframes tour-pulse { 0% { stroke-opacity: 1; stroke-width: 3; } 100% { stroke-opacity: .25; stroke-width: 1; } }
.tour-nav { display: flex; justify-content: space-between; gap: 8px; }
.tour-nav button { font-family: var(--f-ui); font-size: 13px; min-height: 32px; padding: 4px 14px; border: 1px solid var(--ink); background: transparent; cursor: pointer; border-radius: 2px; }
.tour-nav #tourNext { background: var(--ink); color: var(--paper); }
.tour-nav button:disabled { opacity: .4; cursor: default; }
.plate.touring .cartouche, .plate.touring .leaflet-control-scale { opacity: 0; pointer-events: none; }
/* On phones the tour panel sits under the map rather than over it */
@media (max-width: 820px) {
  .plate.touring { height: auto; min-height: 0; display: flex; flex-direction: column; }
  .plate.touring #map { position: relative; inset: auto; height: 52svh; min-height: 300px; }
  .tour { position: relative; left: auto; bottom: auto; transform: none; width: auto; margin: 0; padding: 10px max(16px, env(safe-area-inset-right, 0px)) 12px max(16px, env(safe-area-inset-left, 0px)); outline: 0; box-shadow: none; border-width: 1px 0 0; }
  .tour-place { font-size: 19px; }
  .tour-head { font-size: 14px; max-height: 4.3em; margin-bottom: 8px; }
  .tour-nav button { padding: 4px 10px; }
}
.tour.compact .tour-leg, .tour.compact .tour-when, .tour.compact .tour-head, .tour.compact #tourRead { display: none; }
.tour.compact .tour-place { font-size: 17px; margin-bottom: 6px; }

/* Tours: fading the places already visited and still to come */
.leaflet-marker-icon { transition: opacity .35s; }
.leaflet-marker-icon.t-past { opacity: var(--fade-visited, .5); }
.leaflet-marker-icon.t-past .sg .dot { filter: saturate(.6); }
.leaflet-marker-icon.t-next { opacity: var(--fade-to-come, .25); }
.leaflet-marker-icon.t-next .sg-name { visibility: hidden !important; }
path.leg-now { animation: leg-march 1.2s linear infinite; }
@keyframes leg-march { to { stroke-dashoffset: -30; } }

/* Pop-ups: one scrolling panel no taller than the map, a shorter photo (click to enlarge),
   and the account no longer boxed into its own small scroll area */
.leaflet-popup-content.leaflet-popup-scrolled { margin: 0; padding: 14px 18px 14px 16px; border: 0; scrollbar-color: var(--rule) transparent; overscroll-behavior: contain; }
.leaflet-popup-content.leaflet-popup-scrolled .pop figure { margin-top: -14px; }
.pop figure img { max-height: 150px; cursor: zoom-in; transition: max-height .25s; }
.pop figure .ph-nav { position: absolute; top: 8px; left: 8px; z-index: 2; display: flex; align-items: center; gap: 0; background: var(--card); color: var(--ink); border: 1px solid var(--ink); border-radius: 3px; font: 600 11.5px/1 var(--f-ui); box-shadow: 0 1px 3px rgba(0,0,0,.25); }
.pop figure .ph-nav[hidden] { display: none; }
.pop figure .ph-nav button { all: unset; cursor: pointer; font-size: 17px; line-height: 1; padding: 3px 8px 5px; }
.pop figure .ph-nav button:hover, .pop figure .ph-nav button:focus-visible { background: var(--card-soft); }
.pop figure .ph-nav span { padding: 0 2px; white-space: nowrap; }
.pop figure.big img { max-height: 70vh; object-fit: contain; background: var(--card-soft); cursor: zoom-out; }
.pop .body { max-height: none; overflow: visible; padding-right: 0; }
.pop .where { display: inline; }
.pop .where + .when::before { content: " · "; }
.pop .when { display: inline; }
.pop .head-line { margin-top: 2px; font-family: var(--f-ui); font-size: 12px; color: var(--ink-soft); }
.leaflet-popup-content.leaflet-popup-scrolled { width: 364px !important; max-width: calc(100vw - 56px); }
@media (max-width: 820px) {
  .pop figure img { max-height: 110px; }
  .plate.popup-open .leaflet-top, .plate.popup-open .leaflet-control-scale { opacity: 0; pointer-events: none; }
}
.tour-when .att { display: inline-flex; align-items: center; gap: 5px; }
.tour-when .att i { width: 11px; height: 11px; border-radius: 50%; border: 2.5px solid var(--c); box-sizing: border-box; }

/* "Start here" button under the introduction */
.start-here { margin-top: 12px; display: inline-flex; align-items: center; gap: 12px; padding: 9px 16px 9px 10px; border: 1px solid var(--roy); background: var(--roy); color: #fff8ec; border-radius: 999px; cursor: pointer; text-align: left; box-shadow: 0 2px 6px rgba(90, 20, 20, .25); max-width: 100%; }
.start-here:hover { background: #8f1824; }
.start-here .sh-play { flex: none; width: 30px; height: 30px; border-radius: 50%; background: #fff8ec; color: var(--roy); display: inline-flex; align-items: center; justify-content: center; font-size: 12px; padding-left: 2px; }
.start-here b { display: block; font-family: var(--f-ui); font-size: 15px; }
.start-here small { display: block; font-family: var(--f-ui); font-size: 12px; opacity: .85; }
.start-wrap { margin-top: 12px; display: flex; align-items: center; gap: 8px; }
.start-wrap .start-here { margin-top: 0; }
.start-min { flex: none; width: 28px; height: 28px; border: 1px solid var(--rule); border-radius: 50%; background: transparent; color: var(--ink-soft); cursor: pointer; font-size: 16px; line-height: 1; padding: 0 0 2px; }
.start-min:hover { border-color: var(--ink); color: var(--ink); }

/* "How to use this map" link and guide */
.help-link { margin-top: 10px; display: inline-flex; align-items: center; gap: 7px; border: 0; background: none; padding: 2px 0; font-family: var(--f-ui); font-size: 13.5px; color: var(--ink-soft); cursor: pointer; text-decoration: underline; text-decoration-color: var(--rule); text-underline-offset: 3px; }
.help-link span[aria-hidden] { width: 18px; height: 18px; border: 1px solid currentColor; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; text-decoration: none; }
.help-link:hover { color: var(--ink); }
.start-wrap + .help-link { display: flex; }
.help-layer { position: fixed; inset: 0; z-index: 3000; }
.help-catch { position: absolute; inset: 0; }
.help-spot { position: fixed; border-radius: 4px; box-shadow: 0 0 0 9999px rgba(30, 20, 8, .55); outline: 2px solid #fff8ec; pointer-events: none; transition: left .25s, top .25s, width .25s, height .25s; }
.help-card { position: fixed; width: min(340px, calc(100vw - 32px)); background: var(--paper); color: var(--ink); border: 1px solid var(--ink); outline: 1px solid var(--ink); outline-offset: 3px; box-shadow: 0 6px 22px rgba(30, 20, 8, .45); padding: 12px 16px 12px; }
.help-card .h-top { display: flex; align-items: center; justify-content: space-between; font-family: var(--f-ui); font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-soft); margin-bottom: 6px; }
.help-card .h-x { width: 26px; height: 26px; border: 1px solid var(--ink); background: var(--paper); cursor: pointer; font-size: 17px; line-height: 22px; padding: 0; }
.help-card h3 { font-family: var(--f-display); font-weight: 400; font-size: 22px; margin: 0 0 4px; }
.help-card p { margin: 0 0 12px; font-size: 15px; line-height: 1.45; }
.help-card .h-nav { display: flex; justify-content: space-between; gap: 8px; }
.help-card .h-nav button { font-family: var(--f-ui); font-size: 13px; min-height: 32px; padding: 4px 14px; border: 1px solid var(--ink); background: transparent; cursor: pointer; border-radius: 2px; }
.help-card .h-next { background: var(--ink) !important; color: var(--paper); }
.help-card .h-nav button:disabled { opacity: .4; cursor: default; }
@media (prefers-reduced-motion: reduce) { .help-spot { transition: none; } }

/* the slower zoom used when the map glides to a siege or a story step */
.leaflet-container.glide-zoom .leaflet-zoom-anim .leaflet-zoom-animated { transition: transform .7s cubic-bezier(.45, 0, .25, 1); }
.views { margin: -10px 0 0; font-family: var(--f-ui); font-size: 12px; color: var(--ink-soft); font-variant-numeric: tabular-nums; }

/* "Added separate footer area to display view count */
.views-area {
  border-top: 1px dotted var(--rule);
  padding-top: 8px;
  margin-top: -10px;
}

.views {
  font-family: var(--f-ui);
  font-size: 12px;
  color: var(--ink-soft);
  margin: 0;
  font-weight: 600;
}
