:root {
  --bg: #f3f4f6;
  --panel: #ffffff;
  --panel-2: #f8f9fb;
  --line: #e2e5ea;
  --text: #14171c;
  --muted: #667085;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --ok: #15803d;
  --ok-bg: #dcfce7;
  --warn: #a15c07;
  --warn-bg: #fef3c7;
  --bad: #b42318;
  --bad-bg: #fee4e2;
  --relay: #6d28d9;
  --relay-bg: #ede9fe;
  --c1: #2563eb;
  --c2: #16a34a;
  --c3: #ea580c;
  --c4: #9333ea;
  --c5: #dc2626;
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1116;
    --panel: #161a21;
    --panel-2: #1c212a;
    --line: #2a303b;
    --text: #e6e8ec;
    --muted: #9099a8;
    --accent: #3b82f6;
    --ok: #4ade80;
    --ok-bg: #12321f;
    --warn: #fbbf24;
    --warn-bg: #3a2c0b;
    --bad: #f87171;
    --bad-bg: #3b1515;
    --relay: #c4b5fd;
    --relay-bg: #2e2150;
    --c1: #60a5fa;
    --c2: #4ade80;
    --c3: #fb923c;
    --c4: #c084fc;
    --c5: #f87171;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

[hidden] { display: none !important; }

button, input, select, textarea { font: inherit; color: inherit; }

.mono { font-family: var(--mono); }

/* top bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--relay);
  color: var(--panel);
  font-weight: 700;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-sub { color: var(--muted); font-size: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; flex: 1; justify-content: center; }
.chip {
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  font-size: 12px;
  font-family: var(--mono);
  white-space: nowrap;
}
.chip.ok { color: var(--ok); background: var(--ok-bg); border-color: transparent; }
.chip.warn { color: var(--warn); background: var(--warn-bg); border-color: transparent; }
.chip.bad { color: var(--bad); background: var(--bad-bg); border-color: transparent; }
.chip.relay { color: var(--relay); background: var(--relay-bg); border-color: transparent; }

.banner {
  margin: 12px 18px 0;
  padding: 10px 14px;
  border-radius: var(--radius);
  background: var(--warn-bg);
  color: var(--warn);
}

/* layout */
.layout {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  gap: 16px;
  padding: 16px 18px 40px;
  align-items: start;
}
.sidebar {
  position: sticky;
  top: 70px;
  max-height: calc(100vh - 86px);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-right: 2px;
}
.content { display: flex; flex-direction: column; gap: 14px; min-width: 0; }

@media (max-width: 1000px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: static; max-height: none; overflow: visible; }
  .topbar { flex-wrap: wrap; }
  .chips { order: 3; flex-basis: 100%; justify-content: flex-start; }
}

/* panels & fields */
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0 14px;
}
.panel > summary {
  cursor: pointer;
  padding: 12px 0;
  font-weight: 600;
  list-style: none;
  display: flex;
  justify-content: space-between;
}
.panel > summary::-webkit-details-marker { display: none; }
.panel > summary::after { content: "▾"; color: var(--muted); }
.panel:not([open]) > summary::after { content: "▸"; }
.panel[open] { padding-bottom: 14px; }

.field { display: flex; flex-direction: column; gap: 4px; margin-top: 10px; min-width: 0; }
.field > span { font-size: 12px; color: var(--muted); }
.field input, .field select, .field textarea {
  width: 100%;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel-2);
}
.field textarea { resize: vertical; font-family: var(--mono); font-size: 12px; }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent);
  border-color: var(--accent);
}
.check { display: flex; align-items: center; gap: 8px; margin-top: 12px; cursor: pointer; }

.grid2, .grid3 { display: grid; gap: 0 10px; }
.grid2 { grid-template-columns: 1fr 1fr; }
.grid3 { grid-template-columns: 1fr 1fr 1.4fr; }
.span2 { grid-column: span 2; }
.span3 { grid-column: span 3; }

.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.seg label {
  display: flex;
  justify-content: center;
  padding: 7px;
  border: 1px solid var(--line);
  border-radius: 7px;
  cursor: pointer;
  text-align: center;
  font-size: 13px;
}
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label:has(input:checked) { border-color: var(--accent); color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent); font-weight: 600; }

