:root {
    --bg-color: #0b0d14;
    --text-color: #ffffff;
    --glass-bg: rgba(16, 20, 32, 0.70);
    --glass-border: rgba(255, 255, 255, 0.08);
    --accent: #10b981; /* Emerald green for circuits */
    --accent-glow: rgba(16, 185, 129, 0.3);
    --accent-hover: #34d399;
    --danger: #ef4444;
    --danger-hover: #f87171;
    --secondary-bg: rgba(255, 255, 255, 0.05);
    --secondary-hover: rgba(255, 255, 255, 0.1);
    
    --grid-color: rgba(255, 255, 255, 0.04);
    --grid-size: 20px;

    /* Circuit Colors */
    --wire-color: #94a3b8;
    --wire-glow: rgba(148, 163, 184, 0.2);
    --positive-color: #ef4444;
    --negative-color: #3b82f6;
    --current-color: #fbbf24;
    --component-body: #1e293b;
    --component-border: #cbd5e1;
    --select-color: #fbbf24;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Inter', sans-serif;
    background:
        radial-gradient(circle at 15% 15%, rgba(16, 185, 129, 0.15), transparent 45%),
        radial-gradient(circle at 85% 85%, rgba(59, 130, 246, 0.15), transparent 45%),
        var(--bg-color);
    background-size: 200% 200%;
    animation: backgroundShift 15s ease infinite;
    color: var(--text-color);
    overflow: hidden;
    width: 100vw;
    height: 100vh;
    height: -webkit-fill-available;
}

@keyframes backgroundShift {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

#circuitCanvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    cursor: crosshair;
    touch-action: none; /* Crucial for mobile support */
}

/* === Glassmorphism Basics === */
.glass-panel {
    background: var(--glass-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.45);
    z-index: 10;
}

