:root {
    --primary: #4361ee;
    --primary-light: rgba(67, 97, 238, 0.1);
    --secondary: #3f37c9;
    --accent: #4cc9f0;
    --accent-light: rgba(76, 201, 240, 0.1);
    --pink: #f72585;
    --green: #4ade80;
    --red: #f87171;
    --text: #1a1a2e;
    --text-secondary: #6b7280;
    --bg: #f0f2f5;
    --card: #ffffff;
    --card-border: rgba(0, 0, 0, 0.06);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.12);
    --radius: 16px;
    --radius-sm: 10px;
}

[data-theme="dark"] {
    --primary: #6c8cff;
    --primary-light: rgba(108, 140, 255, 0.12);
    --secondary: #4361ee;
    --accent: #4cc9f0;
    --accent-light: rgba(76, 201, 240, 0.1);
    --text: #e8eaed;
    --text-secondary: #9ca3af;
    --bg: #0f1117;
    --card: #1a1d28;
    --card-border: rgba(255, 255, 255, 0.06);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.2);
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.4);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    transition: background-color 0.4s, color 0.4s;
}

.container {
    max-width: 900px;
    margin: 0 auto;
    padding: 24px 20px;
}

/* Header */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 32px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--card-border);
}

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

.logo i {
    font-size: 1.6rem;
    color: var(--primary);
}

.logo-img {
    height: 36px;
    width: auto;
    border-radius: 6px;
    transition: background-color 0.4s, padding 0.4s;
}

[data-theme="dark"] .logo-img {
    background: #ffffff;
    padding: 4px;
    border-radius: 8px;
}

.logo h1 {
    font-size: 1.5rem;
    font-weight: 800;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    letter-spacing: -0.02em;
}

.theme-toggle {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--card);
    border: 1px solid var(--card-border);
    border-radius: 12px;
    color: var(--text);
    font-size: 1.1rem;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: var(--shadow-sm);
}

.theme-toggle:hover {
    transform: scale(1.05);
    box-shadow: var(--shadow);
}

/* Main Content */
.main-content {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

/* Cards */
.card {
    background: var(--card);
    border: 1px solid var(--card-border);
    border-radius: var(--radius);
    padding: 28px;
    box-shadow: var(--shadow);
    transition: background-color 0.4s, border-color 0.4s;
}

.card h2 {
    font-size: 1.15rem;
    font-weight: 700;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text);
}

.card h2 i {
    color: var(--primary);
    font-size: 1rem;
}

/* Speedometer */
.speedometer-section {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.gauge-wrapper {
    position: relative;
    width: 280px;
    margin-bottom: 8px;
}

/* Glow ring behind gauge during testing */
.gauge-wrapper::before {
    content: '';
    position: absolute;
    top: -10px;
    left: -10px;
    right: -10px;
    bottom: -10px;
    border-radius: 50%;
    opacity: 0;
    transition: opacity 0.6s;
    pointer-events: none;
    background: radial-gradient(circle, var(--primary-light) 0%, transparent 70%);
}

.gauge-wrapper.testing::before {
    opacity: 1;
    animation: glow-pulse 2s ease-in-out infinite;
}

@keyframes glow-pulse {
    0%, 100% { opacity: 0.3; transform: scale(0.95); }
    50% { opacity: 0.7; transform: scale(1.05); }
}

/* Orbiting particles */
.gauge-wrapper .orbit-particle {
    position: absolute;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--primary);
    box-shadow: 0 0 8px var(--primary), 0 0 16px var(--primary);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}

.gauge-wrapper.testing .orbit-particle {
    opacity: 1;
}

.gauge-wrapper .orbit-particle:nth-child(1) {
    animation: orbit1 2.5s linear infinite;
}
.gauge-wrapper .orbit-particle:nth-child(2) {
    animation: orbit2 3s linear infinite;
}
.gauge-wrapper .orbit-particle:nth-child(3) {
    animation: orbit3 3.5s linear infinite;
}

