:root {
  color-scheme: light;
  --bg: #f8f7ef;
  --panel: #ffffff;
  --panel-strong: #fff351;
  --ink: #090b0f;
  --muted: #52606b;
  --line: #111827;
  --soft-line: rgba(17, 24, 39, 0.15);
  --good: #0a7d3e;
  --good-bg: #d8ffe8;
  --warn: #b85b00;
  --warn-bg: #fff0c2;
  --bad: #c81e1e;
  --bad-bg: #ffe1df;
  --sky: #23b8df;
  --shadow: 0 16px 0 rgba(9, 11, 15, 0.12);
  --dish-rotation: 0deg;
  --tilt-x: 0px;
  --tilt-y: 0px;
  --sweep-rotation: 0deg;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  font-family: "Space Grotesk", "Avenir Next", "Segoe UI", sans-serif;
  background:
    linear-gradient(90deg, rgba(9, 11, 15, 0.05) 1px, transparent 1px),
    linear-gradient(rgba(9, 11, 15, 0.05) 1px, transparent 1px),
    var(--bg);
  background-size: 26px 26px;
  color: var(--ink);
}

body.sun-mode {
  --bg: #fff351;
  --panel: #fffef0;
  --panel-strong: #ffffff;
  --muted: #171b20;
  --soft-line: rgba(0, 0, 0, 0.32);
  filter: contrast(1.08) saturate(0.95);
}

button,
input,
a {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

.setup-shell {
  min-height: 100vh;
  display: grid;
  justify-items: center;
  padding:
    max(12px, env(safe-area-inset-top))
    max(10px, env(safe-area-inset-right))
    max(14px, env(safe-area-inset-bottom))
    max(10px, env(safe-area-inset-left));
}

.setup-app {
  width: min(100%, 460px);
  min-height: calc(100vh - 26px);
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr) auto;
  gap: 10px;
}

.setup-header,
.stage-head,
.control-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.setup-date {
  margin: 0 0 2px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(2.35rem, 11vw, 3.7rem);
  line-height: 0.92;
  letter-spacing: 0;
}

h2 {
  font-size: clamp(1.15rem, 5vw, 1.55rem);
  line-height: 1;
}

.sun-button,
.stage-tabs button,
.bottom-actions button,
.quick-checks button,
.scan-actions button,
.target-actions button {
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  font-weight: 800;
}

.sun-button {
  min-width: 58px;
  min-height: 48px;
  box-shadow: 0 5px 0 var(--line);
}

.sun-button[aria-pressed="true"] {
  background: var(--ink);
  color: var(--panel-strong);
}

.signal-card,
.stage-panel {
  border: 2px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.signal-card {
  display: grid;
  grid-template-columns: minmax(142px, 0.9fr) minmax(0, 1.1fr);
  gap: 10px;
  padding: 10px;
}

.sky-meter {
  min-width: 0;
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 6px;
}

.sky-ring {
  position: relative;
  width: min(100%, 178px);
  aspect-ratio: 1;
  border: 3px solid var(--line);
  border-radius: 50%;
  background:
    radial-gradient(circle at center, var(--panel) 0 23%, transparent 24%),
    conic-gradient(from -20deg, rgba(35, 184, 223, 0.22), rgba(255, 243, 81, 0.9), rgba(35, 184, 223, 0.22));
  overflow: hidden;
}

.sky-ring::after {
  content: "";
  position: absolute;
  inset: 25%;
  border: 2px solid rgba(9, 11, 15, 0.22);
  border-radius: 50%;
}

.cardinal {
  position: absolute;
  z-index: 3;
  font-size: 0.78rem;
  font-weight: 800;
}

.north {
  top: 4px;
  left: 50%;
  transform: translateX(-50%);
}

.east {
  top: 50%;
  right: 6px;
  transform: translateY(-50%);
}

.south {
  bottom: 4px;
  left: 50%;
  transform: translateX(-50%);
}

.west {
  top: 50%;
  left: 6px;
  transform: translateY(-50%);
}

.target-band {
  position: absolute;
  inset: 8%;
  border-radius: 50%;
  background: conic-gradient(from -18deg, transparent 0 341deg, rgba(10, 125, 62, 0.34) 341deg 360deg);
  transform: rotate(var(--dish-rotation));
}

.obstruction-sweep {
  position: absolute;
  inset: -1px;
  border-radius: 50%;
  background: conic-gradient(from var(--sweep-rotation), transparent 0 9deg, rgba(200, 30, 30, 0.35) 9deg 18deg, transparent 18deg 360deg);
}

.dish-arrow {
  position: absolute;
  z-index: 4;
  width: 38%;
  top: 12%;
  left: 31%;
  transform: rotate(var(--dish-rotation));
  transform-origin: 50% 85%;
  filter: drop-shadow(4px 8px 0 rgba(9, 11, 15, 0.22));
}

.dish-arrow svg {
  display: block;
  width: 100%;
  overflow: visible;
}

.arrow-shadow {
  fill: rgba(9, 11, 15, 0.22);
  transform: translate(5px, 7px);
}

.arrow-body {
  fill: var(--ink);
}

.arrow-core {
  fill: var(--panel-strong);
}

.tilt-bubble {
  position: absolute;
  z-index: 5;
  top: calc(50% + var(--tilt-y));
  left: calc(50% + var(--tilt-x));
  width: 20px;
  height: 20px;
  border: 3px solid var(--line);
  border-radius: 50%;
  background: #ffffff;
  transform: translate(-50%, -50%);
}

.sky-meter strong {
  font-size: clamp(2.2rem, 12vw, 3.2rem);
  line-height: 0.9;
}

.sky-meter span:not(.cardinal) {
  color: var(--muted);
  font-size: 0.77rem;
  font-weight: 800;
  text-transform: uppercase;
}

.live-readout {
  min-width: 0;
  display: grid;
  gap: 8px;
}

.status-line {
  padding: 8px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
  font-size: clamp(0.95rem, 4.4vw, 1.12rem);
  font-weight: 800;
  line-height: 1.12;
}

.primary-hint,
.stage-note {
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.25;
}

.metric-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}

