:root {
  color-scheme: dark;
  font: 16px system-ui, sans-serif;
  background: #111b22;
  color: #f1f3ed;
  --panel: #1a2831;
  --border: #52616a;
  --muted: #b6c3c8;
  --accent: #f8cb79;
  --green: #a8e6a1;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; }
main { max-width: 460px; margin: auto; padding: 18px 18px max(18px, env(safe-area-inset-bottom)); }
header, .controls, .location, form { display: flex; align-items: center; gap: 8px; }
header { justify-content: space-between; margin-bottom: 12px; }
.header-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
.header-actions button { padding-inline: 8px; font-size: .8rem; }
#rotation-status { margin: 0 0 8px; font-size: .8rem; }
h1 { margin: 0; font-size: 1.35rem; font-weight: 650; }
button, input {
  min-height: 44px; border: 1px solid var(--border); border-radius: 9px;
  background: #22343f; color: inherit; font: inherit;
}
button { padding: 6px 13px; font-weight: 600; cursor: pointer; }
button:disabled { opacity: .48; cursor: default; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.primary { background: var(--accent); color: #21221e; border-color: transparent; }
.instrument, .location { background: var(--panel); border: 1px solid #384952; border-radius: 16px; padding: 12px; }
.compass {
  height: 70px; position: relative; overflow: hidden; margin-bottom: 9px;
  border: 1px solid #52616a; border-radius: 9px; background: #111b22;
}
.compass-scale { position: absolute; inset: 0; }
.compass-scale::after {
  content: ""; position: absolute; left: -10%; width: 420%; bottom: 12px; border-top: 1px solid #52616a;
}
.compass:has(.compass-scale:not([hidden]))::after {
  content: ""; position: absolute; left: 50%; bottom: 1px; translate: -50% 0;
  border-inline: 6px solid transparent; border-bottom: 9px solid var(--accent);
}
.compass-tick {
  position: absolute; bottom: 12px; height: 8px; border-left: 1px solid #74858e;
}
.compass-tick.major { height: 15px; border-color: var(--muted); }
.compass-tick span {
  position: absolute; bottom: 17px; left: 0; translate: -50% 0;
  color: var(--muted); font-size: .72rem; font-variant-numeric: tabular-nums;
}
.compass-tick .cardinal { font-weight: 700; font-size: .95rem; color: #f1f3ed; }
.compass-tick .north { color: var(--accent); }
.readings { display: grid; grid-template-columns: 1fr 1fr; text-align: center; margin: 0; }
dt, p, footer { color: var(--muted); }
dt { font-size: .86rem; }
dd { margin: 0; font-size: clamp(1.9rem, 9vw, 2.7rem); font-variant-numeric: tabular-nums; line-height: 1.13; }
#sensor-status:empty { display: none; }
#sensor-status { text-align: center; font-size: .82rem; margin: 8px 0 10px; }
#start { width: 100%; margin-bottom: 8px; }
.controls > button { flex: 1; }
#target { border-top: 1px solid var(--border); margin-top: 12px; padding-top: 10px; }
form { align-items: end; }
label { min-width: 0; flex: 1; font-size: .82rem; }
input { width: 100%; padding: 5px 8px; display: block; margin-top: 3px; font-size: 1rem; }
.viewfinder { display: grid; justify-items: center; gap: 8px; margin-bottom: 12px; }
.camera-window {
  position: relative; overflow: hidden; isolation: isolate;
  width: min(100%, 210px, max(124px, 30svh)); aspect-ratio: 1;
  border: 1px solid var(--border); border-radius: 50%; background: #111b22;
}
#camera-video {
  --screen-share: 1;
  position: absolute; top: 50%; left: 50%; translate: -50% -50%;
  /* At the narrowest field, a viewport-sized image sits behind the circular aperture. */
  width: calc(100dvw * var(--screen-share) + 100% * (1 - var(--screen-share)));
  height: calc(100dvh * var(--screen-share) + 100% * (1 - var(--screen-share)));
  object-fit: cover;
}
#camera-toggle { font-size: .8rem; }
#camera-status { margin: 0; text-align: center; font-size: .8rem; }
.crosshair, .reticle { position: absolute; inset: 50% auto auto 50%; translate: -50% -50%; pointer-events: none; }
.crosshair { width: 24px; height: 24px; }
.crosshair::before, .crosshair::after {
  content: ""; position: absolute; inset: 50% auto auto 50%; translate: -50% -50%;
  background: #f1f3ed; box-shadow: 0 0 0 1px #111b22;
}
.crosshair::before { width: 24px; height: 2px; }
.crosshair::after { width: 2px; height: 24px; }
.reticle { width: 106px; aspect-ratio: 1; }
.reticle i, .reticle b { position: absolute; top: 50%; left: 50%; translate: -50% -50%; border-radius: 50%; }
.reticle i { width: 25%; aspect-ratio: 1; border: 2px solid #f1f3ed; box-shadow: 0 0 0 1px #111b22; }
.reticle b { width: 10px; aspect-ratio: 1; background: var(--accent); box-shadow: 0 0 0 1px #111b22; }
.reticle[data-aligned] i { border: 2px solid var(--green); }
.reticle[data-aligned] b { background: var(--green); }
.direction { text-align: center; margin: 3px 0 0; font-size: .86rem; min-height: 1.3em; }
.location { margin-top: 10px; }
.location div { flex: 1; min-width: 0; }
.location h2 { font-size: 1rem; margin: 0 0 2px; }
.location p { margin: 0; font-size: .81rem; font-variant-numeric: tabular-nums; }
footer, #install-help { margin: 10px 2px 0; font-size: .79rem; }
footer a { color: inherit; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }

header h1 { display: flex; align-items: center; gap: .5rem; color: var(--accent); }
header h1 img { display: block; flex: none; border-radius: 8px; }
footer { text-align: center; }
body:has(#toggle-target[aria-expanded="false"])::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 10;
  border: 12px solid var(--accent);
  pointer-events: none;
}

.camera-controls { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 8px; }
#zoom-toggle { min-width: 70px; padding-inline: 8px; font-size: .8rem; }
#night-toggle { padding-inline: 8px; font-size: .8rem; }
#night-toggle[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }
#camera-video[data-night] { filter: brightness(3); }

@media (orientation: landscape) and (min-width: 540px) {
  main {
    max-width: 960px;
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(0, 3fr);
    align-items: start;
    gap: 8px 16px;
    padding-inline: max(18px, env(safe-area-inset-left)) max(18px, env(safe-area-inset-right));
  }
  .camera-window { width: min(100%, 310px, max(140px, 58svh)); }
  header, #install-help, #rotation-status, footer { grid-column: 1 / -1; }
  header { margin-bottom: 4px; }
  .viewfinder { margin-bottom: 0; }
  .instrument, .location { padding: 8px 10px; }
  .compass { height: 50px; margin-bottom: 4px; }
  dd { font-size: clamp(1.75rem, 7svh, 2.7rem); }
  #sensor-status { margin-block: 4px 6px; }
  #target { margin-top: 8px; padding-top: 6px; }
  footer { grid-column: 1 / -1; margin-top: 0; }
}

