/* Anchorage Park Passport
   Mobile-first, one-handed. Paper-and-ink passport feel: cream stock, spruce
   green ink, a rubber-stamp red for the thing you just collected. */

:root {
  --cream:    #f7f2e7;
  --paper:    #fffdf7;
  --ink:      #2b2a24;
  --muted:    #6f6a5c;
  --line:     #e0d8c6;
  --spruce:   #2f6b3f;
  --spruce-d: #245231;
  --moss:     #4f9d63;
  --stamp:    #c1553a;
  --evergreen: #1b4332;
  --friend:   #6b3fa0;
  --danger:   #a33a2a;

  --radius: 14px;
  --tap: 48px;                       /* every control clears Apple's 44pt floor */
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --tabbar-h: 58px;

  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overscroll-behavior: none;         /* no rubber-band over the map */
}

body {
  display: flex;
  flex-direction: column;
  background: var(--cream);
  color: var(--ink);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

button, select, input { font: inherit; touch-action: manipulation; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* --- chrome ---------------------------------------------------------------- */

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(var(--safe-t) + 10px) 16px 10px;
  background: var(--spruce);
  color: #fff;
  flex: 0 0 auto;
}
.topbar h1 {
  margin: 0;
  font-size: 17px; font-weight: 650; letter-spacing: .01em;
}
.progress-pill {
  background: rgba(255,255,255,.16);
  border-radius: 999px;
  padding: 4px 11px;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}
.progress-pill strong { font-weight: 700; }
.progress-pill span { opacity: .75; }

#main { flex: 1 1 auto; position: relative; min-height: 0; }

.view { position: absolute; inset: 0; display: flex; flex-direction: column; }
.view[hidden] { display: none; }

.scroll {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px 14px calc(18px + var(--safe-b));
}

.tabbar {
  flex: 0 0 auto;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--paper);
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b);
}
.tab {
  min-height: var(--tabbar-h);
  padding: 0 2px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px;
  border: 0; background: none; color: var(--muted);
  font-size: 11px; font-weight: 600;
  cursor: pointer;
}
.tab-ico { font-size: 21px; line-height: 1; filter: saturate(.25) opacity(.65); }
.tab.is-on { color: var(--spruce); }
.tab.is-on .tab-ico { filter: none; }

/* --- map ------------------------------------------------------------------- */

