:root {
    /* Dark mode (default) */
    --bg-gradient-start: #0f0f1e;
    --bg-gradient-mid: #1a1a2e;
    --bg-gradient-end: #16213e;
    --text-primary: #ffffff;
    --text-secondary: #8a8a9e;
    --card-bg: rgba(26, 26, 46, 0.8);
    --card-bg-secondary: rgba(15, 15, 30, 0.5);
    --card-bg-tertiary: rgba(15, 15, 30, 0.3);
    --border-color: rgba(255, 255, 255, 0.1);
    --border-color-light: rgba(255, 255, 255, 0.05);
    --accent-color: #00d4ff;
    --accent-color-secondary: #0099ff;
    --scale-marker: #4a4a5e;
    --scale-marker-major: #6a6a7e;
}

body.light-mode {
    /* Light mode */
    --bg-gradient-start: #f5f5f7;
    --bg-gradient-mid: #e8e8ed;
    --bg-gradient-end: #d1d1d9;
    --text-primary: #1a1a2e;
    --text-secondary: #4a4a5e;
    --card-bg: rgba(255, 255, 255, 0.9);
    --card-bg-secondary: rgba(245, 245, 247, 0.8);
    --card-bg-tertiary: rgba(232, 232, 237, 0.6);
    --border-color: rgba(0, 0, 0, 0.1);
    --border-color-light: rgba(0, 0, 0, 0.05);
    --accent-color: #0066cc;
    --accent-color-secondary: #0052a3;
    --scale-marker: #b0b0c0;
    --scale-marker-major: #9090a0;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(135deg, var(--bg-gradient-start) 0%, var(--bg-gradient-mid) 50%, var(--bg-gradient-end) 100%);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px;
    position: relative;
    overflow-x: hidden;
    transition: background 0.3s ease, color 0.3s ease;
}

/* Animated background */
#canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    pointer-events: none;
}

#bg_glow {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    pointer-events: none;
    transition: background 0.5s ease;
}

#overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    cursor: pointer;
}

/* Theme Toggle Button */
.theme-toggle {
    position: fixed;
    top: 20px;
    right: 20px;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: var(--card-bg);
    border: 2px solid var(--border-color);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.theme-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}

.theme-toggle:active {
    transform: scale(0.95);
}

.theme-icon {
    font-size: 24px;
    transition: transform 0.3s ease;
}

.theme-toggle:hover .theme-icon {
    transform: rotate(20deg);
}

.container {
    width: 100%;
    max-width: 1200px;
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    z-index: 1;
}

header {
    text-align: center;
    margin: 40px 0;
}

header h1 {
    font-size: 3rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--accent-color) 0%, var(--accent-color-secondary) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 10px;
    transition: background 0.3s ease;
}

.subtitle {
    font-size: 1.2rem;
    color: var(--text-secondary);
    transition: color 0.3s ease;
}

.main-box {
    background: var(--card-bg);
    backdrop-filter: blur(10px);
    border-radius: 30px;
    padding: 50px;
    width: 100%;
    max-width: 700px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border-color);
    margin-bottom: 30px;
    transition: background 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
    position: relative;
    z-index: 10;
}

body.light-mode .main-box {
    background: rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(16px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.1);
}

.speedometer-container {
    position: relative;
    width: 100%;
    margin-bottom: 30px;
}

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

.speedometer-outer-rim {
    stroke: #080606;
    stroke-linecap: round;
}

