/* ==========================================================================
 * Minimap Visual Shell & Cartographic Label System
 * Original Alpine-Enamel / Spruce-Slate Design System
 * Self-hosted OFL Nunito variable fonts (no external font CDN)
 * ========================================================================== */

@font-face {
  font-family: "Nunito";
  src: url("./fonts/nunito-var.woff2") format("woff2");
  font-weight: 200 1000;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Nunito";
  src: url("./fonts/nunito-italic-var.woff2") format("woff2");
  font-weight: 200 1000;
  font-style: italic;
  font-display: swap;
}

:root {
  --font-ui: "Nunito", "Avenir Next Rounded", "Trebuchet MS", system-ui, -apple-system, sans-serif;

  /* Deep spruce-emerald enamel frames (distinct original alpine palette) */
  --frame-dark: #0d2520;
  --frame-deep: #173d34;
  --frame-mid: #215246;
  --frame-rim: #316e5f;
  --frame-text: #f7f4e9;
  --frame-muted: #b5cfc4;

  /* Warm porcelain-cream enamel buttons & surfaces */
  --enamel-top: #fffef9;
  --enamel-mid: #f7f0db;
  --enamel-bot: #e6d8b5;
  --enamel-hover: #fffbf0;
  --enamel-ink: #162e27;
  --enamel-muted: #4e665e;
  --enamel-line: rgba(16, 42, 34, 0.16);

  /* Accent colours */
  --accent-amber: #f2ab34;
  --accent-amber-deep: #d58815;
  --accent-coral: #d45836;
  --accent-sky: #2b89c6;
  --accent-sky-bright: #8adfff;
  --accent-pine: #1f6b5c;

  /* Tactile shadows */
  --shadow-frame: 0 3px 0 var(--frame-dark), 0 8px 22px rgba(8, 22, 18, 0.34);
  --shadow-btn: inset 0 1.5px 0 rgba(255, 255, 255, 0.92), inset 0 -2px 0 rgba(160, 138, 92, 0.36), 0 2.5px 0 var(--frame-dark), 0 5px 12px rgba(8, 22, 18, 0.26);
  --shadow-btn-press: inset 0 1px 0 rgba(255, 255, 255, 0.65), 0 1px 0 var(--frame-dark), 0 2px 6px rgba(8, 22, 18, 0.22);
  --shadow-pill: 0 2px 0 rgba(10, 26, 20, 0.68), 0 4px 10px rgba(8, 22, 18, 0.34);

  --radius-shell: 14px;
  --radius-btn: 11px;
  --radius-pill: 999px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  font-family: var(--font-ui);
  color: var(--enamel-ink);
  background: linear-gradient(180deg, #cbe0f2 0%, #dcebf7 65%, #e8f1f7 100%);
  user-select: none;
  -webkit-font-smoothing: antialiased;
}

#canvas-wrap {
  position: fixed;
  inset: 0;
}

.ui-ico {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  display: block;
}

/* ==========================================================================
 * 1. SVG Leader Lines & Pinned Anchor Dots
 * ========================================================================== */
#leaders-svg {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 4;
}

.leader-casing {
  stroke: rgba(11, 29, 23, 0.86);
  stroke-width: 3.4;
  stroke-linecap: round;
}

.leader-line {
  stroke: #f8f2dd;
  stroke-width: 1.65;
  stroke-linecap: round;
}

