/* ── Qinaya Network X-Ray — Style ── */
:root {
  --bg: #080c18;
  --panel: #0f1528;
  --panel-2: #0c1120;
  --panel-border: #1a2340;
  --accent: #37d4ff;
  --accent-glow: rgba(55, 212, 255, 0.15);
  --text: #e6ecff;
  --muted: #7b8ab5;
  --danger: #ff4757;
  --warning: #ffa502;
  --good: #2ed573;
  --purple: #a78bfa;
  --radius: 16px;
  --radius-sm: 10px;
  --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--text);
  background: radial-gradient(ellipse 1400px 700px at 15% -5%, #151f4a 0%, transparent 60%),
              radial-gradient(ellipse 1000px 500px at 85% 15%, #0e3a4a 0%, transparent 50%),
              var(--bg);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

.app {
  max-width: 720px;
  margin: 0 auto;
  padding: 28px 20px 56px;
  display: grid;
  gap: 16px;
  min-width: 0;
  overflow: hidden;
}

.panel {
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.25);
}

h2 { font-size: 1rem; font-weight: 600; margin: 0 0 14px; color: var(--text); }

/* ═══ Start Screen ═══ */
.start-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  min-height: 70vh;
  gap: 16px;
  padding: 40px 20px;
}

.start-logo { opacity: 0.8; }

.start-title {
  font-size: 2rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--text), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.start-subtitle {
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.6;
  max-width: 400px;
}

.start-explainer {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  max-width: 440px;
  margin-top: 20px;
  padding: 14px 18px;
  background: rgba(55, 212, 255, 0.05);
  border: 1px solid rgba(55, 212, 255, 0.12);
  border-radius: var(--radius-sm);
  text-align: left;
}

.start-explainer svg {
  flex-shrink: 0;
  color: var(--accent);
  margin-top: 2px;
}

.start-explainer p {
  font-size: 0.78rem;
  line-height: 1.6;
  color: var(--muted);
  margin: 0;
}

.start-explainer strong {
  color: var(--text);
}

/* -- Connection info bar -- */
.connection-info {
  width: 100%;
  max-width: 480px;
  margin-bottom: 20px;
  padding: 14px 20px;
  background: rgba(55, 212, 255, 0.05);
  border: 1px solid rgba(55, 212, 255, 0.12);
  border-radius: var(--radius);
  text-align: center;
}

.connection-info-results {
  margin-bottom: 16px;
}

.conn-loading {
  font-size: 0.82rem;
  color: var(--muted);
  animation: pulse 1.5s ease-in-out infinite;
}

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

.conn-details {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.conn-line {
  margin: 0;
  font-size: 0.88rem;
  color: var(--muted);
  line-height: 1.5;
}

.conn-line strong {
  color: var(--text);
  font-weight: 700;
}

.conn-ip {
  font-size: 0.78rem;
  opacity: 0.7;
}

.conn-ip strong {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.76rem;
}

.big-start-btn {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  background: linear-gradient(135deg, var(--accent), #2ba8d4);
  border: none;
  border-radius: 999px;
  padding: 18px 40px;
  font-size: 1.15rem;
  font-weight: 700;
  cursor: pointer;
  color: #061017;
  box-shadow: 0 6px 30px rgba(55,212,255,0.4);
  transition: var(--transition);
  font-family: inherit;
  margin-top: 12px;
}

.big-start-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 40px rgba(55,212,255,0.5);
}

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

/* ═══ Progress Screen ═══ */
.progress-screen {
  text-align: center;
  padding: 48px 28px 40px;
  min-height: 60vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0;
}

.progress-screen > * {
  flex-shrink: 0;
}

/* -- Live Gauge -- */
.live-gauge {
  margin-bottom: 16px;
  position: relative;
  width: 240px;
}

.live-gauge-svg {
  width: 240px;
  height: 140px;
}

.live-gauge-label {
  text-align: center;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent);
  margin-top: -8px;
  opacity: 0.8;
}

.progress-status {
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: 20px;
  color: var(--text);
}

.progress-bar-track {
  height: 10px;
  background: #1a2340;
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 12px;
  width: 100%;
  max-width: 520px;
}

.progress-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), #2ba8d4);
  border-radius: 999px;
  transition: width 0.5s ease;
}

.progress-detail {
  font-size: 0.82rem;
  color: var(--muted);
}

.factoid {
  margin-top: 36px;
  padding: 24px 28px;
  background: rgba(55, 212, 255, 0.06);
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 1.05rem;
  line-height: 1.75;
  color: var(--text);
  max-width: 520px;
  width: 100%;
  text-align: left;
  min-height: 80px;
  display: block;
  opacity: 1;
  transition: opacity 0.4s ease;
}

.factoid:empty {
  display: none;
}

.factoid.fade-out {
  opacity: 0;
}

/* -- Step summary -- */
.step-summary {
  margin-top: 28px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px 16px;
  max-width: 520px;
  width: 100%;
}