.speedometer-arc {
    stroke: url(#arcGradient);
    transition: stroke 0.3s ease;
    stroke-linecap: round;
}

.speedometer-arc-inner-highlight {
    stroke: rgba(211, 218, 222, 0.08);
    stroke-linecap: round;
    transition: stroke 0.3s ease;
}

.speedometer-arc-outer-highlight {
    stroke: rgba(255, 255, 255, 0.1);
    stroke-linecap: round;
    transition: stroke 0.3s ease;
}

.scale-markers line {
    stroke: #CFD8DF;
    stroke-width: 2;
    transition: stroke 0.3s ease;
    stroke-linecap: round;
    opacity: 0.7;
}

.scale-markers line.marker-major {
    stroke: #CFD8DF;
    stroke-width: 3;
    stroke-linecap: round;
    opacity: 1;
}

.scale-markers line.marker-minor {
    stroke: #CFD8DF;
    stroke-width: 1.5;
    opacity: 0.5;
    stroke-linecap: round;
}

.speed-labels {
    fill: #CFD8DF;
    font-size: 16px;
    text-anchor: middle;
    font-weight: 600;
    transition: fill 0.3s ease;
    font-family: Helvetica, Arial, sans-serif;
}

.speed-label {
    fill: #CFD8DF;
    stroke: rgba(0, 0, 0, 0.8);
    stroke-width: 2.5;
    paint-order: stroke fill;
    transition: fill 0.3s ease;
    filter: url(#textGlow);
}

#maxSpeedLabel {
    fill: #CFD8DF;
    stroke: rgba(0, 0, 0, 0.8);
    stroke-width: 2.5;
    paint-order: stroke fill;
    transition: fill 0.3s ease;
    filter: url(#textGlow);
}

.needle {
    transform-origin: 200px 200px;
    transition: transform 0.3s cubic-bezier(0.4, 0.0, 0.2, 1);
}

.needle-body {
    filter: drop-shadow(2px 2px 4px rgba(0, 0, 0, 0.4));
}

.needle-shadow {
    opacity: 0.4;
}

.needle-center-outer {
    filter: drop-shadow(1px 1px 3px rgba(0, 0, 0, 0.66));
}

.needle-center-inner {
    filter: drop-shadow(1px 1px 2px rgba(0, 0, 0, 0.5));
}

.speed-display {
    text-align: center;
    margin-top: -40px;
}

.speed-value {
    display: flex;
    align-items: baseline;
    justify-content: center;
    gap: 10px;
}

.speed-number {
    font-size: 4rem;
    font-weight: 700;
    color: var(--accent-color);
    text-shadow: 0 0 20px rgba(0, 212, 255, 0.5);
    transition: color 0.3s ease;
}

.speed-unit {
    font-size: 1.5rem;
    color: var(--text-secondary);
    font-weight: 600;
    transition: color 0.3s ease;
}

.test-type {
    font-size: 1.2rem;
    color: var(--text-secondary);
    margin-top: 10px;
    text-transform: uppercase;
    letter-spacing: 2px;
    transition: color 0.3s ease;
}

.connection-info {
    background: var(--card-bg-secondary);
    border-radius: 15px;
    padding: 20px;
    margin-bottom: 30px;
    border: 1px solid var(--border-color-light);
    transition: background 0.3s ease, border-color 0.3s ease;
}

.info-loading {
    text-align: center;
    color: var(--text-secondary);
    transition: color 0.3s ease;
}

.info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
}

.info-item {
    display: flex;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid var(--border-color-light);
    transition: border-color 0.3s ease;
}

.info-label {
    color: var(--text-secondary);
    font-size: 0.9rem;
    transition: color 0.3s ease;
}

.info-value {
    color: var(--text-primary);
    font-weight: 600;
    transition: color 0.3s ease;
}

.start-button {
    width: 100%;
    padding: 20px;
    background: linear-gradient(135deg, var(--accent-color) 0%, var(--accent-color-secondary) 100%);
    border: none;
    border-radius: 50px;
    color: #ffffff;
    font-size: 1.2rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 2px;
    box-shadow: 0 10px 30px rgba(0, 153, 255, 0.3);
}

.start-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 15px 40px rgba(0, 153, 255, 0.4);
}

.start-button:active {
    transform: translateY(0);
}

.start-button:disabled {
    background: rgba(138, 138, 158, 0.3);
    cursor: not-allowed;
    box-shadow: none;
}

.progress-container {
    display: flex;
    justify-content: space-around;
    margin-top: 30px;
    gap: 20px;
}

.progress-step {
    flex: 1;
    text-align: center;
    padding: 20px;
    background: var(--card-bg-tertiary);
    border-radius: 15px;
    border: 2px solid transparent;
    transition: all 0.3s ease;
}

.progress-step.active {
    border-color: var(--accent-color);
    background: rgba(0, 212, 255, 0.1);
}

.progress-step.completed {
    border-color: #00ff88;
    background: rgba(0, 255, 136, 0.1);
}

.step-icon {
    font-size: 2rem;
    margin-bottom: 10px;
}

.step-label {
    font-size: 0.9rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 5px;
    transition: color 0.3s ease;
}

