/* ═══════════════════════════════════════════════════════════════
   SpeedTest — Modern Professional White Theme
   ═══════════════════════════════════════════════════════════════ */

/* ─── CSS Custom Properties ──────────────────────────────────── */
:root {
  /* Primary palette */
  --primary-50: #eff6ff;
  --primary-100: #dbeafe;
  --primary-200: #bfdbfe;
  --primary-300: #93c5fd;
  --primary-400: #60a5fa;
  --primary-500: #3b82f6;
  --primary-600: #2563eb;
  --primary-700: #1d4ed8;

  /* Accent colors */
  --accent-purple: #8b5cf6;
  --accent-pink: #ec4899;
  --accent-emerald: #10b981;
  --accent-amber: #f59e0b;
  --accent-rose: #f43f5e;

  /* Neutral palette */
  --gray-50: #f8fafc;
  --gray-100: #f1f5f9;
  --gray-200: #e2e8f0;
  --gray-300: #cbd5e1;
  --gray-400: #94a3b8;
  --gray-500: #64748b;
  --gray-600: #475569;
  --gray-700: #334155;
  --gray-800: #1e293b;
  --gray-900: #0f172a;

  /* Background */
  --bg-primary: #ffffff;
  --bg-secondary: #f7f7f7;
  --bg-tertiary: #f1f5f9;

  /* Text */
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-tertiary: #94a3b8;

  /* Shadows */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.03);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -2px rgba(0, 0, 0, 0.03);
  --shadow-lg: 0 10px 25px -5px rgba(0, 0, 0, 0.06), 0 8px 10px -6px rgba(0, 0, 0, 0.04);
  --shadow-xl: 0 20px 50px -12px rgba(0, 0, 0, 0.08);
  --shadow-glow-blue: 0 0 40px rgba(59, 130, 246, 0.15);
  --shadow-glow-purple: 0 0 40px rgba(139, 92, 246, 0.12);

  /* Border radius */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-2xl: 24px;
  --radius-full: 9999px;

  /* Transitions */
  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-base: 250ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 400ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-bounce: 500ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ─── Reset & Base ───────────────────────────────────────────── */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-secondary);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
  position: relative;
}

/* ─── Background Decorations ─────────────────────────────────── */
.bg-decoration {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

.bg-circle {
  position: absolute;
  border-radius: 50%;
  opacity: 0.4;
}

.bg-circle-1 {
  width: 600px;
  height: 600px;
  top: -200px;
  right: -150px;
  background: radial-gradient(circle, rgba(59, 130, 246, 0.06) 0%, transparent 70%);
  animation: floatSlow 20s ease-in-out infinite;
}

.bg-circle-2 {
  width: 400px;
  height: 400px;
  bottom: -100px;
  left: -100px;
  background: radial-gradient(circle, rgba(139, 92, 246, 0.05) 0%, transparent 70%);
  animation: floatSlow 25s ease-in-out infinite reverse;
}

.bg-circle-3 {
  width: 300px;
  height: 300px;
  top: 40%;
  left: 50%;
  transform: translateX(-50%);
  background: radial-gradient(circle, rgba(236, 72, 153, 0.04) 0%, transparent 70%);
  animation: floatSlow 30s ease-in-out infinite;
}

.bg-grid {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-image: 
    linear-gradient(rgba(0,0,0,0.015) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0,0,0,0.015) 1px, transparent 1px);
  background-size: 60px 60px;
}

@keyframes floatSlow {
  0%, 100% { transform: translate(0, 0); }
  33% { transform: translate(30px, -20px); }
  66% { transform: translate(-20px, 15px); }
}

/* ─── App Container ──────────────────────────────────────────── */
.app-container {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  max-width: 960px;
  margin: 0 auto;
  padding: 0 24px;
}

/* ─── Header ─────────────────────────────────────────────────── */
.header {
  padding: 20px 0;
  animation: slideDown 0.6s ease-out;
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.partner-logo {
  display: flex;
  align-items: center;
}

.brand-logo {
  height: 48px;
  width: auto;
  object-fit: contain;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.02));
  transition: transform var(--transition-base);
}

.brand-logo:hover {
  transform: scale(1.02);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.logo-container {
  display: flex;
  align-items: center;
}

.speedtest-brand-logo {
  height: 32px;
  width: auto;
  object-fit: contain;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.02));
}

