/* ═══════════════════════════════════════════════════════════════
   ACHVC.COM — NETWORK SPEED TEST
   Theme: Deep dark, white typography, neon green/cyan accents
   ═══════════════════════════════════════════════════════════════ */

/* ── DESIGN TOKENS ─────────────────────────────────────────── */
:root {
  --bg-root:          #0a0a0c;
  --bg-surface:       #111114;
  --bg-card:          #13131a;
  --bg-card-header:   #0e0e14;
  --bg-footer:        #0e0e14;

  --border-default:   #1e1e2a;
  --border-neon:      #00ff88;
  --border-accent:    #00d4ff;

  --text-primary:     #f0f0f5;
  --text-secondary:   #8888aa;
  --text-muted:       #44445a;
  --text-neon:        #00ff88;
  --text-accent:      #00d4ff;
  --text-error:       #ff5555;

  --neon-glow:        0 0 8px rgba(0, 255, 136, 0.45);
  --accent-glow:      0 0 8px rgba(0, 212, 255, 0.45);
  --card-shadow:      0 0 0 1px var(--border-neon),
                      0 0 24px rgba(0, 255, 136, 0.07),
                      0 8px 40px rgba(0, 0, 0, 0.7);

  --nav-height:       52px;
  --font-mono:        'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
  --font-sans:        'Inter', system-ui, -apple-system, sans-serif;

  --radius-card:      8px;
  --radius-sm:        4px;

  --transition-fast:  150ms ease;
  --transition-med:   300ms ease;
  --transition-slow:  500ms ease;
}

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

html {
  height: 100%;
  scroll-behavior: smooth;
}

body {
  min-height: 100%;
  background-color: var(--bg-root);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

/* ── TOP NAVIGATION BAR ─────────────────────────────────────── */
.top-nav {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--nav-height);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-default);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.nav-inner {
  max-width: 1280px;
  height: 100%;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  align-items: center;
  gap: 16px;
}

/* Back link — retro escape mechanism */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text-secondary);
  text-decoration: none;
  font-family: var(--font-mono);
  font-size: 13px;
  padding: 6px 12px;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  transition: color var(--transition-fast), border-color var(--transition-fast), box-shadow var(--transition-fast);
  flex-shrink: 0;
}

.back-link:hover,
.back-link:focus-visible {
  color: var(--text-neon);
  border-color: var(--border-neon);
  box-shadow: var(--neon-glow);
  outline: none;
}

.back-arrow {
  font-size: 16px;
  line-height: 1;
  transition: transform var(--transition-fast);
}

.back-link:hover .back-arrow {
  transform: translateX(-3px);
}

/* Brand label */
.nav-brand {
  font-family: var(--font-mono);
  font-size: 13px;
  flex: 1;
  display: flex;
  align-items: center;
  gap: 2px;
  min-width: 0;
}

.brand-prefix   { color: var(--text-neon); font-weight: 700; }
.brand-suffix   { color: var(--text-primary); }
.brand-divider  { color: var(--text-muted); margin: 0 4px; }
.brand-tool     { color: var(--text-accent); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Status indicator */
.nav-status {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: background var(--transition-med), box-shadow var(--transition-med);
}

.status-dot.is-loading { background: #ffaa00; animation: pulse-amber 1.2s ease-in-out infinite; }
.status-dot.is-ready   { background: var(--text-neon); box-shadow: var(--neon-glow); }
.status-dot.is-error   { background: var(--text-error); }

.status-text {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-secondary);
  letter-spacing: 0.03em;
}

/* ── MAIN WORKSPACE ─────────────────────────────────────────── */
.workspace {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px 16px 32px;
  gap: 16px;
  min-height: 0;
}

/* ── TERMINAL-STYLE WRAPPER CARD ────────────────────────────── */
.terminal-card {
  width: 100%;
  max-width: 1100px;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border-neon);
  border-radius: var(--radius-card);
  background: var(--bg-card);
  box-shadow: var(--card-shadow);
  overflow: hidden;
  flex: 1;
  min-height: 0;
}

/* Card chrome header */
.card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: var(--bg-card-header);
  border-bottom: 1px solid var(--border-default);
  user-select: none;
  flex-shrink: 0;
}

.chrome-dots {
  display: flex;
  gap: 6px;
  align-items: center;
}

.dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
}
.dot-red    { background: #ff5f57; }
.dot-yellow { background: #febc2e; }
.dot-green  { background: #28c840; }

.card-title {
  flex: 1;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-secondary);
  text-align: center;
  letter-spacing: 0.04em;
}

.card-badge {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  color: var(--text-neon);
  background: rgba(0, 255, 136, 0.08);
  border: 1px solid rgba(0, 255, 136, 0.3);
  border-radius: var(--radius-sm);
  padding: 2px 7px;
  letter-spacing: 0.1em;
  animation: badge-blink 2s step-end infinite;
}

/* ── VIEWPORT CONTAINER ─────────────────────────────────────── */
/*
  Responsive scaling strategy:
  - On desktop/tablet: aspect-ratio 4/3 with max-height clamp so the
    card never overflows the viewport regardless of window height.
  - The skeleton and iframe share the same grid cell (position:absolute
    inside a position:relative parent), ensuring seamless state swap.
  - On mobile (<600px): aspect-ratio is released; a min-height ensures
    enough space for speed test buttons to remain accessible.
*/
.viewport {
  position: relative;
  flex: 1;
  min-height: 0;

  /* Fluid aspect ratio — 4:3 gives comfortable space for speed gauges */
  aspect-ratio: 4 / 3;

  /* Never taller than available screen real-estate */
  max-height: calc(100vh - var(--nav-height) - 110px);

  /* Ensure it's never too short to be usable */
  min-height: 360px;

  overflow: hidden;
  background: #000;
}

/* ── SKELETON LOADER OVERLAY ────────────────────────────────── */
.skeleton-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-card);
  z-index: 10;
  transition: opacity var(--transition-slow), visibility var(--transition-slow);
  opacity: 1;
  visibility: visible;
}

