:root {
  --sea: #b9d3e6; --land: #e8e2d4; --ink: #18202c; --muted: #5b6676;
  --panel: rgba(255,255,255,.92); --line: rgba(0,0,0,.12); --accent: #2d6cdf;
  --shadow: 0 4px 18px rgba(0,0,0,.18);
}
@media (prefers-color-scheme: dark) {
  :root { --sea: #0f1a2b; --land: #2a2f38; --ink: #e8ecf2; --muted: #9aa5b4;
          --panel: rgba(20,26,36,.92); --line: rgba(255,255,255,.14); --accent: #6ea8ff; }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--sea); color: var(--ink);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
#map { position: absolute; inset: 0; background: var(--sea); }
.leaflet-container { background: var(--sea); font: inherit; }
a { color: var(--accent); }

/* --- шапка с годом ------------------------------------------------------ */
#top { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); z-index: 1000;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow);
  padding: 6px 18px 8px; text-align: center; pointer-events: none; min-width: 220px; backdrop-filter: blur(6px); }
#top .title { font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
#yearBig { font-size: 30px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
#mapNote { font-size: 11px; color: var(--muted); }

/* --- поиск --------------------------------------------------------------- */
#search { position: absolute; top: 10px; left: 10px; width: 330px; z-index: 1100; }
#q { width: 100%; height: 40px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--panel); color: var(--ink); font: inherit; font-size: 14.5px; box-shadow: var(--shadow);
  backdrop-filter: blur(6px); outline: none; }
#q:focus { border-color: var(--accent); }
#results { list-style: none; margin: 6px 0 0; padding: 4px; max-height: min(60vh, 520px); overflow-y: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow);
  backdrop-filter: blur(8px); }
#results li { display: flex; gap: 8px; padding: 6px 8px; border-radius: 8px; cursor: pointer; }
#results li:hover, #results li.act { background: var(--line); }
#results li.none { color: var(--muted); cursor: default; }
#results .ic { width: 20px; text-align: center; flex: none; }
#results .txt { min-width: 0; }
#results b { font-weight: 600; display: block; }
#results small { color: var(--muted); font-size: 12px; display: -webkit-box; -webkit-line-clamp: 2;
  -webkit-box-orient: vertical; overflow: hidden; }

/* --- боковая панель ------------------------------------------------------ */
#side { position: absolute; top: 10px; right: 10px; bottom: 132px; width: 300px; z-index: 1000;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; backdrop-filter: blur(6px); transition: width .2s; }
#sideToggle { position: absolute; top: 6px; left: 6px; border: 0; background: none; color: var(--ink);
  font-size: 18px; cursor: pointer; z-index: 2; }
#side .sideBody { overflow-y: auto; padding: 8px 12px 12px; margin-top: 26px; }
#side.closed { width: 40px; bottom: auto; height: 40px; }
#side.closed .sideBody { display: none; }
.sect { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted);
  margin: 12px 0 6px; font-weight: 600; }
#filters { display: flex; flex-wrap: wrap; gap: 6px; }
#filters label { display: inline-flex; align-items: center; gap: 4px; padding: 3px 8px; border-radius: 99px;
  border: 1px solid var(--line); cursor: pointer; user-select: none; font-size: 12.5px; }
#filters input { display: none; }
#filters .all { flex-basis: 100%; padding: 5px 10px; border-radius: 8px; border: 1px solid var(--accent);
  background: transparent; color: var(--accent); font: inherit; font-weight: 600; cursor: pointer; }
#filters .all:hover { background: var(--accent); color: #fff; }
#filters label.off { opacity: .4; }
#evList, #rulList { list-style: none; margin: 0; padding: 0; }
#evList li, #rulList li { display: flex; gap: 8px; align-items: flex-start; padding: 5px 4px; border-radius: 8px; cursor: pointer; }
#evList li:hover, #rulList li:hover { background: var(--line); }
#evList .y { font-variant-numeric: tabular-nums; color: var(--muted); min-width: 64px; font-size: 12px; padding-top: 1px; }
#evList .ic { width: 20px; text-align: center; }
#rulList img, #rulList .ph { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; flex: none; background: var(--line); }
#rulList small { color: var(--muted); display: block; font-size: 11.5px; }
.src { font-size: 11px; color: var(--muted); margin-top: 16px; }

/* --- шкала времени ------------------------------------------------------ */
#timeline { position: absolute; left: 10px; right: 10px; bottom: 10px; z-index: 1000; background: var(--panel);
  border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); padding: 8px 14px 6px;
  backdrop-filter: blur(6px); }
.controls { display: flex; gap: 6px; align-items: center; justify-content: center; flex-wrap: wrap; }
.controls button, .controls select, #yearInput { height: 30px; border: 1px solid var(--line); border-radius: 8px;
  background: transparent; color: var(--ink); font: inherit; padding: 0 10px; cursor: pointer; }
