/* --- Global Reset & Scroll Fix --- */
html {
    overflow-y: auto;
    overflow-x: hidden;
}

body {
    background: #0f172a;
    color: #f8fafc;
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    text-align: center;
    margin: 0;
    padding: 20px;
    min-height: 100vh;
    /* Allows scrolling but prevents horizontal bounce on mobile */
    overscroll-behavior-y: contain;
}

h1 {
    color: #38bdf8;
    letter-spacing: -1px;
    margin-bottom: 20px;
}

/* --- Layout Utility --- */
.hidden {
    display: none !important;
}

.visible {
    display: block !important;
    opacity: 1;
    transition: opacity 0.5s;
}

/* --- Status & Spinner --- */
#statusContainer {
    margin-bottom: 20px;
    font-weight: 600;
    color: #94a3b8;
    min-height: 24px;
}

.loadCircle {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(56, 189, 248, 0.2);
    border-radius: 50%;
    border-top-color: #38bdf8;
    animation: spin 0.8s linear infinite;
    margin-right: 8px;
    vertical-align: middle;
}

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

/* --- Main Start/Stop Button --- */
#startStopBtn {
    width: 100px;
    height: 100px;
    background: #22c55e;
    border-radius: 50%;
    margin: 0 auto 20px;
    cursor: pointer;
    position: relative;
    box-shadow: 0 0 0 rgba(34, 197, 94, 0.4);
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    display: flex;
    align-items: center;
    justify-content: center;
    border: 4px solid rgba(255, 255, 255, 0.1);
    z-index: 10;
}

#startStopBtn:after {
    content: "START";
    font-weight: 900;
    color: white;
    letter-spacing: 1px;
    transition: all 0.3s ease;
}

#startStopBtn:hover {
    transform: scale(1.08);
    background: #16a34a;
    box-shadow: 0 0 25px rgba(34, 197, 94, 0.6);
}

#startStopBtn:active {
    transform: scale(0.92);
}

#startStopBtn.running {
    background: #ef4444;
    animation: pulseRed 2s infinite;
    border-color: rgba(255, 255, 255, 0.2);
}

#startStopBtn.running:after {
    content: "STOP";
    transform: scale(1.1);
}

#startStopBtn.running:hover {
    background: #dc2626;
    box-shadow: 0 0 25px rgba(239, 68, 68, 0.6);
}

@keyframes pulseRed {
    0% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7);
    }

    70% {
        box-shadow: 0 0 0 15px rgba(239, 68, 68, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0);
    }
}

/* --- Test Area Grid --- */
.testGroup {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 20px;
    margin-top: 20px;
}

.testArea,
.testArea2 {
    background: #1e293b;
    padding: 25px;
    border-radius: 16px;
    width: 280px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

canvas {
    width: 100%;
    height: 160px;
}

.meterText {
    font-family: 'Courier New', Courier, monospace;
    font-size: 3.5em;
    font-weight: 900;
    line-height: 1;
    margin: 10px 0;
    color: #fff;
    text-shadow: 0 0 15px rgba(56, 189, 248, 0.6);
}

#dlText {
    color: #38bdf8;
}

#ulText {
    color: #818cf8;
}

.unit {
    color: #94a3b8;
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.8em;
}

.testName {
    color: #38bdf8;
    font-weight: bold;
    margin-bottom: 10px;
}

#serverArea,
#ipArea {
    margin: 20px 0;
    color: #94a3b8;
    font-size: 0.9em;
}

select {
    background: #1e293b;
    color: white;
    border: 1px solid #334155;
    padding: 5px 15px;
    border-radius: 8px;
}

/* --- Rating Result Banner --- */
#ratingArea {
    background: linear-gradient(135deg, #1e293b, #334155);
    padding: 20px;
    border-radius: 16px;
    max-width: 600px;
    margin: 20px auto;
    border: 1px solid #38bdf8;
    opacity: 0;
    transform: translateY(20px);
    transition: all 0.6s cubic-bezier(0.23, 1, 0.32, 1);
}

#ratingArea.visible {
    opacity: 1;
    transform: translateY(0);
}

#ratingScore {
    font-size: 1.5em;
    font-weight: bold;
    color: #38bdf8;
}

/* --- Privacy Modal (The Overlay) --- */
#privacyPolicy {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    background: rgba(15, 23, 42, 0.9);
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    z-index: 99999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s ease;
}

#privacyPolicy.visible {
    opacity: 1;
    pointer-events: auto;
}

/* --- Privacy Content (The Box) --- */
.privacyContent {
    background: #1e293b;
    padding: 35px;
    border-radius: 24px;
    border: 1px solid rgba(56, 189, 248, 0.3);
    max-width: 550px;
    width: 85%;
    max-height: 80vh;
    overflow-y: auto;
    text-align: left;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.8);
    position: relative;
}

.privacyContent h2,
.privacyContent h4 {
    color: #38bdf8;
    margin-top: 1.2em;
}

.privacyContent p,
.privacyContent li {
    line-height: 1.6;
    color: #cbd5e1;
}

.closeBtn {
    background: #38bdf8;
    color: #0f172a;
    border: none;
    padding: 14px 30px;
    border-radius: 12px;
    font-weight: 800;
    font-size: 1rem;
    cursor: pointer;
    width: 100%;
    margin-top: 25px;
    position: relative;
    overflow: hidden;
    /* Needed for the shimmer effect */
    transition: all 0.3s cubic-bezier(0.23, 1, 0.32, 1);
    box-shadow: 0 4px 12px rgba(56, 189, 248, 0.3);
}

/* --- Hover Effect --- */
.closeBtn:hover {
    background: #7dd3fc;
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(56, 189, 248, 0.5);
    letter-spacing: 0.5px;
}

/* --- Shimmer/Glow Sweep --- */
.closeBtn::after {
    content: '';
    position: absolute;
    top: -50%;
    left: -60%;
    width: 20%;
    height: 200%;
    background: rgba(255, 255, 255, 0.4);
    transform: rotate(30deg);
    transition: all 0.5s;
    opacity: 0;
}

.closeBtn:hover::after {
    left: 120%;
    opacity: 1;
    transition: all 0.6s;
}

/* --- Active/Click Effect --- */
.closeBtn:active {
    transform: translateY(1px) scale(0.98);
    box-shadow: 0 2px 5px rgba(56, 189, 248, 0.2);
}

/* --- Footer --- */
.footer-links {
    margin-top: 50px;
    padding-bottom: 30px;
    opacity: 0.7;
    font-size: 0.85em;
}

.footer-links a {
    color: #38bdf8;
    text-decoration: none;
    font-weight: bold;
}

/* Ensure the Privacy Link and all footer anchors show the pointer */
.privacy-link,
.footer-links a {
    cursor: pointer !important;
    text-decoration: none;
    transition: all 0.2s ease;
}

.privacy-link:hover,
.footer-links a:hover {
    color: #7dd3fc;
    /* Lighter blue on hover */
    text-shadow: 0 0 8px rgba(56, 189, 248, 0.4);
}

/* --- Mobile Fixes --- */
@media screen and (max-width: 600px) {
    .testGroup {
        flex-direction: column;
        align-items: center;
    }

    .testArea2 {
        order: -1;
        width: 90%;
    }

    .testArea {
        width: 90%;
    }

    .meterText {
        font-size: 2.8em;
    }
}