/* One high-contrast light theme, because this is read outdoors in full sun. */
:root {
  color-scheme: light;
  --ink: #16241d;
  --muted: #4d5c54;
  --paper: #f7f4ec;
  --card: #ffffff;
  --line: #d5d2c5;
  --green: #173f30;
  --green-soft: #e3eee7;
  --marsh: #b8560f;
  --marsh-soft: #fbead9;
  --gold: #c98a00;
  --danger: #a32317;
  --gps: #1565d8;
  --serif: "Iowan Old Style", "Palatino", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --nav-h: 62px;
  --top: env(safe-area-inset-top, 0px);
  --bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; overflow: hidden; overscroll-behavior: none; }
body {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--green);
  color: var(--ink);
  font: 17px/1.45 var(--sans);
  -webkit-text-size-adjust: 100%;
}
[hidden] { display: none !important; }
h1, h2, h3 { font-family: var(--serif); line-height: 1.2; margin: 0; }
h1 { font-size: 30px; }
h2 { font-size: 23px; }
h3 { font-size: 19px; }
p { margin: 0; }
svg { fill: currentColor; }
a { color: var(--green); }

#views { position: relative; flex: 1; min-height: 0; background: var(--paper); }
.view { position: absolute; inset: 0; }
.page {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: calc(var(--top) + 18px) 16px 28px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.page > * { flex-shrink: 0; }
.page-head p { color: var(--muted); margin-top: 4px; }

#tabs {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  background: var(--green);
  padding-bottom: var(--bottom);
}
#tabs button {
  height: var(--nav-h);
  background: none;
  border: 0;
  color: #c9dbd0;
  font: 600 12px var(--sans);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 0;
}
#tabs svg { width: 25px; height: 25px; }
#tabs button[aria-current] { color: #fff; box-shadow: inset 0 3px 0 #f0b64a; }

