/* ==========================================================================
   Фотоистория Великих Лук — application styles
   Design goals: fast first paint, strong typography, works at 360px and 4K,
   full keyboard focus visibility, no external font/network dependency.
   ========================================================================== */

:root {
  --navy: #1f3a5f;
  --navy-2: #2e5c8a;
  --navy-soft: #eaf0f7;
  /* --navy is a text/border colour. As a BACKGROUND it needs its own ink: in the
     dark theme --navy is a light blue (#9dc2ef), so `color: #fff` on it measured
     1.84:1 — the same trap --accent-deep was created for. These two tokens flip
     together: light theme = white on #1f3a5f (11.48:1), dark theme = #0d1420 on
     #9dc2ef (10.01:1). */
  --navy-deep: #1f3a5f;
  --navy-deep-ink: #ffffff;
  --accent: #c0553b;
  --accent-soft: #fbf0ec;
  /* --accent is a colour for text and borders. Using it as a BACKGROUND behind
     white text gives only 4.56:1 — technically passing, with no margin. These
     two tokens exist for exactly that case (a filled pill): a slightly deeper
     accent and the ink that sits on it. Light theme: white on #a8462e = 5.87:1.
     Dark theme: #0d1420 on #e0836a = 6.70:1. */
  --accent-deep: #a8462e;
  --accent-deep-ink: #ffffff;
  --green: #3f7d5a;
  --ink: #1b1f24;
  --ink-2: #4a5361;
  /* Was #737f8d, which gave only 3.83:1 on the page background — below the
     WCAG AA minimum of 4.5:1 for normal text. This value reaches 5.11:1 on
     --bg, 5.44:1 on --card and 4.83:1 on --line-2, so muted text stays muted
     but becomes readable. */
  --ink-3: #5f6b78;
  --line: #dde3ea;
  --line-2: #eef2f6;
  --bg: #f6f8fa;
  --card: #ffffff;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow-1: 0 1px 2px rgba(16, 30, 48, .06), 0 2px 8px rgba(16, 30, 48, .05);
  --shadow-2: 0 4px 12px rgba(16, 30, 48, .10), 0 12px 32px rgba(16, 30, 48, .10);
  --shadow-3: 0 12px 40px rgba(16, 30, 48, .20);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
          Arial, "Noto Sans", sans-serif;
  --font-serif: Georgia, "Times New Roman", serif;
  --topbar-h: 64px;
  --ease: cubic-bezier(.32, .72, .34, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --navy: #9dc2ef;
    --navy-2: #7aa8dd;
    --navy-soft: #16243a;
    /* see :root — the background form of --navy carries its own ink so a filled
       pill stays readable when --navy is a light colour */
    --navy-deep: #9dc2ef;
    --navy-deep-ink: #0d1420;
    --accent: #e0836a;
    --accent-soft: #2b1d18;
    /* In dark theme the accent is a LIGHT colour, so a filled pill needs dark
       text, not white. White here measured 2.75:1 — unreadable. */
    --accent-deep: #e0836a;
    --accent-deep-ink: #0d1420;
    --green: #6cb894;
    --ink: #e8edf3;
    --ink-2: #b3bfcd;
    --ink-3: #8b98a7;
    --line: #2a3644;
    --line-2: #212c39;
    --bg: #0f1620;
    --card: #17202c;
    --shadow-1: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-2: 0 4px 14px rgba(0, 0, 0, .5);
    --shadow-3: 0 12px 40px rgba(0, 0, 0, .6);
  }
}

* { box-sizing: border-box; }

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

body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior: none;
}

h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -.012em; }

img { max-width: 100%; display: block; }

button, input, select { font: inherit; color: inherit; }

a { color: var(--navy-2); }
a:hover { text-decoration: none; }

.muted { color: var(--ink-3); }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.skip-link {
  position: absolute; left: -999px; top: 8px; z-index: 1000;
  background: var(--navy-deep); color: var(--navy-deep-ink);
  padding: 10px 16px; border-radius: var(--radius-sm);
}
.skip-link:focus { left: 8px; }

