/* ==========================================================================
   Санкт-Петербург 1897 — интерфейс карты
   Палитра взята с референса: светло-серые объёмы зданий, тёмная вода,
   тёплая тёмная земля, тонкие светлые линии улиц.
   Типографическая шкала — ровно четыре размера, никаких разовых font-size.
   ========================================================================== */

@font-face {
  font-family: 'PT Serif';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('../fonts/pt-serif-cyrillic-400-normal.woff2') format('woff2');
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: 'PT Serif';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('../fonts/pt-serif-latin-400-normal.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+2000-206F, U+2122, U+2191, U+2193, U+2212;
}
@font-face {
  font-family: 'PT Serif';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('../fonts/pt-serif-cyrillic-700-normal.woff2') format('woff2');
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: 'PT Serif';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('../fonts/pt-serif-latin-700-normal.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+2000-206F, U+2122, U+2191, U+2193, U+2212;
}

:root {
  /* Карта */
  --c-ground: #2a2521;
  --c-water: #14181e;
  --c-street: rgba(214, 196, 170, 0.34);
  --c-street-major: rgba(232, 216, 190, 0.52);
  --c-green: #262a24;
  --c-square: #332c26;

  /* Интерфейс */
  --c-chrome: rgba(18, 15, 12, 0.9);
  --c-chrome-solid: #16130f;
  --c-edge: rgba(226, 208, 176, 0.16);
  --c-text: #ece5d8;
  --c-muted: #a49a89;
  --c-accent: #c8a45c;
  --c-danger: #c0684f;
  --c-lost: #7ba6b8;

  /* Типографическая шкала: ровно четыре размера */
  --fs-h1: clamp(1.25rem, 0.95rem + 1.1vw, 1.75rem);
  --fs-h2: clamp(1.05rem, 0.95rem + 0.4vw, 1.2rem);
  --fs-h3: 0.95rem;
  --fs-base: 0.85rem;

  --radius: 3px;
  --shadow: 0 18px 44px rgba(0, 0, 0, 0.5);

  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }

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

body {
  background: var(--c-ground);
  color: var(--c-text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: var(--fs-base);
  line-height: 1.55;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 {
  font-family: 'PT Serif', Georgia, 'Times New Roman', serif;
  font-weight: 700;
  margin: 0;
  line-height: 1.2;
}

a { color: var(--c-accent); }
a:focus-visible,
button:focus-visible,
input:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--c-accent);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.skip-link {
  position: absolute;
  top: -100px;
  left: 12px;
  z-index: 60;
  padding: 10px 14px;
  background: var(--c-chrome-solid);
  border: 1px solid var(--c-edge);
  border-radius: var(--radius);
}
.skip-link:focus { top: calc(12px + env(safe-area-inset-top, 0px)); }

#map {
  position: absolute;
  inset: 0;
}

/* Заголовок ------------------------------------------------------------- */

.titlebar {
  position: absolute;
  top: calc(16px + env(safe-area-inset-top, 0px));
  left: 16px;
  z-index: 10;
  max-width: min(46ch, calc(100vw - 32px));
  pointer-events: none;
  padding: 10px 16px 12px;
  margin: -10px -16px -12px;
  /* Затемнение под заголовком: без него текст теряется на светлых кровлях */
  background: linear-gradient(105deg, rgba(10, 8, 6, 0.9) 0%, rgba(10, 8, 6, 0.72) 45%, rgba(10, 8, 6, 0) 100%);
  text-shadow: 0 2px 14px rgba(0, 0, 0, 0.9);
}

.titlebar__title {
  font-size: var(--fs-h1);
  letter-spacing: 0.02em;
  display: flex;
  align-items: baseline;
  gap: 0.5em;
}

.titlebar__year {
  font-size: var(--fs-h3);
  font-weight: 400;
  letter-spacing: 0.32em;
  color: var(--c-accent);
  border-left: 1px solid var(--c-edge);
  padding-left: 0.6em;
}

.titlebar__sub {
  margin: 4px 0 0;
  color: var(--c-muted);
  max-width: 42ch;
}

/* Панель ---------------------------------------------------------------- */

.panel {
  position: absolute;
  z-index: 20;
  left: 16px;
  bottom: calc(52px + env(safe-area-inset-bottom, 0px));
  width: min(290px, calc(100vw - 32px));
  background: var(--c-chrome);
  backdrop-filter: blur(14px);
  border: 1px solid var(--c-edge);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  max-height: min(60vh, 560px);
  display: flex;
  flex-direction: column;
}

.panel__toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 11px 14px;
  background: none;
  border: 0;
  border-bottom: 1px solid var(--c-edge);
  color: var(--c-text);
  font: inherit;
  font-size: var(--fs-h3);
  font-family: 'PT Serif', Georgia, serif;
  cursor: pointer;
  text-align: left;
}

.panel__toggle-icon {
  width: 9px; height: 9px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(45deg);
  transition: transform 0.18s ease;
  margin-bottom: 3px;
}
.panel__toggle[aria-expanded="false"] .panel__toggle-icon { transform: rotate(-135deg); margin-bottom: -3px; }
.panel__toggle[aria-expanded="false"] { border-bottom-color: transparent; }

.panel__body {
  overflow-y: auto;
  padding: 4px 14px 14px;
  overscroll-behavior: contain;
}
.panel__body[hidden] { display: none !important; }

.field {
  border: 0;
  border-top: 1px solid var(--c-edge);
  margin: 0;
  padding: 12px 0 2px;
}
.field:first-of-type { border-top: 0; }

.field__legend {
  padding: 0;
  color: var(--c-muted);
  text-transform: uppercase;
  letter-spacing: 0.14em;
}

.field__hint {
  margin: 8px 0 2px;
  color: var(--c-muted);
}

.check {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 5px 0;
  cursor: pointer;
}
.check input { accent-color: var(--c-accent); width: 15px; height: 15px; flex: none; }

.seg {
  display: flex;
  margin-top: 8px;
  border: 1px solid var(--c-edge);
  border-radius: var(--radius);
  overflow: hidden;
}
.seg__btn {
  flex: 1;
  padding: 8px 6px;
  background: transparent;
  border: 0;
  color: var(--c-muted);
  font: inherit;
  cursor: pointer;
  min-height: 36px;
}
.seg__btn + .seg__btn { border-left: 1px solid var(--c-edge); }
.seg__btn.is-active { background: rgba(200, 164, 92, 0.16); color: var(--c-text); }

.row { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }

.btn {
  flex: 1 1 auto;
  min-height: 36px;
  padding: 8px 10px;
  background: transparent;
  border: 1px solid var(--c-edge);
  border-radius: var(--radius);
  color: var(--c-text);
  font: inherit;
  cursor: pointer;
}
.btn:hover { border-color: var(--c-accent); }

.slider {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  color: var(--c-muted);
}
.slider input { flex: 1; accent-color: var(--c-accent); }

.search {
  width: 100%;
  margin-top: 8px;
  padding: 9px 10px;
  min-height: 38px;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--c-edge);
  border-radius: var(--radius);
  color: var(--c-text);
  font: inherit;
}

