:root {
    /* 
       ENGINEERING INSTRUMENT THEME 
       "Gold Standard" Design Tokens + General Utilities
    */

    /* Palette - Deep Matte Dark Mode */
    --color-bg-app: #090a0c;
    --color-bg-panel: #121418;
    /* Surface cards */
    --color-bg-input: #050505;
    /* Input fields (recessed) */
    --color-bg-viz: #000000;
    /* Visualization background (scope) */

    /* Borders & Separators */
    --color-border-subtle: #1e2329;
    --color-border-hover: #3b424b;
    --color-border-active: #58a6ff;

    /* Text */
    --color-text-primary: #e6edf3;
    --color-text-secondary: #8b949e;
    --color-text-tertiary: #6e7681;
    --color-text-muted: #484f58;

    /* Semantic Accents */
    --color-accent-primary: #33b3ae;
    /* Cyan/Teal - Calculations */
    --color-signal-high: #58a6ff;
    /* Blue - Logic High */
    --color-signal-low: #30363d;
    /* Muted Blue - Logic Low */
    --color-warning: #d29922;
    --color-error: #f85149;
    --color-success: #3fb950;

    /* Elevations / Depth */
    --shadow-card: 0 4px 12px rgba(0, 0, 0, 0.3);
    --shadow-input: inset 0 1px 2px rgba(0, 0, 0, 0.5);
    --shadow-viz: inset 0 0 20px rgba(0, 0, 0, 0.5);

    /* Typography */
    --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --font-mono: "JetBrains Mono", "SF Mono", Consolas, "Courier New", monospace;

    /* Spacing System (8px Grid) */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;
    --space-xxl: 48px;

    /* Radius */
    --radius-sm: 4px;
    --radius-md: 6px;
    --radius-lg: 8px;

    /* Animation */
    --ease-out: cubic-bezier(0.2, 0.8, 0.2, 1);
    --duration-fast: 150ms;
}

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

body {
    background-color: var(--color-bg-app);
    color: var(--color-text-primary);
    font-family: var(--font-ui);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* --- Layout --- */

header {
    background-color: var(--color-bg-panel);
    border-bottom: 1px solid var(--color-border-subtle);
    padding: var(--space-md) var(--space-xl);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
}

header h1 {
    font-size: 1.1rem;
    font-weight: 600;
    letter-spacing: -0.02em;
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    color: var(--color-text-primary);
}

.brand-glitch {
    font-family: 'Oxanium', sans-serif;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    position: relative;
    color: #fff;
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-logo {
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.5), 0 2px 4px -1px rgba(0, 0, 0, 0.3);
    border-radius: 4px;
}

header a.back-link {
    font-size: 0.85rem;
    color: var(--color-text-secondary);
    text-decoration: none;
    font-family: var(--font-ui);
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    transition: all var(--duration-fast);
}

header a.back-link:hover {
    color: var(--color-text-primary);
}

/* Search Bar */
.search-container {
    position: relative;
    width: 220px;
}

#toolSearch {
    background-color: var(--color-bg-input);
    border: 1px solid var(--color-border-subtle);
    color: var(--color-text-primary);
    padding: 6px 12px;
    padding-left: 32px;
    /* For icon */
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    width: 100%;
    transition: all var(--duration-fast);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238b949e' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'%3E%3C/circle%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'%3E%3C/line%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: 8px center;
}

#toolSearch:focus {
    border-color: var(--color-signal-high);
    background-color: var(--color-bg-app);
    box-shadow: 0 0 0 3px rgba(88, 166, 255, 0.1);
    width: 260px;
    /* Subtle expand */
}

@media (max-width: 600px) {
    .search-container {
        display: none;
        /* Hide on small mobile? Or make icon? */
        /* For now let's just make it full width below header */
    }

    header {
        flex-direction: column;
        gap: 12px;
        align-items: stretch;
    }

    .search-container {
        display: block;
        width: 100%;
        order: 2;
    }

    #toolSearch:focus {
        width: 100%;
    }
}

main {
    flex: 1;
    padding: var(--space-xl);
    max-width: 1000px;
    margin: 0 auto;
    width: 100%;
}

