/* === JFS-IT SpeedTest - Modern Dark Theme === */

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

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

:root {
    --bg: #0a0e17;
    --bg-card: rgba(255, 255, 255, 0.03);
    --bg-card-hover: rgba(255, 255, 255, 0.06);
    --border: rgba(255, 255, 255, 0.08);
    --border-active: rgba(0, 212, 255, 0.3);
    --text: #e8f0fe;
    --text-dim: rgba(232, 240, 254, 0.5);
    --text-muted: rgba(232, 240, 254, 0.3);
    --accent: #00d4ff;
    --accent-2: #0066ff;
    --accent-glow: rgba(0, 212, 255, 0.15);
    --download: #00d4ff;
    --upload: #ff6b9d;
    --ping: #4cffaa;
    --jitter: #ffaa00;
    --radius: 16px;
    --radius-lg: 24px;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

html {
    -webkit-tap-highlight-color: transparent;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Animated background */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    background:
        radial-gradient(circle at 20% 20%, rgba(0, 212, 255, 0.08) 0%, transparent 50%),
        radial-gradient(circle at 80% 80%, rgba(0, 102, 255, 0.06) 0%, transparent 50%),
        radial-gradient(circle at 50% 50%, rgba(255, 107, 157, 0.04) 0%, transparent 50%);
    pointer-events: none;
    z-index: 0;
    animation: bgPulse 8s ease-in-out infinite alternate;
}

@keyframes bgPulse {
    0% { opacity: 0.8; }
    100% { opacity: 1; }
}

.app {
    position: relative;
    z-index: 1;
    max-width: 680px;
    margin: 0 auto;
    padding: 20px 16px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* === Header === */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 28px;
    flex-shrink: 0;
}

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

.logo-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    background: linear-gradient(135deg, rgba(0, 212, 255, 0.15), rgba(0, 102, 255, 0.15));
    border-radius: 12px;
    border: 1px solid var(--border);
}

.logo-text {
    display: flex;
    flex-direction: column;
    line-height: 1;
}

.logo-jfs {
    font-size: 16px;
    font-weight: 700;
    background: linear-gradient(90deg, var(--accent), var(--accent-2));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.logo-speed {
    font-size: 11px;
    font-weight: 500;
    color: var(--text-dim);
    margin-top: 2px;
}

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

.status-pill {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-dim);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--ping);
    box-shadow: 0 0 8px var(--ping);
    animation: pulse 2s ease-in-out infinite;
}

.status-pill.testing .status-dot {
    background: var(--accent);
    box-shadow: 0 0 8px var(--accent);
}

.status-pill.done .status-dot {
    background: var(--download);
    box-shadow: 0 0 8px var(--download);
}

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

.install-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    color: var(--text-dim);
    cursor: pointer;
    transition: var(--transition);
}

.install-btn:hover {
    background: var(--bg-card-hover);
    border-color: var(--border-active);
    color: var(--accent);
}

/* === Main === */
.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* === Gauge === */
.gauge-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 24px;
    padding: 20px 0;
}

.gauge-wrapper {
    position: relative;
    width: 260px;
    height: 260px;
}

.gauge-svg {
    width: 100%;
    height: 100%;
    filter: drop-shadow(0 0 20px var(--accent-glow));
}

.gauge-center {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
}

.gauge-value {
    font-size: 48px;
    font-weight: 800;
    line-height: 1;
    color: var(--text);
    font-variant-numeric: tabular-nums;
    letter-spacing: -2px;
}

.gauge-unit {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-dim);
    margin-top: 4px;
}

.gauge-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    margin-top: 8px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.start-btn {
    position: relative;
    padding: 14px 40px;
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    border: none;
    border-radius: 14px;
    color: white;
    font-family: inherit;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    overflow: hidden;
    transition: var(--transition);
    box-shadow: 0 4px 20px rgba(0, 212, 255, 0.3);
}

.start-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 30px rgba(0, 212, 255, 0.4);
}

.start-btn:active {
    transform: translateY(0);
}

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

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

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

/* === Stats Grid === */
.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.stat-card {
    position: relative;
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    transition: var(--transition);
}

.stat-card.active {
    border-color: var(--border-active);
    background: var(--bg-card-hover);
}

.stat-card.active .stat-icon {
    animation: iconPulse 1s ease-in-out infinite;
}

@keyframes iconPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

.stat-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    flex-shrink: 0;
}

