:root {
  --ink: #102820;
  --green: #165842;
  --green-hover: #104634;
  --paper: #f3f5f0;
  --surface: #fff;
  --field: #f3f7f2;
  --line: #dce5dd;
  --muted: #52645a;
  --accent: #dff3a8;
  --red: #a3282e;
  --focus: #337960;
  --radius-card: 18px;
  --radius-control: 10px;
  --shadow-card: 0 6px 20px #1028200a;
  --shadow-control: 0 3px 12px #1028201a;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 14px/1.5 system-ui, "Segoe UI", Arial, sans-serif;
}

a { color: inherit; }

button, input, select { font: inherit; }

button, a, input, select {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

button {
  cursor: pointer;
  min-height: 42px;
  padding: 9px 15px;
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  background: var(--surface);
  color: var(--ink);
  font-weight: 600;
  transition: background-color .15s, border-color .15s, color .15s, box-shadow .15s;
}

button:hover:not(:disabled) {
  background: #e7f1e9;
  border-color: #b1c8b9;
}

button:disabled { opacity: .52; cursor: not-allowed; }

button.primary {
  background: var(--green);
  border-color: var(--green);
  color: var(--surface);
}

button.primary:hover:not(:disabled) {
  background: var(--green-hover);
  border-color: var(--green-hover);
}

button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 3px;
}

[hidden] { display: none !important; }
h1, h2, p { margin: 0; }

h1, h2 {
  font-weight: 680;
  line-height: 1.15;
  letter-spacing: -.035em;
}

.topbar {
  height: 76px;
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 max(4vw, 24px);
  background: var(--ink);
  color: var(--surface);
}

.topbar a:focus-visible { outline-color: var(--accent); }

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
  font-size: 21px;
  font-weight: 750;
  text-decoration: none;
  letter-spacing: .02em;
}

.brand > span > span { font-weight: 400; margin-left: 5px; }

.back {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  padding: 5px 10px;
  border-radius: 8px;
  color: #e0ece4;
  font-size: 12px;
  text-decoration: none;
}

.back:hover { background: #ffffff15; color: var(--surface); }

.device-status {
  min-width: 0;
  margin-left: auto;
  color: #cbdad0;
  font-size: 12px;
  text-align: right;
  overflow-wrap: anywhere;
}

main { max-width: 1600px; padding: 0 4vw 35px; margin: auto; }

.heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 27px 0 18px;
}

.heading h1 { font-size: 36px; }

.eyebrow {
  font-size: 10px;
  letter-spacing: .09em;
  font-weight: 700;
  color: var(--muted);
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: var(--muted);
  font-size: 11px;
}

input[type=datetime-local], select {
  min-width: 0;
  height: 43px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  background: var(--field);
  color: var(--ink);
}

select { cursor: pointer; }
select:disabled { cursor: not-allowed; }
.device-select { min-width: 180px; }

.range-panel, .workspace {
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  background: var(--surface);
  box-shadow: var(--shadow-card);
}

.range-panel { padding: 18px 22px; }

#range-form {
  display: flex;
  align-items: flex-end;
  gap: 14px;
  flex-wrap: wrap;
}

#range-form label { flex: 1; min-width: 200px; max-width: 300px; }
#range-form button { min-height: 43px; }

.range-bottom {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  margin-top: 13px;
  color: var(--muted);
  font-size: 11px;
}

.presets {
  display: flex;
  gap: 2px;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--field);
}

.presets button {
  min-height: 29px;
  padding: 4px 12px;
  border-color: transparent;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}

.presets button.selected {
  background: var(--accent);
  border-color: transparent;
  color: var(--ink);
  font-weight: 700;
}

.range-help { margin-left: auto; }

.load-status {
  min-height: 20px;
  margin: 14px 0;
  color: var(--muted);
  font-size: 12px;
}

.notice {
  margin: 0 0 14px;
  padding: 12px 16px;
  border: 1px solid #efd0c7;
  border-radius: 12px;
  background: #fff2ef;
  color: var(--red);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 265px;
  overflow: hidden;
}

