:root {
  --bg-top: #f7fbff;
  --bg-bottom: #e5eef8;
  --panel-bg: rgba(252, 255, 255, 0.9);
  --panel-border: rgba(54, 80, 111, 0.14);
  --text-main: #243648;
  --text-soft: #56687a;
  --accent-1: #f5bf36;
  --accent-2: #1eb0a2;
  --accent-3: #3290f5;
  --danger: #ee6a65;
  --shadow: 0 18px 34px rgba(56, 84, 112, 0.14);
  --radius-lg: 18px;
  --radius-md: 14px;
  --radius-sm: 10px;
}

* {
  box-sizing: border-box;
}

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

body {
  font-family: Manrope, "Avenir Next", "Segoe UI", sans-serif;
  color: var(--text-main);
  background: radial-gradient(1200px 500px at 15% -5%, #ffffff, transparent 70%),
    linear-gradient(180deg, var(--bg-top) 0%, var(--bg-bottom) 100%);
}

.app-shell {
  width: 100%;
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

.top-panel {
  position: sticky;
  top: 0;
  z-index: 10;
  padding: 14px 16px 12px;
  backdrop-filter: blur(8px);
  background: linear-gradient(
    180deg,
    rgba(252, 255, 255, 0.95) 0%,
    rgba(246, 251, 255, 0.88) 100%
  );
  border-bottom: 1px solid var(--panel-border);
  box-shadow: 0 8px 20px rgba(37, 58, 79, 0.06);
}

.title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.title-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-left: auto;
}

.transport-controls {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.ios-toggle {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  user-select: none;
  cursor: pointer;
}

.ios-toggle-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: #43586d;
  white-space: nowrap;
}

.ios-toggle input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.ios-toggle-track {
  position: relative;
  width: 44px;
  height: 26px;
  border-radius: 999px;
  background: rgba(176, 190, 205, 0.92);
  box-shadow: inset 0 0 0 1px rgba(77, 103, 130, 0.22);
  transition: background 0.2s ease, box-shadow 0.2s ease;
}

.ios-toggle-track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 1px 2px rgba(16, 34, 53, 0.24);
  transition: transform 0.2s ease;
}

.ios-toggle input[type="checkbox"]:checked + .ios-toggle-track {
  background: #34c759;
  box-shadow: inset 0 0 0 1px rgba(30, 145, 61, 0.26);
}

.ios-toggle input[type="checkbox"]:checked + .ios-toggle-track::after {
  transform: translateX(18px);
}

.ios-toggle input[type="checkbox"]:focus-visible + .ios-toggle-track {
  box-shadow:
    inset 0 0 0 1px rgba(77, 103, 130, 0.22),
    0 0 0 3px rgba(50, 144, 245, 0.2);
}

h1 {
  margin: 0;
  font-size: clamp(1.1rem, 1.5vw, 1.45rem);
  letter-spacing: 0.015em;
}

.subtitle {
  margin: 2px 0 0;
  color: var(--text-soft);
  font-size: 0.84rem;
}

.sim-clock {
  font-size: 0.85rem;
  color: #2d4560;
  background: rgba(240, 247, 253, 0.95);
  border: 1px solid rgba(84, 134, 186, 0.16);
  border-radius: 999px;
  padding: 7px 11px;
  white-space: nowrap;
}

.mobile-spoiler {
  display: block;
}

.mobile-spoiler-summary {
  display: none;
  list-style: none;
}

.mobile-spoiler-summary::-webkit-details-marker {
  display: none;
}

.controls-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 10px;
}

.control-card {
  border: 1px solid var(--panel-border);
  background: linear-gradient(165deg, rgba(255, 255, 255, 0.93), rgba(245, 251, 255, 0.88));
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-height: 78px;
}

.control-card > span {
  color: var(--text-soft);
  font-size: 0.76rem;
  line-height: 1.2;
}

.control-card strong {
  font-size: 0.93rem;
  font-weight: 700;
}

.control-card input[type="range"] {
  width: 100%;
  accent-color: #2786db;
}

.sim-speed-range {
  margin: 0;
}

.sim-speed-labels {
  position: relative;
  height: 22px;
  margin-top: 2px;
}

.sim-speed-labels span {
  position: absolute;
  top: 0;
  left: calc((var(--speed-pos) / 7) * 100%);
  transform: translateX(-50%);
  text-align: center;
  font-size: 0.62rem;
  line-height: 1.1;
  color: #7d8fa1;
  padding-top: 8px;
  transition: color 0.15s ease;
}

.sim-speed-labels span::before {
  content: "";
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 2px;
  height: 6px;
  border-radius: 999px;
  background: rgba(86, 120, 156, 0.35);
  transition: background 0.15s ease, height 0.15s ease;
}

.sim-speed-labels span:first-child {
  transform: none;
}

.sim-speed-labels span:last-child {
  transform: translateX(-100%);
}

.sim-speed-labels span:first-child::before {
  left: 0;
  transform: none;
}

.sim-speed-labels span:last-child::before {
  left: 100%;
  transform: translateX(-100%);
}

.sim-speed-labels span.active {
  color: #23405e;
  font-weight: 700;
}

.sim-speed-labels span.active::before {
  height: 8px;
  background: rgba(39, 134, 219, 0.85);
}

