:root {
  color-scheme: dark;
  --bg: #101114;
  --surface: #17181d;
  --surface-2: #1f2027;
  --surface-3: #252630;
  --terminal: #08090d;
  --line: #343642;
  --line-strong: #7c5cff;
  --text: #f1f2f6;
  --muted: #a8abb7;
  --muted-2: #7f8493;
  --accent: #7c5cff;
  --accent-dark: #4a35a6;
  --ok: #3bd17f;
  --warn: #e5b84f;
  --danger: #f46b63;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background: var(--bg);
  font-family: "Segoe UI Variable", "Segoe UI", Roboto, Arial, sans-serif;
  font-style: normal;
}

body::before {
  display: none;
}

button,
input {
  font: inherit;
}

button {
  border: 0;
}

.shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 10px 0 34px;
}

.network-info {
  display: flex;
  flex-wrap: wrap;
  width: 100%;
  max-width: 100%;
  margin: 0;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-bottom-color: #2c2e38;
  border-radius: 8px 8px 0 0;
  color: var(--muted);
  background: var(--surface-2);
  font-size: 14px;
  gap: 8px;
}

.network-info strong {
  color: var(--text);
}

.network-info span {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.network-info i,
.location-status i {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--ok);
}

.network-status.checking i,
.location-status.checking i,
.network-status.timeout i,
.location-status.timeout i {
  background: var(--warn);
}

.network-status.offline i,
.location-status.offline i {
  background: var(--danger);
}