:focus-visible {
  outline: 3px solid var(--navy-2);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ============================ TOP BAR ============================ */
.topbar {
  position: sticky; top: 0; z-index: 500;
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(220px, 420px) auto;
  align-items: center;
  gap: 14px;
  height: var(--topbar-h);
  padding: 0 18px;
  background: color-mix(in srgb, var(--card) 88%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark { width: 28px; height: 28px; color: var(--navy); flex: 0 0 auto; }
.brand-text { min-width: 0; }
.brand h1 {
  font-size: 16px; line-height: 1.15;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.brand-sub { margin: 2px 0 0; font-size: 11.5px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.search { position: relative; display: flex; align-items: center; }
.search-icon {
  position: absolute; left: 11px; width: 17px; height: 17px; color: var(--ink-3);
  pointer-events: none;
}
.search input {
  width: 100%; height: 40px;
  padding: 0 34px 0 36px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg);
  transition: border-color .15s, box-shadow .15s, background .15s;
}
.search input::-webkit-search-cancel-button { display: none; }
.search input:focus {
  outline: none;
  border-color: var(--navy-2);
  background: var(--card);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--navy-2) 18%, transparent);
}
.search-clear {
  position: absolute; right: 8px;
  width: 24px; height: 24px; border: 0; border-radius: 50%;
  background: var(--line); color: var(--ink-2);
  cursor: pointer; line-height: 1; font-size: 16px;
}
.search-clear:hover { background: var(--line); color: var(--ink); }

.views { display: flex; gap: 4px; }
.view-btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 38px; padding: 0 13px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: transparent;
  color: var(--ink-2);
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, color .15s, border-color .15s;
}
.view-btn span { font-size: 13px; opacity: .8; }
.view-btn:hover { background: var(--navy-soft); color: var(--navy); }
/* --navy-deep carries its own ink, so the theme flip happens in one place instead
   of a separate dark-theme override that had to be remembered. */
.view-btn.is-active {
  background: var(--navy-deep); color: var(--navy-deep-ink);
  border-color: var(--navy-deep);
}

/* ============================ VIEWS ============================ */
main { height: calc(100dvh - var(--topbar-h)); overflow: hidden; }
.view { height: 100%; overflow: auto; }
.view[hidden] { display: none; }

/* ---------- MAP ---------- */
.map-wrap { position: relative; height: 100%; }
#map { position: absolute; inset: 0; background: var(--bg); }

.map-overlay { position: absolute; z-index: 400; pointer-events: none; }
.map-overlay > * { pointer-events: auto; }
.map-overlay-top { top: 12px; left: 50%; transform: translateX(-50%); width: min(680px, calc(100% - 24px)); }
.map-overlay-left { top: 12px; left: 12px; width: 250px; max-height: calc(100% - 24px); display: flex; }
.map-overlay-right { bottom: 22px; right: 12px; }

/* ---------- historical city plans over the map ---------- */
.map-overlay-hist { top: 12px; right: 12px; max-width: min(330px, calc(100% - 24px)); }
.histmaps { padding: 0; overflow: hidden; }
.hist-toggle {
  display: flex; align-items: center; gap: 7px; width: 100%;
  font: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
  padding: 9px 12px; border: 0; background: transparent; color: var(--ink);
  text-align: left;
}
.hist-toggle:hover { background: var(--navy-soft); color: var(--navy); }
.hist-toggle.is-open { border-bottom: 1px solid var(--line); }
.hist-count {
  margin-left: auto; font-size: 11px; font-weight: 700;
  background: var(--accent-deep); color: var(--accent-deep-ink);
  border-radius: 999px; padding: 1px 7px;
}
.hist-body { padding: 10px 12px 12px; max-height: min(60vh, 420px); overflow-y: auto; }
.hist-list { display: grid; gap: 8px; }
.hist-row {
  display: flex; align-items: flex-start; gap: 8px;
  border: 1px solid var(--line); border-radius: 9px; padding: 7px 8px;
  background: var(--card);
}
.hist-row.is-on { border-color: var(--accent); }
.hist-check { display: flex; gap: 7px; align-items: flex-start; flex: 1 1 auto; min-width: 0; cursor: pointer; }
.hist-check input { margin: 2px 0 0; accent-color: var(--accent); flex: 0 0 auto; }
.hist-name { display: grid; gap: 1px; min-width: 0; }
.hist-name b { font-size: 12.5px; font-weight: 600; line-height: 1.3; }
.hist-state { font-size: 11px; }
.hist-state.is-ok { color: var(--green); }
.hist-state.is-warn { color: var(--ink-3); }
.hist-scale { font-size: 10.5px; color: var(--ink-3); font-variant-numeric: tabular-nums; }

/* island reference: the client's test of the overlay is whether Dytlinka lands on
   the real island, so the reference is a checkbox next to the opacity slider */
.hist-island {
  display: flex; align-items: center; gap: 7px; margin-top: 8px;
  font-size: 11.5px; color: var(--ink-2); cursor: pointer; line-height: 1.35;
}
.hist-island input { margin: 0; accent-color: var(--accent); flex: 0 0 auto; }
.hist-adjust {
  flex: 0 0 auto; font: inherit; font-size: 11.5px; cursor: pointer;
  padding: 3px 8px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--bg); color: var(--ink-2);
}
.hist-adjust:hover { border-color: var(--accent); color: var(--accent); }
.hist-op {
  display: flex; align-items: center; gap: 8px; margin-top: 10px;
  font-size: 12px; color: var(--ink-2);
}
.hist-op input { flex: 1 1 auto; accent-color: var(--accent); min-width: 80px; }
.hist-actions { margin-top: 8px; }
.hist-small { font-size: 11.5px; padding: 4px 9px; }
.hist-attr { margin: 9px 0 0; font-size: 10.5px; line-height: 1.45; color: var(--ink-3); }
.hist-attr a { color: var(--navy-2); }
.hist-export { width: 100%; margin-top: 8px; font-size: 10.5px; height: 70px; }

/* calibration bar sits above everything on the map */
.hist-adjust-bar {
  position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%);
  z-index: 620; width: min(760px, calc(100% - 24px));
}
.hist-adjust-in {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: var(--card); border: 2px solid var(--accent);
  border-radius: var(--radius); padding: 10px 14px;
  box-shadow: var(--shadow-3); font-size: 12.5px;
}
.hist-adjust-in strong { font-size: 13px; }
.hist-adjust-hint { color: var(--ink-2); flex: 1 1 260px; line-height: 1.4; }
.hist-saved { color: var(--green); font-weight: 600; }
.hist-btn-primary {
  background: var(--accent-deep); color: var(--accent-deep-ink);
  border: 1px solid var(--accent-deep); font-weight: 600;
}
.hist-btn-primary:hover { filter: brightness(1.06); }

