/* =========================================================================
   ROUTE 77 — Interactive map
   Companion stylesheet for js/mapengine.js. Uses the theme.css palette, and
   falls back to its own values so the map also works standalone.
   ========================================================================= */
.mg-root {
  --mg-bg:      var(--void, #080706);
  --mg-panel:   var(--panel, #15120e);
  --mg-panel-2: var(--panel-2, #1c1813);
  --mg-line:    var(--line, #2e2820);
  --mg-line-2:  var(--line-2, #3d3427);
  --mg-text:    var(--text, #cdc2b2);
  --mg-muted:   var(--muted, #8a8074);
  --mg-dim:     var(--dim, #5e564c);
  --mg-bone:    var(--bone, #e6ddcd);
  --mg-brass:   var(--brass-hi, #d8a53a);
  --mg-bad:     var(--bad, #b3392c);

  position: relative;
  display: flex;
  min-height: 0;
  height: 100%;
  background: var(--mg-bg);
  color: var(--mg-text);
  font-family: 'Arial Narrow', 'Oswald', system-ui, sans-serif;
  overflow: hidden;
}

/* ------------------------------- Stage ---------------------------------- */
.mg-stage { position: relative; flex: 1; min-width: 0; overflow: hidden; }

.mg-canvas { position: absolute; inset: 0; }

.mg-svg {
  width: 100%; height: 100%; display: block;
  touch-action: none;              /* we own pan + pinch */
  cursor: grab;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.mg-svg:active { cursor: grabbing; }

/* Layers animate their own opacity; the engine sets the target value. */
.mg-l { transition: opacity .18s linear; }
.mg-l-pin, .mg-l-overlay { transition: none; }

.mg-dfill { cursor: pointer; transition: fill-opacity .2s ease; }
.mg-dedge { transition: stroke-opacity .2s ease; pointer-events: none; }
/* Halos are sized to survive illustrated terrain underneath, not just the
   flat void background — without them labels vanish into the artwork. */
.mg-dlabel, .mg-plabel {
  pointer-events: none;
  font-weight: 800;
  paint-order: stroke fill;
  stroke: rgba(4,3,2,.92);
  stroke-width: 5px; stroke-linejoin: round;
}
.mg-plabel { font-weight: 700; stroke-width: 3.4px; fill: #b8ad9c; }
.mg-route { transition: opacity .2s ease, stroke-width .2s ease; pointer-events: none; }

/* -------------------------------- Pins ---------------------------------- */
.mg-pin { cursor: pointer; }
.mg-pin .mg-disc { transition: stroke-width .15s ease, fill .15s ease; }
.mg-pin:hover .mg-disc { fill: #1d1913; stroke-width: 2.4; }
.mg-pin.sel .mg-disc { fill: #241f18; stroke-width: 2.6; }
.mg-pin.locked { opacity: .62; }
.mg-pin.locked .mg-disc { stroke-dasharray: 3 2.5; }

/* Fog of war: never visited reads as a silhouette, not as missing. */
.mg-pin.fog { opacity: .46; }
.mg-pin.fog:hover { opacity: .9; }
.mg-pin.found .mg-disc { stroke-width: 2.2; }
.mg-pin.found .mg-ico { stroke: var(--mg-brass); }

.mg-ring { pointer-events: none; }
.mg-you  { pointer-events: none; }

/* -------------------------------- HUD ----------------------------------- */
.mg-hud { position: absolute; inset: 0; pointer-events: none; }

.mg-zoombar {
  position: absolute; left: 12px; bottom: 12px;
  display: flex; flex-direction: column; gap: 4px;
  pointer-events: auto;
}
.mg-zb {
  width: 34px; height: 34px;
  background: rgba(21,18,14,.92);
  border: 1px solid var(--mg-line-2);
  border-radius: var(--r-s, 3px);
  color: var(--mg-text);
  font-size: 17px; line-height: 1;
  cursor: pointer;
  backdrop-filter: blur(4px);
}
.mg-zb:hover { border-color: var(--mg-brass); color: var(--mg-brass); }

.mg-sidetoggle {
  position: absolute; right: 12px; top: 12px;
  width: 34px; height: 34px;
  background: rgba(21,18,14,.92);
  border: 1px solid var(--mg-line-2);
  border-radius: var(--r-s, 3px);
  color: var(--mg-text); font-size: 15px; line-height: 1;
  cursor: pointer; pointer-events: auto;
  backdrop-filter: blur(4px);
}
.mg-sidetoggle:hover { border-color: var(--mg-brass); color: var(--mg-brass); }
.mg-root.side-hidden .mg-side { display: none; }

.mg-scale {
  position: absolute; left: 54px; bottom: 12px;
  padding: 4px 8px;
  background: rgba(21,18,14,.85);
  border: 1px solid var(--mg-line);
  border-radius: var(--r-s, 3px);
  font-size: 11px; letter-spacing: 1px; color: var(--mg-muted);
  pointer-events: none;
}

/* ----------------------------- Detail card ------------------------------ */
.mg-card {
  position: absolute; left: 12px; top: 12px; width: 300px; max-width: calc(100% - 24px);
  background: linear-gradient(180deg, rgba(28,24,19,.97), rgba(15,12,9,.97));
  border: 1px solid var(--mg-line-2);
  border-left: 3px solid var(--fc, var(--mg-brass));
  border-radius: var(--r-m, 5px);
  padding: 12px 14px 13px;
  box-shadow: var(--shadow, 0 10px 30px rgba(0,0,0,.65));
  pointer-events: auto;
  z-index: 5;
}
.mg-card[hidden] { display: none; }

.mg-x {
  position: absolute; right: 6px; top: 5px;
  width: 24px; height: 24px;
  background: none; border: 0; cursor: pointer;
  color: var(--mg-dim); font-size: 19px; line-height: 1;
}
.mg-x:hover { color: var(--mg-bone); }

.mg-ctop { display: flex; gap: 10px; align-items: flex-start; padding-right: 20px; }
.mg-cavatar {
  flex: 0 0 34px; width: 34px; height: 34px;
  display: grid; place-items: center;
  border: 1px solid var(--mg-line-2); border-radius: var(--r-s, 3px);
  background: #12100c; color: var(--fc, var(--mg-bone));
}
.mg-cavatar svg { width: 19px; height: 19px; }
.mg-ctop h3 {
  margin: 0; font-size: 15px; letter-spacing: .6px;
  color: var(--mg-bone); font-weight: 800;
}
.mg-csub { font-size: 11px; color: var(--mg-muted); margin-top: 2px; letter-spacing: .4px; }

.mg-cdesc {
  margin: 9px 0 0; font-size: 12px; line-height: 1.5;
  color: var(--mg-text); opacity: .85;
  font-family: system-ui, sans-serif;
}

.mg-ctags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 10px; }
.mg-tag {
  font-size: 10px; letter-spacing: .8px; text-transform: uppercase;
  padding: 2px 6px;
  border: 1px solid var(--mg-line-2); border-radius: 2px;
  color: var(--mg-muted); background: rgba(255,255,255,.02);
}
.mg-tag.bad { color: var(--mg-bad); border-color: rgba(179,57,44,.5); }

.mg-cact { display: flex; gap: 6px; margin-top: 12px; }
.mg-btn {
  flex: 1;
  padding: 8px 10px;
  background: var(--mg-panel-2);
  border: 1px solid var(--mg-line-2);
  border-radius: var(--r-s, 3px);
  color: var(--mg-text);
  font-family: inherit; font-size: 12px; font-weight: 700;
  letter-spacing: 1px; text-transform: uppercase;
  cursor: pointer;
}
.mg-btn:hover { border-color: var(--mg-brass); color: var(--mg-brass); }
.mg-btn.primary {
  background: linear-gradient(180deg, #3a2e22, #241f18);
  border-color: var(--mg-brass); color: var(--mg-brass);
}
.mg-clock {
  margin-top: 12px; padding: 8px 10px;
  border: 1px dashed var(--mg-line-2); border-radius: var(--r-s, 3px);
  font-size: 11px; letter-spacing: .6px; color: var(--mg-dim); text-align: center;
}

/* ------------------------------ Sidebar --------------------------------- */
.mg-side {
  flex: 0 0 264px;
  display: flex; flex-direction: column;
  background: var(--mg-panel);
  border-left: 1px solid var(--mg-line);
  min-height: 0;
}

.mg-side-head {
  padding: 12px;
  border-bottom: 1px solid var(--mg-line);
  display: flex; flex-direction: column; gap: 9px;
}

.mg-progress { font-size: 11px; letter-spacing: 1.2px; color: var(--mg-muted); text-transform: uppercase; }
.mg-progress b { color: var(--mg-brass); font-size: 14px; margin-right: 5px; }
.mg-pbar {
  height: 3px; margin-top: 6px;
  background: #241f18; border-radius: 2px; overflow: hidden;
}
.mg-pbar i { display: block; height: 100%; background: var(--mg-brass); transition: width .3s ease; }

.mg-search {
  width: 100%; padding: 7px 9px;
  background: #0e0c09;
  border: 1px solid var(--mg-line-2); border-radius: var(--r-s, 3px);
  color: var(--mg-text); font-family: inherit; font-size: 13px;
}
.mg-search:focus { outline: none; border-color: var(--mg-brass); }
.mg-search::placeholder { color: var(--mg-dim); }

.mg-presets, .mg-bulk, .mg-factions { display: flex; flex-wrap: wrap; gap: 4px; }

.mg-preset, .mg-bulk button, .mg-fchip {
  padding: 4px 7px;
  background: var(--mg-panel-2);
  border: 1px solid var(--mg-line-2); border-radius: 2px;
  color: var(--mg-muted);
  font-family: inherit; font-size: 10px; font-weight: 700;
  letter-spacing: .7px; text-transform: uppercase;
  cursor: pointer;
}
.mg-preset:hover, .mg-bulk button:hover { color: var(--mg-bone); border-color: var(--mg-line-2); }
.mg-preset.on { color: var(--mg-brass); border-color: var(--mg-brass); }
.mg-bulk button.on { color: var(--mg-brass); border-color: var(--mg-brass); }

.mg-fchip { color: var(--fc); border-color: color-mix(in srgb, var(--fc) 40%, transparent); opacity: .35; }
.mg-fchip.on { opacity: 1; background: color-mix(in srgb, var(--fc) 14%, transparent); }

/* ---------------------------- Category list ----------------------------- */
.mg-cats { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding-bottom: 16px; }
.mg-cats::-webkit-scrollbar { width: 8px; }
.mg-cats::-webkit-scrollbar-thumb { background: #241f18; border-radius: 4px; }

.mg-group { padding: 4px 0 6px; }
.mg-ghead {
  display: flex; align-items: center; gap: 7px;
  padding: 9px 12px 5px;
  font-size: 10px; font-weight: 800; letter-spacing: 2px;
  color: var(--gc);
}
.mg-gbar { width: 3px; height: 11px; background: var(--gc); border-radius: 1px; }

.mg-cat {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 5px 12px;
  background: none; border: 0; border-left: 2px solid transparent;
  color: var(--mg-dim);
  font-family: inherit; font-size: 12px; text-align: left;
  cursor: pointer;
}
.mg-cat:hover { background: rgba(255,255,255,.03); color: var(--mg-text); }
.mg-cat.on { color: var(--mg-text); border-left-color: var(--gc); }
.mg-cat.on .mg-cico { color: var(--gc); opacity: 1; }

/* districts mode: the row IS the district, so the colour bar carries the
   faction and the count is how much is inside it */
.mg-cat[data-district] { padding: 7px 12px; }
.mg-cat[data-district] .mg-gbar { flex: 0 0 3px; height: 13px; }
.mg-cat[data-district].sel {
  background: rgba(216,165,58,.09);
  border-left-color: var(--mg-brass);
  color: var(--mg-bone);
}
.mg-cat[data-district] .mg-ccount b { color: var(--mg-brass); }

.mg-cico { flex: 0 0 16px; height: 16px; opacity: .35; }
.mg-cico svg { width: 16px; height: 16px; display: block; }
.mg-ctitle { flex: 1; letter-spacing: .3px; }
.mg-ccount { font-size: 10px; color: var(--mg-dim); letter-spacing: .5px; }
.mg-cat.on .mg-ccount b { color: var(--mg-brass); }

/* ------------------------------- Mobile --------------------------------- */
/* The sidebar becomes a bottom sheet and the card docks to the bottom edge.
   Same engine, same data — only the shell changes. */
@media (max-width: 780px) {
  .mg-root { flex-direction: column; }
  .mg-stage { flex: 1 1 58%; }
  .mg-side {
    flex: 0 0 42%;
    border-left: 0; border-top: 1px solid var(--mg-line);
  }
  .mg-side-head { padding: 10px; }
  .mg-card {
    left: 8px; right: 8px; top: auto; bottom: 8px; width: auto; max-width: none;
  }
  .mg-zoombar { bottom: auto; top: 12px; right: 12px; left: auto; }
  .mg-scale { left: 12px; top: 12px; bottom: auto; }
}

/* =========================================================================
   In-game shell: the map screen and the district overlay
   ========================================================================= */
/* The engine sets its own height from the world's aspect (fitAspect), so the
   map is never letterboxed. The card just must not fight it. */
.map-card { padding: 0; overflow: hidden; }
.map-card #cityMap { width: 100%; }

/* Sidebar off: it stays in the DOM (render paths still write to it) but gives
   its width back to the map. */
.mg-root.no-side .mg-side,
.mg-root.no-side .mg-sidetoggle { display: none; }

/* A district opens over the whole app, above the nav bar, and the back
   gesture leaves the district rather than the game. */
.dv {
  position: fixed; inset: 0; z-index: 300;
  background: var(--void, #080706);
  display: flex; flex-direction: column;
}
.dv-bar {
  flex: 0 0 auto; display: flex; align-items: center; gap: 11px;
  padding: 10px 12px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--panel, #15120e); border-bottom: 1px solid var(--line, #2e2820);
}
.dv-back {
  background: var(--panel-2, #1c1813); border: 1px solid var(--line-2, #3d3427);
  border-radius: var(--r-s, 3px); color: var(--text, #cdc2b2);
  font: inherit; font-size: 11px; font-weight: 700; letter-spacing: 1.4px;
  padding: 7px 11px; cursor: pointer;
}
.dv-back:hover { border-color: var(--brass-hi, #d8a53a); color: var(--brass-hi, #d8a53a); }
.dv-name { color: var(--brass-hi, #d8a53a); font-size: 15px; letter-spacing: 2.4px; text-transform: uppercase; }
.dv-sub { color: var(--dim, #5e564c); font-size: 11px; letter-spacing: .8px; }
.dv-map { flex: 1 1 auto; min-height: 0; }

/* On a phone the sidebar would eat the map, so it starts collapsed and the
   ☰ button brings it back. */
@media (max-width: 780px) {
  .dv .mg-side { flex-basis: 42%; }
}

/* =========================================================================
   LIGHT theme (see theme.css). The engine draws with SVG attributes; a CSS
   property outranks an attribute, so the map follows the theme from here
   without touching js/mapengine.js. The painted terrain stays as it is — only
   the wash over it, the pins, the labels and the panels turn to daylight.
   ========================================================================= */
html[data-theme="light"] .mg-void { fill: #e4d9c3; }
html[data-theme="light"] .mg-scrim { fill: #f6f0e3; }
html[data-theme="light"] .mg-l-grid line { stroke: #d6c9ad; }
html[data-theme="light"] .mg-dlabel,
html[data-theme="light"] .mg-plabel { stroke: rgba(250,245,235,.92); }
html[data-theme="light"] .mg-plabel { fill: #4a3f33; }
html[data-theme="light"] .mg-disc { fill: #f6f0e3; }
html[data-theme="light"] .mg-pin:hover .mg-disc { fill: #fbf7ee; }
html[data-theme="light"] .mg-pin.sel .mg-disc { fill: #efe2c4; }
html[data-theme="light"] .mg-ico { stroke: #3a3025; }
html[data-theme="light"] .mg-pin.found .mg-ico { stroke: var(--mg-brass); }

html[data-theme="light"] .mg-zb,
html[data-theme="light"] .mg-sidetoggle { background: rgba(246,240,228,.94); }
html[data-theme="light"] .mg-scale { background: rgba(246,240,228,.88); }
html[data-theme="light"] .mg-card { background: linear-gradient(180deg, rgba(248,242,231,.97), rgba(236,227,208,.97)); }
html[data-theme="light"] .mg-cavatar { background: #efe7d5; }
html[data-theme="light"] .mg-tag { background: rgba(90,60,20,.04); }
html[data-theme="light"] .mg-btn.primary { background: linear-gradient(180deg, #efe2c4, #e2d1ad); }
html[data-theme="light"] .mg-pbar { background: var(--track, #dccfb5); }
html[data-theme="light"] .mg-search { background: #fbf7ee; }
html[data-theme="light"] .mg-cats::-webkit-scrollbar-thumb { background: #c4b393; }
html[data-theme="light"] .mg-cat:hover { background: rgba(90,60,20,.05); }
html[data-theme="light"] .mg-cat[data-district].sel { background: rgba(140,100,23,.12); }
