:root {
  --yellow: #F2B705;        /* machine paint: fresh sightings, primary actions */
  --paint-faded: #F3DD94;   /* 1 to 3 days old */
  --concrete: #B7B5AF;      /* quiet sites */
  --asphalt: #24282C;
  --cone: #D9531E;          /* "gone" and warnings */
  --cone-wash: #FCEDE6;     /* background behind safety warnings */

  --ground: #EEEFEC;
  --surface: #FFFFFF;
  --text: #24282C;
  --text-muted: #5B6168;
  --line: #D9DBD6;
  --chip: #F3F4F1;

  --m-body: var(--yellow);
  --m-dark: var(--asphalt);

  --font: 'Archivo', 'Helvetica Neue', Arial, sans-serif;
  --radius-panel: 18px;
  --radius-control: 10px;
  --shadow: 0 2px 10px rgba(20, 22, 24, .18);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ground: #15181B;
    --surface: #22262A;
    --text: #EEEEEA;
    --text-muted: #A6ABB0;
    --line: #363B40;
    --chip: #2C3135;
    --concrete: #7E7D79;
    --paint-faded: #B9A465;
    --cone-wash: #3A2219;
    --shadow: 0 2px 12px rgba(0, 0, 0, .5);
    --m-dark: #9AA0A6;  /* machine tires and glass read light on dark surfaces */
    color-scheme: dark;
  }
  .btn--dark { background: #4A525A; }
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  color: var(--text);
  background: var(--ground);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

button { font: inherit; color: inherit; }

:focus-visible {
  outline: 3px solid var(--yellow);
  outline-offset: 2px;
  box-shadow: 0 0 0 5px var(--asphalt);
}

[hidden] { display: none !important; }

/* ---------- map ---------- */

#map {
  position: fixed;
  inset: 0;
  background: var(--ground);
}

.leaflet-container { font-family: var(--font); }
.leaflet-control-attribution { font-size: 11px; }
/* OSM tiles are busy and colorful; mute them so the yellow pins stay the loudest thing on the map */
.leaflet-tile-pane { filter: saturate(.35) brightness(1.04); }
@media (prefers-color-scheme: dark) {
  .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) saturate(.3) brightness(.85) contrast(.9); }
}
.leaflet-top.leaflet-left { top: calc(var(--safe-top) + 104px); }

/* ---------- top bar ---------- */

.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  padding: calc(var(--safe-top) + 10px) 12px 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }

.wordmark {
  align-self: flex-start;
  border: 0;
  cursor: pointer;
  background: var(--yellow);
  color: var(--asphalt);
  font-weight: 900;
  font-stretch: 125%;
  font-size: 22px;
  letter-spacing: -0.01em;
  line-height: 1;
  padding: 10px 14px 9px;
  border-radius: var(--radius-control);
  box-shadow: var(--shadow);
}

.filters {
  /* --cols is set from the chip count so the grid stays close to square */
  display: grid;
  grid-template-columns: repeat(var(--cols, 4), minmax(0, 1fr));
  gap: 6px;
  width: 100%;
  max-width: 560px;
  padding-bottom: 6px;
}
.filters .chip {
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  min-height: 52px;
  padding: 5px 4px;
  border-radius: var(--radius-control);
  font-size: 12px;
  line-height: 1.15;
  text-align: center;
}
.filters .chip--clear { padding-left: 4px; }

.chip {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 2px solid transparent;
  background: var(--surface);
  border-radius: 999px;
  padding: 4px 12px 4px 6px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow);
}
.chip .machine { width: 30px; height: 20px; }
.chip[aria-pressed="true"] {
  --m-dark: #9AA0A6;
  background: var(--asphalt);
  color: #fff;
  border-color: var(--yellow);
}
.chip--clear { padding-left: 12px; }

/* ---------- legend ---------- */

.legend {
  position: fixed;
  z-index: 900;
  right: 12px;
  bottom: calc(var(--safe-bottom) + 84px);
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: var(--surface);
  border-radius: var(--radius-control);
  padding: 8px 12px;
  font-size: 12.5px;
  color: var(--text-muted);
  box-shadow: var(--shadow);
}
.legend span { display: flex; align-items: center; gap: 8px; }
.swatch {
  width: 14px; height: 14px;
  border-radius: 4px;
  border: 1.5px solid var(--asphalt);
}
.swatch--today { background: var(--yellow); }
.swatch--recent { background: var(--paint-faded); }
.swatch--quiet { background: var(--concrete); border-color: transparent; }
.swatch--gone { background: var(--concrete); border: 2px dashed var(--asphalt); opacity: .7; }

