:root {
  --bg: #0b1220;
  --surface: #131c2e;
  --surface-2: #1a2440;
  --text: #e8edf7;
  --muted: #8a93a8;
  --accent: #4f8fff;
  --accent-press: #3a78e6;
  --ok: #4ade80;
  --warn: #f59e0b;
  --bad: #ef4444;
  --border: #25304b;
  --radius: 14px;
  --pad: 18px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.4 -apple-system, system-ui, "Segoe UI", Roboto, sans-serif;
  min-height: 100dvh;
}

main {
  max-width: 520px;
  margin: 0 auto;
  padding: max(env(safe-area-inset-top), 18px) 18px max(env(safe-area-inset-bottom), 18px);
}

header h1 {
  margin: 0 0 4px;
  font-size: 28px;
  letter-spacing: -0.01em;
}
header .sub {
  margin: 0 0 22px;
  color: var(--muted);
  font-size: 15px;
}

form {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.group {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 14px 16px;
  margin: 0;
  min-width: 0;  /* fieldset default min-width:min-content overflows parents */
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.group legend {
  padding: 0 8px;
  margin-left: -4px;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.field span {
  font-size: 14px;
  color: var(--muted);
  padding-left: 4px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.field.optional span::after {
  content: "";
}

.row {
  display: flex;
  gap: 8px;
}
.row .field {
  flex: 1 1 0;
  min-width: 0;  /* let columns shrink below input min-content */
}
.row .field input {
  width: 100%;
  min-width: 0;
  padding: 12px 10px;
  min-height: 48px;
}
.row .field span {
  font-size: 13px;
  white-space: nowrap;
}
.row .field .unit {
  color: var(--muted);
  opacity: 0.7;
  font-style: normal;
  font-size: 11px;
}

.section-hint {
  margin: 4px 4px 0;
  font-size: 13px;
  color: var(--muted);
}

.hint {
  margin: 4px 4px 0;
  font-size: 12px;
  color: var(--muted);
  font-style: italic;
}

.auto-badge {
  font-style: normal;
  font-size: 11px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  background: rgba(74, 222, 128, 0.15);
  color: var(--ok);
  border: 1px solid rgba(74, 222, 128, 0.35);
  border-radius: 999px;
  padding: 1px 8px;
}
input.auto-filled {
  background: rgba(74, 222, 128, 0.06);
  border-color: rgba(74, 222, 128, 0.3);
}

.segmented {
  display: flex;
  gap: 6px;
}
.segmented label { flex: 1 1 0; min-width: 0; }
.segmented input[type="radio"] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.segmented label {
  text-align: center;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: 600;
  user-select: none;
  transition: background 80ms, border-color 80ms;
}
.segmented input:checked + label {
  background: rgba(79, 143, 255, 0.15);
  border-color: var(--accent);
  color: var(--text);
}
.segmented label.disabled {
  opacity: 0.35;
  pointer-events: none;
}

input, select, button {
  font: inherit;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 14px;
  min-height: 56px;
  -webkit-appearance: none;
  appearance: none;
}

input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79, 143, 255, 0.18);
}

select {
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
                    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 22px) 50%, calc(100% - 16px) 50%;
  background-size: 6px 6px;
  background-repeat: no-repeat;
  padding-right: 36px;
}

button[type="submit"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
  margin-top: 6px;
  cursor: pointer;
  transition: background 80ms ease, transform 80ms ease;
}
button[type="submit"]:active {
  background: var(--accent-press);
  transform: translateY(1px);
}

.result {
  margin-top: 20px;
  padding: 22px;
  border-radius: var(--radius);
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.result.ok    { border-color: rgba(74, 222, 128, 0.4); }
.result.warn  { border-color: rgba(245, 158, 11, 0.5); }
.result.bad   { border-color: rgba(239, 68, 68, 0.5); }

.result .speed {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 6px;
}
.result .speed .num {
  font-size: 64px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1;
}
.result .speed .unit {
  font-size: 22px;
  color: var(--muted);
}
.result .label {
  font-size: 14px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.result .detail {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  font-size: 14px;
  color: var(--muted);
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 6px 14px;
}
.result .detail dt { color: var(--muted); }
.result .detail dd { margin: 0; color: var(--text); }
.result .note {
  margin-top: 12px;
  padding: 10px 12px;
  font-size: 14px;
  border-radius: 8px;
  background: rgba(245, 158, 11, 0.12);
  border: 1px solid rgba(245, 158, 11, 0.3);
}
.result.bad .num { color: var(--bad); }
.result .num.forbidden {
  font-size: 36px;
  letter-spacing: 0.02em;
}
.result.bad .note {
  background: rgba(239, 68, 68, 0.14);
  border-color: rgba(239, 68, 68, 0.4);
}

.chips {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.chip {
  display: grid;
  grid-template-columns: 28px 1fr auto 36px;
  align-items: center;
  gap: 8px;
  padding: 10px 0 10px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  min-height: 48px;
}
.chip-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: rgba(79, 143, 255, 0.18);
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
}
.chip-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip-tab {
  font-size: 11px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 8px;
}
.chip-remove {
  background: transparent;
  border: 0;
  color: var(--muted);
  font-size: 22px;
  padding: 0;
  width: 36px;
  min-height: 36px;
  cursor: pointer;
  border-radius: 8px;
}
.chip-remove:active { background: rgba(239,68,68,0.15); color: var(--bad); }

.result-list {
  list-style: none;
  margin: 16px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.result-row {
  display: grid;
  grid-template-columns: 24px 1fr auto;
  grid-template-areas: "num name speed" "num detail detail";
  align-items: center;
  column-gap: 10px;
  row-gap: 2px;
  padding: 10px 12px;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.result-row.bad    { border-color: rgba(239,68,68,0.4); background: rgba(239,68,68,0.06); }
.result-row.capped { border-color: rgba(245,158,11,0.4); background: rgba(245,158,11,0.05); }
.rr-num    { grid-area: num; display:flex; align-items:center; justify-content:center; width:22px; height:22px; border-radius:50%; background: rgba(79,143,255,0.18); color: var(--accent); font-size: 11px; font-weight: 600; }
.rr-name   { grid-area: name; font-size: 14px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rr-name .muted { color: var(--muted); font-size: 12px; }
.rr-speed  { grid-area: speed; font-weight: 700; font-size: 17px; white-space: nowrap; }
.rr-speed .rr-unit { font-weight: 400; color: var(--muted); font-size: 12px; }
.rr-detail { grid-area: detail; font-size: 12px; color: var(--muted); }
.result-row.bad .rr-speed { color: var(--bad); font-size: 14px; }

.meta {
  margin-top: 28px;
  font-size: 13px;
  color: var(--muted);
}
.meta summary {
  cursor: pointer;
  padding: 6px 0;
}
.meta p {
  margin: 6px 0;
}
