/* speed.pipiska.fun — строгая тёмная тема */

*,
*::before,
*::after { box-sizing: border-box; }

:root {
  --bg: #0a0b0d;
  --surface: #101215;
  --surface-2: #15181c;
  --line: #20242a;
  --line-2: #2b3038;
  --text: #e8ebf0;
  --muted: #8b929e;
  --dim: #5f6672;
  --accent: #6ea8fe;
  --accent-soft: #16202e;
  --radius: 12px;
  color-scheme: dark;
}

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100svh;
  background:
    radial-gradient(900px 420px at 50% -140px, rgba(110, 168, 254, 0.06), transparent 70%),
    var(--bg);
  color: var(--text);
  font-family: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button,
input { font: inherit; }

.shell {
  width: min(1040px, 100% - 40px);
  margin: 0 auto;
  padding: 30px 0 48px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

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

/* ----------------------------------------------------------- шапка ----- */
.head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 2px 2px 6px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  border: 1px solid var(--line-2);
  border-radius: 9px;
  background:
    linear-gradient(var(--accent), var(--accent)) center / 1px 15px no-repeat,
    linear-gradient(var(--accent), var(--accent)) center / 15px 1px no-repeat,
    var(--surface-2);
}

.brand-text h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.brand-text p {
  margin: 1px 0 0;
  font-size: 10px;
  color: var(--dim);
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.head-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 11.5px;
  color: var(--muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #3f9c6a;
}

/* --------------------------------------------------------- кнопки ------ */
.btn {
  appearance: none;
  cursor: pointer;
  border-radius: 8px;
  border: 1px solid transparent;
  font-weight: 600;
  transition: background 0.15s, border-color 0.15s, color 0.15s, opacity 0.15s;
}
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn-primary {
  background: #e9edf4;
  border-color: #e9edf4;
  color: #0b0d10;
}
.btn-primary:hover { background: #ffffff; border-color: #ffffff; }
.btn-primary:active { background: #d6dbe4; border-color: #d6dbe4; }
.btn-primary:disabled { opacity: 0.5; cursor: default; }

.btn-secondary {
  background: transparent;
  border-color: var(--line-2);
  color: var(--text);
}
.btn-secondary:hover { border-color: #3a414b; background: #14171b; }
.btn-secondary:active { background: #191d22; }

.btn-sm {
  padding: 6px 11px;
  font-size: 11.5px;
  font-weight: 500;
  border-radius: 6px;
}

.btn-run {
  min-width: 178px;
  padding: 12px 22px;
  font-size: 14px;
  border-radius: 8px;
}
.btn-run.running {
  background: transparent;
  border-color: #4a3034;
  color: #ff8a8a;
}
.btn-run.running:hover { background: #1c1416; border-color: #6b3b41; }

.link {
  appearance: none;
  border: 0;
  background: none;
  padding: 0;
  color: var(--dim);
  font-size: 11.5px;
  cursor: pointer;
  transition: color 0.15s;
}
.link:hover { color: var(--text); }
.link:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 2px; }

/* --------------------------------------------------------- главный ----- */
.run {
  display: grid;
  grid-template-columns: minmax(280px, 400px) minmax(0, 1fr);
  align-items: center;
  gap: 28px;
  padding: 26px 28px;
}

.gauge {
  position: relative;
  width: min(320px, 74vw);
  aspect-ratio: 1;
  margin: 0 auto;
}
.gauge-svg { width: 100%; height: 100%; display: block; }

.gauge-track,
.gauge-arc {
  fill: none;
  stroke-width: 4;
  stroke-linecap: round;
  stroke-dasharray: 100px;
}
.gauge-track { stroke: #1e232a; }
.gauge-arc {
  stroke: var(--accent);
  stroke-dashoffset: 100px;
  opacity: 0;
}
.gauge-dot { fill: var(--accent); }

.readout {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding-top: 8px;
  pointer-events: none;
  text-align: center;
}
.readout .value {
  font-size: clamp(44px, 10vw, 62px);
  font-weight: 600;
  line-height: 1;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}
.readout .unit {
  margin-top: 6px;
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}
.readout .phase {
  margin-top: 14px;
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  border: 1px solid var(--line-2);
  border-radius: 4px;
  padding: 3px 8px;
  background: rgba(255, 255, 255, 0.015);
}
.readout .phase.ping { color: #9fb6d6; }
.readout .phase.upload { color: #c9b6e0; }

.ticks {
  position: absolute;
  left: 7%;
  right: 7%;
  bottom: 1%;
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: var(--dim);
  font-variant-numeric: tabular-nums;
}

.run-side {
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.run-actions {
  display: flex;
  align-items: center;
  gap: 16px;
}

.timer {
  font-size: 13px;
  color: var(--dim);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
}

.bar {
  height: 3px;
  margin: 20px 0;
  border-radius: 999px;
  background: #1d2127;
  overflow: hidden;
}
.bar > span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--accent);
  border-radius: inherit;
  transition: width 0.15s linear;
}

.run-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin: 0;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}
.run-stats dt {
  font-size: 10px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--dim);
}
.run-stats dd {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.run-note {
  margin: 22px 0 0;
  font-size: 12px;
  line-height: 1.6;
  color: var(--dim);
  max-width: 46ch;
}

/* ------------------------------------------------------- результаты ---- */
.results {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.result {
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 15px 18px;
  border-right: 1px solid var(--line);
  min-width: 0;
}
.result:last-child { border-right: 0; }

.result-label {
  font-size: 10px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.result-value {
  display: flex;
  align-items: baseline;
  gap: 5px;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
}
.result-value b {
  font-size: 25px;
  font-weight: 600;
  letter-spacing: -0.02em;
}
.result-value small {
  font-size: 11px;
  color: var(--muted);
  font-weight: 400;
}

.result.filled { background: rgba(110, 168, 254, 0.035); }
.result.filled .result-value b { color: #f2f5fa; }
.result[data-kind="extra"] .result-value b { font-size: 17px; }

/* ---------------------------------------------------------- график ----- */
.chart-panel { padding: 18px 20px 12px; }

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.panel-head h2 {
  margin: 0;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}
.hint {
  font-size: 11px;
  color: var(--dim);
  font-variant-numeric: tabular-nums;
}

#chart { width: 100%; height: 160px; display: block; }

/* -------------------------------------------------------- настройки ---- */
.settings-panel { padding: 18px 20px 20px; }

.settings {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 22px 28px;
  padding-top: 4px;
}

.field {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.field-wide { grid-column: 1 / -1; }

.label {
  font-size: 10.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 9px;
}

.segmented {
  display: inline-flex;
  align-self: flex-start;
  max-width: 100%;
  border: 1px solid var(--line-2);
  border-radius: 8px;
  overflow: hidden;
  background: #0c0e11;
  flex-wrap: wrap;
}
.seg {
  appearance: none;
  border: 0;
  border-right: 1px solid var(--line-2);
  background: transparent;
  color: var(--dim);
  padding: 8px 14px;
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.seg:last-child { border-right: 0; }
.seg:hover { color: var(--text); background: #12151a; }
.seg.on {
  background: var(--accent-soft);
  color: #d8e6ff;
  box-shadow: inset 0 -2px 0 var(--accent);
}
.seg:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

input[type="number"] {
  appearance: textfield;
  width: 92px;
  background: #0c0e11;
  border: 1px solid var(--line-2);
  border-radius: 6px;
  color: var(--text);
  padding: 8px 10px;
  font-size: 13.5px;
  font-variant-numeric: tabular-nums;
  text-align: center;
  transition: border-color 0.15s;
}
input[type="number"]:focus { outline: none; border-color: var(--accent); }
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button { appearance: none; margin: 0; }

.input-line {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.presets { display: flex; gap: 4px; flex-wrap: wrap; }
.presets button {
  appearance: none;
  background: transparent;
  border: 1px solid var(--line-2);
  border-radius: 5px;
  color: var(--dim);
  font-size: 11px;
  padding: 5px 9px;
  cursor: pointer;
  font-variant-numeric: tabular-nums;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.presets button:hover { color: var(--text); border-color: #3a414b; }
.presets button.active { color: var(--accent); border-color: rgba(110, 168, 254, 0.55); background: rgba(110, 168, 254, 0.07); }

.help {
  margin: 8px 0 0;
  font-size: 11.5px;
  line-height: 1.55;
  color: var(--dim);
}

.check {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12.5px;
  color: var(--muted);
  cursor: pointer;
  padding-top: 2px;
}
.check input {
  width: 15px;
  height: 15px;
  accent-color: var(--accent);
  cursor: pointer;
}

.estimate {
  margin: 22px 0 0;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  font-size: 11.5px;
  color: var(--dim);
  font-variant-numeric: tabular-nums;
}

/* --------------------------------------------------------- история ----- */
.history-panel { padding: 18px 20px 8px; }

.history-list { display: flex; flex-direction: column; }

.history-empty {
  padding: 8px 0 16px;
  font-size: 12.5px;
  color: var(--dim);
}

.history-row {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr) auto auto auto;
  align-items: center;
  gap: 16px;
  padding: 11px 0;
  border-top: 1px solid var(--line);
  font-size: 12.5px;
}
.history-date {
  color: var(--dim);
  font-variant-numeric: tabular-nums;
  font-size: 11.5px;
  white-space: nowrap;
}
.history-mode {
  color: var(--dim);
  font-size: 11.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.history-metric {
  font-variant-numeric: tabular-nums;
  font-weight: 500;
  white-space: nowrap;
  color: var(--text);
}
.history-metric.down { color: #a9c8f5; }
.history-metric.up { color: #b9aede; }
.history-metric.ping { color: var(--muted); }

/* ---------------------------------------------------------- подвал ----- */
.foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 2px 0;
  font-size: 10.5px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--dim);
}

/* ----------------------------------------------------------- тост ----- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 8px);
  z-index: 50;
  background: var(--surface-2);
  border: 1px solid var(--line-2);
  border-radius: 8px;
  color: var(--text);
  font-size: 12.5px;
  padding: 10px 16px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s, transform 0.18s;
  max-width: calc(100vw - 32px);
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* -------------------------------------------------------- адаптив ----- */
@media (max-width: 820px) {
  .run {
    grid-template-columns: 1fr;
    gap: 20px;
    padding: 22px 20px;
    text-align: left;
  }
  .gauge { width: min(280px, 76vw); }
  .results { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .result:nth-child(2) { border-right: 0; }
  .result:nth-child(-n + 2) { border-bottom: 1px solid var(--line); }
}

@media (max-width: 620px) {
  .shell { width: calc(100% - 24px); padding: 20px 0 36px; gap: 12px; }
  .brand-text p { display: none; }
  .status { display: none; }
  .settings { grid-template-columns: 1fr; gap: 20px; }
  .field-wide { grid-column: auto; }
  .segmented {
    display: grid;
    grid-template-columns: 1fr;
    width: 100%;
    align-self: stretch;
  }
  .seg {
    border-right: 0;
    border-bottom: 1px solid var(--line-2);
    text-align: left;
  }
  .seg:last-child { border-bottom: 0; }
  .history-row {
    grid-template-columns: 1fr auto auto;
    gap: 10px;
  }
  .history-mode { display: none; }
  .history-metric.ping { display: none; }
  .btn-run { flex: 1 1 auto; min-width: 0; }
  .timer { margin-left: 0; }
  .foot { flex-direction: column; align-items: flex-start; gap: 4px; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}
