html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #000;
  font-family: Arial, sans-serif;
  color: #eee;
}

#app-topbar {
  height: 52px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 0 14px;
  box-sizing: border-box;
  background: linear-gradient(180deg, rgba(18,27,41,0.98), rgba(11,19,31,0.98));
  border-bottom: 1px solid rgba(255,255,255,0.07);
  color: #eef5ff;
}

.app-topbar-left {
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 0;
}

.app-product-mark strong {
  display: block;
  font-size: 13px;
  color: #eef5ff;
}

.app-product-mark span {
  display: block;
  font-size: 11px;
  color: #8fb8ff;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.app-context {
  font-size: 12px;
  color: #bfd0e2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-sep {
  margin: 0 6px;
  color: #6f8dad;
}

.app-topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar-link {
  color: #dce9ff;
  text-decoration: none;
  font-size: 13px;
  font-weight: 700;
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(255,255,255,0.05);
}

.topbar-link:hover {
  background: rgba(255,255,255,0.10);
}

#app-shell {
  display: flex;
  width: 100vw;
  height: 100vh;
}

#viewer {
  position: relative;
  flex: 1;
  height: 100vh;
  overflow: hidden;
}

#viewer canvas,
body > canvas {
  display: block;
}

.mission-header-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.mission-header-actions a {
  display: inline-flex;
}

.mission-header-actions button {
  width: auto;           /* override global rule */
  padding: 8px 12px;
  font-size: 13px;
}

.field-label {
  display: block;
  margin: 10px 0 6px 0;
  font-size: 13px;
  color: #b9c6d3;
}

select,
button,
input[type="range"] {
  width: 100%;
  box-sizing: border-box;
}

select,
button {
  padding: 10px 12px;
  margin: 0;
  font-size: 14px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.08);
  background: #152235;
  color: #eee;
}

button {
  cursor: pointer;
  background: #1c314d;
}

button:hover {
  background: #24405f;
}

button:disabled {
  opacity: 0.5;
  cursor: default;
}

.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 8px;
}

.toggle-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
  font-size: 14px;
}

.control-block {
  margin-top: 14px;
}

.slider-row {
  display: grid;
  grid-template-columns: 1fr 56px;
  gap: 10px;
  align-items: center;
}

.metrics-panel {
  margin-top: 14px;
  background: rgba(0,80,0,0.28);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 14px;
  line-height: 1.6;
}

#sidebar {
  width: clamp(260px, 22vw, 420px);
  min-width: 260px;
  max-width: 420px;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
  background:
    radial-gradient(circle at top, rgba(70, 110, 170, 0.16), transparent 28%),
    linear-gradient(180deg, #08111c 0%, #0b1624 100%);
  border-right: 1px solid rgba(255,255,255,0.07);
  padding: 10px;
  box-sizing: border-box;
}

#sidebar-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding-right: 2px;
}

.sidebar-section {
  margin-bottom: 12px;
}

.sidebar-section h2,
.sidebar-section h3 {
  margin: 0 0 10px 0;
  font-size: 15px;
  font-weight: 700;
  color: #eef5ff;
  letter-spacing: 0.02em;
}

.control-card,
.info-card,
details {
  background: linear-gradient(180deg, rgba(22, 34, 53, 0.88), rgba(13, 22, 36, 0.92));
  border: 1px solid rgba(255,255,255,0.07);
  border-radius: 12px;
  padding: 10px 11px;
  box-shadow: 0 6px 18px rgba(0,0,0,0.18);
}

.control-card + .control-card,
.info-card + .info-card {
  margin-top: 8px;
}

.card-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #8fb8ff;
  font-weight: 700;
  margin-bottom: 8px;
}

.field-label {
  display: block;
  margin: 8px 0 4px 0;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #9db0c5;
}

select,
button,
input[type="number"] {
  width: 100%;
  box-sizing: border-box;
  padding: 9px 10px;
  font-size: 13px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.08);
  background: #152235;
  color: #eee;
}

button {
  cursor: pointer;
  background: linear-gradient(180deg, #1f3a5a, #182f49);
  font-weight: 600;
}

button:hover {
  background: linear-gradient(180deg, #28486d, #1d3957);
}

.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
  margin-top: 8px;
}

.button-row.single {
  grid-template-columns: 1fr;
}

.toggle-row.compact {
  gap: 6px;
  margin-top: 0;
  font-size: 13px;
}

.control-block.compact {
  margin-top: 10px;
}

.slider-row,
.input-row {
  display: grid;
  grid-template-columns: 1fr 44px;
  gap: 8px;
  align-items: center;
}

.input-suffix,
#hexOpacityValue {
  font-size: 12px;
  color: #b9c6d3;
  text-align: right;
}

