/* Palette sampled directly from the official Wildwood trail map PDF.
   Every ratio below was measured against the *lightest* backdrop each colour
   can actually land on — the horizon glow flattened with the 5–13% overlays
   used by cards, panels and chips — not just against flat --forest. That is
   why jade is split in two: the map's jade only reaches 3.7:1 and cannot
   legally carry small text.
     --jade       decorative fills only          (worst 3.0 — never text)
     --jade-text  all small jade text            (worst 4.96, need 4.5)
     --line       borders and control boundaries (worst 3.30, need 3.0)
     --mint-dim   secondary text                 (worst 5.77)
     --gold       error text                     (worst 4.87) */
:root {
  --forest: #084338;
  --forest-deep: #04332A;
  --forest-soft: #0B5344;
  --jade: #40A58A;
  --jade-text: #A3D4C6;
  --jade-dim: #2F7D69;
  --line: #60B49D;
  --mint: #F1F9F6;
  --mint-dim: #C9DED6;
  --gold: #E9C46A;

  --radius: 14px;
  --shadow: 0 10px 30px rgba(4, 51, 42, 0.35);
  --hand: "Caveat", "Bradley Hand", "Segoe Print", cursive;
  --body: "Nunito Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;

  /* Lets the OS render native controls (select popups, scrollbars) to match. */
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--forest);
  color: var(--mint);
  font-family: var(--body);
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100vh;
  /* Faint forest horizon, echoing the map's tree-line silhouettes. */
  background-image:
    radial-gradient(1200px 500px at 50% -10%, rgba(11, 83, 68, 0.5) 0%, transparent 70%),
    linear-gradient(180deg, var(--forest) 0%, var(--forest-deep) 100%);
  background-attachment: fixed;
  overflow-wrap: break-word;
}

.hidden { display: none !important; }

/* Screen-reader-only, but still focusable and still announced. */
.vh {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* One visible focus style for everything. Outlines are never removed. */
:focus-visible {
  outline: 3px solid var(--mint);
  outline-offset: 2px;
  border-radius: 6px;
}

/* ---------------------------------------------------------------- crow mark */
.crow {
  display: inline-block;
  width: 1em;
  height: 2em;
  color: currentColor;
  background-color: currentColor;
  -webkit-mask: url("crow.svg") center / contain no-repeat;
  mask: url("crow.svg") center / contain no-repeat;
}

/* ------------------------------------------------------------------- gate */
.gate {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px max(24px, env(safe-area-inset-left)) calc(24px + env(safe-area-inset-bottom));
  text-align: center;
}

.gate-inner { max-width: 380px; width: 100%; }

.gate .crow {
  width: 84px;
  height: 168px;
  color: var(--jade);
  opacity: 0.9;
  margin-bottom: 8px;
}

.wordmark {
  font-family: var(--hand);
  line-height: 0.95;
  margin: 0;
}

.wordmark .big {
  display: block;
  font-size: clamp(2.6rem, 12vw, 3.6rem);
  letter-spacing: 0.06em;
  color: var(--mint);
}

.wordmark .small {
  display: block;
  font-size: clamp(1.1rem, 5vw, 1.4rem);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--jade-text);
  font-family: var(--body);
  font-weight: 700;
  margin-top: 6px;
}

.gate p.tagline {
  color: var(--mint-dim);
  font-size: 0.95rem;
  margin: 18px 0 26px;
}

