:root {
  color-scheme: light;
  --ink: #15211d;
  --muted: #5b665f;
  --paper: #f5f8ef;
  --panel: #ffffff;
  --bush: #2f6b48;
  --deep: #143d33;
  --creek: #1485a3;
  --trail: #ff3f7c;
  --trail-glow: #f5a03b;
  --warn: #b3261e;
  --line: rgba(21, 33, 29, 0.14);
  --shadow: 0 18px 42px rgba(16, 34, 27, 0.22);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  background: var(--paper);
  color: var(--ink);
}

body {
  overflow-x: hidden;
}

button {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

button:focus-visible,
a:focus-visible {
  outline: 3px solid #ffbf47;
  outline-offset: 2px;
}

.app-shell {
  min-height: 100svh;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: fixed;
  z-index: 700;
  top: env(safe-area-inset-top);
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  pointer-events: none;
}

.brand,
.status-pill {
  pointer-events: auto;
  box-shadow: var(--shadow);
}

.brand {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 10px 7px 7px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.94);
  color: var(--ink);
  text-decoration: none;
}

.brand img {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  border-radius: 9px;
}

.brand span {
  min-width: 0;
  display: grid;
  gap: 1px;
}

.brand strong {
  max-width: 46vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.96rem;
}

.brand small {
  color: var(--muted);
  font-size: 0.76rem;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 0 12px;
  background: #17251f;
  color: #fffdf5;
  white-space: nowrap;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: #b7beb8;
}

.dot-ready {
  background: #65d46e;
}

.dot-wait {
  background: #f5a03b;
}

.dot-bad {
  background: #ff6b5f;
}

main {
  min-height: 100svh;
  display: flex;
  flex-direction: column;
}

.map-stage {
  position: relative;
  min-height: 58svh;
  flex: 1 1 58svh;
  background: #dbe7ca;
}

#map {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.3), rgba(87, 120, 82, 0.1)),
    #dce8cb;
}

.leaflet-container {
  font: inherit;
  background: transparent;
}

.leaflet-control-attribution {
  max-width: 72vw;
  border-radius: 8px 0 0 0;
  font-size: 0.68rem;
}

.leaflet-bottom.leaflet-left .leaflet-control,
.leaflet-bottom.leaflet-right .leaflet-control {
  margin-bottom: 72px;
}

.warning-banner {
  position: absolute;
  z-index: 650;
  left: 50%;
  bottom: 102px;
  transform: translateX(-50%);
  padding: 11px 16px;
  border-radius: 8px;
  background: var(--warn);
  color: #fff;
  box-shadow: var(--shadow);
  font-weight: 900;
  letter-spacing: 0;
}

.map-tools {
  position: absolute;
  z-index: 650;
  left: 12px;
  right: 12px;
  bottom: 14px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 10px;
}

.primary-action,
.secondary-action {
  padding: 0 14px;
  box-shadow: 0 10px 26px rgba(16, 34, 27, 0.18);
}

.primary-action {
  background: var(--deep);
  color: #fffdf5;
}

.secondary-action {
  border: 2px solid rgba(20, 61, 51, 0.2);
  background: rgba(255, 255, 255, 0.95);
  color: var(--deep);
}

.full {
  width: 100%;
  margin-top: 14px;
}

.dashboard {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1px;
  background: var(--line);
  border-top: 1px solid var(--line);
}

.metric {
  min-width: 0;
  padding: 12px 13px;
  background: var(--panel);
}

.metric-label {
  display: block;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
  text-transform: uppercase;
}

.metric strong {
  display: block;
  min-height: 1.5rem;
  margin-top: 3px;
  overflow-wrap: anywhere;
  font-size: clamp(1rem, 4.4vw, 1.3rem);
  letter-spacing: 0;
}

.tabbar {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 1px;
  background: var(--line);
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.tabbar button {
  min-width: 0;
  border-radius: 0;
  background: #fbfcf7;
  color: var(--deep);
  font-size: 0.86rem;
}

.gps-panel {
  background: var(--line);
}

.gps-toggle {
  width: 100%;
  min-height: 54px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 13px;
  border-radius: 0;
  background: var(--panel);
  color: var(--deep);
  text-align: left;
}

.gps-toggle span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
}

.gps-toggle strong {
  min-width: 0;
  overflow: hidden;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.95rem;
}

.gps-toggle::after {
  content: "+";
  flex: 0 0 auto;
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: #eff3e7;
  color: var(--deep);
  font-weight: 900;
}

.gps-toggle[aria-expanded="true"]::after {
  content: "-";
}

.gps-details {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1px;
}

.gps-details > div,
.inline-message {
  margin: 0;
  padding: 10px 13px;
  background: var(--panel);
}