.glass-panel-small {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 1rem;
    z-index: 10;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

.hidden { display: none !important; }

/* === Typography & Utilities === */
h1 { font-size: 1.2rem; font-weight: 600; letter-spacing: -0.5px; }
h3 { font-size: 0.9rem; font-weight: 600; color: #cbd5e1; margin-bottom: 0.8rem; text-transform: uppercase; letter-spacing: 0.5px; }
.w-full { width: 100%; }
.mt-2 { margin-top: 0.5rem; }

/* === Top Nav === */
.top-nav {
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 60px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 1.5rem;
    border-radius: 0 0 16px 16px;
    border-top: none;
}

.nav-left, .nav-center, .nav-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.nav-center {
    flex: 1;
    justify-content: center;
}

.title-group {
    display: flex;
    align-items: center;
    gap: 0.8rem;
}

.status-badge {
    padding: 0.2rem 0.6rem;
    border-radius: 100px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.status-badge.red { background: rgba(239, 68, 68, 0.15); color: #fca5a5; border: 1px solid rgba(239, 68, 68, 0.3); }
.status-badge.green { background: rgba(16, 185, 129, 0.15); color: #6ee7b7; border: 1px solid rgba(16, 185, 129, 0.3); }

/* Buttons */
button {
    font-family: 'Inter', sans-serif;
    cursor: pointer;
    border: none;
    outline: none;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.btn-primary {
    background: linear-gradient(135deg, #10b981, #34d399);
    color: #000;
    border: none;
    padding: 0.5rem 1.4rem;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-shadow: 0 4px 15px var(--accent-glow);
}
.btn-primary:hover { 
    background: linear-gradient(135deg, #34d399, #6ee7b7); 
    transform: translateY(-2px) scale(1.02); 
    box-shadow: 0 8px 25px rgba(16, 185, 129, 0.4); 
}
.btn-primary:active { transform: translateY(1px) scale(0.98); }

.btn-secondary {
    background: var(--secondary-bg);
    color: white;
    border: 1px solid var(--glass-border);
    padding: 0.5rem 1rem;
    border-radius: 8px;
    font-weight: 500;
    font-size: 0.9rem;
}
.btn-secondary:hover { background: var(--secondary-hover); }

.btn-danger {
    background: rgba(239, 68, 68, 0.1);
    color: #fca5a5;
    border: 1px solid rgba(239, 68, 68, 0.3);
    padding: 0.5rem 1rem;
    border-radius: 8px;
    font-weight: 500;
    font-size: 0.9rem;
}
.btn-danger:hover { background: rgba(239, 68, 68, 0.2); color: white; border-color: var(--danger-hover); }

.btn-icon {
    width: 36px; height: 36px;
    border-radius: 8px;
    background: var(--secondary-bg);
    border: 1px solid var(--glass-border);
    color: white;
    font-size: 1.1rem;
    text-decoration: none;
}
.btn-icon:hover { background: var(--secondary-hover); }
.btn-icon.small { width: 28px; height: 28px; font-size: 0.9rem; }
.home-btn { font-size: 1.3rem; }

.divider { height: 24px; width: 1px; background: var(--glass-border); margin: 0 0.5rem; }
.stats { font-family: 'SF Mono', 'Cascadia Code', monospace; font-size: 0.8rem; color: #94a3b8; display: flex; align-items: center; gap: 0.5rem; }

/* === Sidebars === */
.sidebar-left, .sidebar-right {
    position: absolute;
    top: 76px; bottom: 16px;
    width: 260px;
    border-radius: 16px;
    display: flex;
    flex-direction: column;
}

.sidebar-left { left: 16px; padding: 1.2rem; }
.sidebar-right { right: 16px; }

/* Components Library */
.component-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.8rem;
    overflow-y: auto;
    padding-right: 0.5rem;
}
.component-grid::-webkit-scrollbar { width: 4px; }
.component-grid::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); border-radius: 4px; }

.component-item {
    background: rgba(0,0,0,0.2);
    border: 1px solid rgba(255,255,255,0.05);
    border-radius: 10px;
    padding: 0.8rem 0.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    cursor: grab;
    transition: all 0.2s;
}
.component-item:hover {
    background: rgba(255,255,255,0.05);
    border-color: rgba(255,255,255,0.15);
    transform: translateY(-2px);
    box-shadow: 0 8px 18px rgba(0, 0, 0, 0.35), 0 0 0 1px rgba(16, 185, 129, 0.25) inset;
}
.component-item:active { cursor: grabbing; }
.component-item[data-type="wire"] {
    border-color: rgba(52, 211, 153, 0.35);
    background: rgba(16, 185, 129, 0.08);
}

.component-item .icon { font-size: 1.8rem; filter: drop-shadow(0 2px 4px rgba(0,0,0,0.5)); }
.component-item span { font-size: 0.75rem; color: #cbd5e1; font-weight: 500; }

.sidebar-footer {
    margin-top: auto;
    padding-top: 1rem;
    border-top: 1px solid var(--glass-border);
    font-size: 0.75rem;
    color: #64748b;
    text-align: center;
}

/* Property Inspector */
.inspector-header { padding: 1.2rem 1.2rem 0.8rem; border-bottom: 1px solid var(--glass-border); display: flex; justify-content: space-between; align-items: center; }
.inspector-header h3 { margin: 0; }
.inspector-content { padding: 1.2rem; flex: 1; overflow-y: auto; }
.inspector-actions { padding: 1.2rem; border-top: 1px solid var(--glass-border); }

.prop-group { margin-bottom: 1rem; }
.prop-group label { display: block; font-size: 0.8rem; color: #cbd5e1; margin-bottom: 0.4rem; }
.prop-input-wrap { display: flex; }
.prop-input-wrap input {
    flex: 1;
    background: rgba(0,0,0,0.3);
    border: 1px solid rgba(255,255,255,0.1);
    color: white;
    padding: 0.5rem 0.8rem;
    border-radius: 6px 0 0 6px;
    font-family: inherit;
    font-size: 16px; /* Prevents iOS zoom */
    outline: none;
    width: 100%;
}
.prop-input-wrap input:focus { border-color: var(--accent); }
.prop-unit {
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.1);
    border-left: none;
    padding: 0.5rem 0.8rem;
    border-radius: 0 6px 6px 0;
    color: #cbd5e1;
    font-size: 0.9rem;
    font-weight: 500;
}

/* === Bottom Info Panels === */
.bottom-left { position: absolute; bottom: 16px; left: 292px; width: 220px; }
.bottom-right { position: absolute; bottom: 16px; right: 16px; width: 280px; }

.reading { font-size: 0.8rem; color: #cbd5e1; margin-bottom: 0.4rem; font-family: 'SF Mono', monospace; }
.reading strong { color: #f8fafc; font-family: 'Inter', sans-serif; font-weight: 500; display: inline-block; width: 90px; }
.reading span { color: var(--accent); font-weight: 600; }
.hud h3 { color: #cbd5e1; }

.toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.35rem 0;
    cursor: pointer;
    font-size: 0.82rem;
    color: #cbd5e1;
}
.toggle-row input[type="checkbox"] { display: none; }
.toggle-switch {
    position: relative; width: 32px; height: 18px;
    background: rgba(255,255,255,0.1); border-radius: 9px;
    transition: background 0.25s ease;
}
.toggle-switch::after {
    content: ''; position: absolute; top: 2px; left: 2px;
    width: 14px; height: 14px; border-radius: 50%;
    background: rgba(255,255,255,0.4); transition: all 0.25s ease;
}
input[type="checkbox"]:checked + .toggle-switch { background: var(--accent); }
input[type="checkbox"]:checked + .toggle-switch::after { left: 16px; background: white; }

.zoom-controls { display: flex; align-items: center; justify-content: space-between; margin-top: 0.8rem; padding-top: 0.8rem; border-top: 1px solid var(--glass-border); }
#zoomLabel { font-size: 0.8rem; font-family: monospace; color: #94a3b8; width: 50px; text-align: center; }

/* === Shortcuts Panel === */
.shortcuts-panel {
    position: absolute;
    top: 76px; right: 16px;
    width: 240px; padding: 1.2rem;
    border-radius: 12px;
}
.shortcut-row { display: flex; align-items: center; justify-content: space-between; font-size: 0.75rem; color: #94a3b8; margin-bottom: 0.4rem;}
kbd { background: rgba(255,255,255,0.08); border: 1px solid rgba(255,255,255,0.15); border-radius: 4px; padding: 0.15rem 0.4rem; font-family: monospace; color: white; }

button:focus-visible,
.btn-icon:focus-visible,
.component-item:focus-visible {
    outline: 2px solid rgba(52, 211, 153, 0.7);
    outline-offset: 2px;
}

/* ========== RESPONSIVE: TABLET ========== */
@media (max-width: 1024px) {
    .sidebar-left, .sidebar-right { width: 220px; }
    .bottom-left { left: 240px; }
}

/* ========== RESPONSIVE: MOBILE ========== */
@media (max-width: 768px) {
    /* Top nav: compact, single row */
    .top-nav {
        height: auto;
        padding: 0.4rem 0.5rem;
        flex-wrap: nowrap;
        gap: 0.3rem;
        border-radius: 0;
    }
    
    h1 { font-size: 0.9rem; }
    .title-group { display: none; }
    .divider { display: none; }
    .stats { display: none; }
    
    .nav-left { gap: 0.5rem; flex-shrink: 0; }
    .nav-center {
        flex: 1;
        justify-content: center;
        gap: 0.3rem;
        flex-wrap: nowrap;
    }
    .nav-right { flex-shrink: 0; gap: 0.3rem; }
    
    .btn-primary { padding: 0.4rem 0.7rem; font-size: 0.78rem; min-height: 36px; }
    .btn-secondary { padding: 0.4rem 0.6rem; font-size: 0.78rem; min-height: 36px; }
    .btn-danger { padding: 0.4rem 0.6rem; font-size: 0.78rem; min-height: 36px; }
    .btn-icon { width: 36px; height: 36px; min-width: 36px; }
    .btn-icon.small { width: 32px; height: 32px; min-width: 32px; }
    .home-btn { font-size: 1.1rem; }
    
    .status-badge { font-size: 0.6rem; padding: 0.15rem 0.4rem; }

    /* Component sidebar: bottom drawer */
    .sidebar-left {
        position: fixed;
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        height: auto;
        max-height: 130px;
        border-radius: 16px 16px 0 0;
        z-index: 20;
        padding: 0.4rem 0.5rem;
        background: rgba(16, 20, 32, 0.95);
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
        flex-direction: column;
    }

    .sidebar-left > h3 {
        display: none; /* Hide "Components" heading on mobile */
    }
    
    .sidebar-footer { display: none; }
    
    .component-grid {
        display: flex;
        flex-direction: row;
        overflow-x: auto;
        overflow-y: hidden;
        gap: 0.5rem;
        width: 100%;
        padding: 0.3rem 0;
        -webkit-overflow-scrolling: touch;
        scroll-snap-type: x proximity;
    }
    
    .component-item {
        min-width: 64px;
        max-width: 72px;
        padding: 0.4rem 0.3rem;
        gap: 0.2rem;
        border-radius: 8px;
        flex-shrink: 0;
        scroll-snap-align: start;
    }
    .component-item .icon { font-size: 1.3rem; }
    .component-item span { font-size: 0.6rem; }
    .component-item:hover { transform: none; } /* Disable hover animations on mobile */

    /* Property inspector: overlay panel */
    .sidebar-right {
        position: fixed;
        top: auto;
        bottom: 130px;
        right: 0.5rem;
        left: auto;
        width: 240px;
        max-height: 45vh;
        border-radius: 12px;
        z-index: 25;
    }
    
    /* Bottom panels */
    .bottom-left, .bottom-right { display: none; }
    
    /* Canvas area */
    #circuitCanvas {
        height: calc(100vh - 130px);
    }
    
    /* Shortcuts: hide on mobile */
    .shortcuts-panel { display: none; }
}

@media (max-width: 380px) {
    .top-nav { padding: 0.3rem; }
    .btn-primary { font-size: 0.72rem; padding: 0.35rem 0.5rem; }
    .btn-secondary { font-size: 0.72rem; padding: 0.35rem 0.4rem; }
    .btn-danger { font-size: 0.72rem; padding: 0.35rem 0.4rem; }
    .component-item { min-width: 56px; }
    .component-item .icon { font-size: 1.1rem; }
    .component-item span { font-size: 0.55rem; }
}
