:root {
  --bg: #0f172a;
  --card: #111827;
  --panel: #1f2937;
  --text: #f8fafc;
  --muted: #94a3b8;
  --green: #22c55e;
  --blue: #38bdf8;
  --purple: #a78bfa;
  --border: rgba(255,255,255,0.08);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: Arial, Helvetica, sans-serif;
  background: radial-gradient(circle at top, #1e293b 0%, var(--bg) 55%);
  color: var(--text);
}

.wrap {
  max-width: 980px;
  margin: 0 auto;
  padding: 40px 20px 60px;
}

header {
  margin-bottom: 24px;
}

.brand {
  margin: 0 0 8px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--blue);
  font-weight: 700;
  font-size: 13px;
}

h1 {
  margin: 0;
  font-size: clamp(28px, 5vw, 46px);
}

.subtitle {
  color: var(--muted);
  margin-top: 8px;
}

.card {
  background: rgba(17, 24, 39, 0.9);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 28px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}

.gauges {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
}

.metric {
  background: var(--panel);
  border-radius: 18px;
  padding: 20px;
  border: 1px solid var(--border);
}

.metric .label {
  display: block;
  color: var(--muted);
  margin-bottom: 10px;
}

.metric strong {
  font-size: clamp(28px, 5vw, 52px);
  line-height: 1;
}

.metric small {
  display: block;
  color: var(--muted);
  margin-top: 8px;
}

.highlight.download { outline: 1px solid rgba(56,189,248,0.35); }
.highlight.upload { outline: 1px solid rgba(167,139,250,0.35); }

.status-panel,
.chart-panel,
.history-panel {
  margin-top: 24px;
  background: var(--panel);
  border-radius: 18px;
  padding: 24px;
  border: 1px solid var(--border);
}

.progress-bar {
  width: 100%;
  height: 14px;
  background: rgba(255,255,255,0.08);
  border-radius: 999px;
  overflow: hidden;
}

#progressFill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--blue), var(--purple));
  transition: width 0.18s ease;
}

#statusText {
  margin: 16px 0 20px;
  color: var(--muted);
}

.controls {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

button {
  border: none;
  border-radius: 12px;
  padding: 14px 18px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  background: linear-gradient(90deg, var(--blue), var(--purple));
  color: white;
}

button.secondary {
  background: transparent;
  border: 1px solid var(--border);
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.chart-head,
.history-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.chart-head h2,
.history-head h2 {
  margin: 0 0 8px;
  font-size: 22px;
}

.chart-head p,
.history-head p {
  margin: 0;
  color: var(--muted);
}

.legend {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 14px;
}

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

.legend-line {
  display: inline-block;
  width: 22px;
  height: 4px;
  border-radius: 999px;
}

.legend-line.download { background: var(--blue); }
.legend-line.upload { background: var(--purple); }

.chart-wrap {
  width: 100%;
  min-height: 320px;
  border-radius: 16px;
  overflow: hidden;
  background:
    linear-gradient(to bottom, rgba(255,255,255,0.03), rgba(255,255,255,0.01)),
    linear-gradient(to right, rgba(255,255,255,0.05) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(255,255,255,0.05) 1px, transparent 1px);
  background-size: auto, 12.5% 100%, 100% 20%;
  border: 1px solid var(--border);
}

#speedChart {
  width: 100%;
  height: 320px;
  display: block;
}

.history-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 14px;
}

.history-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 620px;
}

.history-table th,
.history-table td {
  padding: 14px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.history-table th {
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
  background: rgba(255,255,255,0.03);
}

.history-table td {
  font-size: 15px;
}

.history-table tbody tr:hover {
  background: rgba(255,255,255,0.03);
}

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

.empty-history {
  color: var(--muted);
  text-align: center !important;
  padding: 22px !important;
}

@media (max-width: 640px) {
  .wrap {
    padding: 22px 14px 40px;
  }

  .card {
    padding: 18px;
    border-radius: 18px;
  }

  .status-panel,
  .chart-panel,
  .history-panel {
    padding: 18px;
  }

  #speedChart,
  .chart-wrap {
    min-height: 260px;
    height: 260px;
  }
}
