/* Mogollon Mapper
   Layout: a Forest Service trail sign across the top (brown board, routed yellow
   letters), the map filling everything under it, and a paper legend panel that
   docks on the right on wide screens and slides up as a sheet on phones. */

:root {
  --sign: #4b3020;          /* sign-board brown */
  --sign-deep: #38230f;
  --sign-ink: #f4d58a;      /* routed-letter yellow */
  --paper: #f1f2ec;         /* map paper */
  --paper-2: #e6e8df;
  --paper-a: rgba(241, 242, 236, 0.9);
  --ink: #1b232b;
  --ink-2: #55606b;
  --rule: #c5c9bd;
  --grid: #2a62a6;          /* atlas grid blue */
  --ok: #2e7d4f;
  --warn: #a8560f;
  --bad: #b3261e;
  --trail: #d8401a;
  --shadow: 0 2px 10px rgba(20, 24, 28, 0.28);

  --cond: "Avenir Next Condensed", "Roboto Condensed", "sans-serif-condensed", "Arial Narrow", "Helvetica Neue", Arial, sans-serif;
  --body: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --sign: #3a2414;
    --sign-deep: #2a190c;
    --paper: #1e2226;
    --paper-2: #2a3036;
    --paper-a: rgba(30, 34, 38, 0.9);
    --ink: #e9ebe4;
    --ink-2: #a7b0b8;
    --rule: #434b53;
    --grid: #7fb0ea;
    --ok: #63c08a;
    --warn: #e6a35c;
    --bad: #f0857c;
    --shadow: 0 2px 12px rgba(0, 0, 0, 0.55);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; margin: 0; }
body {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);   /* sign, install banner (phones), map */
  grid-template-columns: minmax(0, 1fr) auto;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: var(--paper);
  color: var(--ink);
  font: 15px/1.4 var(--body);
  -webkit-text-size-adjust: 100%;
}

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--grid); outline-offset: 2px; }

/* ---------- sign bar ---------- */
.bar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 46px;
  padding: 6px 12px;
  padding-top: calc(6px + env(safe-area-inset-top, 0px));
  padding-left: max(12px, env(safe-area-inset-left, 0px));
  padding-right: max(12px, env(safe-area-inset-right, 0px));
  background: var(--sign);
  color: var(--sign-ink);
  border-bottom: 3px solid var(--sign-deep);
  box-shadow: inset 0 -1px 0 rgba(244, 213, 138, 0.28);
}
.bar-title { display: flex; align-items: baseline; gap: 10px; flex: 1 1 auto; min-width: 0; white-space: nowrap; overflow: hidden; }
.bar-name {
  flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis;   /* last to give way; the status chip shrinks first */
  font: 700 21px/1 var(--cond);
  letter-spacing: 0.09em;
  text-transform: uppercase;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.45);
}
.bar-sub {
  font: 500 13px/1 var(--cond);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  opacity: 0.72;
  overflow: hidden;
  text-overflow: ellipsis;
}
.bar-right { display: flex; align-items: center; gap: 8px; flex: 0 1 auto; min-width: 0; }
.chip {
  font: 600 12px/1 var(--cond);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 5px 8px;
  border: 1px solid rgba(244, 213, 138, 0.5);
  border-radius: 3px;
  white-space: nowrap;
  flex: 0 1 auto; min-width: 44px; max-width: 46vw;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chip:empty { display: none; }
.chip.is-off { background: var(--sign-ink); color: var(--sign-deep); border-color: var(--sign-ink); }
.gridchip {
  font: 700 15px/1 var(--cond);
  letter-spacing: 0.04em;
  min-width: 34px;
  text-align: center;
  padding: 5px 6px;
  background: #f6f7f2;
  color: #2a62a6;
  border-radius: 3px;
  font-variant-numeric: tabular-nums;
}
.gridchip:empty { display: none; }
/* "Install" in the sign: a routed yellow tab, text dropped on narrow phones. */
.getbtn {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 30px; padding: 0 10px 0 8px;
  background: var(--sign-ink); color: var(--sign-deep);
  border: 1px solid var(--sign-ink); border-radius: 3px;
  font: 700 12px/1 var(--cond); letter-spacing: 0.08em; text-transform: uppercase;
  white-space: nowrap; cursor: pointer;
}
.getbtn svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.getbtn:hover { filter: brightness(1.06); }
.getbtn:active { transform: translateY(1px); }
@media (max-width: 430px) {
  .bar-sub { display: none; }
  .getbtn span { display: none; }
  .getbtn { padding: 0 7px; }
  .chip { max-width: 34vw; }
}

/* ---------- install banner (phones) ---------- */
.banner {
  grid-row: 2; grid-column: 1 / -1;
  display: flex; align-items: center; gap: 10px;
  padding: 7px 6px 7px 12px;
  padding-left: max(12px, env(safe-area-inset-left, 0px));
  padding-right: max(6px, env(safe-area-inset-right, 0px));
  background: var(--paper-2); color: var(--ink);
  border-bottom: 1.5px solid var(--ink);
}
.banner-icon { flex: none; width: 36px; height: 36px; border-radius: 8px; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25); }
.banner-text { flex: 1; min-width: 0; margin: 0; font-size: 12.5px; line-height: 1.25; color: var(--ink-2); }
.banner-text b { display: block; font: 700 14.5px/1.2 var(--cond); letter-spacing: 0.05em; text-transform: uppercase; color: var(--ink); }
.banner .btn { flex: none; }
.banner-close { width: 36px; height: 36px; color: var(--ink-2); }
.banner-close svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; }
@media (max-width: 359px) { .banner-text { font-size: 0; } .banner-text b { font-size: 13.5px; } }