.search__results {
  list-style: none;
  margin: 6px 0 0;
  padding: 0;
  max-height: 160px;
  overflow-y: auto;
}
.search__results li { margin: 0; }
.search__results button {
  display: block;
  width: 100%;
  padding: 7px 8px;
  min-height: 36px;
  background: none;
  border: 0;
  border-left: 2px solid transparent;
  color: var(--c-text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.search__results button:hover { background: rgba(200, 164, 92, 0.12); border-left-color: var(--c-accent); }

.panel__legend {
  margin: 14px 0 0;
  padding-top: 12px;
  border-top: 1px solid var(--c-edge);
  color: var(--c-muted);
}
.panel__legend-title { margin: 0 0 6px; }
.legend {
  list-style: none;
  margin: 0;
  padding: 0;
}
.legend li {
  display: flex;
  align-items: baseline;
  gap: 7px;
  padding: 2px 0;
}
/* Доля уровня прижимается вправо, чтобы числа читались столбиком. */
.legend b { margin-left: auto; font-weight: 400; color: var(--c-text); }
.swatch {
  width: 11px; height: 11px;
  flex: none;
  display: inline-block;
  border-radius: 2px;
  /* Обводка нужна светлым плашкам на тёмной панели, иначе их не видно. */
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35);
}
/* Те же цвета, что у объёмов в режиме достоверности (см. TRUST_COLORS). */
.swatch--landmark { background: rgb(226, 170, 92); }
.swatch--dated { background: rgb(140, 184, 212); }
.swatch--assumed { background: rgb(176, 170, 160); }
/* Когда раскраска выключена, легенда приглушена: она описывает не то,
   что сейчас на экране, а то, что появится по щелчку. */
.panel__legend.is-idle .legend { opacity: 0.55; }
.panel__legend.is-active #trust-hint { display: none; }

/* Карточка здания ------------------------------------------------------- */

.card {
  position: absolute;
  z-index: 30;
  top: calc(16px + env(safe-area-inset-top, 0px));
  right: 16px;
  bottom: calc(52px + env(safe-area-inset-bottom, 0px));
  width: min(380px, calc(100vw - 32px));
  background: var(--c-chrome);
  backdrop-filter: blur(14px);
  border: 1px solid var(--c-edge);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  animation: card-in 0.22s ease;
}
.card[hidden] { display: none !important; }

@keyframes card-in {
  from { opacity: 0; transform: translateX(14px); }
  to { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .card { animation: none; }
  .panel__toggle-icon { transition: none; }
}

.card__close {
  position: absolute;
  top: 6px; right: 6px;
  z-index: 2;
  width: 36px; height: 36px;
  background: rgba(10, 8, 6, 0.6);
  border: 0;
  border-radius: var(--radius);
  color: var(--c-text);
  font-size: var(--fs-h2);
  line-height: 1;
  cursor: pointer;
}

.card__scroll {
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0 0 18px;
}

.card__figure { margin: 0; background: rgba(0, 0, 0, 0.35); }
.card__figure img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 4 / 3;
  object-fit: cover;
}
.card__noimg {
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 4 / 3;
  padding: 18px;
  text-align: center;
  color: var(--c-muted);
  border-bottom: 1px solid var(--c-edge);
  background:
    repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.02) 0 8px, transparent 8px 16px),
    rgba(0, 0, 0, 0.25);
}
.card__caption {
  padding: 7px 16px;
  color: var(--c-muted);
  border-bottom: 1px solid var(--c-edge);
}