.hint { color: var(--muted); font-size: 12px; margin: 8px 0 0; }
.steps { margin: 4px 0 0; padding-left: 18px; color: var(--muted); font-size: 12px; }
.steps li { margin: 2px 0; }

.sub { margin-top: 10px; }
.sub > summary { cursor: pointer; font-size: 12px; color: var(--muted); }
.code {
  margin: 6px 0 0;
  padding: 8px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 7px;
  font: 11px/1.4 var(--mono);
  overflow-x: auto;
  max-height: 260px;
}

/* buttons */
.btn-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.btn {
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel-2);
  cursor: pointer;
  font-weight: 500;
  white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn:disabled { opacity: .55; cursor: progress; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.danger { color: var(--bad); }
.btn.active { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.btn.small { padding: 4px 9px; font-size: 12px; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.toolbar .sep { width: 1px; align-self: stretch; background: var(--line); margin: 0 4px; }

/* video */
.videos { display: grid; grid-template-columns: 2fr 1fr; gap: 12px; }
@media (max-width: 700px) { .videos { grid-template-columns: 1fr; } }
.video {
  position: relative;
  margin: 0;
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
}
.video video { width: 100%; height: 100%; object-fit: contain; display: block; }
.video figcaption, .video .overlay {
  position: absolute;
  padding: 3px 8px;
  border-radius: 6px;
  background: rgba(0, 0, 0, .55);
  color: #fff;
  font-size: 12px;
}
.video figcaption { top: 8px; left: 8px; }
.video .overlay { bottom: 8px; left: 8px; right: 8px; font-family: var(--mono); font-size: 11px; width: fit-content; max-width: calc(100% - 16px); }
.video .overlay:empty { display: none; }
.video .play { position: absolute; inset: 50% auto auto 50%; transform: translate(-50%, -50%); }

/* cards */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 12px; }
.cards.charts { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.cards.two { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  min-width: 0;
}
.cards .card.span2 { grid-column: span 2; }
@media (max-width: 640px) { .cards .card.span2 { grid-column: auto; } }
.card h3 { margin: 0 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.card-head { display: flex; justify-content: space-between; align-items: center; }
.card-head h3 { margin: 0; }

.kv {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 4px 12px;
  margin: 0;
  font-size: 13px;
}
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-family: var(--mono); font-size: 12px; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.route-relay { color: var(--relay); font-weight: 700; }
.route-p2p { color: var(--ok); font-weight: 700; }

canvas { width: 100%; height: 150px; display: block; }
.legend { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); margin-top: 4px; }
.sw { width: 12px; height: 3px; border-radius: 2px; display: inline-block; }
.sw + span { margin-right: 8px; }
.sw.c1 { background: var(--c1); }
.sw.c2 { background: var(--c2); }
.sw.c3 { background: var(--c3); }
.sw.c4 { background: var(--c4); }
.sw.c5 { background: var(--c5); }

/* tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
th, td { text-align: left; padding: 5px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 500; }
td { font-family: var(--mono); }
td.empty { color: var(--muted); text-align: center; font-family: inherit; }
td.wrap { white-space: normal; min-width: 180px; }
tr.selected td { background: color-mix(in srgb, var(--ok) 12%, transparent); }
.t-relay { color: var(--relay); font-weight: 600; }
.t-srflx { color: var(--c3); }
.t-prflx { color: var(--c4); }
.t-host { color: var(--muted); }
.res-ok { color: var(--ok); font-weight: 600; }
.res-bad { color: var(--bad); font-weight: 600; }
.res-run { color: var(--muted); }

/* log */
.log {
  margin-top: 8px;
  height: 260px;
  overflow: auto;
  padding: 8px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 7px;
  font: 11.5px/1.5 var(--mono);
}
.log-line { white-space: pre-wrap; overflow-wrap: anywhere; }
.log-line .ts { color: var(--muted); margin-right: 8px; }
.log-warn { color: var(--warn); }
.log-error { color: var(--bad); }
.log-ok { color: var(--ok); }
.log-debug { color: var(--muted); }