.legend__toggle {
  display: flex; align-items: center; gap: 8px;
  margin: 4px -6px -2px;
  padding: 6px;
  min-height: 36px;
  border: 0;
  border-top: 1px solid var(--line);
  border-radius: 6px;
  background: none;
  color: inherit;
  font: inherit;
  cursor: pointer;
}
.legend__toggle::after {
  content: 'Off';
  margin-left: auto;
  padding-left: 10px;
  font-weight: 700;
}
.legend__toggle[aria-pressed='true'] { color: var(--text); }
.legend__toggle[aria-pressed='true']::after { content: 'On'; }

/* ---------- buttons ---------- */

.btn {
  border: 0;
  cursor: pointer;
  font-weight: 700;
  font-size: 16px;
  border-radius: var(--radius-control);
  padding: 12px 18px;
  min-height: 48px;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn--primary { background: var(--yellow); color: var(--asphalt); }
.btn--dark { background: var(--asphalt); color: #fff; }
.btn--quiet { background: var(--chip); color: var(--text); }
.btn--warn { background: transparent; color: var(--cone); border: 2px solid var(--cone); }
.btn--link {
  background: none;
  padding: 8px 0;
  min-height: 0;
  font-weight: 600;
  color: var(--text-muted);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.add-btn {
  position: fixed;
  z-index: 1000;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--safe-bottom) + 20px);
  font-size: 18px;
  font-weight: 800;
  font-stretch: 112%;
  padding: 14px 28px;
  box-shadow: 0 0 0 3px var(--asphalt), var(--shadow);
}

.locate-btn {
  position: fixed;
  z-index: 1000;
  right: 12px;
  bottom: calc(var(--safe-bottom) + 20px);
  width: 48px; height: 48px;
  border: 0;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: var(--shadow);
  cursor: pointer;
  display: grid;
  place-items: center;
}
.locate-btn svg { width: 22px; height: 22px; fill: var(--text); stroke: var(--text); }

/* ---------- map pins ---------- */

.pin-wrap { background: none; border: 0; }

.pin {
  --m-body: var(--yellow);
  --m-dark: var(--asphalt);
  position: relative;
  width: 52px;
  height: 40px;
  border-radius: 10px;
  background: var(--surface);
  border: 2.5px solid var(--asphalt);
  display: grid;
  place-items: center;
  box-shadow: var(--shadow);
  cursor: pointer;
}
.pin::after {
  content: '';
  position: absolute;
  left: 50%;
  bottom: -9px;
  width: 12px; height: 12px;
  background: inherit;
  border-right: 2.5px solid var(--asphalt);
  border-bottom: 2.5px solid var(--asphalt);
  transform: translateX(-50%) rotate(45deg);
}
.pin .machine { width: 40px; height: 27px; position: relative; z-index: 1; }

.pin--today { background: var(--yellow); --m-body: #fff; }
.pin--recent { background: var(--paint-faded); --m-body: #fff; }
.pin--quiet {
  background: var(--concrete);
  border-color: transparent;
  --m-body: #ECEBE7;
  --m-dark: #5E5D59;
}
.pin--quiet::after { border-color: transparent; }

.pin__more {
  position: absolute;
  z-index: 2;
  top: -9px;
  right: -9px;
  min-width: 22px;
  height: 22px;
  padding: 0 5px;
  border-radius: 11px;
  background: var(--asphalt);
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  display: grid;
  place-items: center;
}

.pin--gone { filter: grayscale(1); border-style: dashed; opacity: .6; }
.pin--gone.pin--selected { opacity: 1; }
.pin--selected { outline: 3px solid var(--asphalt); outline-offset: 3px; }

/* ---------- placing a new pin ---------- */

.placing__crosshair {
  position: fixed;
  z-index: 950;
  left: 50%;
  top: 50%;
  pointer-events: none;
}
.placing__crosshair span {
  position: absolute;
  left: -14px;
  top: -38px;
  width: 28px;
  height: 28px;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  background: var(--yellow);
  border: 3px solid var(--asphalt);
  box-shadow: var(--shadow);
}
.placing__crosshair::after {
  content: '';
  position: absolute;
  left: -4px; top: -2px;
  width: 8px; height: 4px;
  border-radius: 50%;
  background: rgba(0, 0, 0, .35);
}

.placing__bar {
  position: fixed;
  z-index: 1001;
  left: 12px;
  right: 12px;
  bottom: calc(var(--safe-bottom) + 16px);
  max-width: 460px;
  margin: 0 auto;
  background: var(--surface);
  border-radius: var(--radius-panel);
  padding: 14px 16px 16px;
  box-shadow: var(--shadow);
}
.placing__bar p { margin: 0 0 12px; font-weight: 600; }
.placing__actions { display: flex; gap: 8px; }
.placing__actions .btn { flex: 1; }

body.is-placing .add-btn,
body.is-placing .legend,
body.is-placing .filters,
body.is-placing .locate-btn { display: none; }

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

.sheet {
  position: fixed;
  z-index: 1100;
  left: 0;
  right: 0;
  bottom: 0;
  /* leave a third of the screen for the map so the selected pin stays in view */
  max-height: 64vh;
  max-height: 64dvh;
  background: var(--surface);
  border-radius: var(--radius-panel) var(--radius-panel) 0 0;
  box-shadow: 0 -4px 24px rgba(0, 0, 0, .25);
  display: flex;
  flex-direction: column;
  animation: sheet-in .22s ease-out;
}
.sheet.is-dragging { animation: none; }
.sheet.is-snapping { transition: height .2s ease-out; }

/* Drag to resize (peek, half, full), tap to toggle half and full. Phones only. */
.sheet__handle {
  flex: none;
  display: grid;
  place-items: center;
  height: 28px;
  margin-right: 64px; /* keep clear of the close button */
  border: 0;
  background: none;
  cursor: grab;
  touch-action: none;
}
.sheet__handle::before {
  content: '';
  width: 44px; height: 5px;
  border-radius: 3px;
  background: var(--line);
  margin-left: 64px; /* re-center over the full sheet width */
}
.sheet.is-dragging .sheet__handle { cursor: grabbing; }

@keyframes sheet-in {
  from { transform: translateY(24px); opacity: 0; }
  to { transform: none; opacity: 1; }
}

.sheet__close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 44px; height: 44px;
  border: 0;
  border-radius: 50%;
  background: var(--chip);
  box-shadow: 0 0 0 4px var(--surface);
  cursor: pointer;
  display: grid;
  place-items: center;
  z-index: 2;
}
.sheet__close svg { width: 18px; height: 18px; stroke: var(--text); }

.sheet__body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 10px 20px calc(var(--safe-bottom) + 24px);
}

@media (min-width: 760px) {
  .sheet {
    top: calc(var(--safe-top) + 12px);
    bottom: 12px;
    left: 12px;
    right: auto;
    width: 400px;
    max-height: none;
    border-radius: var(--radius-panel);
  }
  .sheet__handle { display: none; }
  .sheet__body { padding-top: 20px; }
  body.has-sheet .topbar { left: 424px; }
  body.has-sheet .leaflet-top.leaflet-left { left: 424px; }
  body.has-sheet .add-btn { left: calc(50% + 212px); }
}

@media (max-width: 759px) {
  body.has-sheet .add-btn,
  body.has-sheet .legend,
  body.has-sheet .locate-btn,
  body.has-sheet .filters { display: none; } /* filters don't apply inside a site; free the map strip */
}
/* The title takes focus for screen readers when the sheet opens; no ring for that. */
.sheet h2[tabindex="-1"]:focus { outline: none; box-shadow: none; }

/* ---------- sheet content ---------- */

.sheet h2 {
  font-size: 26px;
  font-weight: 800;
  font-stretch: 112%;
  line-height: 1.1;
  letter-spacing: -0.01em;
  margin: 6px 56px 6px 0;
}
.sheet h3 {
  font-size: 17px;
  font-weight: 700;
  margin: 24px 0 10px;
}
.sheet p { margin: 0 0 10px; max-width: 60ch; }

.status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.status .swatch { flex: none; }

.machines-now {
  list-style: none;
  padding: 0;
  margin: 14px 0 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  gap: 8px;
}
.machines-now li {
  background: var(--chip);
  border-radius: var(--radius-control);
  padding: 10px 8px 8px;
  text-align: center;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.2;
}
.machines-now .machine { width: 72px; height: 48px; display: block; margin: 0 auto 4px; }
.machines-now .count {
  display: block;
  font-size: 20px;
  font-weight: 900;
  font-stretch: 112%;
}
.is-quiet .machines-now { --m-body: var(--concrete); }

.facts { margin: 16px 0 0; display: grid; gap: 4px; }
.facts div { display: flex; gap: 8px; }
.facts dt { color: var(--text-muted); flex: none; }
.facts dd { margin: 0; font-weight: 600; }

.stats { grid-template-columns: 1fr 1fr; gap: 8px; }
.stats div { flex-direction: column-reverse; gap: 0; background: var(--chip); border-radius: var(--radius-control); padding: 10px 12px; }
.stats dd { font-size: 24px; font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stats dt { font-size: 14px; }

.notice {
  border-left: 4px solid var(--cone);
  padding: 4px 0 4px 12px;
  margin: 16px 0 0;
  font-weight: 600;
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 20px;
}
.actions .btn--primary { grid-column: 1 / -1; font-size: 18px; }
.actions-note { font-size: 14px; color: var(--text-muted); margin-top: 8px; }

.links { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; margin-top: 12px; }
.links .btn--link { padding: 10px 0; font-size: 16px; }
.links .btn--link-warn { color: var(--cone); }
.links a { color: var(--text-muted); font-weight: 600; text-underline-offset: 3px; }

.history { list-style: none; padding: 0; margin: 0; }
.history li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 0;
  border-top: 1px solid var(--line);
  font-size: 15px;
}
.history time { color: var(--text-muted); flex: none; }

/* ---------- safety ---------- */

.warn-icon { width: 22px; height: 22px; flex: none; }

.stay-back {
  margin: 14px 0 0;
  padding: 12px 14px 4px;
  border-radius: var(--radius-control);
  border: 2px solid var(--cone);
  background: var(--cone-wash);
}
.sheet .stay-back h3 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 6px;
  font-size: 17px;
  font-weight: 800;
}
.stay-back p { font-size: 15px; }
.watch-from { margin: 0 0 8px; padding-left: 22px; font-weight: 700; }
.watch-from li { margin: 2px 0; }
.watch-out-title { font-weight: 800; margin: 4px 0 2px !important; }

