body {
  background-color: #071118;
  color: #ffffff;
  font-family: monospace;
  margin: 0;

  touch-action: none;
  -webkit-touch-callout: none; /* iOS Safari */
  -webkit-user-select: none; /* Safari */
  -khtml-user-select: none; /* Konqueror HTML */
  -moz-user-select: none; /* Old versions of Firefox */
  -ms-user-select: none; /* Internet Explorer/Edge */
  user-select: none; /* Non-prefixed version, currently supported by Chrome, Edge, Opera and Firefox */
}

.viewer-loader {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 20% 20%, rgba(26, 79, 108, 0.28), transparent 34%),
    radial-gradient(circle at 80% 22%, rgba(10, 180, 160, 0.14), transparent 28%),
    linear-gradient(180deg, rgba(2, 8, 15, 0.95), rgba(5, 14, 24, 0.98));
  transition: opacity 260ms ease, visibility 260ms ease;
}

.viewer-loader.is-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.viewer-loader-card {
  width: min(560px, calc(100vw - 32px));
  padding: 24px;
  border: 1px solid rgba(112, 231, 255, 0.24);
  border-radius: 18px;
  background: rgba(5, 13, 24, 0.9);
  box-shadow: 0 26px 80px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(12px);
}

.viewer-loader-kicker {
  margin-bottom: 8px;
  color: #76e9dc;
  font-size: 12px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.viewer-loader-title {
  margin-bottom: 10px;
  color: #f3fdff;
  font-size: 28px;
  font-weight: 700;
  line-height: 1.1;
}

.viewer-loader-message {
  margin-bottom: 16px;
  color: #cbe9f2;
  font-size: 14px;
  line-height: 1.5;
}

.viewer-loader-progress {
  overflow: hidden;
  height: 10px;
  margin-bottom: 12px;
  border-radius: 999px;
  background: rgba(120, 168, 190, 0.18);
}

.viewer-loader-bar {
  width: 12%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #0bc7b6, #68f4ff);
  box-shadow: 0 0 24px rgba(104, 244, 255, 0.28);
  transition: width 280ms ease;
}

.viewer-loader-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  color: #9ec4d3;
  font-size: 12px;
}

.viewer-loader-note {
  margin: 0;
  color: #b8d6e2;
  font-size: 13px;
  line-height: 1.55;
}

.viewer-loader.is-error .viewer-loader-card {
  border-color: rgba(255, 105, 97, 0.38);
}

.viewer-loader.is-error .viewer-loader-kicker {
  color: #ff938b;
}

.viewer-loader.is-error .viewer-loader-bar {
  background: linear-gradient(90deg, #ff6a61, #ff9c7f);
  width: 100%;
}

a {
  color: #4599ff;
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.info {
  box-sizing: border-box;
  position: absolute;
  text-align: center;
  width: 100%;
}

.info.top {
  top: 0px;
}

.info.bottom {
  bottom: 0px;
}

.info .shadow {
  background-color: rgba(0, 0, 0, 0.5);
  display: inline-block;
  padding: 0.5rem 1rem;
}

.agent-panel {
  position: fixed;
  top: 10px;
  right: 10px;
  width: min(360px, calc(100vw - 300px));
  min-width: 300px;
  z-index: 120;
  box-sizing: border-box;
  padding: 12px;
  border: 1px solid rgba(112, 231, 255, 0.25);
  border-radius: 8px;
  background: rgba(4, 12, 22, 0.88);
  color: #e7fbff;
  backdrop-filter: blur(10px);
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.28);
}

.openenv-dock {
  position: fixed;
  right: 10px;
  bottom: 10px;
  width: min(380px, calc(100vw - 20px));
  z-index: 120;
  box-sizing: border-box;
  padding: 12px;
  border: 1px solid rgba(112, 231, 255, 0.22);
  border-radius: 8px;
  background: rgba(5, 13, 24, 0.9);
  color: #e7fbff;
  backdrop-filter: blur(10px);
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.28);
}

.openenv-heading {
  display: grid;
  gap: 3px;
  margin-bottom: 10px;
}

.openenv-title {
  font-size: 13px;
  font-weight: 700;
}

.openenv-subtitle,
.openenv-meta,
.openenv-field-label,
.openenv-label {
  color: #a8cbda;
  font-size: 11px;
}

.openenv-row {
  display: grid;
  gap: 6px;
  margin-bottom: 10px;
}

