:root {
  --background: #0B1210;
  --accent: #C4973A;
  --surface: #10231A;
  --text: #E8E4D9;
  --executing: #3FA34D;
  --verifying: #D9A441;
  --alert: #C1443C;
  --border-muted: rgba(196, 151, 58, 0.32);
  --grid: rgba(196, 151, 58, 0.05);
  --dim: rgba(232, 228, 217, 0.56);
  --mono: "GeistMono", "Geist Mono", "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  --sans: "Geist", Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px),
    var(--background);
  background-size: 24px 24px;
  color: var(--text);
  font-family: var(--sans);
  letter-spacing: 0;
}

body {
  min-height: 100vh;
  overflow-x: hidden;
}

button,
input {
  font: inherit;
}

button {
  color: var(--text);
}

.mono {
  font-family: var(--mono);
}

.ops-shell {
  min-height: 100vh;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.top-bar,
.classification-strip,
.command-zone,
.stage-panel,
.log-panel,
.debrief-panel {
  border: 1px solid var(--border-muted);
  background: rgba(16, 35, 26, 0.92);
}

.top-bar {
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 0 18px;
}

.brand {
  font-weight: 700;
  font-size: clamp(1rem, 2.2vw, 1.35rem);
}

.top-metrics {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 14px;
  white-space: nowrap;
}

.deck-dashboard-button {
  min-height: 28px;
  display: inline-flex;
  align-items: center;
  padding: 0 9px;
  border: 1px solid rgba(196, 151, 58, 0.28);
  background: rgba(11, 18, 16, 0.28);
  color: rgba(232, 228, 217, 0.7);
  font-size: 0.68rem;
  font-weight: 800;
  text-decoration: none;
}

.deck-dashboard-button:hover,
.deck-dashboard-button:focus-visible {
  border-color: rgba(196, 151, 58, 0.62);
  color: var(--accent);
  outline: none;
}

.connection {
  font-family: var(--mono);
  font-weight: 700;
  color: var(--executing);
}

.connection.error {
  color: var(--alert);
}

.classification-strip {
  min-height: 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 0 18px;
  color: rgba(196, 151, 58, 0.72);
  font-size: 0.72rem;
  text-transform: uppercase;
}

.command-zone {
  padding: 16px;
}

.mission-form {
  display: grid;
  grid-template-columns: minmax(90px, 122px) minmax(0, 1fr) minmax(190px, 238px);
  gap: 12px;
  align-items: stretch;
}

.prompt-label {
  min-height: 46px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(196, 151, 58, 0.24);
  color: var(--accent);
  font-weight: 700;
}

.input-frame {
  min-width: 0;
  min-height: 46px;
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr) 14px;
  align-items: center;
  border: 1px solid rgba(196, 151, 58, 0.24);
  background: rgba(11, 18, 16, 0.72);
  padding: 0 12px;
}

.prompt-prefix {
  color: var(--accent);
  font-weight: 700;
}

#mission-input {
  width: 100%;
  min-width: 0;
  height: 100%;
  border: 0;
  outline: none;
  color: var(--text);
  background: transparent;
  caret-color: transparent;
  font-size: 0.98rem;
}

#mission-input::placeholder {
  color: rgba(232, 228, 217, 0.42);
}

.block-cursor {
  width: 10px;
  height: 18px;
  background: var(--accent);
  animation: cursor-blink 1s steps(2, start) infinite;
}

@keyframes cursor-blink {
  0%,
  45% {
    opacity: 1;
  }
  46%,
  100% {
    opacity: 0;
  }
}

#authorize-button,
.default-brief {
  border: 1px solid var(--accent);
  background: rgba(196, 151, 58, 0.12);
  font-weight: 800;
  cursor: pointer;
}

#authorize-button {
  min-height: 46px;
  padding: 0 14px;
}

#authorize-button:disabled {
  cursor: not-allowed;
  color: rgba(232, 228, 217, 0.42);
  border-color: rgba(196, 151, 58, 0.18);
  background: rgba(232, 228, 217, 0.05);
}

.default-brief {
  width: 100%;
  margin-top: 12px;
  padding: 10px 12px;
  color: rgba(232, 228, 217, 0.72);
  text-align: left;
  font-family: var(--mono);
  font-size: 0.82rem;
  line-height: 1.4;
  border-color: rgba(196, 151, 58, 0.2);
  background: rgba(11, 18, 16, 0.4);
}

.main-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 30vw);
  gap: 16px;
  min-height: 600px;
}

.stage-panel {
  min-width: 0;
  padding: 14px;
}

.stage-map {
  min-height: 570px;
  height: 100%;
  display: grid;
  grid-template-rows: auto 34px minmax(160px, 1fr) 34px auto;
  align-content: center;
  gap: 10px;
  padding: 28px;
  overflow: hidden;
  background: rgba(11, 18, 16, 0.28);
}