@keyframes orbit1 {
    0% { top: 50%; left: 0; transform: translate(-50%, -50%); }
    25% { top: 0; left: 50%; transform: translate(-50%, -50%); }
    50% { top: 50%; left: 100%; transform: translate(-50%, -50%); }
    75% { top: 100%; left: 50%; transform: translate(-50%, -50%); }
    100% { top: 50%; left: 0; transform: translate(-50%, -50%); }
}
@keyframes orbit2 {
    0% { top: 0; left: 50%; transform: translate(-50%, -50%); }
    25% { top: 50%; left: 100%; transform: translate(-50%, -50%); }
    50% { top: 100%; left: 50%; transform: translate(-50%, -50%); }
    75% { top: 50%; left: 0; transform: translate(-50%, -50%); }
    100% { top: 0; left: 50%; transform: translate(-50%, -50%); }
}
@keyframes orbit3 {
    0% { top: 100%; left: 50%; transform: translate(-50%, -50%); }
    25% { top: 50%; left: 0; transform: translate(-50%, -50%); }
    50% { top: 0; left: 50%; transform: translate(-50%, -50%); }
    75% { top: 50%; left: 100%; transform: translate(-50%, -50%); }
    100% { top: 100%; left: 50%; transform: translate(-50%, -50%); }
}

/* Data stream particles */
.data-stream {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    overflow: hidden;
    border-radius: 50%;
    opacity: 0;
    transition: opacity 0.4s;
}

.gauge-wrapper.testing .data-stream {
    opacity: 1;
}

.data-stream .particle {
    position: absolute;
    width: 3px;
    height: 3px;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 4px var(--accent);
}

.data-stream.download .particle {
    animation: stream-down 1.2s linear infinite;
}

.data-stream.upload .particle {
    animation: stream-up 1.2s linear infinite;
}

.data-stream.ping .particle {
    background: var(--pink);
    box-shadow: 0 0 4px var(--pink);
    animation: stream-ping 0.8s ease-in-out infinite alternate;
}

@keyframes stream-down {
    0% { transform: translateY(-20px); opacity: 0; }
    20% { opacity: 1; }
    80% { opacity: 1; }
    100% { transform: translateY(140px); opacity: 0; }
}

@keyframes stream-up {
    0% { transform: translateY(140px); opacity: 0; }
    20% { opacity: 1; }
    80% { opacity: 1; }
    100% { transform: translateY(-20px); opacity: 0; }
}

@keyframes stream-ping {
    0% { transform: scale(0.5); opacity: 0.3; }
    100% { transform: scale(1.5); opacity: 1; }
}

/* Speed counter animation */
.gauge-value {
    font-size: 36px;
    font-weight: 800;
    fill: var(--text);
    font-family: inherit;
    transition: fill 0.3s;
}

.gauge-wrapper.testing .gauge-value {
    animation: value-glow 1s ease-in-out infinite alternate;
}

@keyframes value-glow {
    0% { filter: drop-shadow(0 0 0 transparent); }
    100% { filter: drop-shadow(0 0 6px var(--primary)); }
}

.gauge {
    width: 100%;
    height: auto;
}

.gauge-bg {
    stroke: var(--primary-light);
    stroke-width: 12;
}

.gauge-fill {
    transition: stroke-dashoffset 0.3s ease-out;
}

.gauge-wrapper.testing .gauge-fill {
    filter: drop-shadow(0 0 6px var(--primary));
}

.gauge-unit {
    font-size: 12px;
    font-weight: 600;
    fill: var(--text-secondary);
    font-family: inherit;
}

.gauge-label {
    font-size: 10px;
    fill: var(--text-secondary);
    font-family: inherit;
}

/* Phase indicator with animated dots */
.test-phase {
    text-align: center;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--primary);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    margin-top: -8px;
    margin-bottom: 16px;
    transition: color 0.3s;
}

.test-phase.active::after {
    content: '';
    animation: dots 1.5s steps(4, end) infinite;
}