.map-column { min-width: 0; }

.map-stage {
  position: relative;
  height: clamp(390px, 58vh, 730px);
  min-height: 390px;
  isolation: isolate;
}

#map { position: absolute; inset: 0; background: #e5ebe3; }

.map-tools {
  position: absolute;
  z-index: 500;
  top: 15px;
  right: 15px;
  left: 64px;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: flex-start;
  gap: 8px;
  pointer-events: none;
}

.map-tools > * { pointer-events: auto; box-shadow: var(--shadow-control); }

.map-tools label {
  gap: 3px;
  margin-right: auto;
  padding: 5px 7px 7px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  font-size: 10px;
}

.map-tools select {
  min-width: 190px;
  height: 33px;
  padding: 4px 7px;
  border-radius: 7px;
  font-size: 12px;
}

.map-tools > button { font-size: 12px; white-space: nowrap; }

.empty-card {
  position: absolute;
  z-index: 450;
  top: 50%;
  left: 50%;
  max-width: 390px;
  width: calc(100% - 48px);
  padding: 26px 30px;
  transform: translate(-50%, -50%);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  background: #fffffff2;
  box-shadow: var(--shadow-card);
  text-align: center;
  pointer-events: none;
}

.empty-card > span { font-size: 29px; color: var(--green); }
.empty-card h2 { margin: 10px 0; font-size: 23px; }
.empty-card p { color: var(--muted); font-size: 12px; }

.tile-error {
  position: absolute;
  z-index: 500;
  bottom: 28px;
  left: 12px;
  max-width: calc(100% - 24px);
  padding: 8px 12px;
  border: 1px solid #e5ceae;
  border-radius: 9px;
  background: #fff6e6;
  font-size: 11px;
}

.map-legend {
  position: absolute;
  z-index: 450;
  left: 10px;
  bottom: 24px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffffff2;
  color: var(--ink);
  font-size: 10px;
  line-height: 1.3;
  pointer-events: none;
}

.map-legend span { display: flex; align-items: center; gap: 4px; }

.map-legend span::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--marker-color);
}

.legend-track { --marker-color: #2563eb; }
.legend-gnss { --marker-color: #dc2626; }
.legend-geolocator { --marker-color: #f97316; }

#map .leaflet-bar {
  border: 1px solid var(--line);
  border-radius: 11px;
  box-shadow: var(--shadow-control);
}

#map .leaflet-bar a { color: var(--ink); }
#map .leaflet-bar a:hover { background: var(--field); }
#map .leaflet-bar a:first-child { border-radius: 10px 10px 0 0; }
#map .leaflet-bar a:last-child { border-radius: 0 0 10px 10px; }

.leaflet-control-attribution {
  max-width: calc(100% - 10px);
  background: #fffffff2 !important;
  font-size: 10px !important;
}

.leaflet-container { font-family: system-ui, "Segoe UI", Arial, sans-serif; }
.leaflet-tooltip { font-size: 11px; }

.timeline { padding: 17px 20px 13px; border-top: 1px solid var(--line); }

.timeline-controls {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 15px;
}

.timeline-controls button { font-size: 12px; }
.timeline-controls .play { min-width: 145px; }

.timeline-controls label {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  margin-left: 8px;
}

.timeline-controls select { height: 38px; font-size: 12px; }
.timeline-controls .follow { margin-left: auto; color: var(--ink); font-size: 11px; }
.follow input { width: 16px; height: 16px; accent-color: var(--green); }

#live-map[aria-pressed="true"] {
  border-color: #c6df9d;
  background: var(--accent);
  color: var(--ink);
}

#live-map[aria-pressed="true"]:hover { background: #d3eb94; }

#timeline {
  display: block;
  width: 100%;
  height: 24px;
  margin: 0;
  accent-color: var(--green);
  cursor: pointer;
}

