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

:root {
  --primary: #5645d4;
  --primary-pressed: #4534b3;
  --on-primary: #ffffff;
  --brand-navy: #0a1530;

  --canvas: #ffffff;
  --surface: #f6f5f4;
  --hairline: #e5e3df;
  --hairline-soft: #ede9e4;
  --hairline-strong: #c8c4be;

  --ink: #1a1a1a;
  --charcoal: #37352f;
  --slate: #5d5b54;
  --steel: #787671;
  --muted: #bbb8b1;
  --on-dark: #ffffff;
  --on-dark-muted: #9ca3af;

  --success: #1aae39;
  --warning: #dd5b00;
  --error: #e03131;

  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, sans-serif;
  --font-mono: 'SF Mono', 'Cascadia Code', 'Fira Code', 'Consolas', monospace;

  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-full: 9999px;
}

html {
  height: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100dvh;
  font-family: var(--font-sans);
  background: var(--surface);
  color: var(--charcoal);
  line-height: 1.55;
}

.app {
  max-width: 640px;
  margin: 0 auto;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--canvas);
  box-shadow: 0 0 0 1px var(--hairline);
}

.topbar {
  background: var(--brand-navy);
  padding: 0 24px;
  height: 52px;
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.topbar-inner {
  display: flex;
  align-items: center;
  gap: 8px;
}

.topbar-brand {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: var(--radius-sm);
  background: var(--primary);
  color: var(--on-dark);
  font-size: 13px;
  font-weight: 700;
  flex-shrink: 0;
}

.topbar-title {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.3px;
  color: var(--on-dark);
}

.topbar-subtitle {
  font-size: 13px;
  color: var(--on-dark-muted);
  margin-left: 4px;
}

.main {
  flex: 1;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow: hidden;
  min-height: 0;
}

.card {
  background: var(--canvas);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-lg);
  padding: 20px;
}

.card-stats {
  padding: 16px 20px;
}

.card-output {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
  min-height: 0;
}

.input-group {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.input-wrap {
  flex: 1;
}

#targetInput {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 400;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--hairline-strong);
  border-radius: var(--radius-md);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

#targetInput::placeholder {
  color: var(--muted);
}

#targetInput:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(86, 69, 212, 0.1);
}

#targetInput:disabled {
  background: var(--hairline-soft);
  color: var(--steel);
}

#toggleBtn {
  height: 40px;
  padding: 0 20px;
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  white-space: nowrap;
  flex-shrink: 0;
}

#toggleBtn:active {
  transform: scale(0.97);
}

.btn-start {
  background: var(--primary);
  color: var(--on-primary);
}

.btn-start:hover {
  background: var(--primary-pressed);
}

.btn-stop {
  background: var(--error);
  color: var(--on-dark);
}

.btn-stop:hover {
  background: #c62828;
}

.quick-presets {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.preset {
  padding: 5px 12px;
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 500;
  color: var(--steel);
  background: transparent;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all 0.15s;
}

.preset:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: rgba(86, 69, 212, 0.04);
}

.target-info {
  display: none;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  padding: 10px 12px;
  background: var(--surface);
  border-radius: var(--radius-md);
  font-size: 13px;
}

.target-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--success);
  flex-shrink: 0;
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

.target-label {
  font-weight: 600;
  color: var(--charcoal);
}

.target-ip {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--steel);
}

.stats-bar {
  display: flex;
  gap: 0;
}

.stat {
  flex: 1;
  text-align: center;
  position: relative;
}

.stat + .stat::before {
  content: '';
  position: absolute;
  left: 0;
  top: 4px;
  bottom: 4px;
  width: 1px;
  background: var(--hairline-soft);
}

.stat-value {
  display: block;
  font-size: 20px;
  font-weight: 600;
  color: var(--charcoal);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.5px;
  line-height: 1.3;
}

.stat-label {
  display: block;
  font-size: 11px;
  font-weight: 500;
  color: var(--steel);
  margin-top: 1px;
}

.output {
  flex: 1;
  overflow-y: auto;
  padding: 4px 0;
  min-height: 0;
}

.output::-webkit-scrollbar {
  width: 4px;
}

.output::-webkit-scrollbar-thumb {
  background: var(--hairline-strong);
  border-radius: 2px;
}

.placeholder {
  text-align: center;
  padding: 56px 20px;
  color: var(--muted);
  font-size: 14px;
}