.leader-line.peak-high { stroke: #f7c75b; }
.leader-line.peak-low { stroke: #d7ecdf; }
.leader-line.waterfall { stroke: #7fd4ff; }
.leader-line.hut { stroke: #f6b394; }
.leader-line.tower { stroke: #9fe0cf; }
.leader-line.bldg { stroke: #fffdf5; }

.leader-dot {
  fill: #f8f2dd;
  stroke: #0d2520;
  stroke-width: 1.75;
}

.leader-dot.peak-high { fill: #f4b336; stroke: #0d2520; }
.leader-dot.peak-low { fill: #286e58; stroke: #f8f2dd; }
.leader-dot.saddle { fill: #3b7466; stroke: #f8f2dd; }
.leader-dot.waterfall { fill: #2b89c6; stroke: #edf9ff; }
.leader-dot.hut { fill: #d05b34; stroke: #fff5e3; }
.leader-dot.tower { fill: #227868; stroke: #e8f8f0; }
.leader-dot.bldg { fill: #fffef9; stroke: #0d2520; }

/* ==========================================================================
 * 2. Map Labels Layer (Typed Pills, Outlined Towns, Italic Water)
 * ========================================================================== */
#labels-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 6;
}

/* ---- Typed Pill Labels ---- */
.pill-label {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: auto;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px 3px 7px;
  border-radius: 9px;
  font-family: var(--font-ui);
  font-size: 11.5px;
  font-weight: 800;
  line-height: 1.25;
  letter-spacing: 0.005em;
  white-space: nowrap;
  border: 1.5px solid rgba(246, 240, 218, 0.92);
  outline: 1.5px solid rgba(11, 29, 23, 0.88);
  background: linear-gradient(180deg, #215748 0%, #153c32 100%);
  color: #fffdf6;
  box-shadow: var(--shadow-pill);
  will-change: transform;
  transition: filter 0.12s ease;
}

.pill-label:hover {
  filter: brightness(1.07);
  z-index: 24;
}

.pill-label.is-selected {
  outline: 2.5px solid #ffd166;
  box-shadow: 0 0 0 4px rgba(242, 171, 52, 0.25), var(--shadow-pill);
  z-index: 26;
}

.pl-ico {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 13px;
  height: 13px;
  flex-shrink: 0;
}

.pl-svg {
  width: 13px;
  height: 13px;
  display: block;
}

.pl-name {
  display: inline-block;
}

.pl-ele {
  font-size: 10.5px;
  font-weight: 700;
  opacity: 0.82;
  font-variant-numeric: tabular-nums;
  margin-left: 1px;
}

/* Low peaks (< 1000 m): deep spruce green pill with crisp warm light border */
.pill-label.peak-low {
  background: linear-gradient(180deg, #205849 0%, #153d33 100%);
  color: #fbf8ee;
  border-color: rgba(242, 236, 214, 0.86);
}
.pill-label.peak-low .pl-ico {
  color: #b7e2ce;
}

/* High peaks (>= 1000 m): warm alpine honey-amber pill */
.pill-label.peak-high {
  background: linear-gradient(180deg, #f8c44a 0%, #e59a1e 100%);
  color: #192416;
  border-color: rgba(255, 248, 224, 0.95);
  outline-color: rgba(34, 24, 8, 0.9);
}
.pill-label.peak-high .pl-ico {
  color: #2c210b;
}
.pill-label.peak-high .pl-ele {
  color: #3a2b0d;
  opacity: 0.88;
}

/* Saddles: muted moss-slate green pill with light cream rim */
.pill-label.saddle {
  background: linear-gradient(180deg, #2a5b51 0%, #1d433b 100%);
  color: #f4f3ea;
  border-color: rgba(235, 242, 220, 0.82);
}
.pill-label.saddle .pl-ico {
  color: #b8ded2;
}

/* Waterfalls: cerulean alpine blue pill with light sky rim */
.pill-label.waterfall {
  background: linear-gradient(180deg, #2f93d1 0%, #1e6fa8 100%);
  color: #ffffff;
  border-color: rgba(230, 247, 255, 0.95);
  outline-color: rgba(11, 35, 56, 0.9);
}
.pill-label.waterfall .pl-ico {
  color: #dcf4ff;
}

/* Castles, Ruins, Manors, Monasteries, Historic Buildings: crisp porcelain white pills */
.pill-label.bldg {
  background: linear-gradient(180deg, #fffefb 0%, #f3ecdb 100%);
  color: #162922;
  border-color: rgba(255, 255, 255, 0.96);
  outline-color: rgba(14, 37, 31, 0.9);
}
.pill-label.castle .pl-ico { color: #204d40; }
.pill-label.ruins .pl-ico { color: #7a5838; }
.pill-label.manor .pl-ico { color: #8c3f34; }

/* Mountain Huts: alpine terracotta pill with warm cream rim */
.pill-label.hut {
  background: linear-gradient(180deg, #d15d36 0%, #ad4321 100%);
  color: #fffbf2;
  border-color: rgba(255, 242, 220, 0.92);
  outline-color: rgba(54, 18, 9, 0.9);
}
.pill-label.hut .pl-ico {
  color: #fff3de;
}

/* Lookout Towers: crisp emerald-teal pill with pale mint rim */
.pill-label.tower {
  background: linear-gradient(180deg, #217667 0%, #155349 100%);
  color: #fffef9;
  border-color: rgba(226, 248, 238, 0.9);
  outline-color: rgba(10, 35, 30, 0.9);
}
.pill-label.tower .pl-ico {
  color: #bdf0df;
}

/* ---- Outlined City, Town & Village Map Text ---- */
.map-text-label {
  position: absolute;
  top: 0;
  left: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  padding: 2px 4px;
  margin: 0;
  white-space: nowrap;
  font-family: var(--font-ui);
  line-height: 1.1;
  will-change: transform;
}

.map-text-label.settlement {
  pointer-events: auto;
  cursor: pointer;
  color: #ffffff;
  font-weight: 900;
  letter-spacing: 0.01em;
  paint-order: stroke fill;
  -webkit-text-stroke: 4.5px #112a22;
  text-shadow: 0 2px 5px rgba(7, 22, 17, 0.62);
}

.map-text-label.settlement.town {
  font-weight: 800;
  color: #fffef7;
  -webkit-text-stroke: 3.8px #132e25;
}

.map-text-label.settlement.village {
  font-weight: 800;
  color: #f7f4e8;
  -webkit-text-stroke: 3.2px #17342a;
}

.map-text-label.settlement:hover {
  color: #fff2bf;
  z-index: 22;
}

/* ---- Italic Blue Water Labels (Rivers, Lakes, Tarns, Streams) ---- */
.map-text-label.water {
  pointer-events: none;
  font-style: italic;
  font-weight: 800;
  color: #8ce0ff;
  letter-spacing: 0.02em;
  paint-order: stroke fill;
  -webkit-text-stroke: 3.2px #0c2a40;
  text-shadow: 0 1px 4px rgba(6, 22, 36, 0.68);
}

.map-text-label.water-r {
  font-size: 13.5px;
  color: #96e4ff;
  -webkit-text-stroke: 3.5px #0b283d;
}

.map-text-label.water-l {
  font-size: 12px;
  color: #8ee0ff;
}

.map-text-label.water-s {
  font-size: 11px;
  color: #82d7fa;
  -webkit-text-stroke: 2.8px #0d2b40;
}

/* ==========================================================================
 * 3. Top HUD: Command Bar (Left) & Clock/Weather Chips (Right)
 * ========================================================================== */
.hud-top {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  right: max(12px, env(safe-area-inset-right));
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  pointer-events: none;
  z-index: 18;
}

.hud-top-left {
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: auto;
  min-width: 0;
}

/* Unified deep-spruce enamel console housing Menu + Search */
.command-bar {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 6px;
  border-radius: var(--radius-shell);
  background: linear-gradient(180deg, var(--frame-mid) 0%, var(--frame-deep) 100%);
  border: 2px solid var(--frame-dark);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.14), var(--shadow-frame);
}

/* Tactile porcelain-cream enamel icon button */
.enamel-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 36px;
  min-height: 36px;
  padding: 0 9px;
  border-radius: 10px;
  border: 2px solid var(--frame-dark);
  background: linear-gradient(180deg, var(--enamel-top) 0%, var(--enamel-mid) 68%, var(--enamel-bot) 100%);
  color: var(--enamel-ink);
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: var(--shadow-btn);
  transition: transform 0.08s ease, box-shadow 0.08s ease, background 0.12s ease;
}

.enamel-btn:hover {
  background: linear-gradient(180deg, #ffffff 0%, #fcf6e3 70%, #efe2c0 100%);
}

.enamel-btn:active {
  transform: translateY(1.5px);
  box-shadow: var(--shadow-btn-press);
}

.enamel-btn.icon-only {
  width: 36px;
  padding: 0;
}

.enamel-btn.is-active {
  background: linear-gradient(180deg, #fbd068 0%, #eeaa33 100%);
  color: #192416;
}

/* Compact crest badge displaying country brand from config */
.brand-crest {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 6px 0 4px;
  color: var(--frame-text);
  white-space: nowrap;
}

.brand-crest-ico {
  width: 22px;
  height: 22px;
  border-radius: 7px;
  background: linear-gradient(180deg, var(--accent-amber) 0%, var(--accent-amber-deep) 100%);
  color: var(--frame-dark);
  display: grid;
  place-items: center;
  border: 1.5px solid var(--frame-dark);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.5);
  flex-shrink: 0;
}

.brand-crest-ico .ui-ico {
  width: 14px;
  height: 14px;
}

.brand-meta {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}

.brand-title {
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0.01em;
  color: #fffdf5;
}

.brand-sub {
  font-size: 10px;
  font-weight: 700;
  color: var(--frame-muted);
}

/* Search field inside command bar */
.search-box {
  position: relative;
  display: flex;
  align-items: center;
}

.search-field {
  position: relative;
  display: flex;
  align-items: center;
  background: linear-gradient(180deg, #fffefb 0%, #f7f0dc 100%);
  border: 2px solid var(--frame-dark);
  border-radius: 10px;
  box-shadow: inset 0 2px 4px rgba(13, 37, 32, 0.1);
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

.search-field:focus-within {
  border-color: var(--accent-amber);
  box-shadow: 0 0 0 2px rgba(242, 171, 52, 0.32), inset 0 1px 3px rgba(13, 37, 32, 0.08);
}

.search-ico {
  position: absolute;
  left: 9px;
  top: 50%;
  transform: translateY(-50%);
  width: 15px;
  height: 15px;
  color: var(--enamel-muted);
  pointer-events: none;
}

.search-input {
  width: 272px;
  min-height: 34px;
  padding: 6px 28px 6px 30px;
  border: none;
  background: transparent;
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 700;
  color: var(--enamel-ink);
  outline: none;
}

.search-input::placeholder {
  color: #6b7f77;
  font-weight: 600;
}

.search-input::-webkit-search-cancel-button {
  -webkit-appearance: none;
}

.search-clear {
  position: absolute;
  right: 5px;
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 999px;
  background: rgba(22, 46, 39, 0.1);
  color: var(--enamel-ink);
  display: none;
  place-items: center;
  cursor: pointer;
  padding: 0;
}

.search-clear.visible {
  display: grid;
}

.search-clear .ui-ico {
  width: 12px;
  height: 12px;
}

.search-kbd {
  display: inline-grid;
  place-items: center;
  min-width: 24px;
  height: 28px;
  padding: 0 6px;
  border-radius: 7px;
  border: 1.5px solid var(--frame-dark);
  background: linear-gradient(180deg, #faf2da 0%, #e5d4a5 100%);
  color: var(--enamel-ink);
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 900;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8), 0 1.5px 0 var(--frame-dark);
}

.search-results {
  position: absolute;
  top: calc(100% + 9px);
  left: -4px;
  width: 312px;
  max-height: min(320px, 52dvh);
  overflow-y: auto;
  background: linear-gradient(180deg, #fffdf7 0%, #f6efe0 100%);
  border: 2px solid var(--frame-dark);
  border-radius: var(--radius-shell);
  box-shadow: var(--shadow-frame);
  display: none;
  z-index: 35;
  padding: 4px;
}

.search-results.open {
  display: block;
}

.search-item {
  padding: 8px 10px;
  border-radius: 9px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 800;
  color: var(--enamel-ink);
}

.search-item:hover {
  background: rgba(31, 107, 92, 0.14);
}

.search-meta {
  color: var(--enamel-muted);
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

/* ---- Top-Right Clock/Date & Weather Chip ---- */
.hud-top-right {
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: auto;
}

.env-capsule {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 4px;
  border-radius: var(--radius-shell);
  background: linear-gradient(180deg, var(--frame-mid) 0%, var(--frame-deep) 100%);
  border: 2px solid var(--frame-dark);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.15), var(--shadow-frame);
  color: var(--frame-text);
}

.env-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  padding: 4px 10px;
  border: none;
  border-radius: 9px;
  background: transparent;
  color: #fffdf5;
  font-family: var(--font-ui);
  font-size: 13.5px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition: background 0.12s ease;
}

.env-chip:hover {
  background: rgba(255, 255, 255, 0.1);
}

.env-divider {
  width: 1.5px;
  height: 20px;
  border-radius: 2px;
  background: rgba(255, 252, 238, 0.18);
}

.weather-ico {
  width: 19px;
  height: 19px;
  color: var(--accent-amber);
  flex-shrink: 0;
}

.weather-ico.is-night { color: #b9d7ff; }
.weather-ico.is-rain,
.weather-ico.is-snow { color: #90dcff; }
.weather-ico.is-cloud,
.weather-ico.is-mist { color: #d8e7e1; }

.weather-temp {
  font-size: 13.5px;
  font-weight: 900;
  letter-spacing: -0.01em;
}

.clock-time {
  font-size: 14px;
  font-weight: 900;
  letter-spacing: 0.01em;
}

.clock-date {
  font-size: 11px;
  font-weight: 700;
  color: var(--frame-muted);
  padding: 2px 6px;
  border-radius: 6px;
  background: rgba(10, 29, 24, 0.45);
}

/* ==========================================================================
 * 4. Right-Bottom Tool Stack (Compass, Zoom, Layers, Locate, Fullscreen)
 * ========================================================================== */
.tool-stack {
  position: fixed;
  right: max(12px, env(safe-area-inset-right));
  bottom: max(46px, calc(38px + env(safe-area-inset-bottom)));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  z-index: 18;
  pointer-events: auto;
}

.tool-btn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: 2px solid var(--frame-dark);
  background: linear-gradient(180deg, var(--enamel-top) 0%, var(--enamel-mid) 68%, var(--enamel-bot) 100%);
  box-shadow: var(--shadow-btn);
  color: var(--enamel-ink);
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 0;
  transition: transform 0.08s ease, box-shadow 0.08s ease, background 0.12s ease;
}

.tool-btn:hover {
  background: linear-gradient(180deg, #ffffff 0%, #fcf6e3 70%, #efe2c0 100%);
}

.tool-btn:active {
  transform: translateY(1.5px);
  box-shadow: var(--shadow-btn-press);
}

.tool-btn.is-active {
  background: linear-gradient(180deg, #fbd068 0%, #eeaa33 100%);
}

.tool-btn .ui-ico {
  width: 19px;
  height: 19px;
}

/* Paired zoom rocker inside one framed enamel housing */
.zoom-rocker {
  display: flex;
  flex-direction: column;
  width: 40px;
  border-radius: 12px;
  border: 2px solid var(--frame-dark);
  background: linear-gradient(180deg, var(--enamel-top) 0%, var(--enamel-mid) 68%, var(--enamel-bot) 100%);
  box-shadow: var(--shadow-btn);
  overflow: hidden;
}

.zoom-rocker-btn {
  width: 100%;
  height: 34px;
  border: none;
  background: transparent;
  color: var(--enamel-ink);
  display: grid;
  place-items: center;
  cursor: pointer;
  padding: 0;
}

.zoom-rocker-btn + .zoom-rocker-btn {
  border-top: 1.5px solid rgba(13, 37, 32, 0.18);
}

.zoom-rocker-btn:hover {
  background: rgba(255, 255, 255, 0.6);
}

.zoom-rocker-btn:active {
  background: rgba(230, 216, 181, 0.7);
}

.zoom-rocker-btn .ui-ico {
  width: 16px;
  height: 16px;
}

#compass-needle {
  width: 24px;
  height: 24px;
  transition: transform 0.08s linear;
}

/* Subtle scale micro-badge above credits */
.scale-chip {
  font-size: 10.5px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: #fffdf5;
  background: rgba(13, 37, 32, 0.78);
  border: 1.5px solid rgba(255, 250, 232, 0.28);
  border-radius: 8px;
  padding: 2px 7px;
  white-space: nowrap;
  letter-spacing: 0.01em;
}

/* ==========================================================================
 * 5. Bottom HUD: Diary + Share (Left) & Compact Credits Pill (Right)
 * ========================================================================== */
.hud-bottom {
  position: fixed;
  left: max(12px, env(safe-area-inset-left));
  right: max(12px, env(safe-area-inset-right));
  bottom: max(12px, env(safe-area-inset-bottom));
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 10px;
  pointer-events: none;
  z-index: 18;
}

.hud-bottom-left {
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: auto;
}

/* Diary counter badge: deep spruce enamel frame with golden tally */
.diary-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 5px 13px 5px 11px;
  border-radius: 12px;
  border: 2px solid var(--frame-dark);
  background: linear-gradient(180deg, var(--frame-mid) 0%, var(--frame-deep) 100%);
  color: #fffdf5;
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.16), var(--shadow-frame);
  transition: transform 0.08s ease, filter 0.12s ease;
}

.diary-pill:hover {
  filter: brightness(1.08);
}

.diary-pill:active {
  transform: translateY(1.5px);
}

.diary-pill .ui-ico {
  color: var(--accent-amber);
  width: 18px;
  height: 18px;
}

.diary-count {
  font-variant-numeric: tabular-nums;
  display: inline-flex;
  align-items: baseline;
  gap: 3px;
}

.diary-found {
  font-size: 15px;
  font-weight: 900;
  color: #ffd166;
}

.diary-total {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--frame-muted);
}

/* Share button: tactile cream enamel button */
.share-pill {
  min-height: 40px;
  padding: 5px 14px 5px 11px;
  border-radius: 12px;
  font-size: 13.5px;
  font-weight: 800;
}

.share-pill .ui-ico {
  width: 17px;
  height: 17px;
}

/* Compact bottom-right Credits Pill */
.hud-bottom-right {
  display: flex;
  align-items: center;
  gap: 6px;
  pointer-events: auto;
  max-width: 55vw;
}

.credits-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1.5px solid rgba(255, 249, 232, 0.25);
  background: rgba(13, 37, 32, 0.78);
  color: #e6f0ea;
  font-family: var(--font-ui);
  font-size: 10.5px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  box-shadow: 0 2px 8px rgba(8, 22, 18, 0.28);
  transition: background 0.12s ease, border-color 0.12s ease;
}

.credits-pill:hover {
  background: rgba(23, 61, 52, 0.94);
  border-color: rgba(242, 171, 52, 0.65);
  color: #ffffff;
}

.credits-pill .ui-ico {
  width: 13px;
  height: 13px;
  color: var(--accent-amber);
}

#credits-pill-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

/* ==========================================================================
 * 6. Menu & Layers Drawer Panel (#layers-popover)
 * ========================================================================== */
#layers-popover {
  position: fixed;
  inset: auto;
  top: max(66px, calc(58px + env(safe-area-inset-top)));
  left: max(12px, env(safe-area-inset-left));
  margin: 0;
  width: 320px;
  max-width: calc(100vw - 24px);
  max-height: calc(100dvh - 126px);
  overflow: hidden;
  padding: 0;
  border-radius: 16px;
  border: 2px solid var(--frame-dark);
  background: linear-gradient(180deg, #fffdf7 0%, #f5eedb 100%);
  box-shadow: var(--shadow-frame);
  color: var(--enamel-ink);
  font-size: 13px;
  z-index: 30;
}

#layers-popover:is(:popover-open, .is-open) {
  display: flex;
  flex-direction: column;
}

.menu-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  background: linear-gradient(180deg, var(--frame-mid) 0%, var(--frame-deep) 100%);
  color: #fffdf5;
  border-bottom: 2px solid var(--frame-dark);
}

.menu-head-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 900;
}

.menu-close {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 1.5px solid rgba(255, 253, 245, 0.25);
  background: rgba(10, 28, 22, 0.38);
  color: #fffdf5;
  display: grid;
  place-items: center;
  cursor: pointer;
  padding: 0;
}

.menu-close:hover {
  background: rgba(255, 253, 245, 0.16);
}

.menu-close .ui-ico {
  width: 14px;
  height: 14px;
}

.menu-tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  padding: 7px 9px;
  background: rgba(22, 46, 39, 0.07);
  border-bottom: 1.5px solid var(--enamel-line);
}

.menu-tab {
  border: 1.5px solid transparent;
  border-radius: 9px;
  background: transparent;
  color: var(--enamel-muted);
  font-family: var(--font-ui);
  font-size: 11.5px;
  font-weight: 800;
  padding: 6px 4px;
  cursor: pointer;
  text-align: center;
  transition: background 0.1s ease, color 0.1s ease;
}

.menu-tab:hover {
  background: rgba(255, 255, 255, 0.7);
  color: var(--enamel-ink);
}

.menu-tab.active {
  background: linear-gradient(180deg, var(--frame-mid) 0%, var(--frame-deep) 100%);
  color: #fffdf5;
  border-color: var(--frame-dark);
  box-shadow: 0 1.5px 0 var(--frame-dark);
}

.menu-body {
  padding: 12px 13px 14px;
  overflow-y: auto;
  flex: 1 1 auto;
}

.menu-pane[hidden] {
  display: none;
}

.pop-section {
  margin-bottom: 14px;
}

.pop-section:last-child {
  margin-bottom: 0;
}

.pop-section[hidden] {
  display: none;
}

.pop-heading {
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--enamel-muted);
  margin: 0 0 8px 0;
}

/* Tactile toggle rows */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 8px;
  border-radius: 9px;
  cursor: pointer;
  font-weight: 700;
  font-size: 13px;
}

.toggle-row:hover {
  background: rgba(23, 61, 52, 0.07);
}

.toggle-row input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 36px;
  height: 21px;
  border-radius: 999px;
  border: 1.5px solid var(--frame-dark);
  background: #d9cfb6;
  position: relative;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.14s ease;
}

.toggle-row input[type="checkbox"]::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fffef9;
  border: 1.5px solid var(--frame-dark);
  transition: transform 0.14s ease;
}

.toggle-row input[type="checkbox"]:checked {
  background: #236d59;
}

.toggle-row input[type="checkbox"]:checked::after {
  transform: translateX(15px);
}

.seg-row {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}

.seg-btn {
  flex: 1;
  min-width: 52px;
  padding: 6px 8px;
  border-radius: 9px;
  border: 1.5px solid var(--frame-dark);
  background: linear-gradient(180deg, var(--enamel-top) 0%, var(--enamel-mid) 100%);
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
  color: var(--enamel-ink);
  box-shadow: 0 1.5px 0 var(--frame-dark);
}

.seg-btn:hover {
  background: #ffffff;
}

.seg-btn.active {
  background: linear-gradient(180deg, var(--frame-mid) 0%, var(--frame-deep) 100%);
  color: #fffdf5;
}

.trail-legend {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 10px;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--enamel-muted);
}

.trail-swatch {
  display: inline-block;
  width: 14px;
  height: 5px;
  border-radius: 3px;
  margin-right: 6px;
  vertical-align: middle;
  border: 1px solid rgba(13, 37, 32, 0.35);
}

/* Preset camera view chips inside Menu -> Views tab */
.presets-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}

.preset-chip {
  background: linear-gradient(180deg, var(--enamel-top) 0%, var(--enamel-mid) 75%, var(--enamel-bot) 100%);
  border: 1.5px solid var(--frame-dark);
  box-shadow: 0 2px 0 var(--frame-dark);
  border-radius: 10px;
  padding: 7px 9px;
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 800;
  color: var(--enamel-ink);
  cursor: pointer;
  text-align: left;
  line-height: 1.25;
}

.preset-chip:hover {
  background: linear-gradient(180deg, #ffffff 0%, #fcf4db 100%);
}

.preset-chip:active {
  transform: translateY(1px);
  box-shadow: 0 1px 0 var(--frame-dark);
}

/* Diagnostics readout inside Menu */
.status-pill {
  background: rgba(13, 37, 32, 0.06);
  border: 1px solid var(--enamel-line);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 11px;
  font-weight: 700;
  color: var(--enamel-muted);
  line-height: 1.45;
  font-variant-numeric: tabular-nums;
  overflow-wrap: break-word;
}

/* About / Credits list */
.about-lead {
  margin: 0 0 10px 0;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--enamel-muted);
  line-height: 1.45;
}

.credits-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.credits-list li {
  padding: 6px 9px;
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid var(--enamel-line);
  font-size: 11.5px;
  font-weight: 700;
  color: var(--enamel-ink);
  line-height: 1.35;
}

/* ==========================================================================
 * 7. Place Info Card (Dark Spruce Enamel Card, Centered Bottom)
 * ========================================================================== */
.popup-card {
  position: fixed;
  bottom: max(16px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  width: min(352px, calc(100vw - 24px));
  background: linear-gradient(180deg, var(--frame-mid) 0%, var(--frame-deep) 100%);
  border: 2px solid var(--frame-dark);
  border-radius: 16px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.16), var(--shadow-frame);
  color: #fffdf5;
  padding: 13px 15px 14px;
  z-index: 25;
  display: none;
}

.popup-card.open {
  display: block;
}

.popup-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 5px;
}

.popup-title {
  font-size: 16.5px;
  font-weight: 900;
  line-height: 1.2;
  margin: 0;
  color: #fffef9;
}

.popup-close {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 1.5px solid rgba(255, 253, 245, 0.22);
  background: rgba(10, 28, 22, 0.42);
  color: #fffdf5;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  padding: 0;
}

.popup-close:hover {
  background: rgba(255, 253, 245, 0.18);
}

.popup-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 10.5px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 2px 9px;
  border-radius: 999px;
  background: rgba(242, 171, 52, 0.22);
  border: 1px solid rgba(242, 171, 52, 0.55);
  color: #ffd578;
  margin-bottom: 7px;
}

.popup-meta {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--frame-muted);
  margin: 0 0 11px 0;
  line-height: 1.45;
  font-variant-numeric: tabular-nums;
}

.popup-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.popup-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 13px;
  border-radius: 10px;
  border: 2px solid var(--frame-dark);
  background: linear-gradient(180deg, var(--enamel-top) 0%, var(--enamel-mid) 72%, var(--enamel-bot) 100%);
  color: var(--enamel-ink);
  font-family: var(--font-ui);
  font-size: 12.5px;
  font-weight: 800;
  cursor: pointer;
  text-decoration: none;
  box-shadow: var(--shadow-btn);
}

.popup-btn .ui-ico {
  width: 14px;
  height: 14px;
}

.popup-btn:hover {
  background: linear-gradient(180deg, #ffffff 0%, #fcf4dd 100%);
}

.popup-btn.secondary {
  background: rgba(12, 34, 28, 0.52);
  color: #ffd578;
  border: 1.5px solid rgba(242, 171, 52, 0.45);
  box-shadow: none;
}

.popup-btn.secondary:hover {
  background: rgba(242, 171, 52, 0.16);
  color: #ffe4a0;
}

/* ==========================================================================
 * 8. Toast Notification & Loading Banner
 * ========================================================================== */
.ui-toast {
  position: fixed;
  top: max(68px, calc(60px + env(safe-area-inset-top)));
  left: 50%;
  transform: translate(-50%, -8px);
  background: linear-gradient(180deg, var(--frame-mid) 0%, var(--frame-deep) 100%);
  color: #fffdf5;
  border: 2px solid var(--frame-dark);
  border-radius: 12px;
  padding: 8px 15px;
  font-size: 12.5px;
  font-weight: 800;
  box-shadow: var(--shadow-frame);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
  z-index: 45;
  max-width: calc(100vw - 32px);
  text-align: center;
}

.ui-toast.visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

#loading-banner {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: linear-gradient(180deg, var(--enamel-top) 0%, var(--enamel-mid) 100%);
  border: 2px solid var(--frame-dark);
  box-shadow: var(--shadow-frame);
  border-radius: var(--radius-shell);
  padding: 14px 22px;
  font-size: 14px;
  font-weight: 900;
  color: var(--enamel-ink);
  z-index: 50;
}

/* ==========================================================================
 * 9. Responsive Mobile Layout (down to 390 px and 320 px phone widths)
 * ========================================================================== */
@media (max-width: 820px) {
  .brand-crest {
    display: none;
  }
  .search-input {
    width: 196px;
  }
  .search-kbd {
    display: none;
  }
}

@media (max-width: 560px) {
  .hud-top {
    top: max(8px, env(safe-area-inset-top));
    left: max(8px, env(safe-area-inset-left));
    right: max(8px, env(safe-area-inset-right));
    gap: 6px;
  }

  .hud-top-left {
    flex: 1 1 auto;
    min-width: 0;
  }

  .command-bar {
    width: 100%;
    padding: 4px 5px;
    gap: 5px;
    border-radius: 12px;
  }

  .enamel-btn {
    min-width: 34px;
    min-height: 34px;
  }

  .enamel-btn.icon-only {
    width: 34px;
  }

  .search-box {
    flex: 1 1 auto;
    min-width: 0;
  }

  .search-field {
    width: 100%;
  }

  .search-input {
    width: 100%;
    min-width: 0;
    font-size: 12.5px;
    padding: 5px 24px 5px 26px;
  }

  .search-ico {
    left: 7px;
    width: 14px;
    height: 14px;
  }

  .search-results {
    width: calc(100vw - 16px);
    left: -46px;
  }

  .env-capsule {
    padding: 3px;
    border-radius: 12px;
    flex-shrink: 0;
  }

  .env-chip {
    min-height: 32px;
    padding: 3px 6px;
    gap: 4px;
    font-size: 12px;
  }

  .weather-temp {
    font-size: 12px;
  }

  .clock-time {
    font-size: 12.5px;
  }

  .clock-date {
    display: none;
  }

  .tool-stack {
    right: max(8px, env(safe-area-inset-right));
    bottom: max(46px, calc(40px + env(safe-area-inset-bottom)));
    gap: 6px;
  }

  .tool-btn {
    width: 38px;
    height: 38px;
    border-radius: 11px;
  }

  .zoom-rocker {
    width: 38px;
    border-radius: 11px;
  }

  .zoom-rocker-btn {
    height: 31px;
  }

  .scale-chip {
    display: none;
  }

  .hud-bottom {
    left: max(8px, env(safe-area-inset-left));
    right: max(8px, env(safe-area-inset-right));
    bottom: max(8px, env(safe-area-inset-bottom));
    gap: 6px;
  }

  .diary-pill {
    min-height: 36px;
    padding: 4px 10px;
    gap: 6px;
    border-radius: 11px;
  }

  .diary-found {
    font-size: 13.5px;
  }

  .diary-total {
    font-size: 10.5px;
  }

  .share-pill {
    min-height: 36px;
    padding: 4px 10px;
    font-size: 12.5px;
    border-radius: 11px;
  }

  .hud-bottom-right {
    max-width: 44vw;
  }

  .credits-pill {
    padding: 3px 8px;
    font-size: 9.5px;
  }

  #layers-popover {
    top: max(58px, calc(52px + env(safe-area-inset-top)));
    left: 8px;
    width: calc(100vw - 16px);
    max-height: calc(100dvh - 116px);
  }

  .popup-card {
    bottom: max(56px, calc(50px + env(safe-area-inset-bottom)));
    width: calc(100vw - 16px);
    padding: 11px 13px 12px;
  }

  .pill-label {
    font-size: 10.5px;
    padding: 2px 7px 2px 6px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .enamel-btn,
  .tool-btn,
  .diary-pill,
  .ui-toast,
  #compass-needle {
    transition: none;
  }
}
