:root {
  color-scheme: dark;
  --bg: #0b1014;
  --bg-soft: #101820;
  --surface: #151d24;
  --surface-strong: #1b252d;
  --surface-muted: #111920;
  --text: #edf3f2;
  --muted: #93a5a7;
  --muted-strong: #c0cdcc;
  --line: #26343d;
  --line-strong: #40525c;
  --teal: #65d6c5;
  --blue: #70a7ff;
  --amber: #f0b86f;
  --violet: #b49cff;
  --coral: #ff8b7d;
  --green: #9bdc8b;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.36);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  background:
    linear-gradient(180deg, rgba(112, 167, 255, 0.08), transparent 260px),
    linear-gradient(135deg, rgba(101, 214, 197, 0.05), transparent 42%),
    var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input {
  font: inherit;
}

button {
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--teal);
  color: #06100f;
  padding: 0 14px;
  font-weight: 800;
  cursor: pointer;
  transition: transform 160ms ease, background-color 160ms ease, border-color 160ms ease, color 160ms ease;
}

button:hover {
  background: #82e6d8;
}

button:active {
  transform: translateY(1px) scale(0.99);
}

button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 2px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.05;
  font-weight: 850;
}

h2 {
  font-size: 19px;
  line-height: 1.25;
  font-weight: 800;
}

