:root {
  --bg: #ffffff;
  --text: #1b1b1f;
  --hint: #6e6e76;
  --accent: #b07d1c;        /* золото куполов */
  --accent-text: #ffffff;
  --surface: #f4f2ee;
  --border: rgba(0, 0, 0, .08);
  --shadow: 0 6px 24px rgba(0, 0, 0, .14);
  --dot-empty: #8d8d95;
  --spring: #2f86d6;        /* вода */
  --spring-empty: #8fb9e0;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1c1c1f; --text: #f2f2f4; --hint: #9a9aa3; --accent: #d6a94a; --accent-text: #1c1c1f;
    --surface: #2a2a2e; --border: rgba(255, 255, 255, .1); --shadow: 0 6px 24px rgba(0, 0, 0, .5);
    --dot-empty: #6b6b73; --spring: #5aa6ea; --spring-empty: #4d6f90;
  }
}
:root[data-theme="dark"] {
  --bg: #1c1c1f; --text: #f2f2f4; --hint: #9a9aa3; --accent: #d6a94a; --accent-text: #1c1c1f;
  --surface: #2a2a2e; --border: rgba(255, 255, 255, .1); --shadow: 0 6px 24px rgba(0, 0, 0, .5);
  --dot-empty: #6b6b73; --spring: #5aa6ea; --spring-empty: #4d6f90;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
}
#map { position: fixed; inset: 0; background: var(--surface); }
.dark-tiles .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(.85) contrast(.9); }

.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 1000;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 0;
  max-width: 560px; margin: 0 auto;
}
.search {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg); border-radius: 14px; box-shadow: var(--shadow);
  padding: 0 14px; height: 46px;
}
.search svg { width: 20px; height: 20px; fill: var(--hint); flex: none; }
.search input {
  flex: 1; min-width: 0; border: 0; outline: 0; background: transparent;
  color: var(--text); font: inherit; font-size: 16px;
}
.results {
  list-style: none; margin: 6px 0 0; padding: 4px 0; background: var(--bg);
  border-radius: 14px; box-shadow: var(--shadow); max-height: 50vh; overflow: auto;
}
.results li { padding: 10px 14px; cursor: pointer; }
.results li:hover, .results li:focus { background: var(--surface); outline: none; }
.results .addr { color: var(--hint); font-size: 13px; }
.results .empty { color: var(--hint); cursor: default; }

.fab {
  position: fixed; right: 16px; bottom: calc(env(safe-area-inset-bottom) + 24px); z-index: 900;
  width: 48px; height: 48px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--bg); box-shadow: var(--shadow); display: grid; place-items: center;
}
.fab svg { width: 24px; height: 24px; fill: var(--text); }

.status {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 30px); transform: translateX(-50%);
  z-index: 900; background: var(--bg); color: var(--hint); padding: 8px 14px; border-radius: 20px;
  box-shadow: var(--shadow); font-size: 13px; white-space: nowrap; transition: opacity .3s;
}
.status.hide { opacity: 0; pointer-events: none; }

/* Маркеры */
.dot {
  width: 14px; height: 14px; border-radius: 50%; border: 2px solid #fff;
  background: var(--dot-empty); box-shadow: 0 1px 4px rgba(0, 0, 0, .35);
}
.dot.rich { background: var(--accent); width: 16px; height: 16px; }
[data-type="spring"] .cluster { background: var(--spring); color: #fff; }
/* Часовня — точка поменьше, монастырь — квадрат (как обитель за стеной), источник — голубая капля */
.dot-chapel { width: 11px; height: 11px; }
.dot-chapel.rich { width: 13px; height: 13px; }
.dot-monastery { width: 18px; height: 18px; border-radius: 5px; border-width: 3px; }
.dot-monastery.rich { width: 18px; height: 18px; }
.dot-spring { background: var(--spring-empty); border-radius: 50% 50% 50% 0; transform: rotate(-45deg); }
.dot-spring.rich { background: var(--spring); }
.dot.active { outline: 3px solid var(--accent); outline-offset: 2px; }
.dot-spring.active { outline-color: var(--spring); }
.cluster {
  background: var(--accent); color: var(--accent-text); border-radius: 50%;
  display: grid; place-items: center; font-weight: 600; font-size: 13px;
  border: 3px solid rgba(255, 255, 255, .85); box-shadow: 0 2px 8px rgba(0, 0, 0, .3);
}

/* Карточка храма */
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 1100;
  max-width: 560px; margin: 0 auto; max-height: 78vh; overflow: auto;
  background: var(--bg); border-radius: 18px 18px 0 0; box-shadow: var(--shadow);
  padding: 8px 16px calc(env(safe-area-inset-bottom) + 20px);
  animation: up .22s ease-out;
  overscroll-behavior: contain;
}
/* только сдвиг, без прозрачности: карточка никогда не «просвечивает» картой */
@keyframes up { from { transform: translateY(60px); } }
.sheet.dragging { transition: none; }
.sheet.closing { transition: transform .18s ease-in; }
.grip { width: 40px; height: 5px; border-radius: 3px; background: var(--border); margin: 0 auto 8px; touch-action: none; }