.card__head { padding: 16px 16px 0; }

.card__badge {
  display: inline-block;
  padding: 2px 8px;
  margin-bottom: 8px;
  border: 1px solid var(--c-edge);
  border-radius: 999px;
  color: var(--c-muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}
.card__badge--landmark { color: var(--c-accent); border-color: rgba(200, 164, 92, 0.5); }
.card__badge--warn { color: var(--c-danger); border-color: rgba(192, 104, 79, 0.5); }
.card__badge--lost { color: var(--c-lost); border-color: rgba(123, 166, 184, 0.5); }

.card__title { font-size: var(--fs-h2); }
.card__subtitle { margin: 4px 0 0; color: var(--c-muted); }
/* Подзаголовок внутри карточки. Своего размера не заводит — типографическая
   шкала проекта ровно из четырёх ступеней, разница держится начертанием. */
.card__subhead {
  margin: 16px 0 6px;
  font-size: inherit;
  font-weight: 700;
  color: var(--c-accent);
}

.card__body { padding: 12px 16px 0; }
.card__body p { margin: 0 0 10px; }

.card__facts {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 12px;
  margin: 12px 0;
  padding: 12px 0;
  border-top: 1px solid var(--c-edge);
  border-bottom: 1px solid var(--c-edge);
}
.card__facts dt { color: var(--c-muted); }
.card__facts dd { margin: 0; }

.card__note {
  margin: 10px 0;
  padding: 9px 11px;
  border-left: 2px solid var(--c-accent);
  background: rgba(200, 164, 92, 0.07);
  color: var(--c-muted);
}
.card__note--warn { border-left-color: var(--c-danger); background: rgba(192, 104, 79, 0.08); }

.card__sources { margin: 12px 0 0; color: var(--c-muted); }
.card__sources ul { margin: 6px 0 0; padding-left: 16px; }
/* Цвета частей объёма: плашка того тона, которым часть нарисована на карте. */
.card__colours { list-style: none; padding-left: 0 !important; }
.card__colours li { margin: 0 0 6px; }
.card__colours strong { color: var(--c-text); font-weight: 700; }
.card__swatch {
  display: inline-block;
  width: 12px; height: 12px;
  margin-right: 6px;
  vertical-align: -1px;
  border: 1px solid var(--c-edge);
  border-radius: 2px;
}

/* Компас и подвал ------------------------------------------------------- */

.hud {
  position: absolute;
  z-index: 15;
  right: 16px;
  bottom: calc(52px + env(safe-area-inset-bottom, 0px));
}

.hud__compass {
  width: 44px; height: 44px;
  display: grid;
  place-items: center;
  background: var(--c-chrome);
  border: 1px solid var(--c-edge);
  border-radius: 50%;
  color: var(--c-text);
  cursor: pointer;
}
.hud__compass svg { width: 24px; height: 24px; transition: transform 0.1s linear; }
@media (prefers-reduced-motion: reduce) { .hud__compass svg { transition: none; } }

.attrib {
  position: absolute;
  z-index: 15;
  left: 0; right: 0;
  bottom: 0;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 2px 16px;
  padding: 8px 16px calc(10px + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(to top, rgba(10, 8, 6, 0.92), rgba(10, 8, 6, 0));
  color: var(--c-muted);
}
.attrib p { margin: 0; }

/* Загрузка -------------------------------------------------------------- */

.loader {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  background: var(--c-ground);
  transition: opacity 0.4s ease;
}
.loader[hidden] { display: none !important; }
.loader.is-done { opacity: 0; pointer-events: none; }
.loader__text {
  font-family: 'PT Serif', Georgia, serif;
  font-size: var(--fs-h2);
  color: var(--c-muted);
  letter-spacing: 0.1em;
}

/* Узкие экраны ---------------------------------------------------------- */

@media (max-width: 720px) {
  .titlebar__sub { display: none; }

  .panel {
    left: 12px;
    right: 12px;
    width: auto;
    bottom: calc(60px + env(safe-area-inset-bottom, 0px));
    max-height: 48vh;
  }

  /* Карточка и панель настроек делят низ экрана — показываем что-то одно */
  body.is-card-open .panel { display: none; }

  .card__figure img,
  .card__noimg { aspect-ratio: 16 / 9; max-height: 34vh; }

  .card {
    top: auto;
    left: 12px;
    right: 12px;
    bottom: calc(60px + env(safe-area-inset-bottom, 0px));
    width: auto;
    max-height: 62vh;
  }

  .hud { bottom: auto; top: calc(14px + env(safe-area-inset-top, 0px)); right: 12px; }
  .attrib { font-size: var(--fs-base); }
}

/* Подписи MapLibre не используются — свой слой в deck.gl */
.maplibregl-ctrl-attrib { display: none; }
