:root {
  --accent: #d6336c;
  --accent-dark: #a61e4d;
  --text: #212529;
  --muted: #6c757d;
  --border: #dee2e6;
  --bg: #ffffff;
  --hover: #f1f3f5;
  --topbar-height: 64px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
}

* { box-sizing: border-box; }

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

body {
  display: flex;
  flex-direction: column;
}

/* --- Page modes: creating a pin vs. viewing a shared one --- */

body[data-mode="view"] .create-only,
body[data-mode="create"] .view-only { display: none !important; }

/* --- Top bar with search --- */

.topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1rem;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  z-index: 2;
}

.brand {
  font-size: 1.5rem;
  font-weight: 700;
  text-decoration: none;
  color: var(--text);
  white-space: nowrap;
}

.brand span { color: var(--accent); }

.search {
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  max-width: 960px;
}

.search input[type="search"] {
  flex: 1 1 280px;
  min-width: 0;
  padding: 0.6rem 0.8rem;
  font-size: 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.search input[type="search"]:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

.search button {
  padding: 0.6rem 1.1rem;
  font-size: 1rem;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: 8px;
  cursor: pointer;
}

.search button:hover { background: var(--accent-dark); }
.search button:disabled { opacity: 0.6; cursor: progress; }

.bounded {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.875rem;
  color: var(--muted);
  white-space: nowrap;
  cursor: pointer;
}

/* --- Map and result list --- */

.content {
  position: relative;
  flex: 1;
  min-height: 0;
}

#map {
  position: absolute;
  inset: 0;
  /* Long-press drops a pin: suppress the browser's own long-press callout and text selection. */
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

.results-panel {
  position: absolute;
  top: 0.75rem;
  left: 0.75rem;
  width: min(420px, calc(100% - 1.5rem));
  max-height: calc(100% - 1.5rem);
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.15);
  z-index: 1;
}

.results-panel[hidden] { display: none; }

.results-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}

.icon-button {
  font-size: 1.4rem;
  line-height: 1;
  color: var(--muted);
  background: none;
  border: none;
  cursor: pointer;
}

.results {
  margin: 0;
  padding: 0;
  list-style: none;
  overflow-y: auto;
}

.results li {
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--hover);
  cursor: pointer;
}

.results li:last-child { border-bottom: none; }

.results li:hover,
.results li.active { background: var(--hover); }

.results li[aria-selected="true"] {
  background: #fff0f6;
  box-shadow: inset 3px 0 0 var(--accent);
}

.result-name {
  font-weight: 600;
}

.result-type {
  margin-left: 0.4rem;
  font-size: 0.75rem;
  font-weight: 400;
  color: var(--muted);
  text-transform: capitalize;
}

.result-address {
  margin-top: 0.15rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.topbar-link {
  margin-left: auto;
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
}

.topbar-link:hover { text-decoration: underline; }

/* --- Cards floating over the map --- */

.card {
  position: absolute;
  left: 0.75rem;
  width: min(420px, calc(100% - 1.5rem));
  padding: 0.9rem 1rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.15);
  z-index: 1;
}

.card[hidden] { display: none; }

.card h1,
.card h2 {
  margin: 0 0 0.5rem;
  font-size: 1.15rem;
}

.card p { margin: 0.4rem 0; }

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
}

.card-address,
.card-coords,
.hint {
  font-size: 0.85rem;
  color: var(--muted);
}

.hint { margin-bottom: 0 !important; font-size: 0.8rem; }

.card-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.9rem;
  margin-top: 0.6rem;
}

.card a { color: var(--accent); }

.button,
.card button:not(.icon-button):not(.link-button):not(.nearby-item) {
  display: inline-block;
  padding: 0.45rem 0.9rem;
  font: inherit;
  font-size: 0.9rem;
  color: var(--text);
  text-decoration: none;
  background: var(--hover);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
}

.button.primary,
.card button.primary {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
}

.button.primary:hover,
.card button.primary:hover { background: var(--accent-dark); }

.link-button {
  padding: 0;
  font: inherit;
  font-size: 0.85rem;
  color: var(--accent);
  background: none;
  border: none;
  cursor: pointer;
  text-decoration: underline;
}

.feedback {
  font-size: 0.85rem;
  color: #2b8a3e;
}

/* Places near a dropped pin, listed in the share card. */
.nearby { margin: 0.5rem 0; }

.card .nearby-heading {
  margin: 0 0 0.2rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.nearby-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.nearby-item {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  width: 100%;
  padding: 0.3rem 0.4rem;
  font: inherit;
  font-size: 0.9rem;
  color: var(--text);
  text-align: left;
  background: none;
  border: none;
  border-radius: 6px;
  cursor: pointer;
}

.nearby-item:hover { background: var(--hover); }
.nearby-item:disabled { opacity: 0.6; cursor: progress; }

.nearby-name {
  min-width: 0;
  overflow: hidden;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nearby-details {
  flex-shrink: 0;
  margin-left: auto;
  font-size: 0.8rem;
  color: var(--muted);
}

/* Share card on the create page sits at the bottom, above the scale bar. */
.share-card {
  bottom: 2.5rem;
  max-height: calc(100% - 3.25rem);
  overflow-y: auto;
}

.has-pin .results-panel { max-height: calc(45% - 1rem); }

.map-hint {
  position: absolute;
  left: 50%;
  bottom: 2.5rem;
  transform: translateX(-50%);
  margin: 0;
  padding: 0.35rem 0.8rem;
  font-size: 0.8rem;
  color: var(--muted);
  white-space: nowrap;
  background: rgba(255, 255, 255, 0.92);
  border-radius: 999px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  pointer-events: none;
  z-index: 1;
}

.has-pin .map-hint { display: none; }

.field {
  display: block;
  margin-bottom: 0.5rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.field input,
.link-row input {
  display: block;
  width: 100%;
  margin-top: 0.2rem;
  padding: 0.45rem 0.6rem;
  font: inherit;
  font-size: 0.95rem;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.link-row {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.6rem;
}

.link-row input {
  flex: 1;
  min-width: 0;
  margin: 0;
  font-size: 0.85rem;
  background: var(--hover);
}

.pin-card { top: 0.75rem; }

.pin-card .pin-type {
  margin: 0 0 0.15rem;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--accent);
}

@media (max-width: 600px) {
  .topbar { flex-direction: column; align-items: stretch; gap: 0.5rem; }
  .brand { font-size: 1.25rem; }
  .topbar-link { margin-left: 0; }
  .pin-card { top: auto; bottom: 2.5rem; }
  .pin-card,
  .share-card,
  .map-hint { transition: bottom 0.2s; }
  /* While the map attribution is expanded (until the first drag), keep clear of it. */
  body:has(.maplibregl-compact-show) :is(.pin-card, .share-card, .map-hint) { bottom: 4rem; }
  body:has(.maplibregl-compact-show) .share-card { max-height: calc(100% - 4.75rem); }
}
