:root {
  color-scheme: dark;
  --ink: #f7fbff;
  --muted: #95a3bd;
  --soft: #c8d4ea;
  --line: rgba(167, 184, 255, .16);
  --panel: rgba(9, 14, 31, .78);
  --panel-strong: rgba(14, 21, 45, .94);
  --black: #070a16;
  --green: #37e58d;
  --yellow: #f7d64a;
  --red: #ff4c71;
  --blue: #25b8ff;
  --violet: #8d48ff;
  --pink: #f044ff;
  --chain-primary: var(--blue);
  --chain-ink: #081020;
  --chain-paper: #eaf4ff;
  --shadow: 0 24px 70px rgba(0, 0, 0, .42);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--black);
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 48% 18%, color-mix(in srgb, var(--chain-primary) 34%, transparent), transparent 30%),
    radial-gradient(circle at 78% 28%, rgba(240, 68, 255, .24), transparent 32%),
    radial-gradient(circle at 24% 84%, rgba(37, 184, 255, .2), transparent 30%),
    linear-gradient(125deg, #070a16 0%, #0d1226 42%, #120a23 68%, #061426 100%);
  color: var(--ink);
  letter-spacing: 0;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(115deg, transparent 0 42%, rgba(255, 255, 255, .04) 42% 43%, transparent 43% 100%),
    radial-gradient(circle at 52% 42%, rgba(255, 255, 255, .12), transparent 1px);
  background-size: auto, 46px 46px;
  mask-image: linear-gradient(90deg, transparent, #000 16%, #000 86%, transparent);
}

button,
input {
  font: inherit;
  letter-spacing: 0;
}

button {
  cursor: pointer;
}

.app-shell {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 264px minmax(0, 1fr);
  min-height: 100vh;
}

.control-rail {
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(14, 20, 43, .98), rgba(8, 11, 25, .98)),
    var(--black);
  border-right: 1px solid var(--line);
  color: #fff;
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  box-shadow: 20px 0 80px rgba(0, 0, 0, .28);
}

.brand {
  color: inherit;
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
}

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background:
    linear-gradient(135deg, #ffcd35 0 23%, #884bff 23% 50%, #17df9c 50% 72%, #22b8ff 72%),
    #fff;
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, .28),
    0 0 26px rgba(141, 72, 255, .34);
}

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

.brand strong {
  font-size: 18px;
  line-height: 1.05;
}

.brand small {
  color: #b9c7e7;
  font-size: 12px;
}

.rail-nav {
  display: grid;
  gap: 8px;
}

.rail-nav a {
  min-height: 40px;
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  border-radius: 8px;
  padding: 0 12px;
  color: #bac7e4;
  text-decoration: none;
  font-weight: 850;
  border: 1px solid transparent;
}

.rail-nav a.active {
  color: #fff;
  background: linear-gradient(90deg, rgba(141, 72, 255, .8), rgba(37, 184, 255, .16));
  border-color: rgba(167, 184, 255, .2);
  box-shadow: inset 0 0 18px rgba(255, 255, 255, .06);
}

.rail-nav svg {
  width: 18px;
  height: 18px;
}

.analyzer-form,
.status-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(22, 31, 65, .82), rgba(9, 14, 31, .76));
  box-shadow: var(--shadow);
}

.analyzer-form {
  display: grid;
  gap: 10px;
  padding: 14px;
}

.analyzer-form h2 {
  margin: 0;
  font-size: 20px;
  line-height: 1.1;
}

.analyzer-form p {
  margin: 6px 0 0;
  color: var(--soft);
  font-size: 13px;
  line-height: 1.35;
}

.analyzer-form label {
  color: #dce8ff;
  font-size: 13px;
  font-weight: 850;
}

.input-wrap {
  display: grid;
  grid-template-columns: 28px 1fr;
  align-items: center;
  min-height: 46px;
  background: rgba(6, 10, 24, .88);
  border: 1px solid rgba(167, 184, 255, .26);
  border-radius: 8px;
  overflow: hidden;
}

.input-wrap:focus-within {
  border-color: var(--chain-primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--chain-primary) 25%, transparent);
}

.input-wrap span {
  color: #a8b7d5;
  justify-self: end;
}

.input-wrap input {
  width: 100%;
  border: 0;
  outline: 0;
  min-width: 0;
  padding: 0 12px 0 6px;
  color: var(--ink);
  background: transparent;
}

.input-wrap input::placeholder {
  color: #72809b;
}

.primary-btn,
.icon-btn,
.tab-row button {
  border: 0;
  border-radius: 8px;
  min-height: 42px;
}