.control-card select {
  width: 100%;
  border: 1px solid rgba(66, 95, 126, 0.24);
  border-radius: 8px;
  background: #fbfdff;
  padding: 6px 7px;
  color: #243648;
  font-family: inherit;
  font-size: 0.84rem;
}

.buttons-card {
  justify-content: space-between;
  background: linear-gradient(160deg, rgba(240, 247, 253, 0.86), rgba(246, 251, 255, 0.74));
}

.btn-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

button {
  border: 1px solid rgba(51, 84, 118, 0.2);
  border-radius: 8px;
  padding: 7px 8px;
  font-family: inherit;
  font-size: 0.82rem;
  cursor: pointer;
  color: #22394e;
  background: rgba(244, 249, 253, 0.98);
  transition: transform 0.15s ease, box-shadow 0.2s ease;
}

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 999px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(247, 252, 255, 0.98);
}

.icon-btn svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

.icon-btn:hover:not(:disabled) {
  transform: translateY(-1px);
}

button:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 7px 14px rgba(59, 97, 135, 0.14);
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
}

.metric-card {
  border-radius: var(--radius-md);
  border: 1px solid rgba(49, 78, 107, 0.15);
  background: linear-gradient(155deg, rgba(255, 255, 255, 0.98), rgba(245, 251, 255, 0.9));
  box-shadow: 0 10px 22px rgba(56, 84, 112, 0.08);
  padding: 9px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 72px;
}

.metric-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-soft);
  font-size: 0.76rem;
}

.info-tip {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 15px;
  height: 15px;
  border-radius: 999px;
  border: 1px solid rgba(80, 111, 145, 0.34);
  background: rgba(239, 246, 253, 0.95);
  color: #4b6685;
  font-size: 0.66rem;
  font-weight: 700;
  line-height: 1;
  cursor: help;
  user-select: none;
}

.info-tip::after {
  content: attr(data-tip);
  position: absolute;
  left: 50%;
  bottom: calc(100% + 8px);
  transform: translateX(-50%) translateY(3px);
  min-width: 200px;
  max-width: 260px;
  padding: 7px 9px;
  border-radius: 8px;
  border: 1px solid rgba(56, 80, 106, 0.2);
  background: rgba(251, 254, 255, 0.98);
  box-shadow: 0 10px 22px rgba(35, 56, 78, 0.16);
  color: #27405b;
  font-size: 0.72rem;
  line-height: 1.3;
  text-align: left;
  white-space: normal;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease, transform 0.15s ease;
  z-index: 20;
}

.info-tip:hover::after,
.info-tip:focus-visible::after {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.metric-card strong {
  font-size: 1.02rem;
  letter-spacing: 0.01em;
}

.metric-inline-secondary {
  font-weight: 500;
  font-size: calc(1em - 2px);
}

.map-shell {
  position: relative;
  flex: 1;
  min-height: 360px;
  margin: 12px;
  border-radius: var(--radius-lg);
  border: 1px solid rgba(65, 91, 120, 0.14);
  overflow: hidden;
  background: linear-gradient(180deg, #eef5fb 0%, #e3ebf2 100%);
  box-shadow: 0 12px 30px rgba(52, 79, 107, 0.08);
}

.map-shell canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

#dynamicCanvas {
  pointer-events: none;
}

@media (max-width: 1350px) {
  .controls-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .metrics-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 900px) {
  .controls-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .metrics-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 720px) {
  .top-panel {
    padding: 10px;
  }

  .title-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
  }

  .title-right {
    width: 100%;
    justify-content: flex-start;
  }

  .transport-controls {
    margin-left: auto;
  }

  .controls-grid,
  .metrics-grid {
    grid-template-columns: 1fr;
  }

  .map-shell {
    margin: 8px;
    min-height: 440px;
  }
}

@media (max-width: 768px) and (orientation: portrait) {
  .mobile-spoiler {
    margin-bottom: 8px;
    border: 1px solid var(--panel-border);
    border-radius: var(--radius-md);
    background: linear-gradient(
      160deg,
      rgba(255, 255, 255, 0.96),
      rgba(243, 249, 255, 0.88)
    );
    box-shadow: 0 10px 22px rgba(56, 84, 112, 0.08);
    overflow: hidden;
  }

  .mobile-spoiler-summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 11px 12px;
    color: #29455f;
    font-size: 0.84rem;
    font-weight: 700;
    cursor: pointer;
  }

  .mobile-spoiler-summary::after {
    content: "";
    width: 9px;
    height: 9px;
    flex: none;
    border-right: 2px solid rgba(64, 92, 122, 0.72);
    border-bottom: 2px solid rgba(64, 92, 122, 0.72);
    transform: rotate(45deg);
    transition: transform 0.18s ease;
  }

  .mobile-spoiler[open] > .mobile-spoiler-summary::after {
    transform: rotate(225deg);
  }

  .mobile-spoiler-panel {
    padding: 0 8px 8px;
  }

  .mobile-spoiler .controls-grid,
  .mobile-spoiler .metrics-grid {
    margin-bottom: 0;
  }

  .controls-grid {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .metrics-grid {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .control-card {
    padding: 4px 10px;
  }

  .map-shell {
    min-height: 50vh;
  }
}
