:root {
  --ink: #17212b;
  --muted: #687481;
  --sea: #cfe7f3;
  --panel: rgba(255, 255, 255, 0.78);
  --accent: #007aff;
}

* {
  box-sizing: border-box;
}

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

body {
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--sea);
}

.hud {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  left: 50%;
  z-index: 700;
  display: grid;
  grid-template-columns: repeat(4, minmax(64px, 1fr)) minmax(108px, 1.15fr);
  gap: 1px;
  width: min(560px, calc(100vw - 24px));
  overflow: hidden;
  border: 1px solid rgba(20, 30, 40, 0.08);
  border-radius: 16px;
  background: rgba(210, 218, 224, 0.52);
  box-shadow: 0 18px 50px rgba(18, 31, 46, 0.18);
  transform: translateX(-50%);
  -webkit-backdrop-filter: blur(18px);
  backdrop-filter: blur(18px);
}

.speed-panel {
  position: fixed;
  left: max(12px, env(safe-area-inset-left));
  bottom: max(92px, calc(env(safe-area-inset-bottom) + 92px));
  z-index: 690;
  width: min(390px, calc(100vw - 24px));
  padding: 12px;
  border: 1px solid rgba(20, 30, 40, 0.08);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: 0 20px 54px rgba(18, 31, 46, 0.18);
  -webkit-backdrop-filter: blur(18px);
  backdrop-filter: blur(18px);
}

.speed-panel.is-hidden {
  display: none;
}

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

.dashboard-head strong {
  display: block;
  font-size: 17px;
  line-height: 1.1;
}

.dashboard-toggle,
.module-open {
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid rgba(20, 30, 40, 0.08);
  border-radius: 999px;
  color: #17212b;
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  background: rgba(245, 248, 250, 0.92);
}

.module-tabs {
  position: fixed;
  left: max(12px, env(safe-area-inset-left));
  bottom: max(48px, calc(env(safe-area-inset-bottom) + 48px));
  z-index: 700;
  display: flex;
  gap: 8px;
}

.module-open {
  color: #fff;
  font-size: 13px;
  background: var(--accent);
  box-shadow: 0 14px 34px rgba(18, 31, 46, 0.18);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
}

.module-open.active {
  background: rgba(23, 33, 43, 0.86);
}

.dashboard-metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 1px;
  overflow: hidden;
  margin-bottom: 10px;
  border-radius: 12px;
  background: rgba(20, 30, 40, 0.07);
}

.dashboard-metrics > div {
  min-width: 0;
  padding: 9px 10px;
  background: rgba(255, 255, 255, 0.68);
}

.dashboard-metrics strong {
  display: block;
  overflow: hidden;
  font-size: 17px;
  line-height: 1.1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.measure-panel {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  align-items: center;
  margin-bottom: 10px;
  padding: 9px 10px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.68);
}

.measure-panel strong {
  display: block;
  font-size: 18px;
  line-height: 1.1;
}

.measure-actions {
  grid-column: 1 / -1;
  display: flex;
  gap: 6px;
}

.measure-actions button {
  min-height: 32px;
  padding: 0 10px;
  border: 0;
  border-radius: 9px;
  color: #17212b;
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  background: rgba(235, 240, 244, 0.95);
}

.measure-actions button.active {
  color: #fff;
  background: var(--accent);
}

.measure-actions button:disabled {
  color: rgba(23, 33, 43, 0.42);
}

.sync-button {
  min-height: 40px;
  width: 100%;
  padding: 0 12px;
  border: 1px solid rgba(20, 30, 40, 0.08);
  border-radius: 12px;
  color: #fff;
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  background: var(--accent);
  box-shadow: 0 10px 24px rgba(0, 82, 180, 0.18);
}

.sync-button:disabled {
  color: rgba(255, 255, 255, 0.75);
  background: #7aaee7;
}

.sync-status {
  max-width: none;
  min-height: 0;
  padding: 0;
  overflow: hidden;
  border-radius: 12px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
  background: rgba(245, 248, 250, 0.9);
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity 0.2s ease, transform 0.2s ease, padding 0.2s ease;
  -webkit-backdrop-filter: blur(18px);
  backdrop-filter: blur(18px);
}

.sync-status.visible {
  margin-top: 8px;
  padding: 10px 12px;
  opacity: 1;
  transform: translateY(0);
}

.manual-point-form {
  display: grid;
  gap: 9px;
  margin-bottom: 10px;
  padding: 9px 10px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.68);
}

.manual-form-head strong {
  display: block;
  font-size: 15px;
  line-height: 1.1;
}

.manual-form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.manual-form-grid label {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.manual-form-grid span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 650;
}

.manual-form-grid input {
  width: 100%;
  min-height: 34px;
  border: 1px solid rgba(20, 30, 40, 0.12);
  border-radius: 9px;
  padding: 0 8px;
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  background: rgba(255, 255, 255, 0.86);
}

.manual-time {
  grid-column: 1 / -1;
}

.manual-point-form button {
  min-height: 38px;
  border: 0;
  border-radius: 11px;
  color: #fff;
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  background: var(--accent);
}

.manual-point-form button:disabled {
  color: rgba(255, 255, 255, 0.75);
  background: #7aaee7;
}

