/* ParkScore — phone-first layout.
 *
 * There is a separate desktop app for the hackathon, so this is a single
 * mobile layout rather than a responsive one. On a wide screen it centres at a
 * phone-ish width so it reads as intentional instead of stretched.
 *
 * Deliberate mobile choices, each of which fixes a real defect:
 *  - 16px form fields, because iOS Safari zooms the page when focusing anything
 *    smaller.
 *  - 100dvh rather than 100vh, so the mobile browser's collapsing address bar
 *    does not leave the layout taller than the visible area.
 *  - env(safe-area-inset-*) padding so controls clear the notch and home bar.
 *  - 44px minimum hit targets.
 */

:root {
  --ink: #1c2321;
  --muted: #5f6b66;
  --line: #d8e0dc;
  --bg: #f6f8f7;
  --panel: #fff;
  --accent: #2f6f4e;
  --accent-ink: #fff;
  --danger: #a3301f;
  --tap: 44px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overscroll-behavior-y: contain;
}

body {
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

/* The whole app is one column; on a desktop window it centres rather than
   stretching controls across 2000px. */
.app-frame,
body > header,
body > nav,
body > main {
  max-width: 560px;
  margin-inline: auto;
}

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
}

/* --- Controls --- */

input[type="search"], input[type="text"], select, textarea {
  /* 16px minimum: anything smaller triggers iOS focus zoom. */
  font: inherit;
  font-size: 16px;
  padding: 10px 12px;
  min-height: var(--tap);
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: inherit;
}

button {
  font: inherit;
  font-size: 15px;
  min-height: var(--tap);
  padding: 10px 14px;
  border: 1px solid var(--accent);
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-ink);
  cursor: pointer;
  touch-action: manipulation;
}

button:active { filter: brightness(0.92); }

button.ghost {
  background: #fff;
  color: var(--accent);
}

/* --- Header --- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  gap: 8px;
  padding: calc(10px + var(--safe-top)) calc(12px + var(--safe-right)) 10px
           calc(12px + var(--safe-left));
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  text-decoration: none;
  color: inherit;
}

/* Logo ships on a white canvas with no alpha, matching the header, so it needs
   no frame. The radius just softens the corners. */
.brand img {
  display: block;
  width: 30px;
  height: 30px;
  border-radius: 7px;
}

.topbar h1 {
  margin: 0;
  font-size: 18px;
  letter-spacing: -0.01em;
}

#search-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px;
}

.status {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
  min-height: 18px;
}

.status.error { color: var(--danger); font-weight: 600; }

/* --- View switcher --- */

.mobile-bar {
  position: sticky;
  top: 0;
  z-index: 15;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 8px calc(12px + var(--safe-right)) 8px calc(12px + var(--safe-left));
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: #e7ece9;
  border-radius: 10px;
  padding: 3px;
}

.seg {
  background: none;
  border: 0;
  color: var(--muted);
  border-radius: 8px;
  min-height: 36px;
  padding: 6px 10px;
  font-weight: 600;
}

.seg.is-active {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 1px 2px rgb(0 0 0 / 12%);
}

#filters-toggle { background: #fff; color: var(--accent); }

.filter-count {
  display: inline-block;
  margin-left: 6px;
  min-width: 20px;
  padding: 0 5px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  line-height: 19px;
  text-align: center;
}

/* --- Panes --- */

main {
  position: relative;
  /* Fill what is left below the two sticky bars. dvh tracks the collapsing
     address bar; vh does not. */
  height: calc(100dvh - 172px);
  min-height: 320px;
}

.results, .mapwrap {
  height: 100%;
  background: var(--panel);
}

.results {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0 calc(12px + var(--safe-right)) calc(16px + var(--safe-bottom))
           calc(12px + var(--safe-left));
}

.results h2 {
  margin: 0;
  padding: 12px 0 8px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
}

#map { width: 100%; height: 100%; }

/* Exactly one pane is visible at a time; showView() sets the body class. */
.results, .mapwrap, .askwrap { display: none; }
body.view-list .results { display: block; }
body.view-map .mapwrap { display: block; }
body.view-ask .askwrap { display: block; }

.segmented-3 { grid-template-columns: 1fr 1fr 1fr; }

/* --- Ask pane --- */

.askwrap {
  height: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--panel);
  padding: 12px calc(14px + var(--safe-right)) calc(20px + var(--safe-bottom))
           calc(14px + var(--safe-left));
}

.askwrap h2 {
  margin: 0 0 10px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
}

#ask-form { display: grid; gap: 8px; }
#ask-input { resize: vertical; min-height: 76px; }

.ask-status { margin: 8px 0 0; font-size: 13px; color: var(--muted); }
.ask-status.error { color: var(--danger); font-weight: 600; }

.ask-answer {
  margin-top: 12px;
  padding: 12px 13px;
  background: var(--bg);
  border-radius: 10px;
  border-left: 3px solid var(--accent);
  font-size: 15px;
  line-height: 1.5;
}