/* draggable corner handles */
.hist-handle-wrap { background: none; border: 0; }
.hist-handle {
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--accent-deep); border: 2px solid #fff;
  box-shadow: 0 1px 6px rgba(0, 0, 0, .45);
  display: grid; place-items: center; cursor: grab;
}
.hist-handle:active { cursor: grabbing; }
.hist-handle span {
  font-size: 9px; font-weight: 700; letter-spacing: .02em;
  color: var(--accent-deep-ink); line-height: 1;
}
/* the overlay itself must not swallow map clicks */
.hist-overlay { pointer-events: none; }

/* On a narrow screen the map already carries three overlays: the timeline across
   the top centre, the filters filling the top left, and the statistics at the
   bottom right. The historical-maps control is a SIBLING of those panels, so
   making it static does not move it into the filters column — it just stacks at
   the top of the map and overlaps the filters (measured: 74-92% overlap).
   The one free corner is the bottom left, so the control goes there, and its list
   opens upward. */
@media (max-width: 860px) {
  .map-overlay-hist {
    top: auto; bottom: 14px; left: 10px; right: auto;
    max-width: calc(100% - 20px);
  }
  .histmaps { max-width: 170px; }
  .hist-toggle { font-size: 12px; padding: 6px 10px; }
  .hist-body {
    position: absolute; left: 0; bottom: 100%; top: auto;
    width: min(290px, calc(100vw - 28px));
    max-height: min(46vh, 320px); margin-bottom: 6px;
    background: color-mix(in srgb, var(--card) 97%, transparent);
    border: 1px solid var(--line); border-radius: var(--radius);
    box-shadow: var(--shadow-2); z-index: 10;
  }
  .hist-adjust-in { font-size: 12px; padding: 8px 10px; }
}


.panel {
  background: color-mix(in srgb, var(--card) 94%, transparent);
  backdrop-filter: blur(10px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-2);
  padding: 12px 14px;
}

/* timeline */
.timeline-panel { padding: 10px 16px 12px; }
.timeline-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 8px; }
.tl-label { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-3); }
.tl-years { font-variant-numeric: tabular-nums; font-weight: 650; font-size: 15px; color: var(--navy); }
.tl-reset {
  margin-left: auto; border: 0; background: none; color: var(--navy-2);
  cursor: pointer; font-size: 12.5px; text-decoration: underline; padding: 2px 4px;
}
.timeline-track { position: relative; height: 34px; }
.timeline-hist {
  position: absolute; left: 0; right: 0; top: 0; height: 14px;
  display: flex; align-items: flex-end; gap: 1px;
  opacity: .55;
}
.timeline-hist i { flex: 1 1 0; background: var(--navy-2); border-radius: 1px 1px 0 0; min-height: 1px; }
.timeline-selection {
  position: absolute; top: 0; height: 14px;
  background: color-mix(in srgb, var(--navy-2) 22%, transparent);
  border-left: 2px solid var(--navy); border-right: 2px solid var(--navy);
  border-radius: 2px;
  pointer-events: none;
}
.timeline-track input[type="range"] {
  position: absolute; left: 0; right: 0; top: 0; width: 100%; height: 14px;
  margin: 0; background: none; -webkit-appearance: none; appearance: none;
  pointer-events: none;
}
.timeline-track input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--card); border: 2.5px solid var(--navy);
  box-shadow: var(--shadow-1);
  cursor: grab; pointer-events: auto; margin-top: -1px;
}
.timeline-track input[type="range"]::-moz-range-thumb {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--card); border: 2.5px solid var(--navy);
  box-shadow: var(--shadow-1); cursor: grab; pointer-events: auto;
}
.timeline-track input[type="range"]:focus-visible::-webkit-slider-thumb {
  outline: 3px solid var(--navy-2); outline-offset: 2px;
}
.timeline-scale {
  display: flex; justify-content: space-between;
  font-size: 10.5px; color: var(--ink-3); font-variant-numeric: tabular-nums;
  margin-top: 2px;
}

