:root {
  --bg: #f4f1eb;
  --panel: #fffdf8;
  --ink: #202326;
  --muted: #697074;
  --line: #d8d2c7;
  --shadow: 0 18px 44px rgba(31, 35, 38, 0.16);
  --accent: #256d72;
  --accent-2: #b64c3f;
  --green: #477f5b;
  --blue: #316a9c;
  --gold: #b88624;
  --sheet-peek: 138px;
}

* {
  box-sizing: border-box;
}

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

body {
  color: var(--ink);
  background: var(--bg);
  font-family:
    Inter,
    "Segoe UI",
    Arial,
    sans-serif;
}

button,
input {
  font: inherit;
}

.app {
  min-height: 100%;
}

.topbar {
  position: fixed;
  z-index: 20;
  top: 0;
  right: 0;
  left: 0;
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 72px;
  padding: 12px 18px;
  border-bottom: 1px solid rgba(46, 48, 50, 0.12);
  background: rgba(255, 253, 248, 0.94);
  backdrop-filter: blur(14px);
}

.topbar h1 {
  margin: 1px 0 0;
  font-size: 22px;
  font-weight: 720;
  letter-spacing: 0;
}

.eyebrow {
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
  text-transform: uppercase;
}

.topbarMetric {
  margin-left: auto;
  color: var(--muted);
  font-size: 14px;
  text-align: right;
}

.hidden {
  display: none !important;
}

.icon-button {
  display: inline-grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #fffaf1;
  cursor: pointer;
}

.icon-button:hover {
  border-color: #b9b0a2;
  background: #fff4df;
}

.modeLink {
  display: inline-grid;
  min-width: 42px;
  height: 36px;
  place-items: center;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #fffaf1;
  font-size: 13px;
  font-weight: 760;
  text-decoration: none;
}

.modeLink:hover {
  border-color: #b9b0a2;
  background: #fff4df;
}

.cityMenu {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 360px));
  justify-content: center;
  gap: 22px;
  min-height: 100vh;
  padding: 112px 24px 36px;
  align-content: start;
}

.cityMenu:empty::after {
  justify-self: center;
  align-self: start;
  width: min(360px, 100%);
  padding: 18px;
  border: 1px solid rgba(65, 66, 66, 0.16);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.94);
  box-shadow: 0 12px 30px rgba(31, 35, 38, 0.1);
  color: var(--muted);
  content: "Загрузка городов...";
}

.cityMenuMessage {
  justify-self: center;
  width: min(420px, 100%);
  padding: 18px;
  border: 1px solid rgba(65, 66, 66, 0.16);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.96);
  box-shadow: 0 12px 30px rgba(31, 35, 38, 0.1);
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.cityCard {
  --mx: 0.5;
  --my: 0.5;
  --pos: 50% 50%;
  --posx: 50%;
  --posy: 50%;
  --glare-pos: 50% 50%;
  --angle: 0deg;
  position: relative;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto minmax(170px, 1fr) auto;
  gap: 16px;
  min-height: 420px;
  padding: 18px;
  border: 1px solid rgba(210, 198, 179, 0.9);
  border-radius: 8px;
  background: #fffdf8;
  color: var(--ink);
  box-shadow:
    0 18px 42px rgba(38, 42, 43, 0.14),
    inset 0 1px 0 rgba(255, 255, 255, 0.86);
  cursor: pointer;
  isolation: isolate;
  transform-style: preserve-3d;
  transition:
    transform 180ms ease,
    box-shadow 180ms ease;
}

.cityCard::before {
  position: absolute;
  z-index: -1;
  inset: -35%;
  content: "";
  background:
    radial-gradient(circle at var(--glare-pos), rgba(255, 255, 255, 0.9), transparent 22%),
    conic-gradient(
      from var(--angle),
      rgba(255, 255, 255, 0.12),
      rgba(88, 154, 159, 0.28),
      rgba(238, 210, 111, 0.26),
      rgba(184, 76, 110, 0.2),
      rgba(119, 176, 130, 0.24),
      rgba(255, 255, 255, 0.12)
    );
  animation: shimmerSpin 11s linear infinite;
  opacity: 0.9;
}

.cityCard::after {
  position: absolute;
  inset: 1px;
  z-index: -1;
  border-radius: 7px;
  content: "";
  background:
    radial-gradient(circle at var(--pos), rgba(255, 255, 255, 0.52), transparent 26%),
    linear-gradient(115deg, transparent 0 34%, rgba(255, 255, 255, 0.5) 44%, transparent 54%),
    linear-gradient(145deg, rgba(255, 253, 248, 0.94), rgba(246, 239, 226, 0.92) 46%, rgba(235, 241, 237, 0.92));
}

.cityCard > * {
  position: relative;
  z-index: 1;
}

@keyframes shimmerSpin {
  to {
    transform: rotate(1turn);
  }
}