.primary-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  background: linear-gradient(90deg, #ee42ff, #25b8ff);
  color: #fff;
  font-weight: 950;
  box-shadow: 0 16px 34px rgba(37, 184, 255, .24);
}

.primary-btn:disabled {
  cursor: progress;
  opacity: .72;
}

.primary-btn svg,
.icon-btn svg {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

.status-panel {
  padding: 14px;
  color: #cfd9ef;
}

.status-panel p {
  margin: 9px 0 0;
  font-size: 13px;
  line-height: 1.45;
}

.status-line {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #fff;
}

.status-line span {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--muted);
}

.status-line.active span {
  background: var(--green);
  box-shadow: 0 0 0 8px rgba(55, 229, 141, .14);
}

.status-line.loading span {
  background: var(--yellow);
  animation: pulse 1s infinite;
}

.status-line.error span {
  background: var(--red);
}

.controls-group {
  display: grid;
  grid-template-columns: 42px 42px 1fr;
  gap: 8px;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: rgba(255, 255, 255, .08);
  border: 1px solid rgba(167, 184, 255, .14);
  color: #fff;
  font-weight: 900;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, .14);
}

.icon-btn.wide {
  padding: 0 12px;
}

.rail-footer {
  margin-top: auto;
  padding: 16px 10px 6px;
  color: rgba(255, 255, 255, .72);
  text-transform: uppercase;
  letter-spacing: 6px;
  font-size: 12px;
  line-height: 1.55;
}

.rail-footer span {
  display: block;
}

.rail-footer::after {
  content: "";
  display: block;
  width: 80px;
  height: 3px;
  margin-top: 12px;
  background: linear-gradient(90deg, #ee42ff, #25b8ff, transparent);
  border-radius: 999px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(460px, 1fr) minmax(360px, 430px);
  gap: 22px;
  padding: 26px;
  min-width: 0;
  align-items: start;
}

.card-stage,
.inspector {
  min-width: 0;
}

.card-stage {
  display: grid;
  gap: 20px;
}

.stage-toolbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.eyebrow {
  margin: 0 0 4px;
  color: #97a7c6;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 7px;
  text-transform: uppercase;
}

.stage-toolbar h1 {
  margin: 0;
  max-width: 720px;
  font-size: clamp(36px, 3.65vw, 54px);
  line-height: .98;
  color: #fff;
}

.stage-toolbar h1::first-letter {
  color: #fff;
}

.stage-toolbar h1 {
  text-shadow: 0 0 34px rgba(37, 184, 255, .14);
}

.stage-toolbar h1::after {
  content: "";
}

.stage-toolbar p:not(.eyebrow) {
  margin: 10px 0 0;
  color: #c5d2ee;
  font-size: clamp(16px, 1.2vw, 20px);
  line-height: 1.35;
}

.mode-pill {
  flex: 0 0 auto;
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  padding: 0 14px;
  background: rgba(141, 72, 255, .2);
  border: 1px solid rgba(141, 72, 255, .56);
  color: #f1eaff;
  font-size: 12px;
  font-weight: 900;
  max-width: 190px;
  box-shadow: 0 0 28px rgba(141, 72, 255, .18);
}

.mode-pill.live {
  color: #dfffe9;
  background: rgba(55, 229, 141, .12);
  border-color: rgba(55, 229, 141, .42);
}

.mode-pill.partial {
  color: #ffe6ec;
  background: rgba(255, 76, 113, .14);
  border-color: rgba(255, 76, 113, .42);
}

.canvas-wrap {
  display: grid;
  place-items: center;
  min-height: 0;
}

#chainCanvas {
  width: min(100%, calc((100vh - 220px) * .714));
  max-width: 560px;
  aspect-ratio: 900 / 1260;
  height: auto;
  border-radius: 8px;
  background: #070a16;
  box-shadow:
    0 28px 90px rgba(0, 0, 0, .48),
    0 0 80px color-mix(in srgb, var(--chain-primary) 24%, transparent);
}

.inspector {
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr);
  max-height: calc(100vh - 52px);
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(16, 24, 52, .9), rgba(8, 12, 26, .92));
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.identity-strip {
  position: relative;
  padding: 22px 18px 16px;
  border-bottom: 1px solid var(--line);
  overflow: hidden;
}

.identity-strip::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 82% 22%, color-mix(in srgb, var(--chain-primary) 38%, transparent), transparent 28%),
    linear-gradient(135deg, transparent, rgba(255, 255, 255, .04));
  pointer-events: none;
}

.identity-strip > * {
  position: relative;
}

