:root {
  --bg: #0f1410;
  --panel: #161c17;
  --card: #1c241e;
  --border: #2a352c;
  --text: #e6ede6;
  --muted: #9aab9c;
  --accent: #7cb87c;
  --accent-dim: #4a7a4a;
  --warn: #c9a227;
  --smell: #6b9bd1;
  --hear: #d4a017;
  --you: #e85d4c;
  --radius: 10px;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  overflow: hidden;
}

/* Hosted bar (injected by build.py) is a sibling above #app. Flex so the
   map fills the remaining viewport instead of 100dvh + bar (which shoved
   the pin under the sheet). Without a bar, #app still fills the viewport. */
body {
  display: flex;
  flex-direction: column;
}

.hosted-bar {
  flex-shrink: 0;
}

#app {
  display: grid;
  grid-template-rows: auto 1fr;
  grid-template-columns: minmax(280px, 340px) 1fr;
  /* 0% basis = definite height so #map's height:100% and Leaflet
     invalidateSize see the remaining viewport, not a cyclic 0. */
  flex: 1 1 0%;
  min-height: 0;
  width: 100%;
}

.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  z-index: 1000;
}

.brand h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 650;
  letter-spacing: 0.01em;
}

.tagline {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.78rem;
}

.badge {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 999px;
  background: rgba(201, 162, 39, 0.18);
  color: var(--warn);
  font-weight: 600;
  font-size: 0.72rem;
}

.assumed {
  color: var(--warn);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.live {
  color: var(--accent);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  display: inline-block;
  padding: 1px 6px;
  border-radius: 999px;
  background: rgba(124, 184, 124, 0.16);
}

.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 12px;
  font: inherit;
  cursor: pointer;
}

.btn.ghost:hover,
.btn.ghost:focus-visible {
  border-color: var(--accent-dim);
  outline: none;
}

.panel {
  overflow-y: auto;
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 500;
  -webkit-overflow-scrolling: touch;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  box-shadow: var(--shadow);
}

.card h2 {
  margin: 0 0 8px;
  font-size: 0.92rem;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.hint {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 0.8rem;
}

.hint.tight {
  margin-top: -6px;
}

.coords {
  margin: 0;
  font-family: var(--mono);
  font-size: 0.82rem;
  color: var(--accent);
}

.formula {
  margin: 0 0 8px;
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--muted);
  background: rgba(0, 0, 0, 0.25);
  padding: 6px 8px;
  border-radius: 6px;
}

.field {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 10px;
  align-items: center;
  margin-bottom: 10px;
}

.field > span {
  grid-column: 1 / -1;
  font-size: 0.8rem;
  color: var(--muted);
}

.field input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.field select {
  grid-column: 1 / -1;
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px;
  font: inherit;
}

.field output {
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--text);
  min-width: 4.5rem;
  text-align: right;
}

.check {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-top: 6px;
  font-size: 0.82rem;
  color: var(--muted);
}

.check input {
  margin-top: 3px;
  accent-color: var(--accent);
}

.result {
  margin: 4px 0 8px;
  font-weight: 600;
  color: var(--hear);
  font-family: var(--mono);
  font-size: 0.85rem;
}

#smell-summary {
  color: var(--smell);
}

.weather-status {
  margin: 0 0 8px;
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.4;
}

.weather-status.live-note {
  color: var(--accent);
}

.weather-status.fail-note {
  color: var(--warn);
}

.weather-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  margin: 0 0 12px;
}

.btn.compact {
  padding: 6px 10px;
  font-size: 0.78rem;
}

.winds-link {
  color: var(--smell);
  font-size: 0.78rem;
  font-weight: 600;
}

.winds-link[hidden] {
  display: none;
}

.overlay-guide {
  margin: 0;
}

.overlay-guide img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #1a1f1a;
}

.overlay-guide figcaption {
  margin-top: 8px;
}

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

.callouts li {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 0.78rem;
  color: var(--muted);
}

.callouts strong {
  color: var(--text);
}

.chip-guide {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.35;
}

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

.legend li {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 0.8rem;
  color: var(--muted);
}

.swatch {
  width: 18px;
  height: 18px;
  border-radius: 4px;
  flex-shrink: 0;
  margin-top: 1px;
  border: 2px solid transparent;
}

.swatch.hear {
  background: rgba(212, 160, 23, 0.25);
  border-color: var(--hear);
}

.swatch.smell {
  background: rgba(107, 155, 209, 0.3);
  border-color: var(--smell);
}

.swatch.lore {
  background: transparent;
  border: 2px dashed rgba(107, 155, 209, 0.7);
}

.swatch.you {
  background: var(--you);
  border-radius: 50%;
}

#map {
  min-height: 0;
  height: 100%;
  width: 100%;
  z-index: 1;
  background: #1a1f1a;
}

.place-chip {
  position: absolute;
  left: calc(minmax(280px, 340px) + 12px);
  /* fallback positioned via JS-friendly CSS */
  bottom: 18px;
  left: 352px;
  right: 12px;
  max-width: 520px;
  z-index: 800;
  pointer-events: none;
  background: rgba(22, 28, 23, 0.92);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  box-shadow: var(--shadow);
  font-size: 0.82rem;
  backdrop-filter: blur(6px);
}

.place-chip strong {
  color: var(--accent);
}

.chip-title {
  display: block;
}

.chip-detail {
  margin: 4px 0 0;
}

.chip-coords {
  font-family: var(--mono);
}

.drawer {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 24px 12px;
  overflow-y: auto;
}

.drawer[hidden] {
  display: none;
}