.gps-details span {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.gps-details strong {
  display: block;
  margin-top: 2px;
  overflow-wrap: anywhere;
  font-size: 0.95rem;
}

.inline-message {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 0.9rem;
}

.fallback {
  padding: 16px;
  background: #fff7dc;
  border-top: 1px solid rgba(120, 86, 12, 0.2);
}

.fallback h2 {
  margin: 0 0 8px;
  font-size: 1rem;
}

.fallback p {
  margin: 0 0 10px;
}

.panel-overlay {
  position: fixed;
  z-index: 800;
  inset: 0;
  background: rgba(13, 24, 20, 0.36);
}

.panel {
  position: fixed;
  z-index: 810;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: min(78svh, 680px);
  display: flex;
  flex-direction: column;
  border-radius: 12px 12px 0 0;
  background: var(--panel);
  box-shadow: 0 -22px 46px rgba(12, 22, 18, 0.28);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 14px 12px;
  border-bottom: 1px solid var(--line);
}

.panel h2 {
  margin: 0;
  font-size: 1.05rem;
}

.panel-head button {
  min-height: 40px;
  padding: 0 12px;
  background: #eff3e7;
  color: var(--deep);
}

.panel-body {
  overflow: auto;
  padding: 14px;
  -webkit-overflow-scrolling: touch;
}

.notes-list,
.fallback ol {
  margin: 0;
  padding: 0;
  list-style: none;
}

.notes-list li,
.fallback li {
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.notes-list li:first-child,
.fallback li:first-child {
  padding-top: 0;
}

.notes-list strong,
.fallback strong {
  display: block;
  margin-bottom: 4px;
}

.notes-list span {
  display: inline-flex;
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 800;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.status-grid div {
  min-height: 72px;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcf7;
}

.status-grid .wide {
  grid-column: 1 / -1;
}

.status-grid span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.status-grid strong {
  display: block;
  margin-top: 8px;
  overflow-wrap: anywhere;
  font-size: 1rem;
}

.panel-note,
.install-copy p,
.safety-list p {
  color: var(--muted);
  line-height: 1.45;
}

.safety-list p,
.install-copy p {
  margin: 0 0 12px;
}

.legend-list p {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 12px;
}

.legend-list span {
  flex: 0 0 auto;
}

.legend-route,
.legend-creek,
.legend-road {
  width: 36px;
  height: 8px;
  border-radius: 999px;
}

.legend-route {
  background: var(--trail);
  box-shadow: 0 0 0 4px rgba(245, 160, 59, 0.32);
}

.legend-creek {
  background: var(--creek);
}

.legend-road {
  background: #e4bc77;
}

.legend-note,
.legend-position {
  width: 18px;
  height: 18px;
  border-radius: 999px;
}

.legend-note {
  background: #fff3aa;
  border: 3px solid var(--deep);
}

.legend-position {
  background: #1a73e8;
  border: 4px solid #fff;
  box-shadow: 0 0 0 2px #1a73e8;
}

.location-dot {
  width: 24px !important;
  height: 24px !important;
  margin-left: -12px !important;
  margin-top: -12px !important;
  border: 4px solid #fff;
  border-radius: 999px;
  background: #1a73e8;
  box-shadow:
    0 0 0 3px rgba(26, 115, 232, 0.35),
    0 8px 18px rgba(0, 0, 0, 0.3);
}

.note-marker {
  width: 26px !important;
  height: 26px !important;
  margin-left: -13px !important;
  margin-top: -13px !important;
  display: grid;
  place-items: center;
  border: 3px solid var(--deep);
  border-radius: 999px;
  background: #fff3aa;
  color: var(--deep);
  box-shadow: 0 8px 20px rgba(16, 34, 27, 0.25);
  font-size: 0.76rem;
  font-weight: 900;
}

.note-marker.warning {
  background: #ffd0c8;
  border-color: var(--warn);
  color: var(--warn);
}

.note-marker.start,
.note-marker.finish {
  background: #d9f7e3;
}

@media (min-width: 760px) {
  main {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 380px;
    grid-template-rows: 1fr auto auto;
  }

  .map-stage {
    grid-row: 1 / 4;
    min-height: 100svh;
  }

  .dashboard,
  .gps-panel,
  .tabbar {
    grid-column: 2;
  }

  .dashboard {
    grid-template-columns: 1fr;
  }

  .gps-panel {
    display: block;
  }

  .gps-details {
    grid-template-columns: 1fr;
  }

  .tabbar {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .panel {
    left: auto;
    top: env(safe-area-inset-top);
    width: min(430px, calc(100vw - 24px));
    max-height: 100svh;
    border-radius: 0;
  }
}

@media (max-width: 390px) {
  .topbar {
    align-items: stretch;
  }

  .brand {
    flex: 1 1 auto;
  }

  .brand small {
    display: none;
  }

  .status-pill {
    padding-inline: 9px;
    font-size: 0.82rem;
  }

  .map-tools {
    grid-template-columns: 1fr;
  }

  .leaflet-bottom.leaflet-left .leaflet-control,
  .leaflet-bottom.leaflet-right .leaflet-control {
    margin-bottom: 126px;
  }

  .warning-banner {
    bottom: 154px;
  }
}