.safety-rules { margin: 12px 0 0; padding-left: 22px; display: grid; gap: 8px; }
.safety-rules li { padding-left: 2px; }

.disclosure {
  margin-top: 16px !important;
  padding: 10px 12px;
  border-radius: var(--radius-control);
  background: var(--chip);
  font-size: 14px;
}

.confirm {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  margin-top: 20px;
  padding: 12px;
  border-radius: var(--radius-control);
  border: 2px solid var(--line);
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
}
.confirm:has(input:checked) { border-color: var(--asphalt); }
.confirm input { width: 24px; height: 24px; margin: 0; flex: none; accent-color: var(--asphalt); }

/* First visit: nothing else is usable until this is acknowledged */
.safety-intro {
  position: fixed;
  inset: 0;
  z-index: 1300;
  background: rgba(20, 22, 24, .72);
  display: grid;
  place-items: end center;
  overscroll-behavior: contain;
}
.safety-card {
  width: 100%;
  max-width: 480px;
  max-height: 92dvh;
  overflow-y: auto;
  background: var(--surface);
  border-radius: var(--radius-panel) var(--radius-panel) 0 0;
  border-top: 8px solid var(--cone);
  padding: 20px 20px calc(var(--safe-bottom) + 20px);
}
.safety-card h2 {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 8px;
  font-size: 26px;
  font-weight: 800;
  font-stretch: 112%;
  line-height: 1.1;
}
.safety-card h2 .warn-icon { width: 30px; height: 30px; }
.safety-card h2:focus, .safety-card h2:focus-visible { outline: none; box-shadow: none; }
.safety-card .lede { font-weight: 700; margin: 0; }
.safety-card .btn { width: 100%; margin-top: 12px; font-size: 18px; }
@media (min-width: 760px) {
  .safety-intro { place-items: center; }
  .safety-card { border-radius: var(--radius-panel); }
}
body.has-safety-intro .topbar,
body.has-safety-intro .add-btn,
body.has-safety-intro .legend,
body.has-safety-intro .locate-btn { visibility: hidden; }

