:root{
    --bg-1:#07111f;
    --bg-2:#0b172a;
    --surface:rgba(255,255,255,.08);
    --surface-2:rgba(255,255,255,.05);
    --border:rgba(255,255,255,.12);
    --text:#ecf3ff;
    --muted:#9bb0d1;
    --primary:#38bdf8;
    --success:#22c55e;
    --violet:#a78bfa;
    --danger:#ef4444;
    --warning:#f59e0b;
    --shadow:0 20px 50px rgba(0,0,0,.35);
    --radius:24px;
    --radius-sm:18px;
    --card-blur:16px;
}

body.light{
    --bg-1:#eaf4ff;
    --bg-2:#dfeeff;
    --surface:rgba(255,255,255,.72);
    --surface-2:rgba(255,255,255,.6);
    --border:rgba(15,23,42,.08);
    --text:#0f172a;
    --muted:#475569;
    --primary:#0ea5e9;
    --success:#16a34a;
    --violet:#8b5cf6;
    --danger:#dc2626;
    --warning:#d97706;
    --shadow:0 20px 50px rgba(15,23,42,.10);
}

*{box-sizing:border-box}
html,body{margin:0;padding:0}
body{
    min-height:100vh;
    color:var(--text);
    background:
        radial-gradient(circle at top right, rgba(56,189,248,.18), transparent 28%),
        radial-gradient(circle at left bottom, rgba(167,139,250,.16), transparent 30%),
        linear-gradient(135deg, var(--bg-1), var(--bg-2));
    font-family:Tahoma, Arial, sans-serif;
    overflow-x:hidden;
}

.app-bg{
    position:fixed;
    inset:0;
    pointer-events:none;
    background:
        radial-gradient(circle at 20% 20%, rgba(34,197,94,.08), transparent 20%),
        radial-gradient(circle at 80% 25%, rgba(56,189,248,.12), transparent 24%),
        radial-gradient(circle at 50% 80%, rgba(167,139,250,.10), transparent 22%);
    filter:blur(8px);
}

.app-shell{
    position:relative;
    z-index:1;
    width:min(1200px, calc(100% - 32px));
    margin:24px auto 40px;
}

.topbar{
    display:flex;
    align-items:center;
    justify-content:space-between;
    gap:20px;
    margin-bottom:20px;
}

.brand{
    display:flex;
    align-items:center;
    gap:14px;
}

.brand__logo{
    width:52px;
    height:52px;
    border-radius:16px;
    display:grid;
    place-items:center;
    font-size:22px;
    font-weight:700;
    color:#fff;
    background:linear-gradient(135deg,var(--primary),var(--violet));
    box-shadow:var(--shadow);
}

.brand h1{
    margin:0 0 4px;
    font-size:24px;
}

.brand p{
    margin:0;
    color:var(--muted);
    font-size:14px;
}

.topbar__actions{
    display:flex;
    align-items:center;
    gap:10px;
}

.icon-btn, .btn{
    border:none;
    cursor:pointer;
    transition:.2s ease;
}

.icon-btn{
    width:44px;
    height:44px;
    border-radius:14px;
    background:var(--surface);
    color:var(--text);
    border:1px solid var(--border);
    backdrop-filter:blur(var(--card-blur));
}

.icon-btn:hover{transform:translateY(-1px)}

.hero-card, .panel{
    background:var(--surface);
    border:1px solid var(--border);
    backdrop-filter:blur(var(--card-blur));
    box-shadow:var(--shadow);
    border-radius:var(--radius);
}

.hero-card{
    padding:24px;
    margin-bottom:20px;
}

.hero-grid{
    display:grid;
    grid-template-columns: 1.2fr 1fr;
    gap:22px;
}

.gauge-panel, .metrics-panel{
    background:var(--surface-2);
    border:1px solid var(--border);
    border-radius:22px;
    padding:20px;
}

.status-chip{
    display:inline-flex;
    align-items:center;
    gap:8px;
    font-size:13px;
    color:var(--text);
    background:rgba(255,255,255,.08);
    border:1px solid var(--border);
    border-radius:999px;
    padding:8px 12px;
}

.gauge-wrap{
    position:relative;
    width:320px;
    max-width:100%;
    margin:18px auto 12px;
    aspect-ratio:1/1;
}

.gauge{
    width:100%;
    height:100%;
    transform:rotate(-90deg);
}

.gauge__track{
    fill:none;
    stroke:rgba(255,255,255,.08);
    stroke-width:16;
}