/* На широком экране карточка — панель слева, карта остаётся видна */
@media (min-width: 900px) {
  .sheet {
    left: 16px; right: auto; top: 112px; bottom: 16px; width: 400px; margin: 0;
    max-height: none; border-radius: 18px;
  }
  @keyframes up { from { transform: translateX(-30px); } }
  .grip { display: none; }
  .status { left: calc(50% + 216px); }
  .topbar { margin: 0; left: 0; right: auto; width: 432px; }
}

/* Фильтры */
.chips { display: flex; gap: 6px; margin-top: 8px; overflow-x: auto; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 0; cursor: pointer; padding: 7px 12px; border-radius: 18px; font: inherit; font-size: 13px;
  background: var(--bg); color: var(--text); box-shadow: 0 2px 8px rgba(0, 0, 0, .15);
}
.chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); }
.chip-group { display: flex; gap: 6px; flex: none; }
.chip-sep { flex: none; width: 1px; margin: 6px 2px; background: var(--hint); opacity: .35; }
.chip .n { margin-left: 5px; opacity: .6; font-variant-numeric: tabular-nums; }
.chip .n:empty { display: none; }
.chip .sw { margin-right: 6px; }
/* Чипы уходят за край на телефоне — не обрезаем тень и даём докрутить последний */
.chips { padding: 2px 16px 10px; margin-left: -16px; margin-right: -16px; scroll-padding: 0 16px; }

/* Значок типа — та же форма, что у маркера на карте */
.sw {
  display: inline-block; vertical-align: -1px; width: 10px; height: 10px; margin-right: 6px; flex: none;
  border-radius: 50%; background: var(--dot-empty); box-shadow: 0 0 0 1.5px #fff, 0 0 0 2.5px rgba(0, 0, 0, .12);
}
.sw.rich, .chip .sw { background: var(--accent); }
.sw-chapel { width: 8px; height: 8px; vertical-align: 0; }
.sw-monastery { border-radius: 3px; }
.sw-spring, .chip .sw-spring, .sw-spring.rich { background: var(--spring); border-radius: 50% 50% 50% 0; transform: rotate(-45deg); }
.chip[aria-pressed="true"] .sw { box-shadow: 0 0 0 1.5px var(--accent-text); }
.results li .sw { margin-right: 8px; }

/* Рядом */
.nearby { margin: 18px 0 0; }
.nearby h2 { font-size: 15px; margin: 0 0 6px; }
.nearby ul { list-style: none; margin: 0; padding: 0; }
.nearby li {
  display: flex; justify-content: space-between; gap: 10px; padding: 9px 0; cursor: pointer;
  border-top: 1px solid var(--border); font-size: 14px;
}
.nearby li:hover .nm { text-decoration: underline; }
.nearby .dist { color: var(--hint); white-space: nowrap; }
.nearby .mark { color: var(--accent); }
.close {
  position: absolute; top: 10px; right: 12px; width: 32px; height: 32px; border-radius: 50%;
  border: 0; background: var(--surface); color: var(--hint); font-size: 22px; line-height: 1; cursor: pointer;
}
.photo { margin: 6px -16px 0; }
.photo img { display: block; width: 100%; max-height: 300px; object-fit: cover; background: var(--surface); }
.photo figcaption { padding: 4px 16px 0; font-size: 11px; color: var(--hint); }
.photo a, .source a { color: inherit; }
h1 { font-size: 20px; line-height: 1.25; margin: 12px 40px 4px 0; }
.meta { color: var(--hint); font-size: 14px; margin: 0 0 12px; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0 0 14px; font-size: 14px; }
.facts dt { color: var(--hint); }
.facts dd { margin: 0; }
.story { margin: 0 0 6px; }
.story blockquote { margin: 0; padding-left: 12px; border-left: 3px solid var(--accent); }
.source { font-size: 12px; color: var(--hint); margin: 0 0 14px; }
.nostory {
  background: var(--surface); border-radius: 12px; padding: 12px 14px; color: var(--hint);
  font-size: 14px; margin: 0 0 14px;
}
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.btn {
  flex: 1 1 auto; text-align: center; text-decoration: none; padding: 11px 14px; border-radius: 12px;
  background: var(--surface); color: var(--text); font-weight: 500; font-size: 14px; border: 0; cursor: pointer;
}
.btn.primary { background: var(--accent); color: var(--accent-text); }
.fix { display: block; margin-top: 14px; font-size: 12px; color: var(--hint); text-align: center; }

.catalog-link {
  position: fixed; left: 16px; bottom: calc(env(safe-area-inset-bottom) + 24px); z-index: 900;
  padding: 8px 12px; border-radius: 18px; background: var(--bg); color: var(--text); text-decoration: none;
  font-size: 13px; box-shadow: 0 2px 8px rgba(0, 0, 0, .15);
}
body:has(.sheet:not([hidden])) .catalog-link { display: none; }

.leaflet-control-attribution { font-size: 10px; }
.leaflet-bottom.leaflet-right { margin-bottom: env(safe-area-inset-bottom); }
