:root {
  color-scheme: dark;
  --bg: #070810;
  --surface: rgba(12, 14, 24, 0.82);
  --surface-strong: rgba(15, 18, 30, 0.96);
  --line: rgba(180, 192, 220, 0.13);
  --line-strong: rgba(180, 192, 220, 0.23);
  --text: #f3f4fb;
  --muted: #8c91a5;
  --quiet: #5d6275;
  --violet: #a178ff;
  --violet-rgb: 161, 120, 255;
  --mint: #78e5cf;
  --mint-rgb: 120, 229, 207;
  --cyan: #72d9ed;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  --ease: cubic-bezier(.2, .75, .25, 1);
  font-synthesis: none;
}

* { box-sizing: border-box; }

html { min-width: 320px; background: var(--bg); }

body {
  min-width: 320px;
  min-height: 100svh;
  margin: 0;
  overflow-x: hidden;
  color: var(--text);
  background:
    radial-gradient(circle at 8% 0%, rgba(91, 46, 154, 0.42), transparent 34rem),
    radial-gradient(circle at 100% 100%, rgba(12, 112, 126, 0.30), transparent 38rem),
    linear-gradient(122deg, #0d0a18 0%, #080912 49%, #061117 100%);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body::before {
  position: fixed;
  inset: 0;
  z-index: -2;
  opacity: 0.19;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.72' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.3'/%3E%3C/svg%3E");
  pointer-events: none;
  content: "";
}

button, a { -webkit-tap-highlight-color: transparent; }

:focus-visible {
  outline: 2px solid var(--mint);
  outline-offset: 3px;
}

.skip-link {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 50;
  padding: 9px 13px;
  border-radius: 999px;
  color: #06100e;
  background: var(--mint);
  font-size: .78rem;
  font-weight: 800;
  transform: translateY(-180%);
}

.skip-link:focus { transform: translateY(0); }

.ambient {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  pointer-events: none;
}

.ambient i {
  position: absolute;
  border: 1px solid rgba(var(--violet-rgb), .06);
  border-radius: 50%;
}

.ambient i:nth-child(1) { top: 14%; left: 18%; width: 28rem; height: 28rem; }
.ambient i:nth-child(2) { right: 3%; bottom: -17rem; width: 42rem; height: 42rem; border-color: rgba(var(--mint-rgb), .05); }
.ambient i:nth-child(3) { top: 32%; right: 27%; width: 9rem; height: 9rem; opacity: .5; }

#main {
  display: grid;
  width: min(calc(100% - 48px), 1180px);
  min-height: 100svh;
  margin: 0 auto;
  place-items: center;
  padding: 32px 0 24px;
}

.trace { width: 100%; }

.topbar {
  display: flex;
  min-height: 44px;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-size: 1rem;
  font-weight: 750;
  letter-spacing: -.025em;
  text-decoration: none;
}

.brand svg { width: 25px; color: #b897ff; filter: drop-shadow(0 0 10px rgba(var(--violet-rgb), .26)); }

.topbar-badges { display: flex; align-items: center; gap: 8px; }

.topbar-badges span {
  display: inline-flex;
  min-height: 27px;
  padding: 0 11px;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: #b7bac7;
  background: rgba(255, 255, 255, .025);
  font-family: var(--mono);
  font-size: .62rem;
  font-weight: 700;
  letter-spacing: .055em;
  text-transform: uppercase;
}

.topbar-badges i, .run-state i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--mint);
  box-shadow: 0 0 9px rgba(var(--mint-rgb), .72);
}

.trace-head {
  display: flex;
  margin: clamp(44px, 8vh, 88px) 0 18px;
  align-items: end;
  justify-content: space-between;
  gap: 32px;
}

.eyebrow, .phase-code {
  margin: 0;
  color: #a995d9;
  font-family: var(--mono);
  font-size: .64rem;
  font-weight: 700;
  letter-spacing: .15em;
}

h1 {
  margin: 8px 0 0;
  font-size: clamp(1.7rem, 3.2vw, 2.75rem);
  line-height: 1;
  letter-spacing: -.055em;
}

.scenario-picker {
  display: flex;
  max-width: 100%;
  padding: 3px;
  gap: 2px;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(5, 7, 13, .44);
}

.scenario-picker button {
  min-height: 32px;
  padding: 0 11px;
  flex: 0 0 auto;
  border: 0;
  border-radius: 7px;
  color: #73798e;
  background: transparent;
  font: inherit;
  font-size: .68rem;
  font-weight: 700;
  cursor: pointer;
  transition: color 180ms ease, background 180ms ease;
}