.manual-status {
  max-height: 0;
  overflow: hidden;
  border-radius: 10px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
  background: rgba(245, 248, 250, 0.9);
  opacity: 0;
  transition: opacity 0.2s ease, max-height 0.2s ease, padding 0.2s ease;
}

.manual-status.visible {
  max-height: 80px;
  padding: 9px 10px;
  opacity: 1;
}

.dashboard-actions {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.gpx-button {
  display: grid;
  min-height: 40px;
  place-items: center;
  border: 1px solid rgba(20, 30, 40, 0.08);
  border-radius: 12px;
  color: #17212b;
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
  background: rgba(235, 240, 244, 0.95);
}

.speed-panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.speed-panel-head strong {
  font-size: 14px;
}

.speed-panel-head span {
  color: var(--muted);
  font-size: 11px;
}

#speed-chart {
  display: block;
  width: 100%;
  height: 118px;
}

.hud > div {
  min-width: 0;
  display: grid;
  grid-template-rows: 14px 32px;
  align-items: center;
  min-height: 58px;
  padding: 9px 12px;
  background: var(--panel);
}

.label {
  display: block;
  overflow: hidden;
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hud strong {
  display: block;
  overflow: hidden;
  font-size: 16px;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hud-action {
  display: grid;
  grid-template-rows: 14px 32px;
  align-items: center;
  gap: 0;
}

.hud-action button {
  width: min(100%, 82px);
  min-height: 30px;
  border: 0;
  border-radius: 9px;
  color: #fff;
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  background: var(--accent);
}

.hud-action button:disabled {
  color: rgba(255, 255, 255, 0.72);
  background: #8bbbea;
}

.hud-action button.copied {
  background: #1f9d55;
}

.leaflet-control-attribution {
  font-size: 10px;
}

.leaflet-popup-content-wrapper {
  overflow: hidden;
  border: 1px solid rgba(20, 30, 40, 0.08);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.82);
  box-shadow: 0 22px 60px rgba(18, 31, 46, 0.24);
  -webkit-backdrop-filter: blur(18px);
  backdrop-filter: blur(18px);
}

.leaflet-popup-content {
  width: 270px !important;
  margin: 0;
}

.popup {
  padding: 14px;
}

.popup-title {
  margin: 0 0 10px;
  font-size: 16px;
}

.popup-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 12px;
}

.metric {
  min-width: 0;
}

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

.metric strong {
  display: block;
  overflow-wrap: anywhere;
  font-size: 13px;
  font-weight: 650;
}

.copy-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 14px;
}

.copy-row button {
  min-height: 34px;
  border: 0;
  border-radius: 10px;
  color: #fff;
  font: inherit;
  font-size: 12px;
  font-weight: 650;
  background: var(--accent);
  transition: background 0.16s ease, transform 0.16s ease;
}

.copy-row button.copied {
  background: #1f9d55;
  transform: translateY(-1px);
}

.track-line {
  filter: drop-shadow(0 2px 4px rgba(0, 75, 150, 0.25));
}

.measure-line {
  filter: drop-shadow(0 2px 5px rgba(255, 149, 0, 0.25));
}

.measure-point {
  width: 14px;
  height: 14px;
  border: 3px solid #fff;
  border-radius: 999px;
  background: #ff9500;
  box-shadow: 0 4px 14px rgba(18, 31, 46, 0.24);
}

body.measure-active #map {
  cursor: crosshair;
}

.last-pulse {
  width: 18px;
  height: 18px;
  border: 3px solid #fff;
  border-radius: 999px;
  background: var(--accent);
  box-shadow: 0 0 0 rgba(0, 122, 255, 0.55);
  animation: pulse 1.8s infinite;
}

.place-label {
  cursor: pointer;
}

.place-label span {
  display: inline-block;
  padding: 3px 8px;
  border: 1px solid rgba(20, 30, 40, 0.08);
  border-radius: 999px;
  color: #24313d;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
  background: rgba(255, 255, 255, 0.78);
  box-shadow: 0 6px 18px rgba(18, 31, 46, 0.12);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}

.place-popup {
  display: grid;
  gap: 5px;
  min-width: 150px;
  padding: 10px 12px;
}

.place-info-popup .leaflet-popup-content {
  width: auto !important;
  margin: 0;
}

.place-info-popup .leaflet-popup-tip {
  background: rgba(255, 255, 255, 0.86);
}

.place-popup strong {
  font-size: 14px;
}

.place-popup span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(0, 122, 255, 0.55);
  }
  70% {
    box-shadow: 0 0 0 18px rgba(0, 122, 255, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(0, 122, 255, 0);
  }
}

@media (max-width: 460px) {
  .hud {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    width: calc(100vw - 16px);
    border-radius: 14px;
  }

  .hud > div {
    min-height: 54px;
    grid-template-rows: 14px 30px;
    padding: 8px 8px;
  }

  .hud strong {
    font-size: 14px;
  }

  .hud-action {
    grid-column: 1 / -1;
    grid-template-columns: 1fr auto;
    grid-template-rows: 34px;
    align-items: center;
    gap: 8px;
  }

  .hud-action .label {
    margin: 0;
    font-size: 12px;
  }

  .hud-action button {
    width: 82px;
  }

  .speed-panel {
    left: 8px;
    bottom: 84px;
    width: calc(100vw - 16px);
  }

  .module-tabs {
    left: 8px;
    bottom: 40px;
  }
}