/* ---------- forms ---------- */

fieldset { border: 0; padding: 0; margin: 22px 0 0; min-width: 0; }
legend.q {
  font-size: 17px;
  font-weight: 700;
  padding: 0;
  margin-bottom: 10px;
}
.q-hint { font-weight: 400; color: var(--text-muted); font-size: 14px; }

.options { display: flex; flex-wrap: wrap; gap: 8px; }
.option { position: relative; }
.option input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.option span {
  display: block;
  padding: 10px 14px;
  border-radius: var(--radius-control);
  background: var(--chip);
  border: 2px solid transparent;
  font-weight: 600;
  font-size: 15px;
}
.option input:checked + span {
  background: var(--asphalt);
  color: #fff;
  border-color: var(--yellow);
}
.option input:focus-visible + span {
  outline: 3px solid var(--yellow);
  outline-offset: 2px;
}
.options--stack { flex-direction: column; }
.option span { min-height: 44px; display: flex; align-items: center; }
.options--check .option span { gap: 10px; }
.options--check .option span::before {
  content: '';
  width: 20px; height: 20px;
  flex: none;
  border-radius: 5px;
  border: 2px solid var(--text-muted);
  background: var(--surface);
}
.options--check .option input:checked + span::before {
  border-color: var(--yellow);
  background: var(--yellow) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath d='M4.5 10.5l3.5 3.5 7.5-8' fill='none' stroke='%2324282C' stroke-width='2.8'/%3E%3C/svg%3E") center / 16px no-repeat;
}

