:root {
  color-scheme: dark;
  --bg: #101216;
  --panel: #181b21;
  --panel-2: #20242d;
  --line: #343a46;
  --text: #f5f7fb;
  --muted: #a7b0c0;
  --blue: #54a8ff;
  --green: #52d68b;
  --yellow: #f4c95d;
  --red: #ff647c;
  --ink: #11141a;
  --shadow: 0 18px 60px rgba(0, 0, 0, 0.32);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(135deg, #101216 0%, #17191f 52%, #11131a 100%);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
select {
  font: inherit;
}

.app-shell {
  min-height: 100vh;
  padding: 24px;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  margin: 0 auto 18px;
  max-width: 1440px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--green);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 4rem;
  line-height: 0.95;
}

h2 {
  margin-bottom: 10px;
  font-size: 1.35rem;
}

h3 {
  margin-bottom: 10px;
  font-size: 0.9rem;
}

.scenario-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(110px, 1fr));
  gap: 8px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(24, 27, 33, 0.72);
  box-shadow: var(--shadow);
}

.tab {
  min-height: 40px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.tab.is-active {
  background: var(--text);
  color: var(--ink);
  font-weight: 800;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(230px, 280px) minmax(420px, 1fr) minmax(280px, 360px);
  gap: 16px;
  max-width: 1440px;
  margin: 0 auto;
}

.control-panel,
.explain-panel,
.console-panel,
.network-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(24, 27, 33, 0.88);
  box-shadow: var(--shadow);
}

.control-panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 18px;
}

.panel-block {
  display: grid;
  gap: 8px;
}

label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
  color: var(--text);
  padding: 0 12px;
}

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 42px;
  color: var(--text);
}

.switch {
  position: relative;
  width: 48px;
  height: 28px;
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #2d323d;
  cursor: pointer;
  transition: background 180ms ease;
}

.switch span {
  position: absolute;
  top: 4px;
  left: 4px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--text);
  transition: transform 180ms ease;
}

.switch[aria-pressed="true"] {
  background: var(--green);
}

.switch[aria-pressed="true"] span {
  transform: translateX(20px);
}

.primary-action {
  min-height: 48px;
  margin-top: auto;
  border: 0;
  border-radius: 6px;
  background: var(--green);
  color: var(--ink);
  font-weight: 900;
  cursor: pointer;
}

.stage {
  position: relative;
  min-height: 640px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    #151820;
  background-size: 40px 40px;
  box-shadow: var(--shadow);
}

.lane {
  position: absolute;
  left: 28px;
  right: 28px;
  display: flex;
  justify-content: center;
  z-index: 3;
}

.browser-lane {
  top: 32px;
}

.server-lane {
  bottom: 32px;
}

.node {
  display: flex;
  align-items: center;
  gap: 12px;
  width: min(360px, 100%);
  padding: 16px;
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 8px;
  background: rgba(32, 36, 45, 0.94);
}

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

.node small {
  max-width: 250px;
  overflow: hidden;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.node-icon {
  display: grid;
  width: 46px;
  height: 46px;
  place-items: center;
  border-radius: 8px;
  color: var(--ink);
  font-weight: 900;
}

.browser .node-icon {
  background: var(--blue);
}

.server .node-icon {
  background: var(--green);
}

.flow-area {
  position: absolute;
  inset: 132px 28px;
}

.beam {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 4px;
  border-radius: 999px;
  background: linear-gradient(var(--blue), var(--yellow), var(--green));
  opacity: 0.45;
  transform: translateX(-50%);
}

.guardrail {
  position: absolute;
  top: 44%;
  left: 50%;
  width: min(440px, 86%);
  min-height: 48px;
  display: grid;
  place-items: center;
  border: 1px dashed rgba(244, 201, 93, 0.75);
  border-radius: 8px;
  background: rgba(244, 201, 93, 0.08);
  color: var(--yellow);
  font-size: 0.82rem;
  font-weight: 800;
  text-align: center;
  transform: translate(-50%, -50%);
}

.packet {
  position: absolute;
  left: 50%;
  min-width: 112px;
  padding: 10px 12px;
  border-radius: 6px;
  color: var(--ink);
  font-size: 0.82rem;
  font-weight: 900;
  text-align: center;
  opacity: 0;
  transform: translate(-50%, 0);
  box-shadow: 0 12px 26px rgba(0, 0, 0, 0.28);
}

.preflight-packet {
  top: 4%;
  background: var(--yellow);
}

.request-packet {
  top: 4%;
  background: var(--blue);
}

.response-packet {
  bottom: 4%;
  background: var(--green);
}

.blocker {
  position: absolute;
  top: 44%;
  left: 50%;
  display: grid;
  width: min(250px, 78%);
  min-height: 54px;
  place-items: center;
  border-radius: 8px;
  background: var(--red);
  color: var(--ink);
  font-weight: 900;
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.88);
}

.stage.run-simple .request-packet {
  animation: down 1.2s ease-in-out forwards;
}

.stage.run-simple .response-packet {
  animation: up 1.1s ease-in-out 1.1s forwards;
}

.stage.run-preflight .preflight-packet {
  animation: down 0.95s ease-in-out forwards;
}

.stage.run-preflight .response-packet {
  animation: up 0.8s ease-in-out 0.95s forwards, up 0.9s ease-in-out 2.55s forwards;
}

.stage.run-preflight .request-packet {
  animation: down 1s ease-in-out 1.7s forwards;
}

