:root {
    --bg-color: #0f1115;
    --sidebar-bg: #161b22;
    --card-bg: #1c2128;
    --text-primary: #ffffff;
    --text-secondary: #8b949e;
    --accent: #58a6ff;
    --accent-hover: #79c0ff;
    --border: #30363d;
    --success: #2ea043;
    --danger: #da3633;

    --font-main: 'Inter', sans-serif;
    --sidebar-width: 250px;
    --header-height: 60px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-main);
    background-color: var(--bg-color);
    color: var(--text-primary);
    overflow: hidden;
}

.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    position: relative;
}

/* Main Header (Top) */
.main-header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    background-color: var(--sidebar-bg);
    border-bottom: 1px solid var(--border);
    z-index: 60;
    flex-shrink: 0;
}

.main-header .logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-weight: 700;
    font-size: 1.25rem;
    color: var(--text-primary);
    margin-bottom: 0;
}

.mobile-menu-btn {
    display: none;
    /* Hidden on desktop */
    background: transparent;
    border: none;
    color: var(--text-primary);
    padding: 0.5rem;
    border-radius: 6px;
    cursor: pointer;
}

/* Content Wrapper (Main + Right Sidebar) */
.content-wrapper {
    display: flex;
    flex: 1;
    overflow: hidden;
    position: relative;
}

/* Main Content */
.main-content {
    flex: 1;
    overflow-y: auto;
    padding: 0;
    background-color: var(--bg-color);
    position: relative;
}

.page {
    display: none;
    padding: 2rem 3rem;
    animation: fadeIn 0.3s ease;
    max-width: 1200px;
    margin: 0 auto;
}

.page.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.page-header {
    margin-bottom: 2rem;
    border-bottom: 1px solid var(--border);
    padding-bottom: 1rem;
}

.page-header h1 {
    font-size: 2rem;
    margin-bottom: 0.5rem;
}

.page-header p {
    color: var(--text-secondary);
}

/* Right Sidebar (Navigation) */
.right-sidebar {
    width: var(--sidebar-width);
    background-color: var(--sidebar-bg);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
    overflow-y: auto;
    z-index: 50;
    flex-shrink: 0;
}

.right-sidebar h3 {
    font-size: 0.9rem;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin-bottom: 1rem;
    letter-spacing: 0.05em;
}

.icon-box {
    color: var(--accent);
}

.nav-links {
    list-style: none;
    flex: 1;
}

.nav-links li {
    margin-bottom: 0.5rem;
}

.nav-links a {
    display: block;
    padding: 0.75rem 1rem;
    border-radius: 6px;
    text-decoration: none;
    color: var(--text-secondary);
    transition: all 0.2s ease;
    font-weight: 500;
}

.nav-links a:hover,
.nav-links li.active a {
    background-color: rgba(88, 166, 255, 0.1);
    color: var(--text-primary);
}

.nav-links li.active a {
    color: var(--accent);
}

.footer-info {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-align: center;
    margin-top: 2rem;
    border-top: 1px solid var(--border);
    padding-top: 1rem;
}

.footer-links {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
}

.footer-links a {
    color: var(--text-secondary);
    text-decoration: none;
    transition: color 0.2s;
}

.footer-links a:hover {
    color: var(--accent);
    text-decoration: underline;
}

/* Dashboard Cards (Kept for reference if reused, though cleaned from Home) */
.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 1.5rem;
}

.card {
    background-color: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.5rem;
    cursor: pointer;
    transition: transform 0.2s, border-color 0.2s;
    text-align: center;
}

.card:hover {
    transform: translateY(-4px);
    border-color: var(--accent);
}

.card-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
    display: inline-block;
}

.card h3 {
    margin-bottom: 0.5rem;
    font-weight: 600;
}