.flow-line {
  width: 1px;
  justify-self: center;
  background: linear-gradient(to bottom, rgba(196, 151, 58, 0.82), rgba(196, 151, 58, 0.14));
  transform-origin: top;
  transform: scaleY(0);
}

.flow-line.drawn {
  animation: draw-flow 360ms ease-out forwards;
}

@keyframes draw-flow {
  to {
    transform: scaleY(1);
  }
}

.node {
  width: min(280px, 100%);
  min-height: 104px;
  display: grid;
  align-content: center;
  gap: 7px;
  padding: 14px;
  border: 1px solid rgba(232, 228, 217, 0.22);
  background: rgba(11, 18, 16, 0.84);
  cursor: pointer;
  transition: border-color 160ms ease-out, background-color 160ms ease-out, transform 160ms ease-out;
}

.node:hover,
.node:focus-visible {
  border-color: rgba(196, 151, 58, 0.78);
  background: rgba(16, 35, 26, 0.96);
  outline: none;
}

.node:active {
  transform: translateY(1px);
}

.node-command,
.node-overwatch {
  justify-self: center;
}

.node-overwatch {
  width: min(520px, 100%);
}

.node-title {
  font-weight: 800;
  font-size: clamp(1rem, 2vw, 1.32rem);
}

.node-role {
  min-height: 1.15rem;
  color: rgba(232, 228, 217, 0.72);
  font-size: 0.82rem;
  line-height: 1.25;
}

.node-state {
  font-size: 0.78rem;
  color: var(--dim);
}

.unit-grid {
  width: 100%;
  align-self: center;
  display: grid;
  grid-template-columns: repeat(var(--unit-count, 2), minmax(0, 1fr));
  gap: 12px;
}

.unit-grid:empty {
  min-height: 124px;
  border: 1px dashed rgba(232, 228, 217, 0.16);
}

.unit-node {
  width: 100%;
}

.node[data-state="executing"] {
  border-color: var(--executing);
  animation: pulse-executing 1.3s ease-in-out infinite;
}

.node[data-state="verifying"] {
  border-color: var(--verifying);
  animation: pulse-verifying 1.3s ease-in-out infinite;
}

.node[data-state="challenged"] {
  border-color: var(--alert);
  animation: pulse-challenge 620ms ease-in-out infinite;
}

.node[data-state="complete"] {
  border-color: var(--accent);
}

.node[data-state="executing"] .node-state {
  color: var(--executing);
}

.node[data-state="verifying"] .node-state {
  color: var(--verifying);
}

.node[data-state="challenged"] .node-state {
  color: var(--alert);
}

.node[data-state="complete"] .node-state {
  color: var(--accent);
}

@keyframes pulse-executing {
  50% {
    border-color: rgba(63, 163, 77, 0.48);
  }
}

@keyframes pulse-verifying {
  50% {
    border-color: rgba(217, 164, 65, 0.48);
  }
}

@keyframes pulse-challenge {
  50% {
    border-color: rgba(193, 68, 60, 0.42);
  }
}

