:root {
  --bg-canvas: #090c12;
  --bg-surface: #111622;
  --bg-surface-2: #171e2e;
  --border-subtle: rgba(148, 163, 184, 0.14);
  --border-strong: rgba(148, 163, 184, 0.28);

  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --teal: #14b8a6;
  --teal-bright: #2dd4bf;
  --teal-soft: rgba(20, 184, 166, 0.14);

  --amber: #f59e0b;
  --amber-bright: #fbbf24;
  --amber-soft: rgba(245, 158, 11, 0.14);

  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, 0.12);

  --font-sans: "PingFang SC", "Noto Sans SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: ui-monospace, "SFMono-Regular", Menlo, Monaco, Consolas, monospace;

  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
}

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

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background-color: var(--bg-canvas);
  color: var(--text-primary);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Atmospheric dark ink backdrop */
.backdrop {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}

.backdrop-grid {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(to right, rgba(148, 163, 184, 0.04) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(148, 163, 184, 0.04) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: radial-gradient(ellipse 80% 70% at 50% 25%, #000 40%, transparent 100%);
}

.backdrop-glow {
  position: absolute;
  border-radius: 999px;
  filter: blur(110px);
  opacity: 0.34;
}

.backdrop-glow--teal {
  width: 460px;
  height: 460px;
  top: -140px;
  left: -100px;
  background: radial-gradient(circle, rgba(20, 184, 166, 0.45), transparent 70%);
}

.backdrop-glow--amber {
  width: 420px;
  height: 420px;
  bottom: -140px;
  right: -80px;
  background: radial-gradient(circle, rgba(245, 158, 11, 0.32), transparent 70%);
}

.app-shell {
  position: relative;
  z-index: 1;
  max-width: 820px;
  min-height: 100vh;
  margin: 0 auto;
  padding: 24px 20px 32px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

/* Header */
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

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

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 11px;
  background: linear-gradient(145deg, #161d2b, #0e131d);
  border: 1px solid var(--border-subtle);
  display: grid;
  place-items: center;
  color: var(--text-primary);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.35);
}

.brand-mark svg {
  width: 26px;
  height: 26px;
}

.brand-badge {
  display: inline-flex;
  align-items: center;
  margin: 0 0 4px;
  padding: 1px 8px;
  border-radius: 999px;
  border: 1px solid var(--border-subtle);
  background: rgba(20, 184, 166, 0.12);
  color: var(--teal);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  line-height: 1.5;
}

.brand-title {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1.2;
}

.brand-subtitle {
  margin: 2px 0 0;
  font-size: 0.82rem;
  color: var(--text-secondary);
  letter-spacing: 0.04em;
}

.node-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 13px;
  border-radius: 999px;
  background: rgba(17, 22, 34, 0.85);
  border: 1px solid var(--border-subtle);
  font-size: 0.82rem;
  color: var(--text-secondary);
}

.node-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--teal);
  box-shadow: 0 0 8px rgba(20, 184, 166, 0.8);
}

.node-dot--warn {
  background: var(--amber);
  box-shadow: 0 0 8px rgba(245, 158, 11, 0.8);
}

.node-dot--err {
  background: var(--danger);
  box-shadow: 0 0 8px rgba(248, 113, 113, 0.8);
}

/* Main telemetry card */
.main-content {
  display: flex;
  flex-direction: column;
  gap: 20px;
  flex: 1;
}

.telemetry-card {
  background: linear-gradient(180deg, rgba(20, 26, 40, 0.92), rgba(14, 18, 28, 0.96));
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 24px 24px 28px;
  box-shadow:
    0 24px 55px rgba(0, 0, 0, 0.45),
    inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.phase-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.phase-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  background: rgba(148, 163, 184, 0.12);
  color: var(--text-primary);
  border: 1px solid rgba(148, 163, 184, 0.22);
  transition: background-color 0.25s ease, color 0.25s ease, border-color 0.25s ease;
}

.phase-badge[data-phase="ping"] {
  background: rgba(148, 163, 184, 0.16);
  color: #e2e8f0;
  border-color: rgba(245, 158, 11, 0.45);
}

.phase-badge[data-phase="download"] {
  background: var(--teal-soft);
  color: var(--teal-bright);
  border-color: rgba(45, 212, 191, 0.42);
}

.phase-badge[data-phase="upload"] {
  background: var(--amber-soft);
  color: var(--amber-bright);
  border-color: rgba(251, 191, 36, 0.42);
}