/* The trace is the point: it shows the answer came from real tool calls. */
.ask-trace { margin-top: 12px; font-size: 13px; color: var(--muted); }
.ask-trace summary { cursor: pointer; min-height: 32px; padding: 6px 0; }
.ask-trace ol { margin: 4px 0 0; padding-left: 20px; }
.ask-trace li { padding: 3px 0; font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px; overflow-wrap: anywhere; }

.ask-examples { list-style: none; margin: 18px 0 0; padding: 0; display: grid; gap: 6px; }

.ask-examples button {
  width: 100%;
  text-align: left;
  background: #fff;
  color: var(--accent);
  border: 1px solid var(--line);
  font-size: 14px;
  padding: 11px 12px;
}

/* --- Park list --- */

#park-list { list-style: none; margin: 0; padding: 0; }

.park { border-bottom: 1px solid var(--line); }

.park-open {
  display: block;
  width: 100%;
  min-height: var(--tap);
  text-align: left;
  background: none;
  border: 0;
  border-radius: 0;
  color: inherit;
  padding: 12px 2px;
}

.park-open:active { background: var(--bg); filter: none; }

.park-name { display: block; font-weight: 600; font-size: 16px; }
.park-meta, .park-rating, .park-amenities { display: block; font-size: 13px; color: var(--muted); }
.park-amenities { margin-top: 3px; font-size: 12px; }

.empty, .muted { color: var(--muted); font-style: italic; }
.pad { padding: 16px; }

/* --- Filters sheet --- */

.filters {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 40;
  max-height: 82dvh;
  overflow-y: auto;
  background: var(--panel);
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -6px 28px rgb(0 0 0 / 22%);
  padding: 16px calc(16px + var(--safe-right)) calc(16px + var(--safe-bottom))
           calc(16px + var(--safe-left));
  /* Off-screen by default; a transform animates more smoothly than height. */
  transform: translateY(102%);
  transition: transform 0.22s ease;
  max-width: 560px;
  margin-inline: auto;
}

body.filters-open .filters { transform: translateY(0); }

body.filters-open::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgb(0 0 0 / 35%);
}

.filters h2 {
  margin: 0 0 12px;
  font-size: 17px;
}

fieldset { border: 0; padding: 0; margin: 0 0 20px; }
legend { font-weight: 600; padding: 0 0 8px; }

/* Generous rows: a 20px checkbox with a 13px label is not a phone target. */
.filters label {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: var(--tap);
  cursor: pointer;
}

.filters input[type="checkbox"] { width: 20px; height: 20px; flex: none; }
input[type="range"] { width: 100%; height: var(--tap); }

.chips { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 12px; }
.chip { display: flex; align-items: center; gap: 8px; font-size: 15px; }

.sheet-done { width: 100%; }

/* --- Detail sheet --- */

#detail {
  position: fixed;
  inset: 0;
  width: 100%;
  max-width: 560px;
  max-height: none;
  height: 100dvh;
  margin: 0 auto;
  border: 0;
  padding: 0;
  background: var(--panel);
}

#detail::backdrop { background: rgb(0 0 0 / 55%); }

#detail-close {
  position: sticky;
  top: 0;
  float: right;
  z-index: 5;
  margin: 8px 12px 0 0;
  width: var(--tap);
  height: var(--tap);
  min-height: var(--tap);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: #fff;
  color: var(--ink);
  font-size: 24px;
  line-height: 1;
}

#detail-body {
  height: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: calc(14px + var(--safe-top)) calc(16px + var(--safe-right))
           calc(28px + var(--safe-bottom)) calc(16px + var(--safe-left));
}

#detail h2 { margin: 0 0 4px; font-size: 21px; }

#detail h3 {
  margin: 22px 0 8px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
}

#detail h4 { margin: 0 0 4px; font-size: 15px; }

.detail-sub, .detail-rating { margin: 0 0 4px; color: var(--muted); font-size: 14px; }

/* Shown only when a park has a licence-checked photo, which is rare. */
.photo { margin: 14px 0 0; }

.photo img {
  display: block;
  width: 100%;
  max-height: 240px;
  object-fit: cover;
  border-radius: 10px;
  background: var(--bg);
}

.photo figcaption {
  margin-top: 6px;
  font-size: 12px;
  color: var(--muted);
}

.photo figcaption a { color: var(--muted); }

.amenity-grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
}

.amenity-grid li {
  background: var(--bg);
  border-radius: 7px;
  padding: 8px 9px;
  font-size: 13px;
}

.fields { margin: 0; }

.field {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 8px;
  padding: 5px 0;
  font-size: 14px;
}

.field dt { color: var(--muted); }
.field dd { margin: 0; overflow-wrap: anywhere; }

.reviews { list-style: none; margin: 0; padding: 0; }
.reviews li { border-bottom: 1px solid var(--line); padding: 10px 0; font-size: 14px; }
.reviews p { margin: 4px 0 0; }

.review-form { margin-top: 22px; display: grid; gap: 12px; }
.review-form label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.review-form button { width: 100%; }
.form-status { margin: 0; font-size: 13px; color: var(--muted); }

/* Leaflet's default controls are tuned for a mouse. */
.leaflet-touch .leaflet-bar a {
  width: 34px;
  height: 34px;
  line-height: 34px;
}
