:root {
  --bg: #0b1724;
  --panel: #12263a;
  --panel-2: #183149;
  --line: #2a4660;
  --text: #e8f0f6;
  --muted: #9bb0c2;
  --accent: #ffbe46;
  --accent-ink: #2a1c00;
  --ok: #3ccf8e;
  --bad: #ff6b6b;
  --stop: #e5383b;
  --target: #ff79c6;
  --radius: 14px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  padding: env(safe-area-inset-top) 0 0;
}
button, input { font: inherit; color: inherit; }
h1 { margin: 0; font-size: 1.35rem; }
small { color: var(--muted); }

/* ---------- cabecera ---------- */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(6px); border-bottom: 1px solid var(--line);
}
.top .title { flex: 1; min-width: 0; }
.top small { display: block; font-size: .72rem; letter-spacing: .04em; text-transform: uppercase; }
.top form { margin: 0; }
.badge {
  padding: 4px 10px; border-radius: 999px; font-size: .8rem; white-space: nowrap;
  background: var(--panel-2); color: var(--muted);
}
.badge.ok { background: color-mix(in srgb, var(--ok) 20%, transparent); color: var(--ok); }
.badge.bad { background: color-mix(in srgb, var(--bad) 20%, transparent); color: var(--bad); }
.icon-btn {
  height: 40px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--panel); font-size: .85rem; cursor: pointer;
}

main {
  max-width: 520px; margin: 0 auto;
  padding: 12px 16px calc(96px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 12px;
}

/* ---------- lectura ---------- */
.readout { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.readout > div { background: var(--panel); border-radius: var(--radius); padding: 10px 14px; }
.label { display: block; font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
#heading { font-size: 2.1rem; font-variant-numeric: tabular-nums; color: var(--accent); }
#motion { display: block; font-size: 1.35rem; margin-top: 4px; }
#motion.moving { color: var(--ok); }
#remaining { display: block; font-size: .8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- mapa ---------- */
.map-card { background: var(--panel); border-radius: var(--radius); padding: 8px; }
#map { display: block; width: 100%; max-width: 380px; margin: 0 auto; aspect-ratio: 1; cursor: crosshair; }
.sea { fill: #132a40; stroke: #7894aa; stroke-width: 2; }
.ring { fill: none; stroke: #35516a; stroke-width: 1; }
.land { fill: #426079; stroke: #91a8b7; stroke-width: .6; }
.border { fill: none; stroke: #6f879a; stroke-width: .5; }
.beam { fill: var(--accent); fill-opacity: .38; stroke: #ffca65; stroke-width: 1; }
.beam-axis { stroke: #ffdd92; stroke-width: 3; stroke-dasharray: 8 5; }
.target-line { stroke: var(--target); stroke-width: 4; stroke-dasharray: 12 6; }
.tick { stroke: #9bb0c2; stroke-width: 2; }
.cardinal { fill: var(--text); font-size: 26px; font-weight: 700; }
.center { fill: #fff; }
.hint { margin: 4px 4px 0; font-size: .8rem; color: var(--muted); }
.map-card .hint { text-align: center; }

/* ---------- botones ---------- */
.btn {
  min-height: 52px; padding: 0 16px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--panel-2); font-weight: 600; cursor: pointer; touch-action: manipulation;
}
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn:not(:disabled):active { transform: scale(.98); }
.btn.go { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.ghost { background: transparent; }

.target-bar { display: flex; gap: 8px; align-items: stretch; }
.target-field {
  flex: 1; display: flex; align-items: center; gap: 6px; min-width: 0;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 0 12px;
}
.target-field span:first-child { color: var(--muted); font-size: .85rem; }
.target-field input {
  flex: 1; min-width: 0; width: 100%; background: transparent; border: 0; outline: none;
  font-size: 1.25rem; font-variant-numeric: tabular-nums; padding: 10px 0;
}
.target-bar .btn.ghost { width: 52px; padding: 0; }
#target-name { margin-top: -6px; color: var(--target); }

.presets { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.chip {
  min-height: 48px; padding: 4px 2px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--panel); font-size: .78rem; line-height: 1.15; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.chip small { font-size: .72rem; }

.controls { display: flex; flex-direction: column; gap: 8px; background: var(--panel); border-radius: var(--radius); padding: 12px; }
.controls .row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.btn.power { display: flex; align-items: center; justify-content: center; gap: 8px; }
.led { width: 12px; height: 12px; border-radius: 50%; background: #3a4b5a; margin-left: 4px; }
.btn.power.on { border-color: var(--ok); }
.btn.power.on .led { background: var(--ok); box-shadow: 0 0 10px var(--ok); }
.btn.dir { min-height: 64px; font-size: 1.2rem; }
.btn.dir.active { background: var(--ok); color: #04210f; border-color: transparent; }
.notice { margin: 2px 0 0; font-size: .9rem; }
.notice.error { color: var(--bad); }

/* ---------- detalles ---------- */
.more { background: var(--panel); border-radius: var(--radius); padding: 10px 14px; }
.more summary { cursor: pointer; color: var(--muted); }
.details { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0 4px; }
.details dt { font-size: .72rem; color: var(--muted); }
.details dd { margin: 0; font-variant-numeric: tabular-nums; }
.preset-edit { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 10px; margin-top: 8px; }
.preset-edit label { display: flex; justify-content: space-between; align-items: center; gap: 6px; font-size: .85rem; }
.preset-edit input {
  width: 76px; padding: 6px 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg);
}

/* ---------- STOP fijo ---------- */
.stopbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background: linear-gradient(transparent, var(--bg) 35%);
}
.btn.stop {
  display: block; width: 100%; max-width: 488px; margin: 0 auto; min-height: 64px;
  background: var(--stop); border-color: transparent; color: #fff; font-size: 1.35rem; letter-spacing: .06em;
  box-shadow: 0 6px 20px rgba(229, 56, 59, .35);
}
.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(92px + env(safe-area-inset-bottom)); z-index: 11;
  max-width: 488px; margin: 0 auto; padding: 12px 14px; border-radius: 12px;
  background: #3b1416; border: 1px solid var(--bad); color: #ffd6d6; font-size: .9rem;
}

/* ---------- acceso ---------- */
body.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 360px; background: var(--panel); border-radius: var(--radius);
  padding: 24px 20px; display: flex; flex-direction: column; gap: 12px; text-align: center;
}
.login-card img { margin: 0 auto; }
.login-card .hint { margin-top: -6px; }
.login-card label { display: flex; flex-direction: column; gap: 6px; text-align: left; font-size: .9rem; color: var(--muted); }
.login-card input[type=password] {
  padding: 14px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); font-size: 1.05rem;
}
.login-error { margin: 0; color: var(--bad); }
