/* Modern Speed Test CSS */
* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

:root {
    --primary: #00f2ff;
    --secondary: #008cff;
    --bg-dark: #0f172a;
    --card-bg: rgba(255, 255, 255, 0.05);
    --text-main: #ffffff;
    --text-muted: #94a3b8;
    --success: #10b981;
    --glass-border: rgba(255, 255, 255, 0.1);
    --font-family: 'Inter', sans-serif;
}

html,
body {
    width: 100%;
    overflow-x: hidden;
    margin: 0;
    padding: 0;
    font-family: var(--font-family);
    background-color: var(--bg-dark);
    background-image:
        radial-gradient(circle at 10% 20%, rgba(0, 242, 255, 0.1) 0%, transparent 40%),
        radial-gradient(circle at 90% 80%, rgba(0, 140, 255, 0.1) 0%, transparent 40%);
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
}

.container {
    width: 100%;
    max-width: 800px;
    padding: 1rem;
    box-sizing: border-box;
    overflow: hidden;
    /* Prevent child overflow */
}

/* Header */
header {
    text-align: center;
    margin-bottom: 40px;
}

h1 {
    font-size: 2.5rem;
    margin: 0;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    font-weight: 800;
    letter-spacing: -1px;
}

.subtitle {
    color: var(--text-muted);
    margin-top: 10px;
    font-size: 1.1rem;
}

/* Main Gauge Section */
.gauge-container {
    position: relative;
    width: 300px;
    height: 300px;
    margin: 0 auto 50px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Circular Progress */
.circular-chart {
    display: block;
    margin: 0 auto;
    max-width: 100%;
    max-height: 100%;
    transform: rotate(-90deg);
    /* Start from top */
}

.circle-bg {
    fill: none;
    stroke: var(--card-bg);
    stroke-width: 2.5;
}

.circle {
    fill: none;
    stroke: var(--primary);
    stroke-width: 2.5;
    stroke-linecap: round;
    transition: stroke-dasharray 0.3s ease;
    filter: drop-shadow(0 0 10px rgba(0, 242, 255, 0.5));
}

.gauge-center {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    z-index: 10;
}

.speed-value {
    font-size: 3.5rem;
    font-weight: 700;
    line-height: 1;
    display: block;
}

.speed-unit {
    font-size: 1rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-top: 5px;
    display: block;
}

.status-text {
    position: absolute;
    bottom: -40px;
    left: 0;
    right: 0;
    text-align: center;
    color: var(--secondary);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 2px;
    font-size: 0.9rem;
}

/* Start Button */
.start-btn {
    width: 180px;
    height: 180px;
    border-radius: 50%;
    border: 2px solid var(--primary);
    background: rgba(0, 242, 255, 0.1);
    color: var(--primary);
    font-size: 1.5rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 2px;
    box-shadow: 0 0 20px rgba(0, 242, 255, 0.2);
    position: absolute;
    z-index: 20;
}

.start-btn:hover {
    background: var(--primary);
    color: #000;
    box-shadow: 0 0 40px rgba(0, 242, 255, 0.6);
    transform: scale(1.05);
}

.start-btn.hidden {
    opacity: 0 !important;
    visibility: hidden !important;
    display: none !important;
    pointer-events: none;
    transform: scale(0);
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 15px;
    margin-top: 20px;
}

.stat-card {
    background: var(--card-bg);
    border: 1px solid var(--glass-border);
    padding: 20px;
    border-radius: 16px;
    text-align: center;
    backdrop-filter: blur(10px);
    transition: transform 0.2s;
}

.stat-card:hover {
    transform: translateY(-2px);
    background: rgba(255, 255, 255, 0.08);
}

.stat-label {
    display: block;
    color: var(--text-muted);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 8px;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-main);
}

.stat-unit {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-left: 2px;
}

/* Icons */
.icon {
    margin-bottom: 10px;
    font-size: 1.2rem;
    opacity: 0.8;
}

.icon-ping {
    color: #fbbf24;
}

.icon-jitter {
    color: #a8a29e;
}

.icon-download {
    color: #00f2ff;
}

.icon-upload {
    color: #a855f7;
}

/* Footer info */
.footer-info {
    margin-top: 40px;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.9rem;
    display: flex;
    justify-content: center;
    gap: 20px;
}

.info-item span {
    color: var(--text-main);
    margin-left: 5px;
}

/* Mobile Responsive */
@media (max-width: 600px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    h1 {
        font-size: 2rem;
    }

    .gauge-container {
        width: 250px;
        height: 250px;
    }
}