.openenv-select,
.openenv-input {
  min-height: 32px;
  border: 1px solid rgba(146, 215, 230, 0.28);
  border-radius: 6px;
  background: rgba(12, 31, 45, 0.96);
  color: #f1fbff;
  font: 12px monospace;
  padding: 0 10px;
  box-sizing: border-box;
}

.openenv-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}

.openenv-field {
  display: grid;
  gap: 5px;
}

.openenv-buttons {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}

.openenv-meta {
  margin-top: 10px;
}

.body-indicator {
  margin-top: 4px;
  padding: 4px 8px;
  border-radius: 6px;
  background: rgba(11, 199, 182, 0.10);
  border: 1px solid rgba(11, 199, 182, 0.35);
  color: #9ff6e6;
  font-size: 11px;
  letter-spacing: 0.3px;
}

.openenv-json {
  margin: 8px 0 0;
  max-height: 210px;
  overflow: auto;
  border-radius: 6px;
  border: 1px solid rgba(146, 215, 230, 0.18);
  background: rgba(7, 20, 30, 0.96);
  padding: 10px;
  color: #d6effa;
  font: 11px/1.45 monospace;
  white-space: pre-wrap;
  word-break: break-word;
}

.part-dock {
  position: fixed;
  left: 10px;
  bottom: 10px;
  width: min(260px, calc(100vw - 20px));
  z-index: 120;
  box-sizing: border-box;
  padding: 12px;
  border: 1px solid rgba(112, 231, 255, 0.22);
  border-radius: 8px;
  background: rgba(5, 13, 24, 0.9);
  color: #e7fbff;
  backdrop-filter: blur(10px);
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.28);
  display: grid;
  gap: 8px;
}

.part-heading {
  display: grid;
  gap: 3px;
}

.part-title {
  font-size: 13px;
  font-weight: 700;
}

.part-subtitle,
.part-meta {
  color: #a8cbda;
  font-size: 11px;
}

.agent-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.agent-title {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0;
}

.agent-status {
  color: #87f7e0;
  font-size: 11px;
}

.agent-controls {
  display: grid;
  grid-template-columns: 1fr 1fr auto auto;
  gap: 7px;
  margin-bottom: 10px;
}

.agent-select,
.agent-button {
  min-height: 32px;
  border: 1px solid rgba(146, 215, 230, 0.28);
  border-radius: 6px;
  background: rgba(12, 31, 45, 0.96);
  color: #f1fbff;
  font: 12px monospace;
}

.agent-button {
  padding: 0 10px;
  cursor: pointer;
}

.agent-button.primary {
  background: #0bc7b6;
  border-color: #65fff0;
  color: #061012;
  font-weight: 700;
}

.agent-button:disabled,
.agent-select:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.phase-pill {
  margin-bottom: 8px;
  padding: 6px 8px;
  border-radius: 6px;
  background: rgba(14, 41, 58, 0.9);
  color: #bcecff;
  font-size: 11px;
}

.action-line,
.runtime-line,
.rationale-line,
.score-line {
  color: #e8fbff;
  font-size: 11px;
  line-height: 1.45;
}

.runtime-line {
  color: #83f3d8;
  margin-top: 6px;
}

.rationale-line {
  margin-top: 6px;
  margin-bottom: 4px;
  color: #bfd6e7;
  min-height: 32px;
}

.signal-panel {
  display: grid;
  gap: 7px;
  margin: 10px 0;
}

.signal-row {
  display: grid;
  grid-template-columns: 58px 1fr 38px;
  align-items: center;
  gap: 8px;
  font-size: 11px;
}

.signal-label {
  color: #b9dce8;
}

.signal-track {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
}

.signal-fill {
  display: block;
  width: 100%;
  height: 100%;
  transform: scaleX(0.02);
  transform-origin: left center;
  transition: transform 180ms ease;
}

.signal-value {
  text-align: right;
  color: #ffffff;
}

.event-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin: 0 0 8px 0;
  min-height: 22px;
}

.event-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 10.5px;
  letter-spacing: 0.4px;
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.04);
  color: #d6effa;
  white-space: nowrap;
  cursor: help;
  animation: event-chip-pulse 1.4s ease-out;
}

.event-chip-icon {
  font-size: 11px;
  line-height: 1;
}

.event-chip-quiet {
  border-color: rgba(146, 215, 230, 0.18);
  color: rgba(168, 203, 218, 0.55);
  background: transparent;
  animation: none;
  cursor: default;
}

