/* ============================================
   Speed Test — speed.ashmil.me
   Design System & Styles
   ============================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

/* --- CSS Custom Properties --- */
:root {
  --color-bg: #ffffff;
  --color-surface: #f8f9fb;
  --color-primary: #25b4eb;
  --color-primary-hover: #1a9fd4;
  --color-primary-light: rgba(37, 180, 235, 0.08);
  --color-text: #1a1a2e;
  --color-text-secondary: #6b7280;
  --color-border: #e5e7eb;
  --color-shadow: rgba(0, 0, 0, 0.06);
  --color-shadow-lg: rgba(0, 0, 0, 0.1);
  --color-success: #10b981;
  --color-overlay: rgba(0, 0, 0, 0.4);

  --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-full: 9999px;

  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-normal: 250ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-smooth: 350ms cubic-bezier(0.4, 0, 0.2, 1);
}

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

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

body {
  height: 100%;
  font-family: var(--font-family);
  background: var(--color-bg);
  color: var(--color-text);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* --- Header --- */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 60px;
  min-height: 60px;
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border);
  box-shadow: 0 1px 3px var(--color-shadow);
  z-index: 100;
  position: relative;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--color-text);
}

.header-logo {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.header-logo svg {
  width: 100%;
  height: 100%;
}

.header-title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--color-text);
}

.header-title span {
  color: var(--color-primary);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  font-family: var(--font-family);
  font-size: 14px;
  font-weight: 500;
  border: none;
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
  text-decoration: none;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--color-primary);
  color: white;
  box-shadow: 0 2px 8px rgba(37, 180, 235, 0.3);
}

.btn-primary:hover {
  background: var(--color-primary-hover);
  box-shadow: 0 4px 12px rgba(37, 180, 235, 0.4);
  transform: translateY(-1px);
}

.btn-primary:active {
  transform: translateY(0) scale(0.97);
}

.btn-ghost {
  background: transparent;
  color: var(--color-text-secondary);
  border: 1px solid var(--color-border);
}

.btn-ghost:hover {
  background: var(--color-surface);
  color: var(--color-text);
  border-color: var(--color-text-secondary);
}

.btn-icon {
  padding: 8px;
  border-radius: var(--radius-sm);
}

.btn svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

/* --- Speedtest Iframe Container --- */
.speedtest-container {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: var(--color-bg);
}

.speedtest-iframe {
  width: 100%;
  height: 100%;
  border: none;
  display: block;
}

/* --- Share Modal --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--color-overlay);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition-normal);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.modal {
  background: var(--color-bg);
  border-radius: var(--radius-lg);
  box-shadow: 0 20px 60px var(--color-shadow-lg), 0 0 0 1px var(--color-border);
  width: 100%;
  max-width: 440px;
  transform: translateY(20px) scale(0.95);
  transition: transform var(--transition-smooth);
  overflow: hidden;
}

.modal-overlay.active .modal {
  transform: translateY(0) scale(1);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 16px;
}

.modal-header h2 {
  font-size: 18px;
  font-weight: 600;
  color: var(--color-text);
}

.modal-close {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: var(--color-surface);
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--color-text-secondary);
  transition: all var(--transition-fast);
}

.modal-close:hover {
  background: var(--color-border);
  color: var(--color-text);
}

.modal-close svg {
  width: 18px;
  height: 18px;
}

.modal-body {
  padding: 0 24px 24px;
}

/* URL Copy Box */
.url-copy-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 4px 4px 4px 14px;
  margin-bottom: 20px;
}

.url-copy-box input {
  flex: 1;
  border: none;
  background: transparent;
  font-family: var(--font-family);
  font-size: 13px;
  color: var(--color-text);
  outline: none;
  min-width: 0;
}

.url-copy-box .btn-copy {
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  border: none;
  background: var(--color-primary);
  color: white;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
  font-family: var(--font-family);
}

.url-copy-box .btn-copy:hover {
  background: var(--color-primary-hover);
}

.url-copy-box .btn-copy.copied {
  background: var(--color-success);
}

/* Share Buttons Grid */
.share-options-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text-secondary);
  margin-bottom: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.share-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.share-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 14px 8px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-bg);
  cursor: pointer;
  transition: all var(--transition-fast);
  text-decoration: none;
  font-family: var(--font-family);
}

.share-btn:hover {
  background: var(--color-surface);
  border-color: var(--color-primary);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px var(--color-shadow);
}

.share-btn svg {
  width: 24px;
  height: 24px;
}

.share-btn span {
  font-size: 11px;
  font-weight: 500;
  color: var(--color-text-secondary);
}

/* WhatsApp */
.share-btn.whatsapp svg { color: #25D366; }
/* Twitter/X */
.share-btn.twitter svg { color: #1DA1F2; }
/* Telegram */
.share-btn.telegram svg { color: #0088cc; }
/* Email */
.share-btn.email svg { color: #6b7280; }

/* --- Toast Notification --- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--color-text);
  color: white;
  padding: 12px 24px;
  border-radius: var(--radius-full);
  font-size: 14px;
  font-weight: 500;
  box-shadow: 0 8px 30px var(--color-shadow-lg);
  z-index: 2000;
  opacity: 0;
  transition: all var(--transition-smooth);
  pointer-events: none;
  display: flex;
  align-items: center;
  gap: 8px;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

.toast svg {
  width: 18px;
  height: 18px;
  color: var(--color-success);
}

/* --- Result Page Info Bar --- */
.result-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 10px 24px;
  background: var(--color-primary-light);
  border-bottom: 1px solid rgba(37, 180, 235, 0.15);
  font-size: 13px;
  color: var(--color-text-secondary);
}

.result-bar a {
  color: var(--color-primary);
  text-decoration: none;
  font-weight: 500;
}

.result-bar a:hover {
  text-decoration: underline;
}

/* --- Responsive --- */
@media (max-width: 640px) {
  .header {
    padding: 0 16px;
    height: 52px;
    min-height: 52px;
  }

  .header-title {
    font-size: 15px;
  }

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

  .btn .btn-label {
    display: none;
  }

  .modal {
    max-width: 100%;
    border-radius: var(--radius-md);
  }

  .share-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
  }

  .share-btn {
    padding: 10px 6px;
  }

  .result-bar {
    flex-direction: column;
    gap: 6px;
    text-align: center;
  }
}

/* --- Loading Skeleton --- */
.loading-skeleton {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-bg);
  z-index: 10;
  transition: opacity var(--transition-smooth);
}

.loading-skeleton.hidden {
  opacity: 0;
  pointer-events: none;
}

.loading-pulse {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.loading-text {
  font-size: 14px;
  color: var(--color-text-secondary);
  font-weight: 500;
}

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

/* --- Fade-in Animation --- */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.fade-in {
  animation: fadeIn 0.4s ease-out;
}
