:root {
  --ink: #1f2521;
  --muted: #5d665f;
  --line: #dcdfd8;
  --paper: #fbfbf8;
  --stone: #f1f0ea;
  --accent: #2f5d46;
  --accent-ink: #ffffff;
  --shadow: 0 6px 24px rgba(20, 30, 25, .18);
  --topbar-h: 60px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--paper); display: flex; flex-direction: column; }
a { color: var(--accent); }
.muted { color: var(--muted); }
[hidden] { display: none !important; }

/* ---- Top bar ---- */
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 10px 16px;
  background: var(--paper); border-bottom: 1px solid var(--line); z-index: 1000;
  min-height: var(--topbar-h);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.2rem; color: var(--ink); text-decoration: none; white-space: nowrap; }
.brand-mark { display: block; width: 34px; height: 34px; }
.search { flex: 1; min-width: 0; max-width: 520px; }
.search input, .filters select {
  width: 100%; font: inherit; font-size: 16px; padding: 9px 12px; border: 1px solid var(--line);
  border-radius: 10px; background: #fff; color: var(--ink);
}
.search input:focus, .filters select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.filters { display: flex; gap: 8px; }
.filters select { width: auto; max-width: 230px; }
.filters .add-memorial { display: inline-flex; align-items: center; gap: 6px; flex: none; white-space: nowrap; font-size: 15px; padding: 0 14px; }
.toplinks { margin-left: auto; display: flex; gap: 14px; align-items: center; white-space: nowrap; }
.linkish { background: none; border: 0; font: inherit; color: var(--accent); cursor: pointer; text-decoration: underline; padding: 0; }

/* ---- Map layout ---- */
.layout { position: relative; flex: 1; min-height: 0; }
#map { position: absolute; inset: 0; background: #dfe6e2; }

