:root {
  --bg: rgba(12, 16, 22, 0.88);
  --bg2: rgba(20, 26, 34, 0.92);
  --line: rgba(255, 255, 255, 0.12);
  --txt: #eef2f6;
  --dim: #9aa7b4;
  --acc: #37e6ff;
  --a: #ff5a5a;
  --b: #3ddc84;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #0b0e13; color: var(--txt);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
#map { position: fixed; inset: 0; }

#loader { position: fixed; inset: 0; z-index: 60; display: flex; flex-direction: column; gap: 14px;
  align-items: center; justify-content: center; background: #0b0e13; transition: opacity .5s; }
#loader.done { opacity: 0; pointer-events: none; }
#loader .spin { width: 44px; height: 44px; border-radius: 50%;
  border: 4px solid rgba(255,255,255,.15); border-top-color: var(--acc); animation: sp 1s linear infinite; }
@keyframes sp { to { transform: rotate(360deg); } }
#loadStatus { color: var(--dim); font-size: 14px; }

#title { position: fixed; top: 12px; left: 12px; z-index: 20; background: var(--bg);
  border: 1px solid var(--line); border-radius: 12px; padding: 8px 14px; backdrop-filter: blur(6px); }
.t-name { font-weight: 800; letter-spacing: 1px; font-size: 15px; }
.t-sub { font-size: 11px; color: var(--dim); }

#searchPanel { position: fixed; top: 12px; left: 50%; transform: translateX(-50%); z-index: 20;
  width: min(430px, calc(100vw - 24px)); background: var(--bg); border: 1px solid var(--line);
  border-radius: 14px; padding: 10px; backdrop-filter: blur(8px); }
.field { position: relative; display: flex; gap: 6px; margin-bottom: 6px; }
.fld-tag { width: 26px; height: 34px; line-height: 34px; text-align: center; font-weight: 800;
  border-radius: 8px; flex: none; }
.fld-tag.a { background: var(--a); color: #06281a; }
.fld-tag.b { background: var(--b); color: #2b0606; }
.field input { flex: 1; height: 34px; border-radius: 8px; border: 1px solid var(--line);
  background: rgba(255,255,255,.06); color: var(--txt); padding: 0 10px; font-size: 14px; outline: none; }
.field input:focus { border-color: var(--acc); }
.mini { flex: none; width: 34px; border-radius: 8px; border: 1px solid var(--line);
  background: rgba(255,255,255,.06); font-size: 16px; cursor: pointer; }
.mini.arming { border-color: var(--acc); background: rgba(55,230,255,.2); }
.sug-list { display: none; position: absolute; top: 38px; left: 32px; right: 40px; z-index: 30;
  background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; overflow: hidden;
  max-height: 260px; overflow-y: auto; }
.sug { padding: 9px 12px; font-size: 14px; cursor: pointer; display: flex; gap: 8px; align-items: center; }
.sug:hover { background: rgba(55,230,255,.12); }
.sug small { color: var(--dim); }
.row { display: flex; gap: 8px; align-items: center; margin-top: 6px; }
#modeSeg { display: flex; flex: 1; background: rgba(255,255,255,.06); border-radius: 9px; padding: 3px; }
#modeSeg button { flex: 1; border: 0; background: transparent; color: var(--dim); border-radius: 7px;
  padding: 7px; font-size: 14px; cursor: pointer; }
#modeSeg button.active { background: var(--acc); color: #04222a; font-weight: 700; }
#swapBtn, #routeBtn, #clearBtn { border-radius: 9px; cursor: pointer; font-size: 14px; }
#swapBtn { width: 40px; border: 1px solid var(--line); background: rgba(255,255,255,.06); color: var(--txt); }
#routeBtn { flex: 1; border: 0; background: var(--acc); color: #04222a; font-weight: 800; padding: 9px; }
#routeBtn:disabled { opacity: .35; cursor: default; }
#clearBtn.ghost { border: 1px solid var(--line); background: transparent; color: var(--dim); padding: 9px 14px; }
.chk { font-size: 13px; color: var(--dim); display: flex; gap: 6px; align-items: center; cursor: pointer; }

#directions { position: fixed; left: 12px; bottom: 12px; z-index: 20; width: min(380px, calc(100vw - 24px));
  max-height: 46vh; overflow-y: auto; background: var(--bg); border: 1px solid var(--line);
  border-radius: 14px; backdrop-filter: blur(8px); display: none; }
