/*
 * SkyLink web.
 *
 * Dark, low-chrome, built for one hand outdoors: the sky is the content and
 * everything else gets out of its way. Panels are translucent so you can still
 * see the sky behind them.
 *
 * Two things worth knowing before editing:
 *
 *  - `[hidden]` is forced to display:none. Sheets are toggled with the hidden
 *    attribute rather than by sliding them off-screen, because a panel that is
 *    merely translated out of view is still in the accessibility tree -- screen
 *    readers happily announce controls nobody can see.
 *  - Night mode is a variable swap, not a filter. A CSS filter on the body
 *    would also dim the camera feed in a way that looks muddy, and it is a
 *    colour transform on already-red pixels.
 */

:root {
  --bg: #05070e;
  --ink: #eef3ff;
  --ink-dim: #93a4c7;
  --ink-faint: #5d6c8c;
  --line: rgba(120, 150, 220, 0.22);
  --panel: rgba(8, 14, 30, 0.72);
  --panel-solid: rgba(8, 14, 30, 0.94);
  --accent: #7fb2ff;
  --accent-warm: #ffd479;
  --warn: #ffb86b;
  --star: #ffffff;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  --tap: 44px;                      /* minimum comfortable touch target */
}

/* Night-vision mode. Everything that reads from --ink/--line flips with it. */
body.red-mode {
  --bg: #0a0202;
  --ink: #ff8f8f;
  --ink-dim: #c0574f;
  --ink-faint: #7d3a35;
  --line: rgba(220, 70, 70, 0.28);
  --panel: rgba(24, 4, 4, 0.76);
  --panel-solid: rgba(20, 3, 3, 0.95);
  --accent: #ff6b6b;
  --accent-warm: #ff9d6b;
  --warn: #ff9d6b;
}

* { box-sizing: border-box; }

/* Must come first among the display rules so nothing can override it. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

body { overflow: hidden; }

#feed {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 0;
  background: var(--bg);
}
body.no-camera #feed { display: none; }

#overlay {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  touch-action: none;
  cursor: grab;                     /* the sky is draggable: say so */
}
#overlay.dragging { cursor: grabbing; }

#loading {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: grid;
  place-items: center;
  background: var(--bg);
  color: var(--ink-dim);
  font-size: 14px;
  letter-spacing: 0.04em;
  transition: opacity 0.45s ease;
}
#loading.gone { opacity: 0; pointer-events: none; }
/* Fading out is not hiding: an element at opacity 0 with role="status" is still
   announced by a screen reader. */
#loading.gone[hidden] { display: none !important; }

/* ------------------------------------------------------------------ top bar */

#top {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  padding: calc(6px + var(--safe-top)) 12px 18px;
  background: linear-gradient(180deg, rgba(3, 6, 16, 0.88) 0%, rgba(3, 6, 16, 0.5) 55%, rgba(3, 6, 16, 0) 100%);
  pointer-events: none;
}

#compass {
  display: block;
  width: 100%;
  height: 40px;
  opacity: 1;
}

#hud { margin-top: 6px; }

.hud-line {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px;
  font-size: 13px;
  color: var(--ink-dim);
}
.hud-line + .hud-line { margin-top: 3px; }
.hud-line strong {
  color: var(--ink);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.hud-line .sep { color: var(--ink-faint); }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
  font-size: 12px;
  color: var(--ink-dim);
  font-variant-numeric: tabular-nums;
}
.chip b { color: var(--ink); font-weight: 600; }

#hud-foot {
  margin-top: 8px;
  font-size: 12.5px;
  color: var(--ink-faint);
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  align-items: baseline;
}

/* The motion-sensor notice doubles as the way into the explainer, so it has to
   look tappable when it can actually tell you something. */
#sensor-notice {
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid transparent;
  background: none;
  color: var(--ink-faint);
  font: inherit;
  font-size: 12.5px;
  text-align: left;
  cursor: default;
}
#sensor-notice[data-action="help"] {
  cursor: pointer;
  border-color: rgba(255, 190, 90, 0.5);
  background: rgba(255, 190, 90, 0.12);
  color: #ffd479;
}
#sensor-notice[data-action="help"]:hover { background: rgba(255, 190, 90, 0.2); }
#sensor-notice:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* The sky-conditions chip. Tone tells you the answer at a glance: green-ish
   for clear, red-ish for overcast, neutral otherwise. Colours are dimmed so
   night mode eyes are not blasted. */