.field {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

input[type="password"], input[type="text"] {
  flex: 1;
  min-width: 0;
  padding: 13px 16px;
  /* 16px minimum, or iOS Safari zooms the whole page on focus. */
  font-size: 1rem;
  font-family: var(--body);
  color: var(--forest-deep);
  background: var(--mint);
  border: 2px solid var(--forest-deep);
  border-radius: 10px;
  min-height: 48px;
}

input:focus { border-color: var(--jade-dim); }

button {
  font-family: var(--body);
  font-weight: 700;
  font-size: 1rem;
  padding: 13px 20px;
  min-height: 48px;
  border: 0;
  border-radius: 10px;
  background: var(--jade-text);
  color: var(--forest-deep);
  cursor: pointer;
  transition: filter 0.15s ease;
  /* Kill the 300ms tap delay and the grey flash on iOS. */
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

button:hover { filter: brightness(1.08); }
button:active { transform: translateY(1px); }

.error {
  color: var(--gold);
  font-size: 0.9rem;
  min-height: 1.2em;
  margin: 4px 0 0;
}

/* ------------------------------------------------------------------ header */
.wrap {
  max-width: 720px;
  margin: 0 auto;
  padding: 20px max(16px, env(safe-area-inset-left)) calc(104px + env(safe-area-inset-bottom));
}

header.top {
  display: flex;
  align-items: center;
  gap: 14px;
  padding-bottom: 16px;
}

header.top .crow {
  width: 34px;
  height: 68px;
  color: var(--jade);
  flex: none;
}

header.top .titles { flex: 1; min-width: 0; }

header.top h1 {
  font-family: var(--hand);
  font-size: 1.9rem;
  margin: 0;
  line-height: 1;
}

header.top .sub {
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--jade-text);
  font-weight: 700;
  margin: 2px 0 0;
}

/* ----------------------------------------------------------------- progress */
.progress {
  background: rgba(241, 249, 246, 0.06);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 14px;
}

.progress-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.progress .count {
  font-family: var(--hand);
  font-size: 2rem;
  line-height: 1;
  margin: 0;
}

.progress .count b { color: var(--jade-text); }

.progress .msg {
  font-size: 0.85rem;
  color: var(--mint-dim);
  text-align: right;
  margin: 0;
}

.bar {
  height: 10px;
  border-radius: 99px;
  background: rgba(4, 51, 42, 0.6);
  border: 1px solid var(--line);
  overflow: hidden;
}

.bar span {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--jade), var(--jade-text));
  transition: width 0.35s ease;
}

/* ------------------------------------------------------------------ controls */
.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}

.chips { display: flex; gap: 8px; flex-wrap: wrap; }

.chip {
  /* 44px minimum touch target (WCAG 2.5.8 / Apple HIG). */
  min-height: 44px;
  padding: 0 16px;
  font-size: 0.9rem;
  font-weight: 700;
  border-radius: 99px;
  background: rgba(241, 249, 246, 0.08);
  color: var(--mint);
  border: 1px solid var(--line);
}

.chip[aria-pressed="true"] {
  background: var(--jade-text);
  color: var(--forest-deep);
  border-color: var(--jade-text);
}

.sorter {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--mint-dim);
}

.sorter select {
  font-family: var(--body);
  font-size: 1rem;
  font-weight: 700;
  min-height: 44px;
  padding: 0 34px 0 14px;
  border-radius: 99px;
  border: 1px solid var(--line);
  background-color: rgba(241, 249, 246, 0.08);
  color: var(--mint);
  appearance: none;
  -webkit-appearance: none;
  /* Chevron drawn inline so there is no extra request. */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5 6 6.5 11 1.5' fill='none' stroke='%23F1F9F6' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 13px center;
  background-size: 12px 8px;
  touch-action: manipulation;
}

/* --------------------------------------------------------------------- list */
.hood-label {
  font-family: var(--hand);
  font-size: 1.5rem;
  color: var(--jade-text);
  margin: 22px 0 8px;
  padding-left: 4px;
}

ul.list { list-style: none; margin: 0; padding: 0; }

li.crow-card {
  background: rgba(241, 249, 246, 0.05);
  border: 1px solid rgba(96, 180, 157, 0.45);
  border-radius: var(--radius);
  margin-bottom: 10px;
  overflow: hidden;
  transition: border-color 0.2s ease, background 0.2s ease;
}

li.crow-card.found {
  background: rgba(64, 165, 138, 0.13);
  border-color: var(--line);
}

