:root,
[data-theme="light"] {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #111418;
  --text2: #5b6472;
  --line: #dde1e7;
  --accent: #6a50f5;
  --accent-text: #6a50f5;
  --on-accent: #ffffff;
  --gauge: #6a50f5;
  --track: #e4e6ec;
  --run-bg: #f4f1ff;
  --error: #b42318;
  --error-bg: #fdf0ee;
  --success: #067647;
  --focus: #6a50f5;
  color-scheme: light;
}

[data-theme="dark"] {
  --bg: #111418;
  --surface: #1b1f26;
  --text: #f2f3f5;
  --text2: #9aa3b2;
  --line: #2e3440;
  --accent: #6a50f5;
  --accent-text: #a898ff;
  --on-accent: #ffffff;
  --gauge: #a898ff;
  --track: #2e3440;
  --run-bg: #221e36;
  --error: #ff8a7a;
  --error-bg: #2c1c1c;
  --success: #6ce9a6;
  --focus: #a898ff;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font:
    15px/1.45 "Segoe UI",
    system-ui,
    -apple-system,
    Roboto,
    "Helvetica Neue",
    sans-serif;
  font-variant-numeric: tabular-nums;
}

button {
  font: inherit;
  color: inherit;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.65;
}

[hidden] {
  display: none !important;
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: 4px;
}

.wrap {
  max-width: 1320px;
  margin: 0 auto;
  padding: 0 32px;
}

header.top {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 20px 0;
}

.brand {
  display: flex;
  align-items: center;
  min-height: 44px;
}

.logo {
  display: block;
  width: auto;
  height: 30px;
}

.logo-dark {
  display: none;
}

[data-theme="dark"] .logo-light {
  display: none;
}

[data-theme="dark"] .logo-dark {
  display: block;
}

.ip {
  min-width: 0;
  margin-left: auto;
  text-align: right;
}

.ip span {
  display: block;
  color: var(--text2);
  font-size: 12px;
}

.ip strong {
  display: block;
  overflow-wrap: anywhere;
  font-size: 16px;
  font-weight: 600;
}

.btn {
  min-height: 44px;
  padding: 10px 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  cursor: pointer;
  font-weight: 600;
}

.btn:hover:not(:disabled) {
  border-color: var(--text2);
}

.btn.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--on-accent);
}

.btn.primary:hover:not(:disabled) {
  filter: brightness(1.08);
}

.run {
  display: flex;
  align-items: flex-end;
  gap: 24px;
  padding: 16px 0 20px;
  border-top: 1px solid var(--line);
}

.run h1 {
  margin: 0 0 4px;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.2;
}

.run p {
  max-width: 64ch;
  margin: 0;
  color: var(--text2);
}

.run .btn {
  flex: none;
  min-width: 164px;
  margin-left: auto;
}

.progress {
  height: 4px;
  margin-bottom: 16px;
  overflow: hidden;
  border-radius: 2px;
  background: var(--track);
}

.progress i {
  display: block;
  width: var(--p, 0%);
  height: 100%;
  background: var(--gauge);
  transition: width 0.3s ease;
}

.load-error {
  padding: 16px;
  border: 1px solid var(--error);
  border-radius: 8px;
  background: var(--error-bg);
  color: var(--error);
}

table.nodes {
  width: 100%;
  overflow: hidden;
  border: 1px solid var(--line);
  border-spacing: 0;
  border-collapse: separate;
  border-radius: 12px;
  background: var(--surface);
  table-layout: fixed;
}

.nodes th {
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  color: var(--text2);
  font-size: 13px;
  font-weight: 600;
  text-align: left;
  vertical-align: bottom;
}

.nodes th small {
  display: block;
  font-weight: 400;
}