#sky-conditions {
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid transparent;
  background: none;
  color: var(--ink-faint);
  font: inherit;
  font-size: 12.5px;
  text-align: left;
  cursor: pointer;
}
#sky-conditions[data-tone="good"] { border-color: rgba(125, 224, 138, 0.4); background: rgba(125, 224, 138, 0.1); color: #9fe3a9; }
#sky-conditions[data-tone="mid"] { border-color: rgba(255, 212, 121, 0.35); background: rgba(255, 212, 121, 0.08); color: #ffd479; }
#sky-conditions[data-tone="bad"] { border-color: rgba(255, 143, 143, 0.35); background: rgba(255, 143, 143, 0.08); color: #ff9f9f; }
#sky-conditions[data-tone="unknown"] { border-style: dashed; border-color: var(--line); }
#sky-conditions:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Sensor diagnosis rows, in the explainer sheet. */
.diag-list {
  margin: 4px 0 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
}
.diag {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}
.diag:last-child { border-bottom: 0; }
.diag-mark { font-weight: 700; flex: 0 0 auto; }
.diag-mark.yes { color: #7de08a; }
.diag-mark.no { color: #ff8f8f; }
.diag-label { flex: 1 1 auto; color: var(--ink-dim); }
.diag-detail { flex: 1 1 auto; text-align: right; color: var(--ink-faint); font-size: 12px; }

#sensor-help-body p { margin: 0 0 12px; font-size: 14px; line-height: 1.5; color: var(--ink-dim); }
#sensor-help-body p b { color: var(--ink); }
#sensor-help-body ol { margin: 0 0 14px; padding-left: 20px; font-size: 14px; color: var(--ink-dim); line-height: 1.7; }
#sensor-help-body code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12.5px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 5px;
  padding: 1px 5px;
  color: #cfe0ff;
  word-break: break-all;
}
#sensor-help-body i { color: var(--ink); font-style: italic; }

/* --------------------------------------------------------- off-screen pointer */

#pointer {
  position: fixed;
  z-index: 18;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  pointer-events: none;
  transition: left 0.12s linear, top 0.12s linear;
}
#pointer-arrow {
  font-size: 20px;
  color: var(--accent-warm);
  text-shadow: 0 0 10px rgba(0, 0, 0, 0.9);
  line-height: 1;
}
#pointer-label {
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  color: var(--accent-warm);
  background: var(--panel-solid);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 9px;
}

/* ------------------------------------------------------------------ controls */

#controls {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(12px + var(--safe-bottom));
  z-index: 22;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 640px;
  margin: 0 auto;
}

#search-row { position: relative; display: flex; align-items: center; }

#search {
  width: 100%;
  min-height: var(--tap);
  padding: 11px 40px 11px 15px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel-solid);
  backdrop-filter: blur(10px);
  color: var(--ink);
  font: inherit;
  outline: none;
}
#search::placeholder { color: var(--ink-faint); }
#search:focus { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(127, 178, 255, 0.22); }

#search-clear {
  position: absolute;
  right: 6px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 0;
  background: rgba(255, 255, 255, 0.07);
  color: var(--ink-dim);
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
}
#search-clear:hover { background: rgba(255, 255, 255, 0.14); color: var(--ink); }

#search-results {
  display: none;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel-solid);
  backdrop-filter: blur(10px);
  overflow: hidden;
  max-height: 46vh;
  overflow-y: auto;
}
#search-results.open { display: block; }

/* Also applies to the "No match" div, so the reset stays generic. */
.hit {
  display: flex;
  width: 100%;
  min-height: 40px;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 15px;
  border: 0;
  border-bottom: 1px solid rgba(120, 150, 220, 0.1);
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.hit:last-child { border-bottom: 0; }
.hit:hover, .hit:focus-visible { background: rgba(120, 150, 220, 0.14); outline: none; }
.hit .hn { color: var(--ink); }
.hit .hm { color: var(--ink-dim); font-size: 12px; font-variant-numeric: tabular-nums; }
.hit.muted { color: var(--ink-dim); cursor: default; }
.hit .kind {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-faint);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 1px 7px;
}

