:root {
  color-scheme: dark;
  --bg: #071018;
  --bg-deep: #040a10;
  --surface: rgba(13, 25, 35, 0.86);
  --surface-strong: #101f2b;
  --line: rgba(142, 181, 199, 0.17);
  --line-strong: rgba(125, 216, 205, 0.32);
  --text: #edf7f7;
  --muted: #8da7b1;
  --teal: #63dfcd;
  --teal-strong: #19b9a7;
  --blue: #68a7ff;
  --amber: #efc77d;
  --danger: #ff8d8d;
  --radius: 18px;
  --shadow: 0 22px 60px rgba(0, 0, 0, 0.24);
  --mono: "Cascadia Code", "SFMono-Regular", Consolas, monospace;
  --sans: Inter, "Segoe UI", "Microsoft YaHei UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg-deep);
  scroll-behavior: smooth;
}

body {
  min-width: 320px;
  margin: 0;
  background:
    linear-gradient(180deg, rgba(7, 16, 24, 0.86), var(--bg) 32rem),
    repeating-linear-gradient(90deg, transparent 0 79px, rgba(135, 200, 209, 0.025) 80px),
    repeating-linear-gradient(0deg, transparent 0 79px, rgba(135, 200, 209, 0.02) 80px);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
}

button,
input,
select {
  font: inherit;
}

button,
select {
  cursor: pointer;
}

.ambient {
  position: fixed;
  z-index: -1;
  border-radius: 50%;
  filter: blur(90px);
  pointer-events: none;
}

.ambient-one {
  width: 420px;
  height: 420px;
  top: -180px;
  right: 7vw;
  background: rgba(36, 155, 163, 0.12);
}

.ambient-two {
  width: 320px;
  height: 320px;
  top: 48rem;
  left: -180px;
  background: rgba(66, 108, 185, 0.1);
}

.topbar {
  position: sticky;
  z-index: 10;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 72px;
  padding: 0 max(24px, calc((100vw - 1320px) / 2));
  border-bottom: 1px solid var(--line);
  background: rgba(4, 10, 16, 0.8);
  backdrop-filter: blur(18px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: var(--text);
  text-decoration: none;
}

.brand-mark {
  position: relative;
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  transform: rotate(45deg);
}

.brand-mark i {
  position: absolute;
  width: 7px;
  height: 7px;
  border: 1px solid var(--teal);
  background: rgba(99, 223, 205, 0.12);
}

.brand-mark i:nth-child(1) { transform: translate(-8px, -8px); }
.brand-mark i:nth-child(2) { transform: translate(8px, -8px); }
.brand-mark i:nth-child(3) { transform: translate(-8px, 8px); }
.brand-mark i:nth-child(4) { transform: translate(8px, 8px); }

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  font-size: 16px;
  letter-spacing: 0.12em;
}

.brand small {
  margin-top: 1px;
  color: var(--muted);
  font-size: 9px;
  font-weight: 650;
  letter-spacing: 0.17em;
}

.topbar-actions,
.run-input-row,
.run-context,
.run-identity,
.panel-heading,
.section-heading-row,
.dialog-heading,
.solver-footnotes,
footer {
  display: flex;
  align-items: center;
}

.topbar-actions {
  gap: 12px;
}

.environment {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
}

.environment i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--teal);
  box-shadow: 0 0 12px rgba(99, 223, 205, 0.75);
}

.icon-button {
  display: inline-grid;
  width: 38px;
  height: 38px;
  padding: 0;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.025);
  color: var(--muted);
  transition: 160ms ease;
}

.icon-button:hover,
.icon-button:focus-visible {
  border-color: var(--line-strong);
  color: var(--teal);
}