/* Controls */
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 50px;
  padding: 10px 16px;
  border: 2px solid var(--green);
  border-radius: 12px;
  background: var(--card);
  color: var(--green);
  font: 600 17px var(--sans);
  text-align: center;
  text-decoration: none;
}
.btn.primary { background: var(--green); color: #fff; }
.btn.accent { background: var(--marsh); border-color: var(--marsh); color: #fff; }
.btn.danger { border-color: var(--danger); color: var(--danger); }
.btn:disabled { opacity: .5; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stack { display: flex; flex-direction: column; gap: 10px; }

label.field { display: flex; flex-direction: column; gap: 5px; font-weight: 600; font-size: 15px; }
input[type=text], input[type=url], input[type=password], textarea, select {
  width: 100%;
  min-height: 48px;
  padding: 11px 12px;
  border: 1.5px solid #8b968f;
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  font: 400 17px var(--sans);
  min-width: 0;
  max-width: 100%;
}
textarea { min-height: 120px; resize: vertical; }
.switch {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 48px;
  font-weight: 600;
}
.switch input { width: 26px; height: 26px; accent-color: var(--green); flex-shrink: 0; }
.hint { color: var(--muted); font-size: 15px; font-weight: 400; }
.status-ok { color: #17663e; font-weight: 600; font-size: 15px; }
.status-bad { color: var(--danger); font-weight: 600; font-size: 15px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.notice { background: var(--marsh-soft); border: 1px solid #e8c49d; border-radius: 12px; padding: 12px 14px; font-size: 15px; }

.segments { display: grid; grid-template-columns: 1fr 1fr; background: #e7e3d6; border-radius: 12px; padding: 4px; }
.segments button {
  min-height: 44px;
  border: 0;
  border-radius: 9px;
  background: none;
  color: var(--ink);
  font: 600 16px var(--sans);
}
.segments button[aria-pressed=true] { background: var(--green); color: #fff; }

/* Map */
.map-view { display: flex; flex-direction: column; }
#map { flex: 1; min-height: 0; background: #ecead9; font: inherit; }
.leaflet-control-attribution { font-size: 11px; }
.chip {
  position: absolute;
  z-index: 500;
  top: calc(var(--top) + 10px);
  left: 12px;
  right: 72px;
  width: fit-content;
  padding: 7px 12px;
  border-radius: 20px;
  background: rgba(255, 255, 255, .96);
  box-shadow: 0 1px 5px rgba(0, 0, 0, .3);
  font-size: 14px;
  font-weight: 600;
}
.chip::before {
  content: "";
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 7px;
  background: var(--chip-dot, #8b968f);
}
.map-tools {
  position: absolute;
  z-index: 500;
  top: calc(var(--top) + 10px);
  right: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.round {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  border: 0;
  background: #fff;
  color: var(--green);
  box-shadow: 0 1px 6px rgba(0, 0, 0, .35);
  display: grid;
  place-items: center;
  padding: 0;
}
.round svg { width: 27px; height: 27px; }
.round[aria-pressed=true] { background: var(--green); color: #fff; }
#crosshair {
  position: absolute;
  z-index: 490;
  left: 50%;
  width: 44px;
  height: 44px;
  margin: -22px 0 0 -22px;
  pointer-events: none;
  background:
    linear-gradient(var(--marsh), var(--marsh)) center / 3px 100% no-repeat,
    linear-gradient(var(--marsh), var(--marsh)) center / 100% 3px no-repeat;
  filter: drop-shadow(0 0 2px #fff);
}
.walk-card {
  background: var(--paper);
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  border-top: 1px solid var(--line);
  z-index: 500;
}
.next {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  border: 0;
  background: none;
  padding: 0;
  color: inherit;
  text-align: left;
  font: inherit;
}
.next-copy { flex: 1; min-width: 0; }
.next-label { font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.next-title { font: 600 19px/1.25 var(--serif); }
.next-distance { font-weight: 700; font-size: 18px; white-space: nowrap; color: var(--green); }

.pin {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50% 50% 50% 4px;
  transform: rotate(-45deg);
  background: var(--marsh);
  border: 2.500px solid #fff;
  box-shadow: 0 1px 5px rgba(0, 0, 0, .5);
}
.pin span { transform: rotate(45deg); color: #fff; font: 700 15px var(--sans); }
.pin.visited { background: var(--green); }
.entrance-label {
  width: max-content !important;
  padding: 3px 8px;
  border-radius: 6px;
  background: var(--green);
  color: #fff;
  font: 700 12px var(--sans);
  box-shadow: 0 1px 4px rgba(0, 0, 0, .4);
}

/* Stops */
.stop-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px;
}
.stop-open {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  border: 0;
  background: none;
  padding: 0;
  color: inherit;
  font: inherit;
  text-align: left;
}
.stop-thumb {
  width: 58px;
  height: 58px;
  border-radius: 10px;
  object-fit: cover;
  background: var(--green-soft);
  display: grid;
  place-items: center;
  font: 700 21px var(--serif);
  color: var(--green);
  flex-shrink: 0;
}
.stop-copy { min-width: 0; }
.stop-name { font: 600 18px/1.25 var(--serif); overflow-wrap: anywhere; }
.stop-meta { color: var(--muted); font-size: 14px; }
.reorder { display: flex; flex-direction: column; gap: 4px; }
.reorder button {
  width: 42px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--green);
  font-size: 16px;
}
.reorder button:disabled { opacity: .3; }
.progress { height: 10px; border-radius: 5px; background: #e4e1d4; overflow: hidden; }
.progress > div { height: 100%; background: var(--green); }
.tally { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 15px; color: var(--muted); }
.empty { text-align: center; padding: 28px 12px; color: var(--muted); display: flex; flex-direction: column; gap: 14px; }
.empty h2 { color: var(--ink); }

/* Sheet */
#sheet {
  margin: auto 0 0;
  width: 100%;
  max-width: 100%;
  max-height: calc(100dvh - var(--top) - 24px);
  border: 0;
  border-radius: 20px 20px 0 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  overflow: hidden;
}
#sheet[open] { display: flex; flex-direction: column; }
#sheet::backdrop { background: rgba(10, 25, 18, .55); }
.sheet-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 16px 10px;
}
.sheet-head h2 { overflow-wrap: anywhere; }
.close {
  width: 44px;
  height: 44px;
  margin: -6px -6px 0 0;
  border: 0;
  border-radius: 50%;
  background: #e7e3d6;
  color: var(--ink);
  font-size: 22px;
  line-height: 1;
  flex-shrink: 0;
}
.sheet-body {
  padding: 2px 16px calc(var(--bottom) + 20px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.sheet-body > * { flex-shrink: 0; }
.photo { width: 100%; max-height: 42dvh; object-fit: cover; border-radius: 14px; display: block; background: #ddd; }
.meta-line { color: var(--muted); font-size: 15px; }
.scientific { font-style: italic; color: var(--muted); }
.body-text { white-space: pre-wrap; overflow-wrap: anywhere; }

/* AI result */
.result h3 { font-size: 22px; }
.pill { display: inline-block; padding: 2px 10px; border-radius: 12px; font-size: 13px; font-weight: 700; width: fit-content; }
.pill.high { background: var(--green-soft); color: #14553a; }
.pill.medium { background: #fbf0cf; color: #6f4c00; }
.pill.low { background: var(--marsh-soft); color: #8a3e08; }
.fact { font-size: 15px; }
.fact b { display: block; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.caution { background: #fbe4e1; border-radius: 10px; padding: 10px 12px; color: #7d1a10; font-size: 15px; }
.spinner {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 3px solid var(--green-soft);
  border-top-color: var(--green);
  animation: spin .9s linear infinite;
  flex-shrink: 0;
}
.working { display: flex; align-items: center; gap: 12px; font-weight: 600; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }

/* QR */
.scanner { position: relative; border-radius: 14px; overflow: hidden; background: #000; aspect-ratio: 1; }
.scanner video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scanner::after {
  content: "";
  position: absolute;
  inset: 16%;
  border: 3px solid #fff;
  border-radius: 14px;
  box-shadow: 0 0 0 999px rgba(0, 0, 0, .3);
}
.qr-image { width: 100%; max-width: 340px; margin: 0 auto; display: block; border: 1px solid var(--line); border-radius: 12px; image-rendering: pixelated; }

#toast {
  position: fixed;
  z-index: 1200;
  left: 12px;
  right: 12px;
  top: calc(var(--top) + 66px);
  background: var(--green);
  color: #fff;
  padding: 12px 14px;
  border-radius: 14px;
  box-shadow: 0 3px 14px rgba(0, 0, 0, .45);
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 600;
}
#toast span { flex: 1; }
#toast button {
  min-height: 44px;
  padding: 0 14px;
  border: 0;
  border-radius: 10px;
  background: #fff;
  color: var(--green);
  font: 700 16px var(--sans);
}