/* filters */
.filters { width: 100%; overflow: auto; padding: 10px 12px; }
.filters > summary {
  cursor: pointer; font-weight: 650; font-size: 13px; color: var(--navy);
  list-style: none; display: flex; align-items: center; gap: 8px;
  padding-bottom: 6px;
}
.filters > summary::-webkit-details-marker { display: none; }
.filters > summary::after { content: "▾"; margin-left: auto; font-size: 11px; transition: transform .2s; }
.filters:not([open]) > summary::after { transform: rotate(-90deg); }
.filter-count {
  font-size: 11px; font-weight: 600; color: var(--accent);
  background: var(--accent-soft); padding: 1px 6px; border-radius: 999px;
}
.filter-count:empty { display: none; }
.filter-group { border: 0; margin: 10px 0 0; padding: 0; }
.filter-group legend {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .07em;
  color: var(--ink-3); padding: 0 0 5px;
}
.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 9px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--card);
  font-size: 12px; color: var(--ink-2); cursor: pointer;
  transition: background .14s, border-color .14s, color .14s;
}
.chip:hover { border-color: var(--navy-2); color: var(--navy); }
.chip[aria-pressed="true"] {
  background: var(--navy-deep); border-color: var(--navy-deep);
  color: var(--navy-deep-ink);
}
@media (prefers-color-scheme: dark) { .chip[aria-pressed="true"] { color: #0d1420; } }
/* .75 measured 4.09:1 on the white chip — just below the 4.5:1 minimum for
   normal text. .85 gives 5.24:1 in the light theme and 6.73:1 in the dark one,
   and still reads as secondary next to the label. */
.chip b { font-weight: 600; opacity: .85; font-variant-numeric: tabular-nums; }

.switch {
  display: flex; align-items: center; gap: 8px;
  font-size: 12.5px; color: var(--ink-2);
  min-height: 32px;              /* comfortable touch target on phones */
  padding: 2px 0; cursor: pointer;
}
.switch input { accent-color: var(--navy); width: 18px; height: 18px; flex: 0 0 auto; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--card); color: var(--ink);
  cursor: pointer; font-size: 13px; font-weight: 550;
  transition: background .14s, border-color .14s, color .14s;
}
.btn:hover { border-color: var(--navy-2); color: var(--navy); }
.btn-primary {
  background: var(--navy-deep); border-color: var(--navy-deep);
  color: var(--navy-deep-ink);
}
.btn-primary:hover {
  background: var(--navy-2); color: var(--navy-deep-ink);
}
.btn-ghost { background: transparent; }
.btn-block { width: 100%; margin-top: 10px; }

/* map stats */
.map-stats {
  min-width: 148px; padding: 9px 13px;
  font-size: 12.5px; color: var(--ink-2);
  display: grid; gap: 2px;
}
.map-stats b { color: var(--navy); font-variant-numeric: tabular-nums; }
.map-stats .ms-row { display: flex; justify-content: space-between; gap: 14px; }

/* cluster / marker */
.vl-cluster {
  background: color-mix(in srgb, var(--navy) 92%, transparent);
  color: #fff; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 650; font-size: 12px;
  border: 2px solid rgba(255, 255, 255, .9);
  box-shadow: var(--shadow-2);
  font-variant-numeric: tabular-nums;
}
@media (prefers-color-scheme: dark) { .vl-cluster { color: #0d1420; } }
.vl-marker { display: grid; place-items: center; }
.vl-marker span {
  width: 13px; height: 13px; border-radius: 50%;
  background: var(--accent);
  border: 2.5px solid #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .35);
  transition: transform .12s;
}
.vl-marker:hover span { transform: scale(1.45); }
.vl-marker.is-selected span { background: var(--navy); transform: scale(1.5); }
.dir-cone { stroke-width: 1; }

/* leaflet tweaks */
.leaflet-container { font-family: var(--font); background: var(--line-2); }
.leaflet-control-attribution {
  font-size: 10px !important;
  background: color-mix(in srgb, var(--card) 85%, transparent) !important;
  color: var(--ink-3) !important;
}
.leaflet-control-attribution a { color: var(--ink-2) !important; }
.leaflet-bar, .leaflet-control-zoom {
  border: 1px solid var(--line) !important;
  box-shadow: var(--shadow-1) !important;
  border-radius: var(--radius-sm) !important;
  overflow: hidden;
}
.leaflet-bar a {
  background: var(--card) !important; color: var(--ink) !important;
  border-bottom-color: var(--line) !important;
}
.leaflet-bar a:hover { background: var(--navy-soft) !important; color: var(--navy) !important; }
.leaflet-popup-content-wrapper {
  border-radius: var(--radius) !important;
  box-shadow: var(--shadow-3) !important;
  background: var(--card) !important; color: var(--ink) !important;
  padding: 0 !important;
}
.leaflet-popup-content { margin: 0 !important; width: 232px !important; }
.leaflet-popup-tip { background: var(--card) !important; }
.leaflet-popup-close-button { color: var(--ink-3) !important; padding: 6px 6px 0 0 !important; }

.pop-card { cursor: pointer; }
.pop-card img { width: 100%; height: 140px; object-fit: cover; border-radius: var(--radius) var(--radius) 0 0; background: var(--line-2); }
.pop-card .pop-body { padding: 9px 11px 11px; }
.pop-card .pop-year { font-size: 11px; font-weight: 700; color: var(--accent); letter-spacing: .04em; }
.pop-card .pop-title { font-size: 13.5px; line-height: 1.3; margin-top: 1px; }
.pop-card .pop-meta { font-size: 11px; color: var(--ink-3); margin-top: 4px; }

/* ---------- CATALOG ---------- */
.view-catalog { padding: 16px clamp(12px, 3vw, 32px) 64px; }
.catalog-toolbar {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  margin-bottom: 14px;
}
.result-line { font-size: 14px; color: var(--ink-2); }
.result-line strong { color: var(--ink); font-variant-numeric: tabular-nums; }
#activeFilters { margin-left: 8px; font-size: 12.5px; }
.sort-wrap { margin-left: auto; }
.sort-wrap select {
  height: 36px; padding: 0 30px 0 12px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--card) url("data:image/svg+xml;charset=utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%23737f8d' stroke-width='1.8'/%3E%3C/svg%3E") no-repeat right 10px center/12px 8px;
  -webkit-appearance: none; appearance: none; cursor: pointer;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(216px, 1fr));
  gap: 16px;
}
.card {
  position: relative;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: transform .16s var(--ease), box-shadow .16s, border-color .16s;
  text-align: left;
  padding: 0;
  display: flex; flex-direction: column;
}
.card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-2);
  border-color: color-mix(in srgb, var(--navy-2) 40%, var(--line));
}
.card:focus-visible { outline: 3px solid var(--navy-2); outline-offset: 2px; }
.card-thumb {
  position: relative;
  aspect-ratio: 4 / 3;
  background: var(--line-2);
  overflow: hidden;
}
.card-thumb img {
  width: 100%; height: 100%; object-fit: cover;
  transition: transform .4s var(--ease);
}
.card:hover .card-thumb img { transform: scale(1.04); }
.card-year {
  position: absolute; left: 8px; top: 8px;
  padding: 2px 7px; border-radius: 5px;
  background: color-mix(in srgb, #12161c 74%, transparent);
  color: #fff; font-size: 11px; font-weight: 700;
  font-variant-numeric: tabular-nums; letter-spacing: .03em;
  backdrop-filter: blur(4px);
}
.card-badges { position: absolute; right: 8px; top: 8px; display: flex; gap: 4px; }
.badge {
  width: 20px; height: 20px; border-radius: 5px;
  display: grid; place-items: center;
  font-size: 10px; font-weight: 700;
  background: color-mix(in srgb, #12161c 70%, transparent);
  color: #fff; backdrop-filter: blur(4px);
}
.badge.open { background: color-mix(in srgb, var(--green) 88%, transparent); }
.badge.multi { background: color-mix(in srgb, var(--navy-2) 88%, transparent); }
.card-body { padding: 9px 11px 11px; display: flex; flex-direction: column; gap: 3px; flex: 1; }
.card-title {
  font-size: 13.5px; line-height: 1.3; font-weight: 550;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  min-height: 2.6em;
}
.card-meta { font-size: 11.5px; color: var(--ink-3); display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.lic-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--ink-3); flex: 0 0 auto; }
.lic-dot.open { background: var(--green); }
.lic-dot.reserved { background: var(--accent); }

.grid-footer { text-align: center; padding: 26px 0; color: var(--ink-3); font-size: 13px; }
.grid-footer .btn { margin-top: 8px; }

/* ---------- DRAWER / DETAIL ---------- */
.drawer { position: fixed; inset: 0; z-index: 800; }
.drawer[hidden] { display: none; }
.drawer-backdrop {
  position: absolute; inset: 0;
  background: rgba(12, 18, 26, .48);
  backdrop-filter: blur(2px);
  animation: fade .18s ease-out;
}
.drawer-panel {
  position: absolute; top: 0; right: 0; bottom: 0;
  width: min(560px, 100%);
  background: var(--card);
  box-shadow: var(--shadow-3);
  display: flex; flex-direction: column;
  animation: slidein .26s var(--ease);
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes slidein { from { transform: translateX(3%); opacity: .6; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  .drawer-backdrop, .drawer-panel { animation: none; }
  * { transition-duration: .01ms !important; }
}
.drawer-close {
  position: absolute; right: 12px; top: 12px; z-index: 2;
  width: 34px; height: 34px; border-radius: 50%;
  border: 1px solid var(--line); background: color-mix(in srgb, var(--card) 86%, transparent);
  backdrop-filter: blur(6px);
  cursor: pointer; font-size: 19px; line-height: 1; color: var(--ink-2);
}
.drawer-close:hover { color: var(--ink); border-color: var(--navy-2); }
.drawer-body { overflow-y: auto; -webkit-overflow-scrolling: touch; }

.detail-hero {
  position: relative; background: #10151b;
  display: grid; place-items: center;
  min-height: 220px;
}
.detail-hero img { width: 100%; height: auto; max-height: 62vh; object-fit: contain; }
.detail-hero .hero-actions {
  position: absolute; left: 12px; bottom: 12px; display: flex; gap: 6px;
}
.detail-inner { padding: 16px 20px 40px; }
.detail-title { font-family: var(--font-serif); font-size: 21px; line-height: 1.25; margin-bottom: 6px; }
.detail-sub { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 999px;
  background: var(--navy-soft); color: var(--navy);
  font-size: 12px; font-weight: 550;
}
.pill.warn { background: var(--accent-soft); color: var(--accent); }
.pill.ok { background: color-mix(in srgb, var(--green) 15%, transparent); color: var(--green); }

.detail-section { margin-top: 20px; }
.detail-section h3 {
  font-size: 11px; text-transform: uppercase; letter-spacing: .09em;
  color: var(--ink-3); margin-bottom: 7px; font-weight: 650;
}
.detail-desc { font-size: 14.5px; line-height: 1.6; color: var(--ink-2); }
.detail-desc:empty { display: none; }

.kv { display: grid; grid-template-columns: 116px 1fr; gap: 5px 12px; font-size: 13.5px; }
.kv dt { color: var(--ink-3); }
.kv dd { margin: 0; color: var(--ink); word-break: break-word; }

.holdings { display: grid; gap: 8px; }
.holding {
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 10px 12px; background: var(--bg);
}
.holding-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.holding-name { font-weight: 600; font-size: 13.5px; }
.holding-lic { margin-left: auto; font-size: 11px; padding: 2px 8px; border-radius: 999px; }
.holding-lic.open { background: color-mix(in srgb, var(--green) 16%, transparent); color: var(--green); }
.holding-lic.reserved { background: var(--accent-soft); color: var(--accent); }
.holding-lic.unknown { background: var(--line-2); color: var(--ink-3); }
.holding-meta { font-size: 12px; color: var(--ink-3); margin-top: 4px; display: flex; gap: 10px; flex-wrap: wrap; }
.holding-links { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.holding-links a, .holding-links button {
  font-size: 12.5px; color: var(--navy-2); background: none; border: 0;
  padding: 6px 0; min-height: 28px;
  display: inline-flex; align-items: center;
  cursor: pointer; text-decoration: underline;
}
.copy-hint { font-size: 11.5px; color: var(--ink-3); margin-top: 6px; }
/* secondary links inside the drawer must stay tappable on phones */
.detail-inner .copy-hint a,
.detail-inner .detail-section > a {
  display: inline-flex; align-items: center; min-height: 28px; padding: 4px 0;
}

/* ---------- COMPARE ---------- */
.view-compare { padding: 16px clamp(12px, 3vw, 32px) 64px; }
.compare-head { margin-bottom: 14px; }
.compare-head h2 { font-size: 19px; }
.compare-head p { margin: 4px 0 0; font-size: 13.5px; }

.compare-stage {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  background: #10151b;
  box-shadow: var(--shadow-2);
  user-select: none; touch-action: pan-y;
  margin-bottom: 12px;
}
.compare-empty { display: grid; place-items: center; min-height: 320px; color: #cdd6e0; font-size: 14px; }
.cmp-frame { position: relative; width: 100%; aspect-ratio: 16 / 10; }
@media (max-width: 640px) { .cmp-frame { aspect-ratio: 4 / 3; } }
.cmp-frame img {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: cover;
}
/* Both layers fill the frame, so stacking order decides what is visible.
   The "after" photo is the base layer; the "before" photo sits ON TOP and is
   clipped from the right, revealing the base on the other side of the divider.
   Without the explicit z-index the later element (after) paints over before and
   the slider shows a single unchanged photo.
   The images are raised above the default flow, so the handle, knob, labels and
   caption need an explicit higher level — otherwise they disappear behind the
   photos. */
.cmp-frame .cmp-after { z-index: 1; }
.cmp-frame .cmp-before { z-index: 2; clip-path: inset(0 50% 0 0); }
.cmp-handle { z-index: 4; }
.cmp-knob { z-index: 5; }
.cmp-label { z-index: 4; }
.cmp-caption { z-index: 4; }
.cmp-handle {
  position: absolute; top: 0; bottom: 0; left: 50%;
  width: 2px; background: rgba(255, 255, 255, .95);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .25);
  cursor: ew-resize;
}
.cmp-knob {
  position: absolute; top: 50%; left: 50%;
  width: 40px; height: 40px; margin: -20px 0 0 -20px;
  border-radius: 50%;
  background: #fff; color: #1b1f24;
  display: grid; place-items: center;
  font-size: 15px; font-weight: 700;
  box-shadow: 0 2px 10px rgba(0, 0, 0, .4);
  cursor: ew-resize;
}
.cmp-label {
  position: absolute; bottom: 10px;
  padding: 3px 9px; border-radius: 5px;
  background: rgba(12, 16, 22, .72); color: #fff;
  font-size: 11.5px; font-weight: 600; letter-spacing: .02em;
  backdrop-filter: blur(4px);
  pointer-events: none;
}
.cmp-label.left { left: 10px; }
.cmp-label.right { right: 10px; }
.cmp-caption {
  position: absolute; top: 10px; left: 50%; transform: translateX(-50%);
  max-width: calc(100% - 20px);
  padding: 4px 12px; border-radius: 999px;
  background: rgba(12, 16, 22, .68); color: #fff;
  font-size: 12px; text-align: center;
  backdrop-filter: blur(6px);
  pointer-events: none;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.compare-list { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 12px; }
.cmp-thumb {
  flex: 0 0 auto; width: 128px;
  border: 2px solid transparent; border-radius: var(--radius-sm);
  overflow: hidden; cursor: pointer; padding: 0; background: var(--card);
  transition: border-color .14s;
}
.cmp-thumb img { width: 100%; height: 78px; object-fit: cover; }
.cmp-thumb span { display: block; padding: 4px 6px; font-size: 11px; color: var(--ink-2); }
.cmp-thumb.is-active { border-color: var(--navy); }
.cmp-thumb:hover { border-color: var(--navy-2); }

/* ---------- ABOUT ---------- */
.prose { max-width: 780px; margin: 0 auto; padding: 26px clamp(14px, 4vw, 32px) 80px; }
.prose h2 { font-size: 24px; margin-bottom: 6px; }
.prose h3 { font-size: 15px; margin: 26px 0 8px; color: var(--navy); }
.prose p { font-size: 15px; line-height: 1.65; color: var(--ink-2); margin: 0 0 12px; }
.prose ul { margin: 0 0 14px; padding-left: 20px; color: var(--ink-2); font-size: 14.5px; line-height: 1.7; }
.prose code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12.5px; background: var(--line-2); padding: 1px 5px; border-radius: 4px;
}
.prose .stat-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px; margin: 16px 0 22px;
}
.prose .stat {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 12px 14px;
}
.prose .stat b { display: block; font-size: 22px; color: var(--navy); font-variant-numeric: tabular-nums; }
.prose .stat span { font-size: 12px; color: var(--ink-3); }

/* ---------- TOAST ---------- */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  z-index: 900;
  background: var(--navy-deep); color: var(--navy-deep-ink);
  padding: 9px 18px; border-radius: 999px;
  font-size: 13px; font-weight: 550;
  box-shadow: var(--shadow-3);
  animation: toastin .2s var(--ease);
}
@media (prefers-color-scheme: dark) { .toast { color: #0d1420; } }
@keyframes toastin { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ---------- RESPONSIVE ---------- */
@media (max-width: 1080px) {
  .topbar { grid-template-columns: minmax(140px, 1fr) minmax(180px, 1fr) auto; gap: 10px; }
  .view-btn { padding: 0 10px; font-size: 13px; }
}
@media (max-width: 860px) {
  :root { --topbar-h: auto; }
  .topbar {
    grid-template-columns: 1fr auto;
    grid-template-areas: "brand views" "search search";
    gap: 8px; padding: 8px 12px;
  }
  .brand { grid-area: brand; }
  .search { grid-area: search; }
  .views { grid-area: views; overflow-x: auto; min-width: 0; }
  .brand h1 { font-size: 14px; }
  .brand-sub { display: none; }
  /* Five view buttons no longer leave room for the title at this width, so the
     icons go first and the padding tightens: the nav keeps its own row space and
     the title keeps its ellipsis budget. Without this the title clips at 768 px. */
  .view-btn { padding: 0 9px; font-size: 12.5px; gap: 4px; }
  .view-btn span[aria-hidden="true"] { display: none; }
  main { height: calc(100dvh - 108px); }
  .map-overlay-top { top: auto; bottom: 76px; width: calc(100% - 20px); left: 10px; transform: none; }
  .map-overlay-left { width: calc(100% - 20px); left: 10px; max-height: 46%; }
  .filters:not([open]) { width: auto; }
  .map-overlay-right { bottom: 12px; right: 10px; }
  .map-stats { min-width: 0; font-size: 11.5px; padding: 7px 10px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
  .card-title { font-size: 12.5px; }
  .drawer-panel { width: 100%; }
  .compare-list { gap: 6px; }
  /* phones: secondary text links become comfortable tap targets */
  .detail-inner a, .detail-inner button {
    min-height: 32px; display: inline-flex; align-items: center;
  }
  .detail-inner .copy-hint a { padding: 6px 0; }
}
@media (max-width: 420px) {
  .view-btn span { display: none; }
  .brand-mark { width: 24px; height: 24px; }
}

@media print {
  .topbar, .map-overlay, .drawer, .toast, .grid-footer { display: none !important; }
  .view { height: auto; overflow: visible; }
  .grid { grid-template-columns: repeat(3, 1fr); }
}

/* ================= ERAS: one view across periods ================= */
.view-eras { padding: 16px clamp(12px, 3vw, 32px) 64px; }
.eras-head { margin-bottom: 14px; }
.eras-head h2 { font-size: 19px; }
.eras-head p { margin: 4px 0 0; font-size: 13.5px; }

/* ---- where the list of views sits ----
   Four layouts from one markup: data-pos on .eras-layout. On top and bottom the
   list is a horizontal scroll strip; on the sides it becomes a vertical column
   that stays put while the photograph scrolls, so choosing the next view never
   means losing the picture you were looking at. */
.eras-settings {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  margin-top: 10px; font-size: 12.5px; color: var(--ink-3);
}
.eras-pos-group { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.eras-pos {
  font: inherit; font-size: 12.5px; cursor: pointer;
  padding: 4px 11px; border: 0; background: var(--card); color: var(--ink-2);
  border-right: 1px solid var(--line);
}
.eras-pos:last-child { border-right: 0; }
.eras-pos:hover { background: var(--navy-soft); color: var(--navy); }
.eras-pos.is-active { background: var(--accent-deep); color: var(--accent-deep-ink); }
.eras-pos:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

.eras-layout { display: flex; gap: 16px; align-items: flex-start; }
.eras-layout[data-pos="top"],
.eras-layout[data-pos="bottom"] { flex-direction: column; }
.eras-layout[data-pos="right"] { flex-direction: row-reverse; }
.eras-layout[data-pos="left"],
.eras-layout[data-pos="right"] { flex-wrap: nowrap; }
.eras-layout[data-pos="left"] > .eras-body,
.eras-layout[data-pos="right"] > .eras-body { flex: 1 1 auto; min-width: 0; }

.eras-picker {
  display: flex; gap: 8px; overflow-x: auto; padding-bottom: 10px;
  border-bottom: 1px solid var(--line-2, #2a3644); margin-bottom: 16px;
}
/* Sticky in every layout: the list must stay reachable while the photograph
   scrolls. .view is the scroll container, so top:0 pins it there. */
.eras-layout[data-pos="top"] > .eras-picker,
.eras-layout[data-pos="bottom"] > .eras-picker {
  position: sticky; z-index: 6; background: var(--bg);
  padding-top: 6px; margin-bottom: 10px;
}
.eras-layout[data-pos="top"] > .eras-picker { top: 0; }
/* At the bottom the list sticks to the lower edge instead. */
.eras-layout[data-pos="bottom"] > .eras-picker { bottom: 0; margin-top: 6px; margin-bottom: 0; }
.eras-layout[data-pos="bottom"] > .eras-body { order: 1; }
.eras-layout[data-pos="bottom"] > .eras-picker { order: 2; }

.eras-layout[data-pos="left"] > .eras-picker,
.eras-layout[data-pos="right"] > .eras-picker {
  flex: 0 0 236px; width: 236px;
  flex-direction: column; overflow-x: hidden; overflow-y: auto;
  max-height: calc(100vh - var(--topbar-h) - 90px);
  position: sticky; top: 0;
  border-bottom: 0; padding: 0 4px 4px 0; margin-bottom: 0;
}
.eras-layout[data-pos="left"] > .eras-picker { border-right: 1px solid var(--line-2); }
.eras-layout[data-pos="right"] > .eras-picker { border-left: 1px solid var(--line-2); padding: 0 0 4px 4px; }
.eras-layout[data-pos="left"] > .eras-picker > .eras-pick,
.eras-layout[data-pos="right"] > .eras-picker > .eras-pick { width: 100%; max-width: none; }
/* In a narrow side column an ellipsis hides the very word that distinguishes one
   view from another, so let the title wrap instead. */
.eras-layout[data-pos="left"] .eras-pick-t,
.eras-layout[data-pos="right"] .eras-pick-t {
  white-space: normal; overflow: visible; max-width: none;
}

/* A narrow screen cannot hold a side column: fall back to the top strip, which
   works at any width. The preference is kept, so widening the window restores it. */
@media (max-width: 900px) {
  .eras-layout[data-pos="left"],
  .eras-layout[data-pos="right"] { flex-direction: column; }
  .eras-layout[data-pos="left"] > .eras-picker,
  .eras-layout[data-pos="right"] > .eras-picker {
    flex: 0 0 auto; width: auto; flex-direction: row; overflow-x: auto;
    overflow-y: hidden; max-height: none; position: sticky; top: 0;
    border-right: 0; border-left: 0; border-bottom: 1px solid var(--line-2);
    padding: 6px 0 10px;
  }
  .eras-layout[data-pos="right"] { flex-direction: column; }
}

.eras-pick {
  flex: 0 0 auto; max-width: 260px; text-align: left; cursor: pointer;
  /* Was `background: var(--panel, #161d26); color: inherit`. --panel is not
     defined anywhere, so EVERY plaque fell back to that dark navy, while
     `color: inherit` supplied near-black text in the light theme: contrast
     1.02:1, i.e. black on black — the reported bug. Use real theme tokens. */
  background: var(--card); color: var(--ink);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 12px; font: inherit;
}
.eras-pick:hover { border-color: var(--accent); }
.eras-pick.is-active {
  border-color: var(--accent);
  /* accent-soft is the app's own tint token, so the active plaque is light on
     light and dark on dark instead of depending on a translucent overlay. */
  background: var(--accent-soft);
}
.eras-pick-t {
  display: block; font-size: 12.5px; font-weight: 600; line-height: 1.35;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 230px;
}
.eras-pick-n { display: block; font-size: 11px; opacity: .65; margin-top: 2px; }

/* A view and a place promise different things, so the picker says which is which:
   "вид" is one standpoint in several eras, "место" is an object photographed from
   wherever the photographer could stand. */
.eras-kind {
  display: inline-block; font-size: 9.5px; font-weight: 700; line-height: 1.5;
  letter-spacing: .03em; text-transform: uppercase;
  padding: 0 5px; border-radius: 4px; vertical-align: 1px;
}
.eras-kind.is-view { background: var(--navy-soft); color: var(--navy); }
.eras-kind.is-place { background: var(--accent-soft); color: var(--accent-deep); }
.eras-pick.is-active .eras-kind.is-view {
  background: var(--navy-deep); color: var(--navy-deep-ink);
}
.eras-pick.is-active .eras-kind.is-place {
  background: var(--accent-deep); color: var(--accent-deep-ink);
}

/* There used to be .eras-tabs / .eras-tab here: a row of textual era pills above
   the photograph, duplicating the thumbnail strip below it. Both selected an era,
   so the text row was removed and the thumbnails — which show what you are
   choosing — moved above the photograph. */

/* The hero sits on a deliberately dark backdrop in both themes, so its text must
   be light in both. Inheriting --ink made the caption black on black (1.17:1) in
   the light theme. */
.eras-hero {
  margin: 0 0 14px; background: #0a0e12; color: #eef3f8;
  border-radius: 12px; overflow: hidden;
}
.eras-hero img {
  display: block; width: 100%; max-height: 62vh; object-fit: contain;
  margin: 0 auto; cursor: zoom-in;
}
.eras-cap { padding: 8px 14px 10px; font-size: 13px; display: flex; gap: 10px;
  align-items: baseline; flex-wrap: wrap; }
.eras-cap strong { font-size: 13.5px; }
.eras-cap span { opacity: .72; }
/* the honest caveat on a place sequence: framing changes between photographs */
.eras-cap-note {
  font-size: 11.5px !important; opacity: 1 !important;
  color: #a9bacb; font-style: italic;
}
/* "снимок 2 из 3 этой эпохи" — says how many shots the era actually has */
.eras-cap-count {
  font-size: 11.5px !important; opacity: 1 !important;
  color: #cfe0f0; font-variant-numeric: tabular-nums;
}

/* Era chooser: the row of small photographs, directly above the large one.
   It is the only control for the era now, so the active state has to be obvious
   without relying on hover — a tinted background, a thicker accent border and a
   brighter year. */
.eras-strip {
  display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 8px;
  margin-bottom: 10px; scrollbar-width: thin;
}
.eras-cell {
  flex: 0 0 auto; width: 124px; padding: 0; cursor: pointer; font: inherit;
  color: var(--ink); background: var(--card);
  border: 2px solid var(--line); border-radius: 9px; overflow: hidden;
  text-align: left; transition: border-color .12s, background .12s;
}
.eras-cell:hover { border-color: var(--accent); }
.eras-cell:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.eras-cell.is-active {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: 0 0 0 1px var(--accent);
}
.eras-cell img { display: block; width: 100%; height: 82px; object-fit: cover; }
.eras-cell.is-active img { opacity: 1; }
.eras-cell:not(.is-active) img { opacity: .82; }
/* An era can hold several photographs. A gap marks where one era ends and the
   next begins, so three shots of the war do not read as three unrelated eras. */
.eras-cell.is-era-start:not(:first-child) { margin-left: 14px; }
.eras-cell-y {
  display: block; font-size: 12px; font-weight: 600; padding: 4px 7px 0;
  font-variant-numeric: tabular-nums;
}
.eras-cell-p {
  /* Was `opacity: .6`, which measured 4.3:1 — just under the 4.5:1 minimum.
     --ink-3 is already the muted colour, so it needs no extra transparency. */
  display: block; font-size: 10.5px; color: var(--ink-3); padding: 0 7px 5px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

@media (max-width: 640px) {
  .eras-pick { max-width: 200px; }
  .eras-pick-t { max-width: 172px; }
  .eras-cell { width: 104px; }
  .eras-cell img { height: 68px; }
}