/* ---------- map stage ---------- */
.stage { position: relative; grid-row: 3; grid-column: 1; min-width: 0; min-height: 0; }
#map { position: absolute; inset: 0; }

.leaflet-container {
  font: 13px/1.35 var(--body);
  color: var(--ink);
  background-color: var(--paper-2);
  background-image:
    linear-gradient(var(--rule) 1px, transparent 1px),
    linear-gradient(90deg, var(--rule) 1px, transparent 1px);
  background-size: 32px 32px;
}

.leaflet-container:focus, .leaflet-container:focus-visible { outline: none; }
body.kbd .leaflet-container:focus { outline: 3px solid var(--grid); outline-offset: -3px; }

.mapbtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  width: 46px;
  height: 46px;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  border: 1.5px solid var(--ink);
  border-radius: 6px;
  box-shadow: var(--shadow);
}
.mapbtn svg, .iconbtn svg, .find svg {
  width: 22px; height: 22px;
  fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round;
}
.mapbtn:active { transform: translateY(1px); }
.mapbtn[aria-pressed="true"], .mapbtn[aria-expanded="true"] { background: var(--sign); color: var(--sign-ink); border-color: var(--sign-deep); }
.mapbtn-wide {
  position: absolute; z-index: 1000;
  top: 10px; right: max(10px, env(safe-area-inset-right, 0px));
  width: auto; padding: 0 13px 0 11px;
  font: 700 15px/1 var(--cond); letter-spacing: 0.08em; text-transform: uppercase;
}
.mapbtns {
  position: absolute; z-index: 1000;
  right: max(10px, env(safe-area-inset-right, 0px));
  bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  display: flex; flex-direction: column; gap: 8px;
}