footer {
    padding: var(--space-lg) var(--space-xl);
    color: var(--color-text-tertiary);
    /* Muted blue-grey */
    font-size: 0.75rem;
    border-top: 1px solid var(--color-border-subtle);
    background-color: var(--color-bg-app);
}

.footer-content {
    max-width: 1000px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: var(--space-md);
}

.footer-left {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

.footer-row {
    display: flex;
    align-items: center;
    gap: var(--space-lg);
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.footer-item {
    display: flex;
    align-items: center;
    gap: 6px;
    color: #7d8590;
    /* Specific muted tone */
}

.footer-item svg {
    opacity: 0.8;
}

.footer-link {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--color-text-secondary);
    text-decoration: none;
    font-size: 0.85rem;
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    transition: all var(--duration-fast);
    background-color: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--color-border-subtle);
}

.footer-link:hover {
    background-color: var(--color-border-subtle);
    color: var(--color-text-primary);
    border-color: var(--color-border-hover);
}

@media (max-width: 700px) {
    .footer-content {
        flex-direction: column;
        align-items: center;
        text-align: center;
        gap: var(--space-lg);
    }

    .footer-row {
        justify-content: center;
        flex-wrap: wrap;
        gap: var(--space-md);
    }
}

/* --- 1. Homepage & Tool Grid --- */

.tool-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: var(--space-lg);
    margin-bottom: var(--space-xxl);
}

.tool-card {
    background-color: var(--color-bg-panel);
    border: 1px solid var(--color-border-subtle);
    border-radius: var(--radius-md);
    padding: var(--space-lg);
    transition: all var(--duration-fast);
    text-decoration: none;
    color: inherit;
    display: flex;
    flex-direction: column;
    height: 100%;
    position: relative;
    box-shadow: var(--shadow-card);
}

.tool-card:hover {
    transform: translateY(-2px);
    border-color: var(--color-border-active);
    background-color: rgba(255, 255, 255, 0.03);
}

.tool-card h3 {
    color: var(--color-signal-high);
    margin-bottom: var(--space-xs);
    font-size: 1rem;
    font-weight: 600;
}

.tool-card p {
    color: var(--color-text-secondary);
    font-size: 0.875rem;
    line-height: 1.5;
}

.tool-card.featured {
    border-color: var(--color-signal-high);
    background: linear-gradient(to bottom right, var(--color-bg-panel), rgba(88, 166, 255, 0.05));
}

/* --- 2. Standard Tool Layout (Legacy & Simple Tools) --- */

.tool-container {
    background-color: var(--color-bg-panel);
    border: 1px solid var(--color-border-subtle);
    border-radius: var(--radius-lg);
    padding: var(--space-xl);
    max-width: 900px;
    margin: 0 auto;
    box-shadow: var(--shadow-card);
}

h2 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: var(--space-lg);
    padding-bottom: var(--space-sm);
    border-bottom: 1px solid var(--color-border-subtle);
    color: var(--color-text-primary);
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.section-icon {
    width: 20px;
    height: 20px;
    stroke: var(--color-signal-high);
    stroke-width: 2;
    fill: none;
    display: inline-block;
    vertical-align: middle;
}

.tool-desc {
    color: var(--color-text-secondary);
    margin-bottom: var(--space-xl);
    font-size: 0.95rem;
    border-left: 3px solid var(--color-signal-high);
    padding-left: var(--space-md);
}

/* --- 3. Instrument Panel Components (New / Advanced Tools) --- */

.tool-header {
    margin-bottom: var(--space-xl);
    border-bottom: 1px solid var(--color-border-subtle);
    padding-bottom: var(--space-md);
}

.tool-header h2 {
    border-bottom: none;
    /* Override universal h2 */
    margin-bottom: var(--space-xs);
}

.instrument-grid {
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: var(--space-lg);
    align-items: start;
}

@media (max-width: 850px) {
    .instrument-grid {
        grid-template-columns: 1fr;
    }
}

.panel {
    background-color: var(--color-bg-panel);
    border: 1px solid var(--color-border-subtle);
    border-radius: var(--radius-md);
    padding: var(--space-lg);
    box-shadow: var(--shadow-card);
}

.panel-title {
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-tertiary);
    font-weight: 700;
    margin-bottom: var(--space-md);
    display: block;
}

/* --- 4. Inputs (Shared) --- */