.card p {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

/* Components Common */
.btn-primary {
    background-color: var(--accent);
    color: #fff;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s;
}

.btn-primary:hover {
    background-color: var(--accent-hover);
}

.btn-secondary {
    background-color: var(--card-bg);
    color: var(--text-primary);
    border: 1px solid var(--border);
    padding: 0.75rem 1.5rem;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    transition: border-color 0.2s;
}

.btn-secondary:hover {
    border-color: var(--text-secondary);
}

.test-container {
    background-color: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 2rem;
    min-height: 400px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.hidden {
    display: none !important;
}

/* Microphone Visualizer */
.visualizer-wrapper {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

canvas#mic-visualizer {
    width: 100%;
    height: 200px;
    background-color: #000;
    border-radius: 8px;
}

.mic-stats {
    color: var(--accent);
    font-weight: 500;
}

/* Webcam */
.video-wrapper {
    width: 100%;
    max-width: 640px;
    background: #000;
    border-radius: 8px;
    overflow: hidden;
    position: relative;
    aspect-ratio: 16/9;
}

video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.cam-info {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0, 0, 0, 0.7);
    padding: 0.5rem;
    text-align: center;
    font-size: 0.9rem;
}

/* Sound */
.sound-controls {
    flex-direction: row;
    gap: 2rem;
    flex-wrap: wrap;
}

/* Keyboard */
.keyboard-wrapper {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding: 1rem;
    background: #000;
    border-radius: 12px;
    margin-bottom: 1rem;
    overflow-x: auto;
    max-width: 100%;
}

.key-row {
    display: flex;
    justify-content: center;
    gap: 0.4rem;
    min-width: 800px;
}

.key {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    color: var(--text-secondary);
    transition: all 0.1s;
}

.key.wide {
    width: 70px;
}

.key.space {
    width: 250px;
}

.key.pressed {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
    box-shadow: 0 0 10px var(--accent);
    transform: scale(0.95);
}

.last-key-info {
    margin-top: 1rem;
    font-family: monospace;
    font-size: 1.1rem;
    text-align: center;
}

/* Mouse */
.mouse-test-area {
    width: 100%;
    height: 400px;
    background: #111;
    border: 2px dashed var(--border);
    border-radius: 12px;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    user-select: none;
    touch-action: none;
}

.mouse-visual {
    width: 120px;
    height: 180px;
    position: relative;
    border-radius: 60px 60px 40px 40px;
    border: 2px solid var(--text-secondary);
    margin-bottom: 1rem;
}

.mouse-btn {
    position: absolute;
    top: 0;
    width: 50%;
    height: 40%;
    border-bottom: 1px solid var(--text-secondary);
}

.mouse-btn.left {
    left: 0;
    border-right: 1px solid var(--text-secondary);
    border-radius: 60px 0 0 0;
}

.mouse-btn.right {
    right: 0;
    border-radius: 0 60px 0 0;
}

.mouse-wheel {
    position: absolute;
    top: 15%;
    left: 50%;
    transform: translateX(-50%);
    width: 14px;
    height: 30px;
    border: 1px solid var(--text-secondary);
    border-radius: 10px;
}

.mouse-visual .active {
    background-color: var(--accent);
}

/* Gamepad */
.controller-body {
    width: 300px;
    height: 180px;
    background: var(--card-bg);
    border: 2px solid var(--text-secondary);
    border-radius: 40px;
    position: relative;
    margin-top: 2rem;
    transform-origin: center;
}

.d-pad,
.face-btns {
    position: absolute;
    top: 40px;
    width: 80px;
    height: 80px;
}

.d-pad {
    left: 20px;
}

.face-btns {
    right: 20px;
}

.pad-btn.active {
    background-color: var(--accent);
}

.status-msg {
    font-size: 1.2rem;
    margin-bottom: 2rem;
    text-align: center;
}

/* =========================================
   MEDIA QUERIES FOR RESPONSIVENESS
   ========================================= */

@media (max-width: 768px) {
    .mobile-menu-btn {
        display: block;
    }

    .main-header {
        padding: 0 1rem;
    }

    /* Stack content and sidebar */
    .content-wrapper {
        flex-direction: column;
        overflow-y: auto;
        /* Allow scrolling wrapper */
    }

    .main-content {
        overflow: visible;
        /* Let it flow in the wrapper */
        height: auto;
        padding: 1rem;
        order: 1;
        /* Content first */
    }

    .right-sidebar {
        /* Drawer style or just stacked? Stick to drawer for better UX or stacked for simplicity */
        position: fixed;
        top: var(--header-height);
        right: 0;
        height: calc(100vh - var(--header-height));
        width: 80%;
        max-width: 300px;
        transform: translateX(100%);
        transition: transform 0.3s ease;
        border-left: 1px solid var(--border);
        box-shadow: -2px 0 10px rgba(0, 0, 0, 0.5);
    }

    .right-sidebar.open {
        transform: translateX(0);
    }

    .page {
        padding: 1.5rem 1rem;
    }

    .page-header h1 {
        font-size: 1.5rem;
    }

    .keyboard-wrapper {
        padding: 0.5rem;
    }

    .key {
        width: 30px;
        height: 30px;
        font-size: 0.6rem;
    }

    .key-row {
        min-width: 600px;
    }

    .sound-controls {
        gap: 1rem;
        flex-direction: column;
        width: 100%;
    }

    .sound-card button {
        width: 100%;
    }
}

/* =========================================
   NEW TOOLS STYLES
   ========================================= */

/* Screen Test */
#screen-test-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: #000;
    z-index: 9999;
    cursor: none;
}

