:root {
    /* --- Light Mode (Default) --- */
    --bg-color: #f8fafc;        /* Light Grey Background */
    --panel-bg: #ffffff;        /* White Cards */
    --primary-color: #0f172a;   /* Dark Headings */
    --text-color: #334155;      /* Grey Body Text */
    --accent-color: #2563eb;    /* Brand Blue */
    --border-color: #e2e8f0;    /* Light Borders */
    --grid-color: #e2e8f0;      /* Grid Lines */
    --input-bg: #ffffff;        /* Input Backgrounds */
}

[data-theme="dark"] {
    /* --- Premium Dark Mode (Platinum & Slate) --- */
    --bg-color: #0f172a;        /* Midnight Slate Background */
    --panel-bg: #1e293b;        /* Lighter Slate Cards */
    --primary-color: #f1f5f9;   /* Off-white Headings */
    --text-color: #94a3b8;      /* Muted Grey Body Text */
    --accent-color: #38bdf8;    /* Bright Cyan-Blue */
    --border-color: #334155;    /* Dark Borders */
    --grid-color: #1e293b;      /* Subtle Grid Lines */
    --input-bg: #0f172a;        /* Dark Input Backgrounds */
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    /* Grid Pattern */
    background-image:
        linear-gradient(var(--grid-color) 1px, transparent 1px),
        linear-gradient(90deg, var(--grid-color) 1px, transparent 1px);
    background-size: 40px 40px;
    color: var(--text-color);
    min-height: 100vh;
    line-height: 1.6;
    display: flex;
    flex-direction: column;
    /* Smooth transition for theme toggle */
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* Header */
.main-header {
    background: var(--panel-bg);
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 0;
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

nav {
    max-width: 1000px;
    margin: 0 auto;
    padding: 0 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    font-family: 'Outfit', sans-serif;
    font-weight: 700;
    font-size: 1.25rem;
    color: var(--primary-color);
    letter-spacing: -0.02em;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.nav-links {
    list-style: none;
    display: flex;
    gap: 2rem;
}

.nav-links a {
    color: var(--text-color); /* Changed from fixed grey to variable */
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    transition: color 0.2s;
}

.nav-links a:hover,
.nav-links a.active {
    color: var(--accent-color);
}

/* Main Container */
.container {
    max-width: 800px;
    margin: 3rem auto;
    padding: 0 1.5rem;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

/* Panels */
.panel {
    background: var(--panel-bg);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 2rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

/* Calculator Section */
.calculator-section {
    text-align: center;
}

h1 {
    font-family: 'Outfit', sans-serif;
    font-size: 2rem;
    color: var(--primary-color);
    margin-bottom: 0.5rem;
    letter-spacing: -0.03em;
}

.subtitle {
    color: var(--text-color);
    font-size: 0.95rem;
    margin-bottom: 2rem;
    opacity: 0.8;
}

/* Band Selector */
.band-selector {
    display: inline-flex;
    background: var(--bg-color); /* Changed from fixed #f1f5f9 */
    padding: 0.25rem;
    border-radius: 6px;
    margin-bottom: 2.5rem;
    border: 1px solid var(--border-color);
}

.band-btn {
    background: transparent;
    border: none;
    color: var(--text-color);
    padding: 0.5rem 1.5rem;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 500;
    font-size: 0.9rem;
    transition: all 0.2s;
}

.band-btn.active {
    background: var(--panel-bg); /* Changed from white to variable */
    color: var(--primary-color);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    font-weight: 600;
}

/* Resistor Visual */
.resistor-visual {
    height: 120px;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 2.5rem;
    position: relative;
    /* Updated radial gradient to use variable so dots change color */
    background-image: radial-gradient(var(--border-color) 1px, transparent 1px);
    background-size: 10px 10px;
    border: 1px dashed var(--border-color);
    border-radius: 4px;
}

.resistor-body {
    width: 300px;
    height: 70px;
    background: #f1f5f9; /* Keep resistor body light even in dark mode for realism */
    border: 2px solid #94a3b8;
    border-radius: 35px;
    position: relative;
    display: flex;
    justify-content: space-evenly;
    align-items: center;
    z-index: 2;
}

.wire {
    position: absolute;
    height: 4px;
    width: 60px;
    background: #94a3b8;
    z-index: 1;
}

.left-wire { right: 100%; }
.right-wire { left: 100%; }

.stripe {
    width: 12px;
    height: 100%;
    background-color: transparent;
    transition: background-color 0.2s;
}

.stripe.hidden { display: none; }

/* Controls Grid */
.controls-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2.5rem;
    text-align: left;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.control-group label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-color);
    font-weight: 600;
    opacity: 0.7;
}

select {
    appearance: none;
    background-color: var(--input-bg); /* Changed from white */
    border: 1px solid var(--border-color);
    color: var(--primary-color);
    padding: 0.6rem;
    border-radius: 4px;
    cursor: pointer;
    font-family: 'Inter', sans-serif;
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.2s;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2364748b'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.5rem center;
    background-size: 1rem;
    padding-right: 2rem;
}

select:focus {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.1);
}

/* Result Display */
.result-display {
    display: flex;
    justify-content: center;
    gap: 3rem;
    flex-wrap: wrap;
    background: var(--bg-color); /* Changed from #f8fafc */
    padding: 2rem;
    border-radius: 4px;
    border: 1px solid var(--border-color);
    transition: background-color 0.3s ease;
}

.result-item {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.result-item.hidden { display: none; }

.result-item .label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-color);
    margin-bottom: 0.5rem;
    font-weight: 600;
    opacity: 0.7;
}

.result-item .value {
    font-family: 'Courier New', Courier, monospace;
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--primary-color);
}

