/* The map fills the window; everything else is a glass panel floating on a grid above it. */
:root {
  color-scheme: dark;
  --bg: #0d0f0e;
  --glass: #121514e0;
  --solid: #161a18;
  --raised: #ffffff10;
  --line: #ffffff1c;
  --ink: #eef1ee;
  --muted: #98a19b;
  --accent: #6ccf58;
  --accent-ink: #071406;
  --accent-soft: #6ccf5826;
  --accent-line: #6ccf5866;
  --brand: linear-gradient(135deg, #8fe070, #3fae52);
  --radius: 14px;
  --gap: 10px;
  --bar: 48px;
  --tap: 30px;
  --map-control: 34px;
  --thumb: 16px;
  font: 13px/1.45 ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}
@media (pointer: coarse) {
  :root { --tap: 38px; --thumb: 22px; }
}

*, ::before, ::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; overflow: hidden; background: var(--bg); color: var(--ink); }
h1, h2, h3, p, dl, dd { margin: 0; }
button, input, select { font: inherit; color: inherit; }
button { padding: 0; border: 0; background: none; cursor: pointer; -webkit-tap-highlight-color: transparent; transition: background .15s, color .15s, border-color .15s; }
button:disabled, input:disabled { opacity: .4; cursor: default; }
a { color: var(--accent); text-underline-offset: 3px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
select, input:not([type=range], [type=file]) { min-height: var(--tap); padding: 0 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--raised); font-size: 12px; }
.sprite { position: absolute; width: 0; height: 0; }
.icon { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }

