: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;
}

/* Quick Search (tool pages) */
.quick-search {
    position: relative;
    max-width: 560px;
    margin: 3rem auto 1.5rem auto;
    padding: 0 1rem;
    z-index: 10;
}

.quick-search-label {
    color: rgba(255, 255, 255, 0.78);
    font-size: 0.95rem;
    font-weight: 600;
    margin: 0 0 0.35rem 0.15rem;
    text-align: center;
}

.quick-shell {
    position: relative;
    display: flex;
    align-items: center;
    gap: 0.65rem;
    min-height: 44px;
    padding: 0 0.85rem;
    background: rgba(15, 18, 26, 0.72);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.32);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.quick-shell:focus-within {
    border-color: rgba(99, 179, 237, 0.6);
    box-shadow: 0 0 0 1px rgba(99, 179, 237, 0.4), 0 18px 55px rgba(20, 100, 180, 0.26);
}

.quick-icon {
    width: 18px;
    height: 18px;
    color: rgba(255, 255, 255, 0.7);
    flex-shrink: 0;
}

#quick-input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: #fff;
    font-size: 0.95rem;
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
}

#quick-input::placeholder {
    color: rgba(255, 255, 255, 0.55);
}

.quick-hint {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.22rem 0.5rem;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: rgba(255, 255, 255, 0.75);
    font-size: 0.75rem;
    line-height: 1;
    flex-shrink: 0;
}

.quick-results {
    position: absolute;
    left: 0;
    right: 0;
    top: calc(100% + 0.5rem);
    margin: 0;
    padding: 0.35rem;
    list-style: none;
    background: rgba(11, 13, 20, 0.96);
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: 0 18px 55px rgba(0, 0, 0, 0.48);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    overflow: hidden;
    z-index: 30;
}

.quick-results.drop-up {
    top: auto;
    bottom: calc(100% + 0.5rem);
}

.quick-results.hidden {
    display: none;
}

.quick-item {
    display: flex;
    flex-direction: column;
    padding: 0.5rem 0.65rem;
    border-radius: 10px;
    color: #e6e7ec;
    cursor: pointer;
    gap: 0.08rem;
}

.quick-item:hover,
.quick-item.active {
    background: linear-gradient(90deg, rgba(99, 179, 237, 0.16), rgba(99, 179, 237, 0.07));
}

.quick-item-title {
    font-weight: 600;
}

.quick-item-desc {
    font-size: 0.9rem;
    color: rgba(230, 231, 236, 0.7);
}

.quick-highlight {
    font-weight: 700;
    color: #fff;
}

/* 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);
}

/* --- Search Bar / Command Palette (shared) --- */
.command-palette {
    max-width: 820px;
    margin: 1.5rem auto 2rem auto;
    padding: 0 1rem;
    position: relative;
    z-index: 50;
}

.command-shell {
    position: relative;
    display: flex;
    align-items: center;
    background: rgba(23, 25, 32, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.08);
    /* Fixed light border */
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-radius: 14px;
    padding: 0.75rem 1rem;
    gap: 0.75rem;
}

.command-shell:focus-within {
    border-color: rgba(99, 179, 237, 0.45);
    box-shadow: 0 20px 70px rgba(99, 179, 237, 0.15);
}

.command-icon {
    width: 20px;
    height: 20px;
    color: rgba(255, 255, 255, 0.7);
    flex-shrink: 0;
}

#command-input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: #fff;
    /* Always white text in search */
    font-size: 1rem;
    font-family: 'Inter', 'Outfit', system-ui, -apple-system, sans-serif;
}

#command-input::placeholder {
    color: rgba(255, 255, 255, 0.5);
}

.shortcut-hint {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.25rem 0.5rem;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    color: rgba(255, 255, 255, 0.75);
    font-size: 0.8rem;
    line-height: 1;
    gap: 0.25rem;
    flex-shrink: 0;
}

.command-results {
    position: absolute;
    left: 1rem;
    right: 1rem;
    top: calc(100% + 0.6rem);
    background: rgba(17, 19, 26, 0.9);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    box-shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
    list-style: none;
    margin: 0;
    padding: 0.4rem;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    overflow: hidden;
    z-index: 1000;
}

.command-results.hidden {
    display: none;
}

.command-label {
    color: rgba(255, 255, 255, 0.75);
    /* Always light text for label on dark/glass header */
    font-size: 0.9rem;
    font-weight: 600;
    margin: 0 0 0.45rem 0.15rem;
}

.command-item {
    display: flex;
    flex-direction: column;
    padding: 0.65rem 0.75rem;
    border-radius: 10px;
    color: #e6e7ec;
    cursor: pointer;
    gap: 0.1rem;
}

.command-item:hover,
.command-item.active {
    background: linear-gradient(90deg, rgba(99, 179, 237, 0.16), rgba(99, 179, 237, 0.07));
}

.command-item-title {
    font-weight: 600;
    display: inline-block;
}

.command-item-desc {
    font-size: 0.9rem;
    color: rgba(230, 231, 236, 0.7);
}

.command-highlight {
    font-weight: 700;
    color: #fff;
}

.command-palette.sticky-on-mobile {
    position: sticky;
    top: 0;
    padding-top: 0.75rem;
    padding-bottom: 0.5rem;
    background: linear-gradient(180deg, rgba(10, 12, 18, 0.94), rgba(10, 12, 18, 0.6));
}

@media (max-width: 768px) {
    .command-shell {
        padding: 0.7rem 0.85rem;
    }

    .shortcut-hint {
        font-size: 0.75rem;
        padding: 0.2rem 0.45rem;
    }
}