*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
  background: var(--bg-0);
  color: var(--ink-1);
  font: var(--fs-body) / 1.6 var(--font-body);
  -webkit-font-smoothing: antialiased;
  /* Dragging the globe must not select the HUD text it passes over; the explainer stays selectable. */
  -webkit-user-select: none;
  user-select: none;
}

button {
  font: inherit;
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.label {
  margin: 0;
  color: var(--ink-3);
  font: 500 var(--fs-label) / 1 var(--font-mono);
  letter-spacing: var(--ls-label);
  text-transform: uppercase;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---- Layout: the globe fills the screen, the HUD floats over it ---- */

#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.hud {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  /* The station card sits under the title, in a row that may shrink: it never pushes the timeline off screen. */
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  grid-template-areas:
    "brand clock"
    "panel ."
    "caption caption"
    "timeline timeline";
  gap: var(--s-4);
  padding: var(--s-6);
  pointer-events: none;
}

.hud > * {
  pointer-events: auto;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

/* ---- Brand ---- */

.brand {
  grid-area: brand;
  align-self: start;
  max-width: 440px;
  pointer-events: none;
}

.brand h1 {
  margin: var(--s-2) 0 var(--s-2);
  font: 600 var(--fs-display) / 1 var(--font-display);
  letter-spacing: var(--ls-display);
}

.brand h1 span {
  color: var(--accent);
}

.brand .lead {
  margin: 0;
  color: var(--ink-2);
  font-size: var(--fs-small);
  line-height: 1.5;
}

.brand .rule {
  width: 120px;
  height: 2px;
  margin-top: var(--s-4);
  background: var(--spectrum);
  border-radius: 2px;
}

/* ---- Clock ---- */

.clock {
  grid-area: clock;
  align-self: start;
  justify-self: end;
  padding: var(--s-3) var(--s-4);
  text-align: right;
}

.clock time {
  display: block;
  margin: var(--s-2) 0 var(--s-1);
  font: 500 32px / 1 var(--font-mono);
  font-variant-numeric: tabular-nums;
}

/* ---- Station panel ---- */

.station {
  grid-area: panel;
  align-self: start;
  justify-self: start;
  width: 300px;
  max-height: 100%;
  overflow-y: auto;
  padding: var(--s-4);
}

.station[hidden] {
  display: none;
}

.station header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: var(--s-3);
}

.station h2 {
  margin: var(--s-2) 0 0;
  font: 600 20px / 1.2 var(--font-display);
  letter-spacing: -0.01em;
}

.station .close {
  padding: var(--s-1) var(--s-2);
  background: none;
  border: 1px solid var(--line-2);
  border-radius: 6px;
  cursor: pointer;
}

.station dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: var(--s-2) var(--s-4);
  margin: var(--s-4) 0;
  font-size: var(--fs-small);
}

.station dt {
  color: var(--ink-3);
}

.station dd {
  margin: 0;
  text-align: right;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.station canvas {
  display: block;
  width: 100%;
  height: 14px;
  margin-top: var(--s-2);
  border-radius: 3px;
}

/* ---- Link state colours ---- */

.state-4 {
  color: var(--ok);
}
.state-3 {
  color: var(--warn);
}
.state-2 {
  color: var(--alert);
}
.state-1,
.state-0 {
  color: var(--ink-3);
}

/* ---- Caption ---- */

.caption {
  grid-area: caption;
  justify-self: center;
  max-width: 640px;
  margin: 0;
  padding: var(--s-3) var(--s-5);
  text-align: center;
  font-size: var(--fs-body);
  opacity: 0;
  transform: translateY(6px);
  transition:
    opacity 0.4s,
    transform 0.4s;
}

.caption.visible {
  opacity: 1;
  transform: none;
}

/* ---- Timeline ---- */

.timeline {
  grid-area: timeline;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: var(--s-3) var(--s-5);
  align-items: center;
  padding: var(--s-4) var(--s-5);
}

.controls {
  display: flex;
  align-items: center;
  gap: var(--s-2);
}

.controls button {
  min-width: 36px;
  height: 32px;
  padding: 0 var(--s-3);
  background: var(--bg-2);
  border: 1px solid var(--line-2);
  border-radius: 8px;
  cursor: pointer;
  font: 500 var(--fs-label) / 1 var(--font-mono);
  letter-spacing: 0.04em;
}

.controls button:hover {
  border-color: var(--line-3);
}

.controls button[aria-pressed="true"] {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--sky-300);
}

