:root {
    --bg: #080b12;
    --bg2: #0d111a;
    --card: rgba(18, 23, 34, .86);
    --card2: #111722;
    --border: rgba(255,255,255,.08);
    --border2: rgba(255,255,255,.12);
    --text: #f5f7fb;
    --muted: #8993a6;
    --green: #45e6a0;
    --green2: #25c985;
    --blue: #55a8ff;
    --purple: #9b7cff;
    --danger: #ff6b7a;
    --radius: 22px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
    margin: 0;
    min-height: 100vh;
    color: var(--text);
    font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background:
        radial-gradient(circle at 50% -10%, rgba(69,230,160,.12), transparent 35%),
        radial-gradient(circle at 100% 40%, rgba(85,168,255,.07), transparent 30%),
        var(--bg);
    -webkit-font-smoothing: antialiased;
}

button { font: inherit; }

.container { width: min(760px, calc(100% - 30px)); margin: auto; }

/* HEADER */
.header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 10px 16px;
    padding: 24px 0;
}

.logo { display: flex; align-items: center; gap: 9px; font-size: 18px; font-weight: 800; letter-spacing: -.04em; }
.logo-mark { width: 30px; height: 30px; display: grid; place-items: center; border-radius: 9px; color: #06110b; background: linear-gradient(135deg, var(--green), #7bf5c1); box-shadow: 0 0 25px rgba(69,230,160,.2); }
.logo-name span { color: var(--green); }

.nav { display: flex; flex-wrap: wrap; gap: 6px 14px; }
.nav a { color: var(--muted); text-decoration: none; font-size: 12px; }
.nav a:hover { color: var(--text); }

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

.icon-toggle { padding: 6px 10px; border: 1px solid var(--border2); border-radius: 999px; background: transparent; color: #b9c2d2; font-size: 11px; cursor: pointer; }
.icon-toggle:hover { color: var(--text); border-color: #3c4658; }

.streak { display: none; padding: 7px 11px; border: 1px solid var(--border2); border-radius: 999px; color: var(--muted); font-size: 11px; }

/* ADS */
.ad { margin: 4px 0 18px; min-height: 0; text-align: center; }
.ad-label { margin-bottom: 7px; color: #5d6676; font-size: 9px; text-transform: uppercase; letter-spacing: .12em; }

/* MAIN CARD */
.speed-card {
    position: relative;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: linear-gradient(180deg, rgba(22,28,41,.95), rgba(13,17,26,.96));
    box-shadow: 0 25px 80px rgba(0,0,0,.35);
}

.speed-card::before {
    content: "";
    position: absolute;
    top: -180px; left: 50%;
    width: 420px; height: 300px;
    transform: translateX(-50%);
    background: radial-gradient(circle, rgba(69,230,160,.10), transparent 70%);
    pointer-events: none;
}

@keyframes doneFlash {
    0% { box-shadow: 0 25px 80px rgba(0,0,0,.35); }
    30% { box-shadow: 0 25px 80px rgba(0,0,0,.35), 0 0 60px rgba(69,230,160,.45); }
    100% { box-shadow: 0 25px 80px rgba(0,0,0,.35); }
}
.speed-card.done-flash { animation: doneFlash 900ms ease; }

.test-info { position: relative; z-index: 1; padding: 24px 24px 0; text-align: center; }
.test-title { margin: 0; font-size: 14px; font-weight: 500; color: var(--muted); }

.ip-info { min-height: 20px; margin-top: 10px; display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 7px; color: #aeb7c7; font-size: 11px; }
.ip-info strong { color: var(--text); }
.ip-separator { color: #394252; }
.ip-flag { width: 18px; height: 13px; border-radius: 2px; object-fit: cover; }

/* GAUGE */
.gauge-area { position: relative; width: min(470px, 100%); margin: 4px auto 0; }
.gauge { display: block; width: 100%; }
.gauge-track { fill: none; stroke: #252c39; stroke-width: 13; stroke-linecap: round; }
.gauge-progress { fill: none; stroke: var(--green); stroke-width: 13; stroke-linecap: round; stroke-dasharray: 565; stroke-dashoffset: 565; filter: drop-shadow(0 0 8px rgba(69,230,160,.28)); transition: stroke-dashoffset .16s linear, stroke .25s ease; }
.gauge-progress.upload { stroke: var(--blue); filter: drop-shadow(0 0 8px rgba(85,168,255,.28)); }

.gauge-value { position: absolute; left: 0; right: 0; bottom: 22px; text-align: center; }
.speed-number { font-family: "JetBrains Mono", monospace; font-size: clamp(42px, 9vw, 66px); line-height: 1; font-weight: 700; letter-spacing: -.06em; }
.speed-unit { margin-top: 7px; color: var(--muted); font-size: 12px; font-weight: 500; }
.speed-scale { margin-top: 5px; color: #596477; font-size: 10px; }

.gauge-ad { display: none; position: absolute; left: 0; right: 0; bottom: 14px; text-align: center; }
.gauge-ad-download { margin-bottom: 10px; color: var(--green); font-family: "JetBrains Mono", monospace; font-size: 15px; font-weight: 700; letter-spacing: -.02em; }
.gauge-ad-box { display: inline-flex; align-items: center; justify-content: center; min-width: 240px; min-height: 90px; padding: 14px; border: 1px dashed var(--border2); border-radius: 12px; background: rgba(255,255,255,.02); color: #5d6676; font-size: 11px; text-align: center; }

/* BUTTON */
.controls { position: relative; z-index: 2; padding: 0 24px 25px; text-align: center; }
.start-button { min-width: 190px; padding: 14px 24px; border: 0; border-radius: 12px; color: #06110b; background: linear-gradient(135deg, var(--green), #70f1b9); box-shadow: 0 10px 30px rgba(69,230,160,.16); font-size: 14px; font-weight: 700; cursor: pointer; transition: transform .15s ease, filter .15s ease, opacity .15s ease; }
.start-button:hover { transform: translateY(-1px); filter: brightness(1.05); }
.start-button:active { transform: translateY(0); }
.start-button:disabled { opacity: .45; cursor: not-allowed; transform: none; }

.status { min-height: 18px; margin-top: 11px; color: var(--muted); font-size: 11px; }

/* RESULTS */
.results { display: grid; grid-template-columns: repeat(4, 1fr); border-top: 1px solid var(--border); }
.result { padding: 19px 10px; text-align: center; border-left: 1px solid var(--border); }
.result:first-child { border-left: 0; }
.result-label { display: flex; align-items: center; justify-content: center; gap: 5px; margin-bottom: 7px; color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .05em; }
.result-dot { width: 5px; height: 5px; border-radius: 50%; background: var(--green); }
.result:nth-child(2) .result-dot { background: var(--blue); }
.result:nth-child(3) .result-dot, .result:nth-child(4) .result-dot { background: var(--purple); }
.result-value { font-family: "JetBrains Mono", monospace; font-size: 18px; font-weight: 600; }
.result-unit { margin-left: 3px; color: #687387; font-size: 9px; }

/* HISTORY */
.history { margin-top: 22px; padding: 24px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--card); }
.history-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 17px; }
.history-title { margin: 0; font-size: 14px; font-weight: 700; }
.share-button { padding: 8px 12px; border: 1px solid var(--border2); border-radius: 9px; color: #b9c2d2; background: transparent; font-size: 11px; cursor: pointer; }
.share-button:hover { color: var(--text); border-color: #3c4658; }

.chart-wrap { width: 100%; height: 150px; padding: 5px; border: 1px solid var(--border); border-radius: 13px; background: linear-gradient(180deg, rgba(255,255,255,.015), transparent); }
#historyChart { width: 100%; height: 100%; display: block; }

.legend { display: flex; gap: 18px; margin-top: 10px; color: var(--muted); font-size: 10px; }
.legend span { display: flex; align-items: center; gap: 6px; }
.legend i { width: 16px; height: 2px; display: inline-block; border-radius: 2px; }
.legend .download { background: var(--green); }
.legend .upload { background: var(--blue); }

.history-empty { padding: 25px 0 8px; color: var(--muted); text-align: center; font-size: 11px; }

.history-table { width: 100%; margin-top: 17px; border-collapse: collapse; font-size: 10px; }
.history-table th { color: #657084; font-weight: 500; text-align: left; padding: 7px 5px; border-bottom: 1px solid var(--border); }
.history-table td { padding: 9px 5px; color: #aeb7c7; border-bottom: 1px solid var(--border); }
.history-table td:not(:first-child) { font-family: "JetBrains Mono", monospace; color: var(--text); }

/* CONTENT PAGES (about / faq / how-it-works / widget) */
.content-page { padding: 26px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--card); }
.content-page h1 { margin-top: 0; font-size: 20px; }
.content-page h2 { font-size: 15px; color: var(--text); margin: 22px 0 8px; }
.content-page p { color: #b9c2d2; font-size: 13px; line-height: 1.7; }
.faq-item { margin-bottom: 18px; }
.faq-item h2 { margin-bottom: 6px; }

.code-block { padding: 14px; border: 1px solid var(--border2); border-radius: 10px; background: #0b0f18; color: #9ad9ff; font-family: "JetBrains Mono", monospace; font-size: 12px; overflow-x: auto; white-space: pre; }

.copy-button { margin-top: 10px; padding: 8px 12px; border: 1px solid var(--border2); border-radius: 9px; color: #b9c2d2; background: transparent; font-size: 11px; cursor: pointer; }
.copy-button:hover { color: var(--text); border-color: #3c4658; }

/* EMBED WIDGET PAGE */
body.embed-body { margin: 0; background: transparent; }
.embed-widget { width: 260px; padding: 14px; border: 1px solid var(--border); border-radius: 14px; background: var(--card2); text-align: center; font-family: Inter, sans-serif; }
.embed-widget a { display: inline-block; margin-top: 8px; padding: 8px 14px; border-radius: 9px; background: linear-gradient(135deg, var(--green), #70f1b9); color: #06110b; font-weight: 700; font-size: 12px; text-decoration: none; }

/* FOOTER */
footer { padding: 30px 0 50px; color: #4f596b; text-align: center; font-size: 10px; line-height: 1.7; }
.footer-brand { color: #697487; }
footer .nav { justify-content: center; margin-top: 8px; }

/* MOBILE */
@media (max-width: 600px) {
    .container { width: min(100% - 18px, 760px); }
    .header { padding: 17px 3px; }
    .speed-card { border-radius: 18px; }
    .test-info { padding-left: 15px; padding-right: 15px; }
    .controls { padding-left: 15px; padding-right: 15px; }
    .results { grid-template-columns: repeat(2, 1fr); }
    .result:nth-child(3) { border-left: 0; border-top: 1px solid var(--border); }
    .result:nth-child(4) { border-top: 1px solid var(--border); }
    .history, .content-page { padding: 17px; border-radius: 18px; }
    .history-head { align-items: flex-start; }
    .share-button { white-space: nowrap; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