.cityCard:hover {
  box-shadow: 0 30px 70px rgba(22, 29, 30, 0.3);
}

.cityCardTop {
  display: flex;
  gap: 18px;
  justify-content: space-between;
  align-items: flex-start;
}

.cityName {
  margin: 0;
  font-size: 31px;
  font-weight: 760;
  line-height: 1.08;
}

.cityRating {
  text-align: right;
  white-space: nowrap;
}

.cityRating strong {
  display: block;
  font-size: 38px;
  font-weight: 760;
  line-height: 1;
}

.cityRating span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.muted {
  color: var(--muted);
}

.crestSlot {
  display: grid;
  place-items: center;
  align-self: center;
  justify-self: center;
  width: min(68%, 190px);
  aspect-ratio: 4 / 5;
  border: 1px solid rgba(191, 178, 157, 0.72);
  border-radius: 8px;
  background:
    linear-gradient(160deg, rgba(37, 109, 114, 0.08), transparent 35%),
    rgba(255, 250, 241, 0.86);
}

.crestSlot img {
  display: block;
  max-width: 78%;
  max-height: 82%;
  object-fit: contain;
  filter: drop-shadow(0 10px 18px rgba(42, 46, 48, 0.14));
}

.cityFacts {
  display: grid;
  gap: 8px;
  margin: 0;
}

.cityFacts div {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 9px 0;
  border-bottom: 1px solid rgba(86, 80, 71, 0.12);
}

.cityFacts dt {
  color: var(--muted);
  font-size: 13px;
}

.cityFacts dd {
  margin: 0;
  font-size: 14px;
  font-weight: 720;
}

.mapShell {
  position: fixed;
  inset: 72px 0 0;
  overflow: hidden;
  background: #e7e0d3;
}

#mapCanvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
}

#mapCanvas.dragging {
  cursor: grabbing;
}

.mapControls {
  position: absolute;
  z-index: 5;
  top: 16px;
  left: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: min(320px, calc(100vw - 32px));
}

.controlGroup {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px;
  border: 1px solid rgba(65, 66, 66, 0.16);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.94);
  box-shadow: 0 12px 30px rgba(31, 35, 38, 0.1);
}

.controlGroup.compact {
  width: max-content;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 30px;
  padding: 4px 8px;
  border: 1px solid #ded6c9;
  border-radius: 8px;
  background: #fffaf1;
  color: var(--ink);
  font-size: 13px;
  white-space: nowrap;
}

.toggle input {
  width: 15px;
  height: 15px;
  accent-color: var(--accent);
}

.infoPanel {
  position: absolute;
  z-index: 6;
  top: 16px;
  right: 16px;
  width: min(380px, calc(100vw - 32px));
  max-height: calc(100vh - 112px);
  overflow: auto;
  padding: 16px;
  border: 1px solid rgba(65, 66, 66, 0.16);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.96);
  box-shadow: var(--shadow);
}

.panelTitle {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
  margin-bottom: 14px;
}

.sheetHandle {
  display: none;
}

.panelTitle h2 {
  margin: 0;
  font-size: 20px;
}

.metricGrid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 14px;
}

.metric {
  padding: 10px;
  border: 1px solid #e2dbcf;
  border-radius: 8px;
  background: #fffaf1;
}

.metric strong {
  display: block;
  font-size: 22px;
  font-variant-numeric: tabular-nums;
}

.metric span {
  color: var(--muted);
  font-size: 12px;
}

.barList {
  display: grid;
  gap: 8px;
}

.barRow {
  display: grid;
  grid-template-columns: 116px 1fr 44px;
  gap: 8px;
  align-items: center;
  font-size: 13px;
}

.helpText,
.indicatorGroup h3,
.indicator {
  cursor: help;
}

.barTrack {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #e2dbcf;
}

.barFill {
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 1600ms cubic-bezier(0.45, 0, 0.55, 1);
}

.barRow strong {
  font-variant-numeric: tabular-nums;
}

.indicatorList {
  display: grid;
  gap: 12px;
  margin-top: 14px;
}

.indicatorGroup h3 {
  margin: 0 0 7px;
  font-size: 14px;
  font-weight: 760;
}

.indicator {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto 58px;
  align-items: baseline;
  gap: 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid #ece4d8;
  color: var(--muted);
  font-size: 13px;
}

.indicator em {
  color: #8a8175;
  font-size: 12px;
  font-style: normal;
  white-space: nowrap;
}

.indicator strong {
  color: var(--ink);
  text-align: right;
}

.legend {
  position: absolute;
  z-index: 5;
  left: 16px;
  right: auto;
  bottom: 16px;
  display: grid;
  gap: 7px;
  width: min(280px, calc(100vw - 32px));
  padding: 12px;
  border: 1px solid rgba(65, 66, 66, 0.16);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.94);
  color: var(--muted);
  font-size: 12px;
  transition:
    opacity 220ms ease,
    transform 220ms ease;
}