.step-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  color: var(--muted);
  opacity: 0.5;
  transition: opacity 0.3s ease, color 0.3s ease;
  white-space: nowrap;
}

.step-item.active {
  opacity: 1;
  color: var(--accent);
  font-weight: 600;
}

.step-item.done {
  opacity: 0.8;
  color: var(--good);
}

.step-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
  opacity: 0.4;
  transition: background 0.3s ease, opacity 0.3s ease, box-shadow 0.3s ease;
  flex-shrink: 0;
}

.step-item.active .step-dot {
  background: var(--accent);
  opacity: 1;
  box-shadow: 0 0 6px rgba(55, 212, 255, 0.5);
}

.step-item.done .step-dot {
  background: var(--good);
  opacity: 1;
}

.factoid strong {
  color: var(--accent);
  font-weight: 700;
}

/* ═══ Results Header ═══ */
.results-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
}

.results-logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.results-brand {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--muted);
}

.btn-secondary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  padding: 8px 18px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
  transition: var(--transition);
}

.btn-secondary:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-glow);
}

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

.share-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 14px 20px;
  margin-bottom: 16px;
  background: linear-gradient(135deg, rgba(55, 212, 255, 0.10), rgba(43, 168, 212, 0.08));
  border: 1px solid rgba(55, 212, 255, 0.2);
  border-radius: var(--radius);
  animation: fadeSlideDown 0.5s ease;
}

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

.share-confirmation {
  font-size: 0.85rem;
  font-weight: 600;
  color: #2ed573;
  transition: opacity 0.3s ease;
}