.toast {
  position: absolute; z-index: 1100;
  left: 50%; bottom: calc(58px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  max-width: min(440px, calc(100% - 130px));
  padding: 9px 13px;
  background: var(--ink); color: var(--paper);
  border-radius: 6px;
  box-shadow: var(--shadow);
  font-size: 14px; line-height: 1.35;
  text-align: center;
}
.fatal {
  position: absolute; z-index: 1200; inset: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 24px; text-align: center;
  background: var(--paper); color: var(--ink);
  font-size: 16px;
}

/* ---------- Leaflet chrome ---------- */
.leaflet-bar { border: 1.5px solid var(--ink) !important; border-radius: 6px; box-shadow: var(--shadow); }
.leaflet-bar a, .leaflet-bar a:hover { background: var(--paper); color: var(--ink); border-bottom-color: var(--rule); }
.leaflet-bar a.leaflet-disabled { background: var(--paper-2); color: var(--ink-2); }
.leaflet-touch .leaflet-bar a { width: 34px; height: 34px; line-height: 34px; }
.leaflet-bottom.leaflet-left { padding-bottom: env(safe-area-inset-bottom, 0px); padding-left: env(safe-area-inset-left, 0px); }
.leaflet-control-attribution {
  background: var(--paper-a) !important; color: var(--ink-2);
  font-size: 10.5px; line-height: 1.5; padding: 1px 6px;
  max-width: calc(100vw - 80px);
  border-top-right-radius: 4px;
}
.leaflet-control-attribution a { color: inherit; text-decoration: underline; }
.leaflet-control-scale-line {
  background: var(--paper-a); color: var(--ink);
  border-color: var(--ink); border-width: 1.5px;
  font: 600 11px/1.2 var(--cond); letter-spacing: 0.03em; text-shadow: none;
}
.leaflet-popup-content-wrapper {
  background: var(--paper); color: var(--ink);
  border: 1.5px solid var(--ink); border-radius: 6px;
  box-shadow: var(--shadow);
}
.leaflet-popup-tip { background: var(--paper); border: 1.5px solid var(--ink); box-shadow: none; }
.leaflet-popup-content { margin: 11px 13px 12px; min-width: 150px; }
.leaflet-container a.leaflet-popup-close-button { color: var(--ink-2); font-size: 20px; width: 28px; height: 28px; }

.pop-type {
  font: 700 11.5px/1.2 var(--cond); letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--ink-2); padding-right: 18px;
}
.pop-name { font: 700 19px/1.15 var(--cond); margin: 3px 0 0; overflow-wrap: anywhere; }
.pop-warn { margin: 6px 0 0; font-weight: 600; color: var(--bad); }
.pop-dl { display: grid; grid-template-columns: auto 1fr; gap: 3px 10px; margin: 8px 0 0; padding-top: 7px; border-top: 1px solid var(--rule); }
.pop-dl dt { color: var(--ink-2); white-space: nowrap; }
.pop-dl dd { margin: 0; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.pop-dl a { color: var(--grid); }

.mm-label.leaflet-tooltip {
  background: var(--paper-a); color: var(--ink);
  border: 0; border-radius: 3px; box-shadow: none;
  padding: 1px 5px;
  font: 600 12.5px/1.25 var(--cond); letter-spacing: 0.02em;
  white-space: nowrap; max-width: 190px; overflow: hidden; text-overflow: ellipsis;
  pointer-events: none;
}
.mm-label.leaflet-tooltip::before { display: none; }

.mm-gridlabel {
  font: 700 13px/1 var(--cond); letter-spacing: 0.04em;
  color: var(--grid);
  text-shadow: 0 0 2px var(--paper), 0 0 2px var(--paper), 0 0 3px var(--paper), 0 0 3px var(--paper);
  white-space: nowrap;
  pointer-events: none;
}

/* ---------- panel ---------- */
.panel {
  grid-row: 3; grid-column: 2;
  width: 344px;
  overflow-y: auto; overscroll-behavior: contain;
  background: var(--paper);
  border-left: 1.5px solid var(--ink);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.panel-head {
  position: sticky; top: 0; z-index: 2;
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px;
  background: var(--paper);
  border-bottom: 1px solid var(--rule);
}
.find {
  flex: 1; min-width: 0;
  display: flex; align-items: center; gap: 8px;
  height: 42px; padding: 0 10px;
  background: var(--paper-2);
  border: 1.5px solid var(--ink); border-radius: 6px;
}
.find svg { flex: none; width: 19px; height: 19px; color: var(--ink-2); }
.find input { flex: 1; min-width: 0; height: 100%; border: 0; background: transparent; outline: none; font-size: 16px; }
.find:focus-within { outline: 3px solid var(--grid); outline-offset: 1px; }
.iconbtn {
  flex: none; width: 42px; height: 42px; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent; border: 0; border-radius: 6px; color: var(--ink);
}
.iconbtn:hover { background: var(--paper-2); }

.results { list-style: none; margin: 0; padding: 4px 8px 8px; border-bottom: 1px solid var(--rule); max-height: 46vh; overflow-y: auto; }
.results button {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; align-items: baseline;
  width: 100%; padding: 8px 6px; text-align: left;
  background: transparent; border: 0; border-bottom: 1px dotted var(--rule); border-radius: 4px;
}
.results li:last-child button { border-bottom: 0; }
.results button:hover { background: var(--paper-2); }
.res-name { font: 600 16px/1.2 var(--cond); overflow-wrap: anywhere; }
.res-grid { font: 700 13px/1 var(--cond); color: var(--grid); font-variant-numeric: tabular-nums; }
.res-type { grid-column: 1 / -1; font-size: 12.5px; color: var(--ink-2); }
.results .res-none { padding: 10px 6px; color: var(--ink-2); }

.sec { padding: 14px 12px 4px; }
.sec h2 {
  display: flex; align-items: center; gap: 10px;
  margin: 0 0 10px;
  font: 700 13px/1 var(--cond); letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--ink-2);
}
.sec h2::after { content: ""; flex: 1; height: 1px; background: var(--rule); }

.bases { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.base {
  position: relative;
  display: block; width: 100%; min-width: 0; padding: 9px 10px 8px; text-align: left;
  background: var(--paper); color: var(--ink);
  border: 1.5px solid var(--rule); border-radius: 6px;
}
.base:hover { border-color: var(--ink-2); }
.base[aria-checked="true"] { border-color: var(--ink); background: var(--paper-2); box-shadow: inset 0 -4px 0 var(--sign); }
.base-name { display: block; font: 700 17px/1.1 var(--cond); letter-spacing: 0.02em; }
.base-note { display: block; margin-top: 2px; font-size: 12px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.base-tag {
  position: absolute; top: 7px; right: 8px;
  font: 700 10px/1 var(--cond); letter-spacing: 0.08em; text-transform: uppercase;
  padding: 3px 4px; border-radius: 2px;
  color: var(--ink-2); border: 1px solid var(--rule);
}
.base-tag.is-saved { color: #fff; background: var(--ok); border-color: var(--ok); }

.layers { list-style: none; margin: 0; padding: 0; }
.layers li { border-bottom: 1px dotted var(--rule); }
.layers li:last-child { border-bottom: 0; }
.layer {
  display: grid; grid-template-columns: 22px 30px minmax(0, 1fr); align-items: center; gap: 2px 9px;
  padding: 9px 2px; min-height: 46px; cursor: pointer;
}
.layer input { width: 20px; height: 20px; margin: 0; accent-color: var(--sign); }
.layer svg { width: 30px; height: 16px; display: block; }
.layer-name { font: 600 17px/1.15 var(--cond); letter-spacing: 0.01em; }
.layer-meta { grid-column: 3; font-size: 12.5px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.layer-meta.is-busy { color: var(--warn); }
.layer-meta.is-bad { color: var(--bad); }

.row-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 10px 0 6px; }
.btn {
  min-height: 40px; padding: 0 14px;
  background: var(--paper); color: var(--ink);
  border: 1.5px solid var(--ink); border-radius: 6px;
  font: 700 14px/1 var(--cond); letter-spacing: 0.08em; text-transform: uppercase;
}
.btn:hover { background: var(--paper-2); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-solid { background: var(--sign); color: var(--sign-ink); border-color: var(--sign-deep); }
.btn-solid:hover { background: var(--sign-deep); }
.btn-quiet { border-color: var(--rule); color: var(--ink-2); }
.btn-small { min-height: 34px; padding: 0 10px; font-size: 13px; }
.note { font-size: 12.5px; color: var(--ink-2); flex: 1; min-width: 120px; }

/* ---------- offline maps ---------- */
.off-intro { margin: 0 0 10px; font-size: 13.5px; color: var(--ink-2); }
.off-detail { display: flex; align-items: center; gap: 8px; margin: 0 0 10px; font-size: 13.5px; }
.off-detail select {
  flex: 1; min-width: 0; height: 38px; padding: 0 8px;
  background: var(--paper); border: 1.5px solid var(--ink); border-radius: 6px;
}
.off-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 10px; align-items: center; padding: 9px 0; border-top: 1px dotted var(--rule); }
.off-name { font: 700 17px/1.1 var(--cond); }
.off-state { grid-column: 1; font-size: 12.5px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.off-state.is-saved { color: var(--ok); }
.off-state.is-bad { color: var(--bad); }
.off-btns { grid-row: 1 / span 2; grid-column: 2; display: flex; gap: 6px; }
.off-bar { grid-column: 1 / -1; height: 8px; background: var(--paper-2); border: 1px solid var(--rule); border-radius: 4px; overflow: hidden; }
.off-bar i { display: block; height: 100%; width: 0; background: var(--sign); }
.off-storage { margin: 10px 0 0; padding-top: 9px; border-top: 1px dotted var(--rule); font-size: 12.5px; color: var(--ink-2); font-variant-numeric: tabular-nums; }

.panel-foot { padding: 12px 12px 18px; }
.credits { margin: 10px 0 0; font-size: 11.5px; line-height: 1.5; color: var(--ink-2); }
.credits a { color: inherit; }

/* ---------- "Add to Home Screen" sheet ---------- */
.sheet {
  position: fixed; inset: 0; z-index: 2000;
  display: flex; align-items: flex-end; justify-content: center;
  padding: 12px;
  padding-bottom: max(12px, env(safe-area-inset-bottom, 0px));
  background: rgba(20, 24, 28, 0.55);
}
@media (min-width: 760px) { .sheet { align-items: center; } }
.sheet-card {
  width: 100%; max-width: 440px; max-height: 100%; overflow: auto;
  padding: 18px 18px 16px;
  background: var(--paper); color: var(--ink);
  border: 1.5px solid var(--ink); border-radius: 14px;
  box-shadow: var(--shadow);
}
.sheet-head { display: flex; align-items: center; gap: 14px; }
.sheet-icon { flex: none; width: 56px; height: 56px; border-radius: 12px; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3); }
.sheet-text { min-width: 0; }
.sheet-card h2 { margin: 0; font: 700 21px/1.1 var(--cond); letter-spacing: 0.05em; text-transform: uppercase; }
.sheet-sub { margin: 4px 0 0; font-size: 13.5px; line-height: 1.4; color: var(--ink-2); }
.steps { margin: 14px 0 0; padding: 0 0 0 24px; font-size: 15px; line-height: 1.45; }
.steps:empty { display: none; }
.steps li { margin: 7px 0; padding-left: 2px; }
.steps li::marker { font: 700 15px/1 var(--cond); color: var(--sign); }
.steps b { font-weight: 700; white-space: nowrap; }
.glyph {
  display: inline-block; width: 19px; height: 19px; margin: 0 1px; vertical-align: -4px;
  fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round;
}
.glyph-dots { stroke-width: 3.4; }
.sheet-note { margin: 12px 0 0; font-size: 13px; line-height: 1.45; color: var(--ink-2); }
.sheet-note:empty { display: none; }
.sheet-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; margin-top: 16px; }

/* ---------- phones: panel becomes a bottom sheet ---------- */
@media (max-width: 759px) {
  .panel {
    position: fixed; z-index: 1500;
    left: 0; right: 0; bottom: 0;
    width: auto; max-height: 72%;
    border-left: 0; border-top: 1.5px solid var(--ink);
    border-radius: 14px 14px 0 0;
    box-shadow: 0 -6px 24px rgba(0, 0, 0, 0.3);
  }
  .panel-head { border-radius: 14px 14px 0 0; }
}

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