.metrics-panel,
#hex-info-panel {
  margin-top: 0;
  background: transparent;
  padding: 0;
  border-radius: 0;
}

.info-stack {
  display: grid;
  gap: 8px;
}

.info-grid {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 5px 10px;
  font-size: 12px;
  line-height: 1.4;
}

.info-grid div:nth-child(odd) {
  color: #99aec5;
}

.info-grid div:nth-child(even) {
  color: #f1f6ff;
  text-align: right;
  font-weight: 600;
}

details summary {
  outline: none;
  font-size: 13px;
  color: #d7e7ff;
  font-weight: 600;
}

.faq-content {
  font-size: 12px;
  line-height: 1.45;
  color: #b9c6d3;
}

#status-box {
  flex: 0 0 auto;
  margin-top: 10px;
  padding: 10px 11px;
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(18, 27, 41, 0.96), rgba(11, 19, 31, 0.98));
  border: 1px solid rgba(110, 170, 255, 0.14);
  box-shadow: 0 6px 18px rgba(0,0,0,0.2);
}

.status-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #8fb8ff;
  margin-bottom: 6px;
  font-weight: 700;
}

#status {
  margin-top: 0;
  font-size: 12px;
  line-height: 1.35;
  color: #d5deea;
  white-space: pre-wrap;
  min-height: 18px;
}

.plot-popup {
  position: absolute;
  top: 20px;
  right: 20px;
  width: min(420px, calc(100vw - 60px));
  max-height: calc(100vh - 40px);
  background: rgba(10, 18, 30, 0.96);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 12px;
  z-index: 20;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
  overflow: hidden;
}

.plot-popup.hidden {
  display: none;
}

.popup-content {
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 40px);
}

.popup-content img {
  display: block;
  width: 100%;
  max-height: 60vh;
  object-fit: contain;
  background: #09111b;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.popup-info {
  padding: 10px;
  font-size: 13px;
  overflow-y: auto;
}

.popup {
  position: absolute;
  top: 20px;
  right: 20px;
  width: min(420px, calc(100vw - 60px));
  max-height: calc(100vh - 40px);
  background: rgba(10, 18, 30, 0.96);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 12px;
  z-index: 30;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
  overflow: hidden;
}

.popup.hidden {
  display: none;
}

.agent-hud {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 280px;
  max-height: 420px;
  overflow: auto;
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(10, 14, 20, 0.82);
  color: #eaf2ff;
  box-shadow: 0 10px 30px rgba(0,0,0,0.35);
  backdrop-filter: blur(8px);
  z-index: 20;
  font-size: 13px;
  line-height: 1.35;
}

.agent-hud-title {
  font-weight: 700;
  font-size: 14px;
  margin-bottom: 10px;
  letter-spacing: 0.02em;
}

.agent-card {
  padding: 8px 10px;
  margin-bottom: 8px;
  border-radius: 10px;
  background: rgba(255,255,255,0.05);
}

.agent-card:last-child {
  margin-bottom: 0;
}

.agent-name {
  font-weight: 700;
  margin-bottom: 4px;
}

.agent-meta {
  opacity: 0.92;
}

.agent-energy-bar {
  margin-top: 6px;
  height: 6px;
  border-radius: 999px;
  background: rgba(255,255,255,0.12);
  overflow: hidden;
}

.agent-energy-fill {
  height: 100%;
  border-radius: 999px;
  background: currentColor;
}

.agent-hud-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.agent-hud-close {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 8px;
  background: rgba(255,255,255,0.08);
  color: #eaf2ff;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}

.agent-hud-close:hover {
  background: rgba(255,255,255,0.14);
}

.ecosystem-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-top: 10px;
}

.ecosystem-link {
  text-decoration: none;
  color: inherit;
  display: block;
}

.ecosystem-link .flow-node {
  height: 60%;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

.ecosystem-link:hover .flow-node {
  transform: translateY(-2px);
  border-color: rgba(143,184,255,0.22);
  box-shadow: 0 10px 24px rgba(0,0,0,0.22);
}

@media (max-width: 1100px) {
  .ecosystem-grid {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 700px) {
  .ecosystem-grid {
    grid-template-columns: 1fr;
  }
}