:root {
  --bg: #05070d;
  --bg-deep: #02040a;
  --panel: rgba(15, 20, 35, 0.85);
  --panel-strong: rgba(13, 18, 31, 0.94);
  --panel-border: rgba(139, 169, 210, 0.18);
  --panel-border-strong: rgba(139, 169, 210, 0.3);
  --text: #eef4ff;
  --muted: #9bacbf;
  --faint: #6d7d91;
  --accent: #7fb6ff;
  --accent-soft: rgba(127, 182, 255, 0.16);
  --accent-2: #ffcf70;
  --danger: #ff746c;
  --ok: #82e0b7;
  --shadow: 0 18px 60px rgba(0, 0, 0, 0.5);
  --radius-lg: 22px;
  --radius-md: 15px;
  --radius-sm: 10px;
  --font-sans: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior: none;
}

body {
  overflow: hidden;
  background:
    radial-gradient(ellipse at 50% -20%, rgba(45, 78, 130, 0.16), transparent 55%),
    var(--bg);
}

button, input { font: inherit; }
button { color: inherit; }
button, a, input { -webkit-tap-highlight-color: transparent; }
button:focus-visible, input:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}
::selection { background: rgba(127, 182, 255, 0.3); }

.skip-link {
  position: fixed;
  top: 8px;
  left: 8px;
  z-index: 500;
  padding: 10px 14px;
  background: var(--panel-strong);
  color: var(--text);
  border-radius: 8px;
  transform: translateY(-160%);
  transition: transform 0.2s ease;
}
.skip-link:focus { transform: translateY(0); }