.icon-button svg {
  width: 17px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.shell {
  width: min(1320px, calc(100% - 48px));
  margin: 0 auto;
}

.run-console {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(520px, 1.1fr);
  gap: 64px;
  align-items: end;
  min-height: 280px;
  padding: 58px 0 40px;
}

.console-copy h1 {
  max-width: 650px;
  margin: 0 0 15px;
  font-size: clamp(31px, 4vw, 50px);
  font-weight: 620;
  letter-spacing: -0.045em;
  line-height: 1.1;
}

.console-copy p {
  max-width: 620px;
  margin: 0;
  color: var(--muted);
  font-size: 15px;
}

.run-form label,
.section-label {
  color: var(--teal);
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

.run-form label {
  display: block;
  margin-bottom: 9px;
}

.run-input-row {
  gap: 10px;
}

.run-input-row input {
  min-width: 0;
  flex: 1;
  height: 50px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  outline: none;
  background: rgba(2, 8, 13, 0.68);
  color: var(--text);
  font-size: 13px;
  transition: 160ms ease;
}

.run-input-row input:focus {
  border-color: rgba(99, 223, 205, 0.52);
  box-shadow: 0 0 0 3px rgba(99, 223, 205, 0.08);
}

.primary-button {
  position: relative;
  height: 50px;
  min-width: 132px;
  padding: 0 20px;
  border: 0;
  border-radius: 12px;
  background: var(--teal);
  color: #05201c;
  font-size: 13px;
  font-weight: 750;
  transition: 160ms ease;
}

.primary-button:hover:not(:disabled) {
  background: #82ebdc;
  transform: translateY(-1px);
}

.primary-button:disabled {
  cursor: wait;
  opacity: 0.75;
}

.button-spinner {
  display: none;
  width: 17px;
  height: 17px;
  margin: auto;
  border: 2px solid rgba(5, 32, 28, 0.25);
  border-top-color: #05201c;
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

.primary-button.loading .button-label { display: none; }
.primary-button.loading .button-spinner { display: block; }

@keyframes spin { to { transform: rotate(360deg); } }

.form-status {
  min-height: 20px;
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 11px;
}

.form-status.error { color: var(--danger); }

.run-context {
  justify-content: space-between;
  min-height: 66px;
  padding: 12px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.run-context > div:first-child {
  display: flex;
  align-items: center;
  gap: 16px;
}

.run-context select {
  max-width: 430px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-family: var(--mono);
  font-size: 12px;
}

.run-context option {
  background: var(--surface-strong);
}

.run-identity {
  gap: 18px;
  font-family: var(--mono);
  font-size: 11px;
}

.run-identity span { color: var(--muted); }
.run-identity strong { color: var(--teal); font-weight: 600; }

.metric-strip {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  padding: 34px 0 38px;
}

.metric-strip article {
  min-width: 0;
  padding: 4px 24px;
  border-left: 1px solid var(--line);
}

.metric-strip article:first-child {
  padding-left: 0;
  border-left: 0;
}

.metric-strip span,
.metric-strip small {
  display: block;
  color: var(--muted);
  font-size: 10px;
}

.metric-strip span {
  margin-bottom: 7px;
  font-family: var(--mono);
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.metric-strip strong {
  display: block;
  overflow: hidden;
  margin-bottom: 3px;
  font-family: var(--mono);
  font-size: 25px;
  font-weight: 570;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.metric-strip .status-value { color: var(--teal); }

.workspace-grid {
  display: grid;
  grid-template-columns: 0.78fr 1.22fr;
  gap: 16px;
}

.panel {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(145deg, rgba(15, 30, 41, 0.9), rgba(8, 17, 25, 0.86));
  box-shadow: var(--shadow);
}

.panel-heading,
.section-heading-row,
.dialog-heading {
  justify-content: space-between;
}

.panel-heading {
  min-height: 83px;
  padding: 21px 24px 16px;
  border-bottom: 1px solid var(--line);
}

.panel-heading h2,
.section-heading-row h2,
.dialog-heading h2 {
  margin: 4px 0 0;
  font-size: 17px;
  font-weight: 610;
  letter-spacing: -0.02em;
}

.panel-meta {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 10px;
}

.agent-flow {
  margin: 0;
  padding: 10px 24px 18px;
  list-style: none;
}

.agent-flow li {
  position: relative;
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: start;
  padding: 15px 0;
}

.agent-flow li:not(:last-child)::after {
  position: absolute;
  top: 42px;
  bottom: -11px;
  left: 14px;
  width: 1px;
  background: var(--line-strong);
  content: "";
}

.flow-index {
  z-index: 1;
  display: grid;
  width: 29px;
  height: 29px;
  place-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  background: #0c1c26;
  color: var(--teal);
  font-family: var(--mono);
  font-size: 10px;
}

.flow-copy strong,
.flow-copy small {
  display: block;
}

.flow-copy strong {
  font-size: 12px;
  font-weight: 620;
}

.flow-copy small {
  overflow: hidden;
  margin-top: 4px;
  color: var(--muted);
  font-size: 10px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.flow-status {
  padding-top: 4px;
  color: var(--teal);
  font-family: var(--mono);
  font-size: 9px;
  text-transform: uppercase;
}

.graph-wrap {
  position: relative;
  min-height: 390px;
  padding: 8px 18px 42px;
}

#riskGraph {
  display: block;
  width: 100%;
  height: 330px;
}

.risk-edge {
  stroke: rgba(104, 167, 255, 0.26);
  stroke-linecap: round;
}

.risk-node {
  stroke: rgba(141, 167, 177, 0.42);
  stroke-width: 1.2;
  fill: #142c3a;
}

.risk-node.selected {
  stroke: var(--teal);
  fill: rgba(25, 185, 167, 0.28);
  filter: drop-shadow(0 0 8px rgba(99, 223, 205, 0.35));
}

.risk-label {
  fill: var(--text);
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 650;
  text-anchor: middle;
}

.risk-value {
  fill: var(--muted);
  font-family: var(--mono);
  font-size: 8px;
  text-anchor: middle;
}

.graph-legend {
  position: absolute;
  right: 24px;
  bottom: 20px;
  display: flex;
  gap: 17px;
  color: var(--muted);
  font-size: 9px;
}

.graph-legend span {
  display: flex;
  align-items: center;
  gap: 6px;
}

.graph-legend i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
}

.legend-selected { background: var(--teal); }
.legend-node { background: #36576a; }

.solver-chart {
  padding: 32px 26px 12px;
}

.solver-row {
  display: grid;
  grid-template-columns: 104px minmax(0, 1fr) 122px;
  gap: 14px;
  align-items: center;
  margin-bottom: 23px;
}

.solver-row > span {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 10px;
}

.solver-track {
  height: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.045);
}

.solver-bar {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--blue);
  transition: width 700ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

.solver-row.qaoa .solver-bar { background: var(--teal); }

.solver-row strong {
  color: var(--text);
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 560;
  text-align: right;
}

.selection-summary {
  margin: 0 24px;
  padding: 20px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.selection-summary > span {
  display: block;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 10px;
}

.asset-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.asset-list span {
  padding: 6px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: rgba(99, 223, 205, 0.06);
  color: var(--teal);
  font-family: var(--mono);
  font-size: 11px;
}

.solver-footnotes {
  justify-content: space-between;
  padding: 17px 24px 21px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 9px;
}

.boundary-panel {
  grid-column: 1 / -1;
}

.boundary-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.boundary-grid > div {
  padding: 24px;
}

.boundary-grid > div + div {
  border-left: 1px solid var(--line);
}

.boundary-grid span,
.boundary-grid small,
.boundary-grid strong {
  display: block;
}

.boundary-grid span {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 9px;
  text-transform: uppercase;
}

.boundary-grid strong {
  margin: 7px 0 4px;
  font-family: var(--mono);
  font-size: 18px;
  font-weight: 560;
}

.boundary-grid small { color: var(--muted); font-size: 10px; }

.boundary-note {
  margin: 0;
  padding: 14px 24px;
  border-top: 1px solid var(--line);
  color: var(--amber);
  font-size: 10px;
}

.evidence-section {
  margin-top: 48px;
}

.section-heading-row {
  margin-bottom: 16px;
}

.section-heading-row > span {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 9px;
}

.evidence-table-wrap {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(8, 17, 25, 0.72);
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  text-align: left;
}

th {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

td {
  color: #c9dadd;
  font-size: 11px;
}

tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: rgba(99, 223, 205, 0.025); }

.artifact-name {
  color: var(--text);
  font-family: var(--mono);
}

.hash {
  max-width: 250px;
  overflow: hidden;
  color: var(--muted);
  font-family: var(--mono);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.view-button {
  border: 0;
  background: transparent;
  color: var(--teal);
  font-size: 10px;
}

.view-button:hover { text-decoration: underline; }

footer {
  justify-content: space-between;
  width: min(1320px, calc(100% - 48px));
  min-height: 110px;
  margin: 28px auto 0;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 9px;
}

dialog {
  width: min(860px, calc(100% - 40px));
  max-height: min(760px, calc(100vh - 48px));
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 18px;
  background: #09131c;
  color: var(--text);
  box-shadow: 0 32px 100px rgba(0, 0, 0, 0.65);
}

dialog::backdrop {
  background: rgba(0, 6, 10, 0.72);
  backdrop-filter: blur(8px);
}

.dialog-heading {
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}

dialog pre {
  max-height: calc(100vh - 180px);
  margin: 0;
  padding: 22px;
  overflow: auto;
  color: #bbced2;
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 960px) {
  .run-console {
    grid-template-columns: 1fr;
    gap: 30px;
    align-items: start;
    padding-top: 44px;
  }

  .metric-strip {
    grid-template-columns: repeat(3, 1fr);
    row-gap: 28px;
  }

  .metric-strip article:nth-child(4) {
    padding-left: 0;
    border-left: 0;
  }

  .workspace-grid { grid-template-columns: 1fr; }
  .boundary-panel { grid-column: auto; }
}

@media (max-width: 640px) {
  .topbar {
    height: 62px;
    padding: 0 16px;
  }

  .environment { display: none; }
  .shell { width: min(100% - 28px, 1320px); }

  .run-console {
    min-height: auto;
    padding: 36px 0 30px;
  }

  .console-copy h1 { font-size: 33px; }
  .run-input-row { align-items: stretch; flex-direction: column; }
  .primary-button { width: 100%; }

  .run-context {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
    padding: 16px 0;
  }

  .run-context > div:first-child {
    width: 100%;
    align-items: flex-start;
    flex-direction: column;
    gap: 5px;
  }

  .run-context select { width: 100%; max-width: none; }
  .run-identity { width: 100%; justify-content: space-between; }

  .metric-strip {
    grid-template-columns: 1fr 1fr;
    gap: 0;
    padding: 25px 0;
  }

  .metric-strip article {
    padding: 15px;
    border-bottom: 1px solid var(--line);
  }

  .metric-strip article:nth-child(odd) {
    padding-left: 0;
    border-left: 0;
  }

  .metric-strip article:last-child { border-bottom: 0; }
  .metric-strip strong { font-size: 21px; }
  .panel-heading { padding-inline: 18px; }
  .agent-flow { padding-inline: 18px; }
  .graph-wrap { min-height: 310px; padding-inline: 4px; }
  #riskGraph { height: 270px; }
  .solver-row { grid-template-columns: 78px minmax(0, 1fr); }
  .solver-row strong { grid-column: 2; text-align: left; }
  .boundary-grid { grid-template-columns: 1fr; }
  .boundary-grid > div + div { border-top: 1px solid var(--line); border-left: 0; }

  .evidence-table-wrap { overflow-x: auto; }
  table { min-width: 720px; }

  footer {
    width: min(100% - 28px, 1320px);
    align-items: flex-start;
    flex-direction: column;
    justify-content: center;
    gap: 8px;
  }
}

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