.app-shell {
  width: min(1080px, calc(100% - 24px));
  margin: 0 auto;
  padding: max(14px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  overflow-x: clip;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-width: 0;
  gap: 16px;
  padding: 2px 0 12px;
}

.brand-lockup {
  display: flex;
  align-items: center;
  flex: 1 1 auto;
  min-width: 0;
  gap: 12px;
}

.brand-lockup > div {
  min-width: 0;
}

.brand-lockup h1,
.brand-lockup .eyebrow {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  border: 1px solid rgba(101, 214, 197, 0.42);
  border-radius: 8px;
  background:
    radial-gradient(circle at 35% 28%, rgba(237, 243, 242, 0.96), transparent 0 8%),
    linear-gradient(145deg, #24323a, #101820);
  color: var(--teal);
  font-weight: 900;
  box-shadow: inset 0 0 22px rgba(112, 167, 255, 0.16);
}

.eyebrow {
  color: var(--blue);
  font-size: 12px;
  font-weight: 800;
  line-height: 1.3;
  text-transform: uppercase;
}

.icon-button,
.ghost-button,
.quick-menu button,
.segmented-control button {
  border-color: var(--line);
  background: rgba(21, 29, 36, 0.86);
  color: var(--text);
}

.icon-button {
  display: grid;
  place-items: center;
  width: 62px;
  flex: 0 0 62px;
  min-width: 0;
  height: 42px;
  padding: 0;
  font-size: 13px;
}

.icon-button:hover,
.ghost-button:hover,
.quick-menu button:hover,
.segmented-control button:hover {
  border-color: var(--line-strong);
  background: #202c35;
  color: var(--teal);
}

.quick-menu {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  min-width: 0;
  gap: 8px;
  margin-bottom: 12px;
}

.quick-menu button {
  min-width: 0;
  min-height: 38px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.control-strip {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(16, 24, 32, 0.86);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
  min-width: 0;
}

.location-form {
  width: 100%;
  min-width: 0;
}

.field-label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.location-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  min-width: 0;
  gap: 8px;
}

input[type="text"] {
  min-width: 0;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0a1015;
  color: var(--text);
  padding: 0 12px;
}

input::placeholder {
  color: #728386;
}

.ghost-button {
  min-width: 104px;
}

.earth-panel {
  position: relative;
  overflow: hidden;
  min-height: 490px;
  margin-top: 14px;
  border: 1px solid rgba(101, 214, 197, 0.2);
  border-radius: 8px;
  background: #060a0e;
  box-shadow: var(--shadow);
  isolation: isolate;
  contain: layout paint;
}

#orbitCanvas {
  display: block;
  width: 100%;
  max-width: 100%;
  height: 490px;
}

.stage-toolbar {
  position: absolute;
  left: 14px;
  right: 14px;
  top: 14px;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  pointer-events: none;
  min-width: 0;
}

.segmented-control {
  display: inline-grid;
  grid-template-columns: repeat(2, minmax(84px, 1fr));
  gap: 4px;
  padding: 4px;
  border: 1px solid rgba(237, 243, 242, 0.12);
  border-radius: 8px;
  background: rgba(8, 14, 18, 0.74);
  backdrop-filter: blur(10px);
  pointer-events: auto;
}

.segmented-control button {
  min-height: 34px;
  border-radius: 6px;
  padding: 0 12px;
}

.segmented-control button.is-active {
  border-color: rgba(101, 214, 197, 0.45);
  background: rgba(101, 214, 197, 0.16);
  color: var(--teal);
}

.space-clock {
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid rgba(237, 243, 242, 0.14);
  border-radius: 8px;
  background: rgba(8, 14, 18, 0.74);
  color: var(--muted-strong);
  font-size: 12px;
  font-weight: 800;
  backdrop-filter: blur(10px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.signal-card {
  position: absolute;
  left: 14px;
  bottom: 14px;
  z-index: 2;
  display: grid;
  gap: 5px;
  width: min(290px, calc(100% - 28px));
  padding: 14px;
  border: 1px solid rgba(101, 214, 197, 0.28);
  border-radius: 8px;
  background: rgba(8, 14, 18, 0.78);
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.32);
  backdrop-filter: blur(12px);
}

.signal-card p {
  overflow-wrap: anywhere;
  color: var(--muted-strong);
  font-size: 14px;
}

.signal-card strong {
  color: var(--text);
  font-size: 58px;
  line-height: 0.92;
  font-weight: 900;
  animation: signalPulse 2600ms ease-in-out infinite;
}

.signal-card span {
  color: var(--green);
  font-size: 15px;
  font-weight: 850;
}

.earth-caption {
  position: absolute;
  right: 14px;
  bottom: 14px;
  z-index: 2;
  max-width: min(340px, calc(100% - 28px));
  padding: 11px 12px;
  border: 1px solid rgba(237, 243, 242, 0.12);
  border-radius: 8px;
  background: rgba(8, 14, 18, 0.72);
  color: var(--muted-strong);
  font-size: 13px;
  line-height: 1.45;
  backdrop-filter: blur(12px);
}

.today-panel,
.automation-panel,
.week-panel,
.timeline,
.orbit-note {
  margin-top: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(21, 29, 36, 0.88);
}

.today-panel {
  display: grid;
  grid-template-columns: minmax(150px, 0.35fr) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.today-panel p:last-child,
.orbit-note p,
.subtle-text {
  color: var(--muted-strong);
  line-height: 1.56;
}

.subtle-text {
  margin-top: 10px;
  font-size: 14px;
}

.metrics,
.insight-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.metrics article,
.insight-grid article,
.showers article,
.best-grid article,
.week-row {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
}

.metrics article,
.insight-grid article {
  position: relative;
  display: grid;
  gap: 8px;
  min-height: 88px;
  padding: 12px;
  overflow: hidden;
}

.metrics article::before,
.insight-grid article::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 2px;
  background: linear-gradient(90deg, var(--teal), transparent);
  opacity: 0.78;
}

.insight-grid article:nth-child(2)::before {
  background: linear-gradient(90deg, var(--amber), transparent);
}

.insight-grid article:nth-child(3)::before {
  background: linear-gradient(90deg, var(--violet), transparent);
}

.insight-grid article:nth-child(4)::before {
  background: linear-gradient(90deg, var(--coral), transparent);
}

.metrics span,
.insight-grid span,
.section-title span,
.showers span,
.best-grid span,
.week-row span {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.3;
}

.metrics strong,
.insight-grid strong {
  overflow-wrap: anywhere;
  font-size: 19px;
  line-height: 1.18;
}

.section-title {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
}

.showers,
.best-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.showers article,
.best-grid article {
  padding: 12px;
  transition: border-color 180ms ease, background-color 180ms ease;
}

.showers article:hover,
.best-grid article:hover,
.week-row:hover,
.metrics article:hover,
.insight-grid article:hover {
  border-color: var(--line-strong);
  background: #202c35;
}

.showers strong,
.best-grid strong {
  display: block;
  margin: 5px 0;
  overflow-wrap: anywhere;
  font-size: 18px;
  line-height: 1.25;
}

.showers p,
.best-grid p {
  color: var(--muted-strong);
  font-size: 14px;
  line-height: 1.45;
}

.week-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.week-row {
  display: grid;
  grid-template-columns: 118px minmax(0, 1fr) 62px;
  align-items: center;
  gap: 10px;
  min-height: 54px;
  padding: 10px 12px;
}

.week-meter {
  overflow: hidden;
  height: 9px;
  border-radius: 999px;
  background: #0a1015;
}

.week-meter i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--coral), var(--amber), var(--green));
  box-shadow: 0 0 14px rgba(101, 214, 197, 0.24);
  transition: width 380ms ease;
}