.event-chip-info {
  border-color: rgba(105, 167, 255, 0.55);
  background: rgba(105, 167, 255, 0.12);
  color: #c3dcff;
}

.event-chip-warn {
  border-color: rgba(255, 176, 46, 0.65);
  background: rgba(255, 176, 46, 0.14);
  color: #ffd58a;
  box-shadow: 0 0 12px rgba(255, 176, 46, 0.18);
}

.event-chip-crisis {
  border-color: rgba(255, 77, 61, 0.7);
  background: rgba(255, 77, 61, 0.16);
  color: #ffb1a4;
  box-shadow: 0 0 14px rgba(255, 77, 61, 0.25);
}

.tour-overlay {
  position: fixed;
  inset: 0;
  z-index: 1500;
  background: rgba(2, 8, 16, 0.62);
  backdrop-filter: blur(2px);
  pointer-events: auto;
}

.tour-spotlight {
  position: absolute;
  border-radius: 14px;
  border: 2px solid rgba(104, 244, 255, 0.9);
  box-shadow:
    0 0 0 9999px rgba(2, 8, 16, 0.55),
    0 0 38px rgba(104, 244, 255, 0.55);
  pointer-events: none;
  transition: left 220ms ease, top 220ms ease, width 220ms ease, height 220ms ease;
}

.tour-popup {
  position: absolute;
  width: 320px;
  padding: 16px 18px 14px;
  border-radius: 12px;
  border: 1px solid rgba(112, 231, 255, 0.45);
  background: rgba(7, 18, 30, 0.97);
  color: #e7fbff;
  box-shadow: 0 22px 60px rgba(0, 0, 0, 0.55);
  font-family: monospace;
  z-index: 1501;
}

.tour-kicker {
  font-size: 10.5px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: #76e9dc;
  margin-bottom: 6px;
}

.tour-title {
  font-size: 15px;
  font-weight: 700;
  color: #f3fdff;
  margin-bottom: 8px;
}

.tour-body {
  font-size: 12.5px;
  line-height: 1.55;
  color: #cbe9f2;
  margin-bottom: 12px;
}

.tour-actions {
  display: flex;
  justify-content: flex-end;
  gap: 7px;
}

.tour-btn {
  min-height: 30px;
  padding: 0 12px;
  border-radius: 6px;
  border: 1px solid rgba(146, 215, 230, 0.35);
  background: rgba(12, 31, 45, 0.8);
  color: #e7fbff;
  font: 12px monospace;
  cursor: pointer;
}

.tour-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.tour-btn-primary {
  background: #0bc7b6;
  border-color: #65fff0;
  color: #061012;
  font-weight: 700;
}

.tour-btn-ghost {
  background: transparent;
}

.tour-help-btn {
  position: fixed;
  left: 14px;
  bottom: 14px;
  z-index: 130;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid rgba(112, 231, 255, 0.45);
  background: rgba(7, 18, 30, 0.85);
  color: #9ff6e6;
  font: 11px monospace;
  letter-spacing: 0.6px;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
}

.tour-help-btn:hover {
  border-color: #65fff0;
  color: #f1fbff;
}

@keyframes event-chip-pulse {
  0% { transform: scale(0.85); opacity: 0; }
  60% { transform: scale(1.06); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

@media (max-width: 760px) {
  .agent-panel {
    top: auto;
    right: 8px;
    bottom: 8px;
    left: 8px;
    width: auto;
    min-width: 0;
  }

  .agent-controls {
    grid-template-columns: 1fr 1fr;
  }

  .openenv-dock {
    right: 8px;
    bottom: 8px;
    left: 8px;
    width: auto;
  }

  .part-dock {
    right: 8px;
    bottom: 280px;
    left: 8px;
    width: auto;
  }

  .openenv-grid,
  .openenv-buttons {
    grid-template-columns: 1fr 1fr;
  }
}

/* Brain panel grew to ~340px wide with EEG + pathway diagram below it.
 * On narrow viewports, the agent panel and brain panel both anchor to the
 * top edges, so make sure the agent panel's right anchor still leaves clear
 * horizontal space for the larger brain card on the left. */
@media (max-width: 1100px) {
  .agent-panel {
    width: min(330px, calc(100vw - 360px));
  }
}

@media (max-width: 640px) {
  .viewer-loader-card {
    padding: 18px;
    border-radius: 14px;
  }

  .viewer-loader-title {
    font-size: 22px;
  }

  .viewer-loader-meta {
    flex-direction: column;
    gap: 6px;
  }
}