.phase-badge[data-phase="done"] {
  background: var(--teal-soft);
  color: var(--teal-bright);
  border-color: rgba(45, 212, 191, 0.35);
}

.phase-badge[data-phase="error"] {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: rgba(248, 113, 113, 0.38);
}

.phase-detail {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

/* Gauge */
.gauge-stage {
  position: relative;
  width: 100%;
  max-width: 440px;
  margin: 4px auto 0;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.horizon-gauge {
  width: 100%;
  height: auto;
  display: block;
  overflow: visible;
}

.gauge-outer-ring {
  stroke: rgba(148, 163, 184, 0.12);
  stroke-width: 1.2;
  stroke-dasharray: 4 6;
}

.gauge-track {
  stroke: rgba(148, 163, 184, 0.13);
  stroke-width: 15;
  stroke-linecap: round;
}

.gauge-progress {
  stroke-width: 15;
  stroke-linecap: round;
  transition: stroke 0.25s ease;
}

.gauge-pointer {
  fill: #f8fafc;
  stroke: #090c12;
  stroke-width: 2.5;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.gauge-pointer--visible {
  opacity: 1;
}

.gauge-tick {
  stroke: rgba(148, 163, 184, 0.35);
  stroke-width: 1.5;
}

.gauge-tick--major {
  stroke: rgba(226, 232, 240, 0.55);
  stroke-width: 2;
}

.gauge-tick-label {
  fill: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 10.5px;
  text-anchor: middle;
  user-select: none;
}

.gauge-readout {
  position: absolute;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  text-align: center;
  pointer-events: none;
  width: 72%;
}

.readout-value {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: clamp(2.5rem, 6vw, 3.6rem);
  font-weight: 700;
  line-height: 1.02;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.readout-unit {
  margin-top: 4px;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 0.04em;
}

.readout-caption {
  margin-top: 4px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Telemetry strip */
.telemetry-strip {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.step-pills {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.step-pill {
  background: rgba(9, 12, 18, 0.55);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  transition: border-color 0.25s ease, background-color 0.25s ease;
}

.step-pill[data-state="active"] {
  border-color: rgba(45, 212, 191, 0.5);
  background: rgba(20, 184, 166, 0.08);
}

#step-upload[data-state="active"] {
  border-color: rgba(251, 191, 36, 0.5);
  background: rgba(245, 158, 11, 0.08);
}

.step-pill[data-state="done"] {
  border-color: rgba(148, 163, 184, 0.28);
}

.step-pill-label {
  font-size: 0.82rem;
  color: var(--text-secondary);
}

.step-pill-val {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--text-primary);
}

.sparkline-wrap {
  height: 54px;
  border-radius: var(--radius-sm);
  background: rgba(9, 12, 18, 0.55);
  border: 1px solid rgba(148, 163, 184, 0.1);
  overflow: hidden;
  padding: 4px 6px;
}

#throughput-sparkline {
  width: 100%;
  height: 100%;
  display: block;
}

/* Error banner */
.error-banner {
  margin-top: 16px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--danger-soft);
  border: 1px solid rgba(248, 113, 113, 0.35);
  color: #fecaca;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.9rem;
}

.error-banner[hidden] {
  display: none;
}

.error-icon {
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(248, 113, 113, 0.25);
  color: #fca5a5;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 0.85rem;
}

/* Action bar */
.action-bar {
  margin-top: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.btn-start {
  position: relative;
  min-width: 200px;
  height: 54px;
  padding: 0 32px;
  border: 1px solid rgba(45, 212, 191, 0.45);
  border-radius: 999px;
  background: linear-gradient(135deg, #0f766e, #14b8a6);
  color: #041312;
  font-family: var(--font-sans);
  font-size: 1.06rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  cursor: pointer;
  box-shadow:
    0 10px 28px rgba(20, 184, 166, 0.28),
    inset 0 1px 0 rgba(255, 255, 255, 0.35);
  transition: transform 0.16s ease, box-shadow 0.2s ease, filter 0.2s ease, opacity 0.2s ease;
}

.btn-start:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow:
    0 14px 34px rgba(20, 184, 166, 0.38),
    inset 0 1px 0 rgba(255, 255, 255, 0.45);
  filter: brightness(1.06);
}

.btn-start:active:not(:disabled) {
  transform: translateY(0);
}

.btn-start:focus-visible,
.btn-abort:focus-visible,
.btn-clear-history:focus-visible {
  outline: 2px solid var(--amber-bright);
  outline-offset: 3px;
}

.btn-start:disabled {
  cursor: not-allowed;
  background: linear-gradient(135deg, #1e293b, #283548);
  border-color: rgba(148, 163, 184, 0.25);
  color: var(--text-secondary);
  box-shadow: none;
}

.btn-abort {
  height: 54px;
  padding: 0 22px;
  border-radius: 999px;
  border: 1px solid rgba(248, 113, 113, 0.38);
  background: rgba(248, 113, 113, 0.1);
  color: #fca5a5;
  font-family: var(--font-sans);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.2s ease, border-color 0.2s ease;
}

.btn-abort:hover {
  background: rgba(248, 113, 113, 0.18);
  border-color: rgba(248, 113, 113, 0.55);
}

/* Results panel */
.results-panel {
  background: linear-gradient(180deg, rgba(20, 26, 40, 0.9), rgba(14, 18, 28, 0.95));
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 22px 24px 24px;
  animation: fadeSlideUp 0.28s ease-out;
}

.results-panel[hidden] {
  display: none;
}

@keyframes fadeSlideUp {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.results-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.results-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
}

.results-meta {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text-muted);
}

.results-primary {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}

.metric-card {
  background: rgba(9, 12, 18, 0.6);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 18px 20px;
}

.metric-card--download {
  border-top: 2px solid var(--teal);
}

.metric-card--upload {
  border-top: 2px solid var(--amber);
}

.metric-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.metric-tag {
  font-size: 0.88rem;
  font-weight: 600;
}

.metric-tag--teal {
  color: var(--teal-bright);
}

.metric-tag--amber {
  color: var(--amber-bright);
}

.metric-en {
  font-size: 0.78rem;
  color: var(--text-muted);
  letter-spacing: 0.04em;
}

.metric-body {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.metric-number {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: clamp(2rem, 4.5vw, 2.75rem);
  font-weight: 700;
  line-height: 1.05;
  color: var(--text-primary);
}

.metric-unit {
  font-size: 0.95rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.results-secondary {
  margin-top: 14px;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}

.metric-subcard {
  background: rgba(9, 12, 18, 0.45);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 13px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.subcard-label {
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.subcard-en {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-left: 4px;
}

.subcard-value {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-primary);
}

.subcard-unit {
  font-size: 0.82rem;
  color: var(--text-secondary);
  font-weight: 500;
  margin-left: 2px;
}

/* History panel */
.history-panel {
  background: rgba(17, 22, 34, 0.75);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 18px 22px;
}

.history-panel[hidden] {
  display: none;
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.history-title {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.btn-clear-history {
  background: transparent;
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 5px 10px;
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 0.78rem;
  cursor: pointer;
  transition: color 0.2s ease, border-color 0.2s ease;
}

.btn-clear-history:hover {
  color: var(--text-primary);
  border-color: var(--border-strong);
}

.history-table-wrap {
  overflow-x: auto;
}

.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.86rem;
}

.history-table th,
.history-table td {
  padding: 9px 10px;
  text-align: left;
  border-bottom: 1px solid rgba(148, 163, 184, 0.08);
  white-space: nowrap;
}

.history-table th {
  color: var(--text-muted);
  font-weight: 500;
  font-size: 0.8rem;
}

.history-table td {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  color: var(--text-primary);
}

.history-table tbody tr:last-child td {
  border-bottom: none;
}

.history-val--down {
  color: var(--teal-bright);
}

.history-val--up {
  color: var(--amber-bright);
}

/* Footer */
.site-footer {
  margin-top: auto;
  padding-top: 8px;
  text-align: center;
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.6;
}

.site-footer p {
  margin: 2px 0;
}

.footer-credit {
  opacity: 0.8;
}

/* Responsive */
@media (max-width: 600px) {
  .app-shell {
    padding: 16px 14px 24px;
    gap: 16px;
  }

  .telemetry-card {
    padding: 18px 16px 22px;
  }

  .step-pills {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .results-primary,
  .results-secondary {
    grid-template-columns: 1fr;
  }

  .gauge-readout {
    bottom: 10px;
  }

  .action-bar {
    flex-direction: column;
  }

  .btn-start,
  .btn-abort {
    width: 100%;
  }
}