.row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
}

/* The numbered jade disc from the map legend. */
.badge {
  flex: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--jade-dim);
  color: var(--mint);
  font-weight: 700;
  font-size: 0.95rem;
}

li.crow-card.found .badge { background: var(--jade-text); color: var(--forest-deep); }

.row .naming {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  text-align: left;
  background: none;
  border: 0;
  padding: 4px 2px;
  color: inherit;
  font: inherit;
  cursor: pointer;
}

.row .naming:hover { filter: none; }
.row .naming:active { transform: none; }

.naming .cname {
  font-family: var(--hand);
  font-size: 1.35rem;
  line-height: 1.15;
  display: block;
}

.naming .cmeta {
  font-size: 0.78rem;
  color: var(--mint-dim);
  display: block;
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

li.crow-card.found .naming .cname {
  text-decoration: line-through;
  text-decoration-thickness: 2px;
  /* Struck-through text still has to clear 4.5:1, so no opacity dimming. */
  color: var(--mint-dim);
}

/* Tick box — a real checkbox, sized to a 44x44 hit area, with the native input
   made invisible but left in place so it keeps focus and hit testing. The
   visible square is the sibling .box, styled off :checked and :focus-visible. */
.tick {
  position: relative;
  flex: none;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.tick input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.tick .box {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: 2px solid var(--line);
  display: grid;
  place-items: center;
  pointer-events: none;
}

.tick svg {
  width: 20px;
  height: 20px;
  stroke: var(--forest-deep);
  stroke-width: 3.2;
  fill: none;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.tick input:checked + .box { background: var(--jade-text); border-color: var(--jade-text); }
.tick input:checked + .box svg { opacity: 1; }

.tick input:focus-visible + .box {
  outline: 3px solid var(--mint);
  outline-offset: 3px;
}

/* ------------------------------------------------------------------ details */
.details {
  padding: 0 14px 14px 58px;
  font-size: 0.9rem;
  color: var(--mint-dim);
}

.details dl { margin: 0 0 12px; display: grid; grid-template-columns: auto 1fr; gap: 6px 10px; }

.details dt {
  color: var(--jade-text);
  font-weight: 700;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding-top: 3px;
}

.details dd { margin: 0; }

.maps { display: flex; gap: 8px; flex-wrap: wrap; }

.maps a {
  flex: 1 1 130px;
  display: grid;
  place-items: center;
  min-height: 44px;
  text-align: center;
  text-decoration: none;
  padding: 8px 14px;
  border-radius: 10px;
  font-weight: 700;
  font-size: 0.9rem;
  background: var(--jade-text);
  color: var(--forest-deep);
  border: 1px solid var(--jade-text);
  touch-action: manipulation;
}

.maps a.alt {
  background: transparent;
  color: var(--jade-text);
  border-color: var(--line);
}

.found-by {
  margin: 10px 0 0;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--jade-text);
}

/* ------------------------------------------------------------------- footer */
.syncbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 10px max(16px, env(safe-area-inset-left)) calc(10px + env(safe-area-inset-bottom));
  background: rgba(4, 51, 42, 0.96);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(8px);
  font-size: 0.8rem;
  color: var(--mint-dim);
  display: flex;
  align-items: center;
  gap: 10px;
}

.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--jade-text); flex: none; }
.dot.warn { background: var(--gold); }
.dot.off { background: var(--mint-dim); }

.syncbar .who {
  margin-left: auto;
  color: var(--jade-text);
  font-weight: 700;
  flex: none;
}

.empty { text-align: center; color: var(--mint-dim); padding: 40px 12px; }
.empty .crow { width: 40px; height: 80px; color: var(--line); }

footer.credits {
  margin-top: 30px;
  font-size: 0.78rem;
  color: var(--mint-dim);
  text-align: center;
  line-height: 1.6;
}

footer.credits a { color: var(--jade-text); }