.step-value {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--accent-color);
    transition: color 0.3s ease;
}

.results-section {
    width: 100%;
    max-width: 900px;
    background: var(--card-bg);
    backdrop-filter: blur(10px);
    border-radius: 30px;
    padding: 40px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border-color);
    transition: background 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

.results-section h2 {
    text-align: center;
    font-size: 2rem;
    margin-bottom: 30px;
    color: var(--accent-color);
    transition: color 0.3s ease;
}

.results-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 40px;
}

.result-card {
    background: var(--card-bg-secondary);
    border-radius: 15px;
    padding: 25px;
    text-align: center;
    border: 1px solid var(--border-color-light);
    transition: background 0.3s ease, border-color 0.3s ease;
}

.result-label {
    font-size: 0.9rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 10px;
    transition: color 0.3s ease;
}

.result-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--accent-color);
    transition: color 0.3s ease;
}

.connection-details {
    background: var(--card-bg-tertiary);
    border-radius: 15px;
    padding: 25px;
    margin-bottom: 30px;
    transition: background 0.3s ease;
}

.connection-details h3 {
    font-size: 1.3rem;
    margin-bottom: 20px;
    color: var(--text-primary);
    transition: color 0.3s ease;
}

.details-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 15px;
}

.detail-item {
    display: flex;
    justify-content: space-between;
    padding: 12px 0;
    border-bottom: 1px solid var(--border-color-light);
    transition: border-color 0.3s ease;
}

.detail-label {
    color: var(--text-secondary);
    font-size: 0.9rem;
    transition: color 0.3s ease;
}

.detail-value {
    color: var(--text-primary);
    font-weight: 600;
    text-align: right;
    transition: color 0.3s ease;
}

.retry-button {
    width: 100%;
    padding: 18px;
    background: linear-gradient(135deg, var(--accent-color) 0%, var(--accent-color-secondary) 100%);
    border: none;
    border-radius: 50px;
    color: #ffffff;
    font-size: 1.1rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 2px;
    box-shadow: 0 10px 30px rgba(0, 153, 255, 0.3);
}

.retry-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 15px 40px rgba(0, 153, 255, 0.4);
}

footer {
    margin-top: 40px;
    text-align: center;
    color: var(--text-secondary);
    padding: 20px;
    position: relative;
    z-index: 1;
    transition: color 0.3s ease;
}

/* Animations */
@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

.testing .speed-number {
    animation: pulse 1.5s ease-in-out infinite;
}

/* Light mode adjustments for speedometer */
body.light-mode .speed-label {
    fill: #4a4a5e;
    stroke: rgba(255, 255, 255, 0.9);
    stroke-width: 2.5;
    filter: url(#textGlow);
}

body.light-mode #maxSpeedLabel {
    fill: #4a4a5e;
    stroke: rgba(255, 255, 255, 0.9);
    stroke-width: 2.5;
    filter: url(#textGlow);
}

body.light-mode .scale-markers line {
    stroke: #4a4a5e;
}

body.light-mode .scale-markers line.marker-major {
    stroke: #4a4a5e;
}

body.light-mode .scale-markers line.marker-minor {
    stroke: #4a4a5e;
    opacity: 0.4;
}

body.light-mode .speedometer-arc-inner-highlight {
    stroke: rgba(0, 0, 0, 0.05);
}

body.light-mode .speedometer-arc-outer-highlight {
    stroke: rgba(0, 0, 0, 0.08);
}

body.light-mode .speedometer-outer-rim {
    stroke: rgba(0, 0, 0, 0.2);
}

body.light-mode .needle-body {
    filter: drop-shadow(2px 2px 6px rgba(0, 0, 0, 0.25));
}


/* Responsive design */
@media (max-width: 768px) {
    .theme-toggle {
        top: 15px;
        right: 15px;
        width: 45px;
        height: 45px;
    }

    .theme-icon {
        font-size: 20px;
    }
    header h1 {
        font-size: 2rem;
    }

    .main-box {
        padding: 30px 20px;
    }

    .speed-number {
        font-size: 3rem;
    }

    .progress-container {
        flex-direction: column;
    }

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

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

@media (max-width: 480px) {
    header h1 {
        font-size: 1.5rem;
    }

    .speed-number {
        font-size: 2.5rem;
    }

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