/* ── Layout ── */
#app { position: fixed; inset: 0; isolation: isolate; overflow: hidden; }
#map { position: absolute; inset: 0; }
.ui {
  position: absolute; inset: 0; z-index: 2; pointer-events: none;
  display: grid; row-gap: var(--gap);
  grid-template: "panel stage" minmax(0, 1fr) "dock dock" auto / auto minmax(0, 1fr);
  padding: max(var(--gap), env(safe-area-inset-top)) max(var(--gap), env(safe-area-inset-right)) calc(max(var(--attribution, 0px), var(--native-footer, 0px)) + var(--gap)) max(var(--gap), env(safe-area-inset-left));
}
.ui > * { min-width: 0; pointer-events: auto; }
.panel { border: 1px solid var(--line); border-radius: var(--radius); background: var(--glass); backdrop-filter: blur(18px) saturate(1.5); box-shadow: 0 8px 32px #0005; }
.worker-status { grid-area: stage; place-self: start end; z-index: 6; display: flex; align-items: center; gap: 6px; max-width: min(52ch, calc(100% - var(--map-control) - var(--gap))); margin: 5px calc(var(--map-control) + var(--gap)) 0 0; padding: 4px 9px; border: 1px solid var(--line); border-radius: 99px; background: var(--solid); color: var(--muted); font-size: 11px; pointer-events: none; animation: show-working 0s .12s both; }
.worker-status::before { content: ''; flex: none; width: 12px; height: 12px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: working .8s linear infinite; }
.worker-status span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@keyframes working { to { transform: rotate(360deg); } }
@keyframes show-working { from { visibility: hidden; } to { visibility: visible; } }
.panel-head { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; gap: 8px; padding: 8px 8px 8px 16px; background: var(--solid); }
.panel-head h2 { font-size: 14px; font-weight: 600; }
.panel-head .icon-button { margin-left: auto; }

/* ── Shared controls ── */
.icon-button { display: grid; place-items: center; flex: none; width: var(--tap); height: var(--tap); border-radius: 9px; color: var(--muted); }
.icon-button:hover:not(:disabled) { background: var(--raised); color: var(--ink); }
.icon-button:is([aria-expanded=true], [aria-pressed=true]) { background: var(--accent-soft); color: var(--accent); }
.link { color: var(--accent); font-size: 12px; white-space: nowrap; }
.link:hover:not(:disabled) { text-decoration: underline; text-underline-offset: 3px; }
.hint { color: var(--muted); font-size: 11px; }
.hint:empty { display: none; }
.split { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 4px 10px; }

.seg { display: flex; gap: 2px; padding: 2px; border-radius: 9px; background: var(--raised); }
.seg button { flex: 1; min-height: calc(var(--tap) - 4px); padding: 0 10px; border-radius: 7px; color: var(--muted); font-size: 12px; white-space: nowrap; }
.seg button:hover:not(:disabled) { color: var(--ink); }
.seg [aria-pressed=true], #place-finish:enabled { background: var(--accent-soft); color: var(--accent); }

.tabs { display: flex; gap: 2px; overflow-x: auto; border-bottom: 1px solid var(--line); scrollbar-width: none; }
.tabs button { min-height: var(--tap); margin-bottom: -1px; padding: 0 10px; border-bottom: 2px solid transparent; color: var(--muted); font-size: 12px; white-space: nowrap; }
.tabs button:hover { color: var(--ink); }
.tabs [aria-selected=true] { border-color: var(--accent); color: var(--accent); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { min-height: calc(var(--tap) - 4px); padding: 0 10px; border: 1px solid var(--line); border-radius: 99px; color: var(--muted); font-size: 12px; white-space: nowrap; }
.chip:hover { border-color: #fff5; color: var(--ink); }
.chip:is(.active, [aria-pressed=true]) { border-color: var(--accent-line); background: var(--accent-soft); color: var(--accent); }

.field { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 12px; }
.field .seg button { flex: none; }
.slider { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 2px 8px; font-size: 12px; }
.slider .range { grid-area: 2 / 1 / 3 / -1; }
.slider output, .filter-unit { color: var(--muted); font-variant-numeric: tabular-nums; }

/* Every slider: one painted track with one or two native, keyboard-accessible thumbs. */
.range { position: relative; min-width: 80px; height: 24px; }
.range::before {
  content: ''; position: absolute; inset: 10px 8px; border-radius: 4px;
  background: linear-gradient(to right, #fff3 var(--low, 0%), var(--accent) var(--low, 0%), var(--accent) var(--high, 100%), #fff3 var(--high, 100%));
}
.range input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; appearance: none; background: none; cursor: pointer; }
/* Two thumbs overlap, so only the thumbs themselves take the pointer. */
.range input:not(:only-child) { pointer-events: none; }
.range input + input { z-index: 2; }
.range input::-webkit-slider-runnable-track { height: 4px; background: none; }
.range input::-moz-range-track { background: none; }
.range input::-webkit-slider-thumb { appearance: none; width: var(--thumb); height: var(--thumb); margin-top: calc(2px - var(--thumb) / 2); border: 2px solid var(--bg); border-radius: 50%; background: var(--accent); cursor: ew-resize; pointer-events: auto; }
.range input::-moz-range-thumb { width: calc(var(--thumb) - 4px); height: calc(var(--thumb) - 4px); border: 2px solid var(--bg); border-radius: 50%; background: var(--accent); cursor: ew-resize; pointer-events: auto; }
.range input:focus-visible { outline: none; }
.range input:focus-visible::-webkit-slider-thumb { outline: 2px solid #fff; outline-offset: 2px; }
.range input:focus-visible::-moz-range-thumb { outline: 2px solid #fff; outline-offset: 2px; }
.range:has(:disabled) { opacity: .35; }

/* Fixed ISO text with a native calendar button; no locale-dependent date text. */
.date-field { position: relative; display: inline-block; width: calc(10ch + 46px); font-size: 12px; font-variant-numeric: tabular-nums; }
.date-field:has(> .iso-date[hidden]) { display: none; }
.date-field .iso-date { width: 100%; padding-right: 30px; }
.date-picker { position: absolute; inset: 2px 2px 2px auto; display: grid; place-items: center; width: 28px; border-radius: 6px; color: var(--muted); }
.date-picker:hover { color: var(--accent); }
.date-picker .icon { width: 15px; height: 15px; }
.date-field .native-date { position: absolute; right: 0; bottom: 0; width: 1px; height: 1px; min-height: 0; padding: 0; border: 0; opacity: 0; pointer-events: none; }

/* ── Top panel: the bar, which unfolds into the settings ── */
#panel { grid-area: panel; z-index: 5; place-self: start; display: flex; flex-direction: column; width: 440px; max-width: 100%; max-height: 100%; margin-right: var(--gap); overflow: hidden; }
.bar { display: flex; flex: none; align-items: center; gap: 4px; min-height: calc(var(--bar) - 2px); padding: 4px 6px 4px 10px; }
#settings-toggle { margin-left: auto; }
.brand { display: flex; align-items: center; gap: 9px; margin-right: 8px; color: inherit; text-decoration: none; }
.brand svg { width: 28px; height: 28px; fill: none; stroke: var(--accent-ink); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.brand h1 { font-size: 15px; font-weight: 650; letter-spacing: -.02em; white-space: nowrap; }
.brand h1 span { color: var(--muted); font-weight: 400; }
.bar:has(.stats:not([hidden])) h1 { display: none; }
/* Fixed columns: a growing count never pushes its neighbours. */
.stats { flex: 1; display: grid; grid-template-columns: 4fr 3fr 4fr; gap: 10px; min-width: 0; overflow: hidden; margin-right: 6px; padding-left: 12px; border-left: 1px solid var(--line); }
.stats p { display: grid; color: var(--muted); font-size: 10px; line-height: 1.25; white-space: nowrap; }
.stats b { color: var(--ink); font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; }

/* ── Settings ── */
#settings { overflow: auto; overscroll-behavior: contain; scrollbar-width: thin; }
#settings section, #settings footer { display: grid; gap: 10px; padding: 14px 16px; border-top: 1px solid var(--line); }
#settings h3 { display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; }
#settings h3 .link { letter-spacing: 0; text-transform: none; }
#settings footer { gap: 4px; justify-items: center; text-align: center; }
#settings footer .icon { width: 12px; height: 12px; vertical-align: -2px; color: var(--accent); }
#source-label { overflow: hidden; color: var(--muted); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.upload { display: flex; align-items: center; gap: 12px; padding: 12px; border: 1px dashed #fff4; border-radius: 10px; background: var(--raised); text-align: left; }
.upload:hover:not(:disabled) { border-color: var(--accent); }
.upload .icon { width: 22px; height: 22px; color: var(--accent); }
.upload b { display: block; font-weight: 600; }
.upload small { color: var(--muted); font-size: 11px; }
#modes { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); }
#modes button { display: grid; justify-items: center; gap: 4px; min-width: 0; padding: 8px 0; font-size: clamp(9px, 2.5vw, 11px); }
.palettes { gap: 8px; width: 240px; padding: 0; background: none; }
.field .palettes button { flex: 1; min-height: 20px; }
.palettes [aria-pressed=true] { outline: 2px solid var(--accent); outline-offset: 2px; }

.basemaps { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 8px; }
.basemaps button { display: flex; align-items: center; gap: 8px; min-width: 0; padding: 6px; border: 1px solid transparent; border-radius: 10px; background: var(--raised); text-align: left; }
.basemaps button:hover { border-color: #fff5; }
.basemaps [aria-pressed=true] { border-color: var(--accent); color: var(--accent); }
.basemaps span:last-child { display: grid; min-width: 0; font-size: 12px; line-height: 1.25; }
.basemaps b { font-weight: 500; white-space: nowrap; }
.basemaps small { color: var(--muted); font-size: 10px; }
.map-swatch { flex: 0 0 36px; height: 36px; overflow: hidden; border-radius: 7px; background: #2b2f3a; }
.map-swatch svg { display: block; width: 100%; height: 100%; }

/* Preview colours: images/map-previews.svg reads these per provider and style. */
.provider-google {
  --map-land: #e9ecdf; --map-block: #dbe0d5; --map-park: #badbab; --map-water: #b3dbf4; --map-road: #fff; --map-highway: #ffe08b; --map-casing: #edc75e;
  --image-land: #43513a; --field-a: #908155; --field-b: #657347; --field-c: #b3a17b; --image-city: #7c7b70; --image-roof: #c2b8a3; --image-water: #254e60; --image-shore: #83937d; --hybrid-road: #f7d66b;
}
.provider-yandex {
  --map-land: #f4f3ee; --map-block: #e4e3df; --map-park: #c8e5b6; --map-water: #a8d5f1; --map-road: #fff; --map-highway: #ffdf38; --map-casing: #dec369; --map-label: #71706d;
  --image-land: #304f3d; --field-a: #59764b; --field-b: #466451; --field-c: #949073; --image-city: #616d6a; --image-roof: #a4aaa1; --image-water: #183c4b; --image-shore: #587663; --hybrid-road: #fff3b3;
}
.provider-openstreetmap { --map-land: #eee7dc; --map-block: #ded7d0; --map-park: #b7d7a9; --map-water: #abd4df; --map-road: #fffefb; --map-highway: #f8d7ac; --map-casing: #d59f9f; --map-label: #75695d; }
.provider-esri {
  --map-land: #f0eee6; --map-block: #e2ded4; --map-park: #c5d7aa; --map-water: #abd3df; --map-road: #fff; --map-highway: #eac77e; --map-casing: #cbb78c; --map-label: #59616a;
  --terrain-low: #e5e6cc; --terrain-mid: #b8c99d; --terrain-high: #c6b59d; --terrain-peak: #f1e8d8; --terrain-contour: #a0947f;
  --image-land: #594c3b; --field-a: #9e8b59; --field-b: #726846; --field-c: #b6a17c; --image-city: #81796c; --image-roof: #c9bda4; --image-water: #31575b; --image-shore: #9a9e83;
}
.provider-openfreemap { --map-land: #f8f4f0; --map-block: #dcd9d5; --map-park: #b0d59a; --map-water: #9ebdff; --map-highway: #fea; --map-casing: #e9ac77; }
.style-bright { --map-block: #dfdbd7; --map-park: #c7dfa7; --map-water: #aecfe2; --map-highway: #fc8; --map-casing: #e9ac77; }
.style-light { --map-land: #f2f3f0; --map-block: #eaeae5; --map-park: #dedfd6; --map-water: #c2c8ca; --map-highway: #fff; --map-casing: #d5d5d5; --map-label: #89918b; }
.style-dark { --map-land: #0c0c0c; --map-block: #0a0a0a; --map-park: #202020; --map-water: #1b1b1d; --map-road: #303030; --map-highway: #181818; --map-casing: #3c3c3c; --map-label: #999; }
.style-fiord { --map-land: #45516e; --map-block: #303757; --map-park: #3d505b; --map-water: #38435c; --map-road: #596683; --map-highway: #3b4359; --map-casing: #59678c; --map-label: #b7c9d7; }
.style-yandex-map { --map-land: #f9f4e6; --map-block: #e9e2d2; --map-water: #9dcce7; --map-highway: #ffcc66; }
.style-yandex-driving { --map-land: #f2f1eb; --map-park: #e0e5d7; --map-highway: #ffc940; --map-casing: #d6af46; }
.style-yandex-transit { --map-road: #d8d6d0; --map-highway: #b37ac5; --map-casing: #935cad; }
.style-yandex-admin { --map-land: #f8f8f2; --map-block: #e5e5df; --map-park: #dfecc5; --map-highway: #ffe6a0; --map-casing: #afa8cf; }
:is(.style-google-roadmap-dark, .style-google-terrain-dark) { --map-land: #202124; --map-block: #303134; --map-park: #263c30; --map-water: #172c39; --map-road: #494b50; --map-highway: #8b8068; --map-casing: #292a2d; --map-label: #aeb0b4; --terrain-low: #26302d; --terrain-mid: #34423b; --terrain-high: #4d5045; --terrain-peak: #64655a; --terrain-contour: #202822; }
:is(.style-esri-streets-night, .style-esri-navigation-night) { --map-land: #252b37; --map-block: #303747; --map-park: #293d39; --map-water: #182333; --map-road: #586071; --map-highway: #ac976e; --map-casing: #202633; --map-label: #b6bbc6; }
.style-esri-navigation { --map-land: #edf0f4; --map-highway: #e8aa60; --map-water: #9bc4e1; }
.style-esri-light-gray { --map-land: #ededed; --map-block: #dedede; --map-park: #e2e2df; --map-water: #d0d4d8; --map-highway: #fafafa; --map-casing: #ccc; }
.style-esri-dark-gray { --map-land: #292929; --map-block: #333; --map-park: #303330; --map-water: #1f2226; --map-road: #505050; --map-highway: #666; --map-casing: #222; --map-label: #aaa; }
.style-esri-terrain, .style-esri-hillshade-light, .style-esri-hillshade-dark { --map-water: transparent; --map-road: transparent; }
.style-esri-terrain { --terrain-low: #e8e9e4; --terrain-mid: #cdcfca; --terrain-high: #dedfda; --terrain-peak: #f8f9f4; --terrain-contour: #b0b4ac; }
.style-esri-hillshade-light { --terrain-low: #dedede; --terrain-mid: #b5b5b5; --terrain-high: #cecece; --terrain-peak: #f2f2f2; --terrain-contour: #999; }
.style-esri-hillshade-dark { --terrain-low: #252525; --terrain-mid: #393939; --terrain-high: #505050; --terrain-peak: #707070; --terrain-contour: #222; }

/* New provider previews use their map palette; no map tiles are fetched for cards. */
.provider-opentopomap { --map-land: #eee7c9; --map-block: #dcd3b2; --map-park: #b6cfa5; --map-water: #a7cfdb; --map-road: #fffdf0; --map-highway: #e5b881; --map-casing: #b28c62; --terrain-low: #e8e6c9; --terrain-mid: #bcc79e; --terrain-high: #c3b49a; --terrain-peak: #f6f1dd; --terrain-contour: #99886c; }
.provider-thunderforest { --map-land: #f3efdc; --map-block: #dedbcc; --map-park: #c7dda7; --map-water: #9bcde2; --map-road: #fff; --map-highway: #e0c39c; --map-casing: #bca784; --map-label: #636659; --terrain-low: #e5e4c9; --terrain-mid: #b4c99a; --terrain-high: #c7b99c; --terrain-peak: #eee8d6; --terrain-contour: #a69878; }
.style-thunderforest-transport { --map-highway: #ca657d; --map-casing: #98576e; --map-water: #b7d8e4; }
.style-thunderforest-atlas-canvas { --map-land: #eeede8; --map-block: #deded9; --map-park: #dce3d5; --map-water: #cbd9de; --map-highway: #faf8f2; --map-casing: #ccc7bd; }
.style-thunderforest-mobile-atlas { --map-land: #fff; --map-block: #deded8; --map-park: #d3e4bc; --map-water: #8fbfb6; --map-road: #787d79; --map-highway: #121514; --map-casing: #070909; --map-label: #222; }
.style-thunderforest-neighbourhood { --map-land: #e5ecd9; --map-block: #d3dbcd; --map-park: #c8e2b7; --map-water: #91c6df; --map-highway: #e9cf83; --map-casing: #cbb676; --map-label: #53645a; }
.style-thunderforest-pioneer { --map-land: #ece1c7; --map-block: #b0c7b9; --map-park: #c9d1b0; --map-water: #b7d0cd; --map-highway: #5c6760; --map-casing: #303b35; --map-label: #576155; }
.style-thunderforest-cycle { --map-road: #455cbb; --map-highway: #788ed4; --map-casing: #4a62ac; --terrain-contour: #8b917c; }
.style-thunderforest-outdoors { --terrain-low: #d4dfb8; --terrain-mid: #a2bf87; --terrain-high: #b7ae8e; --terrain-peak: #e6dfcb; --map-road: #efc66e; }
.style-thunderforest-landscape { --terrain-low: #e8e4d4; --terrain-mid: #b9c89c; --terrain-high: #c4bfae; --terrain-peak: #eeeade; --map-road: #e6b6c7; }
.style-thunderforest-transport-dark { --map-land: #3b3049; --map-block: #31263b; --map-park: #305644; --map-water: #423d85; --map-road: #b63b48; --map-highway: #e4d354; --map-casing: #7e7837; --map-label: #e8dca4; }
.style-versatiles-colorful-dark { --map-land: rgb(40,39,37); --map-block: rgb(43,40,38); --map-park: rgb(43,59,29); --map-water: rgb(12,28,42); --map-road: rgb(82,82,82); --map-highway: rgb(105,71,16); --map-casing: rgb(90,49,4); }
.style-versatiles-gray-dark { --map-land: #272727; --map-block: #292929; --map-park: #303030; --map-water: #000; --map-road: #424242; --map-highway: #3a3a3a; --map-casing: #383838; }
.style-versatiles-toner { --map-land: rgb(255,255,255); --map-block: rgb(255,252,250); --map-park: rgb(224,240,213); --map-water: rgb(216,231,247); --map-road: rgb(255,255,255); --map-highway: rgb(242,181,97); --map-casing: rgb(197,127,60); }

/* ── Stage: messages and Place history share the free map area ── */
.toasts { grid-area: stage; z-index: 6; place-self: start center; display: grid; justify-items: center; gap: 6px; }
.toasts p { max-width: 46ch; padding: 9px 14px; border: 1px solid var(--accent-line); border-radius: 10px; background: #18201af5; box-shadow: 0 6px 30px #0006; font-size: 12px; }
.toasts .error { border-color: #976c5a; background: #3c2424f5; color: #ffdcc9; }
#drop-overlay { position: absolute; inset: var(--gap); z-index: 9; display: grid; place-content: center; justify-items: center; gap: 10px; border: 2px dashed var(--accent); border-radius: 18px; background: #0d140fee; text-align: center; pointer-events: none; }
#drop-overlay .icon { width: 48px; height: 48px; color: var(--accent); }
#drop-overlay strong { font-size: 20px; }
#drop-overlay span { color: var(--muted); }

/* ── Date window ── */
.dock { grid-area: dock; display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; padding: 10px 12px; }
.dock-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 12px; }
.stepper { display: flex; align-items: center; gap: 2px; min-width: 0; }
.stepper p { display: grid; min-width: 0; padding: 0 6px; line-height: 1.3; white-space: nowrap; }
/* Reserve a stable date box without changing the interface font. */
#range-summary { width: 20em; text-align: center; font-size: 13px; font-weight: 500; font-variant-numeric: tabular-nums; }
#timeline-toggle[aria-expanded=false] .icon { transform: rotate(180deg); }
.histogram { display: flex; align-items: end; gap: 2px; height: 36px; }
.histogram button { position: relative; flex: 1; min-width: 0; height: 100%; border-radius: 3px; }
.histogram button::before { content: ''; position: absolute; inset: auto 0 0; height: var(--height, 3%); border-radius: 2px 2px 0 0; background: var(--accent); opacity: .22; transition: height .2s, opacity .2s; }
.histogram button:is(.in, :hover, :focus-visible)::before { opacity: 1; }
.histogram button:is(:hover, :focus-visible) { background: var(--raised); }
.dates { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 10px; }
.legend { display: flex; align-items: center; gap: 8px; color: var(--ink); }
#legend-ramp { width: 90px; height: 6px; border-radius: 3px; }
#legend-unit { color: var(--muted); }
#legend-unknown { display: inline-flex; align-items: center; gap: 4px; }
#legend-unknown-swatch { width: 8px; height: 8px; border-radius: 2px; }
#render-note { margin-left: auto; text-align: right; }

.filter-popover { position: fixed; inset: auto; width: min(300px, calc(100vw - 16px)); max-height: calc(100dvh - 16px); margin: 0; padding: 14px; overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--solid); color: var(--ink); box-shadow: 0 12px 40px #0009; }
.filter-popover:popover-open { display: grid; gap: 10px; }
.filter-popover > .chip { justify-self: start; }
.filter-values { display: flex; justify-content: space-between; gap: 12px; }
.filter-values label { display: grid; gap: 4px; color: var(--muted); font-size: 11px; }
.filter-values input { width: 12ch; }
.filter-unit input { width: 9ch; }

/* ── Place history ── */
.place { grid-area: stage; z-index: 3; place-self: end; display: flex; flex-direction: column; gap: 8px; width: min(100%, 760px); max-height: 100%; padding: 0 14px 12px; overflow: hidden; }
.place .panel-head { flex-wrap: wrap; margin: 0 -14px; }
#place-kind { flex: 1; }
#place-drawing { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; }
#place-results { display: flex; flex-direction: column; gap: 8px; min-height: 0; }
/* Only the active view gives way when results are long. */
#place-results > :not(.place-view) { flex: none; }
#place-results:has(#place-tab-calendar[aria-selected=true]) .place-note { display: none; }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(92px, 1fr)); gap: 6px 12px; }
.facts dt { color: var(--muted); font-size: 10px; }
.facts dd { font-size: 14px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.facts .wide { grid-column: span 2; }
.facts .wide dd { font-size: 12px; }
.place-view { min-height: 0; overflow: auto; scrollbar-width: thin; }
#place-view-calendar { display: flex; flex-direction: column; gap: 6px; overflow: hidden; }

.calendar-toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px; color: var(--muted); font-size: 12px; }
.calendar-toolbar > * { flex: none; }
.calendar-toolbar label { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
#place-calendar-year { width: calc(4ch + 36px); }
#place-calendar-caption { color: var(--ink); }
.calendar-scroll { min-height: 0; padding: 2px; overflow: auto; scrollbar-width: thin; }
.calendar-scale { display: inline-flex; align-items: center; gap: 4px; }
.calendar-scale i { width: 10px; height: 10px; }
#place-calendar-detail { min-height: 1.45em; }

/* Activity cells: shade by level, dimmed when empty or outside the window. */
.calendar-days button, .calendar-scale i, .calendar-hours [data-level] { border-radius: 2px; background: var(--level, var(--raised)); }
.calendar-days button:disabled { opacity: .6; }
.place-view [data-level="1"] { --level: color-mix(in srgb, var(--accent) 25%, var(--bg)); }
.place-view [data-level="2"] { --level: color-mix(in srgb, var(--accent) 45%, var(--bg)); }
.place-view [data-level="3"] { --level: color-mix(in srgb, var(--accent) 70%, var(--bg)); }
.place-view [data-level="4"] { --level: var(--accent); }
.place-view :is(.is-month, .quarter-days) :is([data-level="3"], [data-level="4"]) { color: var(--accent-ink); }

/* Year: one column per week, as on a contribution graph. */
.calendar-chart.is-year { --weeks: 53; min-width: calc(var(--weeks) * 13px + 26px); }
.calendar-months, .calendar-days { display: grid; grid-template-columns: repeat(var(--weeks), minmax(10px, 1fr)); gap: 3px; }
.calendar-months { margin: 0 0 4px 29px; color: var(--muted); font-size: 10px; }
.calendar-months span { overflow: hidden; white-space: nowrap; }
.calendar-body { display: grid; grid-template-columns: 26px minmax(0, 1fr); gap: 3px; }
.calendar-days, .calendar-weekdays { grid-template-rows: repeat(7, 11px); }
.calendar-weekdays { display: grid; row-gap: 3px; align-items: center; color: var(--muted); font-size: 9px; }
.calendar-weekdays span { grid-row: 2; }
.calendar-weekdays span + span { grid-row: 4; }
.calendar-weekdays span + span + span { grid-row: 6; }

/* Month: one row per week. Quarter: three small months. */
:is(.is-month, .is-quarter) .calendar-body { display: block; }
:is(.is-month, .is-quarter) .calendar-weekdays, .is-quarter .calendar-months { display: none; }
.is-month :is(.calendar-months, .calendar-days) { grid-template-columns: repeat(7, minmax(0, 1fr)); margin-left: 0; }
.is-month .calendar-months { position: sticky; top: 0; z-index: 1; padding: 3px 0; background: var(--solid); }
.is-month .calendar-days { grid-template-rows: none; grid-auto-rows: 44px; }
.is-month .calendar-days button { display: grid; align-content: start; padding: 4px; text-align: left; }
.is-month .calendar-days small { font-size: 9px; }
.is-quarter .calendar-days { grid-template-columns: repeat(3, minmax(0, 1fr)); grid-template-rows: none; gap: 14px; }
.calendar-days h3 { margin-bottom: 6px; font-size: 12px; font-weight: 500; }
.quarter-days { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); grid-template-rows: 12px; grid-auto-rows: 16px; align-items: center; gap: 3px; }
.quarter-days span { color: var(--muted); font-size: 9px; text-align: center; }
.quarter-days button { height: 100%; font-size: 10px; }

/* Week: a day per row, an hour per column. Day: 24 bars. */
.calendar-hours { display: grid; align-items: center; gap: 3px; color: var(--muted); font-size: 9px; }
.calendar-hours [data-level] { height: 100%; }
.calendar-hours.is-week { grid-template-columns: 40px repeat(24, minmax(0, 1fr)); grid-template-rows: 14px repeat(7, 12px); }
.calendar-day { height: 12px; color: var(--accent); text-align: left; white-space: nowrap; }
.calendar-hours.is-day { grid-template-columns: repeat(24, minmax(0, 1fr)); grid-template-rows: 82px 14px; }
.is-day [data-level] { position: relative; background: none; }
.is-day [data-level]::before { content: ''; position: absolute; inset: auto 0 0; height: var(--activity, 0%); border-radius: 2px; background: var(--level, var(--raised)); }

.place table { width: 100%; border-collapse: collapse; table-layout: fixed; font-size: 12px; font-variant-numeric: tabular-nums; }
.place :is(th, td) { padding: 6px 4px; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; text-align: left; vertical-align: top; }
.place :is(th, td):last-child { width: 22%; text-align: right; }
.place thead { position: sticky; top: 0; z-index: 1; background: var(--solid); }
.pagination:not([hidden]) + table thead { top: 32px; }
.place th button { width: 100%; min-height: 24px; color: var(--muted); font-size: 11px; text-align: inherit; }
.place th[aria-sort=ascending] button::after { content: ' ↑'; }
.place th[aria-sort=descending] button::after { content: ' ↓'; }
.place th:not([aria-sort=none]) button { color: var(--accent); }
.place td .link { text-align: left; white-space: normal; }
.pagination { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; justify-content: space-between; height: 32px; background: var(--solid); font-size: 12px; }

/* ── MapLibre ── */
.maplibregl-ctrl-top-right { top: max(var(--gap), env(safe-area-inset-top)); right: max(var(--gap), env(safe-area-inset-right)); display: flex; flex-direction: column; align-items: end; gap: 6px; }
.maplibregl-ctrl-top-right .maplibregl-ctrl { margin: 0; }
.maplibregl-ctrl-group { overflow: hidden; border: 1px solid var(--line); border-radius: 10px !important; background: var(--glass) !important; backdrop-filter: blur(18px) saturate(1.5); box-shadow: 0 4px 16px #0005 !important; }
.maplibregl-ctrl-group button { display: grid; place-items: center; width: var(--map-control); height: var(--map-control); color: var(--ink); }
.maplibregl-ctrl-group button + button { border-top: 1px solid var(--line); }
.maplibregl-ctrl-icon { filter: invert(1); }
#map-actions:not(:has(button:not([hidden]))) { display: none; }
#map-actions [aria-pressed=true] { background: var(--accent-soft); color: var(--accent); }
.maplibregl-ctrl-bottom-right { right: 0; bottom: 0; }
.maplibregl-map { font: inherit; }
.maplibregl-ctrl-attrib { max-width: calc(100vw - 24px); background: #12141bd9 !important; color: #d0d4de; font-size: 10px; line-height: 1.7; }
.maplibregl-ctrl-attrib a { color: inherit !important; }
:is(.google-map, .yandex-map) .maplibregl-ctrl-attrib { font: 11px/17px Arial, sans-serif; }
.google-maps-brand { margin-right: 6px; color: #fff; font: 400 14px/20px Arial, sans-serif; white-space: nowrap; }

.maplibregl-popup-content { padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--solid); box-shadow: 0 12px 40px #0009; color: var(--ink); font: inherit; }
.maplibregl-popup[class*=anchor-top] .maplibregl-popup-tip { border-bottom-color: var(--solid); }
.maplibregl-popup[class*=anchor-bottom] .maplibregl-popup-tip { border-top-color: var(--solid); }
.maplibregl-popup-anchor-left .maplibregl-popup-tip { border-right-color: var(--solid); }
.maplibregl-popup-anchor-right .maplibregl-popup-tip { border-left-color: var(--solid); }
.maplibregl-popup-close-button { padding: 2px 8px; color: var(--muted); font-size: 16px; }
/* Fixed width: stepping through points keeps the arrows under the pointer. */
.point { width: 250px; font-size: 12px; font-variant-numeric: tabular-nums; }
.point header { display: flex; align-items: end; justify-content: space-between; gap: 12px; }
.point header p { display: grid; grid-template-columns: auto auto; justify-content: start; align-items: baseline; gap: 0 8px; }
.point a:first-child { grid-column: 1 / -1; font-size: 13px; font-weight: 600; }
.point small { color: var(--muted); font-size: 10px; }
.point-nav { display: flex; gap: 2px; }
.point dl { display: grid; grid-template-columns: auto 1fr; gap: 3px 16px; margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--line); }
.point dt { color: var(--muted); }
.point dd { text-align: right; overflow-wrap: anywhere; }

/* Satellite imagery comes from the provider SDK underneath a transparent MapLibre canvas. */
.native-basemap { position: absolute; inset: 0; z-index: -1; }
.native-map { --native-footer: 40px; }
.native-map #map { pointer-events: none; }
/* Preserve clickable SDK copyright controls beneath the history overlay. */
.native-map .maplibregl-canvas-container { position: absolute; inset: 0; clip-path: inset(0 0 var(--native-footer) 0); pointer-events: auto; }
.native-map .maplibregl-ctrl-compass { display: none; }

/* ── Guide ── */
dialog { width: min(760px, 100% - 24px); max-height: 86dvh; padding: 0; overflow: hidden; border: 1px solid var(--line); border-radius: 18px; background: var(--solid); color: var(--ink); box-shadow: 0 30px 100px #0009; }
dialog[open] { display: flex; flex-direction: column; }
dialog::backdrop { background: #06090799; backdrop-filter: blur(4px); }
.guide { padding: 0 20px 20px; overflow: auto; color: #c4c8d4; line-height: 1.7; }
.guide section { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
.guide h3 { margin-bottom: 6px; color: var(--accent); font-size: 14px; }
.guide :is(p + p, dl + p, ul, details, dl) { margin-top: 8px; }
.guide ul { padding-left: 18px; }
.guide li + li { margin-top: 6px; }
.guide details { padding: 10px 14px; border: 1px solid var(--line); border-radius: 10px; }
.guide summary { color: var(--ink); font-weight: 600; cursor: pointer; }
.guide dt { margin-top: 8px; color: var(--ink); font-weight: 600; }
.guide :is(.guide-modes, .guide-links) { display: grid; grid-template-columns: max-content minmax(0, 1fr); align-items: baseline; gap: 8px 14px; }
.guide :is(.guide-modes, .guide-links) dt { margin: 0; }
.guide-links a { margin-right: 10px; }
.ctl, kbd { display: inline-flex; align-items: center; gap: 4px; padding: 0 6px; border: 1px solid var(--line); border-radius: 6px; background: var(--raised); color: var(--ink); font: inherit; font-size: 12px; white-space: nowrap; vertical-align: baseline; }
.ctl .icon { width: 14px; height: 14px; color: var(--accent); }
.noscript { position: fixed; inset: 70px 20px auto; z-index: 50; padding: 16px; border-radius: 12px; background: #4b2a23; }

/* With the settings folded, Place history may use the full width below the bar. */
@media (min-width: 761px) {
  .dock:has(#timeline-toggle[aria-expanded=false]) { width: max-content; max-width: 100%; justify-self: start; }
  .ui:not(:has(#settings:not([hidden]))) .place { grid-column: 1 / -1; max-height: calc(100% - var(--bar) - var(--gap)); }
}

/* The compact dock and Place history can share the bottom edge when both fit. */
@media (min-width: 1280px) {
  .ui:has(#timeline-toggle[aria-expanded=false]) .place { grid-row: 1 / -1; }
}

/* ── Phones: one column; the settings unfold over the map, Place history is a bottom sheet ── */
@media (max-width: 760px) {
  :root { --tap: 38px; --thumb: 22px; }
  .ui { grid-template: "panel" var(--bar) "stage" minmax(0, 1fr) "dock" auto / minmax(0, 1fr); }
  /* The bar keeps its row; unfolded settings extend over the stage below it. */
  #panel { grid-area: 1 / 1 / 3 / 2; width: auto; justify-self: stretch; margin: 0; }
  .maplibregl-ctrl-top-right { top: calc(max(var(--gap), env(safe-area-inset-top)) + var(--bar) + var(--gap)); }
  .native-map { --native-footer: 56px; }

  /* Place history scrolls as one sheet instead of squeezing its calendar. */
  .place { grid-area: stage; width: 100%; max-height: min(100%, 62dvh); overflow-y: auto; overscroll-behavior: contain; }
  .place > *, #place-results > *, #place-view-calendar > * { flex: none; }
  .place-view, #place-view-calendar { overflow: visible; }
  .place thead, .pagination { position: static; }
  .place table { font-size: 11px; }
  .place :is(th, td) { padding-inline: 3px; }
  .place td .link { font-size: inherit; }
  #place-view-visits :is(th, td):nth-child(-n+2) { width: 30.5%; }
  #place-scope { order: 1; flex-basis: 100%; }
  .is-quarter .calendar-days { grid-template-columns: minmax(0, 1fr); }
  /* Keep filters and period controls available without losing the selected area. */
  .ui:has(.place:not([hidden])) .dock > :not(.dock-head, #window-filters) { display: none; }

  .dock .stepper { flex: 1; display: grid; grid-template-columns: repeat(4, var(--tap)); justify-content: space-between; }
  .dock .stepper p { display: contents; }
  #period-back { grid-area: 2 / 1; }
  #period-forward { grid-area: 2 / 2; }
  #play { grid-area: 2 / 3; }
  #timeline-toggle { grid-area: 2 / 4; }
  #range-summary { grid-area: 1 / 1 / 2 / -1; width: auto; text-align: center; white-space: nowrap; }
  #periods { flex: 1 0 100%; }
  #periods button { padding: 0 2px; }
  .dock > .chips { flex-wrap: nowrap; margin: 0 -12px; padding: 0 12px; overflow-x: auto; scrollbar-width: none; }
  .dates { grid-template: "range range" "from to" / 1fr 1fr; gap: 4px 10px; }
  .dates > :first-child { grid-area: from; }
  .dates > :last-child { grid-area: to; justify-self: end; }
  #date-range { grid-area: range; }
  #legend-unit { display: none; }

  .calendar-toolbar { display: grid; grid-template-columns: minmax(0, .8fr) auto minmax(0, 1fr); gap: 4px; font-size: 11px; }
  .calendar-toolbar label { min-width: 0; }
  .calendar-toolbar label > span { display: none; }
  .calendar-toolbar :is(select, input) { min-width: 0; padding: 0 4px; font-size: 11px; }
  .calendar-toolbar select { width: 100%; }
  .calendar-toolbar .date-field { width: calc(10ch + 28px); }
  .calendar-toolbar .iso-date { padding-right: 22px; }
  .calendar-toolbar .date-picker { width: 22px; }
}

/* On very narrow phones, give the full numbers their own row. */
@media (max-width: 360px) {
  :root:has(.stats:not([hidden])) { --bar: 82px; }
  .bar:has(.stats:not([hidden])) { flex-wrap: wrap; }
  .stats { order: 1; flex-basis: 100%; margin-right: 0; padding-left: 0; border-left: 0; }
  .calendar-toolbar { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .calendar-toolbar > .stepper { grid-area: 2 / 1 / 3 / -1; justify-content: center; }
}

@media (prefers-reduced-motion: reduce) {
  *, ::before, ::after { transition: none !important; animation: none !important; }
}