footer.credits button.link {
  background: none;
  border: 0;
  min-height: 44px;
  padding: 0 8px;
  color: var(--jade-text);
  font-size: 0.85rem;
  font-weight: 600;
  text-decoration: underline;
  cursor: pointer;
}

/* ------------------------------------------------------------ walking route */
.routebar {
  margin: 0 0 14px;
  padding: 11px 14px;
  border-radius: var(--radius);
  background: rgba(241, 249, 246, 0.06);
  border: 1px solid var(--line);
  font-size: 0.85rem;
  color: var(--mint-dim);
}

.leg { margin-top: 22px; }
.leg:first-child { margin-top: 4px; }
.leg .hood-label { margin: 0 0 2px; }

.leg .legsub {
  margin: 0 0 8px;
  padding-left: 4px;
  font-size: 0.8rem;
  color: var(--mint-dim);
}

/* A hop you cannot walk. Marked with a dashed rule, not just colour. */
.leg .jump {
  margin: 0 0 16px;
  padding: 9px 12px;
  border: 1px dashed var(--line);
  border-radius: 10px;
  font-size: 0.8rem;
  color: var(--mint-dim);
  background: rgba(4, 51, 42, 0.45);
}

/* -------------------------------------------------------------------- map */
/* OSM tiles are bright white next to a dark forest UI. A light tint settles
   them into the theme without touching label legibility — the alternative
   (a filter dark enough to match) turns street names into dark-on-dark mud. */
.leaflet-tile-pane {
  filter: sepia(0.18) saturate(0.85) hue-rotate(-6deg) brightness(0.97) contrast(1.02);
}

#map {
  height: 62vh;
  /* Keep the whole map clear of the fixed sync bar without having to scroll:
     the header, controls, legend and bar take roughly 380px between them.
     min-height wins over max-height, so short screens keep a usable map and
     scroll instead. Browsers without dvh just get the 62vh. */
  max-height: calc(100dvh - 380px);
  min-height: 340px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--forest-deep);
  /* Leaflet panes would otherwise paint over the rounded corners. */
  overflow: hidden;
  z-index: 0;
}

#map.map-error {
  display: grid;
  place-items: center;
  padding: 24px;
  text-align: center;
  color: var(--mint-dim);
  font-size: 0.9rem;
  height: auto;
  min-height: 160px;
}

.maphint {
  margin: 10px 0 0;
  font-size: 0.8rem;
  color: var(--mint-dim);
  line-height: 1.7;
}

.maphint .key {
  display: inline-block;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  vertical-align: -2px;
  margin-right: 3px;
  border: 2px solid var(--line);
}

.maphint .key {
  border-color: var(--mint-dim);
}

.maphint .key.found { background: var(--jade-text); border-color: var(--jade-text); }
.maphint .key.todo { background: var(--forest-deep); }

/* Route-line swatches: the same dark-on-light casing used on the map itself. */
.maphint .key.line {
  width: 26px;
  height: 11px;
  border-radius: 3px;
  border: 0;
  background: var(--mint);
  vertical-align: -1px;
  position: relative;
}

.maphint .key.line::after {
  content: "";
  position: absolute;
  left: 1px;
  right: 1px;
  top: 4px;
  height: 3px;
  border-radius: 2px;
  background: var(--forest);
}

.maphint .key.line.dash::after {
  height: 3px;
  background: repeating-linear-gradient(90deg, var(--forest) 0 3px, transparent 3px 8px);
}

/* Numbered pins, echoing the jade discs in the map legend. */
.pin-wrap { background: none; border: 0; }

.pin {
  position: relative;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--forest-deep);
  border: 2px solid var(--mint);
  color: var(--mint);
  font-family: var(--body);
  font-weight: 700;
  font-size: 0.85rem;
  box-shadow: 0 2px 6px rgba(4, 51, 42, 0.55);
}

.is-found .pin {
  background: var(--jade-text);
  border-color: var(--forest-deep);
  color: var(--forest-deep);
}