#directions.open { display: block; }
#directions.loading::after { content: "Finding the road…"; display: block; padding: 18px; color: var(--dim); text-align: center; }
.dir-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px 4px; }
.dir-title { font-size: 17px; font-weight: 800; }
.dir-title em { font-style: normal; color: var(--acc); }
.dir-title span { color: var(--dim); }
#dirClose { border: 0; background: transparent; color: var(--dim); font-size: 16px; cursor: pointer; }
.dir-sub { padding: 0 14px 8px; font-size: 12px; color: var(--dim); }
.dir-warn { margin: 0 14px 8px; font-size: 12px; color: #ffd479; background: rgba(255,212,121,.08);
  border: 1px solid rgba(255,212,121,.25); border-radius: 8px; padding: 8px 10px; }
.dir-err { padding: 16px; color: #ffb3b3; }
.dir-steps { list-style: none; margin: 0; padding: 0 6px 10px; }
.dir-steps li { display: flex; gap: 10px; padding: 9px 8px; border-radius: 8px; cursor: pointer; font-size: 13.5px; }
.dir-steps li:hover { background: rgba(55,230,255,.1); }
.mi { flex: none; width: 26px; height: 26px; line-height: 26px; text-align: center; border-radius: 50%;
  background: rgba(55,230,255,.15); font-size: 14px; }
.mt { color: var(--txt); }

#sideControls { position: fixed; right: 12px; top: 50%; transform: translateY(-50%); z-index: 20;
  display: flex; flex-direction: column; gap: 8px; }
#sideControls button { width: 42px; height: 42px; border-radius: 11px; border: 1px solid var(--line);
  background: var(--bg); color: var(--txt); font-size: 19px; cursor: pointer; backdrop-filter: blur(6px); }
#sideControls button.active { border-color: var(--acc); color: var(--acc); }
#dimToggle span { font-size: 14px; font-weight: 800; }
/* A/B panel hide button: eye with a tiny A/B under it, A red / B green like the pins */
#panelToggle { font-size: 15px; line-height: 1.1; padding: 2px 0; }
#panelToggle .ab { display: block; font-size: 9.5px; font-weight: 800; letter-spacing: .3px; margin-top: 1px; }
#panelToggle .ab i { font-style: normal; }
#panelToggle .ab i:first-child { color: #ff5a5a; }
#panelToggle .ab i:last-child { color: #3ddc84; }
body.panel-hidden #searchPanel { display: none; }
#pinBtn.arming { border-color: var(--acc); background: rgba(55,230,255,.2); }

/* compass: top-right, rotates with the map bearing; tap resets north */
#compass { position: fixed; top: 12px; right: 12px; z-index: 20; width: 44px; height: 44px;
  border-radius: 50%; border: 1px solid var(--line); background: var(--bg); cursor: pointer;
  backdrop-filter: blur(6px); padding: 6px; -webkit-tap-highlight-color: transparent; }
#compassRose { width: 100%; height: 100%; display: block; }
#layersWrap { position: relative; }
#layersPop { display: none; position: absolute; right: 50px; top: 0; background: var(--bg2);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; width: 150px; }
#layersPop.open { display: block; }
#layersPop label { display: flex; gap: 8px; font-size: 14px; padding: 5px 0; cursor: pointer; }

/* legend: (i) button bottom-right where the attribution pill used to be;
   the scale bar sits above it (same layout as before, her own button now) */
.maplibregl-ctrl-bottom-right { bottom: 56px; }
#legendBtn { position: fixed; right: 12px; bottom: 12px; z-index: 20; width: 40px; height: 40px;
  border-radius: 50%; border: 1px solid var(--line); background: var(--bg); color: var(--txt);
  font-size: 19px; font-weight: 800; font-style: italic; font-family: Georgia, serif; cursor: pointer;
  backdrop-filter: blur(6px); }
#legendBtn.active { border-color: var(--acc); color: var(--acc); }
#legendPop { position: fixed; right: 12px; bottom: 62px; z-index: 30; width: min(318px, 88vw);
  max-height: 62vh; overflow-y: auto; background: var(--bg); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px 14px; color: var(--txt); display: none;
  box-shadow: 0 8px 28px rgba(0,0,0,.5); backdrop-filter: blur(8px); }
#legendPop.open { display: block; }
.leg-head { font-weight: 800; font-size: 15px; margin-bottom: 8px; display: flex;
  justify-content: space-between; align-items: center; }
#legendClose { background: none; border: none; color: var(--dim); font-size: 15px; cursor: pointer; padding: 2px 4px; }
.leg-row { display: flex; gap: 10px; padding: 6px 0; border-top: 1px solid rgba(255,255,255,.07);
  font-size: 13.5px; line-height: 1.45; color: var(--txt); }