#buttons {
  display: flex;
  gap: 8px;
  align-items: stretch;
  flex-wrap: wrap;
}

.ctl-btn, #zoom {
  min-height: var(--tap);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel-solid);
  backdrop-filter: blur(10px);
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.ctl-btn:hover { border-color: var(--accent); }
.ctl-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.ctl-btn .ico { font-size: 15px; line-height: 1; color: var(--accent); }
#toggle-red[aria-pressed="true"] {
  background: rgba(200, 50, 50, 0.22);
  border-color: rgba(230, 80, 80, 0.6);
}
#toggle-red[aria-pressed="true"] .ico { color: #ff8a8a; }

#zoom { padding: 0; gap: 0; }
#zoom button {
  width: var(--tap);
  height: 100%;
  border: 0;
  background: none;
  color: var(--ink);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  border-radius: 12px;
}
#zoom button:hover { background: rgba(120, 150, 220, 0.16); }
#zoom-val {
  min-width: 52px;
  text-align: center;
  font-size: 12px;
  color: var(--ink-dim);
  font-variant-numeric: tabular-nums;
}

/* -------------------------------------------------------------------- sheets */

#settings, #whats-up, #sensor-help {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(12px + var(--safe-bottom));
  z-index: 30;
  max-width: 640px;
  margin: 0 auto;
  padding: 16px;
  max-height: 76vh;
  overflow-y: auto;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: var(--panel-solid);
  backdrop-filter: blur(14px);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.55);
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}
.sheet-head h3 {
  margin: 0;
  font-size: 12px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--ink-dim);
}
.sheet-close {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: none;
  color: var(--ink-dim);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}
.sheet-close:hover { color: var(--ink); border-color: var(--accent); }

.sheet-sub { margin: 0 0 12px; font-size: 13px; color: var(--ink-dim); }

.ctl { display: block; margin-bottom: 16px; }
.ctl > span { display: block; font-size: 13px; color: var(--ink); margin-bottom: 6px; }
.ctl > span b { color: var(--accent); font-variant-numeric: tabular-nums; }
.ctl .note { display: block; margin-top: 5px; font-size: 12px; font-style: normal; color: var(--ink-faint); }

input[type="range"] {
  width: 100%;
  height: 26px;
  accent-color: var(--accent);
  background: none;
}

.chk {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 38px;
  font-size: 14px;
  color: var(--ink);
  cursor: pointer;
}
.chk input { width: 18px; height: 18px; accent-color: var(--accent); }

.row-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.row-btns button {
  min-height: 38px;
  padding: 8px 13px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: none;
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.row-btns button:hover { border-color: var(--accent); }

#loc-form { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
#loc-form input {
  flex: 1 1 130px;
  min-height: 38px;
  padding: 8px 11px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  color: var(--ink);
  font: inherit;
  font-size: 13px;
}
#loc-form button {
  min-height: 38px;
  padding: 8px 15px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(120, 150, 220, 0.16);
  color: var(--ink);
  font: inherit;
  cursor: pointer;
}

/* ------------------------------------------------------------- what's up list */

.wu-group { margin-bottom: 14px; }
.wu-group h4 {
  margin: 0 0 6px;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
.wu-item {
  display: flex;
  width: 100%;
  align-items: center;
  gap: 12px;
  min-height: 46px;
  padding: 9px 11px;
  margin-bottom: 4px;
  border-radius: 11px;
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.035);
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.wu-item:hover, .wu-item:focus-visible {
  background: rgba(120, 150, 220, 0.16);
  border-color: var(--accent);
  outline: none;
}
.wu-dot {
  flex: 0 0 auto;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent-warm);
  box-shadow: 0 0 8px currentColor;
}
.wu-main { flex: 1 1 auto; min-width: 0; }
.wu-name { display: block; color: var(--ink); font-size: 14px; }
.wu-meta { display: block; font-size: 12px; color: var(--ink-dim); }
.wu-where {
  flex: 0 0 auto;
  font-size: 12px;
  color: var(--ink-dim);
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.wu-empty { padding: 14px 4px; color: var(--ink-dim); font-size: 13px; }

/* --------------------------------------------------------------- detail card */

#panel {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(12px + var(--safe-bottom));
  z-index: 32;
  max-width: 640px;
  margin: 0 auto;
  max-height: 74vh;
  overflow-y: auto;
  padding: 18px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: var(--panel-solid);
  backdrop-filter: blur(14px);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.6);
}