/* Found pins also carry a tick, so the state is never colour alone. */
.is-found .pin::after {
  content: "";
  position: absolute;
  right: -3px;
  bottom: -3px;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--forest-deep);
  /* A check mark, drawn rather than fetched. */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpolyline points='4,13 9,18 20,6' fill='none' stroke='%23A3D4C6' stroke-width='4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-size: 11px 11px;
  background-position: center;
  background-repeat: no-repeat;
}

/* Cluster badge: how many crows are hiding here, and how many you have. */
.cluster {
  display: grid;
  place-content: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--forest-deep);
  border: 2px solid var(--mint);
  color: var(--mint);
  font-family: var(--body);
  line-height: 1;
  text-align: center;
  box-shadow: 0 2px 8px rgba(4, 51, 42, 0.55);
}

.cluster b { font-size: 0.95rem; font-weight: 700; }
.cluster small { font-size: 0.5rem; letter-spacing: 0.02em; opacity: 0.9; }
.cluster.some-found { border-color: var(--jade-text); }
.cluster.all-found { background: var(--jade-text); border-color: var(--forest-deep); color: var(--forest-deep); }

.pin-wrap:focus-visible { outline: none; }
.pin-wrap:focus-visible .pin { outline: 3px solid var(--mint); outline-offset: 3px; }

/* Leaflet popup, re-skinned to the trail map palette. */
.leaflet-popup-content-wrapper {
  background: var(--forest-deep);
  color: var(--mint);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.leaflet-popup-tip { background: var(--forest-deep); border: 1px solid var(--line); }
.leaflet-popup-content { margin: 12px 14px; font-family: var(--body); }
.leaflet-popup-content p { margin: 0; }
.leaflet-container a.leaflet-popup-close-button { color: var(--mint-dim); width: 30px; height: 30px; font-size: 22px; }
.leaflet-container a.leaflet-popup-close-button:hover { color: var(--mint); background: none; }

.pop-name { font-family: var(--hand); font-size: 1.3rem; line-height: 1.15; margin-bottom: 2px; }
.pop-meta { font-size: 0.82rem; color: var(--mint-dim); }
.pop .maps { margin-top: 10px; }

.pop-tick {
  width: 100%;
  margin-top: 8px;
  font-size: 0.9rem;
  min-height: 44px;
  padding: 8px 12px;
  background: transparent;
  color: var(--jade-text);
  border: 1px solid var(--line);
}

/* Leaflet's own chrome, toned to match. */
.leaflet-bar a, .leaflet-bar a:hover {
  background: var(--forest-deep);
  color: var(--mint);
  border-bottom-color: var(--line);
}

.leaflet-bar { border: 1px solid var(--line); }

.leaflet-control-attribution {
  background: rgba(4, 51, 42, 0.85) !important;
  color: var(--mint-dim);
  font-size: 0.65rem;
}

.leaflet-control-attribution a { color: var(--jade-text); }

/* --------------------------------------------------------------- responsive */
@media (max-width: 380px) {
  .details { padding-left: 14px; }
  #map { height: 56vh; }
  .sorter { margin-left: 0; width: 100%; }
  .sorter select { flex: 1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* Honour a user's request for extra contrast by dropping the tints. */
@media (prefers-contrast: more) {
  li.crow-card { background: var(--forest-deep); border-color: var(--mint-dim); }
  li.crow-card.found { background: var(--forest-soft); border-color: var(--mint); }
  .chip, .sorter select { background-color: var(--forest-deep); border-color: var(--mint-dim); }
  .progress { background: var(--forest-deep); border-color: var(--mint-dim); }
  .naming .cmeta, .details, footer.credits, .syncbar { color: var(--mint); }
  .routebar, .leg .jump, .leg .legsub, .maphint { color: var(--mint); }
  .routebar, .leg .jump { background: var(--forest-deep); border-color: var(--mint-dim); }
  .pin, .cluster { border-color: var(--mint); }
  .leaflet-tile-pane { filter: none; }
}