.stage.run-blocked .request-packet,
.stage.run-blocked .preflight-packet {
  animation: downToGate 0.85s ease-in-out forwards;
}

.stage.run-blocked .blocker {
  animation: blockPulse 0.55s ease-out 0.75s forwards;
}

.stage.run-blocked .response-packet {
  animation: upToGate 0.85s ease-in-out 0.5s forwards;
}

@keyframes down {
  0% {
    opacity: 0;
    transform: translate(-50%, 0);
  }
  12%,
  88% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translate(-50%, 390px);
  }
}

@keyframes up {
  0% {
    opacity: 0;
    transform: translate(-50%, 0);
  }
  12%,
  88% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -390px);
  }
}

@keyframes downToGate {
  0% {
    opacity: 0;
    transform: translate(-50%, 0);
  }
  20%,
  100% {
    opacity: 1;
  }
  100% {
    transform: translate(-50%, 175px);
  }
}

@keyframes upToGate {
  0% {
    opacity: 0;
    transform: translate(-50%, 0);
  }
  20%,
  100% {
    opacity: 1;
  }
  100% {
    transform: translate(-50%, -170px);
  }
}

@keyframes blockPulse {
  100% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
}

.explain-panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 18px;
}

.explain-panel p {
  color: var(--muted);
  line-height: 1.55;
}

.headers {
  border-top: 1px solid var(--line);
  padding-top: 16px;
}

pre {
  min-height: 132px;
  overflow: auto;
  margin: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #101319;
  color: #dce6f4;
  white-space: pre-wrap;
}

.timeline {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: step;
}

.timeline li {
  position: relative;
  min-height: 48px;
  padding: 12px 12px 12px 48px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
  color: var(--muted);
  line-height: 1.35;
}

.timeline li::before {
  position: absolute;
  top: 12px;
  left: 12px;
  display: grid;
  width: 24px;
  height: 24px;
  place-items: center;
  border-radius: 6px;
  background: #303641;
  color: var(--text);
  counter-increment: step;
  content: counter(step);
  font-size: 0.76rem;
  font-weight: 900;
}

.timeline li.is-active {
  border-color: rgba(84, 168, 255, 0.75);
  color: var(--text);
}

.console-panel {
  grid-column: 1 / span 2;
  overflow: hidden;
}

.network-panel {
  grid-column: 3;
  overflow: hidden;
}

.console-bar,
.network-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(32, 36, 45, 0.72);
}

.console-bar h2,
.network-bar h2 {
  margin-bottom: 0;
}

.console-status,
.network-status {
  display: inline-grid;
  min-width: 96px;
  min-height: 30px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
}

.console-status.is-ok,
.network-status.is-ok {
  border-color: rgba(82, 214, 139, 0.45);
  color: var(--green);
}

.console-status.is-error,
.network-status.is-error {
  border-color: rgba(255, 100, 124, 0.55);
  color: var(--red);
}

.console-output {
  display: grid;
  min-height: 190px;
  max-height: 260px;
  overflow: auto;
  padding: 12px 0;
  background: #0c0f14;
  font-family:
    "SFMono-Regular", Consolas, "Liberation Mono", Menlo, ui-monospace, monospace;
  font-size: 0.86rem;
  line-height: 1.45;
}

.console-line {
  display: grid;
  grid-template-columns: 68px minmax(0, 1fr);
  gap: 10px;
  padding: 6px 18px;
  border-left: 3px solid transparent;
  color: #dce6f4;
}

.console-line.is-info {
  border-left-color: var(--blue);
}

.console-line.is-success {
  border-left-color: var(--green);
}

.console-line.is-warn {
  border-left-color: var(--yellow);
  color: #f7df9d;
}

.console-line.is-error {
  border-left-color: var(--red);
  background: rgba(255, 100, 124, 0.08);
  color: #ffd8df;
}

.console-time {
  color: #7f8ba0;
  user-select: none;
}

.console-message {
  min-width: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.network-table {
  padding: 12px 18px 4px;
}

.network-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 84px 110px;
  gap: 10px;
  min-height: 38px;
  align-items: center;
  border-bottom: 1px solid rgba(52, 58, 70, 0.8);
  color: #dce6f4;
  font-size: 0.86rem;
}

.network-head {
  min-height: 30px;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 900;
  text-transform: uppercase;
}

.network-row.is-ok span:last-child {
  color: var(--green);
  font-weight: 900;
}

.network-row.is-error span:last-child {
  color: var(--red);
  font-weight: 900;
}

.network-detail {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  padding: 14px 18px 18px;
}

.network-detail pre {
  min-height: 112px;
  max-height: 154px;
  font-size: 0.78rem;
}

@media (max-width: 1100px) {
  .workspace {
    grid-template-columns: 280px 1fr;
  }

  .explain-panel,
  .console-panel,
  .network-panel {
    grid-column: 1 / -1;
  }
}

@media (max-width: 760px) {
  .app-shell {
    padding: 14px;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .scenario-tabs {
    grid-template-columns: 1fr;
  }

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

  .stage {
    min-height: 560px;
  }

  h1 {
    font-size: 2.5rem;
  }

  .flow-area {
    inset: 120px 16px;
  }

  .lane {
    left: 16px;
    right: 16px;
  }

  .node {
    padding: 12px;
  }

  .node small {
    max-width: 180px;
  }

  .console-bar,
  .network-bar {
    align-items: flex-start;
    flex-direction: column;
  }

  .console-line,
  .network-row {
    grid-template-columns: 1fr;
    gap: 2px;
  }
}
