/* The primary color is a map-pin blue, #2563eb, with white text on it. Links use the text
   color with a primary underline, as in notes. The map's tiles are always light, so what sits
   on the map is styled for a light background in both modes. */
:root {
  --primary: #2563eb;
  --on-primary: #ffffff;
  --bg: #f4f5f7;
  --paper: #ffffff;
  --fg: #141518;
  --muted: #5f636b;
  --line: #d9dce1;
  --raised: #e9ebef;
  --focus: #000000;
  --warn: #b3261e;
  --moving: #1e7d32;
}

@media (prefers-color-scheme: dark) {
  :root {
    --primary: #4f86f7;
    --bg: #121316;
    --paper: #1d1f23;
    --fg: #f1f2f4;
    --muted: #a2a6ad;
    --line: #33363c;
    --raised: #2a2d32;
    --focus: #7aa5ff;
    --warn: #ff8a7a;
    --moving: #6fd27f;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}

main {
  max-width: 44rem;
  margin: 0 auto;
  padding: 1rem 1rem 3rem;
}

a {
  color: inherit;
  text-decoration-color: var(--primary);
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
}

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

[hidden] { display: none !important; }

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

/* --- Header ------------------------------------------------------------------------------ */

header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  padding-bottom: 0.75rem;
  margin-bottom: 1.25rem;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 1.25rem;
  font-weight: 700;
  text-decoration: none;
}

.brand img { width: 2rem; height: 2rem; }

/* The account menu: the name with a chevron, opening a small panel below it. */
.menu { position: relative; }

.menu summary {
  list-style: none;
  cursor: pointer;
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
}

.menu summary::-webkit-details-marker { display: none; }
.menu summary::after { content: " ▾"; color: var(--muted); }
.menu summary:hover, .menu[open] summary { background: var(--raised); }

.menu > div {
  position: absolute;
  right: 0;
  top: calc(100% + 0.25rem);
  z-index: 2;
  display: grid;
  min-width: 11rem;
  padding: 0.25rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper);
  box-shadow: 0 4px 16px rgb(0 0 0 / 0.15);
}

.menu > div > * {
  padding: 0.5rem 0.75rem;
  border: 0;
  border-radius: 4px;
  font-weight: 400;
  text-align: left;
  text-decoration: none;
}

.menu > div > :hover { background: var(--raised); }

/* --- Controls ---------------------------------------------------------------------------- */

button {
  font: inherit;
  font-weight: 600;
  padding: 0.4rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: transparent;
  color: var(--fg);
  cursor: pointer;
  /* No double-tap zoom, so the map's buttons can be tapped quickly. */
  touch-action: manipulation;
}

button:hover { background: var(--raised); }

button.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--on-primary);
  font-weight: 700;
}

button.primary:hover { filter: brightness(0.93); }

.footer { margin-top: 2rem; font-size: 0.875rem; }

/* --- The device list --------------------------------------------------------------------- */

.devices { list-style: none; margin: 0; padding: 0; }

.devices a {
  display: grid;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--line);
  text-decoration: none;
}

.devices .name { font-weight: 700; }
.devices a:hover .name { text-decoration: underline var(--primary) 3px; text-underline-offset: 4px; }

/* --- One device -------------------------------------------------------------------------- */

.device .title {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0 1rem;
  margin-top: 1rem;
}

.device h1 { font-size: 1.4rem; line-height: 1.25; margin: 0; }

.device p { margin: 0.4rem 0; }

.state { font-weight: 600; white-space: nowrap; }
.state.moving { color: var(--moving); }
.state.offline, .state.location-off { color: var(--warn); }

.coords-row { display: flex; align-items: center; gap: 0.75rem; }
.coords { font-variant-numeric: tabular-nums; user-select: all; }
.coords-row button { padding: 0.2rem 0.7rem; }

/* --- The map ----------------------------------------------------------------------------- */

.map {
  position: relative;
  height: min(60vh, 26rem);
  min-height: 17rem; /* room for the buttons, even on a phone held sideways */
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #e5e3df; /* OpenStreetMap's land color, while tiles load */
  color-scheme: light;
}

/* Tiles and the marker take no taps: a long press doesn't open an image menu, and a swipe
   scrolls the page. */
.map .tiles img {
  position: absolute;
  max-width: none;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.map svg { position: absolute; inset: 0; pointer-events: none; }

.map .accuracy { fill: rgb(37 99 235 / 0.15); stroke: rgb(37 99 235 / 0.6); stroke-width: 1.5; }
.map .dot { fill: #2563eb; stroke: #fff; stroke-width: 3; }
.map .heading { fill: #2563eb; stroke: #fff; stroke-width: 1.5; stroke-linejoin: round; }

.map .zoom, .map .pan {
  position: absolute;
  right: 0.5rem;
  display: grid;
  gap: 0.25rem;
}

.map .zoom { top: 0.5rem; }

/*      ↑
      ← ◎ →
        ↓      */
.map .pan {
  bottom: 1.75rem;
  grid-template-columns: repeat(3, auto);
  grid-template-areas: ". n ." "w c e" ". s .";
}
.map .pan > :nth-child(1) { grid-area: n; }
.map .pan > :nth-child(2) { grid-area: w; }
.map .pan > :nth-child(3) { grid-area: c; }
.map .pan > :nth-child(4) { grid-area: e; }
.map .pan > :nth-child(5) { grid-area: s; }

.map button {
  width: 2.5rem;
  height: 2.5rem;
  padding: 0;
  border-color: rgb(0 0 0 / 0.2);
  background: rgb(255 255 255 / 0.9);
  color: #141518;
  font-size: 1.1rem;
  line-height: 1;
  box-shadow: 0 1px 4px rgb(0 0 0 / 0.2);
}

.map button:hover { background: #fff; }

/* OpenStreetMap's attribution, required on the map itself. */
.map .attribution {
  position: absolute;
  left: 0;
  bottom: 0;
  padding: 0.1rem 0.4rem;
  border-top-right-radius: 6px;
  background: rgb(255 255 255 / 0.85);
  color: #141518;
  font-size: 0.75rem;
}