.input-group {
    margin-bottom: var(--space-md);
}

label {
    display: block;
    margin-bottom: var(--space-xs);
    color: var(--color-text-secondary);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}

.input-row {
    display: flex;
    gap: var(--space-xs);
}

input[type="number"],
input[type="text"],
select,
textarea {
    background-color: var(--color-bg-input);
    border: 1px solid var(--color-border-subtle);
    color: var(--color-text-primary);
    border-radius: var(--radius-sm);
    padding: 8px 10px;
    font-family: var(--font-mono);
    font-size: 0.9rem;
    width: 100%;
    transition: border-color var(--duration-fast);
    box-shadow: var(--shadow-input);
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--color-border-active);
}

select {
    width: auto;
    min-width: 70px;
    cursor: pointer;
}

input[type="range"] {
    display: block;
    width: 100%;
    margin-top: 8px;
    -webkit-appearance: none;
    appearance: none;
    background: transparent;
}

input[type="range"]::-webkit-slider-track {
    width: 100%;
    height: 4px;
    background: var(--color-border-subtle);
    border-radius: 2px;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    height: 16px;
    width: 16px;
    border-radius: 50%;
    background: var(--color-signal-high);
    cursor: pointer;
    margin-top: -6px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

/* --- 5. Results (Legacy & Shared) --- */

.result-box {
    margin-top: var(--space-xl);
    padding: var(--space-lg);
    background-color: var(--color-bg-input);
    border: 1px solid var(--color-border-subtle);
    border-radius: var(--radius-md);
    position: relative;
    border-left: 4px solid var(--color-accent-primary);
}

.result-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-sm);
    padding-bottom: var(--space-sm);
    border-bottom: 1px solid var(--color-border-subtle);
}

.result-item:last-child {
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: none;
}

.result-label {
    color: var(--color-text-secondary);
    font-size: 0.9rem;
}

.result-value {
    color: var(--color-text-primary);
    font-family: var(--font-mono);
    font-weight: 600;
    font-size: 1.1rem;
}

/* --- 6. Stats Grid (Instrument) --- */

.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-md);
}

@media (max-width: 600px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }
}

.stat-card {
    background-color: var(--color-bg-input);
    border: 1px solid var(--color-border-subtle);
    border-left: 3px solid var(--color-accent-primary);
    border-radius: var(--radius-sm);
    padding: var(--space-md);
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.stat-label {
    font-size: 0.75rem;
    color: var(--color-text-tertiary);
    text-transform: uppercase;
    margin-bottom: 4px;
}

.stat-value {
    font-family: var(--font-mono);
    font-size: 1.1rem;
    color: var(--color-text-primary);
    font-weight: 600;
}

/* --- 7. Visualization Containers --- */

.viz-panel {
    grid-column: 2;
    display: flex;
    flex-direction: column;
    gap: var(--space-lg);
}

@media (max-width: 850px) {
    .viz-panel {
        grid-column: 1;
    }
}

.scope-container {
    background-color: var(--color-bg-viz);
    border: 1px solid var(--color-border-subtle);
    border-radius: var(--radius-md);
    height: 240px;
    position: relative;
    overflow: hidden;
    box-shadow: var(--shadow-viz);
}

.canvas-container {
    width: 100%;
    height: 150px;
    background-color: var(--color-bg-viz);
    border: 1px solid var(--color-border-subtle);
    border-radius: var(--radius-sm);
    margin: var(--space-md) 0;
    position: relative;
}

canvas {
    display: block;
    width: 100%;
    height: 100%;
}

/* --- 8. Notes & Utilities --- */

.notes-section {
    margin-top: var(--space-lg);
    border-top: 1px solid var(--color-border-subtle);
    padding-top: var(--space-md);
    font-size: 0.8rem;
    color: var(--color-text-muted);
}

.notes-section strong {
    color: var(--color-text-tertiary);
    font-weight: 600;
}

.text-mono {
    font-family: var(--font-mono);
}

.text-small {
    font-size: 0.8rem;
}

.text-error {
    color: var(--color-error);
}

.text-warning {
    color: var(--color-warning);
}

.text-success {
    color: var(--color-success);
}

.text-muted {
    color: var(--color-text-tertiary);
}