:root {
  color-scheme: dark;
  --bg: #06101d;
  --panel: rgba(9, 20, 36, 0.84);
  --panel-border: rgba(120, 157, 211, 0.18);
  --text: #ebf3ff;
  --muted: #9db0ca;
  --accent: #73bfff;
  --accent-2: #8cffc8;
  --user: #ffbe6b;
  --danger: #ff8d8d;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html { height: 100%; }

body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at 18% 18%, rgba(115, 191, 255, 0.11), transparent 25%),
    radial-gradient(circle at 78% 14%, rgba(140, 255, 200, 0.07), transparent 20%),
    linear-gradient(180deg, #040b14 0%, #081426 100%);
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow: hidden;
}

button { font: inherit; }

.app-shell {
  width: 100%;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding:
    calc(18px + var(--safe-top))
    calc(18px + var(--safe-right))
    calc(18px + var(--safe-bottom))
    calc(18px + var(--safe-left));
  gap: 16px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  padding: 18px 22px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 20px;
  backdrop-filter: blur(14px);
}

.title-wrap h1 {
  margin: 0;
  font-size: clamp(24px, 3vw, 30px);
  line-height: 1.05;
}

.title-wrap p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: clamp(13px, 2vw, 16px);
  max-width: 58ch;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 14px;
}

.status-stack {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 13px;
  border-radius: 999px;
  font-size: 14px;
  white-space: nowrap;
  background: rgba(115, 191, 255, 0.12);
  border: 1px solid rgba(115, 191, 255, 0.28);
}

.last-update {
  color: var(--muted);
  font-size: 13px;
}

.primary-btn,
.ghost-btn {
  border: 1px solid rgba(115, 191, 255, 0.26);
  color: var(--text);
  border-radius: 999px;
  cursor: pointer;
  transition: transform 0.16s ease, border-color 0.16s ease, background 0.16s ease;
}

.primary-btn:hover,
.ghost-btn:hover,
.primary-btn:active,
.ghost-btn:active {
  transform: translateY(-1px);
  border-color: rgba(115, 191, 255, 0.45);
}

.primary-btn {
  padding: 11px 16px;
  background: linear-gradient(180deg, rgba(23, 60, 102, 0.95), rgba(14, 39, 68, 0.95));
}

.ghost-btn {
  padding: 10px 14px;
  background: rgba(5, 12, 22, 0.72);
  backdrop-filter: blur(10px);
}

.main-content {
  min-height: 0;
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 16px;
}

.globe-section,
.panel-card {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 22px;
  backdrop-filter: blur(14px);
}

.globe-section {
  position: relative;
  overflow: hidden;
  min-height: 0;
}

#globeViz {
  width: 100%;
  height: 100%;
  min-height: 460px;
  touch-action: manipulation;
}

.floating-actions {
  position: absolute;
  top: 16px;
  right: 16px;
  display: flex;
  gap: 10px;
  z-index: 4;
}

.legend {
  position: absolute;
  left: 16px;
  bottom: 16px;
  z-index: 4;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(4, 10, 18, 0.68);
  border: 1px solid rgba(120, 157, 211, 0.15);
  color: var(--muted);
  font-size: 13px;
  max-width: calc(100% - 32px);
}

.dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 999px;
  margin-right: 8px;
}

.dot-iss { background: var(--accent-2); box-shadow: 0 0 12px rgba(140,255,200,0.75); }
.dot-user { background: var(--user); box-shadow: 0 0 12px rgba(255,190,107,0.75); }
.dot-path { background: var(--accent); box-shadow: 0 0 12px rgba(115,191,255,0.75); }

.side-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 0;
}

.panel-card { padding: 18px; }

.panel-card h2 {
  margin: 0 0 14px;
  font-size: 18px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.stats-grid > div {
  padding: 14px;
  border-radius: 16px;
  background: rgba(4, 10, 18, 0.48);
  border: 1px solid rgba(120, 157, 211, 0.12);
}

.label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.stats-grid strong { font-size: 21px; }

.hint {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.info-card {
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.event-log {
  min-height: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.log-item {
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(4, 10, 18, 0.48);
  border: 1px solid rgba(120, 157, 211, 0.12);
  color: var(--muted);
  line-height: 1.45;
}

@media (max-width: 1020px) {
  body { overflow: auto; }
  .main-content { grid-template-columns: 1fr; }
  .side-panel {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: start;
  }
  .info-card { grid-column: 1 / -1; min-height: 260px; }
}

@media (max-width: 720px) {
  body { overflow: auto; }
  .app-shell {
    padding:
      calc(10px + var(--safe-top))
      calc(10px + var(--safe-right))
      calc(10px + var(--safe-bottom))
      calc(10px + var(--safe-left));
    gap: 10px;
  }
  .topbar {
    padding: 14px;
    border-radius: 16px;
    flex-direction: column;
    align-items: flex-start;
  }
  .topbar-actions {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
  }
  .status-stack { align-items: flex-start; }
  .main-content { display: block; }
  .globe-section { min-height: 58dvh; border-radius: 18px; }
  #globeViz { min-height: 58dvh; }
  .floating-actions {
    top: 12px;
    left: 12px;
    right: 12px;
    justify-content: space-between;
    gap: 8px;
  }
  .legend {
    left: 10px;
    right: 10px;
    bottom: 10px;
    max-width: none;
    font-size: 12px;
    gap: 10px;
  }
  .side-panel {
    margin-top: 10px;
    grid-template-columns: 1fr;
  }
}