.server-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--accent-emerald);
  background: rgba(16, 185, 129, 0.06);
  padding: 6px 14px;
  border-radius: var(--radius-full);
  border: 1px solid rgba(16, 185, 129, 0.15);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-emerald);
  animation: pulse 2s ease-in-out infinite;
  box-shadow: 0 0 8px rgba(16, 185, 129, 0.5);
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.7; transform: scale(1.2); }
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-20px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ─── Info Bar ───────────────────────────────────────────────── */
.info-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 16px 0;
  margin-bottom: 20px;
  animation: fadeInUp 0.6s ease-out 0.1s both;
}

.info-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  color: var(--text-secondary);
  background: var(--bg-secondary);
  padding: 8px 14px;
  border-radius: var(--radius-full);
  border: 1px solid var(--gray-200);
  transition: all var(--transition-fast);
}

.info-item:hover {
  border-color: var(--primary-200);
  background: var(--primary-50);
}

.info-item svg {
  color: var(--gray-400);
  flex-shrink: 0;
}

.info-item strong {
  font-weight: 600;
  color: var(--text-primary);
}

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

/* ─── Gauge Section ──────────────────────────────────────────── */
.gauge-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 32px;
  animation: fadeInUp 0.6s ease-out 0.2s both;
}

.gauge-container {
  width: 100%;
  max-width: 420px;
  position: relative;
}

.gauge-svg {
  width: 100%;
  height: auto;
  overflow: visible;
}

.gauge-track {
  fill: none;
  stroke: var(--gray-200);
  stroke-width: 18;
  stroke-linecap: round;
}

.gauge-arc {
  fill: none;
  stroke: url(#gaugeGradient);
  stroke-width: 18;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.3s ease-out;
}

.gauge-glow {
  fill: none;
  stroke: url(#gaugeGradient);
  stroke-width: 28;
  stroke-linecap: round;
  opacity: 0.15;
  transition: stroke-dashoffset 0.3s ease-out;
}

.gauge-value {
  font-family: 'JetBrains Mono', monospace;
  font-size: 56px;
  font-weight: 700;
  fill: var(--text-primary);
}

.gauge-unit {
  font-family: 'Inter', sans-serif;
  font-size: 16px;
  font-weight: 600;
  fill: var(--text-secondary);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.gauge-status {
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  font-weight: 500;
  fill: var(--text-tertiary);
  letter-spacing: 0.05em;
}

.scale-markers text {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  fill: var(--gray-400);
  font-weight: 500;
}

.scale-markers line {
  stroke: var(--gray-300);
  stroke-width: 1.5;
}

/* ─── Start Button ───────────────────────────────────────────── */
.button-container {
  margin-top: 12px;
}

.start-btn {
  position: relative;
  border: none;
  outline: none;
  cursor: pointer;
  background: linear-gradient(135deg, var(--primary-500), var(--primary-600), var(--accent-purple));
  color: white;
  font-family: 'Inter', sans-serif;
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  padding: 16px 52px;
  border-radius: var(--radius-full);
  overflow: hidden;
  transition: all var(--transition-base);
  animation: pulseButtonGlow 3s infinite ease-in-out;
}

.start-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 40px rgba(59, 130, 246, 0.4);
}

.start-btn:active {
  transform: translateY(0);
  box-shadow: 0 4px 15px rgba(59, 130, 246, 0.3);
}

.start-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.btn-content {
  display: flex;
  align-items: center;
  gap: 10px;
  position: relative;
  z-index: 1;
}

.btn-icon {
  transition: transform var(--transition-base);
}

.start-btn:hover .btn-icon {
  transform: scale(1.1);
}

.btn-ripple {
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, transparent, rgba(255,255,255,0.1), transparent);
  transform: translateX(-100%);
  transition: transform 0.6s ease;
}

.start-btn:hover .btn-ripple {
  transform: translateX(100%);
}

.start-btn.testing {
  background: linear-gradient(135deg, var(--gray-600), var(--gray-700));
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
  padding: 14px 40px;
}

.start-btn.testing .btn-icon {
  animation: spin 1s linear infinite;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* ─── Live Metrics ───────────────────────────────────────────── */
.live-metrics {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 32px;
  animation: fadeInUp 0.6s ease-out 0.3s both;
}

.metric-card {
  background: var(--bg-primary);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-lg);
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  transition: all var(--transition-base);
  position: relative;
  overflow: hidden;
}

.metric-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  opacity: 0;
  transition: opacity var(--transition-base);
}