#map { flex: 1 1 auto; min-height: 0; background: #dfe6dd; }
.leaflet-container { font: inherit; background: #dfe6dd; }

.map-btn {
  position: absolute; top: 12px; right: 12px; z-index: 500;
  width: var(--tap); height: var(--tap);
  border: 1px solid var(--line); border-radius: 50%;
  background: var(--paper); color: var(--spruce);
  font-size: 22px; line-height: 1;
  box-shadow: 0 2px 8px rgba(0,0,0,.15);
  cursor: pointer;
}

.legend {
  position: absolute; top: 12px; left: 12px; z-index: 500;
  display: flex; flex-direction: column; gap: 3px;
  background: rgba(255,253,247,.92);
  border: 1px solid var(--line); border-radius: 9px;
  padding: 7px 9px;
  font-size: 11.5px; color: var(--muted);
}
.legend span { display: flex; align-items: center; gap: 6px; }
.sw { width: 13px; height: 13px; border-radius: 3px; display: inline-block; }
.sw-stamped   { background: rgba(27,67,50,.72); border: 1.5px solid #0d2818; }
.sw-unstamped { background: rgba(185,173,148,.35); border: 1px solid #8a7f6a; }

.action-card {
  flex: 0 0 auto;
  background: var(--paper);
  border-top: 1px solid var(--line);
  padding: 12px 14px 14px;
  box-shadow: 0 -3px 14px rgba(0,0,0,.06);
}
.status { margin: 0 0 4px; font-size: 15px; line-height: 1.4; }
.status b { font-weight: 650; }
.accuracy { margin: 0 0 8px; font-size: 12.5px; color: var(--muted); }
.accuracy.is-bad { color: var(--danger); }

.actions { display: flex; gap: 9px; margin-top: 10px; }
.actions.wrap { flex-wrap: wrap; }
.actions .btn { flex: 1 1 0; }

/* --- buttons --------------------------------------------------------------- */

.btn {
  min-height: var(--tap);
  padding: 0 16px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-size: 16px; font-weight: 650;
  cursor: pointer;
  transition: transform .08s ease, background-color .15s ease;
}
.btn:active:not(:disabled) { transform: scale(.975); }
.btn:disabled { opacity: .45; cursor: default; }

.btn-primary   { background: var(--spruce); color: #fff; }
.btn-primary:not(:disabled) { box-shadow: 0 2px 0 var(--spruce-d); }
.btn-secondary { background: var(--paper); color: var(--spruce); border-color: var(--line); }
.btn-danger    { background: var(--paper); color: var(--danger); border-color: #e6c4bd; width: 100%; }

/* The stamp button when it's live: a rubber stamp waiting to come down. */
.btn-primary.is-ready { background: var(--stamp); box-shadow: 0 2px 0 #92402c; }

/* --- cards, passport ------------------------------------------------------- */

.card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}
.card h2 { margin: 0 0 8px; font-size: 15.5px; font-weight: 700; }
.card p { margin: 0 0 9px; font-size: 14.5px; }
.card p:last-child { margin-bottom: 0; }
.muted { color: var(--muted); font-size: 13.5px; }
.note { font-size: 13px; color: var(--muted); margin-top: 8px; }
.danger-h { color: var(--danger); }

.steps { margin: 0; padding-left: 20px; font-size: 14.5px; }
.steps li { margin-bottom: 7px; }
.steps li:last-child { margin-bottom: 0; }

.summary-top { display: flex; align-items: flex-end; justify-content: space-between; }
.big { font-size: 40px; font-weight: 750; line-height: 1; font-variant-numeric: tabular-nums; }
.pct { font-size: 25px; font-weight: 700; color: var(--spruce); font-variant-numeric: tabular-nums; }
.bar { height: 9px; border-radius: 999px; background: var(--cream); margin-top: 12px; overflow: hidden; }
.bar-fill { height: 100%; width: 0; border-radius: 999px; background: var(--moss); transition: width .4s ease; }

.seg {
  display: flex; gap: 4px; padding: 4px;
  background: var(--paper); border: 1px solid var(--line);
  border-radius: 11px; margin-bottom: 10px;
}
.seg-btn {
  flex: 1; min-height: 38px; border: 0; border-radius: 8px;
  background: none; color: var(--muted); font-size: 14px; font-weight: 650;
  cursor: pointer;
}
.seg-btn.is-on { background: var(--spruce); color: #fff; }

.filters { display: flex; gap: 8px; margin-bottom: 10px; }
.filters select {
  flex: 1 1 0; min-width: 0; min-height: 42px;
  padding: 0 10px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--paper); color: var(--ink);
  -webkit-appearance: none; appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%236f6a5c'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 11px center;
  padding-right: 28px;
  font-size: 14px;
}

.listnote { margin: 0 2px 8px; font-size: 13px; color: var(--muted); }

.parklist { list-style: none; margin: 0 0 12px; padding: 0; }
.parklist li {
  display: flex; align-items: center; gap: 11px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 10px 12px;
  margin-bottom: 7px;
}
.parklist .pin {
  flex: 0 0 auto; width: 34px; height: 34px; border-radius: 50%;
  display: grid; place-items: center; font-size: 16px;
  background: var(--evergreen); color: #eef3ee;
  border: 1.5px solid #0d2818;
}
.parklist li.is-todo .pin {
  background: var(--cream); color: var(--muted); border-color: var(--line);
}
.parklist .nm { flex: 1 1 auto; min-width: 0; }
.parklist .nm b { display: block; font-size: 14.5px; font-weight: 600; }
.parklist .nm small { color: var(--muted); font-size: 12px; }
.parklist .when {
  flex: 0 0 auto; font-size: 12px; color: var(--muted); text-align: right;
  font-variant-numeric: tabular-nums;
}
.parklist .go {
  flex: 0 0 auto; border: 0; background: none; color: var(--spruce);
  font-size: 19px; padding: 6px; cursor: pointer;
}
.empty { text-align: center; color: var(--muted); padding: 26px 10px; font-size: 14px; }

.version { text-align: center; color: var(--muted); font-size: 11.5px; margin: 4px 0 0; }

/* --- sheet & toast --------------------------------------------------------- */

.sheet-wrap { position: fixed; inset: 0; z-index: 1000; display: flex; align-items: flex-end; }
.sheet-wrap[hidden] { display: none; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(20,18,12,.45); }
.sheet {
  position: relative; width: 100%;
  background: var(--paper);
  border-radius: 18px 18px 0 0;
  padding: 18px 16px calc(16px + var(--safe-b));
  max-height: 78vh; overflow-y: auto;
  animation: rise .18s ease-out;
}
@keyframes rise { from { transform: translateY(14px); opacity: .6; } }
.sheet h2 { margin: 0 0 3px; font-size: 17px; }
.sheet ul { list-style: none; margin: 13px 0; padding: 0; }
.sheet li { margin-bottom: 8px; }
.sheet li button {
  width: 100%; min-height: 56px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  text-align: left;
  padding: 9px 14px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--cream); color: var(--ink);
  cursor: pointer;
}
.sheet li button b { font-size: 15px; font-weight: 640; }
.sheet li button small { display: block; color: var(--muted); font-size: 12px; }
.sheet li button .dist { color: var(--spruce); font-size: 13px; font-weight: 650; white-space: nowrap; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabbar-h) + var(--safe-b) + 16px);
  z-index: 1200;
  max-width: calc(100% - 32px);
  background: var(--ink); color: var(--paper);
  padding: 11px 16px; border-radius: 999px;
  font-size: 14px; font-weight: 600;
  box-shadow: 0 4px 16px rgba(0,0,0,.28);
  animation: rise .18s ease-out;
}
.toast[hidden] { display: none; }
.toast.is-win { background: var(--stamp); }

/* --- leaflet popups, restyled to match ------------------------------------- */

.leaflet-popup-content-wrapper { border-radius: 11px; }
.leaflet-popup-content { margin: 11px 13px; font-size: 14px; }
.leaflet-popup-content b { display: block; font-size: 15px; margin-bottom: 2px; }
.leaflet-popup-content small { color: var(--muted); }
.leaflet-control-attribution { font-size: 10px; }

/* The blue dot. Leaflet's default marker is a pin; a dot reads as "you". */
.me-dot {
  width: 16px; height: 16px; border-radius: 50%;
  background: #1a73e8; border: 2.5px solid #fff;
  box-shadow: 0 0 0 1px rgba(0,0,0,.2);
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}


/* --- friends --------------------------------------------------------------- */

.head-row {
  display: flex; align-items: baseline; justify-content: space-between;
  margin: 4px 2px 10px;
}
.head-row h2 { margin: 0; font-size: 15.5px; font-weight: 700; }
.btn-link {
  border: 0; background: none; color: var(--spruce);
  font-size: 14px; font-weight: 650; cursor: pointer; padding: 6px 2px;
}
.btn-link:disabled { opacity: .45; }

.leaderboard, .feed { list-style: none; margin: 0 0 16px; padding: 0; }

.lb-row {
  display: flex; align-items: center; gap: 11px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 11px 12px;
  margin-bottom: 7px;
  cursor: pointer;
}
.lb-row.is-me { border-color: var(--moss); background: #f4f8f4; }
.lb-row:focus-visible { outline: 2px solid var(--spruce); outline-offset: 2px; }

.lb-rank {
  flex: 0 0 auto; width: 28px; text-align: center;
  font-size: 17px; font-weight: 700; color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.lb-main { flex: 1 1 auto; min-width: 0; }
.lb-main b { display: block; font-size: 14.5px; font-weight: 640; }
.lb-main small { color: var(--muted); font-size: 11.5px; }

/* A bar scaled to the leader, so the gap is legible at a glance. */
.lb-bar {
  display: block; height: 6px; border-radius: 999px;
  background: var(--cream); margin: 5px 0 4px; overflow: hidden;
}
.lb-fill {
  display: block; height: 100%; border-radius: 999px;
  background: var(--evergreen); transition: width .4s ease;
}

.lb-count { flex: 0 0 auto; text-align: right; }
.lb-count b {
  display: block; font-size: 19px; font-weight: 750; line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.lb-count small { color: var(--muted); font-size: 11px; }

.feed-row {
  display: flex; align-items: baseline; justify-content: space-between; gap: 10px;
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}
.feed-row:last-child { border-bottom: 0; }
.feed-row b { font-weight: 650; }
.feed-row small { flex: 0 0 auto; color: var(--muted); font-size: 11.5px; }

/* Banner shown while a friend's parks are on the map.
   A normal flex item, NOT absolutely positioned: anchored to the bottom of the
   view it sat on top of the Check location and Stamp buttons and made them
   untappable. */
.friend-banner {
  flex: 0 0 auto;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--friend); color: #fff;
  padding: 10px 14px;
  font-size: 13.5px;
}
.friend-banner[hidden] { display: none; }
.friend-banner button {
  border: 1px solid rgba(255,255,255,.55); border-radius: 8px;
  background: transparent; color: #fff;
  font-size: 13px; font-weight: 650; padding: 6px 12px; min-height: 34px;
  cursor: pointer;
}

/* --- the stamp impression -------------------------------------------------- */
/* Collecting a park is the one moment this app exists for. It used to be a
   toast. Now the mark comes down like a rubber stamp onto the passport page:
   red ink on cream stock, overshoot, settle, hold, fade.

   The name sits BELOW the spruce rather than over it -- the first version drew
   both in the same place and the park name was unreadable. */

.impression {
  position: fixed; inset: 0; z-index: 1500;
  display: grid; place-items: center;
  background: rgba(20, 18, 12, .42);
  animation: imp-veil .18s ease-out;
}
.impression[hidden] { display: none; }

.impression-mark {
  position: relative;
  box-sizing: border-box;
  /* Width AND height given explicitly. An aspect-ratio here fed back on itself:
     tall wrapped text grew the height, aspect-ratio pushed the width to match,
     which wrapped the text taller still -- it ended up 1999px across with one
     letter per line. Fixed padding for the same reason; percentage padding
     resolves against that same unstable width. */
  width: min(68vw, 262px);
  height: min(68vw, 262px);
  padding: 38px 34px;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 6px;
  border-radius: 50%;
  background: var(--paper);
  color: var(--stamp);
  text-align: center;
  overflow: hidden;
  box-shadow: 0 14px 34px rgba(0, 0, 0, .38);
  /* A stamp is never perfectly square to the page. */
  animation: imp-down .5s cubic-bezier(.2, 1.5, .4, 1) both;
}

.impression-ring {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  opacity: .9;
}

.impression-spruce { width: clamp(26px, 8vw, 34px); height: auto; opacity: .95; }

.impression-name {
  font-size: clamp(11.5px, 3.4vw, 14.5px);
  font-weight: 750; line-height: 1.2;
  letter-spacing: .03em; text-transform: uppercase;
  /* Wrap at word boundaries. "anywhere" broke mid-word, one letter per line. */
  max-width: 100%;
  overflow-wrap: break-word;
}
.impression-date {
  font-size: 10px; font-weight: 650; letter-spacing: .12em;
  text-transform: uppercase; opacity: .75;
}

@keyframes imp-veil { from { opacity: 0; } }
@keyframes imp-down {
  0%   { transform: scale(2.4) rotate(-17deg); opacity: 0; }
  60%  { transform: scale(.93) rotate(-6deg);  opacity: 1; }
  78%  { transform: scale(1.05) rotate(-6deg); }
  100% { transform: scale(1) rotate(-6deg);    opacity: 1; }
}
.impression.is-leaving { animation: imp-veil .3s ease-in reverse both; }

@media (prefers-reduced-motion: reduce) {
  .impression-mark { animation: none; transform: rotate(-6deg); }
}

/* --- nearby parks strip ---------------------------------------------------- */

.nearby { margin-top: 9px; }
.nearby[hidden] { display: none; }
.nearby-label {
  display: block;
  font-size: 10.5px; font-weight: 700; letter-spacing: .07em;
  text-transform: uppercase; color: var(--muted);
  margin-bottom: 5px;
}
.nearby-strip {
  display: flex; gap: 7px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding-bottom: 2px;
}
.nearby-strip::-webkit-scrollbar { display: none; }
.nearby-chip {
  flex: 0 0 auto;
  display: flex; flex-direction: column; align-items: flex-start;
  min-height: 42px;
  max-width: 190px;
  padding: 6px 11px;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--cream); color: var(--ink);
  font-size: 13px; line-height: 1.25;
  cursor: pointer;
  white-space: nowrap;
}
.nearby-chip b {
  font-weight: 620;
  max-width: 168px; overflow: hidden; text-overflow: ellipsis;
}
.nearby-chip small { color: var(--spruce); font-size: 11px; font-weight: 650; }
.nearby-chip.is-close { border-color: var(--moss); background: #eef4ee; }
