:root {
  --bg: #000;
  --fg: #fff;
  --muted: #ccc;
  --amber: #ffb000;
  --alert: #ff2a2a;
  --panel: #111;
  --line: #333;
  --speed-size: 40vw;
  --font: -apple-system, BlinkMacSystemFont, "Helvetica Neue", system-ui, sans-serif;
}

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

/* ---------- Stage (the mirrored area) ---------- */

#stage {
  position: fixed;
  inset: 0;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  display: flex;
  align-items: center;
  justify-content: center;
}

.readout, .nosignal, .message { display: none; }

.readout, .nosignal {
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.speed {
  font-size: var(--speed-size);
  font-weight: 600;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  color: var(--fg);
  white-space: nowrap;
}

.unit {
  font-size: 22px;
  color: var(--muted);
  margin-top: 4px;
}

.measure {
  position: absolute;
  left: -9999px;
  top: 0;
  font-size: 100px;
  visibility: hidden;
}

.lost-icon { color: var(--muted); margin-top: 12px; }

/* ---------- States ---------- */

body.state-initial #initial,
body.state-acquiring #acquiring,
body.state-denied #denied,
body.state-unavailable #unavailable { display: block; }

body.state-active #readout,
body.state-weak #readout,
body.state-nosignal #nosignal { display: flex; }

.message {
  max-width: 34em;
  padding: 0 16px;
  text-align: center;
  font-size: 18px;
  line-height: 1.45;
  color: var(--muted);
}

.message strong { color: var(--fg); }

.start {
  font: 600 32px var(--font);
  color: var(--bg);
  background: var(--fg);
  border: 0;
  border-radius: 999px;
  padding: 22px 64px;
}

/* the only continuous animation; it exists only while "Acquiring" is shown */
.pulse {
  width: 18px;
  height: 18px;
  margin: 0 auto 16px;
  border-radius: 50%;
  background: var(--muted);
  animation: pulse 1.6s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 0.2; transform: scale(0.8); }
  50% { opacity: 1; transform: scale(1.1); }
}

/* ---------- GPS quality dot ---------- */

.gps {
  position: absolute;
  top: calc(env(safe-area-inset-top) + 12px);
  left: calc(env(safe-area-inset-left) + 16px);
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #444;
}

.gps.good { background: #2ecc40; }
.gps.fair { background: #ffdc00; }
.gps.poor { background: #ff4136; }

/* ---------- Themes, weak signal, alert ---------- */

body.theme-night .speed { color: var(--amber); opacity: 0.6; }
body.theme-night .unit,
body.theme-night .message,
body.theme-night .lost-icon { opacity: 0.6; }

body.state-weak #readout .speed { opacity: 0.4; }

body.alert #readout .speed { color: var(--alert); }

/* ---------- HUD: number only ---------- */

body.hud .chrome { display: none !important; }

/* ---------- Gear and notices ---------- */

.gear {
  display: none;
  position: fixed;
  top: calc(env(safe-area-inset-top) + 4px);
  right: calc(env(safe-area-inset-right) + 8px);
  padding: 8px;
  color: var(--muted);
  background: transparent;
  border: 0;
}

body.show-gear .gear { display: block; }

.notice {
  display: none;
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(env(safe-area-inset-bottom) + 16px);
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  color: var(--muted);
  font-size: 15px;
  text-align: center;
}

.notice.visible { display: block; }
.notice.lowrate { bottom: calc(env(safe-area-inset-bottom) + 76px); }

/* ---------- Panels (settings, help) — never mirrored ---------- */

.panel {
  display: none;
  position: fixed;
  inset: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: calc(env(safe-area-inset-top) + 16px) calc(env(safe-area-inset-right) + 16px) calc(env(safe-area-inset-bottom) + 24px) calc(env(safe-area-inset-left) + 16px);
  background: var(--panel);
  color: var(--fg);
  font-size: 17px;
  box-sizing: border-box;
}

.panel.open { display: block; }

.panel h2 { margin: 0 0 12px; font-size: 22px; }

.panel ol { padding-left: 1.3em; line-height: 1.5; }
.panel li { margin-bottom: 8px; }
.panel .hint { color: var(--muted); font-size: 15px; }

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.row input, .row select {
  font: inherit;
  color: var(--fg);
  background: #222;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 8px;
  -webkit-user-select: text;
  user-select: text;
}

.row input[type="number"] { width: 5.5em; text-align: right; }
.row input[type="checkbox"] { width: 24px; height: 24px; }
.row input:disabled { opacity: 0.4; }

.buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 20px;
}

.buttons button {
  font: inherit;
  color: var(--fg);
  background: #222;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 16px;
}

.buttons button.primary { background: var(--fg); color: var(--bg); border-color: var(--fg); }

/* ---------- Login (RF-34) ---------- */

body.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
}

.login {
  width: 100%;
  max-width: 340px;
  padding: 0 16px;
  box-sizing: border-box;
}

.login h1 { margin: 0 0 24px; font-size: 28px; text-align: center; }

.login label {
  display: block;
  margin-bottom: 16px;
  font-size: 15px;
  color: var(--muted);
}

.login input {
  display: block;
  width: 100%;
  box-sizing: border-box;
  margin-top: 6px;
  font: 17px var(--font);
  color: var(--fg);
  background: #222;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  -webkit-user-select: text;
  user-select: text;
}

.login button {
  width: 100%;
  margin-top: 8px;
  font: 600 18px var(--font);
  color: var(--bg);
  background: var(--fg);
  border: 0;
  border-radius: 999px;
  padding: 14px;
}

.login button:disabled { opacity: 0.5; }

.login-error { min-height: 1.4em; margin-top: 16px; color: var(--alert); text-align: center; }