.metric-card:hover {
  border-color: var(--primary-200);
  box-shadow: var(--shadow-md);
}

.metric-card.active::before {
  opacity: 1;
}

#metric-ping::before { background: linear-gradient(90deg, var(--accent-emerald), #34d399); }
#metric-jitter::before { background: linear-gradient(90deg, var(--accent-amber), #fbbf24); }
#metric-download::before { background: linear-gradient(90deg, var(--primary-500), var(--accent-purple)); }
#metric-upload::before { background: linear-gradient(90deg, var(--accent-purple), var(--accent-pink)); }

@keyframes pulsePing {
  0%, 100% { box-shadow: 0 4px 15px rgba(16, 185, 129, 0.08), 0 0 0 2px rgba(16, 185, 129, 0.05); border-color: rgba(16, 185, 129, 0.25); }
  50% { box-shadow: 0 10px 25px rgba(16, 185, 129, 0.2), 0 0 0 4px rgba(16, 185, 129, 0.1); border-color: rgba(16, 185, 129, 0.5); }
}
@keyframes pulseJitter {
  0%, 100% { box-shadow: 0 4px 15px rgba(245, 158, 11, 0.08), 0 0 0 2px rgba(245, 158, 11, 0.05); border-color: rgba(245, 158, 11, 0.25); }
  50% { box-shadow: 0 10px 25px rgba(245, 158, 11, 0.2), 0 0 0 4px rgba(245, 158, 11, 0.1); border-color: rgba(245, 158, 11, 0.5); }
}
@keyframes pulseDownload {
  0%, 100% { box-shadow: 0 4px 15px rgba(59, 130, 246, 0.08), 0 0 0 2px rgba(59, 130, 246, 0.05); border-color: rgba(59, 130, 246, 0.25); }
  50% { box-shadow: 0 10px 25px rgba(59, 130, 246, 0.2), 0 0 0 4px rgba(59, 130, 246, 0.1); border-color: rgba(59, 130, 246, 0.5); }
}
@keyframes pulseUpload {
  0%, 100% { box-shadow: 0 4px 15px rgba(139, 92, 246, 0.08), 0 0 0 2px rgba(139, 92, 246, 0.05); border-color: rgba(139, 92, 246, 0.25); }
  50% { box-shadow: 0 10px 25px rgba(139, 92, 246, 0.2), 0 0 0 4px rgba(139, 92, 246, 0.1); border-color: rgba(139, 92, 246, 0.5); }
}

#metric-ping.active { animation: pulsePing 2s infinite ease-in-out; }
#metric-jitter.active { animation: pulseJitter 2s infinite ease-in-out; }
#metric-download.active { animation: pulseDownload 2s infinite ease-in-out; }
#metric-upload.active { animation: pulseUpload 2s infinite ease-in-out; }

.metric-icon {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
}

.ping-icon { background: rgba(16, 185, 129, 0.08); color: var(--accent-emerald); }
.jitter-icon { background: rgba(245, 158, 11, 0.08); color: var(--accent-amber); }
.download-icon { background: rgba(59, 130, 246, 0.08); color: var(--primary-500); }
.upload-icon { background: rgba(139, 92, 246, 0.08); color: var(--accent-purple); }

.metric-info {
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.metric-label {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--text-tertiary);
  text-transform: uppercase;
}

.metric-value {
  font-family: 'JetBrains Mono', monospace;
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
}

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

/* ─── Results Section ────────────────────────────────────────── */
.results-section {
  animation: fadeInUp 0.5s ease-out;
  margin-bottom: 40px;
}

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

.results-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--accent-emerald);
}

.results-timestamp {
  font-size: 0.78rem;
  color: var(--text-tertiary);
  font-weight: 500;
}

.results-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.result-card {
  background: var(--bg-primary);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-xl);
  padding: 24px;
  transition: all var(--transition-base);
  animation: scaleIn 0.4s ease-out both;
}

.result-card:nth-child(1) { animation-delay: 0.1s; }
.result-card:nth-child(2) { animation-delay: 0.2s; }
.result-card:nth-child(3) { animation-delay: 0.3s; }
.result-card:nth-child(4) { animation-delay: 0.4s; }

