:root {
  color-scheme: light;
  --bg: #eef2f6;
  --panel: #fff;
  --line: #d5dee9;
  --text: #17202c;
  --muted: #667587;
  --blue: #1688e8;
  --blue-dark: #075d9f;
  --green: #2ca145;
  --red: #d74336;
  --gold: #ffc629;
  --shadow: 0 12px 34px rgba(18, 28, 40, .12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at 50% -20%, #fff 0, var(--bg) 48%);
  color: var(--text);
}

button,
input,
select { font: inherit; }

button,
.primary-link,
.navigation-menu a {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 9px 12px;
  background: #f9fbfd;
  color: var(--text);
  font-weight: 800;
  text-decoration: none;
}

button:active,
.primary-link:active { transform: translateY(1px); }

.primary {
  border-color: var(--blue) !important;
  background: linear-gradient(180deg, #35a8ff, var(--blue)) !important;
  color: #fff !important;
}

.navigation-shell {
  width: min(920px, 100%);
  margin: 0 auto;
  padding: 12px 12px 76px;
  display: grid;
  gap: 12px;
}

.navigation-header,
.panel {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, .96);
  box-shadow: var(--shadow);
}

.navigation-header {
  position: sticky;
  top: 0;
  z-index: 50;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
}

.navigation-header > div > strong {
  display: block;
  font-size: 21px;
}

.navigation-header > div > span {
  display: block;
  color: var(--muted);
}

.navigation-menu { position: relative; }
.navigation-menu summary {
  width: 50px;
  min-height: 50px;
  border: 1px solid var(--line);
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: #f8fafc;
  font-size: 25px;
  list-style: none;
  cursor: pointer;
}
.navigation-menu summary::-webkit-details-marker { display: none; }
.navigation-menu nav {
  position: absolute;
  left: 0;
  top: calc(100% + 8px);
  z-index: 70;
  width: 230px;
  padding: 8px;
  display: grid;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  box-shadow: var(--shadow);
}
.navigation-menu:not([open]) nav { display: none; }
.navigation-menu a { display: flex; align-items: center; }

.source-badge {
  border: 1px solid rgba(22, 136, 232, .35);
  border-radius: 999px;
  padding: 6px 10px;
  background: #eaf6ff;
  color: var(--blue-dark);
  font-size: 13px;
  font-weight: 900;
}

.panel { padding: 18px; }
.panel h1,
.panel h2,
.panel p { margin-top: 0; }
.panel p { color: var(--muted); }

.panel-heading {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 12px;
}
.panel-heading h1 { margin-bottom: 5px; }
.panel-heading p { margin-bottom: 12px; }

#routeForm {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

label { display: grid; gap: 6px; }
label > span { color: var(--muted); font-weight: 850; }
input {
  width: 100%;
  min-height: 50px;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 10px 12px;
  background: #fff;
  color: var(--text);
  font-size: 17px;
  font-weight: 800;
}
select {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 9px 38px 9px 11px;
  background: #fff;
  color: var(--text);
  font-weight: 800;
}
input:focus {
  border-color: var(--blue);
  outline: 3px solid rgba(22, 136, 232, .12);
}

.navigation-calibration-bar {
  margin: 2px 0 14px;
  border: 1px solid rgba(44, 161, 69, .36);
  border-radius: 11px;
  padding: 11px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 8px 10px;
  background: linear-gradient(135deg, #f0fff3, #f5fbff);
}
.navigation-calibration-bar small {
  grid-column: 1 / -1;
  color: #316243;
  font-weight: 750;
}
.calibration-toggle {
  border-color: rgba(44, 161, 69, .55);
  background: #eaf8ed;
  color: #126d29;
}
.calibration-toggle.is-off {
  border-color: var(--line);
  background: #f7f8fa;
  color: var(--muted);
}

.route-actions {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.message {
  min-height: 22px;
  margin-top: 10px;
  color: var(--muted);
  font-weight: 750;
}
.message.error { color: var(--red); }
.message.ok { color: var(--green); }

.guidance-panel {
  overflow: hidden;
  text-align: center;
  background: linear-gradient(180deg, #fff, #f5faff);
}

.location-panel {
  border-color: rgba(22, 136, 232, .38);
  background: linear-gradient(145deg, #fff, #eef8ff);
}
.location-heading {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 12px;
  margin-bottom: 12px;
}
.location-heading div { display: grid; gap: 2px; }
.location-heading small { color: var(--muted); font-weight: 900; }
.location-heading strong { font-size: clamp(29px, 6vw, 48px); }
.location-heading > span {
  border: 1px solid rgba(22, 136, 232, .3);
  border-radius: 999px;
  padding: 6px 9px;
  background: #fff;
  color: var(--blue-dark);
  font-size: 12px;
  font-weight: 900;
}
.location-heading > span.is-live {
  border-color: rgba(44, 161, 69, .45);
  background: #eaf8ed;
  color: #126d29;
}
.location-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
.location-grid > div {
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 10px;
  display: grid;
  gap: 4px;
  background: rgba(255, 255, 255, .9);
}
.location-grid small { color: var(--muted); font-weight: 750; }
.location-grid strong { font-size: 17px; }
.location-panel > p {
  margin: 12px 0 0;
  color: #8a5a00;
  font-size: 13px;
  font-weight: 750;
}

.route-points {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
}
.route-points span {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px;
  background: #fff;
}
.route-points small,
.route-points strong { display: block; }
.route-points small { color: var(--muted); font-size: 11px; font-weight: 900; }
.route-points strong { font-size: 20px; }
.route-points i { color: var(--blue); font-size: 30px; font-style: normal; }

.direction-stage {
  padding: 22px 0 10px;
  display: grid;
  justify-items: center;
  gap: 6px;
}
.direction-ring {
  width: clamp(170px, 35vw, 245px);
  aspect-ratio: 1;
  border: 5px solid rgba(22, 136, 232, .18);
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: radial-gradient(circle, #fff 48%, #e9f5ff 49% 100%);
  box-shadow: inset 0 0 0 12px rgba(22, 136, 232, .05), 0 14px 35px rgba(22, 136, 232, .15);
}
.direction-arrow {
  display: block;
  color: var(--blue);
  font-size: clamp(112px, 24vw, 170px);
  font-weight: 950;
  line-height: .8;
  transform: rotate(var(--route-angle, 0deg));
  transform-origin: 50% 52%;
  transition: transform 300ms cubic-bezier(.2, .8, .2, 1), color 200ms ease;
  filter: drop-shadow(0 8px 8px rgba(22, 136, 232, .22));
}
.direction-label { font-size: clamp(24px, 5vw, 38px); }
.direction-meta { color: var(--muted); font-weight: 750; }
.route-instruction {
  margin: 8px auto 18px;
  max-width: 720px;
  font-size: clamp(22px, 4vw, 32px);
}

.axis-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border: 1px solid var(--line);
  border-radius: 11px;
  overflow: hidden;
  background: #fff;
}
.axis-summary > div {
  padding: 12px 8px;
  display: grid;
  gap: 2px;
}
.axis-summary > div + div { border-left: 1px solid var(--line); }
.axis-summary small,
.axis-summary span { color: var(--muted); font-weight: 750; }
.axis-summary strong { font-size: clamp(25px, 5vw, 38px); }

.arrival-message {
  margin-top: 16px;
  border: 2px solid rgba(44, 161, 69, .36);
  border-radius: 12px;
  padding: 18px;
  background: #eaf8ed;
  color: #15702a;
  font-size: 25px;
  font-weight: 950;
}
.guidance-panel.is-arrived .direction-arrow { color: var(--green); }

.scale-panel details summary {
  cursor: pointer;
  font-size: 18px;
  font-weight: 900;
}
.scale-panel details[open] summary { margin-bottom: 12px; }
.scale-fields,
.calibration-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.metric-summary {
  margin-top: 10px;
  border: 1px solid rgba(22, 136, 232, .25);
  border-radius: 9px;
  padding: 10px;
  background: #eef8ff;
  color: var(--blue-dark);
  font-weight: 850;
}
.calibration-grid > div {
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 10px;
  display: grid;
  gap: 3px;
  background: #f9fbfd;
}
.calibration-grid small { color: var(--muted); font-weight: 800; }
.calibration-status > p { margin: 12px 0 0; font-size: 13px; }

.app-version {
  position: fixed;
  right: 12px;
  bottom: max(8px, env(safe-area-inset-bottom));
  z-index: 5;
  color: var(--muted);
  font-size: 12px;
}

@media (max-width: 620px) {
  .navigation-shell { padding: 8px 8px 70px; gap: 8px; }
  .navigation-header { padding: 8px; }
  .navigation-header > div > strong { font-size: 18px; }
  .navigation-header > div > span { font-size: 13px; }
  .source-badge { max-width: 88px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .panel { padding: 13px; }
  .panel-heading { align-items: center; }
  .panel-heading p { font-size: 13px; }
  #routeForm { grid-template-columns: 1fr; }
  .route-actions { grid-template-columns: 1fr 1fr; }
  .direction-stage { padding-top: 15px; }
  .axis-summary span { font-size: 12px; }
  .scale-fields,
  .calibration-grid { grid-template-columns: 1fr; }
  .navigation-calibration-bar { grid-template-columns: 1fr; }
  .navigation-calibration-bar small { grid-column: auto; }
  .location-grid { grid-template-columns: 1fr 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  .direction-arrow { transition: none; }
}