.leg-ic { flex: 0 0 34px; text-align: center; font-size: 16px; }
.leg-ic .ab { display: block; font-size: 8.5px; font-weight: 800; }
.leg-ic .ab i { font-style: normal; }
.leg-ic .ab i:first-child { color: #ff5a5a; }
.leg-ic .ab i:last-child { color: #3ddc84; }
.leg-foot { margin-top: 9px; padding-top: 8px; border-top: 1px solid rgba(255,255,255,.07);
  font-size: 11px; color: var(--dim); }

.pin { width: 26px; height: 26px; border-radius: 50% 50% 50% 4px; transform: rotate(-45deg);
  border: 2px solid #fff; box-shadow: 0 2px 6px rgba(0,0,0,.5); cursor: grab; }

/* Jenna's minimal mode: only the map name, zoom in/out, and the eye stay. */
body.minimal .hidable { display: none !important; }
body.minimal #dimToggle, body.minimal #layersWrap { display: none !important; }

@media (max-width: 640px) {
  #title { top: 8px; left: 8px; padding: 6px 10px; }
  #compass { top: 8px; right: 8px; }
  .t-name { font-size: 13px; } .t-sub { font-size: 10px; }
  #searchPanel { top: auto; bottom: 8px; left: 8px; transform: none; width: calc(100vw - 76px); }
  #directions { bottom: auto; top: 64px; max-height: 40vh; }
  #sideControls { top: auto; bottom: 190px; transform: none; }
  #sideControls button { width: 38px; height: 38px; }
}

/* while a route is active, hide the search panel so the map/route is fully visible;
   it comes back when the route is cleared (X on the directions card) */
body.routing #searchPanel { display: none; }

/* coordinate readout pill (X / Z, + elevation in 3D) */
#coords { position: fixed; top: 88px; left: 12px; z-index: 19; background: var(--bg);
  border: 1px solid var(--line); border-radius: 9px; padding: 5px 10px;
  font: 11px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--dim);
  backdrop-filter: blur(6px); pointer-events: none; }
#coords b { color: #fff; font-weight: 600; }

/* town name labels (from locations.geojson, tier-filtered by zoom) */
.town-label { font-family: system-ui, -apple-system, sans-serif; font-weight: 700;
  color: #fff; white-space: nowrap; pointer-events: none;
  text-shadow: 0 1px 2px #000, 0 0 5px rgba(0,0,0,.9), 0 0 2px #000; }
.town-label.tier-major { font-size: 17px; }
.town-label.tier-city { font-size: 14px; }
.town-label.tier-village { font-size: 12px; }
.town-label.tier-local { font-size: 11px; opacity: .88; }
.town-label.tier-ruin_camp { font-size: 10px; opacity: .72; font-style: italic; }

/* topo (light relief) basemap: dark town names with a light halo */
body.topo .town-label { color: #2e2a24;
  text-shadow: 0 1px 0 rgba(255,255,255,.85), 0 0 4px rgba(255,255,255,.9), 0 0 2px #fff; }

/* route option chips */
.route-opts { display: flex; gap: 8px; padding: 2px 14px 10px; overflow-x: auto; }
.route-opt {
  flex: 0 0 auto; padding: 7px 12px; border-radius: 999px;
  border: 1px solid var(--line); background: transparent; color: var(--fg);
  font-size: 12px; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.route-opt.sel { background: var(--accent); border-color: var(--accent); color: #fff; }

/* building info card + basemap switch (v4) */
.baseRow { display: flex; gap: 12px; padding-bottom: 6px; margin-bottom: 6px; border-bottom: 1px solid rgba(255,255,255,0.14); }
.maplibregl-popup-content { background: #171b21; color: #e8ecf1; border-radius: 12px; padding: 0; overflow: hidden; box-shadow: 0 6px 24px rgba(0,0,0,0.5); }
.bldg-img { display: block; width: 100%; height: 76px; background: #22262c; }
img.bldg-photo { object-fit: contain; background: #f2f0eb; }
.bldg-head { padding: 11px 14px 9px; }
.bldg-head .bldg-name { margin-bottom: 0; }
.bldg-body { padding: 10px 14px 12px; }
.maplibregl-popup-anchor-bottom .maplibregl-popup-tip { border-top-color: #171b21; }
.maplibregl-popup-anchor-top .maplibregl-popup-tip { border-bottom-color: #171b21; }
.maplibregl-popup-close-button { color: #9fb0c0; font-size: 16px; padding: 2px 7px; }
.bldg-name { font-weight: 700; font-size: 15px; margin-bottom: 3px; padding-right: 14px; }
.bldg-meta { font-size: 12.5px; color: #aeb9c6; margin-bottom: 2px; }
.bldg-btns { display: flex; gap: 8px; margin-top: 9px; }
.bldg-btns button { flex: 1; background: #0aa2c0; color: #fff; border: 0; border-radius: 8px; padding: 7px 4px; font-size: 12.5px; font-weight: 600; cursor: pointer; }
.bldg-btns button[data-w="start"] { background: #3a4654; }