.ping-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 20px;
  font-size: 13px;
  animation: fadeIn 0.15s ease;
  border-bottom: 1px solid var(--hairline-soft);
}

.ping-row:last-child {
  border-bottom: none;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.ping-name {
  font-weight: 600;
  color: var(--charcoal);
  min-width: 64px;
  font-size: 13px;
}

.ping-ip {
  color: var(--steel);
  font-family: var(--font-mono);
  font-size: 11px;
}

.ping-time {
  margin-left: auto;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  font-family: var(--font-mono);
  font-size: 14px;
  color: var(--charcoal);
  min-width: 52px;
  text-align: right;
}

.ping-badge {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 10px;
  border-radius: var(--radius-full);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  min-width: 42px;
  text-align: center;
  flex-shrink: 0;
}

.badge-best {
  background: rgba(26, 174, 57, 0.1);
  color: var(--success);
}

.badge-good {
  background: rgba(0, 117, 222, 0.08);
  color: #0066c0;
}

.badge-low {
  background: rgba(221, 91, 0, 0.08);
  color: var(--warning);
}

.badge-bad {
  background: rgba(224, 49, 49, 0.08);
  color: var(--error);
}

.line-info {
  color: var(--steel);
  font-size: 13px;
  padding: 8px 20px;
}

.line-error {
  color: var(--error);
  font-size: 13px;
  padding: 8px 20px;
}

.info-bar {
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  min-height: 18px;
}

@media (max-width: 700px) {
  .topbar-subtitle {
    display: none;
  }

  .stat-value {
    font-size: 17px;
  }
}

@media (max-width: 600px) {
  .app {
    box-shadow: none;
    height: 100dvh;
  }

  .topbar {
    padding: 0 14px;
    height: 48px;
  }

  .main {
    padding: 14px;
    gap: 10px;
  }

  .card {
    padding: 14px;
  }

  .card-stats {
    padding: 10px 14px;
  }

  .stat-label {
    font-size: 10px;
  }

  .input-group {
    flex-direction: column;
    margin-bottom: 10px;
  }

  #targetInput {
    height: 44px;
    font-size: 16px;
  }

  #toggleBtn {
    height: 44px;
    width: 100%;
  }

  .quick-presets {
    gap: 4px;
  }

  .preset {
    padding: 7px 12px;
    font-size: 12px;
  }

  .placeholder {
    padding: 40px 16px;
    font-size: 13px;
  }

  .stat-value {
    font-size: 16px;
  }
}

@media (max-width: 480px) {
  .stats-bar {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
  }

  .stat + .stat::before {
    display: none;
  }

  .stat {
    padding: 6px 0;
  }

  .stat-value {
    font-size: 18px;
  }

  .ping-row {
    padding: 6px 12px;
    gap: 6px;
  }

  .ping-name {
    min-width: 56px;
    font-size: 12px;
  }

  .ping-time {
    font-size: 13px;
    min-width: 48px;
  }

  .ping-badge {
    font-size: 9px;
    padding: 2px 8px;
    min-width: 38px;
  }

  .ping-ip {
    display: none;
  }



  .placeholder {
    padding: 32px 14px;
  }
}

@media (max-width: 380px) {
  .topbar {
    height: 44px;
    padding: 0 10px;
  }

  .topbar-brand {
    width: 22px;
    height: 22px;
    font-size: 11px;
  }

  .topbar-title {
    font-size: 13px;
  }

  .main {
    padding: 10px;
    gap: 8px;
  }

  .card {
    padding: 10px;
    border-radius: var(--radius-md);
  }

  .card-stats {
    padding: 8px 10px;
  }

  #targetInput {
    height: 40px;
    font-size: 14px;
  }

  #toggleBtn {
    height: 40px;
    font-size: 12px;
  }

  .preset {
    padding: 6px 10px;
    font-size: 11px;
  }

  .stat-value {
    font-size: 16px;
  }

  .stat-label {
    font-size: 9px;
  }

  .ping-row {
    padding: 5px 10px;
    gap: 4px;
  }

  .ping-name {
    min-width: 44px;
    font-size: 11px;
  }

  .ping-time {
    font-size: 12px;
    min-width: 40px;
  }

  .ping-badge {
    font-size: 8px;
    padding: 1px 6px;
    min-width: 32px;
  }
}