.timeline-labels {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 6px;
  color: var(--muted);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
}

.point-panel { padding: 27px 22px; border-left: 1px solid var(--line); }
.point-panel h2 { margin-top: 13px; font-size: 26px; }

.point-panel > time {
  display: block;
  margin-top: 9px;
  color: var(--muted);
  font-size: 12px;
}

.point-panel > dl { margin: 26px 0 23px; }
.point-panel > dl > div { padding: 14px 0; border-bottom: 1px solid var(--line); }
.point-panel dt { color: var(--muted); font-size: 11px; }

.point-panel dd {
  margin: 4px 0 0;
  font-size: 19px;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.point-note, .contact { margin-top: 13px; color: var(--muted); font-size: 11px; line-height: 1.65; }
.contact { padding-top: 15px; border-top: 1px solid var(--line); }

.current-location, .imu-card {
  margin: 0 0 14px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--field);
}

.current-location { overflow-wrap: anywhere; }
.current-location b { color: #b42328; font-size: 12px; }
.current-location b.approximate { color: #98400e; }
.current-location p:not(.eyebrow) { margin-top: 4px; color: var(--muted); font-size: 11px; line-height: 1.4; }
#current-coordinates { font-variant-numeric: tabular-nums; }

.imu-caption {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 6px;
  color: var(--muted);
  font-size: 10px;
}

.imu-card dl {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 5px 8px;
  margin: 5px 0 0;
}

.imu-card dt { font-size: 10px; }
.imu-card dd { margin-top: 1px; font-size: 15px; }

footer {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  max-width: 1600px;
  margin: auto;
  padding: 22px 4vw 27px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 10px;
}

footer > span:first-child { font-weight: 750; letter-spacing: .08em; }
footer a { text-decoration: none; }
footer a:hover { text-decoration: underline; }

@media (max-width: 1000px) {
  .workspace { grid-template-columns: minmax(0, 1fr) 220px; }
  .point-panel { padding: 24px 17px; }
  .range-help { margin-left: 0; }
  .timeline-controls { flex-wrap: wrap; }
  .map-stage { height: 54vh; }
}

@media (max-width: 700px) {
  .topbar { height: 64px; gap: 8px; padding: 0 14px; }
  .brand { gap: 6px; font-size: 16px; }
  .brand img { width: 24px; height: 27px; }
  .device-status { max-width: 110px; font-size: 10px; }
  .back { min-height: 40px; padding: 4px 6px; font-size: 11px; }
  main { padding: 0 14px 25px; }
  .heading { gap: 12px; padding: 20px 0 14px; }
  .heading h1 { font-size: 27px; }
  .device-select { min-width: 0; max-width: 145px; }
  .device-select select { width: 100%; font-size: 12px; }
  .range-panel { padding: 14px 12px; }
  #range-form { gap: 10px; }
  #range-form label { min-width: 0; max-width: none; flex: 1 1 40%; }
  input[type=datetime-local] { width: 100%; padding: 8px 5px; font-size: 11px; }
  #range-form button { flex: 1; }
  .range-bottom { gap: 8px; font-size: 10px; }
  .range-help { width: 100%; }
  .presets button { min-height: 34px; padding: 5px 9px; }
  .workspace { display: flex; flex-direction: column; }
  .map-stage { height: 55svh; min-height: 360px; max-height: 620px; }
  .map-tools { top: 10px; right: 9px; left: 51px; gap: 6px; }
  .map-tools select { min-width: 141px; max-width: 175px; font-size: 11px; }
  .map-tools > button { min-height: 38px; padding: 7px 8px; font-size: 10px; }
  .timeline { padding: 12px; }
  .timeline-controls { gap: 7px; }
  .timeline-controls button { padding: 8px 10px; }
  .timeline-controls .play { min-width: 135px; }
  .timeline-controls label { margin-left: 0; }
  .timeline-controls .follow { width: 100%; margin-left: 0; }
  .timeline-labels { gap: 5px; font-size: 9px; }
  .timeline-labels > span { white-space: nowrap; }
  .point-panel { padding: 18px 16px; border-top: 1px solid var(--line); border-left: 0; }
  .point-panel h2 { font-size: 23px; }
  .point-panel > dl { display: grid; grid-template-columns: 1fr 1fr; gap: 0 18px; margin: 16px 0; }
  .point-panel dd { font-size: 17px; }
  .imu-card dd { font-size: 15px; }
  footer { flex-wrap: wrap; padding: 18px; }
}

@media (max-width: 350px) {
  #range-form label { flex-basis: 100%; }
}

/* Desktop uses the available window; short and mobile views keep normal flow. */
@media (min-width: 1000px) and (min-height: 680px) {
  body { height: 100vh; height: 100dvh; display: flex; flex-direction: column; }
  .topbar { height: 54px; flex: 0 0 54px; padding: 0 24px; }
  .brand { font-size: 19px; }
  .brand img { width: 25px; height: 29px; }
  main { width: 100%; flex: 1; min-height: 0; padding: 10px 24px 8px; display: flex; flex-direction: column; }
  .heading { flex: none; min-height: 44px; padding: 0 0 8px; gap: 16px; }
  .heading h1 { font-size: 27px; }
  .eyebrow { font-size: 9px; }
  .device-select { min-width: 175px; flex-direction: row; align-items: center; gap: 10px; }
  .device-select select { height: 40px; }
  .range-panel { flex: none; padding: 9px 14px; }
  #range-form { gap: 10px; flex-wrap: nowrap; }
  #range-form label { min-width: 175px; max-width: 260px; gap: 3px; font-size: 10px; }
  input[type=datetime-local] { height: 40px; font-size: 12px; }
  #range-form button { min-height: 40px; padding: 8px 14px; font-size: 12px; }
  .range-bottom { margin-top: 6px; gap: 12px; font-size: 10px; flex-wrap: nowrap; }
  .presets button { min-height: 27px; padding: 4px 10px; }
  .load-status { flex: none; min-height: 16px; margin: 7px 0; font-size: 10px; line-height: 1.4; }
  .notice { flex: none; margin-bottom: 7px; padding: 6px 12px; font-size: 11px; }
  .workspace { flex: 1; min-height: 0; grid-template-columns: minmax(0, 1fr) 245px; }
  .map-column { min-height: 0; display: flex; flex-direction: column; }
  .map-stage { flex: 1; height: auto; min-height: 180px; }
  .map-tools { top: 10px; right: 10px; }
  .map-tools > button { min-height: 40px; }
  .timeline { flex: none; padding: 8px 14px 7px; }
  .timeline-controls { gap: 8px; margin-bottom: 6px; flex-wrap: nowrap; }
  .timeline-controls button { min-height: 40px; padding: 7px 11px; }
  .timeline-controls select { height: 36px; }
  #timeline { height: 20px; }
  .timeline-labels { margin-top: 3px; font-size: 9px; }
  .point-panel { min-height: 0; overflow: auto; overscroll-behavior: contain; padding: 13px 16px; }
  .point-panel h2 { margin-top: 6px; font-size: 21px; }
  .point-panel > time { margin-top: 5px; font-size: 10px; }
  .point-panel > dl { margin: 12px 0; }
  .point-panel > dl > div { padding: 6px 0; }
  .point-panel dt { font-size: 10px; }
  .point-panel dd { margin-top: 1px; font-size: 15px; }
  .point-note, .contact { margin-top: 8px; font-size: 10px; line-height: 1.4; }
  .contact { padding-top: 8px; }
  .current-location, .imu-card { padding: 7px 9px; margin-bottom: 9px; }
  .current-location p:not(.eyebrow) { margin-top: 2px; font-size: 10px; }
  footer { width: calc(100% - 48px); flex: 0 0 30px; margin: 0 auto; padding: 6px 0; font-size: 9px; }
}

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