:root {
  --bg: #0a3d62;
  --accent: #3c9ed9;
  --danger: #d9534f;
  --ink: #1b2733;
  --muted: #6b7785;
  --star: #f5b942;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: #f4f6f8;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}

/* Page header */
.app-header {
  background: var(--bg);
  color: #fff;
  padding: calc(14px + env(safe-area-inset-top, 0px)) 16px 14px;
  text-align: center;
}
.app-header h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 0.2px;
}

/* Search bar */
.search-bar {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  background: #fff;
  border-bottom: 1px solid #e3e8ed;
}
.search-bar input {
  flex: 1;
  min-width: 0;
  padding: 12px 14px;
  font-size: 16px; /* 16px avoids iOS zoom-on-focus */
  border: 1px solid #d0d7de;
  border-radius: 10px;
  font-family: inherit;
}
.search-go {
  flex: 0 0 auto;
  padding: 0 18px;
  border: none;
  border-radius: 10px;
  background: var(--bg);
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}
.search-go:active { transform: scale(0.97); }
.search-go:disabled { opacity: 0.6; }

/* Map lives in a sized box now, not full-screen. Overlay buttons are scoped
   to this box (position: absolute relative to .map-wrap). */
.map-wrap {
  position: relative;
  height: 56vh;
  min-height: 320px;
}
#map {
  position: absolute;
  inset: 0;
  z-index: 1;
}

/* Rated fountains list */
.list-section {
  padding: 16px 16px calc(28px + var(--safe-bottom));
}
.list-heading {
  margin: 4px 2px 12px;
  font-size: 17px;
  font-weight: 800;
}
.list-count {
  color: var(--muted);
  font-weight: 600;
  font-size: 14px;
}
.fountain-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.fountain-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  background: #fff;
  border: 1px solid #e3e8ed;
  border-radius: 12px;
  cursor: pointer;
  text-align: left;
  width: 100%;
  font-family: inherit;
}
.fountain-item:active { background: #f0f4f8; }
.fountain-item .fi-name {
  font-size: 16px;
  font-weight: 700;
  color: var(--ink);
}
.fountain-item .fi-scores {
  margin-top: 3px;
  font-size: 13px;
  color: var(--muted);
}
.fountain-item .fi-chevron {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 20px;
}
.list-empty {
  color: var(--muted);
  font-size: 15px;
  line-height: 1.5;
  margin: 4px 2px;
}

/* Add-fountain button — labeled pill, bottom-center, hard to mistake for zoom */
.add-btn {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 16px 28px;
  border: none;
  border-radius: 999px;
  background: var(--bg);
  color: #fff;
  font-size: 17px;
  font-weight: 700;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
  z-index: 1000;
  cursor: pointer;
}
.add-btn:active { transform: translateX(-50%) scale(0.96); }

/* Export — small secondary button, top-right corner of the map */
.export-btn {
  position: absolute;
  right: 12px;
  top: 12px;
  padding: 10px 16px;
  border: none;
  border-radius: 999px;
  background: #fff;
  color: var(--bg);
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  z-index: 1000;
  cursor: pointer;
}
.export-btn:active { transform: scale(0.96); }

/* Placement bar — floats at the bottom while you position a new pin.
   Intentionally NOT a full-screen overlay, so the map stays draggable. */
.place-bar {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 16px;
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.28);
  padding: 12px;
  z-index: 1700;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.place-bar-text {
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  text-align: center;
  padding: 2px 0 4px;
}
.place-bar-row {
  display: flex;
  gap: 8px;
}
.place-bar > .btn {
  flex: none;
  width: 100%;
  margin: 0;
}

/* Helper row inside the new-fountain form */
.place-help {
  background: #eaf4fb;
  border: 1px solid #cfe6f5;
  color: var(--ink);
  padding: 11px 13px;
  border-radius: 10px;
  font-size: 14px;
  line-height: 1.5;
  margin-bottom: 16px;
}
.btn-link {
  background: none;
  border: none;
  color: var(--accent);
  font-weight: 700;
  font-size: 14px;
  padding: 0;
  cursor: pointer;
  text-decoration: underline;
}

/* Toast */
.toast {
  position: fixed;
  bottom: calc(20px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 12px 18px;
  border-radius: 10px;
  font-size: 15px;
  z-index: 1500;
  max-width: 84vw;
  text-align: center;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3);
}
.toast.error { background: var(--danger); }

/* Detail sheet */
.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  z-index: 1800;
}

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1900;
  background: #fff;
  border-radius: 18px 18px 0 0;
  padding: 20px 20px calc(20px + var(--safe-bottom));
  box-shadow: 0 -6px 24px rgba(0, 0, 0, 0.25);
  max-height: 88vh;
  overflow-y: auto;
  animation: slideUp 0.18s ease-out;
}
@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.sheet h2 {
  margin: 0 0 16px;
  font-size: 20px;
}

.field {
  display: block;
  margin-bottom: 16px;
}
.field span {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 6px;
}
.field input,
.field textarea {
  width: 100%;
  padding: 12px;
  font-size: 16px; /* 16px avoids iOS zoom-on-focus */
  border: 1px solid #d0d7de;
  border-radius: 10px;
  font-family: inherit;
  resize: vertical;
}

/* Rating rows */
.rating {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.rating-label {
  font-size: 16px;
  font-weight: 600;
}
.stars {
  display: flex;
  gap: 6px;
}
.num {
  width: 46px;
  height: 46px;
  border: none;
  background: #eef1f4;
  border-radius: 10px;
  font-size: 18px;
  font-weight: 700;
  color: var(--ink);
  cursor: pointer;
}
.num.on {
  background: var(--bg);
  color: #fff;
}
.num:active { transform: scale(0.92); }

/* Buttons */
.sheet-actions {
  display: flex;
  gap: 10px;
  margin-top: 8px;
}
.btn {
  flex: 1;
  padding: 14px;
  font-size: 16px;
  font-weight: 600;
  border: none;
  border-radius: 12px;
  cursor: pointer;
}
.btn-primary { background: var(--bg); color: #fff; }
.btn-ghost { background: #eef1f4; color: var(--ink); }
.btn-danger { background: var(--danger); color: #fff; flex: 0 0 auto; }

.hidden { display: none !important; }

/* Leaflet popup tweak */
.pin-popup b { font-size: 15px; }
.pin-popup .rt { color: var(--muted); font-size: 13px; }
