:root {
  color-scheme: light;
  --ink: #121314;
  --muted: #69707a;
  --line: #d9dde3;
  --paper: #f7f4ef;
  --panel: #ffffff;
  --black: #101112;
  --green: #13a66f;
  --green-deep: #087452;
  --yellow: #efff6a;
  --soft-yellow: #fff6be;
  --coral: #ef6b4f;
  --blue: #2468d2;
  --shadow: 0 18px 50px rgba(16, 17, 18, .1);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(135deg, rgba(19, 166, 111, .14), transparent 30%),
    linear-gradient(225deg, rgba(239, 107, 79, .14), transparent 32%),
    var(--paper);
  color: var(--ink);
  letter-spacing: 0;
}

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

button {
  cursor: pointer;
}

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

.control-rail {
  min-height: 100vh;
  background: var(--black);
  color: #fff;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

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

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  background:
    radial-gradient(circle at 71% 25%, #fff 0 6px, transparent 7px),
    linear-gradient(135deg, var(--green), var(--yellow) 52%, var(--coral));
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .18);
}

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

.brand strong {
  font-size: 15px;
  line-height: 1.1;
}

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

.checker-form {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, .13);
  border-radius: 8px;
  background: rgba(255, 255, 255, .06);
}

.checker-form label {
  color: #d8dde4;
  font-size: 13px;
  font-weight: 700;
}

.input-wrap {
  display: grid;
  grid-template-columns: 28px 1fr;
  align-items: center;
  min-height: 46px;
  background: #fff;
  border: 1px solid transparent;
  border-radius: 8px;
  overflow: hidden;
}

.input-wrap:focus-within {
  border-color: var(--yellow);
  box-shadow: 0 0 0 3px rgba(239, 255, 106, .2);
}

.input-wrap span {
  color: #727982;
  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;
}

.primary-btn,
.icon-btn,
.segmented 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: var(--yellow);
  color: #101112;
  font-weight: 800;
}

.primary-btn:hover,
.segmented button.active {
  filter: saturate(1.08);
}

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

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

.status-panel {
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, .13);
  padding: 14px;
  color: #cbd0d8;
  background: rgba(255, 255, 255, .05);
}

.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: 9px;
  height: 9px;
  border-radius: 999px;
  background: var(--muted);
}

.status-line.active span {
  background: var(--green);
  box-shadow: 0 0 0 6px rgba(19, 166, 111, .16);
}

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

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

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

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  background: rgba(255, 255, 255, .08);
  border-radius: 8px;
  padding: 3px;
}

.segmented button {
  min-height: 36px;
  background: transparent;
  color: #d8dde4;
  font-weight: 800;
}

.segmented button.active {
  background: #fff;
  color: var(--black);
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  background: rgba(255, 255, 255, .09);
  color: #fff;
}

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

.workspace {
  display: grid;
  grid-template-columns: minmax(420px, 1.05fr) minmax(330px, .72fr);
  gap: 18px;
  padding: 18px;
  min-width: 0;
}

.stage,
.inspector {
  min-width: 0;
  background: rgba(255, 255, 255, .76);
  border: 1px solid rgba(18, 19, 20, .1);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.stage {
  display: grid;
  grid-template-rows: auto 1fr;
  overflow: hidden;
}

.stage-toolbar {
  min-height: 78px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--green-deep);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.stage-toolbar h1 {
  margin: 0;
  font-size: clamp(25px, 3vw, 44px);
  line-height: 1;
}

.mode-pill {
  flex: 0 0 auto;
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  padding: 0 12px;
  background: var(--black);
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  max-width: 180px;
}

.mode-pill.live {
  background: var(--green);
}

.mode-pill.partial {
  background: var(--coral);
}

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

#connectionCanvas {
  width: min(100%, calc(100vh - 150px));
  max-width: 880px;
  aspect-ratio: 1;
  height: auto;
  border-radius: 8px;
  background: var(--paper);
  box-shadow: 0 18px 45px rgba(18, 19, 20, .16);
}

.inspector {
  display: grid;
  grid-template-rows: auto auto 1fr;
  max-height: calc(100vh - 36px);
  overflow: hidden;
}

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

.tab-row button {
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
}

.tab-row button.active {
  background: var(--black);
  color: #fff;
}

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

.metric {
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  padding: 10px;
  min-height: 72px;
}

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

.metric span {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

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

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

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

.rank-item,
.signal-card,
.stat-card {
  list-style: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 10px;
}

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

.rank-number {
  color: var(--muted);
  font-weight: 900;
  text-align: right;
}

.avatar {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 900;
  overflow: hidden;
  background: hsl(var(--hue, 150) 65% 43%);
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

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

.rank-main strong {
  display: block;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.rank-main span {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.score-pill {
  min-width: 52px;
  min-height: 32px;
  border-radius: 8px;
  display: inline-grid;
  place-items: center;
  padding: 0 8px;
  background: var(--soft-yellow);
  color: #564400;
  font-weight: 900;
  font-size: 13px;
}

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

.signal-card p,
.stat-card p {
  margin: 6px 0 0;
  color: var(--muted);
  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(420px, calc(100vw - 32px));
  background: var(--black);
  color: #fff;
  border-radius: 8px;
  padding: 10px 12px;
  box-shadow: var(--shadow);
  transition: opacity .18s ease, transform .18s ease;
  font-size: 13px;
  font-weight: 700;
}

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

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

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

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

  .status-panel {
    display: none;
  }

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

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

  .inspector {
    max-height: none;
  }

  #connectionCanvas {
    width: min(100%, 780px);
  }
}

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

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

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

  .canvas-wrap {
    padding: 10px;
  }

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

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

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