.result-card:hover {
  border-color: var(--primary-200);
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
}

@keyframes scaleIn {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

.result-card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.result-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
}

.download-color { background: rgba(59, 130, 246, 0.08); color: var(--primary-500); }
.upload-color { background: rgba(139, 92, 246, 0.08); color: var(--accent-purple); }
.ping-color { background: rgba(16, 185, 129, 0.08); color: var(--accent-emerald); }
.jitter-color { background: rgba(245, 158, 11, 0.08); color: var(--accent-amber); }

.result-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.result-value-container {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin-bottom: 12px;
}

.result-value {
  font-family: 'JetBrains Mono', monospace;
  font-size: 2rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1;
}

.result-unit {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-tertiary);
}

.result-bar {
  width: 100%;
  height: 6px;
  background: var(--gray-100);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.result-bar-fill {
  height: 100%;
  border-radius: var(--radius-full);
  width: 0%;
  transition: width 1s cubic-bezier(0.4, 0, 0.2, 1);
}

.download-bar {
  background: linear-gradient(90deg, var(--primary-500), var(--accent-purple));
}

.upload-bar {
  background: linear-gradient(90deg, var(--accent-purple), var(--accent-pink));
}

/* ─── Test Again Button ──────────────────────────────────────── */
.test-again-container {
  display: flex;
  justify-content: center;
  margin-top: 24px;
}

.test-again-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 2px solid var(--gray-200);
  background: var(--bg-primary);
  color: var(--text-secondary);
  font-family: 'Inter', sans-serif;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 12px 32px;
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all var(--transition-base);
}

.test-again-btn:hover {
  border-color: var(--primary-400);
  color: var(--primary-600);
  background: var(--primary-50);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.test-again-btn:hover svg {
  animation: spinOnce 0.5s ease-out;
}

@keyframes spinOnce {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* ─── Footer ─────────────────────────────────────────────────── */
.footer {
  margin-top: auto;
  padding: 20px 0;
  border-top: 1px solid var(--gray-100);
}

.footer-inner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}

.footer-text {
  font-size: 0.75rem;
  color: var(--text-tertiary);
  font-weight: 500;
}

.footer-separator {
  color: var(--gray-300);
  font-size: 0.75rem;
}

/* ─── Phase Animations ───────────────────────────────────────── */
.phase-ping .gauge-arc,
.phase-ping .gauge-glow {
  stroke: var(--accent-emerald) !important;
}

.phase-download .gauge-arc,
.phase-download .gauge-glow {
  stroke: url(#gaugeGradient);
}

.phase-upload .gauge-arc,
.phase-upload .gauge-glow {
  stroke: var(--accent-purple) !important;
}

/* ─── Responsive ─────────────────────────────────────────────── */
@media (max-width: 768px) {
  .app-container {
    padding: 0 16px;
  }

  .info-bar {
    gap: 6px;
  }

  .info-item {
    font-size: 0.72rem;
    padding: 6px 10px;
  }

  .live-metrics {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }

  .results-grid {
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }

  .gauge-value {
    font-size: 44px;
  }

  .start-btn {
    padding: 14px 40px;
    font-size: 0.85rem;
  }

  .results-header {
    flex-direction: column;
    gap: 6px;
    align-items: flex-start;
  }
}

@media (max-width: 480px) {
  .header-inner {
    flex-direction: column;
    gap: 12px;
    align-items: flex-start;
  }

  .live-metrics {
    grid-template-columns: 1fr 1fr;
  }

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

  .gauge-container {
    max-width: 320px;
  }

  .gauge-value {
    font-size: 38px;
  }

  .result-card {
    padding: 18px;
  }

  .result-value {
    font-size: 1.6rem;
  }
}

/* ─── Utility Animations ─────────────────────────────────────── */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

.shimmer {
  background: linear-gradient(90deg, 
    var(--gray-200) 0%, 
    var(--gray-100) 40%, 
    var(--gray-200) 100%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}

@keyframes pulseButtonGlow {
  0%, 100% {
    box-shadow: 0 8px 30px rgba(59, 130, 246, 0.3), 0 0 0 0px rgba(59, 130, 246, 0.25);
  }
  50% {
    box-shadow: 0 12px 40px rgba(59, 130, 246, 0.5), 0 0 0 15px rgba(59, 130, 246, 0);
  }
}