/* Animations */
@keyframes pulse {
    0% {
        filter: drop-shadow(0 0 10px rgba(0, 242, 255, 0.5));
    }

    50% {
        filter: drop-shadow(0 0 25px rgba(0, 242, 255, 0.8));
    }

    100% {
        filter: drop-shadow(0 0 10px rgba(0, 242, 255, 0.5));
    }
}

.pulsing {
    animation: pulse 1.5s infinite ease-in-out;
}

/* Modal Styles */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(5px);
    z-index: 100;
    display: flex;
    justify-content: center;
    align-items: center;
}

.modal-content {
    background: #1e293b;
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    width: 90%;
    max-width: 500px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from {
        transform: translateY(20px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-header {
    padding: 20px;
    border-bottom: 1px solid var(--glass-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    margin: 0;
    color: var(--text-main);
}

.close-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
    transition: color 0.2s;
}

.close-btn:hover {
    color: var(--primary);
}

.modal-body {
    padding: 10px;
    overflow-y: auto;
}

.server-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.server-item {
    padding: 15px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    color: var(--text-muted);
}

.server-item:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-main);
}

.server-item.active {
    background: rgba(0, 242, 255, 0.1);
    color: var(--primary);
    border: 1px solid rgba(0, 242, 255, 0.2);
}

.server-item i {
    margin-right: 10px;
}

/* SEO Content Section */
.seo-content {
    margin-top: 4rem;
    padding-top: 2rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    text-align: left;
    color: var(--text-secondary);
}

.content-wrapper {
    max-width: 800px;
    margin: 0 auto;
}

.seo-content h2 {
    color: var(--text-primary);
    font-size: 1.8rem;
    margin-bottom: 1rem;
    text-align: center;
}

.seo-content p {
    line-height: 1.6;
    margin-bottom: 2rem;
    font-size: 0.95rem;
}

.info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
    margin-top: 2rem;
}

.info-box {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    padding: 1.5rem;
    transition: transform 0.3s ease;
}

.info-box:hover {
    transform: translateY(-5px);
    background: rgba(255, 255, 255, 0.05);
}

.info-box h3 {
    color: var(--primary-color);
    font-size: 1.1rem;
    margin-bottom: 0.8rem;
    display: flex;
    align-items: center;
    gap: 10px;
}

.info-box h3 i {
    font-size: 0.9em;
}

.info-box p {
    margin-bottom: 0;
    font-size: 0.85rem;
    color: var(--text-secondary);
}


/* Streaming Check Section */
.streaming-section {
    margin-top: 2rem;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 12px;
    padding: 1.5rem;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.streaming-section h3 {
    margin-bottom: 1rem;
    font-size: 1.1rem;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 10px;
}

.stream-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
}

.stream-item {
    background: rgba(255, 255, 255, 0.05);
    padding: 1rem;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    text-align: center;
}

.stream-item i:first-child {
    font-size: 1.5rem;
    color: var(--text-secondary);
}

.stream-item .status-icon {
    font-size: 1.2rem;
    margin-top: 5px;
}

.status-success {
    color: #00ff88;
}

.status-warn {
    color: #ffcc00;
}

.status-fail {
    color: #ff0055;
}


/* Result History Section */
.history-section {
    margin-top: 1.5rem;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 12px;
    padding: 1.5rem;
}

.history-section h3 {
    margin-bottom: 1rem;
    font-size: 1.1rem;
    color: var(--text-primary);
}

.history-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.history-table th {
    text-align: left;
    color: var(--text-secondary);
    padding: 8px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.history-table td {
    padding: 8px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
}

.text-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 0.8rem;
    margin-top: 10px;
    cursor: pointer;
    text-decoration: underline;
}

/* Share Section */
.share-section {
    margin-top: 1.5rem;
    text-align: center;
}

.share-buttons {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin-top: 1rem;
}

.share-btn {
    border: none;
    padding: 0.8rem 1.5rem;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    color: #fff;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: transform 0.2s;
}

.share-btn:hover {
    transform: scale(1.05);
}

.share-btn.whatsapp {
    background: #25D366;
}

.share-btn.copy {
    background: #333;
    border: 1px solid #555;
}


/* Theme Toggle */
.theme-toggle {
    position: absolute;
    top: 20px;
    right: 20px;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: #fff;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.2rem;
    transition: background 0.3s;
}

.theme-toggle:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Light Theme Variables */
body.light-mode {
    --bg-color: #f0f2f5;
    --text-primary: #333;
    --text-secondary: #666;
    --text-main: #333;
    /* Fix: Update main text color for light mode */
    --card-bg: #ffffff;
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
}