#close-panel {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: none;
  color: var(--ink-dim);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}
#close-panel:hover { color: var(--ink); border-color: var(--accent); }

#panel h2 { margin: 0 0 3px; font-size: 21px; font-weight: 600; padding-right: 40px; }
#panel .subtitle { margin: 0 0 12px; font-size: 13px; color: var(--ink-dim); }

.facts { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.fact {
  display: inline-flex;
  align-items: baseline;
  gap: 5px;
  padding: 5px 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  font-size: 12px;
}
.fact .fk { color: var(--ink-faint); }
.fact .fv { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }

#panel .sect {
  margin: 16px 0 7px;
  font-size: 11px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
#panel .row {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding: 6px 0;
  border-bottom: 1px solid rgba(120, 150, 220, 0.1);
  font-size: 14px;
}
#panel .row .k { color: var(--ink-dim); }
#panel .row .v { color: var(--ink); text-align: right; font-variant-numeric: tabular-nums; }
#panel .prose { margin: 6px 0 0; font-size: 14px; color: var(--ink-dim); }
#panel ul { margin: 6px 0 0; padding-left: 18px; }
#panel li { margin-bottom: 6px; font-size: 14px; color: var(--ink-dim); }
#panel .prose strong, #panel li strong { color: var(--ink); }

#panel .goto {
  margin: 12px 0 4px;
  min-height: var(--tap);
  width: 100%;
  padding: 11px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(120, 150, 220, 0.16);
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}
#panel .goto:hover { border-color: var(--accent); }

/* -------------------------------------------------------------- onboarding */

#onboarding {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(3, 6, 16, 0.82);
  backdrop-filter: blur(6px);
}

.onb-card {
  width: 100%;
  max-width: 460px;
  padding: 24px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: var(--panel-solid);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.65);
}
.onb-card h2 { margin: 0 0 6px; font-size: 21px; font-weight: 600; }
.onb-lede { margin: 0 0 18px; font-size: 14px; color: var(--ink-dim); }
.onb-list { list-style: none; margin: 0 0 16px; padding: 0; }
.onb-list li {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 14px;
  font-size: 14px;
  color: var(--ink-dim);
}
/* The description must be a single flex item. Left as bare inline content, every
   <b> and every text node becomes its own column and the sentence shreds. */
.onb-text { flex: 1 1 auto; }
.onb-list b { color: var(--ink); }
.onb-ico {
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: rgba(120, 150, 220, 0.14);
  color: var(--accent);
  font-size: 15px;
}
.onb-note { margin: 0 0 16px; font-size: 12px; color: var(--ink-faint); }
.onb-go {
  width: 100%;
  min-height: 48px;
  border-radius: 12px;
  border: 1px solid var(--accent);
  background: rgba(127, 178, 255, 0.2);
  color: var(--ink);
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.onb-go:hover { background: rgba(127, 178, 255, 0.3); }

.onb-skip {
  width: 100%;
  margin-top: 8px;
  min-height: 40px;
  border: 0;
  border-radius: 12px;
  background: none;
  color: var(--ink-faint);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.onb-skip:hover { color: var(--ink-dim); }

/* ------------------------------------------------------------ small screens */

@media (max-width: 430px) {
  .ctl-btn .lbl { display: none; }      /* icons only; titles carry the meaning */
  .ctl-btn { padding: 9px 13px; }
  #buttons { justify-content: space-between; }
  #panel { padding: 16px; }
  #panel h2 { font-size: 19px; }
}

/* Landscape phones: keep the sheet from eating the whole sky. */
@media (max-height: 480px) {
  #settings, #whats-up, #sensor-help { max-height: 82vh; }
  #top { padding-bottom: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