.metric {
  min-width: 0;
  padding: 8px;
  border: 2px solid var(--soft-line);
  border-radius: 8px;
  background: #f8fafc;
}

body.sun-mode .metric {
  background: #ffffff;
}

.metric span,
.metric small {
  display: block;
  color: var(--muted);
  font-size: 0.65rem;
  font-weight: 800;
  text-transform: uppercase;
}

.metric strong {
  display: block;
  margin: 1px 0;
  font-size: clamp(1.16rem, 5.8vw, 1.58rem);
  line-height: 1;
}

.stage-tabs {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}

.stage-tabs button {
  min-height: 42px;
  padding: 0 4px;
  font-size: 0.84rem;
}

.stage-tabs button.is-active {
  background: var(--ink);
  color: #ffffff;
}

.stage-panel {
  min-width: 0;
  padding: 12px;
  display: grid;
  align-content: start;
  gap: 12px;
}

.stage-panel.is-hidden {
  display: none;
}

.stage-head span {
  flex: 0 0 auto;
  padding: 6px 8px;
  border: 2px solid var(--line);
  border-radius: 999px;
  background: var(--warn-bg);
  font-size: 0.78rem;
  font-weight: 800;
}

.quick-checks,
.scan-actions,
.target-actions {
  display: grid;
  gap: 8px;
}

.quick-checks {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.quick-checks button,
.scan-actions button,
.target-actions button {
  min-height: 48px;
  padding: 0 8px;
  line-height: 1.05;
}

.quick-checks button.is-on,
.clear-action,
.target-actions button {
  background: var(--good-bg);
}

.scan-actions {
  grid-template-columns: 1fr 1fr;
}

.blocked-action {
  background: var(--bad-bg) !important;
}

.sector-list {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 5px;
}

.sector {
  min-height: 34px;
  border: 2px solid var(--soft-line);
  border-radius: 7px;
  display: grid;
  place-items: center;
  background: #eef2f7;
  color: var(--muted);
  font-size: 0.64rem;
  font-weight: 800;
}

.sector.is-clear {
  border-color: var(--good);
  background: var(--good-bg);
  color: var(--good);
}

.sector.is-blocked {
  border-color: var(--bad);
  background: var(--bad-bg);
  color: var(--bad);
}

.control-row label,
.control-row output {
  font-size: 0.88rem;
  font-weight: 800;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--ink);
}

.target-actions {
  grid-template-columns: 0.75fr 1.2fr 0.75fr;
}

.final-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.final-list label {
  min-height: 52px;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 8px;
  border: 2px solid var(--soft-line);
  border-radius: 8px;
  background: #f8fafc;
  font-size: 0.9rem;
  font-weight: 800;
  line-height: 1.05;
}

.final-list input {
  width: 20px;
  height: 20px;
  accent-color: var(--good);
}

.bottom-actions {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(0, 0.8fr);
  gap: 8px;
}

.bottom-actions button {
  min-height: 56px;
  padding: 0 12px;
  font-size: 0.96rem;
  line-height: 1;
}

.main-action {
  background: var(--ink) !important;
  color: #ffffff !important;
}

.secondary-action {
  background: var(--panel-strong) !important;
}

.is-good {
  background: var(--good-bg) !important;
  color: var(--good) !important;
}

.is-warn {
  background: var(--warn-bg) !important;
  color: var(--warn) !important;
}

.is-bad {
  background: var(--bad-bg) !important;
  color: var(--bad) !important;
}

@media (max-width: 379px) {
  .setup-app {
    gap: 8px;
  }

  .signal-card {
    grid-template-columns: 132px minmax(0, 1fr);
    padding: 8px;
  }

  .sky-ring {
    width: 132px;
  }

  .primary-hint {
    display: none;
  }

  .metric {
    padding: 6px;
  }

  .stage-panel {
    padding: 10px;
  }
}

@media (min-width: 650px) {
  body {
    display: grid;
    place-items: center;
  }

  .setup-shell {
    width: 500px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