/* CPS Tester */
.cps-stats {
    display: flex;
    gap: 2rem;
    margin-bottom: 2rem;
}

.stat-box {
    text-align: center;
}

.stat-label {
    display: block;
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 0.2rem;
}

.stat-val {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-primary);
}

.click-pad {
    width: 100%;
    max-width: 400px;
    height: 200px;
    background-color: var(--sidebar-bg);
    border: 2px solid var(--border);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    font-weight: 700;
    cursor: pointer;
    user-select: none;
    transition: all 0.1s;
    margin-bottom: 1.5rem;
}

.click-pad:hover {
    border-color: var(--text-secondary);
}

.click-pad:active,
.click-pad.active-test:active {
    transform: scale(0.98);
    background-color: #21262d;
}

.click-pad.active-test {
    border-color: var(--accent);
    color: var(--accent);
    background-color: rgba(88, 166, 255, 0.05);
}

.cps-result-msg {
    margin-bottom: 1.5rem;
    font-size: 1.1rem;
    text-align: center;
    min-height: 3rem;
}

/* Device Info */
.info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.5rem;
    width: 100%;
}

.info-card {
    background-color: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1.5rem;
}

.info-label {
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.info-value {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
    word-break: break-all;
}

/* Polling Rate */
.polling-stats {
    text-align: center;
    margin-bottom: 2rem;
}

.hz-big {
    font-size: 3rem;
    font-weight: 700;
    color: var(--accent);
    display: block;
}

.graph-area {
    width: 100%;
    height: 200px;
    background: #0f1115;
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 1.5rem;
    overflow: hidden;
}

canvas#polling-graph {
    width: 100%;
    height: 100%;
}

/* Double Click */
.stats-row {
    display: flex;
    gap: 2rem;
    margin-bottom: 1rem;
    font-size: 1.1rem;
}

.stats-row .stat-item {
    font-weight: 500;
}

.log-container {
    width: 100%;
    max-width: 500px;
    margin: 1.5rem 0;
}

.log-container h3 {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
    text-transform: uppercase;
}

.dc-log {
    height: 150px;
    background: #0f1115;
    border: 1px solid var(--border);
    border-radius: 6px;
    overflow-y: auto;
    padding: 0.5rem;
    font-family: monospace;
    font-size: 0.9rem;
}

.log-entry {
    display: flex;
    justify-content: space-between;
    padding: 0.25rem 0.5rem;
    border-bottom: 1px solid #21262d;
}

.log-entry.warn {
    color: var(--danger);
    font-weight: 700;
}

/* Reaction Time */
.no-pad {
    padding: 0 !important;
    overflow: hidden;
}

.reaction-card {
    width: 100%;
    height: 400px;
    /* fills container */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    user-select: none;
    transition: background-color 0.2s;
    border-radius: 12px;
}

.reaction-content {
    text-align: center;
    pointer-events: none;
    /* Let clicks pass to card */
}

.reaction-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
    display: block;
}

.reaction-card.waiting {
    background-color: var(--card-bg);
    color: var(--text-primary);
}

.reaction-card.ready {
    background-color: #da3633;
    /* Red */
    color: white;
}

.reaction-card.now {
    background-color: #2ea043;
    /* Green */
    color: white;
}

.reaction-card.result {
    background-color: var(--accent);
    /* Blue */
    color: white;
}

/* Tone Generator */
.tone-control-panel {
    width: 100%;
    max-width: 500px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
}

.hz-mega {
    font-size: 3.5rem;
    font-weight: 700;
    color: var(--accent);
    font-variant-numeric: tabular-nums;
}

.slider-container {
    width: 100%;
    margin: 1rem 0;
}

input[type=range] {
    width: 100%;
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    outline: none;
    appearance: none;
    -webkit-appearance: none;
}

input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    background: var(--accent);
    border-radius: 50%;
    cursor: pointer;
    transition: transform 0.1s;
}

input[type=range]::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

.slider-labels {
    display: flex;
    justify-content: space-between;
    margin-top: 0.5rem;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.tone-options select {
    padding: 0.5rem;
    border-radius: 6px;
    background: var(--bg-color);
    border: 1px solid var(--border);
    color: var(--text-primary);
    font-family: inherit;
    margin-left: 0.5rem;
}

.play-controls {
    display: flex;
    gap: 1rem;
}

.btn-danger {
    background-color: var(--danger);
    color: white;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-danger:hover {
    background-color: #d02e2b;
}