.controls button:hover { border-color: var(--accent); }
#play { width: 40px; font-size: 14px; background: var(--accent); color: #fff; border-color: var(--accent); }
#yearInput { width: 120px; text-align: center; cursor: text; font-variant-numeric: tabular-nums; }
.controls select option { color: #000; }
.track { position: relative; height: 62px; margin-top: 4px; }
#density { position: absolute; left: 0; right: 0; top: 0; width: 100%; height: 24px; }
#slider { position: absolute; left: 0; right: 0; top: 16px; width: 100%; margin: 0; height: 22px;
  -webkit-appearance: none; appearance: none; background: transparent; cursor: pointer; }
#slider::-webkit-slider-runnable-track { height: 6px; border-radius: 3px;
  background: linear-gradient(90deg,#7b5e3b,#a0784a 20%,#c4a15a 30%,#6c9a5b 50%,#3d82b8 70%,#5a5fc7 85%,#c0392b); }
#slider::-moz-range-track { height: 6px; border-radius: 3px;
  background: linear-gradient(90deg,#7b5e3b,#a0784a 20%,#c4a15a 30%,#6c9a5b 50%,#3d82b8 70%,#5a5fc7 85%,#c0392b); }
#slider::-webkit-slider-thumb { -webkit-appearance: none; width: 22px; height: 22px; margin-top: -8px; border-radius: 50%;
  background: #fff; border: 3px solid var(--accent); box-shadow: 0 1px 6px rgba(0,0,0,.4); }
#slider::-moz-range-thumb { width: 18px; height: 18px; border-radius: 50%; background: #fff; border: 3px solid var(--accent); }
#ticks { position: absolute; left: 0; right: 0; top: 40px; height: 20px; font-size: 11px; color: var(--muted); }
#ticks span { position: absolute; transform: translateX(-50%); white-space: nowrap; cursor: pointer; }
#ticks span::before { content: ""; position: absolute; left: 50%; top: -5px; height: 4px; border-left: 1px solid var(--muted); }

/* --- маркеры ------------------------------------------------------------ */
.ruler { border-radius: 50%; overflow: hidden; border: 3px solid #fff; box-shadow: 0 2px 8px rgba(0,0,0,.45);
  background: #ddd center/cover no-repeat; transition: transform .15s; }
.ruler:hover { transform: scale(1.35); z-index: 9999 !important; }
.ruler .ini { display: flex; align-items: center; justify-content: center; width: 100%; height: 100%;
  font-weight: 700; color: #fff; font-size: 15px; text-shadow: 0 1px 2px rgba(0,0,0,.5); }

.ev { display: flex; align-items: center; justify-content: center; border-radius: 50%; color: #fff;
  border: 2px solid #fff; box-shadow: 0 2px 6px rgba(0,0,0,.4); font-size: 15px; line-height: 1; }
.ev.now::after { content: ""; position: absolute; inset: -8px; border-radius: 50%; border: 3px solid currentColor;
  animation: pulse 1.6s ease-out infinite; }
@keyframes pulse { from { transform: scale(.6); opacity: 1; } to { transform: scale(1.6); opacity: 0; } }

.stateLabel { font-size: 11px; font-weight: 600; color: #222; text-shadow: 0 0 3px #fff, 0 0 3px #fff, 0 0 2px #fff;
  white-space: nowrap; pointer-events: none; text-align: center; transform: translate(-50%,-50%); }
.stateLabel.big { font-size: 13px; letter-spacing: .04em; text-transform: uppercase; }
@media (prefers-color-scheme: dark) {
  .stateLabel { color: #f2f2f2; text-shadow: 0 0 3px #000, 0 0 3px #000; }
}

.leaflet-popup-content-wrapper { border-radius: 12px; }
.leaflet-popup-content { margin: 12px 14px; width: 260px !important; }
.pop img { width: 100%; height: 170px; object-fit: cover; border-radius: 8px; display: block; margin-bottom: 8px; background: #eee; }
.pop .k { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: #667; }
.pop h3 { margin: 2px 0 4px; font-size: 15px; }
.pop p { margin: 0 0 6px; }
.leaflet-tooltip { font: 12.5px/1.35 -apple-system, "Segoe UI", Roboto, sans-serif; border-radius: 8px; }

#loading { position: absolute; left: 50%; top: 50%; transform: translate(-50%,-50%); z-index: 2000; background: var(--panel);
  padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); }
#loading.hide { display: none; }

@media (max-width: 760px) {
  #side { top: auto; bottom: 150px; right: 8px; left: 8px; width: auto; max-height: 38vh; }
  #side.closed { left: auto; width: 40px; }
  #top { top: 8px; min-width: 0; padding: 4px 12px 6px; }
  #yearBig { font-size: 22px; }
  #search { top: 74px; left: 8px; right: 8px; width: auto; }
  #q { height: 36px; }
  #timeline { left: 6px; right: 6px; bottom: 6px; padding: 6px 8px 4px; }
  .controls select, .controls button[data-step="-100"], .controls button[data-step="100"] { display: none; }}