.scenario-picker button:hover { color: #d7d9e3; }

.scenario-picker button[aria-pressed="true"] {
  color: #f2f0f8;
  background: rgba(var(--violet-rgb), .12);
  box-shadow: inset 0 0 0 1px rgba(var(--violet-rgb), .17);
}

.workbench {
  --phase: var(--violet);
  --phase-rgb: var(--violet-rgb);
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 18px;
  background: linear-gradient(145deg, rgba(13, 13, 23, .91), rgba(6, 12, 17, .87));
  box-shadow: 0 35px 100px rgba(0, 0, 0, .29), inset 0 1px 0 rgba(255, 255, 255, .025);
  backdrop-filter: blur(18px);
}

.workbench[data-phase="route"] { --phase: var(--cyan); --phase-rgb: 114, 217, 237; }
.workbench[data-phase="ownership"] { --phase: #b58cff; --phase-rgb: 181, 140, 255; }
.workbench[data-phase="audit"] { --phase: var(--mint); --phase-rgb: var(--mint-rgb); }

.workbench-bar {
  display: grid;
  min-height: 42px;
  padding: 0 14px;
  align-items: center;
  grid-template-columns: 1fr auto 1fr;
  border-bottom: 1px solid var(--line);
  color: #74798c;
  background: rgba(3, 5, 10, .34);
  font-family: var(--mono);
  font-size: .6rem;
  letter-spacing: .065em;
  text-transform: uppercase;
}

.run-state { display: inline-flex; align-items: center; gap: 8px; }

.run-state i { animation: breathe 1.8s ease-in-out infinite; }

@keyframes breathe { 50% { opacity: .38; box-shadow: 0 0 15px rgba(var(--mint-rgb), .18); } }

.run-id { color: #777c90; }

.play-control {
  display: inline-flex;
  min-height: 28px;
  padding: 0 8px;
  justify-self: end;
  align-items: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: 7px;
  color: #9499aa;
  background: transparent;
  font: inherit;
  text-transform: uppercase;
  cursor: pointer;
}

.play-control:hover { color: var(--text); border-color: var(--line); }
.play-control svg { width: 13px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; }
.play-control[aria-pressed="true"] svg { fill: currentColor; stroke: none; }
.play-control[aria-pressed="true"] .run-state i { animation: none; }

.pipeline-wrap { position: relative; padding: 25px 34px 20px; }

.pipeline-line {
  position: absolute;
  top: 43px;
  right: calc(12.5% + 34px);
  left: calc(12.5% + 34px);
  height: 1px;
  background: rgba(180, 192, 220, .12);
}

.pipeline-line span {
  display: block;
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--violet), var(--cyan), var(--mint));
  box-shadow: 0 0 14px rgba(var(--phase-rgb), .3);
  transition: width 480ms var(--ease);
}

.pipeline-line i {
  position: absolute;
  top: 50%;
  left: 0;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #f5f3ff;
  box-shadow: 0 0 0 4px rgba(var(--phase-rgb), .12), 0 0 18px rgba(var(--phase-rgb), .65);
  transform: translate(-50%, -50%);
  transition: left 480ms var(--ease);
}

.pipeline {
  position: relative;
  display: grid;
  margin: 0;
  padding: 0;
  grid-template-columns: repeat(4, 1fr);
  list-style: none;
}

.pipeline button {
  display: flex;
  width: 100%;
  padding: 0 8px;
  align-items: center;
  flex-direction: column;
  border: 0;
  color: #7b8093;
  background: transparent;
  font: inherit;
  cursor: pointer;
}

.pipeline button i {
  display: grid;
  width: 36px;
  height: 36px;
  margin-bottom: 11px;
  place-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  color: #777d91;
  background: #0b0c15;
  font-family: var(--mono);
  font-size: .6rem;
  font-style: normal;
  transition: border-color 220ms ease, color 220ms ease, box-shadow 220ms ease, transform 220ms ease;
}

.pipeline button span { font-size: .74rem; font-weight: 750; }
.pipeline button small { margin-top: 3px; color: #73788c; font-family: var(--mono); font-size: .54rem; }
.pipeline button:hover { color: #c9ccd8; }

.pipeline button[aria-pressed="true"] { color: var(--text); }
.pipeline button[aria-pressed="true"] i {
  border-color: rgba(var(--phase-rgb), .7);
  color: var(--phase);
  box-shadow: 0 0 0 5px rgba(var(--phase-rgb), .07), 0 0 24px rgba(var(--phase-rgb), .17);
  transform: scale(1.06);
}

.pipeline button[aria-pressed="true"] small { color: #888da0; }

.stage {
  display: grid;
  min-height: 320px;
  padding: 14px 30px 30px;
  align-items: stretch;
  grid-template-columns: minmax(210px, .9fr) minmax(300px, 1.25fr) minmax(210px, .9fr);
  gap: 14px;
}

.terminal, .core {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: rgba(7, 9, 16, .52);
}

.terminal { padding: 17px; }

.terminal-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: #858a9e;
  font-family: var(--mono);
  font-size: .59rem;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
}

.terminal-title i { width: 22px; height: 1px; background: var(--line-strong); }
.output-terminal .terminal-title { color: var(--phase); }
.output-terminal .terminal-title i { background: var(--phase); box-shadow: 0 0 10px rgba(var(--phase-rgb), .35); }

.terminal dl { margin: 22px 0 0; }

.terminal dl div {
  min-height: 48px;
  padding: 9px 0;
  border-top: 1px solid var(--line);
}

.terminal dt, .terminal dd { font-family: var(--mono); font-size: .64rem; }
.terminal dt { margin-bottom: 6px; color: #797e92; }
.terminal dd { margin: 0; color: #c5c8d4; line-height: 1.35; overflow-wrap: anywhere; }
.output-terminal dd { transition: color 180ms ease; }
.output-terminal .status-value { color: var(--phase); font-weight: 800; text-transform: uppercase; }

.core {
  display: flex;
  overflow: hidden;
  padding: clamp(24px, 3vw, 36px);
  align-items: center;
  flex-direction: column;
  justify-content: center;
  text-align: center;
  background:
    radial-gradient(circle at 50% 22%, rgba(var(--phase-rgb), .10), transparent 48%),
    rgba(10, 11, 20, .64);
}

.core::before, .core::after {
  position: absolute;
  top: 50%;
  width: 24px;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(var(--phase-rgb), .7));
  content: "";
  animation: transfer 1.8s var(--ease) infinite;
}

.core::before { left: 0; }
.core::after { right: 0; transform: rotate(180deg); }

@keyframes transfer { 50% { width: 48px; opacity: .3; } }

.core-mark {
  position: relative;
  display: grid;
  width: 74px;
  height: 74px;
  margin-bottom: 20px;
  place-items: center;
  color: var(--phase);
}

.core-mark svg { width: 39px; filter: drop-shadow(0 0 11px rgba(var(--phase-rgb), .35)); }

.orbit {
  position: absolute;
  border: 1px solid rgba(var(--phase-rgb), .26);
  border-radius: 50%;
}

.orbit-a { inset: 7px; border-right-color: var(--phase); animation: spin 4.5s linear infinite; }
.orbit-b { inset: 0; border-top-color: var(--phase); border-left-color: transparent; animation: spin 7.5s linear infinite reverse; }
.core-glow { position: absolute; inset: 24px; border-radius: 50%; background: rgba(var(--phase-rgb), .16); filter: blur(8px); }

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

.phase-code { color: var(--phase); }

.core h2 {
  max-width: 370px;
  margin: 10px 0 0;
  font-size: clamp(1.25rem, 2.1vw, 1.9rem);
  line-height: 1.08;
  letter-spacing: -.045em;
}

.core > p:not(.phase-code) {
  max-width: 400px;
  margin: 12px 0 0;
  color: var(--muted);
  font-size: .78rem;
  line-height: 1.55;
}

.core ul {
  display: flex;
  max-width: 100%;
  margin: 18px 0 0;
  padding: 0;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  list-style: none;
}

.core li {
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: #9297a8;
  background: rgba(255, 255, 255, .018);
  font-family: var(--mono);
  font-size: .56rem;
}

.trace-footer {
  display: flex;
  min-height: 55px;
  padding: 0 2px;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  color: #74798d;
  font-family: var(--mono);
  font-size: .58rem;
}

.principles { display: flex; flex-wrap: wrap; gap: 12px 24px; }
.principles span + span::before { margin-right: 24px; color: #5e526e; content: "•"; }
.trace-footer p { margin: 0; white-space: nowrap; }
.trace-footer p i { margin: 0 3px; color: #656b7d; font-style: normal; }

@media (max-width: 900px) {
  #main { width: min(calc(100% - 28px), 1180px); }
  .stage { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .core { min-height: 270px; grid-column: 1 / -1; grid-row: 1; }
  .input-terminal { grid-column: 1; }
  .output-terminal { grid-column: 2; }
}

@media (max-width: 620px) {
  #main { width: min(calc(100% - 18px), 1180px); padding-top: 14px; }
  .topbar-badges span:last-child { display: none; }
  .trace-head { margin-top: 34px; align-items: stretch; flex-direction: column; gap: 18px; }
  .scenario-picker { width: 100%; }
  .scenario-picker button { flex: 1 0 auto; }
  .workbench-bar { grid-template-columns: 1fr auto; }
  .run-id { display: none; }
  .pipeline-wrap { padding-inline: 8px; }
  .pipeline-line { right: calc(12.5% + 8px); left: calc(12.5% + 8px); }
  .pipeline button { padding-inline: 2px; }
  .pipeline button i { width: 31px; height: 31px; }
  .pipeline button span { font-size: .62rem; }
  .pipeline button small { display: none; }
  .stage { min-height: 0; padding: 8px 10px 10px; grid-template-columns: 1fr; }
  .core { min-height: 260px; grid-column: 1; }
  .input-terminal, .output-terminal { grid-column: 1; }
  .terminal dl { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 14px; }
  .trace-footer { padding: 15px 4px 6px; align-items: flex-start; flex-direction: column; gap: 12px; }
  .principles { gap: 8px 14px; }
  .principles span + span::before { margin-right: 14px; }
}

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