.nodes td {
  padding: 16px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

.nodes tbody:last-of-type tr:last-child td {
  border-bottom: 0;
}

.nodes tbody.is-run tr.main td {
  background: var(--run-bg);
}

.col-node {
  width: 22%;
}

.col-status {
  width: 17%;
}

.col-m {
  width: 12%;
}

.col-trace {
  width: 13%;
}

.nname {
  overflow-wrap: anywhere;
  font-weight: 600;
}

.nip {
  color: var(--text2);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.tag {
  display: inline-block;
  margin-left: 6px;
  padding: 0 6px;
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--text2);
  font-size: 12px;
  font-weight: 400;
}

.st {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
}

.st .ic {
  position: relative;
  flex: none;
  width: 14px;
  height: 14px;
}

.st.s-wait {
  color: var(--text2);
  font-weight: 400;
}

.st.s-wait .ic {
  border: 2px solid var(--text2);
  border-radius: 50%;
}

.st.s-run .ic {
  border-radius: 50%;
  background: var(--accent);
}

.st.s-done {
  color: var(--success);
}

.st.s-done .ic {
  border: 1.6px solid currentColor;
  border-radius: 50%;
}

.st.s-done .ic::after {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 6px;
  height: 3px;
  border-bottom: 1.8px solid currentColor;
  border-left: 1.8px solid currentColor;
  content: "";
  transform: rotate(-45deg);
}

.st.s-error {
  color: var(--error);
}

.st.s-error .ic {
  border: 1.6px solid currentColor;
  border-radius: 50%;
}

.st.s-error .ic::before {
  position: absolute;
  inset: -2px 0 0;
  content: "!";
  font-size: 11px;
  line-height: 14px;
  text-align: center;
}

.sub {
  display: block;
  margin-top: 2px;
  color: var(--text2);
  font-size: 13px;
}

.errmsg {
  display: block;
  margin-top: 4px;
  color: var(--error);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.retry {
  margin-top: 10px;
  padding: 8px 14px;
  font-size: 14px;
}

.g {
  min-width: 0;
}

.g .v {
  display: block;
  font-size: 17px;
  font-weight: 600;
  white-space: nowrap;
}

.g .v small {
  margin-left: 3px;
  color: var(--text2);
  font-size: 13px;
  font-weight: 400;
}

.g .bar {
  display: block;
  height: 6px;
  margin: 8px 0 6px;
  overflow: hidden;
  border-radius: 3px;
  background: var(--track);
}

.g .bar i {
  display: block;
  width: var(--p, 0%);
  height: 100%;
  border-radius: 3px;
  background: var(--gauge);
  transition: width 0.15s linear;
}

.g .q {
  display: block;
  min-height: 19px;
  color: var(--text2);
  font-size: 13px;
}

.g.none .v {
  color: var(--text2);
  font-weight: 400;
}

.g.fail .v {
  color: var(--error);
  font-size: 15px;
}

.g.live .q {
  color: var(--accent-text);
}

.trbtn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
  font-weight: 600;
}

.trbtn:hover {
  border-color: var(--text2);
}

.trbtn svg {
  width: 12px;
  height: 12px;
  transition: transform 0.2s ease;
}

.trbtn[aria-expanded="true"] svg {
  transform: rotate(180deg);
}

.muted {
  color: var(--text2);
  font-size: 14px;
}

tr.trace td {
  padding: 4px 16px 20px;
}

.trace h3 {
  margin: 0 0 10px;
  font-size: 14px;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.trace h3 span {
  color: var(--text2);
  font-weight: 400;
}

ol.hops {
  display: grid;
  max-width: 760px;
  margin: 0;
  padding: 0;
  gap: 2px;
  list-style: none;
}

ol.hops li {
  display: grid;
  grid-template-columns: 32px minmax(150px, 220px) 80px minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  padding: 6px 0;
  border-top: 1px solid var(--line);
  font-size: 14px;
}

ol.hops .n {
  color: var(--text2);
  text-align: right;
}

ol.hops .addr {
  overflow-wrap: anywhere;
}

ol.hops .rtt {
  text-align: right;
  white-space: nowrap;
}

ol.hops .hb {
  height: 6px;
  overflow: hidden;
  border-radius: 3px;
  background: var(--track);
}

ol.hops .hb i {
  display: block;
  width: var(--p, 0%);
  height: 100%;
  background: var(--gauge);
}

ol.hops li.lost .addr,
ol.hops li.lost .rtt {
  color: var(--text2);
}

.foot {
  max-width: 80ch;
  margin: 16px 0 48px;
  color: var(--text2);
  font-size: 13px;
}

.foot p {
  margin: 0 0 4px;
}

.foot a {
  color: var(--accent-text);
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

@media (max-width: 960px) {
  .wrap {
    padding: 0 20px;
  }

  .run {
    flex-wrap: wrap;
    align-items: stretch;
  }

  .run .btn {
    margin-left: 0;
  }

  table.nodes,
  .nodes tbody,
  .nodes tr,
  .nodes td {
    display: block;
    width: auto;
  }

  table.nodes {
    overflow: visible;
    border: 0;
    border-radius: 0;
    background: none;
  }

  .nodes thead,
  .nodes colgroup {
    display: none;
  }

  .nodes tbody {
    margin-bottom: 12px;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--surface);
  }

  .nodes tr.main {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 16px;
    padding: 16px;
  }

  .nodes tbody.is-run tr.main {
    background: var(--run-bg);
  }

  .nodes tbody.is-run tr.main td {
    background: none;
  }

  .nodes td {
    min-width: 0;
    padding: 0;
    border: 0;
  }

  .nodes td.c-node {
    grid-column: 1 / 3;
  }

  .nodes td.c-status {
    grid-column: 3 / 5;
  }

  .nodes td.c-trace {
    grid-column: 1 / -1;
  }

  .nodes td[data-label]::before {
    display: block;
    margin-bottom: 4px;
    color: var(--text2);
    content: attr(data-label);
    font-size: 12px;
  }

  tr.trace td {
    padding: 0 16px 16px;
  }
}

@media (max-width: 600px) {
  header.top {
    flex-wrap: wrap;
    gap: 12px;
    padding: 16px 0;
  }

  .ip {
    display: flex;
    order: 3;
    align-items: baseline;
    gap: 8px;
    width: 100%;
    text-align: left;
  }

  .ip span {
    display: inline;
  }

  .themebtn {
    margin-left: auto;
  }

  .run h1 {
    font-size: 22px;
  }

  .run .btn {
    width: 100%;
  }

  .nodes tr.main {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px 16px;
  }

  .nodes td.c-node,
  .nodes td.c-status {
    grid-column: 1 / -1;
  }

  ol.hops li {
    grid-template-columns: 24px minmax(0, 1fr) auto;
    gap: 4px 10px;
  }

  ol.hops .hb {
    grid-column: 2 / -1;
  }

  .nodes tbody.is-wait td:not(.c-node):not(.c-status) {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
  }
}
