:root {
  --bg0: #060a14;
  --bg1: #0b1326;
  --bg2: #111b33;
  --ink: #d7e1ff;
  --muted: #8ea4d9;
  --card: rgba(12, 20, 42, 0.86);
  --line: #2a3b66;
  --sender: #4cc9f0;
  --receiver: #22c55e;
  --good: #34d399;
  --warn: #f59e0b;
  --bad: #fb7185;
  --violet: #7c8cff;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Manrope", sans-serif;
  color: var(--ink);
  background: radial-gradient(circle at 20% -10%, #182850 0%, transparent 40%),
    radial-gradient(circle at 90% 120%, #12384f 0%, transparent 45%),
    linear-gradient(180deg, var(--bg0), var(--bg1) 45%, var(--bg2));
  position: relative;
  overflow-x: hidden;
}

.backdrop {
  position: fixed;
  z-index: -1;
  pointer-events: none;
}

.glow-a {
  width: 360px;
  height: 360px;
  border-radius: 50%;
  right: -120px;
  top: -120px;
  background: radial-gradient(circle, rgba(124, 140, 255, 0.28), rgba(124, 140, 255, 0));
}

.glow-b {
  width: 320px;
  height: 320px;
  border-radius: 50%;
  left: -110px;
  bottom: -110px;
  background: radial-gradient(circle, rgba(76, 201, 240, 0.22), rgba(76, 201, 240, 0));
}

.grid {
  inset: 0;
  background-image:
    linear-gradient(rgba(120, 150, 220, 0.09) 1px, transparent 1px),
    linear-gradient(90deg, rgba(120, 150, 220, 0.09) 1px, transparent 1px);
  background-size: 24px 24px;
  opacity: 0.32;
}

.layout {
  width: min(1240px, 94vw);
  margin: 20px auto 28px;
  display: grid;
  gap: 14px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 18px;
  backdrop-filter: blur(6px);
}

.hero {
  display: grid;
  grid-template-columns: 1.35fr 1fr;
  gap: 14px;
  position: relative;
  overflow: hidden;
}

.hero::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(110deg, rgba(76, 201, 240, 0.08), rgba(124, 140, 255, 0.08));
  pointer-events: none;
}

.eyebrow {
  margin: 0;
  font-family: "JetBrains Mono", monospace;
  color: #8db4ff;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 0.74rem;
}

.hero h1 {
  margin: 8px 0;
  font-size: clamp(1.8rem, 4.2vw, 2.8rem);
  line-height: 1.1;
  color: #f2f7ff;
}

.hero-copy {
  margin: 0;
  max-width: 56ch;
  color: var(--muted);
}

.hero-points {
  display: grid;
  gap: 8px;
  align-content: start;
}

.point {
  border: 1px solid #304579;
  border-radius: 12px;
  padding: 10px;
  background: rgba(12, 28, 58, 0.65);
  display: grid;
  grid-template-columns: 34px 1fr;
  gap: 8px;
  align-items: center;
}

.point span {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: linear-gradient(135deg, #283d76, #4567c7);
  color: #fff;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.73rem;
}

.point p {
  margin: 0;
  font-size: 0.84rem;
  color: #c7d5f7;
}

.main-grid {
  display: grid;
  grid-template-columns: 1.55fr 1fr;
  gap: 14px;
}

.title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.title-row.compact {
  align-items: baseline;
}

h2 {
  margin: 0;
  font-size: 1.08rem;
  color: #edf3ff;
}

.sub {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
}

h3 {
  margin: 0;
  font-size: 0.92rem;
  color: #dbe7ff;
}

.phase {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.75rem;
  border-radius: 999px;
  padding: 6px 11px;
  border: 1px solid #39539a;
  background: rgba(37, 56, 105, 0.55);
  color: #aac4ff;
  font-weight: 600;
}

.phase.phase-timeout,
.phase.phase-data-lost,
.phase.phase-ack-lost {
  background: rgba(82, 44, 9, 0.58);
  border-color: rgba(245, 158, 11, 0.6);
  color: #ffd28e;
}

.phase.phase-complete,
.phase.phase-ack-received,
.phase.phase-receiver-accept {
  background: rgba(14, 63, 38, 0.6);
  border-color: rgba(52, 211, 153, 0.55);
  color: #8ef0cb;
}

.phase.phase-stopped {
  background: rgba(44, 53, 74, 0.58);
  border-color: rgba(148, 163, 184, 0.5);
  color: #c7d2e8;
}

.stage {
  margin-top: 12px;
  background: linear-gradient(180deg, rgba(10, 18, 37, 0.9), rgba(11, 24, 49, 0.9));
  border: 1px solid #2a3f73;
  border-radius: 14px;
  padding: 14px;
  position: relative;
}

.stage::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 14px;
  background: linear-gradient(90deg, rgba(76, 201, 240, 0.08), rgba(34, 197, 94, 0.05));
  pointer-events: none;
}

.stage-card[data-phase="phase-timeout"] .stage,
.stage-card[data-phase="phase-data-lost"] .stage,
.stage-card[data-phase="phase-ack-lost"] .stage {
  box-shadow: inset 0 0 0 1px rgba(245, 158, 11, 0.5), 0 0 18px rgba(245, 158, 11, 0.2);
}

.stage-card[data-phase="phase-receiver-accept"] .stage,
.stage-card[data-phase="phase-ack-received"] .stage,
.stage-card[data-phase="phase-complete"] .stage {
  box-shadow: inset 0 0 0 1px rgba(52, 211, 153, 0.45), 0 0 18px rgba(52, 211, 153, 0.16);
}

.lane-header {
  display: grid;
  grid-template-columns: 116px 1fr 116px;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.host {
  text-align: center;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.73rem;
  border-radius: 9px;
  padding: 7px 4px;
  color: #fff;
  letter-spacing: 0.05em;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.sender { background: linear-gradient(120deg, #2e6aff, #2452cb); }
.receiver { background: linear-gradient(120deg, #1a9d74, #12745a); }

.channel-name {
  text-align: center;
  font-size: 0.74rem;
  color: #a9bce7;
  font-family: "JetBrains Mono", monospace;
  letter-spacing: 0.09em;
}

.lane {
  position: relative;
  height: 74px;
}

.track {
  position: absolute;
  top: 31px;
  left: 50px;
  right: 50px;
  height: 10px;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(76, 201, 240, 0.45), rgba(124, 140, 255, 0.45), rgba(34, 197, 94, 0.45));
  box-shadow: inset 0 0 0 1px rgba(185, 208, 255, 0.25);
}

.endpoint {
  position: absolute;
  top: 24px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
}

.sender-dot {
  left: 41px;
  background: var(--sender);
  box-shadow: 0 0 0 7px rgba(76, 201, 240, 0.18);
}

.receiver-dot {
  right: 41px;
  background: var(--receiver);
  box-shadow: 0 0 0 7px rgba(34, 197, 94, 0.18);
}

.token {
  position: absolute;
  top: 8px;
  left: 46px;
  transform: translateX(0);
  padding: 8px 11px;
  border-radius: 999px;
  border: 1px solid #496fca;
  background: linear-gradient(180deg, #122149, #1a2d5c);
  color: #d8e6ff;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.72rem;
  transition: transform 860ms cubic-bezier(0.22, 1, 0.36, 1), opacity 220ms linear, background-color 180ms linear;
  box-shadow: 0 8px 18px rgba(42, 78, 175, 0.35);
}

.token.ack {
  border-color: #329a7d;
  background: linear-gradient(180deg, #103c31, #175144);
}

.token.loss {
  border-color: #b0455c;
  background: linear-gradient(180deg, #481422, #5f1d2f);
}

.hidden {
  opacity: 0;
  pointer-events: none;
}

.timeout-wrap {
  margin-top: 8px;
  display: grid;
  gap: 6px;
}

.timeout-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.timeout-label {
  font-size: 0.74rem;
  color: #9cb2e5;
  font-family: "JetBrains Mono", monospace;
}

.timeout-note {
  font-size: 0.72rem;
  color: #7e94c8;
}

.timeout-bar {
  width: 100%;
  height: 9px;
  border-radius: 999px;
  background: #1c2a4c;
  overflow: hidden;
  border: 1px solid #314a84;
}

.timeout-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #f59e0b, #f43f5e);
}

.explain {
  margin-top: 9px;
  min-height: 24px;
  color: #bfd1fa;
  font-size: 0.86rem;
  line-height: 1.45;
}

.timeline-wrap {
  margin-top: 14px;
}

.timeline {
  margin-top: 8px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(84px, 1fr));
  gap: 8px;
}

.step {
  border: 1px solid #32497f;
  background: rgba(14, 25, 51, 0.75);
  border-radius: 11px;
  padding: 7px;
  font-size: 0.7rem;
  min-height: 56px;
  transition: transform 180ms ease;
}

.step:hover { transform: translateY(-2px); }

.step .idx {
  font-family: "JetBrains Mono", monospace;
  color: #9db4e8;
}

.step .status {
  margin-top: 5px;
  font-weight: 700;
}

.step.waiting .status { color: #c8d8ff; }
.step.inflight {
  background: rgba(83, 50, 9, 0.62);
  border-color: rgba(245, 158, 11, 0.55);
}
.step.inflight .status { color: #ffd08f; }
.step.done {
  background: rgba(18, 67, 45, 0.62);
  border-color: rgba(52, 211, 153, 0.5);
}
.step.done .status { color: #8af0ca; }

.side-grid {
  display: grid;
  gap: 12px;
}

.controls {
  margin-top: 10px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
}

label {
  display: grid;
  gap: 5px;
  font-size: 0.78rem;
  color: #9cb0df;
}

input,
select,
button {
  font: inherit;
  border-radius: 10px;
  padding: 10px;
}

input,
select {
  border: 1px solid #35508f;
  background: #0f1b39;
  color: #dde7ff;
}

input:focus,
select:focus {
  outline: 2px solid rgba(76, 201, 240, 0.45);
  border-color: #4e7fd8;
}

.button-row {
  margin-top: 12px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

button {
  border: 1px solid transparent;
  cursor: pointer;
  font-weight: 800;
}

#startBtn {
  background: linear-gradient(130deg, #1f7ae0, #2a59d8);
  color: #f5f9ff;
}

.secondary {
  background: linear-gradient(130deg, #3b2c14, #513816);
  border-color: #8b5d1a;
  color: #ffd594;
}

.ghost {
  background: linear-gradient(130deg, #172545, #1d2f59);
  border-color: #345393;
  color: #c7d8ff;
}

.state-grid {
  margin-top: 10px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.state-grid div {
  border: 1px solid #314a84;
  border-radius: 11px;
  background: linear-gradient(180deg, #0f1c3a, #13264a);
  padding: 8px;
}

.state-grid span {
  display: block;
  font-size: 0.72rem;
  color: #8ea6d9;
}

.state-grid strong {
  display: block;
  margin-top: 4px;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.88rem;
  color: #e2ecff;
}

.legend {
  font-size: 0.72rem;
  font-family: "JetBrains Mono", monospace;
  color: #90a6d9;
}

.log {
  margin-top: 10px;
  height: 300px;
  overflow: auto;
  border-radius: 12px;
  background: linear-gradient(180deg, #070d1e, #0b142b);
  color: #d7e4ff;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.74rem;
  line-height: 1.5;
  padding: 11px;
  border: 1px solid #273e74;
}

.log .good { color: #6ee7b7; }
.log .warn { color: #fdba74; }
.log .bad { color: #fda4af; }

.footnote p {
  margin: 8px 0 0;
  color: #a9bde9;
}

code {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.82em;
  color: #d9e7ff;
}

@media (max-width: 1000px) {
  .hero { grid-template-columns: 1fr; }
  .main-grid { grid-template-columns: 1fr; }
  .controls { grid-template-columns: 1fr; }
  .button-row { grid-template-columns: 1fr; }
  .timeline { grid-template-columns: repeat(auto-fit, minmax(68px, 1fr)); }
}