/* ----------------------------- Gate ----------------------------- */
.gate {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: grid;
  place-items: center;
  padding: calc(var(--safe-top) + 20px) 18px calc(var(--safe-bottom) + 20px);
  overflow: auto;
  background: #03050a;
}
.gate-backdrop {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 18% 12%, rgba(62, 112, 196, 0.22), transparent 34%),
    radial-gradient(circle at 82% 78%, rgba(180, 112, 48, 0.12), transparent 38%),
    radial-gradient(circle at 50% 50%, rgba(8, 16, 32, 0.9), #02040a 70%);
}
.gate-backdrop::after {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.38;
  background-image:
    radial-gradient(1.2px 1.2px at 8% 18%, #c9dcff 45%, transparent 55%),
    radial-gradient(1px 1px at 22% 72%, #9fc4ef 45%, transparent 55%),
    radial-gradient(1.4px 1.4px at 34% 28%, #ffe3ae 45%, transparent 55%),
    radial-gradient(1px 1px at 48% 82%, #bcd4ff 45%, transparent 55%),
    radial-gradient(1.5px 1.5px at 58% 16%, #ffffff 45%, transparent 55%),
    radial-gradient(1px 1px at 68% 62%, #b9d2ff 45%, transparent 55%),
    radial-gradient(1.2px 1.2px at 78% 34%, #ffe0a3 45%, transparent 55%),
    radial-gradient(1px 1px at 88% 78%, #d8e6ff 45%, transparent 55%),
    radial-gradient(1px 1px at 14% 88%, #a8c8ff 45%, transparent 55%),
    radial-gradient(1.4px 1.4px at 92% 12%, #ffffff 45%, transparent 55%);
  background-size: 100% 100%;
}
.gate-card {
  position: relative;
  width: min(580px, 100%);
  background: linear-gradient(180deg, rgba(19, 26, 44, 0.96), rgba(10, 15, 26, 0.97));
  border: 1px solid rgba(151, 183, 228, 0.29);
  border-radius: 28px;
  padding: clamp(22px, 4vw, 36px);
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.7), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  animation: gateIn 0.45s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}
@keyframes gateIn {
  from { opacity: 0; transform: translateY(16px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.gate-eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 11px;
  border: 1px solid rgba(255, 196, 100, 0.28);
  border-radius: 999px;
  background: rgba(255, 180, 72, 0.08);
  color: #ffd68a;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.live-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #ffcf70;
  box-shadow: 0 0 0 4px rgba(255, 207, 112, 0.12);
}
.gate-icon { color: #9fc4ef; margin: 20px 0 12px; }
.gate-card h1 {
  margin: 0 0 12px;
  font-size: clamp(1.6rem, 5vw, 2.3rem);
  line-height: 1.08;
  letter-spacing: -0.035em;
  font-weight: 750;
}
.gate-lead {
  margin: 0 0 22px;
  color: #c3d0e2;
  font-size: 1rem;
  line-height: 1.55;
}
.gate-steps { display: grid; gap: 14px; margin-bottom: 24px; }
.gate-step { display: flex; gap: 13px; align-items: flex-start; }
.step-number {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: rgba(127, 182, 255, 0.14);
  border: 1px solid rgba(127, 182, 255, 0.36);
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
}
.gate-step > div > strong { display: block; font-size: 0.95rem; margin-bottom: 3px; }
.gate-step p strong { display: inline; font-size: inherit; margin: 0; color: var(--text); }
.gate-step p { margin: 0; color: var(--muted); font-size: 0.88rem; line-height: 1.45; }
.inline-menu {
  display: inline-grid;
  place-items: center;
  min-width: 24px;
  padding: 2px 6px;
  border: 1px solid var(--panel-border-strong);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  font-size: 12px;
}
.gate-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.gate-status { min-height: 18px; margin: 9px 0 0; color: var(--ok); font-size: 0.85rem; }
.gate-footnote { margin: 16px 0 0; color: var(--faint); font-size: 0.75rem; line-height: 1.5; }

/* ----------------------------- Buttons ----------------------------- */
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  padding: 0 16px;
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font-size: 0.88rem;
  font-weight: 650;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.16s ease, border-color 0.16s ease, transform 0.16s ease;
}
.button:hover { background: rgba(255, 255, 255, 0.08); }
.button:active { transform: scale(0.98); }
.button-primary {
  background: linear-gradient(135deg, #6faaff, #4a7fd4);
  border-color: rgba(160, 205, 255, 0.6);
  color: #06111f;
  box-shadow: 0 10px 24px rgba(61, 119, 210, 0.32);
}
.button-primary:hover { background: linear-gradient(135deg, #86bcff, #5c92e8); }
.button-secondary {
  background: rgba(127, 182, 255, 0.12);
  border-color: rgba(127, 182, 255, 0.36);
  color: #cfe5ff;
}
.button-quiet {
  background: transparent;
  border-color: transparent;
  color: var(--muted);
  font-weight: 550;
}
.button-quiet:hover { background: rgba(255, 255, 255, 0.05); color: var(--text); }
.icon-button {
  flex: 0 0 auto;
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--panel-border);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.045);
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}
.icon-button:hover { color: var(--text); background: rgba(255, 255, 255, 0.09); }
.mini-close {
  flex: 0 0 auto;
  width: 24px;
  height: 24px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
  font-size: 15px;
  cursor: pointer;
}

/* ----------------------------- App shell ----------------------------- */
.app { position: fixed; inset: 0; opacity: 0; transition: opacity 0.35s ease; }
body.app-ready .app { opacity: 1; }
body.gate-blocked .app { display: none; }
.scene { position: absolute; inset: 0; z-index: 0; background: var(--bg); }
.scene canvas { display: block; width: 100%; height: 100%; cursor: grab; }
.scene canvas:active { cursor: grabbing; }
.labels {
  position: absolute;
  inset: 0;
  z-index: 2;
  overflow: hidden;
  pointer-events: none;
}
.label {
  position: absolute;
  top: 0;
  left: 0;
  white-space: nowrap;
  padding: 2px 4px;
  border-radius: 4px;
  text-shadow: 0 1px 5px rgba(0, 0, 0, 0.95), 0 0 12px rgba(0, 0, 0, 0.65);
  will-change: transform;
}
.label-planet {
  color: #f6f2e8;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.015em;
}
.label-star {
  color: rgba(220, 233, 255, 0.9);
  font-size: 10.5px;
  font-weight: 500;
}
.label-constellation {
  color: rgba(159, 196, 239, 0.72);
  font-size: 10px;
  font-style: italic;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.label-transient {
  color: #ffcf70;
  font-size: 10.5px;
  font-weight: 650;
  letter-spacing: 0.02em;
}
.label-cardinal {
  color: #b9d5f3;
  font-size: 12px;
  font-weight: 750;
  letter-spacing: 0.14em;
  opacity: 0.9;
}

.loading {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 14px;
  background:
    radial-gradient(ellipse at 50% 35%, rgba(44, 77, 130, 0.18), transparent 48%),
    var(--bg);
  color: var(--muted);
  transition: opacity 0.3s ease;
}
body.app-ready .loading { opacity: 0; pointer-events: none; }
.loading-mark { color: var(--accent); animation: spin 4.5s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading p { margin: 0; font-size: 0.82rem; letter-spacing: 0.06em; }

.topbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: calc(var(--safe-top) + 14px) 18px 12px;
  background: linear-gradient(180deg, rgba(3, 5, 10, 0.78), rgba(3, 5, 10, 0.26) 72%, transparent);
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid rgba(127, 182, 255, 0.26);
  border-radius: 12px;
  background: rgba(15, 24, 42, 0.7);
  color: var(--accent);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}
.brand-copy { display: flex; flex-direction: column; min-width: 0; }
.brand-name {
  font-size: 12.5px;
  font-weight: 800;
  letter-spacing: 0.18em;
  color: #eaf2ff;
  white-space: nowrap;
}
.brand-tag {
  margin-top: 1px;
  font-size: 10px;
  letter-spacing: 0.08em;
  color: var(--faint);
  white-space: nowrap;
}
.top-actions { display: flex; align-items: center; gap: 8px; min-width: 0; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  max-width: 210px;
  padding: 0 12px;
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  background: var(--panel);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.18);
}
.chip svg { color: var(--accent); flex: 0 0 auto; }
.chip:hover { border-color: var(--panel-border-strong); background: rgba(21, 29, 49, 0.92); }
.chip.previewing {
  border-color: rgba(127, 182, 255, 0.34);
  color: var(--accent);
}
.chip.previewing svg { color: var(--accent); }
.chip span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#time-label { font-variant-numeric: tabular-nums; }

.sky-status {
  position: absolute;
  top: calc(var(--safe-top) + 70px);
  left: 18px;
  z-index: 9;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  border: 1px solid rgba(139, 169, 210, 0.14);
  border-radius: 999px;
  background: rgba(8, 12, 22, 0.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.015em;
  pointer-events: none;
}
.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 0 3px rgba(130, 224, 183, 0.13);
}
.sky-status.daylight .status-dot { background: var(--accent-2); box-shadow: 0 0 0 3px rgba(255, 207, 112, 0.15); }
.sky-status.twilight .status-dot { background: #8bb8e8; box-shadow: 0 0 0 3px rgba(139, 184, 232, 0.14); }

.sensor-hint {
  position: absolute;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 94px);
  z-index: 12;
  display: flex;
  align-items: center;
  gap: 10px;
  width: min(560px, calc(100% - 24px));
  transform: translateX(-50%);
  padding: 11px 14px;
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  background: var(--panel);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
  box-shadow: var(--shadow);
  transition: opacity 0.25s ease, transform 0.25s ease;
}
.sensor-hint strong { color: var(--text); font-weight: 700; }
.sensor-hint-icon { color: var(--accent); flex: 0 0 auto; }
.sensor-hint.dismissed { opacity: 0; transform: translateX(-50%) translateY(8px); pointer-events: none; }

.bottom-dock {
  position: absolute;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 14px);
  z-index: 14;
  display: flex;
  align-items: stretch;
  gap: 4px;
  padding: 6px;
  transform: translateX(-50%);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  background: var(--panel-strong);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.05);
}
.dock-button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-width: 66px;
  padding: 8px 9px 7px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.16s ease, color 0.16s ease;
}
.dock-button:hover { background: rgba(255, 255, 255, 0.055); color: var(--text); }
.dock-button[aria-pressed="true"] {
  background: var(--accent-soft);
  color: var(--accent);
}
.dock-icon { display: grid; place-items: center; }
.dock-label { font-size: 9.5px; font-weight: 650; letter-spacing: 0.02em; }
.dock-button[aria-pressed="true"] .dock-icon {
  filter: drop-shadow(0 0 7px rgba(127, 182, 255, 0.4));
}

/* ----------------------------- Object card ----------------------------- */
.info-card {
  position: absolute;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 94px);
  z-index: 20;
  width: min(460px, calc(100% - 24px));
  max-height: min(62vh, 540px);
  overflow: auto;
  transform: translateX(-50%);
  padding: 18px 18px 16px;
  border: 1px solid var(--panel-border-strong);
  border-radius: var(--radius-lg);
  background: linear-gradient(180deg, rgba(20, 28, 48, 0.96), rgba(10, 15, 26, 0.98));
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  animation: cardIn 0.22s cubic-bezier(0.2, 0.8, 0.2, 1);
}
@keyframes cardIn {
  from { opacity: 0; transform: translateX(-50%) translateY(14px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}
.sheet-handle {
  width: 34px;
  height: 4px;
  margin: -6px auto 12px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.14);
}
.info-close { position: absolute; top: 12px; right: 12px; }
.info-head { padding-right: 42px; }
.info-kind {
  display: inline-block;
  margin-bottom: 6px;
  padding: 3px 8px;
  border: 1px solid rgba(127, 182, 255, 0.28);
  border-radius: 999px;
  background: rgba(127, 182, 255, 0.1);
  color: var(--accent);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.13em;
}
.info-head h2 {
  margin: 0 0 2px;
  font-size: 1.55rem;
  letter-spacing: -0.025em;
  line-height: 1.05;
}
.info-head p { margin: 0; color: var(--muted); font-size: 0.82rem; }
.info-metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 16px 0 14px;
}
.metric {
  padding: 9px 10px;
  border: 1px solid rgba(139, 169, 210, 0.12);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.025);
}
.metric span {
  display: block;
  margin-bottom: 3px;
  color: var(--faint);
  font-size: 9px;
  font-weight: 650;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.metric strong {
  display: block;
  color: var(--text);
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
}
.metric-wide { grid-column: 1 / -1; }
.info-notes {
  margin: 0 0 16px;
  color: #bdcbdd;
  font-size: 0.86rem;
  line-height: 1.55;
}
.info-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ----------------------------- Toast ----------------------------- */
.toast {
  position: fixed;
  left: 50%;
  top: calc(var(--safe-top) + 74px);
  z-index: 60;
  max-width: min(520px, calc(100% - 32px));
  padding: 10px 14px;
  transform: translateX(-50%) translateY(8px);
  border: 1px solid var(--panel-border-strong);
  border-radius: 12px;
  background: var(--panel-strong);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: var(--text);
  font-size: 0.8rem;
  line-height: 1.4;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ----------------------------- Debug panel ----------------------------- */
.debug-panel {
  position: fixed;
  top: calc(var(--safe-top) + 82px);
  right: 14px;
  z-index: 25;
  width: min(340px, calc(100vw - 28px));
  max-height: calc(100vh - 190px);
  overflow: auto;
  padding: 16px;
  border: 1px solid var(--panel-border-strong);
  border-radius: 20px;
  background: rgba(9, 14, 25, 0.94);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
  animation: panelIn 0.2s ease;
}
@keyframes panelIn {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}
.panel-header { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; margin-bottom: 15px; }
.panel-eyebrow {
  display: block;
  margin-bottom: 3px;
  color: var(--accent);
  font-size: 9px;
  font-weight: 750;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}
.panel-header h2 { margin: 0; font-size: 1.08rem; letter-spacing: -0.01em; }
.debug-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px 12px; }
.debug-grid > div {
  min-width: 0;
  padding-bottom: 7px;
  border-bottom: 1px solid rgba(139, 169, 210, 0.09);
}
.debug-grid span {
  display: block;
  margin-bottom: 2px;
  color: var(--faint);
  font-size: 8.5px;
  font-weight: 650;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.debug-grid strong {
  display: block;
  overflow: hidden;
  color: #d7e6fa;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 550;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.debug-slider { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--panel-border); }
.debug-slider label {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.debug-slider label span { color: var(--accent); font-family: var(--font-mono); }
.debug-slider input[type="range"] { width: 100%; accent-color: var(--accent); }
.field-hint { margin: 6px 0 0; color: var(--faint); font-size: 9.5px; line-height: 1.45; }
.panel-actions { display: flex; gap: 6px; margin-top: 15px; }
.panel-actions .button { min-height: 35px; padding: 0 11px; font-size: 10px; }
.debug-note { margin: 12px 0 0; color: var(--faint); font-size: 9px; }
code { padding: 1px 4px; border-radius: 4px; background: rgba(255, 255, 255, 0.07); font-family: var(--font-mono); font-size: 0.92em; }

/* ----------------------------- Modals ----------------------------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: calc(var(--safe-top) + 16px) 14px calc(var(--safe-bottom) + 16px);
  overflow: auto;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(2, 4, 9, 0.72);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
}
.modal-card {
  position: relative;
  width: min(540px, 100%);
  max-height: calc(100vh - 32px);
  overflow: auto;
  padding: 24px;
  border: 1px solid var(--panel-border-strong);
  border-radius: 25px;
  background: linear-gradient(180deg, rgba(20, 28, 48, 0.98), rgba(9, 14, 25, 0.99));
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  animation: modalIn 0.22s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.modal-wide { width: min(640px, 100%); }
@keyframes modalIn {
  from { opacity: 0; transform: translateY(10px) scale(0.99); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.modal-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; margin-bottom: 8px; }
.modal-header h2 { margin: 0; font-size: 1.4rem; letter-spacing: -0.025em; }
.modal-lede { margin: 0 0 18px; color: var(--muted); font-size: 0.87rem; line-height: 1.55; }
.modal-footnote { margin: 14px 0 0; color: var(--faint); font-size: 0.75rem; line-height: 1.5; }

.gps-button {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 13px;
  margin-bottom: 18px;
  border: 1px solid rgba(127, 182, 255, 0.3);
  border-radius: 15px;
  background: rgba(127, 182, 255, 0.08);
  color: var(--text);
  text-align: left;
  cursor: pointer;
}
.gps-button:hover { background: rgba(127, 182, 255, 0.13); }
.gps-icon {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 11px;
  background: rgba(127, 182, 255, 0.12);
  color: var(--accent);
}
.gps-button strong { display: block; font-size: 0.9rem; }
.gps-button small { display: block; margin-top: 2px; color: var(--muted); font-size: 0.75rem; }

.city-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 20px;
}
.city-button {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 11px 12px;
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.035);
  color: var(--text);
  text-align: left;
  cursor: pointer;
}
.city-button:hover { border-color: var(--panel-border-strong); background: rgba(255, 255, 255, 0.065); }
.city-button strong { font-size: 0.86rem; }
.city-button small { color: var(--faint); font-size: 0.68rem; }

.custom-location { padding-top: 16px; border-top: 1px solid var(--panel-border); }
.custom-location h3 { margin: 0 0 10px; font-size: 0.8rem; letter-spacing: 0.07em; text-transform: uppercase; color: var(--muted); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 10px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field span { color: var(--faint); font-size: 0.7rem; font-weight: 650; letter-spacing: 0.06em; text-transform: uppercase; }
.field input {
  width: 100%;
  min-height: 40px;
  padding: 0 11px;
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.045);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.82rem;
}
.field input:focus { border-color: rgba(127, 182, 255, 0.5); background: rgba(255, 255, 255, 0.065); }

.time-presets { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; }
.time-chip {
  padding: 9px 14px;
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 650;
  cursor: pointer;
}
.time-chip:hover { color: var(--text); border-color: var(--panel-border-strong); }
.time-chip.active { background: var(--accent-soft); border-color: rgba(127, 182, 255, 0.4); color: var(--accent); }
.custom-time { display: flex; flex-direction: column; gap: 10px; padding-top: 16px; border-top: 1px solid var(--panel-border); }
.custom-time .button { align-self: flex-start; }

.search-field {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 0 12px;
  border: 1px solid var(--panel-border-strong);
  border-radius: 13px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--faint);
}
.search-field:focus-within { border-color: rgba(127, 182, 255, 0.55); background: rgba(255, 255, 255, 0.07); }
.search-field input {
  flex: 1;
  min-height: 45px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-size: 0.9rem;
}
.search-field input::placeholder { color: var(--faint); }
.search-results { margin: 12px 0 18px; display: grid; gap: 5px; min-height: 80px; }
.search-result {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 11px;
  border: 1px solid transparent;
  border-radius: 11px;
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}
.search-result:hover { background: rgba(255, 255, 255, 0.05); border-color: var(--panel-border); }
.result-icon {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: rgba(127, 182, 255, 0.1);
  color: var(--accent);
  font-size: 13px;
}
.result-copy { min-width: 0; flex: 1; }
.result-copy strong { display: block; overflow: hidden; font-size: 0.84rem; text-overflow: ellipsis; white-space: nowrap; }
.result-copy small { display: block; margin-top: 1px; color: var(--faint); font-size: 0.7rem; }
.result-meta { flex: 0 0 auto; color: var(--muted); font-family: var(--font-mono); font-size: 0.7rem; }
.search-empty { padding: 18px 4px; color: var(--faint); font-size: 0.82rem; text-align: center; }
.about-strip {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  justify-content: space-between;
  padding: 14px;
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.025);
}
.about-strip strong { font-size: 0.8rem; }
.about-strip p { margin: 4px 0 0; color: var(--faint); font-size: 0.72rem; line-height: 1.5; }
.about-strip .button { flex: 0 0 auto; min-height: 34px; padding: 0 10px; font-size: 0.72rem; }
.about-more { margin-top: 12px; padding: 14px; border-radius: 14px; background: rgba(127, 182, 255, 0.055); }
.about-more p { margin: 0 0 8px; color: var(--muted); font-size: 0.78rem; line-height: 1.55; }
.about-more p:last-child { margin-bottom: 0; }

/* ----------------------------- Fatal ----------------------------- */
.fatal {
  position: fixed;
  inset: 0;
  z-index: 400;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(2, 4, 9, 0.94);
}
.fatal-card {
  width: min(480px, 100%);
  padding: 26px;
  border: 1px solid var(--panel-border-strong);
  border-radius: 22px;
  background: var(--panel-strong);
  box-shadow: var(--shadow);
}
.fatal-card h2 { margin: 0 0 8px; font-size: 1.35rem; }
.fatal-card p { margin: 0 0 18px; color: var(--muted); font-size: 0.9rem; line-height: 1.55; }

/* ----------------------------- Red night mode ----------------------------- */
body.red-mode {
  --accent: #ff3b30;
  --accent-soft: rgba(255, 59, 48, 0.16);
  --accent-2: #ff8a64;
  --ok: #ff665c;
  --text: #ffe1dc;
  --muted: #c48f87;
  --faint: #8e5d57;
  --panel: rgba(30, 10, 10, 0.88);
  --panel-strong: rgba(26, 7, 7, 0.95);
  --panel-border: rgba(255, 90, 72, 0.2);
  --panel-border-strong: rgba(255, 90, 72, 0.34);
}
body.red-mode .brand-mark,
body.red-mode .chip svg,
body.red-mode .sensor-hint-icon,
body.red-mode .gps-icon,
body.red-mode .result-icon {
  color: #ff5a4a;
}
body.red-mode .label-star { color: rgba(255, 140, 125, 0.8); }
body.red-mode .label-constellation { color: rgba(255, 120, 105, 0.68); }
body.red-mode .label-planet { color: #ffd0c8; }
body.red-mode .label-cardinal { color: #ff8d7c; }
body.red-mode .label-transient { color: #ff7b63; }
body.red-mode .gate-card,
body.red-mode .modal-card,
body.red-mode .info-card { background: linear-gradient(180deg, rgba(33, 10, 10, 0.98), rgba(12, 4, 4, 0.99)); }
body.red-mode .status-dot { background: #ff5a4a; box-shadow: 0 0 0 3px rgba(255, 90, 74, 0.16); }
body.red-mode .button-primary {
  background: linear-gradient(135deg, #ff5c50, #b8241d);
  border-color: rgba(255, 130, 115, 0.55);
  color: #1d0504;
  box-shadow: 0 10px 24px rgba(180, 30, 20, 0.3);
}

/* ----------------------------- Responsive ----------------------------- */
@media (max-width: 700px) {
  .topbar { gap: 8px; padding: calc(var(--safe-top) + 10px) 12px 9px; }
  .brand-mark { width: 34px; height: 34px; }
  .brand-name { font-size: 11px; letter-spacing: 0.14em; }
  .brand-tag { display: none; }
  .top-actions { gap: 5px; }
  .chip { min-height: 33px; padding: 0 9px; font-size: 10.5px; max-width: 118px; }
  .chip svg { width: 13px; height: 13px; }
  .icon-button { width: 33px; height: 33px; }
  #time-label { letter-spacing: -0.01em; }
  .sky-status { left: 12px; top: calc(var(--safe-top) + 57px); padding: 6px 10px; font-size: 10px; }
  .bottom-dock { bottom: calc(var(--safe-bottom) + 10px); gap: 1px; padding: 5px; }
  .dock-button { min-width: 58px; padding: 7px 7px 6px; }
  .dock-label { font-size: 9px; }
  .sensor-hint { bottom: calc(var(--safe-bottom) + 86px); font-size: 11px; padding: 9px 11px; }
  .info-card { bottom: calc(var(--safe-bottom) + 86px); width: calc(100% - 16px); max-height: 58vh; }
  .info-metrics { grid-template-columns: repeat(3, 1fr); gap: 6px; }
  .metric { padding: 8px; }
  .metric strong { font-size: 0.82rem; }
  .toast { top: calc(var(--safe-top) + 100px); max-width: calc(100% - 24px); }
  .debug-panel { top: auto; left: 10px; right: 10px; bottom: calc(var(--safe-bottom) + 82px); width: auto; max-height: 58vh; }
  .modal { padding: calc(var(--safe-top) + 10px) 10px calc(var(--safe-bottom) + 10px); }
  .modal-card { padding: 19px; border-radius: 21px; }
  .city-grid { grid-template-columns: 1fr 1fr; }
  .field-row { gap: 8px; }
  .about-strip { flex-direction: column; }
  .gate-card { border-radius: 23px; padding: 22px; }
}

@media (max-width: 410px) {
  .brand-copy { display: none; }
  .chip { max-width: 104px; }
  .dock-button { min-width: 52px; }
  .dock-label { font-size: 8.5px; }
  .info-metrics { grid-template-columns: 1fr 1fr; }
  .metric-wide { grid-column: 1 / -1; }
}

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

.dock-button.connecting { color: var(--accent-2); }
.dock-button.connecting .dock-icon { animation: dockPulse 1.1s ease-in-out infinite; }
@keyframes dockPulse {
  0%, 100% { opacity: 0.55; transform: scale(0.94); }
  50% { opacity: 1; transform: scale(1.06); }
}