.pin { background: none; border: 0; }
.pin span {
  display: block; width: 24px; height: 24px; margin: 1px 2px;
  background: var(--c); border: 2px solid #fff; border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg); box-shadow: 0 2px 5px rgba(0,0,0,.35);
}
.pin span::after { content: ""; position: absolute; inset: 7px; border-radius: 50%; background: #fff; }

.locate-btn {
  width: 34px; height: 34px; font-size: 20px; line-height: 1; cursor: pointer;
  background: #fff; border: 2px solid rgba(0,0,0,.2); border-radius: 4px; background-clip: padding-box;
}
.locate-btn:hover { background: #f4f4f4; }

.dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; background: var(--c); flex: none; }

/* ---- Legend ---- */
.legend { position: absolute; left: 12px; bottom: 24px; z-index: 1000; background: #fff; border-radius: 10px; box-shadow: var(--shadow); font-size: 14px; }
.legend-toggle { background: none; border: 0; font: inherit; font-weight: 600; padding: 8px 12px; cursor: pointer; width: 100%; text-align: left; }
.legend ul { list-style: none; margin: 0; padding: 0 12px 10px; }
.legend li { display: flex; align-items: center; gap: 8px; padding: 3px 0; }

/* ---- Search results & notices ---- */
.results {
  position: absolute; top: 12px; left: 56px; width: 340px; max-width: calc(100% - 72px); z-index: 1050;
  max-height: 55%; overflow: auto; background: #fff; border-radius: 12px; box-shadow: var(--shadow);
}
.results-head { margin: 0; padding: 10px 14px; font-size: 14px; color: var(--muted); border-bottom: 1px solid var(--line); }
.results ul { list-style: none; margin: 0; padding: 4px 0; }
.results button {
  display: flex; gap: 10px; align-items: center; width: 100%; text-align: left; padding: 8px 14px;
  background: none; border: 0; font: inherit; cursor: pointer; color: var(--ink);
}
.results button:hover, .results button:focus { background: var(--stone); outline: none; }
.results small { display: block; color: var(--muted); }

.notice {
  position: absolute; top: 16px; left: 50%; transform: translateX(-50%); z-index: 1050;
  background: #fff; padding: 12px 18px; border-radius: 12px; box-shadow: var(--shadow); text-align: center; max-width: calc(100% - 32px);
}

/* ---- Memorial card panel ---- */
.panel {
  position: absolute; top: 0; right: 0; bottom: 0; width: 420px; max-width: 100%; z-index: 1100;
  background: var(--paper); box-shadow: var(--shadow); overflow-y: auto;
}
.panel-close {
  position: sticky; top: 8px; float: right; margin: 8px 8px -44px 0; z-index: 2;
  width: 36px; height: 36px; border-radius: 50%; border: 0; background: rgba(255,255,255,.92);
  box-shadow: 0 1px 4px rgba(0,0,0,.25); font-size: 22px; line-height: 1; cursor: pointer;
}
#panel-body > *:not(.gallery) { padding-left: 20px; padding-right: 20px; }

.gallery { display: grid; grid-template-columns: repeat(3, 1fr); gap: 3px; }
.gallery .thumb { padding: 0; border: 0; cursor: zoom-in; background: var(--stone); aspect-ratio: 1; overflow: hidden; }
.gallery .thumb:first-child { grid-column: 1 / -1; aspect-ratio: 16 / 10; }
.gallery img { width: 100%; height: 100%; object-fit: cover; display: block; }

.card-head { padding-top: 18px; }
.badges { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.badge { font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 999px; background: var(--c); color: #fff; }
.badge.outline { background: none; color: var(--muted); border: 1px solid var(--line); }
.card-head h2 { margin: 0 0 4px; font-size: 1.45rem; line-height: 1.25; outline: none; }
.where { margin: 0 0 12px; color: var(--muted); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }

.btn {
  display: inline-block; font: inherit; font-size: 14px; font-weight: 600; padding: 8px 14px; border-radius: 10px;
  border: 1px solid var(--accent); background: var(--accent); color: var(--accent-ink); text-decoration: none; cursor: pointer;
}
.btn.ghost { background: #fff; color: var(--accent); }

.block { border-top: 1px solid var(--line); padding-top: 14px; margin-top: 14px; }
.block h3 { margin: 0 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.prose { white-space: pre-line; line-height: 1.55; }
.prose.small { font-size: 14px; color: var(--muted); }
.inscription {
  white-space: pre-line; text-align: center; font-family: Georgia, "Times New Roman", serif; font-size: 1.05rem;
  line-height: 1.6; background: var(--stone); border: 1px solid var(--line); border-radius: 6px; padding: 16px;
}
.people { list-style: none; margin: 0; padding: 0; }
.people li { padding: 8px 0; border-bottom: 1px dashed var(--line); }
.people li:last-child { border-bottom: 0; }
.people span { display: block; font-size: 14px; color: var(--muted); }
.people .notes { font-style: italic; }
dl { margin: 0; }
.field { display: flex; gap: 12px; padding: 3px 0; }
.field dt { width: 90px; color: var(--muted); flex: none; }
.field dd { margin: 0; }
.coords { font-size: 12px; color: var(--muted); padding-bottom: 24px; margin-top: 18px; }

/* ---- Dialogs ---- */
dialog { border: 0; border-radius: 14px; box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(10, 15, 12, .6); }
.about { max-width: 520px; padding: 24px; line-height: 1.5; }
.about h2 { margin-top: 0; }
.about ul { padding-left: 20px; }

.lightbox { padding: 0; background: transparent; box-shadow: none; max-width: 100vw; max-height: 100vh; overflow: visible; }
.lightbox figure { margin: 0; text-align: center; }
.lightbox img { max-width: 92vw; max-height: 82vh; display: block; margin: 0 auto; border-radius: 6px; }
.lightbox figcaption { color: #fff; padding: 10px; font-size: 15px; }
.lightbox .credit { opacity: .75; font-size: 13px; }
.lightbox button {
  position: fixed; background: rgba(0,0,0,.55); color: #fff; border: 0; font-size: 30px; width: 46px; height: 46px;
  border-radius: 50%; cursor: pointer; line-height: 1;
}
.lb-close { top: 14px; right: 14px; }
.lb-prev { left: 14px; top: 50%; }
.lb-next { right: 14px; top: 50%; }

/* ---- Phones ---- */
@media (max-width: 900px) {
  .topbar { flex-wrap: wrap; gap: 8px; padding: 8px 12px; }
  .search { order: 3; flex-basis: 100%; max-width: none; }
  .filters { order: 4; flex-basis: 100%; min-width: 0; }
  .filters select { flex: 1; min-width: 0; max-width: none; font-size: 15px; padding: 7px 8px; }
  .filters .add-memorial { padding: 0 10px; font-size: 14px; }
}
@media (max-width: 480px) {
  .add-long { display: none; }
  .panel { top: auto; height: 72%; width: 100%; border-radius: 16px 16px 0 0; }
  .results { left: 12px; right: 12px; width: auto; max-width: none; max-height: 45%; }
  .legend { bottom: 28px; }
  .panel-close { width: 42px; height: 42px; }
}

/* ---- Alpha mode ---- */
.alpha-badge {
  display: inline-block; padding: 2px 9px; border-radius: 999px; background: #fdf1d8; color: #7a5510;
  border: 1px solid #f0d9a6; font-size: 12px; font-weight: 700; letter-spacing: .03em; text-decoration: none;
  white-space: nowrap; vertical-align: middle;
}

/* ---- Admin "Add memorial here" popup ---- */
.add-here-popup .leaflet-popup-content { margin: 12px 14px; text-align: center; }
.add-here-popup .btn.add-here { color: var(--accent-ink); white-space: nowrap; }
.add-here-coords { margin-top: 6px; font-size: 12px; color: var(--muted); }

/* ---- Drafts (admins only) ---- */
.pin-draft span { opacity: .55; border-style: dashed; border-color: #1f2521; }
.badge.draft { background: #fdf1d8; color: #7a5510; border: 1px dashed #c99a3a; }
.legend-draft { border-top: 1px solid var(--line); margin-top: 4px; padding-top: 6px !important; }
.dot-draft { background: transparent; border: 2px dashed #7a5510; }