/* Automatic camera paused by a drag or zoom: still on, but waiting (js/render/camera-director.js). */
.controls button[data-state="paused"] {
  background: transparent;
  border-color: var(--line-3);
  border-style: dashed;
  color: var(--ink-3);
}

.controls .play {
  min-width: 44px;
  background: var(--accent);
  border-color: var(--accent);
  color: #06101e;
}

.controls .group {
  display: flex;
  gap: 2px;
  padding: 2px;
  background: var(--bg-1);
  border: 1px solid var(--line-1);
  border-radius: 10px;
}

.controls .group button {
  border-color: transparent;
  background: transparent;
}

.availability {
  min-width: 0;
}

.availability-head {
  display: flex;
  justify-content: space-between;
  gap: var(--s-3);
  margin-bottom: var(--s-2);
}

.availability-rows {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  align-items: center;
  gap: 3px var(--s-3);
}

.row-name {
  color: var(--ink-3);
  font-size: 10px;
  text-align: right;
  white-space: nowrap;
}

button.row-name {
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
}

button.row-name:hover,
button.row-name:focus-visible {
  color: var(--ink-1);
}

#availability {
  grid-column: -2;
  display: block;
  width: 100%;
  height: 28px;
  border-radius: 4px;
  cursor: pointer;
}

.region-row {
  display: block;
  width: 100%;
  height: 7px;
  border-radius: 2px;
  cursor: pointer;
}

.recent {
  display: flex;
  gap: 3px;
  height: 18px;
  margin-top: var(--s-2);
}

.recent-label {
  margin: var(--s-1) 0 0;
  color: var(--ink-3);
  font-size: 10px;
  text-align: right;
}

.recent span {
  flex: 1;
  border-radius: 3px;
  background: var(--ok);
  opacity: 0.9;
}

.recent span.g1 {
  background: var(--warn);
}
.recent span.g0 {
  background: var(--alert);
}

.legend {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2) var(--s-5);
  margin: 0;
  padding: 0;
  list-style: none;
}

.legend li {
  display: flex;
  align-items: center;
  gap: var(--s-2);
}

.legend i {
  display: inline-block;
  width: 18px;
  height: 3px;
  border-radius: 2px;
}

.legend .beam-up {
  height: 4px;
  background: var(--ok);
  box-shadow: 0 0 6px var(--ok);
}
.legend .beam-degraded {
  background: var(--warn);
}
.legend .reroute {
  height: 2px;
  background: repeating-linear-gradient(90deg, var(--sky-300) 0 4px, transparent 4px 7px);
}
.legend .beam-down {
  height: 2px;
  background: var(--alert);
  opacity: 0.7;
}
.legend .cloud {
  height: 10px;
  background: #eaf0fa99;
  border-radius: 5px;
}
.legend .turbulence {
  height: 10px;
  width: 6px;
  background: linear-gradient(0deg, var(--ok), var(--warn), var(--alert));
}

/* ---- View from below (js/ui/sky-view.js) ---- */

.sky-open {
  display: block;
  width: 100%;
  margin-top: var(--s-3);
  padding: var(--s-2) var(--s-3);
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 8px;
  color: #06101e;
  cursor: pointer;
  font: 600 var(--fs-label) / 1 var(--font-mono);
  letter-spacing: var(--ls-label);
  text-transform: uppercase;
}

.sky-open[hidden] {
  display: none;
}

/* Under "How it works": straight to the view from below. */
.sky-shortcut {
  display: block;
  width: 100%;
  margin-top: var(--s-2);
  padding: var(--s-2) var(--s-3);
  background: transparent;
  border: 1px solid var(--line-3);
  border-radius: 8px;
  color: var(--ink-2);
  cursor: pointer;
  font: 500 var(--fs-label) / 1 var(--font-mono);
  letter-spacing: var(--ls-label);
  text-transform: uppercase;
}