.automation-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr)) minmax(220px, 1.2fr) auto;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
}

.toggle-row,
.threshold-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 50px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  color: var(--text);
}

.toggle-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--teal);
}

.threshold-row {
  display: grid;
  grid-template-columns: auto minmax(80px, 1fr) 40px;
}

.threshold-row input {
  width: 100%;
  height: auto;
  accent-color: var(--teal);
}

.threshold-row span {
  color: var(--muted);
  font-size: 13px;
}

.level-high {
  color: var(--green);
}

.level-medium {
  color: var(--amber);
}

.level-low {
  color: var(--coral);
}

@keyframes signalPulse {
  0%,
  100% {
    text-shadow: 0 0 0 rgba(101, 214, 197, 0);
  }

  50% {
    text-shadow: 0 0 22px rgba(101, 214, 197, 0.32);
  }
}

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

@media (max-width: 820px) {
  .app-shell {
    width: calc(100% - 16px);
    padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  }

  .control-strip,
  .today-panel,
  .metrics,
  .insight-grid,
  .showers,
  .best-grid,
  .week-row,
  .automation-grid {
    grid-template-columns: 1fr;
  }

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

  .location-row {
    grid-template-columns: 1fr;
  }

  .location-row button,
  .ghost-button,
  .automation-grid button {
    width: 100%;
  }

  .earth-panel {
    min-height: 520px;
  }

  #orbitCanvas {
    max-width: 100%;
    height: 520px;
  }

  .stage-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .space-clock {
    width: max-content;
    max-width: 100%;
  }

  .signal-card {
    bottom: 70px;
  }

  .earth-caption {
    left: 14px;
    right: 14px;
    max-width: none;
  }

  .signal-card strong {
    font-size: 48px;
  }

  .threshold-row {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .topbar {
    gap: 10px;
  }

  .icon-button {
    flex-basis: 54px;
    width: 54px;
    height: 40px;
    font-size: 12px;
  }

  .quick-menu {
    gap: 6px;
  }

  .control-strip,
  .today-panel,
  .automation-panel,
  .week-panel,
  .timeline,
  .orbit-note {
    padding: 12px;
  }
}

@media (max-width: 420px) {
  h1 {
    font-size: 24px;
  }

  h2 {
    font-size: 18px;
  }

  .brand-mark {
    width: 38px;
    height: 38px;
  }

  .earth-panel {
    min-height: 500px;
  }

  #orbitCanvas {
    height: 500px;
  }

  .signal-card {
    width: calc(100% - 28px);
  }
}