.panel,
.output-wrap {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.panel {
  border-top: 0;
  border-radius: 0 0 8px 8px;
}

form {
  padding: 14px 16px 16px;
}

.form-grid {
  display: grid;
  grid-template-columns: minmax(220px, 0.55fr) minmax(0, 1.45fr) minmax(280px, 0.8fr) minmax(210px, 0.58fr);
  column-gap: 18px;
  row-gap: 14px;
  align-items: end;
}

.target-field {
  grid-column: 1;
}

.locations-field {
  grid-column: 2 / 5;
}

.tools-field {
  grid-column: 1 / 4;
}

.run-field {
  grid-column: 4;
  display: grid;
  gap: 8px;
}

.field {
  display: grid;
  gap: 9px;
}

label,
.label {
  color: var(--muted);
  font-size: 13px;
  font-style: normal;
  font-weight: 500;
}

input[type="text"],
input[type="number"] {
  width: 100%;
  height: 50px;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
  color: var(--text);
  background: #121319;
  padding: 0 15px;
}

input[type="text"]:focus,
input[type="number"]:focus {
  border-color: var(--line-strong);
}

input.invalid {
  border-color: var(--danger);
  background: #211719;
}

.input-error {
  min-height: 16px;
  color: #ffb4ad;
  font-size: 12px;
}

.location-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.location-card,
.tools label {
  min-width: 0;
  cursor: pointer;
}

.location-card input,
.tools input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.location-body,
.tools span {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: var(--surface-2);
}

.location-body {
  display: grid;
  grid-template-columns: 50px minmax(0, 1fr) minmax(92px, auto);
  grid-template-areas:
    "flag copy latency"
    "flag copy status";
  column-gap: 12px;
  row-gap: 9px;
  min-height: 68px;
  align-items: center;
  padding: 16px;
}

.flag {
  position: relative;
  grid-area: flag;
  display: block;
  width: 50px;
  height: 34px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 6px;
  background: #ffffff;
}

.flag::before,
.flag::after {
  position: absolute;
  content: "";
}

.flag-pl::after {
  left: 0;
  right: 0;
  bottom: 0;
  height: 50%;
  background: #dc143c;
}

.flag-fi::before {
  top: 0;
  bottom: 0;
  left: 28%;
  width: 16%;
  background: #003580;
}

.flag-fi::after {
  left: 0;
  right: 0;
  top: 38%;
  height: 18%;
  background: #003580;
}

.flag-de {
  background: #dd0000;
}

.flag-de::before {
  left: 0;
  right: 0;
  top: 0;
  height: 33.333%;
  background: #000000;
}

.flag-de::after {
  left: 0;
  right: 0;
  bottom: 0;
  height: 33.333%;
  background: #ffce00;
}

.flag-nl {
  background: #ffffff;
}

.flag-nl::before {
  left: 0;
  right: 0;
  top: 0;
  height: 33.333%;
  background: #ae1c28;
}

.flag-nl::after {
  left: 0;
  right: 0;
  bottom: 0;
  height: 33.333%;
  background: #21468b;
}

.location-copy {
  grid-area: copy;
  display: grid;
  gap: 2px;
}

.location-copy strong {
  overflow: hidden;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: normal;
}

.location-copy small {
  color: var(--muted);
  font-size: 12px;
}

.location-status {
  display: inline-flex;
  grid-area: status;
  align-items: center;
  justify-self: end;
  gap: 6px;
  color: #9ce5bc;
  font-size: 12px;
  font-weight: 500;
}

.location-status.checking {
  color: #f0cf78;
}

.location-status.timeout,
.location-status.offline {
  color: #ffaaa4;
}

.client-latency {
  grid-area: latency;
  justify-self: end;
  min-width: 78px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  text-align: right;
  white-space: nowrap;
}

.latency-good {
  color: #9ce5bc;
}

.latency-warn {
  color: #f0cf78;
}

.latency-bad {
  color: #ffaaa4;
}

.latency-measuring {
  color: var(--muted);
  font-weight: 500;
}

.tools {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.tools span {
  display: grid;
  min-height: 58px;
  place-items: center;
  padding: 16px 12px;
  font-weight: 600;
}

.location-card input:checked + .location-body,
.tools input:checked + span {
  border-color: var(--line-strong);
  background: #252033;
}

.submit {
  height: 58px;
  width: 100%;
  min-width: 190px;
  border: 1px solid #8b72ff;
  border-radius: 8px;
  color: #ffffff;
  background: var(--accent-dark);
  cursor: pointer;
  font-weight: 600;
}

.submit:hover {
  background: #563dc2;
}

.submit:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

.submit.loading {
  cursor: wait;
}

.run-hint {
  min-height: 16px;
  color: #ffcfca;
  font-size: 12px;
  line-height: 1.35;
}

.advanced {
  display: grid;
  grid-template-rows: auto 0fr;
  margin-top: 14px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.advanced summary {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  width: fit-content;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  cursor: pointer;
  color: #d9dbe4;
  background: var(--surface-2);
  font-size: 13px;
  font-weight: 500;
  list-style: none;
}

.advanced summary::-webkit-details-marker {
  display: none;
}

.advanced summary span::before {
  display: inline-block;
  margin-right: 10px;
  color: var(--accent);
  content: "›";
  font-size: 18px;
  line-height: 1;
}

.advanced[open] {
  grid-template-rows: auto 1fr;
}

.advanced[open] summary span::before {
  content: "⌄";
}

.advanced-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  overflow: hidden;
  margin-top: 12px;
}

.advanced-grid label {
  display: grid;
  gap: 7px;
}

.advanced-grid input {
  height: 44px;
}

.result-context {
  margin: 14px 0 0;
  color: #d9dbe4;
  font-size: 14px;
}

.result-summary {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
  margin: 10px 0 0;
}

.result-summary article {
  grid-column: span 2;
  min-height: 76px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: var(--surface-2);
}

.result-summary article:nth-child(4),
.result-summary article:nth-child(5) {
  grid-column: span 3;
}

.result-summary span {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

.result-summary strong {
  color: var(--text);
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 0;
}

.result-summary .good {
  color: var(--ok);
}

.result-summary .bad {
  color: var(--danger);
}

.output-wrap {
  overflow: hidden;
  margin-top: 14px;
  background: var(--terminal);
}

.output-head {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  min-height: 50px;
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  background: #0f1015;
  font-size: 13px;
}

.window-dots {
  white-space: nowrap;
}

.dot {
  display: inline-block;
  width: 11px;
  height: 11px;
  margin-right: 6px;
  border-radius: 999px;
}

.red {
  background: var(--danger);
}

.amber {
  background: var(--warn);
}

.green {
  background: var(--ok);
}

#meta {
  overflow: hidden;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.terminal-actions {
  display: inline-flex;
  gap: 8px;
}

.terminal-actions button {
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  color: #e9eaf0;
  background: var(--surface-2);
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
}

.terminal-actions button[hidden] {
  display: none;
}

.terminal-actions button:hover {
  border-color: var(--line-strong);
}

.terminal-body {
  min-height: 340px;
  max-height: 620px;
  overflow: auto;
  padding: 18px;
  color: #e9eaf0;
  background: var(--terminal);
  font: 14px/1.6 "Cascadia Mono", "Consolas", "Liberation Mono", monospace;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
}

.terminal-line {
  width: max-content;
  min-width: 100%;
  white-space: pre;
  tab-size: 4;
}

.terminal-snapshot {
  width: max-content;
  min-width: 100%;
}

.mtr-row {
  white-space: pre;
}

.mtr-row-updated {
  animation: mtr-row-flash 420ms ease-out;
}

@keyframes mtr-row-flash {
  0% {
    background: rgba(124, 92, 255, 0.24);
    color: #ffffff;
  }

  100% {
    background: transparent;
    color: inherit;
  }
}

.line-good {
  color: #9ce5bc;
}

.line-warn {
  color: #f0cf78;
}

.line-bad {
  color: #ffaaa4;
}

.empty-state {
  color: var(--muted);
  white-space: normal;
}

.cursor,
.terminal-body.running::after {
  display: inline-block;
  width: 8px;
  height: 16px;
  margin-left: 4px;
  background: var(--accent);
  vertical-align: -2px;
  content: "";
}

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

  .target-field,
  .locations-field {
    grid-column: 1 / -1;
  }

  .location-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .tools-field {
    grid-column: 1;
  }

  .run-field {
    grid-column: 2;
  }

  .submit {
    width: 100%;
  }

  .result-summary {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .shell {
    width: min(100% - 22px, 1180px);
    padding-top: 8px;
  }

  .form-grid {
    grid-template-columns: 1fr;
    row-gap: 16px;
  }

  .target-field,
  .locations-field,
  .tools-field,
  .run-field {
    grid-column: 1;
  }

  .network-info {
    width: 100%;
    border-radius: 8px 8px 0 0;
    white-space: normal;
  }

  .location-grid,
  .advanced-grid {
    grid-template-columns: 1fr;
  }

  .result-summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .result-summary article,
  .result-summary article:nth-child(4),
  .result-summary article:nth-child(5) {
    grid-column: auto;
    min-height: 70px;
    padding: 12px;
  }

  .result-summary article:nth-child(5) {
    grid-column: 1 / -1;
  }

  .result-summary span {
    margin-bottom: 6px;
    font-size: 11px;
  }

  .result-summary strong {
    font-size: 19px;
  }

  .tools {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
  }

  .tools span {
    min-height: 52px;
    padding: 12px 8px;
    overflow: hidden;
    font-size: 13px;
    text-align: center;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .location-body {
    grid-template-columns: 50px minmax(0, 1fr) auto;
    min-height: 68px;
  }

  .submit {
    height: 54px;
    min-width: 0;
  }

  .run-hint {
    min-height: auto;
  }

  .output-head {
    grid-template-columns: 1fr;
    align-items: start;
    padding: 12px 14px;
  }

  #meta {
    width: 100%;
    text-align: left;
    white-space: normal;
  }

  .terminal-actions {
    display: grid;
    width: 100%;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .terminal-actions button {
    padding: 0 8px;
  }

  .terminal-body {
    min-height: 300px;
    font-size: 13px;
  }
}