.sky-shortcut:hover {
  border-color: var(--accent);
  color: var(--sky-300);
}

.sky-shortcut[hidden] {
  display: none;
}

/* The globe and its HUD step aside while the view from below is open. */
#scene,
.hud {
  transition: opacity 0.6s;
}

body.inside #scene,
body.inside .hud {
  opacity: 0;
  pointer-events: none;
}

.sky-view {
  position: fixed;
  inset: 0;
  z-index: 5;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: var(--s-4);
  padding: var(--s-5) var(--s-6);
  background: radial-gradient(ellipse at 50% 0%, var(--bg-2), var(--bg-0) 70%);
  opacity: 0;
  transition: opacity 0.6s;
}

.sky-view[hidden] {
  display: none;
}

body.inside .sky-view {
  opacity: 1;
}

.sky-head {
  display: flex;
  align-items: center;
  gap: var(--s-5);
}

.sky-head > :first-child {
  flex: 1;
}

.sky-head h2 {
  margin: var(--s-1) 0 0;
  font: 600 var(--fs-display) / 1.1 var(--font-display);
  letter-spacing: var(--ls-display);
}

.sky-head h2:focus {
  outline: none;
}

.sky-now {
  text-align: right;
}

.sky-now time {
  display: block;
  font: 500 32px / 1 var(--font-mono);
}

.sky-now .label {
  margin-top: var(--s-1);
  color: var(--sky-300);
}

.sky-actions {
  display: flex;
  gap: var(--s-2);
}

.sky-actions .explain-open {
  width: auto;
  margin: 0;
}

.sky-back {
  padding: var(--s-2) var(--s-3);
  background: var(--bg-2);
  border: 1px solid var(--line-2);
  border-radius: 8px;
  cursor: pointer;
  font: 500 var(--fs-label) / 1 var(--font-mono);
  letter-spacing: var(--ls-label);
  text-transform: uppercase;
}

.sky-back:hover {
  border-color: var(--line-3);
}

.sky-windows {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--s-4);
  min-height: 0;
}

.sky-window {
  display: flex;
  flex-direction: column;
  min-height: 0;
  margin: 0;
  padding: var(--s-3);
}

/* The space left in the window, measured, so the frame inside can be the largest square that fits. */
.sky-frame-box {
  flex: 1;
  min-height: 0;
  display: grid;
  place-items: center;
  container-type: size;
}

.sky-frame {
  position: relative;
  width: min(100cqw, 100cqh);
  height: min(100cqw, 100cqh);
}

.sky-frame img,
.sky-frame canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

/* The fisheye circle only: hides the frame's corners and the edge labels burned into it. */
.sky-frame img {
  clip-path: circle(42% at 50% 50%);
  object-fit: contain;
}

/* Captions keep a fixed height (three lines of text), so the windows never jump as the text changes. */
.sky-window figcaption {
  padding-top: var(--s-3);
  min-height: calc(var(--fs-label) + var(--s-1) + 3 * 1.45 * var(--fs-small) + var(--s-3));
}

.sky-window figcaption p:not(.label) {
  margin: var(--s-1) 0 0;
  color: var(--ink-2);
  font-size: var(--fs-small);
  line-height: 1.45;
}

.sky-timeline {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: var(--s-5);
  padding: var(--s-3) var(--s-4);
}

#sky-curve {
  display: block;
  width: 100%;
  height: 72px;
  cursor: pointer;
}

.sky-curve .legend {
  margin-top: var(--s-2);
}

.legend .clear-sky {
  background: var(--sky-300);
}

.legend .transmission {
  height: 2px;
  background: repeating-linear-gradient(90deg, var(--ink-2) 0 4px, transparent 4px 7px);
}

.legend .night {
  height: 10px;
  background: #2b3a5c;
}

