:root {
  --bg: #0b1017;
  --bg-soft: #121a24;
  --bg-elev: #17212e;
  --line: #24303f;
  --text: #eef3f9;
  --muted: #93a4b8;
  --accent: #38bdf8;
  --accent-soft: rgba(56, 189, 248, 0.14);
  --sea: #0d1620;
  --land: #1b2532;
  --land-line: #2b3948;
  --topbar-h: 62px;
  --radius: 14px;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.45);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

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

.app {
  display: grid;
  grid-template-rows: var(--topbar-h) minmax(0, 1fr) auto;
  grid-template-columns: minmax(0, 1fr);
  height: 100dvh;
  width: 100%;
  overflow: hidden;
}

/* ---------- Шапка ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 14px;
  background: linear-gradient(180deg, #131c27, #0e1620);
  border-bottom: 1px solid var(--line);
  z-index: 30;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand__mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 26px;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.14);
  flex: none;
}

.brand__mark svg {
  display: block;
}

.brand__text h1 {
  margin: 0;
  font-size: 16px;
  letter-spacing: 0.2px;
  white-space: nowrap;
}

.brand__text p {
  margin: 1px 0 0;
  font-size: 11.5px;
  color: var(--muted);
  white-space: nowrap;
}

.period {
  margin-left: auto;
  text-align: center;
  min-width: 0;
}

.period__title {
  font-size: 15px;
  font-weight: 650;
  white-space: nowrap;
}

.period__meta {
  font-size: 11.5px;
  color: var(--muted);
  white-space: nowrap;
}

.topbar__actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg-soft);
  color: var(--text);
  cursor: pointer;
  font-size: 17px;
  line-height: 1;
  transition: background 0.15s, border-color 0.15s;
}

.icon-btn:hover {
  background: var(--bg-elev);
  border-color: #35485e;
}

.icon-btn.is-active {
  background: var(--accent-soft);
  border-color: rgba(56, 189, 248, 0.5);
  color: var(--accent);
}

/* ---------- Сцена ---------- */
.stage {
  position: relative;
  display: flex;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
}

.map-wrap {
  position: relative;
  flex: 1;
  min-width: 0;
  background: radial-gradient(circle at 60% 35%, #101d2b, var(--sea) 70%);
  touch-action: none;
  cursor: grab;
  overflow: hidden;
}

.map-wrap.is-grabbing {
  cursor: grabbing;
}

#map {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}

.country {
  fill: var(--land);
  stroke: var(--land-line);
  stroke-width: 0.7;
  vector-effect: non-scaling-stroke;
}

.grid-line {
  fill: none;
  stroke: rgba(120, 160, 200, 0.09);
  stroke-width: 0.6;
  vector-effect: non-scaling-stroke;
}

.state {
  fill-opacity: 0.38;
  stroke-width: 2;
  stroke-opacity: 0.95;
  vector-effect: non-scaling-stroke;
  cursor: pointer;
  transition: fill-opacity 0.18s;
}

.state:hover {
  fill-opacity: 0.62;
}

.state.is-selected {
  fill-opacity: 0.7;
  stroke-width: 3.5;
}

.state.is-dimmed {
  fill-opacity: 0.08;
  stroke-opacity: 0.25;
}

.state-label {
  pointer-events: none;
}

.state-label.is-dimmed {
  opacity: 0.25;
}

.state-label__name {
  fill: #fff;
  font-size: 13px;
  font-weight: 650;
  text-anchor: middle;
  paint-order: stroke;
  stroke: rgba(6, 12, 20, 0.85);
  stroke-width: 3.5px;
  stroke-linejoin: round;
}

.state-label__years {
  fill: #d5e3f2;
  font-size: 10.5px;
  text-anchor: middle;
  paint-order: stroke;
  stroke: rgba(6, 12, 20, 0.85);
  stroke-width: 3px;
  stroke-linejoin: round;
}

.map-tools {
  position: absolute;
  right: 12px;
  top: 12px;
  display: grid;
  gap: 6px;
  z-index: 5;
}

.map-hint {
  position: absolute;
  left: 12px;
  bottom: 12px;
  max-width: 300px;
  padding: 8px 11px;
  border-radius: 10px;
  background: rgba(12, 20, 30, 0.78);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.45;
  backdrop-filter: blur(6px);
  transition: opacity 0.4s;
}

.map-hint.is-hidden {
  opacity: 0;
  pointer-events: none;
}

.tooltip {
  position: absolute;
  z-index: 10;
  pointer-events: none;
  padding: 7px 10px;
  border-radius: 9px;
  background: rgba(10, 16, 24, 0.94);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  font-size: 12px;
  max-width: 240px;
  transform: translate(-50%, -130%);
}

.tooltip__name {
  font-weight: 650;
}

.tooltip__years {
  color: var(--muted);
  font-size: 11px;
  margin-top: 2px;
}

/* ---------- Панель ---------- */
.panel {
  width: 356px;
  flex: none;
  display: flex;
  flex-direction: column;
  background: var(--bg-soft);
  border-left: 1px solid var(--line);
  position: relative;
  min-height: 0;
}

.panel__handle {
  display: none;
}

.panel__tabs {
  display: flex;
  gap: 6px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}

.tab {
  flex: 1;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
}

.tab.is-active {
  background: var(--bg-elev);
  border-color: var(--line);
  color: var(--text);
}

.panel__body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.state-list {
  list-style: none;
  margin: 0;
  padding: 8px;
  display: grid;
  gap: 6px;
}

.state-item {
  display: grid;
  grid-template-columns: 6px 1fr;
  gap: 10px;
  align-items: stretch;
  padding: 10px 12px 10px 0;
  border-radius: 12px;
  background: var(--bg-elev);
  border: 1px solid transparent;
  cursor: pointer;
  text-align: left;
  width: 100%;
  overflow: hidden;
}

.state-item:hover {
  border-color: #34465c;
}

.state-item.is-selected {
  border-color: var(--accent);
  background: #1b2836;
}

.state-item__bar {
  border-radius: 6px 0 0 6px;
  margin: -10px 0;
}

.state-item__name {
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1.3;
}

.state-item__meta {
  margin-top: 3px;
  font-size: 11.5px;
  color: var(--muted);
}

.state-item__era {
  display: inline-block;
  justify-self: start;
  margin-top: 6px;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(147, 164, 184, 0.12);
  color: var(--muted);
  font-size: 10.5px;
}

.list-group {
  padding: 14px 12px 4px;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #64798f;
}

.list-note {
  padding: 14px 14px 22px;
  color: #64798f;
  font-size: 11.5px;
  line-height: 1.5;
}

.empty {
  padding: 30px 20px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

/* ---------- Карточка государства ---------- */
.detail {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg-soft);
  z-index: 4;
}

.detail__back {
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  padding: 13px 14px;
  text-align: left;
  cursor: pointer;
  font-size: 13px;
}

.detail__scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 16px 16px 26px;
}