/* State: Ready — skeleton fades out */
.viewport.loaded .skeleton-overlay {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.skeleton-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  text-align: center;
  padding: 32px;
  position: relative;
  z-index: 1;
}

.skeleton-icon {
  color: var(--text-neon);
  opacity: 0.7;
  animation: spin-slow 4s linear infinite;
}

.skeleton-headline {
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 500;
  color: var(--text-primary);
  letter-spacing: 0.02em;
}

.skeleton-subline {
  font-size: 12px;
  color: var(--text-secondary);
  font-family: var(--font-mono);
}

/* Animated shimmer bars */
.skeleton-bars {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 220px;
  margin-top: 4px;
}

.skel-bar {
  height: 6px;
  border-radius: 3px;
  background: linear-gradient(
    90deg,
    var(--border-default) 25%,
    rgba(0, 255, 136, 0.15) 50%,
    var(--border-default) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.8s ease-in-out infinite;
}

.skel-bar--wide   { width: 100%; }
.skel-bar--medium { width: 70%; }
.skel-bar--narrow { width: 45%; }

/* Pulse ring behind icon */
.skeleton-pulse-ring {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 120px;
  height: 120px;
  border-radius: 50%;
  border: 1px solid rgba(0, 255, 136, 0.15);
  animation: ring-expand 2s ease-out infinite;
  pointer-events: none;
}

/* ── IFRAME ─────────────────────────────────────────────────── */
.speed-iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: none;
  display: block;
  opacity: 0;
  transition: opacity var(--transition-slow);
  background: #fff; /* LibreSpeed has a light bg — will be contained */
}

/* State: Ready — iframe fades in */
.viewport.loaded .speed-iframe {
  opacity: 1;
}

/* ── CARD FOOTER ────────────────────────────────────────────── */
.card-footer {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 16px;
  padding: 8px 16px;
  background: var(--bg-footer);
  border-top: 1px solid var(--border-default);
  flex-shrink: 0;
}

.footer-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.footer-label {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.footer-value {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-secondary);
}

.footer-sep {
  color: var(--text-muted);
  font-size: 12px;
}

.footer-item--tip .footer-value {
  color: var(--text-accent);
}

/* ── ERROR BANNER ───────────────────────────────────────────── */
.error-banner {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 14px 20px;
  background: rgba(255, 85, 85, 0.07);
  border: 1px solid rgba(255, 85, 85, 0.3);
  border-radius: var(--radius-card);
  width: 100%;
  max-width: 1100px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-error);
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--transition-med), visibility var(--transition-med);
}

.error-banner.visible {
  opacity: 1;
  visibility: visible;
}

.error-icon { font-size: 16px; flex-shrink: 0; }

.error-link {
  color: var(--text-accent);
  margin-left: 8px;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.error-link:hover { color: var(--text-neon); }

/* ── ANIMATIONS ─────────────────────────────────────────────── */
@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

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

@keyframes ring-expand {
  0%   { transform: translate(-50%, -50%) scale(0.6); opacity: 0.5; }
  100% { transform: translate(-50%, -50%) scale(1.8); opacity: 0; }
}

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

@keyframes badge-blink {
  0%, 49% { opacity: 1; }
  50%, 100% { opacity: 0.4; }
}

/* ── RESPONSIVE BREAKPOINTS ─────────────────────────────────── */

/* Tablet (≤ 768px): tighten spacing */
@media (max-width: 768px) {
  .workspace { padding: 16px 12px 24px; }

  .nav-brand { display: none; }  /* save space on small nav */

  .viewport {
    max-height: calc(100vh - var(--nav-height) - 100px);
    min-height: 400px;
  }

  .footer-item--tip { display: none; } /* drop tip on tablets */
}

/* Mobile (≤ 600px): release aspect-ratio, fixed height mode */
@media (max-width: 600px) {
  :root { --nav-height: 48px; }

  .back-label { display: none; } /* show only arrow on mobile */

  .back-link { padding: 6px 10px; }

  .workspace { padding: 12px 8px 20px; }

  .terminal-card { border-radius: var(--radius-sm); }

  .viewport {
    /* Release fluid aspect-ratio; use viewport-based height */
    aspect-ratio: unset;
    height: calc(100svh - var(--nav-height) - 90px);
    max-height: none;
    min-height: 320px;
  }

  .skeleton-bars { width: 160px; }

  .card-footer {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }

  .footer-sep { display: none; }
}

/* Large screens: ensure card doesn't get absurdly tall */
@media (min-width: 1400px) {
  .viewport { max-height: 780px; }
}

/* ── FOCUS / ACCESSIBILITY ──────────────────────────────────── */
:focus-visible {
  outline: 2px solid var(--border-neon);
  outline-offset: 3px;
  border-radius: var(--radius-sm);
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .skel-bar,
  .skeleton-icon,
  .skeleton-pulse-ring,
  .card-badge { animation: none !important; }

  .skeleton-overlay,
  .speed-iframe { transition: none !important; }
}