.btn-share {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: linear-gradient(135deg, var(--accent), #2ba8d4);
  border: none;
  border-radius: 999px;
  padding: 10px 24px;
  font-size: 0.92rem;
  font-weight: 700;
  color: #061017;
  cursor: pointer;
  font-family: inherit;
  transition: var(--transition);
  box-shadow: 0 2px 12px rgba(55,212,255,0.3);
}

.btn-share:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 18px rgba(55,212,255,0.45);
  background: linear-gradient(135deg, #5ce0ff, #37d4ff);
}

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

.shared-banner {
  text-align: center;
  padding: 10px 16px;
  background: rgba(55, 212, 255, 0.08);
  border: 1px solid rgba(55, 212, 255, 0.15);
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  color: var(--accent);
  font-weight: 500;
}

/* ═══ Verdict Card (screenshot target) ═══ */
.verdict-card {
  padding: 28px;
}

.verdict-top {
  display: flex;
  align-items: center;
  gap: 28px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.verdict-gauge {
  position: relative;
  flex-shrink: 0;
}

.gauge-svg { width: 180px; height: 108px; }

.grade-badge {
  position: absolute;
  bottom: 4px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel);
  border: 2px solid var(--accent);
  border-radius: 50%;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  font-weight: 800;
  color: var(--accent);
  box-shadow: 0 0 12px var(--accent-glow);
}

.verdict-text { flex: 1; min-width: 200px; }

.verdict-title {
  font-size: 1.5rem;
  font-weight: 800;
  line-height: 1.2;
  margin-bottom: 6px;
}

.verdict-subtitle {
  font-size: 0.9rem;
  color: var(--muted);
  line-height: 1.5;
}

.verdict-speeds {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.speed-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 700;
  font-family: "JetBrains Mono", monospace;
  border: 1px solid var(--panel-border);
  background: rgba(255,255,255,0.02);
}

.speed-pill small {
  font-weight: 400;
  font-size: 0.7rem;
  color: var(--muted);
  font-family: "Inter", sans-serif;
}

.speed-pill.download { color: var(--good); }
.speed-pill.upload   { color: var(--purple); }
.speed-pill.latency  { color: var(--accent); }
.speed-pill.jitter   { color: var(--warning); }

/* ═══ Findings ═══ */
.findings-card { padding: 22px; }
.findings-card h2 { margin-bottom: 12px; }

.findings-list {
  list-style: none;
  display: grid;
  gap: 0;
}

.finding {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid #151d35;
  font-size: 0.9rem;
  line-height: 1.5;
}

.finding:last-child { border-bottom: none; }

.finding-icon {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 700;
  margin-top: 1px;
}

.finding-icon.good   { background: rgba(46,213,115,0.15); color: var(--good); }
.finding-icon.warn   { background: rgba(255,165,2,0.15); color: var(--warning); }
.finding-icon.bad    { background: rgba(255,71,87,0.15); color: var(--danger); }

.finding-text { color: var(--text); }
.finding-detail { color: var(--muted); font-size: 0.78rem; margin-top: 2px; }

/* ═══ Chart ═══ */
.chart-panel { padding: 18px; min-width: 0; overflow: hidden; }
.chart-title { font-size: 0.9rem; margin-bottom: 8px; }

.chart-legend-simple {
  display: flex;
  gap: 12px;
  font-size: 0.7rem;
  color: var(--muted);
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.chart-legend-simple span { display: flex; align-items: center; gap: 4px; }

.legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.chart-wrapper {
  background: #080e1e;
  border-radius: var(--radius-sm);
  border: 1px solid #151d35;
  padding: 8px;
  overflow: hidden;
  min-width: 0;
}

.chart-wrapper canvas {
  display: block;
  max-width: 100%;
  height: 180px;
}

/* ═══ Tech Details (collapsible) ═══ */
.tech-details { cursor: default; }

.tech-details summary {
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  padding: 4px 0;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
}

.tech-details summary::before {
  content: "▸";
  transition: var(--transition);
  font-size: 0.8rem;
}

.tech-details[open] summary::before {
  content: "▾";
}

.tech-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 10px;
  margin: 16px 0;
}

.tech-item {
  background: rgba(255,255,255,0.02);
  border: 1px solid #151d35;
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  transition: var(--transition);
}

.tech-item:hover {
  border-color: rgba(55,212,255,0.3);
  background: rgba(255,255,255,0.04);
}

/* Tech item tooltips: position above the item */
.tech-item[data-tooltip]::after {
  left: 0;
  transform: translateX(0) translateY(4px);
  max-width: 240px;
}

.tech-item[data-tooltip]:hover::after {
  transform: translateX(0) translateY(0);
}

.tech-item[data-tooltip]::before {
  left: 20px;
  transform: translateX(0);
}

.tech-item-label {
  font-size: 0.65rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.tech-item-value {
  font-size: 1.1rem;
  font-weight: 700;
  font-family: "JetBrains Mono", monospace;
}

.tech-item-value.good { color: var(--good); }
.tech-item-value.warn { color: var(--warning); }
.tech-item-value.bad  { color: var(--danger); }

.tech-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 8px;
}

/* ═══ Tooltips ═══ */
[data-tooltip] {
  position: relative;
  cursor: help;
}

[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 10px);
  left: 50%;
  transform: translateX(-50%) translateY(4px);
  background: #1a2240;
  color: var(--text);
  font-size: 0.75rem;
  font-weight: 400;
  line-height: 1.5;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid #2a3558;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  white-space: normal;
  width: max-content;
  max-width: 280px;
  z-index: 1000;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

[data-tooltip]:hover::after {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

[data-tooltip]::before {
  content: "";
  position: absolute;
  bottom: calc(100% + 4px);
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: #1a2240;
  z-index: 1001;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease;
}

[data-tooltip]:hover::before {
  opacity: 1;
}

/* Tooltip below for elements near the top of the screen */
.verdict-gauge[data-tooltip]::after {
  bottom: auto;
  top: calc(100% + 10px);
  transform: translateX(-50%) translateY(-4px);
}

.verdict-gauge[data-tooltip]:hover::after {
  transform: translateX(-50%) translateY(0);
}

.verdict-gauge[data-tooltip]::before {
  bottom: auto;
  top: calc(100% + 4px);
  border-top-color: transparent;
  border-bottom-color: #1a2240;
}

/* Tooltip below for chart legend items (near chart) */
.chart-legend-simple span[data-tooltip]::after {
  bottom: auto;
  top: calc(100% + 10px);
  transform: translateX(-50%) translateY(-4px);
}

.chart-legend-simple span[data-tooltip]:hover::after {
  transform: translateX(-50%) translateY(0);
}

.chart-legend-simple span[data-tooltip]::before {
  bottom: auto;
  top: calc(100% + 4px);
  border-top-color: transparent;
  border-bottom-color: #1a2240;
}

/* Prevent tooltip overflow on edges */
.chart-legend-simple span:last-child[data-tooltip]::after {
  left: auto;
  right: 0;
  transform: translateX(0) translateY(-4px);
}

.chart-legend-simple span:last-child[data-tooltip]:hover::after {
  transform: translateX(0) translateY(0);
}

.chart-legend-simple span:first-child[data-tooltip]::after {
  left: 0;
  transform: translateX(0) translateY(-4px);
}

.chart-legend-simple span:first-child[data-tooltip]:hover::after {
  transform: translateX(0) translateY(0);
}

/* ═══ Animations ═══ */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

.verdict-card, .findings-card, .chart-panel, .tech-details {
  animation: fadeInUp 0.5s ease both;
}

.findings-card { animation-delay: 0.1s; }
.chart-panel   { animation-delay: 0.2s; }
.tech-details  { animation-delay: 0.3s; }

/* ═══ Responsive ═══ */
@media (max-width: 600px) {
  .app { padding: 16px 12px 40px; }
  .start-title { font-size: 1.5rem; }
  .big-start-btn { padding: 14px 28px; font-size: 1rem; }
  .verdict-top { flex-direction: column; text-align: center; gap: 16px; }
  .verdict-text { min-width: auto; text-align: center; }
  .verdict-speeds { justify-content: center; }
  .gauge-svg { width: 150px; height: 90px; }
  .verdict-title { font-size: 1.2rem; }
  .tech-grid { grid-template-columns: 1fr 1fr; }
  .speed-pill { font-size: 0.78rem; padding: 6px 10px; }
}