.detail__color {
  height: 5px;
  border-radius: 999px;
  margin-bottom: 14px;
}

.detail h2 {
  margin: 0 0 4px;
  font-size: 19px;
  line-height: 1.25;
}

.detail__native {
  color: var(--muted);
  font-size: 12.5px;
  font-style: italic;
}

.detail__years {
  margin: 14px 0;
  padding: 11px 13px;
  border-radius: 12px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  font-size: 14px;
  font-weight: 600;
}

.detail__duration {
  display: block;
  margin-top: 3px;
  font-size: 11.5px;
  font-weight: 400;
  color: var(--muted);
}

.detail__row {
  margin: 12px 0;
  font-size: 13px;
  line-height: 1.55;
}

.detail__label {
  display: block;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #64798f;
  margin-bottom: 3px;
}

.detail__hint {
  font-size: 11.5px;
  color: #64798f;
  margin-bottom: 8px;
}

.rulers {
  display: grid;
  gap: 5px;
  margin-bottom: 4px;
}

.ruler {
  display: grid;
  gap: 1px;
  text-align: left;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--text);
  cursor: pointer;
}

.ruler:hover {
  border-color: #35485e;
}

.ruler.is-active {
  border-color: rgba(56, 189, 248, 0.55);
  background: var(--accent-soft);
}

