html, body { margin: 0; height: 100%; font-family: "Source Sans 3", system-ui, sans-serif; }
#map { position: absolute; inset: 0; }
#panel { position: absolute; top: 10px; left: 10px; width: 280px; background: rgba(255,255,255,0.95);
  border-radius: 8px; box-shadow: 0 1px 6px rgba(0,0,0,0.25); padding: 8px; font-size: 14px; z-index: 2; }
#q { width: 100%; box-sizing: border-box; padding: 7px 9px; font-size: 15px; border: 1px solid #bbb; border-radius: 6px; }
#results { list-style: none; margin: 4px 0 0; padding: 0; max-height: 45vh; overflow-y: auto; }
#results li { padding: 6px 8px; cursor: pointer; border-radius: 5px; }
#results li:hover, #results li.active { background: #e8f2ea; }
#results small { color: #666; display: block; }
#layers { margin-top: 8px; }
#layers summary { cursor: pointer; font-weight: 600; }
#layers label { display: block; padding: 2px 0; }
.tools { margin-top: 8px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.tools button { padding: 5px 10px; border: 1px solid #aaa; background: #fff; border-radius: 6px; cursor: pointer; font-size: 14px; }
.tools button.on { background: #1f9a3e; color: #fff; border-color: #1f9a3e; }
#measure-out { font-weight: 600; }
#gridref { position: absolute; bottom: 30px; left: 10px; background: rgba(255,255,255,0.92); padding: 3px 8px;
  border-radius: 5px; font: 600 13px ui-monospace, monospace; box-shadow: 0 1px 4px rgba(0,0,0,0.2); z-index: 2; }
.maplibregl-ctrl-scale { font-size: 11px; }
@media (max-width: 600px) { #panel { width: calc(100% - 36px); } #layers { display: none; } }
#panel { max-height: calc(100vh - 40px); overflow-y: auto; }
#layers .cols { display: grid; grid-template-columns: 1fr 1fr; column-gap: 6px; }
#layers label { font-size: 13px; }
.hist { margin-top: 6px; display: grid; grid-template-columns: 1fr; gap: 3px; font-size: 13px; }
.hist select { padding: 3px; }
#three-d.on { background: #6b4fbb; color: #fff; border-color: #6b4fbb; }
#add-place.on { background: #d4145a; color: #fff; border-color: #d4145a; }
#places-panel { margin-top: 8px; }
#places-panel summary { cursor: pointer; font-weight: 600; }
#places-list { list-style: none; margin: 4px 0 0; padding: 0; max-height: 30vh; overflow-y: auto; }
#places-list li { display: flex; align-items: center; gap: 6px; padding: 4px 6px; border-radius: 5px; cursor: pointer; font-size: 13px; }
#places-list li:hover { background: #f3e8ee; }
#places-list img { width: 15px; height: 20px; }
dialog { border: none; border-radius: 10px; box-shadow: 0 4px 24px rgba(0,0,0,0.3); padding: 16px 18px; width: min(340px, 90vw); }
dialog h3 { margin: 0 0 10px; }
dialog label { display: block; margin: 8px 0; font-size: 14px; }
dialog input, dialog textarea { width: 100%; box-sizing: border-box; padding: 6px; font: inherit; border: 1px solid #bbb; border-radius: 5px; }
.icon-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; margin: 8px 0; }
.icon-grid button { background: #fff; border: 2px solid transparent; border-radius: 6px; padding: 3px; cursor: pointer; }
.icon-grid button.sel { border-color: #d4145a; background: #fbeaf0; }
.icon-grid img { width: 22px; height: 29px; display: block; margin: auto; }
.dialog-buttons { display: flex; justify-content: flex-end; gap: 8px; margin-top: 10px; }
.dialog-buttons button { padding: 6px 14px; border-radius: 6px; border: 1px solid #aaa; background: #fff; cursor: pointer; }
.dialog-buttons .primary { background: #d4145a; color: #fff; border-color: #d4145a; }
.place-popup h4 { margin: 0 0 4px; } .place-popup p { margin: 4px 0; white-space: pre-wrap; } .place-popup small { color: #666; }
.place-popup .actions { margin-top: 6px; display: flex; gap: 6px; }
.place-popup button { padding: 3px 8px; border: 1px solid #aaa; background: #fff; border-radius: 5px; cursor: pointer; }
/* 2026-10-10: panel never wider than its box (long historic-map names made the select push it sideways) */
#panel { box-sizing: border-box; overflow-x: hidden; max-width: calc(100vw - 20px); }
#layers .cols { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.hist { grid-template-columns: minmax(0, 1fr); }
.hist select, .hist input[type=range] { width: 100%; min-width: 0; box-sizing: border-box; margin: 0; }

/* Timeline Slider: wide bar along the bottom of the map, greyed out unless the timeline overlay is chosen (2026-10-11) */
.hist input[type=range] { width: 100%; min-width: 0; }
#tl { position: absolute; bottom: 12px; left: 190px; right: 220px; z-index: 3; box-sizing: border-box;
  background: rgba(255,255,255,0.94); border-radius: 8px; box-shadow: 0 1px 4px rgba(0,0,0,0.3); padding: 6px 12px 4px;
  font: 13px/1.3 "Source Sans 3", system-ui, sans-serif; }
#tl.off > * { opacity: 0.4; filter: grayscale(1); }
#tl .tl-head { display: flex; justify-content: space-between; align-items: baseline; }
#tl .tl-head label { font-weight: 600; color: #333; }
#tl #tl-val { font-weight: 600; color: #4a2a10; min-width: 3em; text-align: right; }
#tl .tl-row { display: flex; align-items: flex-start; gap: 8px; }
#tl .tl-track { flex: 1; min-width: 0; }
#tl #tl-year { width: 100%; margin: 4px 0 0; height: 22px; cursor: pointer; }
#tl #tl-year:disabled, #tl button:disabled { cursor: not-allowed; }
#tl button { border: 1px solid #bbb; background: #fff; border-radius: 4px; padding: 2px 8px; margin-top: 3px; cursor: pointer; }
#tl-ticks { position: relative; height: 15px; margin: 0 8px; font-size: 11px; color: #666; }
#tl-ticks span { position: absolute; transform: translateX(-50%); }
#tl-ticks span::before { content: ""; position: absolute; left: 50%; top: -4px; height: 4px; border-left: 1px solid #999; }
@media (max-width: 760px) { #tl { left: 8px; right: 8px; bottom: 74px; } }
.hist label.op { font-size: 0.85em; color: #555; margin-top: 4px; display: block; }

/* context-aware key (2026-10-11) */
#keybox { position: absolute; top: 110px; right: 10px; width: 310px; max-height: calc(100vh - 230px); z-index: 3; display: flex; flex-direction: column;
  background: rgba(255,255,255,0.95); border-radius: 8px; box-shadow: 0 1px 4px rgba(0,0,0,0.3); font: 12px/1.35 "Source Sans 3", system-ui, sans-serif; }
#key-toggle { display: flex; gap: 6px; align-items: baseline; width: 100%; border: 0; background: none; padding: 7px 10px; cursor: pointer; text-align: left; font: inherit; }
#key-toggle span { font-weight: 700; font-size: 13px; }
#key-toggle b { flex: 1; font-weight: 400; color: #555; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#key-toggle i { font-style: normal; color: #777; }
#keybox.closed #key-body { display: none; }
#keybox.closed #key-toggle i { transform: rotate(-90deg); }
#key-body { overflow-y: auto; padding: 0 10px 8px; }
#key-body table { border-collapse: collapse; width: 100%; }
#key-body td { padding: 1px 4px 1px 0; vertical-align: middle; }
#key-body td.sw { width: 38px; }
#key-body img { width: 100%; height: auto; display: block; margin: 2px 0 4px; }
#key-body details summary { cursor: pointer; color: #335; margin: 4px 0; }
#key-body .kn { margin: 5px 0; color: #444; }
#key-body dl.abbr { display: grid; grid-template-columns: max-content 1fr; gap: 1px 8px; margin: 4px 0; }
#key-body dl.abbr dt { font-weight: 600; } #key-body dl.abbr dd { margin: 0; color: #444; }
@media (max-width: 760px) { #keybox { top: auto; bottom: 150px; width: calc(100% - 20px); max-height: 40vh; } }
#key-body ol.refs { columns: 2; column-gap: 14px; margin: 2px 0 4px; padding-left: 22px; font-size: 11.5px; }