body.light-mode .container {
    background: rgba(255, 255, 255, 0.8);
    box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.4);
}

body.light-mode .stat-card,
body.light-mode .info-box,
body.light-mode .stream-item,
body.light-mode .history-section,
body.light-mode .streaming-section {
    background: rgba(0, 0, 0, 0.03);
    border: 1px solid rgba(0, 0, 0, 0.05);
    color: #333;
}

body.light-mode .stat-label,
body.light-mode h1,
body.light-mode h2,
body.light-mode h3,
body.light-mode .subtitle {
    color: #333;
}

body.light-mode .stat-value {
    color: #000;
}

body.light-mode .theme-toggle {
    background: rgba(0, 0, 0, 0.1);
    color: #333;
}

/* Graph */
#realtime-graph {
    width: 100%;
    max-width: 300px;
    transition: opacity 0.5s;
}

/* Install Button */
.install-btn {
    position: absolute;
    top: 20px;
    left: 20px;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    border: none;
    color: #000;
    padding: 8px 16px;
    border-radius: 20px;
    cursor: pointer;
    font-weight: 700;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 4px 15px rgba(0, 242, 255, 0.2);
    transition: transform 0.2s;
    z-index: 50;
}

.install-btn:hover {
    transform: scale(1.05);
}

/* Global Share Bar */
.global-share-bar {
    margin-top: 1.5rem;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 15px;
    background: rgba(0, 0, 0, 0.2);
    padding: 10px 20px;
    border-radius: 30px;
    width: fit-content;
    margin-left: auto;
    margin-right: auto;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.global-share-bar span {
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 600;
}

.social-icon {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    text-decoration: none;
    font-size: 1.1rem;
    transition: transform 0.2s;
}

.social-icon:hover {
    transform: translateY(-3px);
}

.social-icon.whatsapp {
    background: #25D366;
}

.social-icon.facebook {
    background: #1877F2;
}

.social-icon.instagram {
    background: linear-gradient(45deg, #405de6, #5851db, #833ab4, #c13584, #e1306c, #fd1d1d);
}

.social-icon.copy {
    background: #333;
}

body.light-mode .global-share-bar {
    background: rgba(255, 255, 255, 0.5);
    border: 1px solid rgba(0, 0, 0, 0.05);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.05);
}


/* Mobile Fixes for Header & Share Bar */
@media (max-width: 600px) {
    .global-share-bar {
        flex-wrap: wrap;
        width: 90%;
        gap: 10px;
    }

    /* Compact Install Button on Mobile to prevent overlap */
    .install-btn {
        padding: 8px;
        width: 40px;
        height: 40px;
        border-radius: 50%;
        justify-content: center;
        overflow: hidden;
    }

    .install-btn span,
    .install-btn i+span {
        /* If text is in span */
        display: none;
    }

    /* Since the button text is just text node, we might need to wrap it or just use css text-indent if we can't change HTML easily. 
       Actually, modern.html has <i class='fas fa-download'></i> Install App.
       We can hide the text by hacking 'font-size: 0' for the button and resetting it for 'i'.
    */
    .install-btn {
        font-size: 0;
        /* Hide text */
    }

    .install-btn i {
        font-size: 1.2rem;
        /* Restore icon size */
        margin: 0;
    }

    h1 {
        margin-top: 50px;
        /* Push title down so buttons don't overlap if they stay top */
        font-size: 1.8rem;
    }

    /* Ensure buttons stay at top */
    .install-btn,
    .theme-toggle {
        top: 15px;
    }
}


/* User Request: Hide Gauge initially */
.circular-chart {
    opacity: 0.3;
    /* Keep faint for context, or 0 if strictly requested */
    transition: opacity 0.5s;
}

/* We want it fully hidden? User said 'blue dot... jab start hoe'. */
/* Let's make it opacity 0.1 for track, but hide the blue part? */
/* Actually, simply setting opacity 0 on load and 1 on start is safest interpretation. */
.circular-chart.active {
    opacity: 1;
}


/* Indeterminate Gauge Animation for Latency/Connecting */
@keyframes spin-gauge {
    0% {
        stroke-dasharray: 10, 100;
        stroke-dashoffset: 0;
    }

    50% {
        stroke-dasharray: 50, 100;
        stroke-dashoffset: -40;
    }

    100% {
        stroke-dasharray: 10, 100;
        stroke-dashoffset: -100;
    }
}

.circle.indeterminate {
    animation: spin-gauge 1.5s infinite linear;
    stroke: var(--secondary);
}