.ruler__years {
  font-size: 10.5px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.ruler.is-active .ruler__years {
  color: var(--accent);
}

.ruler__name {
  font-size: 13px;
  font-weight: 600;
}

.ruler__note {
  font-size: 11.5px;
  color: var(--muted);
  line-height: 1.45;
}

.detail__facts {
  margin: 8px 0 0;
  padding-left: 18px;
  font-size: 13px;
  line-height: 1.6;
  color: #cfdcea;
}

.detail__facts li {
  margin-bottom: 5px;
}

.detail__sources {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  font-size: 11px;
  line-height: 1.5;
  color: #64798f;
}

.detail__actions {
  display: flex;
  gap: 8px;
  margin-top: 18px;
}

.btn {
  flex: 1;
  padding: 11px 12px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: var(--bg-elev);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
}

.btn--accent {
  background: var(--accent-soft);
  border-color: rgba(56, 189, 248, 0.45);
  color: var(--accent);
}

/* ---------- Таймлайн ---------- */
.timeline {
  position: relative;
  min-width: 0;
  overflow: hidden;
  border-top: 1px solid var(--line);
  background: linear-gradient(180deg, #0f1823, #0b1017);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 20;
}

/* Метка центра шкалы — показывает, какое десятилетие выбрано */
.timeline::before {
  content: '';
  position: absolute;
  left: 50%;
  top: 36px;
  height: 62px;
  width: 2px;
  margin-left: -1px;
  border-radius: 2px;
  background: linear-gradient(180deg, rgba(56, 189, 248, 0.75), rgba(56, 189, 248, 0.05));
  pointer-events: none;
  z-index: 1;
}

.rail {
  display: flex;
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  outline: none;
}

.rail::-webkit-scrollbar {
  display: none;
}

.rail__track {
  display: flex;
  align-items: flex-end;
  padding: 10px 50vw 8px;
}

.decade {
  scroll-snap-align: center;
  flex: none;
  width: 56px;
  display: grid;
  justify-items: center;
  gap: 4px;
  padding: 4px 0 2px;
  background: none;
  border: 0;
  cursor: pointer;
  color: var(--muted);
  transition: color 0.15s;
}

.decade:hover {
  color: var(--text);
}

.decade.is-active {
  color: var(--accent);
}

.decade__bars {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 22px;
}

.decade__bar {
  width: 4px;
  height: 100%;
  border-radius: 2px;
  opacity: 0.85;
}

.decade__label {
  font-size: 11.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.decade__note {
  font-size: 9px;
  opacity: 0.6;
  white-space: nowrap;
}

.decade.is-active .decade__label {
  text-shadow: 0 0 14px rgba(56, 189, 248, 0.6);
}

.decade.is-active::after {
  content: '';
  position: absolute;
  width: 1px;
}

/* Быстрые переходы по эпохам */
.chips {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 8px 12px 2px;
}

.chips::-webkit-scrollbar {
  display: none;
}

.chip {
  flex: none;
  padding: 5px 11px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg-soft);
  color: var(--muted);
  font-size: 11.5px;
  white-space: nowrap;
  cursor: pointer;
}

.chip:hover {
  color: var(--text);
  border-color: #35485e;
}

.chip.is-active {
  background: var(--accent-soft);
  border-color: rgba(56, 189, 248, 0.5);
  color: var(--accent);
}

.slider-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 14px 12px;
}

#yearSlider {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  border-radius: 3px;
  background: linear-gradient(90deg, #1f6feb33, #38bdf855);
  border: 1px solid var(--line);
  outline: none;
}

#yearSlider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid #0b1017;
  box-shadow: 0 0 0 1px var(--accent);
  cursor: pointer;
}

#yearSlider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid #0b1017;
  cursor: pointer;
}

.year-badge {
  min-width: 92px;
  text-align: center;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.only-mobile {
  display: none;
}

/* ---------- Планшет ---------- */
@media (max-width: 1100px) {
  .panel {
    width: 310px;
  }

  .brand__text p {
    display: none;
  }
}

/* ---------- Мобильные ---------- */
@media (max-width: 820px) {
  :root {
    --topbar-h: 56px;
  }

  .topbar {
    gap: 8px;
    padding: 0 10px;
  }

  .brand__text {
    display: none;
  }

  .period {
    margin-left: 0;
    text-align: left;
    flex: 1;
    min-width: 0;
  }

  .period__title {
    font-size: 13.5px;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .period__meta {
    font-size: 10.5px;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .topbar__actions {
    gap: 6px;
  }

  .icon-btn {
    width: 32px;
    height: 32px;
  }

  .only-mobile {
    display: grid;
  }

  .stage {
    position: relative;
  }

  .panel {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    height: 72dvh;
    border-left: 0;
    border-top: 1px solid var(--line);
    border-radius: 18px 18px 0 0;
    box-shadow: var(--shadow);
    transform: translateY(100%);
    transition: transform 0.28s cubic-bezier(0.32, 0.72, 0, 1);
    z-index: 25;
  }

  .panel.is-open {
    transform: translateY(0);
  }

  .panel__handle {
    display: block;
    width: 42px;
    height: 4px;
    border: 0;
    border-radius: 999px;
    background: #3a4a5e;
    margin: 9px auto 3px;
    padding: 0;
    cursor: pointer;
  }

  .map-hint {
    max-width: none;
    right: 12px;
    bottom: 10px;
    font-size: 11px;
  }

  .decade {
    width: 52px;
  }

  .rail__track {
    padding: 6px 50vw 4px;
  }

  .chips {
    padding: 6px 10px 0;
  }

  .slider-row {
    padding: 4px 12px 10px;
  }

  .year-badge {
    min-width: 84px;
    font-size: 12px;
  }

  .state-label__name {
    font-size: 12px;
  }
}

@media (max-width: 380px) {
  .brand__text h1 {
    font-size: 14px;
  }
}

/* Мобильный ландшафт: экономим вертикаль */
@media (max-height: 520px) and (orientation: landscape) {
  .decade__bars {
    height: 14px;
  }

  .decade__note {
    display: none;
  }

  .panel {
    height: 88dvh;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