.swatch.sky-photo {
  height: 10px;
  background: radial-gradient(circle, #8290ab, #0b1121);
  border-radius: 5px;
}

.swatch.sector {
  height: 10px;
  background: var(--sky-400);
}

.swatch.decor {
  height: 10px;
  background: #b0413e;
}

@media (max-width: 900px), (max-height: 640px) {
  .sky-view {
    overflow-y: auto;
    grid-template-rows: auto auto auto;
    padding: var(--s-4);
  }
  .sky-windows {
    grid-template-columns: minmax(0, 1fr);
  }
  /* Stacked: each window keeps its natural height, and the view scrolls. */
  .sky-windows,
  .sky-window {
    min-height: auto;
  }
  .sky-frame-box {
    flex: none;
    container-type: inline-size;
  }
  .sky-frame {
    width: min(100cqw, 420px);
    height: min(100cqw, 420px);
  }
  .sky-head {
    flex-wrap: wrap;
  }
  .sky-timeline {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* ---- "How it works" drawer ---- */

.explain-open {
  display: block;
  width: 100%;
  margin-top: var(--s-3);
  padding: var(--s-2) var(--s-3);
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  border-radius: 8px;
  color: var(--sky-300);
  cursor: pointer;
  font: 500 var(--fs-label) / 1 var(--font-mono);
  letter-spacing: var(--ls-label);
  text-transform: uppercase;
}

.explain-open:hover,
.explain-open[aria-expanded="true"] {
  background: var(--accent);
  color: #06101e;
}

.drawer {
  -webkit-user-select: text;
  user-select: text;
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  width: min(500px, 100%);
  padding: var(--s-5) var(--s-6) var(--s-6);
  overflow-y: auto;
  overscroll-behavior: contain;
  background: #111a2df2;
  border-left: 1px solid var(--line-2);
  box-shadow: -24px 0 48px #0006;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transform: translateX(100%);
  visibility: hidden;
  transition:
    transform 0.35s cubic-bezier(0.2, 0.7, 0.2, 1),
    visibility 0s 0.35s;
}

.drawer.open {
  transform: none;
  visibility: visible;
  transition: transform 0.35s cubic-bezier(0.2, 0.7, 0.2, 1);
}

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.drawer .close {
  padding: var(--s-1) var(--s-2);
  background: none;
  border: 1px solid var(--line-2);
  border-radius: 6px;
  cursor: pointer;
}

.drawer h2 {
  margin: var(--s-4) 0 var(--s-3);
  font: 600 26px / 1.15 var(--font-display);
  letter-spacing: -0.02em;
}

.drawer h2:focus {
  outline: none;
}

.drawer .lead {
  margin: 0;
  color: var(--ink-2);
}

.drawer strong {
  color: var(--ink-1);
  font-weight: 600;
}

.steps {
  margin: var(--s-5) 0 0;
  padding: 0;
  list-style: none;
}

.step {
  padding: var(--s-5) 0;
  border-top: 1px solid var(--line-1);
}

.step .label {
  color: var(--accent);
}

.step h3 {
  margin: var(--s-2) 0 var(--s-3);
  font: 600 19px / 1.25 var(--font-display);
  letter-spacing: -0.01em;
}

.step p {
  margin: 0 0 var(--s-3);
  color: var(--ink-2);
  font-size: var(--fs-small);
}

.formula {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: var(--s-3) var(--s-6);
  margin: var(--s-4) 0;
  padding: var(--s-4) var(--s-3);
  overflow-x: auto;
  background: var(--bg-0);
  border: 1px solid var(--line-1);
  border-left: 2px solid var(--accent);
  border-radius: 6px;
}

.formula math {
  color: var(--ink-1);
  font-family: "STIX Two Math", "Cambria Math", "Latin Modern Math", math;
  font-size: 17px;
}

.drawer .note {
  color: var(--ink-3);
  font-size: 12.5px;
}

.drawer .seen {
  display: flex;
  align-items: baseline;
  gap: var(--s-3);
  padding: var(--s-2) var(--s-3);
  background: var(--bg-2);
  border-radius: 6px;
  color: var(--ink-1);
}

.swatch {
  flex: none;
  display: inline-block;
  width: 18px;
  height: 4px;
  border-radius: 2px;
  transform: translateY(-3px);
}
.swatch.sat {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ink-1);
  box-shadow: 0 0 6px var(--sky-300);
}
.swatch.cloud {
  height: 10px;
  background: #eaf0fa99;
  border-radius: 5px;
}
.swatch.down {
  background: var(--alert);
}
.swatch.degraded {
  background: var(--warn);
}
.swatch.turbulence {
  width: 6px;
  height: 12px;
  background: linear-gradient(0deg, var(--ok), var(--warn), var(--alert));
}
.swatch.reroute {
  height: 2px;
  border-radius: 0;
  background: repeating-linear-gradient(90deg, var(--sky-300) 0 4px, transparent 4px 7px);
}
.swatch.ok {
  height: 10px;
  background: linear-gradient(90deg, var(--ok) 0 70%, var(--warn) 70% 85%, var(--alert) 85%);
}

.drawer-foot {
  padding-top: var(--s-4);
  border-top: 1px solid var(--line-1);
}

.drawer-foot .note {
  margin: var(--s-2) 0 0;
}

/* ---- Station labels on the globe ---- */

#labels {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

/* Best-guess values (not measured): a discreet dotted underline. */
.inferred {
  text-decoration: underline dotted var(--ink-3);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

/* Always takes its line, so the card keeps its height; only shown while a value is a guess. */
.inferred-note {
  margin: var(--s-2) 0 var(--s-3);
  color: var(--ink-3);
  font-size: 11.5px;
  opacity: 0;
  visibility: hidden;
  transition:
    opacity 0.3s,
    visibility 0.3s;
}

.inferred-note.shown {
  opacity: 1;
  visibility: visible;
}

.station-label {
  position: absolute;
  top: 0;
  left: 0;
  padding: 2px 6px;
  border-radius: 4px;
  background: #0b1121b3;
  color: var(--ink-2);
  font: 500 10.5px / 1.3 var(--font-mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
  pointer-events: none;
  transition: opacity 0.6s;
}

.station-label.selected {
  color: var(--ink-1);
  box-shadow: var(--accent-glow);
}

/* ---- Overlays ---- */

.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: var(--bg-0);
  transition: opacity 0.6s;
}

.overlay.done {
  opacity: 0;
  pointer-events: none;
}

.overlay p {
  max-width: 420px;
  padding: var(--s-4);
  text-align: center;
}

.fps {
  position: fixed;
  right: var(--s-2);
  bottom: var(--s-2);
  font: 11px var(--font-mono);
  color: var(--ink-3);
}

/* ---- Small screens: brand shrinks, panel becomes a sheet, legend hides ---- */

@media (max-width: 760px) {
  .hud {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "brand clock"
      ". ."
      "panel panel"
      "caption caption"
      "timeline timeline";
    grid-template-rows: auto minmax(0, 1fr) auto auto auto;
    gap: var(--s-2);
    padding: var(--s-4);
  }
  .brand .lead,
  .brand .rule,
  .legend {
    display: none;
  }
  .clock time {
    font-size: 22px;
  }
  .station {
    width: 100%;
  }
  .station dl {
    grid-template-columns: auto 1fr auto 1fr;
  }
  .timeline {
    grid-template-columns: 1fr;
    padding: var(--s-3);
  }
}

/* ---- Short screens (small laptops, the browser not maximised): compact HUD ---- */

@media (max-height: 760px) {
  .hud {
    gap: var(--s-2);
    padding: var(--s-4);
  }
  .brand .lead,
  .brand .rule {
    display: none;
  }
  .timeline {
    gap: var(--s-2) var(--s-4);
    padding: var(--s-3) var(--s-4);
  }
  #availability {
    height: 18px;
  }
  .recent {
    height: 10px;
    gap: 2px;
  }
  .legend {
    display: none;
  }
  .clock {
    padding: var(--s-2) var(--s-3);
  }
  .clock time {
    font-size: 24px;
  }
  .caption {
    padding: var(--s-2) var(--s-4);
    font-size: var(--fs-small);
  }
}

@media (prefers-reduced-motion: reduce) {
  .drawer,
  .drawer.open,
  .caption,
  .overlay,
  .station-label,
  .inferred-note {
    transition: none;
  }
}

.availability-rows.single {
  grid-template-columns: minmax(0, 1fr);
}

/* Small screens: the network row only. */
@media (max-width: 760px), (max-height: 600px) {
  .availability-rows {
    grid-template-columns: minmax(0, 1fr);
  }
  .region-row,
  .row-name {
    display: none;
  }
}