/* Info Section */
.info-section h2 {
    font-family: 'Outfit', sans-serif;
    font-size: 1.5rem;
    margin-bottom: 1.5rem;
    color: var(--primary-color);
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.5rem;
}

.info-section h3 {
    font-size: 1.1rem;
    margin-top: 2rem;
    margin-bottom: 0.75rem;
    color: var(--primary-color);
}

.info-section p {
    color: var(--text-color);
    margin-bottom: 1rem;
}

/* Footer */
.main-footer {
    border-top: 1px solid var(--border-color);
    padding: 2rem;
    text-align: center;
    color: var(--text-color); /* Changed from fixed Black */
    font-size: 0.85rem;
    background: var(--panel-bg);
    margin-top: auto;
}

/* Tools Grid */
.tools-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 1.5rem;
    margin-top: 2rem;
}

.tool-card {
    background: var(--panel-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1.5rem;
    text-decoration: none;
    color: var(--text-color);
    transition: all 0.2s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

.tool-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    border-color: var(--accent-color);
}

.tool-icon {
    margin-bottom: 1rem;
    display: flex;
    justify-content: center;
    align-items: center;
}
.tool-icon svg {
    width: 40px;
    height: 40px;
    stroke: var(--accent-color);
    stroke-width: 1.5px;
    fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
    transition: all 0.3s ease;
}
.tool-card:hover .tool-icon svg {
    transform: translateY(-5px);
    stroke: var(--primary-color);
}

.tool-title {
    font-family: 'Outfit', sans-serif;
    font-weight: 600;
    font-size: 1.1rem;
    color: var(--primary-color);
    margin-bottom: 0.5rem;
}

.tool-desc {
    font-size: 0.9rem;
    color: var(--text-color);
    line-height: 1.5;
    opacity: 0.8;
}

/* Responsive */
@media (max-width: 768px) {
    body { display: block; }
    .container {
        display: flex;
        flex-direction: column;
        width: 100%;
        padding: 10px;
    }
    .main-content, .sidebar {
        width: 100%;
        max-width: 100%;
        margin: 0;
    }
    input, select, button {
        min-height: 48px;
        font-size: 16px;
    }
}

/* Force the sidebar to obey Dark Mode */
.sidebar, aside {
    background-color: var(--panel-bg) !important;
    color: var(--text-color) !important;
    border-color: var(--border-color) !important;
    transition: background-color 0.3s ease;
}

/* Premium Theme Toggle Button */
#theme-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 50%; /* Make it a perfect circle */
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-color);
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1); /* Smooth animation */
}

/* Hover Effect */
/* Premium Theme Toggle Button (Larger Size) */
#theme-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    
    /* Increased from 40px to 50px */
    width: 50px;
    height: 50px;
    
    border-radius: 50%;
    background: transparent;
    border: 2px solid var(--border-color); /* Thicker border for visibility */
    color: var(--text-color);
    cursor: pointer;
    transition: all 0.2s ease;
    
    /* Ensure it doesn't shrink on mobile */
    flex-shrink: 0; 
}

/* Force the Icon (SVG) to be larger */
/* Premium Theme Toggle Button (High Visibility) */
#theme-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    
    /* Good touch target size */
    width: 45px;
    height: 45px;
    
    border-radius: 50%;
    background: transparent;
    
    /* THE FIX: Use Muted Text color (Grey) so it is clearly visible */
    border: 2px solid var(--text-muted);
    
    color: var(--text-color);
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

/* Premium Theme Toggle Button (High Visibility) */
#theme-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    
    /* Good touch target size */
    width: 45px;
    height: 45px;
    
    border-radius: 50%;
    background: transparent;
    
    /* THE FIX: Use Muted Text color (Grey) so it is clearly visible */
    border: 2px solid var(--text-muted);
    
    color: var(--text-color);
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

/* Premium Theme Toggle Button (High Visibility) */
#theme-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    
    /* Good touch target size */
    width: 45px;
    height: 45px;
    
    border-radius: 50%;
    background: transparent;
    
    /* THE FIX: Use Muted Text color (Grey) so it is clearly visible */
    border: 2px solid var(--text-muted);
    
    color: var(--text-color);
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

/* Force Icon Size */
/* Premium Theme Toggle Button (High Visibility) */
#theme-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    
    /* Good touch target size */
    width: 45px;
    height: 45px;
    
    border-radius: 50%;
    background: transparent;
    
    /* THE FIX: Use Muted Text color (Grey) so it is clearly visible */
    border: 2px solid var(--text-muted);
    
    color: var(--text-color);
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

/* FORCE the button to be visible */
#theme-toggle {
    /* 1. Force Size (prevent shrinking) */
    width: 48px !important;
    height: 48px !important;
    min-width: 48px !important; 
    
    /* 2. Force Border (Use text color so it is always visible) */
    border: 2px solid var(--text-color) !important;
    border-radius: 50%;
    
    /* 3. Layout & Spacing */
    display: flex !important;
    align-items: center;
    justify-content: center;
    background: transparent;
    cursor: pointer;
    margin-left: 15px; /* Add space from the nav links */
    padding: 0;
}

/* FORCE the Icon Size */
#theme-toggle svg {
    width: 24px !important;
    height: 24px !important;
    stroke: var(--text-color); /* Ensure icon matches border */
    display: block;
}

/* Hover Effect */
#theme-toggle:hover {
    border-color: var(--accent-color) !important;
    transform: scale(1.1);
}

#theme-toggle:hover svg {
    stroke: var(--accent-color);
}