@keyframes dots {
    0% { content: ''; }
    25% { content: '.'; }
    50% { content: '..'; }
    75% { content: '...'; }
}

/* Phase colors */
.gauge-wrapper.phase-ping .gauge-fill { stroke: var(--pink) !important; filter: drop-shadow(0 0 6px var(--pink)); }
.gauge-wrapper.phase-ping .orbit-particle { background: var(--pink); box-shadow: 0 0 8px var(--pink), 0 0 16px var(--pink); }
.gauge-wrapper.phase-ping::before { background: radial-gradient(circle, rgba(247, 37, 133, 0.12) 0%, transparent 70%); }

.gauge-wrapper.phase-download .gauge-fill { stroke: url(#gaugeGradient) !important; }
.gauge-wrapper.phase-download .orbit-particle { background: var(--primary); box-shadow: 0 0 8px var(--primary), 0 0 16px var(--primary); }

.gauge-wrapper.phase-upload .gauge-fill { stroke: var(--accent) !important; filter: drop-shadow(0 0 6px var(--accent)); }
.gauge-wrapper.phase-upload .orbit-particle { background: var(--accent); box-shadow: 0 0 8px var(--accent), 0 0 16px var(--accent); }
.gauge-wrapper.phase-upload::before { background: radial-gradient(circle, rgba(76, 201, 240, 0.12) 0%, transparent 70%); }

/* Result box active pulse */
.result-box.active {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
    animation: box-pulse 1.5s ease-in-out infinite;
}

@keyframes box-pulse {
    0%, 100% { box-shadow: 0 0 0 3px var(--primary-light); transform: scale(1); }
    50% { box-shadow: 0 0 0 6px var(--primary-light), 0 4px 20px rgba(67, 97, 238, 0.15); transform: scale(1.02); }
}

/* Done checkmark animation */
.result-box.done {
    border-color: var(--green);
    box-shadow: 0 0 0 2px rgba(74, 222, 128, 0.15);
    animation: done-pop 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes done-pop {
    0% { transform: scale(1); }
    50% { transform: scale(1.06); }
    100% { transform: scale(1); }
}

/* Completion burst */
.gauge-wrapper.complete .gauge-fill {
    animation: complete-flash 0.6s ease;
}

@keyframes complete-flash {
    0% { filter: drop-shadow(0 0 20px var(--primary)); }
    100% { filter: drop-shadow(0 0 0 transparent); }
}

/* Test Results */
.test-results {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    width: 100%;
    margin-top: 12px;
}

.result-box {
    text-align: center;
    padding: 16px 10px;
    border-radius: var(--radius-sm);
    background: var(--bg);
    border: 1px solid var(--card-border);
    transition: all 0.4s;
    position: relative;
}

.result-box.active {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.result-box.done {
    border-color: var(--green);
    box-shadow: 0 0 0 2px rgba(74, 222, 128, 0.15);
}

.result-icon {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 8px;
    font-size: 0.8rem;
    background: var(--primary-light);
    color: var(--primary);
}

.result-box h3 {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 4px;
}

.result-value {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--text);
    line-height: 1.2;
}

.result-unit {
    font-size: 0.7rem;
    color: var(--text-secondary);
    font-weight: 500;
}

/* Connection Status */
.connection-status {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 20px;
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    background: var(--bg);
    font-size: 0.9rem;
    font-weight: 500;
}

.status-indicator {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #d1d5db;
    flex-shrink: 0;
    transition: background-color 0.3s;
}

.status-indicator.online {
    background: var(--green);
    box-shadow: 0 0 8px rgba(74, 222, 128, 0.5);
    animation: pulse-green 2s infinite;
}

.status-indicator.offline {
    background: var(--red);
    box-shadow: 0 0 8px rgba(248, 113, 113, 0.5);
}

@keyframes pulse-green {
    0%, 100% { box-shadow: 0 0 4px rgba(74, 222, 128, 0.3); }
    50% { box-shadow: 0 0 12px rgba(74, 222, 128, 0.6); }
}

/* Buttons */
.action-buttons {
    display: flex;
    gap: 10px;
    margin-top: 24px;
    flex-wrap: wrap;
}

.btn {
    padding: 12px 28px;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.25s;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border: none;
    font-family: inherit;
}

.btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none !important;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: white;
    box-shadow: 0 4px 15px rgba(67, 97, 238, 0.3);
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 25px rgba(67, 97, 238, 0.4);
}

.btn-primary:active:not(:disabled) {
    transform: translateY(0);
}

.btn-primary.testing {
    background: linear-gradient(135deg, var(--pink), var(--primary));
    animation: btn-pulse 1.5s infinite;
}

@keyframes btn-pulse {
    0%, 100% { box-shadow: 0 4px 15px rgba(247, 37, 133, 0.3); }
    50% { box-shadow: 0 4px 25px rgba(247, 37, 133, 0.5); }
}

.btn-outline {
    background: transparent;
    color: var(--primary);
    border: 1.5px solid var(--primary);
}

.btn-outline:hover:not(:disabled) {
    background: var(--primary-light);
    transform: translateY(-1px);
}

/* Info Card */
.info-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.info-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px;
    border-radius: var(--radius-sm);
    background: var(--bg);
    border: 1px solid var(--card-border);
    transition: background-color 0.4s;
}

.info-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--primary-light);
    color: var(--primary);
    font-size: 0.95rem;
    flex-shrink: 0;
}

