:root {
  --bg: #fbf7ef;
  --card: #ffffff;
  --ink: #2b2a26;
  --muted: #67614f;
  --line: #ece4d4;
  --brand: #2f6b4f;
  --brand-2: #e8963a;
  --brand-soft: #e6f1ea;
  --loud: #e04848;
  --shadow: 0 10px 30px rgba(54, 42, 20, 0.16);
  --radius: 18px;
  --loop-1: #2f6b4f;
  --loop-2: #e8963a;
  --loop-3: #4a7fc1;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #1d1f1c;
    --card: #272a26;
    --ink: #f1ede4;
    --muted: #a7a194;
    --line: #3a3d37;
    --brand: #6cc497;
    --brand-soft: #2c3d33;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
    --loop-1: #4fb07f;
    --loop-3: #6aa0e6;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: 'Nunito', system-ui, -apple-system, 'Segoe UI', sans-serif;
  overflow: hidden;
}

#map { position: fixed; inset: 0; background: #e9e4da; }
.leaflet-tile-pane { filter: saturate(0.8) contrast(0.95); }
@media (prefers-color-scheme: dark) { .leaflet-tile-pane { filter: saturate(0.7) brightness(0.85); } }

/* ---------- panel ---------- */
.panel {
  position: fixed;
  top: 16px;
  left: 16px;
  bottom: 16px;
  width: 390px;
  max-width: calc(100vw - 32px);
  background: var(--bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  z-index: 1000;
  overflow: hidden;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 18px 8px;
}
.logo {
  cursor: pointer; padding: 0;
  width: 46px; height: 46px;
  display: grid; place-items: center;
  border-radius: 14px;
  background: #fff6e6;
  border: 2.5px solid var(--brand);
  font-size: 26px;
  transform: rotate(-8deg);
  box-shadow: 0 4px 0 rgba(0,0,0,.12);
}
h1 {
  font-family: 'Fredoka', 'Nunito', sans-serif;
  font-size: 26px;
  margin: 0;
  letter-spacing: 0.3px;
  color: var(--brand);
}
.tagline { margin: 0; color: var(--muted); font-size: 13px; font-weight: 600; }
.sheet-toggle { display: none; margin-left: auto; border: 0; background: var(--line); color: var(--ink); border-radius: 10px; width: 36px; height: 32px; font-size: 18px; cursor: pointer; }

.tabs {
  display: flex;
  gap: 4px;
  margin: 8px 14px 0;
  padding: 4px;
  background: var(--line);
  border-radius: 14px;
}
.tab {
  flex: 1;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: 700 13px 'Nunito', sans-serif;
  padding: 9px 4px;
  border-radius: 10px;
  cursor: pointer;
  white-space: nowrap;
}
.tab.active { background: var(--card); color: var(--ink); box-shadow: 0 2px 6px rgba(0,0,0,.08); }
.pill { display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 10px; background: #b3591c; color: #fff; font-size: 11px; line-height: 18px; }

.tab-body { display: none; padding: 14px 18px 18px; overflow-y: auto; flex: 1; }
.tab-body.active { display: block; }

.credits { font-size: 11px; color: var(--muted); padding: 8px 18px 12px; border-top: 1px solid var(--line); }
.credits a { color: inherit; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.hidden { display: none !important; }

/* ---------- controls ---------- */
.btn {
  border: 0;
  border-radius: 12px;
  padding: 10px 14px;
  font: 700 14px 'Nunito', sans-serif;
  cursor: pointer;
  transition: transform .08s ease, filter .15s ease, opacity .15s;
}
.btn:active { transform: translateY(1px) scale(.99); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--brand); color: #fff; box-shadow: 0 4px 0 rgba(0,0,0,.18); }
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); }
.btn.secondary { background: var(--card); color: var(--ink); border: 1.5px solid var(--line); }
.btn.ghost { background: transparent; color: var(--muted); text-decoration: underline; padding: 6px 0; }
.btn.big { width: 100%; padding: 14px; font-size: 16px; margin-top: 6px; }
.btn.accent { background: #b3591c; color: #fff; box-shadow: 0 4px 0 rgba(0,0,0,.15); } /* darker than --brand-2 so white text passes WCAG AA */

.start-row { display: flex; align-items: center; gap: 10px; }
.or { color: var(--muted); font-size: 13px; font-weight: 600; }
.start-label { margin: 8px 0 12px; font-size: 13px; min-height: 18px; }

.field { display: block; margin: 12px 0; }
.field-label { display: block; font-weight: 700; font-size: 14px; margin-bottom: 6px; }
.field-label strong { color: var(--brand); }
input[type='range'] { width: 100%; accent-color: var(--brand); }
input[type='text'] {
  width: 100%;
  padding: 11px 12px;
  border-radius: 12px;
  border: 1.5px solid var(--line);
  background: var(--card);
  color: var(--ink);
  font: 600 15px 'Nunito', sans-serif;
}
input[type='text']:focus { outline: 2px solid var(--brand); outline-offset: 1px; }

.switch { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 14px; margin: 14px 0; cursor: pointer; }
.switch input { display: none; }
.switch .track { width: 44px; height: 26px; border-radius: 13px; background: var(--line); position: relative; transition: background .2s; flex: none; }
.switch .thumb { position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: left .2s; }
.switch input:checked + .track { background: var(--brand); }
.switch input:checked + .track .thumb { left: 21px; }

/* ---------- progress ---------- */
.progress { margin: 16px 0 6px; text-align: center; }
.progress-bar { height: 8px; border-radius: 4px; background: var(--line); overflow: hidden; margin: 6px 0; }
.progress-bar > div { height: 100%; width: 0; background: linear-gradient(90deg, var(--brand), var(--brand-2)); transition: width .3s ease; }
.progress-dog { font-size: 28px; display: inline-block; animation: trot .5s ease-in-out infinite alternate; }
@keyframes trot { from { transform: translateX(-30px) rotate(-6deg); } to { transform: translateX(30px) rotate(6deg); } }

/* ---------- loop cards ---------- */
.loop-list { display: grid; gap: 10px; margin-top: 14px; }
.loop-card {
  background: var(--card);
  border-radius: 16px;
  padding: 12px 14px;
  border: 2px solid transparent;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,.06);
  transition: border-color .15s, transform .15s;
  animation: pop-in .35s ease both;
}
.loop-card:hover { transform: translateY(-1px); }
.loop-card.selected { border-color: var(--loop-color); }
@keyframes pop-in { from { opacity: 0; transform: translateY(8px) scale(.98); } }
.loop-top { display: flex; align-items: center; gap: 10px; }
.loop-icon { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; font-size: 22px; background: color-mix(in srgb, var(--loop-color) 18%, transparent); flex: none; }
.loop-title { font-family: 'Fredoka', sans-serif; font-weight: 600; font-size: 17px; }
.loop-blurb { font-size: 12.5px; color: var(--muted); }
.loop-km { margin-left: auto; text-align: right; font-weight: 800; font-size: 17px; color: var(--loop-color); }
.loop-km small { display: block; font-size: 11px; color: var(--muted); font-weight: 600; }
.meters { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px 14px; margin: 10px 0 6px; }
.meter { font-size: 11px; color: var(--muted); font-weight: 700; }
.meter-bar { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; margin-top: 3px; }
.meter-bar > div { height: 100%; border-radius: 3px; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.chip { font-size: 12px; padding: 2px 8px; border-radius: 10px; background: var(--brand-soft); font-weight: 700; }
.chip.new { background: color-mix(in srgb, var(--brand-2) 25%, transparent); }
.loop-actions { display: flex; gap: 8px; margin-top: 10px; }
.loop-actions .btn { flex: 1; padding: 9px; font-size: 13px; }
.warn { font-size: 12px; color: #b92b2b; font-weight: 700; margin-top: 6px; }

.legend { font-size: 12px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 6px 12px; }
.map-key {
  background: var(--card); color: var(--ink); border-radius: 12px; padding: 8px 10px;
  box-shadow: 0 2px 10px rgba(0,0,0,.2); max-width: 240px; max-height: 40vh; overflow-y: auto;
  flex-direction: column; gap: 4px; font-weight: 600;
}
.map-key-title { font-weight: 800; font-size: 12px; margin-bottom: 2px; }
@media (max-width: 720px) {
  /* the bottom sheet covers the bottom corner on phones: float the key at the top left */
  .map-key { position: fixed; top: 10px; left: 10px; max-width: 170px; max-height: 30vh; font-size: 11px; }
}
.legend .swatch { display: inline-block; width: 18px; height: 4px; border-radius: 2px; vertical-align: middle; margin-right: 4px; }

.empty { text-align: center; padding: 18px 8px; color: var(--muted); font-weight: 600; }
.empty .big-emoji { font-size: 36px; display: block; margin-bottom: 6px; }

/* ---------- passport ---------- */
.passport-head { display: flex; align-items: center; gap: 12px; background: var(--card); border-radius: 16px; padding: 12px; }
.rank { font-size: 34px; width: 56px; height: 56px; display: grid; place-items: center; background: var(--brand-soft); border-radius: 50%; }
.rank-title { font-family: 'Fredoka', sans-serif; font-weight: 600; font-size: 19px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 10px 0; }
.stats > div { background: var(--card); border-radius: 12px; padding: 8px; text-align: center; }
.stats strong { display: block; font-size: 20px; color: var(--brand); }
.stats span { font-size: 12px; color: var(--muted); font-weight: 700; }
.section-title { font-family: 'Fredoka', sans-serif; font-weight: 600; margin: 18px 0 4px; font-size: 16px; }
.stamp-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 8px; }
.stamp {
  aspect-ratio: 1; border-radius: 50%;
  display: grid; place-items: center; text-align: center;
  border: 2px dashed var(--line); color: var(--muted);
  font-size: 10px; font-weight: 700; padding: 4px; position: relative;
}
.stamp .e { font-size: 24px; filter: grayscale(1); opacity: .35; display: block; line-height: 1.1; }
.stamp.got { border: 3px solid var(--brand-2); color: var(--ink); background: var(--card); transform: rotate(-6deg); }
.stamp.got .e { filter: none; opacity: 1; }
.stamp .n { position: absolute; top: -4px; right: -4px; background: var(--brand); color: #fff; border-radius: 10px; font-size: 10px; padding: 0 5px; }
.walk-log { list-style: none; padding: 0; margin: 6px 0; font-size: 13px; }
.walk-log li { padding: 7px 0; border-bottom: 1px solid var(--line); display: flex; gap: 8px; }
.walk-log .when { color: var(--muted); margin-left: auto; white-space: nowrap; }

/* ---------- map bits ---------- */
.emoji-marker { font-size: 20px; line-height: 1; text-align: center; filter: drop-shadow(0 1px 1px rgba(0,0,0,.35)); }
.emoji-marker.poi { filter: none; }
.poi-inner { width: 30px; height: 30px; display: grid; place-items: center; font-size: 16px; background: var(--card); border-radius: 50%; border: 2px solid #fff; box-shadow: 0 2px 6px rgba(0,0,0,.25); }
.poi-inner.wiggle { animation: sniff 1.2s ease-in-out; border-color: var(--brand-2); }
@keyframes sniff {
  0% { transform: scale(1) rotate(0); }
  15% { transform: scale(1.55) translateY(-8px) rotate(-14deg); box-shadow: 0 0 0 6px color-mix(in srgb, var(--brand-2) 45%, transparent); }
  30% { transform: scale(1.5) translateY(-8px) rotate(12deg); }
  45% { transform: scale(1.45) translateY(-6px) rotate(-10deg); }
  60% { transform: scale(1.35) translateY(-4px) rotate(8deg); }
  80% { transform: scale(1.1) rotate(-3deg); }
  100% { transform: scale(1) rotate(0); }
}
.emoji-marker.start { font-size: 30px; }
.emoji-marker.walker { font-size: 24px; transition: transform .05s linear; }
.emoji-marker.stop-marker { background: var(--brand-2); color: #fff; border-radius: 50%; width: 30px !important; height: 30px !important; display: grid !important; place-items: center; font: 800 14px 'Nunito', sans-serif; border: 3px solid #fff; box-shadow: 0 2px 6px rgba(0,0,0,.3); }
.leaflet-popup-content { font-family: 'Nunito', sans-serif; font-size: 13px; }
.popup-title { font-weight: 800; font-size: 14px; }
.leaflet-container { font-family: 'Nunito', sans-serif; }

/* ---------- toast & stamp pop ---------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 12px;
  font-weight: 700; font-size: 14px; z-index: 3000; box-shadow: var(--shadow); max-width: calc(100vw - 32px);
}
.stamp-pop {
  position: fixed; inset: 0; display: grid; place-items: center; z-index: 4000;
  background: rgba(20, 20, 15, .45); backdrop-filter: blur(2px);
}
.stamp-pop .card {
  background: var(--bg); border-radius: 24px; padding: 24px 28px; text-align: center;
  box-shadow: var(--shadow); max-width: 340px; animation: pop-in .3s ease both;
}
.stamp-pop h2 { font-family: 'Fredoka', sans-serif; margin: 4px 0 10px; color: var(--brand); }
.stamp-pop .new-stamps { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin: 12px 0 16px; }
.stamp-pop .new-stamps .stamp { width: 70px; animation: thump .5s cubic-bezier(.2,1.6,.4,1) both; }
@keyframes thump { from { transform: scale(2.4) rotate(12deg); opacity: 0; } to { transform: scale(1) rotate(-6deg); opacity: 1; } }

/* ---------- mobile: bottom sheet ---------- */
@media (max-width: 720px) {
  .panel {
    top: auto; left: 0; right: 0; bottom: 0; width: 100%; max-width: none;
    height: 58vh; border-radius: 22px 22px 0 0;
    transition: height .25s ease;
  }
  .panel.collapsed { height: 150px; }
  .panel.collapsed .tab-body, .panel.collapsed .credits { display: none; }
  .sheet-toggle { display: block; }
  .panel.collapsed .sheet-toggle { transform: rotate(180deg); }
  .brand { padding: 12px 16px 4px; }
  .tab-body { padding: 12px 16px 16px; }
  .leaflet-top.leaflet-right { top: 0; }
}

/* ---------- welcome ---------- */
.stamp-pop .welcome-card { max-width: 400px; margin: 16px; text-align: left; }
.stamp-pop .welcome-card h2, .stamp-pop .welcome-card > p { text-align: center; }
.welcome-dog { font-size: 54px; text-align: center; animation: wag 1.2s ease-in-out infinite; transform-origin: 50% 90%; }
@keyframes wag { 0%, 100% { transform: rotate(-8deg); } 50% { transform: rotate(8deg) translateY(-3px); } }
.welcome-steps { list-style: none; padding: 0; margin: 14px 0; display: grid; gap: 10px; }
.welcome-steps li { display: flex; gap: 12px; align-items: flex-start; background: var(--card); border-radius: 14px; padding: 10px 12px; font-size: 14px; animation: pop-in .4s ease both; }
.welcome-steps li:nth-child(2) { animation-delay: .1s; }
.welcome-steps li:nth-child(3) { animation-delay: .2s; }
.welcome-steps span { font-size: 22px; line-height: 1; }
.welcome-actions { display: flex; gap: 10px; }
.welcome-actions .btn { flex: 1; padding: 12px; font-size: 15px; }
.welcome-foot { margin: 12px 0 0; }

/* Dark emoji (🐾) on a dark button: give it a light backing so it stays visible. */
.emoji-chip {
  display: inline-grid; place-items: center;
  width: 1.6em; height: 1.6em; margin-left: 4px;
  border-radius: 50%; background: #fff6e6;
  font-size: 0.95em; line-height: 1; vertical-align: middle;
}

.warn.dogfree { color: #8a4fc7; }
@media (prefers-color-scheme: dark) { .warn.dogfree { color: #c39af0; } }

/* ---------- live GPS ---------- */
#locateBtn.live { border-color: #2f80ed; color: #2f80ed; }
.gps-dot { width: 18px; height: 18px; border-radius: 50%; background: #2f80ed; border: 3px solid #fff; box-shadow: 0 0 0 0 rgba(47,128,237,.6); animation: gps-pulse 1.8s ease-out infinite; }
@keyframes gps-pulse { to { box-shadow: 0 0 0 16px rgba(47,128,237,0); } }

/* ---------- rain window ---------- */
.rain-box { background: var(--card); border-radius: 14px; margin: 0 0 12px; font-size: 13px; border: 2px solid transparent; }
.rain-box.rainy { border-color: color-mix(in srgb, #1971fa 45%, transparent); }
.rain-box summary { display: block; padding: 10px 12px; cursor: pointer; list-style: none; }
.rain-row { display: flex; align-items: center; gap: 8px; }
.rainy-switch { background: none; border: 0; padding: 0; margin: 10px 0 0; color: var(--ink); font: inherit; font-weight: 700; font-size: 14px; text-align: left; }
.rainy-switch.on .track { background: var(--brand); }
.rainy-switch.on .thumb { left: 21px; }
.rain-box .weather-note { margin-top: 0; margin-bottom: 8px; }
.rain-box summary::-webkit-details-marker { display: none; }
.rain-box-title { font-weight: 800; }
.rain-summary { margin-left: auto; font-weight: 700; color: var(--muted); }
.rain-box.rainy .rain-summary { color: #1560d8; }
.rain-chev { transition: transform .2s; color: var(--muted); }
.rain-box[open] .rain-chev { transform: rotate(180deg); }
.rain-box > :not(summary) { margin-left: 12px; margin-right: 12px; }
.rain-box > :last-child { margin-bottom: 12px; }
#rainWindow { margin-bottom: 10px; }
.rain-head { display: flex; justify-content: space-between; margin-bottom: 6px; }
.rain-bars { display: flex; align-items: flex-end; gap: 3px; height: 34px; }
.rain-bar { flex: 1; height: 100%; display: flex; align-items: flex-end; border-radius: 4px; }
.rain-bar span { display: block; width: 100%; border-radius: 3px; background: var(--line); }
.rain-bar.wet span { background: #4e97ff; }
.rain-bar.walk { background: color-mix(in srgb, var(--brand) 18%, transparent); }
.rain-bar.walk span { outline: 1.5px solid var(--brand); }
.rain-axis { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: 2px; }
.rain-verdict { margin-top: 6px; font-weight: 700; }

/* ---------- rain legend (also the radar on/off switch) ---------- */
.rain-legend {
  display: block; text-align: left;
  width: calc(100% - 24px); background: transparent; color: var(--ink); border: 0; border-top: 1px solid var(--line);
  padding: 8px 0 0; font: 700 12px 'Nunito', sans-serif;
}
.rain-legend-title { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.rain-legend-switch { width: 26px; height: 15px; border-radius: 8px; background: var(--brand); position: relative; transition: background .2s; }
.rain-legend-switch span { position: absolute; top: 2px; left: 13px; width: 11px; height: 11px; border-radius: 50%; background: #fff; transition: left .2s; }
.rain-legend-bar { display: flex; height: 8px; border-radius: 3px; overflow: hidden; transition: opacity .2s, filter .2s; }
.rain-legend-bar span { flex: 1; }
.rain-legend-axis { display: flex; justify-content: space-between; color: var(--muted); font-weight: 600; margin-top: 2px; }

/* ---------- rain time slider ---------- */
.rain-time { display: flex; gap: 10px; align-items: center; padding: 8px 0; border-top: 1px solid var(--line); margin-bottom: 4px; }
.rain-time .btn { width: 40px; height: 40px; padding: 0; font-size: 16px; flex: none; }
.rain-time-main { flex: 1; }
.rain-time input[type='range'] { accent-color: #1971fa; }
.emoji-marker.walker .wet { position: absolute; top: -14px; left: 12px; font-size: 18px; }

/* ---------- accessibility ---------- */
:focus-visible { outline: 3px solid var(--brand-2); outline-offset: 2px; }
.loop-card:focus-visible { outline-offset: 3px; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; scroll-behavior: auto !important; }
}
@media (prefers-color-scheme: dark) {
  .btn.primary { color: #1d1f1c; } /* light green button needs dark text in dark mode */
  .warn { color: #ff8a80; }
  .rain-box.rainy .rain-summary { color: #8ab8ff; }
}

/* ---------- features document ---------- */
.features-btn {
  position: fixed; top: 16px; left: 422px; z-index: 1000;
  border: 0; border-radius: 12px; padding: 9px 14px; cursor: pointer;
  background: var(--card); color: var(--ink); font: 800 13px 'Nunito', sans-serif;
  box-shadow: 0 4px 14px rgba(0,0,0,.2);
}
.features-btn:hover { transform: translateY(-1px); }
.stamp-pop .features-card { position: relative; max-width: 560px; max-height: calc(100vh - 48px); overflow-y: auto; margin: 16px; text-align: left; }
.features-x { position: absolute; top: 12px; right: 12px; border: 0; background: var(--line); color: var(--ink); width: 34px; height: 34px; border-radius: 50%; font-size: 15px; cursor: pointer; }
.features-head { font-size: 40px; text-align: center; }
.stamp-pop .features-card h2, .stamp-pop .features-card > p { text-align: center; }
.features-list { list-style: none; padding: 0; margin: 14px 0; display: grid; gap: 8px; }
.features-list li { display: flex; gap: 12px; background: var(--card); border-radius: 12px; padding: 10px 12px; font-size: 14px; line-height: 1.45; }
.features-list span { font-size: 22px; line-height: 1.2; flex: none; }
.features-foot { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); font-size: 13px; font-weight: 700; text-align: center; }
.features-foot a { color: var(--brand); }
@media (max-width: 720px) {
  .features-btn { top: 10px; left: 10px; padding: 8px 11px; font-size: 12px; }
  .map-key { top: 54px; }
}