.drawer-inner {
  width: min(640px, 100%);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 18px 24px;
  box-shadow: var(--shadow);
  position: relative;
}

.drawer-inner h2 {
  margin: 0 40px 12px 0;
  font-size: 1.15rem;
}

.drawer-inner h3 {
  margin: 16px 0 8px;
  font-size: 0.95rem;
  color: var(--accent);
}

.drawer-inner ul {
  margin: 0;
  padding-left: 1.2rem;
  color: var(--muted);
}

.drawer-inner li {
  margin-bottom: 6px;
}

.drawer-inner .close {
  position: absolute;
  top: 12px;
  right: 12px;
}

.cite {
  margin-top: 16px;
  font-size: 0.8rem;
  color: var(--muted);
}

.cite code {
  font-family: var(--mono);
  color: var(--text);
}

/* Leaflet dark tweaks */
.leaflet-control-attribution {
  background: rgba(15, 20, 16, 0.8) !important;
  color: var(--muted) !important;
  font-size: 10px !important;
}

.leaflet-control-attribution a {
  color: var(--accent) !important;
}

.leaflet-control-zoom a {
  background: var(--card) !important;
  color: var(--text) !important;
  border-color: var(--border) !important;
}

.you-icon {
  background: var(--you);
  border: 2px solid #fff;
  border-radius: 50%;
  width: 16px !important;
  height: 16px !important;
  margin-left: -8px !important;
  margin-top: -8px !important;
  box-shadow: 0 0 0 4px rgba(232, 93, 76, 0.35);
}


/* Place-yourself UI */
.coords.muted { color: var(--muted); margin-top: 4px; }
.place-tabs {
  display: flex;
  gap: 6px;
  margin: 10px 0 8px;
  flex-wrap: wrap;
}
.place-tab {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--muted);
  border-radius: 999px;
  padding: 6px 10px;
  font: inherit;
  font-size: 0.78rem;
  cursor: pointer;
}
.place-tab.active {
  color: var(--text);
  border-color: var(--accent-dim);
  background: rgba(124, 184, 124, 0.12);
}
.place-pane.hidden, .place-pane[hidden] { display: none !important; }
.field.stack {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 4px;
  margin-bottom: 8px;
}
.field.stack input[type="text"] {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 10px;
  font: inherit;
  font-size: 16px; /* iOS zoom avoid */
}
.latlon-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.btn.primary {
  width: 100%;
  margin-top: 4px;
  background: rgba(124, 184, 124, 0.18);
  border-color: var(--accent-dim);
  color: var(--text);
  font-weight: 600;
}
.place-status { min-height: 1.2em; margin-top: 8px; }
.sheet-handle { display: none; }
.panel-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

@media (max-width: 820px) {
  /* Flex column (not grid) so #map gets a definite leftover height.
     Grid 1fr + height:100% was collapsing the Leaflet pane to 0. */
  #app {
    display: flex;
    flex-direction: column;
    grid-template-columns: none;
    grid-template-rows: none;
    position: relative;
  }

  .topbar {
    grid-column: auto;
    flex-shrink: 0;
  }

  /* In-flow bottom sheet so the map is the unoccluded leftover.
     Collapsed = handle only. Expanded = scrollable controls. */
  .panel {
    position: relative;
    flex: 0 0 auto;
    z-index: 1200;
    max-height: none;
    border-right: none;
    border-top: 1px solid var(--border);
    border-radius: 16px 16px 0 0;
    padding: 0 10px 0;
    box-shadow: 0 -12px 32px rgba(0,0,0,0.45);
    background: var(--panel);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-height: 0;
    width: 100%;
  }

  .panel.sheet-open {
    max-height: min(72dvh, 640px);
    padding: 0 10px 12px;
  }

  .sheet-handle {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    width: 100%;
    appearance: none;
    border: 0;
    background: transparent;
    color: var(--text);
    padding: 8px 8px max(8px, env(safe-area-inset-bottom));
    cursor: pointer;
    flex-shrink: 0;
  }
  .panel.sheet-open .sheet-handle {
    padding: 10px 8px 8px;
  }
  .sheet-grip {
    width: 40px;
    height: 4px;
    border-radius: 999px;
    background: var(--border);
    margin-bottom: 4px;
  }
  .sheet-label { font-weight: 650; font-size: 0.9rem; }
  .sheet-hint { color: var(--muted); font-size: 0.72rem; }

  .panel-body {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: max(8px, env(safe-area-inset-bottom));
    min-height: 0;
  }

  /* Collapsed: handle only — no You/MGRS peek, no guide, no knobs */
  .panel:not(.sheet-open) .panel-body {
    display: none;
  }

  #map {
    flex: 1 1 0%;
    min-height: 0;
    height: auto;
    width: 100%;
  }

  .topbar { order: 0; }
  .place-chip { order: 1; }
  #map { order: 2; }
  .panel { order: 3; }

  /* Compact in-flow strip under the title — does not cover the map */
  .place-chip {
    position: relative;
    left: auto;
    right: auto;
    top: auto;
    bottom: auto;
    max-width: none;
    margin: 0;
    border-radius: 0;
    border-left: none;
    border-right: none;
    font-size: 0.72rem;
    padding: 6px 10px;
    flex: 0 0 auto;
    pointer-events: none;
  }
  .place-chip .chip-detail,
  .place-chip .chip-coords {
    display: none;
  }
  .chip-guide {
    margin-top: 4px;
  }
}

@media (orientation: landscape) and (max-height: 500px) {
  .panel.sheet-open {
    max-height: 85dvh;
  }
  body.sheet-open .place-chip {
    display: none; /* keep map clear in landscape when sheet open */
  }
}