.info-content h3 {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 2px;
}

.info-content p {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text);
    word-break: break-all;
}

/* Skeleton loader */
.skeleton {
    display: inline-block;
    width: 100px;
    height: 16px;
    background: linear-gradient(90deg, var(--card-border) 25%, transparent 50%, var(--card-border) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: 4px;
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* History Card */
.chart-container {
    height: 180px;
    position: relative;
    margin-bottom: 16px;
}

.history-list {
    max-height: 260px;
    overflow-y: auto;
}

.empty-history {
    text-align: center;
    padding: 32px 20px;
    color: var(--text-secondary);
}

.empty-history i {
    font-size: 2rem;
    margin-bottom: 10px;
    opacity: 0.3;
    display: block;
}

.empty-history p {
    font-size: 0.9rem;
}

.history-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 16px;
    border-radius: var(--radius-sm);
    background: var(--bg);
    margin-bottom: 8px;
    transition: background-color 0.4s;
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}

.history-date {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.history-stats {
    display: flex;
    gap: 16px;
}

.history-stat {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.85rem;
    font-weight: 700;
}

.history-stat i {
    font-size: 0.7rem;
}

.history-stat.download { color: var(--primary); }
.history-stat.upload { color: var(--accent); }
.history-stat.ping { color: var(--pink); }

/* Footer */
.app-footer {
    text-align: center;
    margin-top: 32px;
    padding-top: 20px;
    border-top: 1px solid var(--card-border);
    font-size: 0.8rem;
    color: var(--text-secondary);
}

/* Scrollbar */
.history-list::-webkit-scrollbar { width: 6px; }
.history-list::-webkit-scrollbar-track { background: transparent; }
.history-list::-webkit-scrollbar-thumb {
    background: var(--card-border);
    border-radius: 3px;
}
.history-list::-webkit-scrollbar-thumb:hover { background: var(--text-secondary); }

/* Responsive */
@media (max-width: 640px) {
    .container { padding: 16px 12px; }

    .logo h1 { font-size: 1.2rem; }

    .gauge-wrapper { width: 220px; overflow: visible; }

    .test-results {
        grid-template-columns: repeat(2, 1fr);
    }

    .info-grid {
        grid-template-columns: 1fr;
    }

    .action-buttons {
        flex-direction: column;
    }

    .btn {
        width: 100%;
        justify-content: center;
    }

    .history-stats { gap: 10px; }
    .history-stat { font-size: 0.78rem; }
    .history-item { flex-direction: column; align-items: flex-start; gap: 6px; }
}