.log-panel,
.debrief-panel {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.panel-header {
  min-height: 42px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 12px;
  border-bottom: 1px solid var(--border-muted);
  color: var(--accent);
  font-weight: 800;
}

.panel-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.view-toggle,
.detail-close {
  min-height: 28px;
  border: 1px solid rgba(196, 151, 58, 0.34);
  background: rgba(11, 18, 16, 0.44);
  color: rgba(232, 228, 217, 0.7);
  font-family: var(--mono);
  font-size: 0.68rem;
  font-weight: 800;
  cursor: pointer;
}

.view-toggle {
  padding: 0 9px;
}

.view-toggle[aria-pressed="true"] {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(196, 151, 58, 0.12);
}

.narration-frame {
  border-bottom: 1px solid rgba(196, 151, 58, 0.22);
  padding: 14px 12px;
  background: rgba(11, 18, 16, 0.42);
}

.narration-label {
  margin-bottom: 7px;
  color: rgba(196, 151, 58, 0.76);
  font-size: 0.7rem;
}

.narration-text {
  min-height: 3.1rem;
  color: var(--text);
  font-weight: 700;
  font-size: clamp(1rem, 1.7vw, 1.24rem);
  line-height: 1.35;
}

.operational-feed,
.ops-log {
  height: 452px;
  overflow-y: auto;
}

.operational-feed {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.operational-line {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  padding: 10px;
  border: 1px solid rgba(232, 228, 217, 0.14);
  background: rgba(11, 18, 16, 0.38);
}

.operational-icon {
  min-height: 32px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(196, 151, 58, 0.32);
  color: var(--accent);
  font-size: 0.66rem;
  font-weight: 900;
}

.operational-copy {
  min-width: 0;
  display: grid;
  gap: 5px;
}

.operational-agent {
  color: rgba(196, 151, 58, 0.72);
  font-size: 0.68rem;
  font-weight: 800;
}

.operational-message {
  color: var(--text);
  font-size: clamp(0.98rem, 1.5vw, 1.18rem);
  font-weight: 700;
  line-height: 1.32;
  overflow-wrap: anywhere;
}

.operational-line[data-status="executing"] .operational-icon {
  color: var(--executing);
  border-color: rgba(63, 163, 77, 0.5);
}

.operational-line[data-status="verifying"] .operational-icon {
  color: var(--verifying);
  border-color: rgba(217, 164, 65, 0.5);
}

.operational-line[data-status="challenged"] .operational-icon,
.operational-line[data-status="failed"] .operational-icon {
  color: var(--alert);
  border-color: rgba(193, 68, 60, 0.58);
}

.ops-log {
  padding: 12px;
  font-size: 0.78rem;
  line-height: 1.48;
}

.log-line {
  min-height: 1.48em;
  color: rgba(232, 228, 217, 0.82);
  overflow-wrap: anywhere;
}

.log-line + .log-line {
  margin-top: 7px;
}

.log-line[data-status="executing"] {
  color: var(--executing);
}

.log-line[data-status="verifying"] {
  color: var(--verifying);
}

.log-line[data-status="challenged"],
.log-line[data-status="failed"] {
  color: var(--alert);
}

.log-line[data-status="complete"] {
  color: var(--text);
}

.debrief-panel {
  min-height: 220px;
}

.debrief-text {
  padding: 16px;
  display: grid;
  gap: 14px;
}

.debrief-fallback {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 0.9rem;
  line-height: 1.5;
}

.debrief-block,
.debrief-unit {
  border: 1px solid rgba(232, 228, 217, 0.14);
  background: rgba(11, 18, 16, 0.38);
  padding: 12px;
}

.debrief-final-plan,
.debrief-unit {
  display: grid;
  gap: 12px;
}

.debrief-final-plan {
  border: 1px solid rgba(196, 151, 58, 0.48);
  background: rgba(196, 151, 58, 0.08);
  padding: 14px;
}

.debrief-final-plan h3,
.debrief-unit h3 {
  margin: 0;
  color: var(--accent);
  font-size: 0.98rem;
}

.debrief-final-plan h3 {
  font-size: 1.08rem;
}

.debrief-final-plan .structured-list dd {
  color: var(--text);
  font-size: 0.98rem;
}

.detail-label {
  margin-bottom: 6px;
  color: rgba(196, 151, 58, 0.76);
  font-size: 0.68rem;
  font-weight: 800;
}

.detail-value {
  color: rgba(232, 228, 217, 0.84);
  font-size: 0.92rem;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.structured-list {
  margin: 0;
  display: grid;
  gap: 8px;
}

.structured-list dt {
  color: var(--accent);
  font-family: var(--mono);
  font-size: 0.72rem;
  font-weight: 800;
}

.structured-list dd {
  margin: 0 0 0 12px;
  color: rgba(232, 228, 217, 0.86);
  font-size: 0.92rem;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.agent-detail-panel {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 20;
  width: min(420px, 100vw);
  height: 100vh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  border-left: 1px solid var(--border-muted);
  background: rgba(11, 18, 16, 0.98);
  box-shadow: -18px 0 42px rgba(0, 0, 0, 0.36);
  transform: translateX(100%);
  transition: transform 250ms ease-out;
}

.agent-detail-panel.open {
  transform: translateX(0);
}

.detail-header {
  min-height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px;
  border-bottom: 1px solid var(--border-muted);
}

.detail-title {
  color: var(--accent);
  font-weight: 900;
  font-size: 1.05rem;
}

.detail-role {
  margin-top: 4px;
  color: rgba(232, 228, 217, 0.64);
  font-size: 0.82rem;
}

.detail-close {
  padding: 0 10px;
}

.detail-body {
  min-height: 0;
  overflow-y: auto;
  display: grid;
  align-content: start;
  gap: 12px;
  padding: 14px;
}

[hidden] {
  display: none !important;
}

@media (max-width: 1080px) {
  .main-grid {
    grid-template-columns: 1fr;
  }

  .ops-log {
    height: 320px;
  }

  .operational-feed {
    height: 320px;
  }
}

@media (max-width: 940px) {
  .top-bar,
  .top-metrics,
  .classification-strip {
    align-items: flex-start;
    flex-direction: column;
  }

  .top-bar {
    padding: 14px;
  }

  .mission-form {
    grid-template-columns: 1fr;
  }

  .panel-header,
  .panel-actions {
    align-items: flex-start;
    flex-direction: column;
  }

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

@media (max-width: 620px) {
  .ops-shell {
    padding: 10px;
  }

  .stage-map {
    min-height: 560px;
    padding: 18px;
  }

  .unit-grid {
    grid-template-columns: 1fr;
  }

  .node {
    width: 100%;
    min-height: 92px;
    padding: 10px;
  }

  .node-title {
    font-size: 0.98rem;
  }
}