.gauge__progress{
    fill:none;
    stroke:url(#gaugeGrad);
    stroke-width:16;
    stroke-linecap:round;
    stroke-dasharray:578;
    stroke-dashoffset:578;
    transition:stroke-dashoffset .12s linear;
    filter:drop-shadow(0 0 12px rgba(56,189,248,.35));
}

.gauge-center{
    position:absolute;
    inset:0;
    display:flex;
    flex-direction:column;
    align-items:center;
    justify-content:center;
    text-align:center;
}

.gauge-label{
    color:var(--muted);
    font-size:14px;
    margin-bottom:6px;
}

.gauge-value{
    font-size:54px;
    line-height:1;
    font-weight:700;
    letter-spacing:-1px;
}

.gauge-phase{
    margin-top:10px;
    color:var(--muted);
    font-size:14px;
}

.action-row{
    display:flex;
    justify-content:center;
    gap:12px;
    margin-top:18px;
    flex-wrap:wrap;
}

.btn{
    border-radius:999px;
    padding:14px 22px;
    font-size:15px;
    font-weight:700;
}

.btn--primary{
    background:linear-gradient(135deg,var(--primary),var(--violet));
    color:#fff;
    min-width:150px;
}

.btn--primary:hover{
    transform:translateY(-1px) scale(1.01);
}

.btn--ghost{
    background:transparent;
    color:var(--text);
    border:1px solid var(--border);
}

.btn--small{
    padding:10px 14px;
    border-radius:14px;
    background:var(--surface-2);
    color:var(--text);
    border:1px solid var(--border);
}

.btn:disabled{
    opacity:.5;
    cursor:not-allowed;
    transform:none !important;
}

.metrics-panel{
    display:grid;
    grid-template-columns:1fr 1fr;
    gap:14px;
    align-content:start;
}

.metric-card{
    min-height:120px;
    border-radius:20px;
    padding:18px;
    border:1px solid var(--border);
    background:rgba(255,255,255,.04);
    display:flex;
    flex-direction:column;
    justify-content:center;
}

.metric-card__label{
    color:var(--muted);
    font-size:14px;
    margin-bottom:8px;
}

.metric-card__value{
    font-size:34px;
    line-height:1;
    margin-bottom:6px;
}

.metric-card__unit{
    color:var(--muted);
    font-size:13px;
}

.metric-card--download .metric-card__value{color:var(--primary)}
.metric-card--upload .metric-card__value{color:var(--success)}

.meta-grid{
    grid-column:1 / -1;
    display:grid;
    grid-template-columns:1fr 1fr;
    gap:12px;
    margin-top:4px;
}

.meta-item{
    border-radius:18px;
    border:1px solid var(--border);
    background:rgba(255,255,255,.04);
    padding:14px;
    display:flex;
    align-items:center;
    justify-content:space-between;
    gap:12px;
    color:var(--muted);
}

.meta-item strong{
    color:var(--text);
    font-size:14px;
}

.panel-grid{
    display:grid;
    grid-template-columns: 1.3fr .7fr;
    gap:20px;
    margin-bottom:20px;
}

.panel{
    padding:20px;
}

.panel__head{
    display:flex;
    align-items:center;
    justify-content:space-between;
    gap:16px;
    margin-bottom:16px;
}

.panel__head h2{
    margin:0;
    font-size:18px;
}

.legend{
    display:flex;
    gap:14px;
    flex-wrap:wrap;
    color:var(--muted);
    font-size:13px;
}

.legend__item{
    position:relative;
    padding-right:16px;
}

.legend__item::before{
    content:"";
    position:absolute;
    right:0;
    top:50%;
    transform:translateY(-50%);
    width:10px;
    height:10px;
    border-radius:50%;
}

.legend__item--download::before{background:var(--primary)}
.legend__item--upload::before{background:var(--success)}

.chart-wrap{
    position:relative;
    height:320px;
    border-radius:20px;
    overflow:hidden;
    background:linear-gradient(180deg, rgba(255,255,255,.03), rgba(255,255,255,.01));
    border:1px solid var(--border);
}

#speedChart{
    width:100%;
    height:100%;
    display:block;
}

.details-list{
    display:flex;
    flex-direction:column;
    gap:12px;
}

.details-row{
    display:flex;
    justify-content:space-between;
    gap:12px;
    padding:14px 16px;
    border-radius:16px;
    background:rgba(255,255,255,.04);
    border:1px solid var(--border);
    color:var(--muted);
}

.details-row strong{color:var(--text)}

.history-list{
    display:flex;
    flex-direction:column;
    gap:12px;
}

.history-item{
    display:grid;
    grid-template-columns:1.4fr 1fr 1fr 1fr 1fr;
    gap:12px;
    padding:14px 16px;
    border-radius:18px;
    background:rgba(255,255,255,.04);
    border:1px solid var(--border);
    align-items:center;
}

.history-item__cell{
    display:flex;
    flex-direction:column;
    gap:4px;
}

.history-item__cell span{
    color:var(--muted);
    font-size:12px;
}

.history-item__cell strong{
    color:var(--text);
    font-size:14px;
}

.history-empty{
    padding:20px;
    text-align:center;
    color:var(--muted);
    border:1px dashed var(--border);
    border-radius:18px;
}

@media (max-width: 980px){
    .hero-grid,
    .panel-grid{
        grid-template-columns:1fr;
    }

    .gauge-wrap{
        width:280px;
    }
}

@media (max-width: 640px){
    .app-shell{
        width:min(100% - 18px, 100%);
        margin:12px auto 24px;
    }

    .hero-card,.panel{
        padding:14px;
        border-radius:20px;
    }

    .gauge-value{
        font-size:42px;
    }

    .metrics-panel{
        grid-template-columns:1fr 1fr;
    }

    .history-item{
        grid-template-columns:1fr 1fr;
    }

    .topbar{
        align-items:flex-start;
        flex-direction:column;
    }
}