.chain-chip {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  border-radius: 8px;
  padding: 0 11px;
  background: var(--chain-primary);
  color: #fff;
  font-size: 12px;
  font-weight: 950;
  box-shadow: 0 0 24px color-mix(in srgb, var(--chain-primary) 38%, transparent);
}

.identity-strip strong {
  display: block;
  margin-top: 12px;
  color: #fff;
  font-size: 26px;
  line-height: 1.02;
}

.identity-strip p {
  margin: 8px 0 0;
  color: #c1cce3;
  font-size: 13px;
  line-height: 1.45;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

.metric {
  border-radius: 8px;
  border: 1px solid rgba(167, 184, 255, .16);
  background: rgba(255, 255, 255, .055);
  padding: 10px;
  min-height: 68px;
}

.metric strong {
  display: block;
  color: #fff;
  font-size: 22px;
  line-height: 1;
}

.metric span {
  display: block;
  margin-top: 6px;
  color: #aab8d5;
  font-size: 12px;
  font-weight: 850;
}

.tab-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

.tab-row button {
  border: 1px solid transparent;
  background: rgba(255, 255, 255, .035);
  color: #a9b7d3;
  font-weight: 900;
}

.tab-row button.active {
  background: linear-gradient(90deg, #7f35ff, #4a5dff);
  color: #fff;
  box-shadow: 0 0 24px rgba(141, 72, 255, .24);
}

.tab-panel {
  min-height: 0;
  overflow: auto;
  display: none;
  padding: 12px;
}

.tab-panel.active {
  display: block;
}

.chain-list,
.signal-list,
.stats-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
}

.chain-item,
.signal-card,
.stat-card {
  list-style: none;
  border: 1px solid rgba(167, 184, 255, .14);
  border-radius: 8px;
  background: rgba(255, 255, 255, .055);
  padding: 10px;
}

.chain-item {
  display: grid;
  grid-template-columns: 32px 38px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
}

.rank-number {
  color: #b8c4df;
  font-weight: 950;
  text-align: right;
}

.chain-dot {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 11px;
  font-weight: 950;
  overflow: hidden;
  background: var(--chain-color, var(--blue));
  box-shadow: 0 0 20px color-mix(in srgb, var(--chain-color, var(--blue)) 34%, transparent);
}

.chain-main {
  min-width: 0;
}

.chain-main strong {
  display: block;
  color: #fff;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.chain-main span {
  display: block;
  margin-top: 2px;
  color: #9fabca;
  font-size: 12px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.score-pill {
  min-width: 50px;
  min-height: 32px;
  border-radius: 8px;
  display: inline-grid;
  place-items: center;
  padding: 0 8px;
  background: rgba(247, 214, 74, .16);
  color: #ffe680;
  border: 1px solid rgba(247, 214, 74, .28);
  font-weight: 950;
  font-size: 13px;
}

.signal-card strong,
.stat-card strong {
  display: block;
  color: #fff;
  font-size: 14px;
}

.signal-card p,
.stat-card p {
  margin: 6px 0 0;
  color: #aebbd8;
  font-size: 13px;
  line-height: 1.45;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%) translateY(20px);
  pointer-events: none;
  opacity: 0;
  max-width: min(430px, calc(100vw - 32px));
  background: rgba(9, 14, 31, .95);
  color: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  box-shadow: var(--shadow);
  transition: opacity .18s ease, transform .18s ease;
  font-size: 13px;
  font-weight: 850;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@keyframes pulse {
  50% {
    transform: scale(1.28);
  }
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .control-rail {
    min-height: 0;
    position: sticky;
    top: 0;
    z-index: 4;
    display: grid;
    grid-template-columns: minmax(190px, 1fr) minmax(260px, 340px);
    align-items: start;
  }

  .rail-nav,
  .rail-footer {
    display: none;
  }

  .status-panel {
    display: none;
  }

  .controls-group {
    grid-column: 1 / -1;
  }

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

  .inspector {
    max-height: none;
  }

  #chainCanvas {
    width: min(100%, 620px);
  }
}

@media (max-width: 680px) {
  .control-rail {
    grid-template-columns: 1fr;
    gap: 12px;
    padding: 16px;
  }

  .workspace {
    padding: 16px 10px;
    gap: 18px;
  }

  .stage-toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .eyebrow {
    letter-spacing: 4px;
  }

  .stage-toolbar h1 {
    font-size: 34px;
  }

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

  .chain-item {
    grid-template-columns: 26px 38px minmax(0, 1fr);
  }

  .score-pill {
    grid-column: 3;
    justify-self: start;
  }
}