.legend.legendHidden {
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
}

.symbolLegend {
  position: absolute;
  z-index: 5;
  left: 16px;
  bottom: 16px;
  width: min(280px, calc(100vw - 32px));
  padding: 12px;
  border: 1px solid rgba(65, 66, 66, 0.16);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.94);
  color: var(--muted);
  font-size: 12px;
  transition:
    bottom 220ms ease,
    opacity 220ms ease,
    transform 220ms ease;
}

.symbolLegend.legendOffset {
  bottom: 112px;
}

.legendTitle {
  color: var(--ink);
  font-weight: 720;
}

.legendGradient {
  height: 10px;
  border-radius: 999px;
  background: linear-gradient(90deg, #a83d4b, #d97842, #dfbd54, #76ad70, #2d7b78);
}

.legendScale {
  display: flex;
  justify-content: space-between;
}

.legendSymbols {
  display: grid;
  gap: 6px;
}

.legendSymbols span {
  display: flex;
  align-items: center;
  gap: 7px;
}

.dot {
  display: inline-block;
  flex: 0 0 auto;
  width: 9px;
  height: 9px;
  border: 1px solid #fff;
  border-radius: 50%;
}

.dot.bus {
  background: #316a9c;
}

.dot.tram {
  border-radius: 2px;
  background: #b64c3f;
}

.dot.crash,
.dot.accident {
  background: #b64c3f;
}

.dot.crash.small {
  width: 7px;
  height: 7px;
  margin-right: -4px;
}

.dot.crash.big {
  width: 14px;
  height: 14px;
}

.accidentPopup {
  position: absolute;
  z-index: 8;
  display: grid;
  gap: 3px;
  min-width: 190px;
  max-width: 260px;
  padding: 10px 12px;
  border: 1px solid rgba(80, 52, 47, 0.2);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.98);
  box-shadow: 0 14px 34px rgba(31, 35, 38, 0.2);
  color: var(--ink);
  font-size: 12px;
  transform: translate(-50%, calc(-100% - 14px));
  pointer-events: none;
}

.accidentPopup::after {
  position: absolute;
  left: 50%;
  bottom: -7px;
  width: 12px;
  height: 12px;
  content: "";
  border-right: 1px solid rgba(80, 52, 47, 0.2);
  border-bottom: 1px solid rgba(80, 52, 47, 0.2);
  background: rgba(255, 253, 248, 0.98);
  transform: translateX(-50%) rotate(45deg);
}

.accidentPopup strong {
  font-size: 13px;
}

.accidentPopup small {
  color: var(--muted);
}

@media (max-width: 860px) {
  .topbar {
    min-height: 66px;
    padding: 10px 12px;
  }

  .topbar h1 {
    font-size: 18px;
  }

  .topbarMetric {
    display: none;
  }

  .cityMenu {
    padding: 90px 14px 20px;
    grid-template-columns: minmax(0, 1fr);
  }

  .cityCard {
    min-height: 480px;
  }

  .cityName {
    font-size: 23px;
  }

  .cityRating strong {
    font-size: 30px;
  }

  .mapShell {
    top: 66px;
  }

  .infoPanel {
    top: auto;
    right: 0;
    bottom: 0;
    left: 0;
    width: auto;
    height: calc(100dvh - 66px);
    max-height: none;
    padding: 18px 12px 20px;
    border-right: 0;
    border-bottom: 0;
    border-left: 0;
    border-radius: 14px 14px 0 0;
    background: #fffdf8;
    overflow: auto;
    transform: translateY(calc(100% - var(--sheet-peek)));
    transition: transform 260ms ease;
    touch-action: none;
    user-select: none;
    will-change: transform;
  }

  .infoPanel.sheetExpanded {
    transform: translateY(0);
    touch-action: pan-y;
  }

  .sheetHandle {
    display: block;
    width: 42px;
    height: 4px;
    margin: 0 auto 10px;
    padding: 0;
    border: 0;
    border-radius: 999px;
    background: #d6cec1;
    cursor: ns-resize;
    touch-action: none;
  }

  .infoPanel .panelTitle {
    margin-bottom: 10px;
  }

  .infoPanel .metricGrid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
    margin-bottom: 0;
  }

  .infoPanel .metric {
    min-width: 0;
    padding: 7px 5px;
  }

  .infoPanel .metric strong {
    font-size: 18px;
    line-height: 1.05;
    white-space: nowrap;
  }

  .infoPanel .metric span {
    display: block;
    margin-top: 4px;
    font-size: 9.5px;
    line-height: 1.05;
    overflow-wrap: anywhere;
  }

  .infoPanel .barRow {
    grid-template-columns: 92px 1fr 34px;
    gap: 6px;
  }

  .infoPanel .barList {
    margin-top: 12px;
  }

  .legend,
  .symbolLegend {
    display: none;
  }
}