.submit-row--stack { flex-direction: column; }
.submit-row--stack .btn { width: 100%; text-align: center; text-decoration: none; }

.picker {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  gap: 8px;
}
.pick {
  position: relative;
  background: var(--chip);
  border-radius: var(--radius-control);
  border: 2px solid transparent;
  --m-body: var(--concrete);
  text-align: center;
}
.pick__toggle {
  width: 100%;
  border: 0;
  background: none;
  cursor: pointer;
  padding: 10px 6px 8px;
  font-weight: 600;
  font-size: 14px;
  line-height: 1.2;
  border-radius: inherit;
}
.pick .machine { width: 72px; height: 48px; display: block; margin: 0 auto 4px; }
.pick.is-on {
  --m-body: var(--yellow);
  border-color: var(--asphalt);
  background: var(--surface);
}
.pick__count {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 6px 8px;
}
.pick__count button {
  width: 40px; height: 40px;
  border-radius: 50%;
  border: 0;
  background: var(--asphalt);
  color: #fff;
  font-size: 20px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
}
.pick__count output { font-size: 20px; font-weight: 900; font-stretch: 112%; }

.form-error {
  color: var(--cone);
  font-weight: 700;
  margin-top: 12px;
}

.submit-row { margin-top: 24px; display: flex; gap: 8px; }
.submit-row .btn--primary { flex: 1; font-size: 18px; }

.nearby { list-style: none; padding: 0; margin: 12px 0 0; display: grid; gap: 8px; }
.nearby button {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
  background: var(--chip);
  border: 0;
  border-radius: var(--radius-control);
  padding: 10px 12px;
  cursor: pointer;
}
.nearby .machine { width: 54px; height: 36px; flex: none; }
.nearby strong { display: block; }
.nearby small { color: var(--text-muted); font-size: 14px; }

/* ---------- toast ---------- */

.toast {
  position: fixed;
  z-index: 1200;
  left: 50%;
  top: calc(var(--safe-top) + 16px);
  transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  background: var(--asphalt);
  color: #fff;
  padding: 12px 18px;
  border-radius: var(--radius-control);
  font-weight: 600;
  box-shadow: var(--shadow);
}
.toast.is-error { background: var(--cone); }

/* ---------- motion ---------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- machine drawings ---------- */

.machine .b { fill: var(--m-body); }
.machine .d { fill: var(--m-dark); }
.machine [stroke-width] { stroke: var(--m-dark); }
.machine .d[fill="none"] { fill: none; }