#downloadCard .stat-icon { color: var(--download); background: rgba(0, 212, 255, 0.1); }
#uploadCard .stat-icon { color: var(--upload); background: rgba(255, 107, 157, 0.1); }
#pingCard .stat-icon { color: var(--ping); background: rgba(76, 255, 170, 0.1); }
#jitterCard .stat-icon { color: var(--jitter); background: rgba(255, 170, 0, 0.1); }

.stat-info {
    flex: 1;
    min-width: 0;
}

.stat-value {
    font-size: 24px;
    font-weight: 700;
    line-height: 1.1;
    font-variant-numeric: tabular-nums;
}

.stat-label {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-dim);
    margin-top: 2px;
}

.stat-unit {
    font-size: 11px;
    color: var(--text-muted);
}

.stat-bar {
    position: absolute;
    bottom: 0;
    left: 0;
    height: 3px;
    width: 0%;
    transition: width 0.5s ease;
}

#downloadCard .stat-bar { background: var(--download); box-shadow: 0 0 8px var(--download); }
#uploadCard .stat-bar { background: var(--upload); box-shadow: 0 0 8px var(--upload); }

/* === Graph === */
.graph-section {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
}

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

.graph-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-dim);
}

.graph-legend {
    display: flex;
    gap: 14px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 11px;
    color: var(--text-muted);
}

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

.legend-dot.download { background: var(--download); }
.legend-dot.upload { background: var(--upload); }

#liveGraph {
    width: 100%;
    height: 160px;
    display: block;
}

/* === ISP === */
.isp-section {
    margin-top: 0;
}

.isp-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.isp-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 0;
}

.isp-row + .isp-row {
    border-top: 1px solid var(--border);
}

.isp-label {
    font-size: 13px;
    color: var(--text-dim);
    font-weight: 500;
}

.isp-value {
    font-size: 13px;
    color: var(--text);
    font-weight: 600;
    text-align: right;
}

/* === Quote === */
.quote-section {
    margin-top: 0;
}

.quote-card {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 18px 20px;
    background: linear-gradient(135deg, rgba(0, 212, 255, 0.08), rgba(0, 102, 255, 0.05));
    border: 1px solid var(--border-active);
    border-radius: var(--radius);
    animation: quoteSlide 0.5s ease;
}

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

.quote-icon {
    font-size: 22px;
    flex-shrink: 0;
}

.quote-text {
    font-size: 14px;
    font-weight: 500;
    line-height: 1.5;
    color: var(--text);
}

/* === History === */
.history-section {
    margin-top: 0;
}

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

.history-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-dim);
}

.history-clear {
    font-size: 12px;
    color: var(--text-muted);
    background: none;
    border: none;
    cursor: pointer;
    transition: var(--transition);
}

.history-clear:hover {
    color: var(--text);
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.history-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 12px;
    animation: quoteSlide 0.3s ease;
}

.history-time {
    color: var(--text-muted);
    font-size: 11px;
    flex-shrink: 0;
}

.history-speed {
    color: var(--text);
    font-weight: 600;
    display: flex;
    gap: 8px;
}

.history-speed .dl { color: var(--download); }
.history-speed .ul { color: var(--upload); }
.history-speed .pg { color: var(--ping); }

/* === Footer === */
.footer {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 20px 0 8px;
    font-size: 11px;
    color: var(--text-muted);
    flex-shrink: 0;
}

.footer-link {
    color: var(--accent);
    text-decoration: none;
    font-weight: 600;
}

.footer-link:hover {
    text-decoration: underline;
}

.footer-sep {
    color: var(--text-muted);
}

/* === Responsive === */
@media (max-width: 480px) {
    .app {
        padding: 14px 12px;
    }
    
    .gauge-wrapper {
        width: 220px;
        height: 220px;
    }
    
    .gauge-value {
        font-size: 40px;
    }
    
    .start-btn {
        padding: 12px 32px;
        font-size: 15px;
    }
    
    .stats-grid {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }
    
    .stat-card {
        padding: 12px;
        gap: 10px;
    }
    
    .stat-value {
        font-size: 20px;
    }
    
    .stat-icon {
        width: 36px;
        height: 36px;
    }
    
    #liveGraph {
        height: 120px;
    }
    
    .logo-jfs {
        font-size: 14px;
    }
    
    .logo-speed {
        font-size: 10px;
    }
}

@media (min-width: 768px) {
    .app {
        padding: 32px 24px;
    }
    
    .gauge-wrapper {
        width: 300px;
        height: 300px;
    }
    
    .gauge-value {
        font-size: 56px;
    }
}

/* === Test animations === */
.stat-card.flash {
    animation: flashCard 0.4s ease;
}

@keyframes flashCard {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); border-color: var(--accent); }
    100% { transform: scale(1); }
}
