    /* CSS Variables for Theming */
    :root {
        --bg-page: #f0f2f5;
        --calc-bg: #ffffff;
        --text-main: #1a1a1a;
        --text-muted: #666666;
        --display-bg: #f8f9fa;
        --key-bg: #ffffff;
        --key-border: #d1d5db;
        --key-hover: #f3f4f6;
        --key-active: #e5e7eb;
        --accent: #2563eb;
        --accent-text: #ffffff;
        --clear-key: #dc2626;
        --radius: 8px;
        
        /* Graph Theme Variables */
        --graph-line: #2563eb;
        --graph-bg: #f8f9fa;
        --graph-grid: #d1d5db;

        /* Cross Decoration Colors */
        --cross-color-1: #2563eb;
        --cross-color-2: #3b82f6;
    }

    body.dark-theme {
        --bg-page: #1e1e1e;
        --calc-bg: #2d2d2d;
        --text-main: #f3f4f6;
        --text-muted: #9ca3af;
        --display-bg: #1f1f1f;
        --key-bg: #3f3f3f;
        --key-border: #525252;
        --key-hover: #4a4a4a;
        --key-active: #555555;
        --accent: #3b82f6;
        --accent-text: #ffffff;
        --clear-key: #ef4444;
        
        --graph-line: #3b82f6;
        --graph-bg: #1f1f1f;
        --graph-grid: #525252;

        --cross-color-1: #3b82f6;
        --cross-color-2: #60a5fa;
    }

    * { box-sizing: border-box; }

    /* Background Decorations Layer */
    #bg-decorations {
        position: fixed;
        top: 0;
        left: 0;
        width: 100vw;
        height: 100vh;
        z-index: -1;
        pointer-events: none;
        opacity: 0.15; /* Subtle background */
        background-size: cover;
        background-position: center;
        transition: background-image 0.3s ease;
    }

    body {
        margin: 0;
        min-height: 100vh;
        display: flex;
        flex-direction: column;
        background-color: var(--bg-page);
        font-family: Tahoma, Verdana, Segoe, sans-serif;
        color: var(--text-main);
        transition: background-color 0.3s, color 0.3s;
    }
    
    input, select, button, textarea {
        font-family: Tahoma, Verdana, Segoe, sans-serif;
    }

    /* --- Separated Language Bar --- */
    .lang-bar {
        position: fixed;
        top: 20px;
        left: 20px;
        z-index: 1000;
    }

    .lang-bar .top-select {
        background: var(--calc-bg);
        color: var(--text-main);
        border: 1px solid var(--key-border);
        padding: 8px 12px;
        border-radius: calc(var(--radius) / 2);
        cursor: pointer;
        font-size: 0.9rem;
        font-weight: bold;
        font-family: inherit;
        outline: none;
        box-shadow: 0 4px 12px rgba(0,0,0,0.08);
        transition: all 0.2s;
    }
    
    .lang-bar .top-select:hover {
        border-color: var(--accent);
    }

    .app-container {
        flex: 1 0 auto;
        display: flex;
        flex-direction: column;
        align-items: center;
        padding-top: 80px;
        padding-bottom: 30px;
        position: relative;
        z-index: 1;
    }

    .main-wrapper {
        width: 460px;
        max-width: 95vw;
        display: flex;
        flex-direction: column;
        gap: 15px;
    }

    /* Top Controls */
    .top-controls {
        display: flex;
        justify-content: space-between;
        align-items: center;
        background: var(--calc-bg);
        padding: 10px;
        border-radius: var(--radius);
        box-shadow: 0 4px 20px rgba(0,0,0,0.08);
        border: 1px solid var(--key-border);
        flex-wrap: wrap;
        gap: 10px;
        transition: all 0.3s ease;
    }

    .mode-tabs {
        display: flex;
        gap: 5px;
    }

    .tab-btn {
        background: transparent;
        border: none;
        padding: 8px 12px;
        border-radius: calc(var(--radius) / 2);
        cursor: pointer;
        color: var(--text-muted);
        font-weight: 600;
        font-size: 0.85rem;
        font-family: inherit;
        transition: all 0.2s;
    }

    .tab-btn:hover { background: var(--key-hover); }
    .tab-btn.active {
        background: var(--accent);
        color: var(--accent-text);
    }

    .top-selectors {
        display: flex;
        gap: 8px;
    }

    .top-select {
        background: var(--key-bg);
        color: var(--text-main);
        border: 1px solid var(--key-border);
        padding: 6px;
        border-radius: calc(var(--radius) / 2);
        cursor: pointer;
        font-size: 0.85rem;
        font-family: inherit;
        outline: none;
    }

    /* Main Calculator Body */
    .calculator {
        background-color: var(--calc-bg);
        border-radius: var(--radius);
        padding: 20px;
        box-shadow: 0 8px 30px rgba(0,0,0,0.12);
        border: 1px solid var(--key-border);
        display: flex;
        flex-direction: column;
        gap: 15px;
        transition: all 0.3s ease;
    }

    /* Display */
    .display-container {
        background-color: var(--display-bg);
        border: 1px solid var(--key-border);
        border-radius: var(--radius);
        padding: 15px;
        display: flex;
        flex-direction: column;
        align-items: flex-end;
        min-height: 90px;
        word-break: break-all;
    }

    .expression {
        color: var(--text-muted);
        font-size: 0.95rem;
        min-height: 20px;
        width: 100%;
        text-align: right;
        overflow-x: auto;
        white-space: pre-wrap;
        line-height: 1.4;
    }

    .result {
        font-size: 1.8rem;
        font-weight: 500;
        width: 100%;
        text-align: right;
        overflow-x: auto;
        white-space: pre-wrap;
        margin-top: 10px;
        line-height: 1.2;
        min-height: 2rem;
    }

    /* Keypad Grid */
    .keypad {
        display: grid;
        grid-template-columns: repeat(5, 1fr);
        gap: 8px;
    }

    button {
        font-family: inherit;
        font-size: 1.1rem;
        padding: 15px 0;
        border: 1px solid var(--key-border);
        border-radius: calc(var(--radius) * 0.75);
        background-color: var(--key-bg);
        color: var(--text-main);
        cursor: pointer;
        transition: all 0.1s cubic-bezier(0.4, 0, 0.2, 1);
        user-select: none;
    }

    button:hover { background-color: var(--key-hover); }
    button:active { background-color: var(--key-active); transform: scale(0.92); }

    button.op { color: var(--accent); font-weight: bold; }
    button.equals { background-color: var(--accent); color: var(--accent-text); border-color: var(--accent); }
    button.equals:hover { opacity: 0.9; }
    button.clear { color: var(--clear-key); font-weight: bold; }
    
    button.eq-btn { color: #059669; font-weight: bold; }
    button.const { color: #8b5cf6; font-weight: bold; }

    /* Graphing & Trig UI */
    .graph-controls {
        display: flex;
        gap: 10px;
        margin-bottom: 10px;
        align-items: center;
    }

    .graph-input, .trig-input {
        flex: 1;
        padding: 12px;
        border: 1px solid var(--key-border);
        border-radius: var(--radius);
        background: var(--key-bg);
        color: var(--text-main);
        font-family: monospace;
        font-size: 1rem;
        box-sizing: border-box;
    }

    .graph-select {
        padding: 10px;
        border: 1px solid var(--key-border);
        border-radius: var(--radius);
        background: var(--key-bg);
        color: var(--text-main);
        font-family: inherit;
        outline: none;
    }

    .graph-limits {
        display: flex;
        gap: 10px;
        margin-bottom: 10px;
    }
    
    .graph-limits input {
        width: 100%;
        padding: 8px;
        border: 1px solid var(--key-border);
        border-radius: 4px;
        background: var(--key-bg);
        color: var(--text-main);
        font-family: monospace;
    }

    .auto-scale-wrapper {
        display: flex;
        align-items: center;
        gap: 6px;
        font-size: 0.85rem;
        color: var(--text-muted);
        cursor: pointer;
        user-select: none;
        margin-bottom: 10px;
    }

    .auto-scale-wrapper input[type="checkbox"] {
        cursor: pointer;
        width: 16px;
        height: 16px;
        accent-color: var(--accent);
    }

    .graph-btn, .trig-btn {
        width: 100%;
        padding: 14px;
        background: var(--accent);
        color: var(--accent-text);
        border: none;
        border-radius: var(--radius);
        font-weight: bold;
        font-size: 1.05rem;
        cursor: pointer;
        transition: all 0.2s;
        box-shadow: 0 2px 5px rgba(0,0,0,0.1);
        margin-bottom: 10px;
    }

    .graph-btn:hover, .trig-btn:hover { filter: brightness(1.1); transform: translateY(-1px); box-shadow: 0 4px 8px rgba(0,0,0,0.15); }
    .graph-btn:active, .trig-btn:active { transform: translateY(1px) scale(0.98); box-shadow: none; }

    .canvas-container {
        width: 100%;
        height: 300px;
        background: var(--graph-bg);
        border: 1px solid var(--key-border);
        border-radius: var(--radius);
        position: relative;
        overflow: hidden;
    }

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

    /* Trigonometry Specifics */
    .trig-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 10px;
        margin-bottom: 10px;
    }

    .trig-grid label {
        font-size: 0.85rem;
        margin-bottom: 2px;
        display: block;
        color: var(--text-muted);
    }

    .trig-results {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 10px;
        background: var(--display-bg);
        padding: 15px;
        border-radius: var(--radius);
        border: 1px solid var(--key-border);
        font-size: 0.9rem;
        line-height: 1.6;
    }

    .trig-results span { color: var(--accent); font-weight: bold; }
    .trig-results span.error { color: #dc2626; }

    .trig-actions {
        display: flex;
        gap: 10px;
        margin-bottom: 10px;
    }

    .trig-actions button {
        flex: 1;
        padding: 8px;
        font-size: 0.9rem;
        font-weight: bold;
        border-radius: 4px;
        background: var(--key-bg);
        color: var(--text-main);
        border: 1px solid var(--key-border);
        cursor: pointer;
    }

    /* Utility Section (Now a Dropdown) */
    .util-section, .tools-panel {
        background: var(--display-bg);
        border: 1px solid var(--key-border);
        padding: 15px;
        border-radius: var(--radius);
        margin-top: 10px;
    }

    .util-section summary, .tools-panel summary {
        cursor: pointer;
        font-weight: bold;
        color: var(--accent);
        font-size: 0.9rem;
        user-select: none;
    }

    .util-grid {
        display: grid;
        grid-template-columns: 1fr;
        gap: 10px;
        margin-bottom: 10px;
        margin-top: 15px;
    }

    .util-row {
        display: flex;
        gap: 10px;
        align-items: flex-end;
    }

    .util-row > div { flex: 1; }

    .util-row input, .util-row select {
        width: 100%;
        padding: 8px;
        border: 1px solid var(--key-border);
        border-radius: 4px;
        background: var(--key-bg);
        color: var(--text-main);
    }

    .util-row button {
        padding: 8px 15px;
        margin: 0;
        width: auto;
        font-size: 0.9rem;
    }

    #utilResult {
        margin-top: 10px;
        padding: 10px;
        background: var(--key-bg);
        border: 1px solid var(--key-border);
        border-radius: 4px;
        font-size: 0.9rem;
        color: var(--accent);
        font-weight: bold;
        word-break: break-all;
    }

    /* Conversion Tools */
    .conv-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 10px;
        margin-bottom: 10px;
    }

    .conv-grid input {
        width: 100%;
        padding: 6px;
        border: 1px solid var(--key-border);
        border-radius: 4px;
        background: var(--key-bg);
        color: var(--text-main);
        box-sizing: border-box;
    }

    .conv-btns {
        display: flex;
        flex-wrap: wrap;
        gap: 5px;
    }

    .conv-btns button {
        padding: 6px 10px;
        font-size: 0.8rem;
        border-radius: 4px;
    }

    #convResult {
        margin-top: 10px;
        font-weight: bold;
        color: var(--accent);
        min-height: 20px;
    }

    /* Custom Theme Panel */
    .custom-panel {
        display: none;
        background: var(--calc-bg);
        padding: 20px 15px 15px;
        border-radius: var(--radius);
        border: 1px solid var(--key-border);
        font-size: 0.85rem;
        grid-template-columns: 1fr 1fr;
        gap: 10px;
        position: relative;
        z-index: 10;
        box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    }

    .close-panel {
        position: absolute;
        top: 5px;
        right: 10px;
        background: none;
        border: none;
        font-size: 1.2rem;
        color: var(--text-muted);
        cursor: pointer;
        padding: 0;
        line-height: 1;
    }

    .close-panel:hover { color: #dc2626; }

    .custom-panel label {
        display: flex;
        justify-content: space-between;
        align-items: center;
    }

    .custom-panel input[type="color"] {
        border: none;
        width: 30px;
        height: 30px;
        cursor: pointer;
        background: none;
        padding: 0;
    }

    .custom-panel input[type="range"] {
        width: 100%;
        grid-column: span 2;
    }

    .custom-actions {
        grid-column: span 2;
        display: flex;
        gap: 10px;
        margin-top: 10px;
    }

    .custom-actions button {
        flex: 1;
        padding: 10px 0;
        font-size: 0.85rem;
        font-weight: bold;
        background-color: var(--key-bg);
        color: var(--text-main);
        border: 1px solid var(--key-border);
        border-radius: calc(var(--radius) * 0.75);
        cursor: pointer;
        transition: all 0.1s;
    }

    .custom-actions button:hover:not(:disabled) { background-color: var(--key-hover); }
    .custom-actions button:active:not(:disabled) { background-color: var(--key-active); transform: scale(0.98); }
    .custom-actions button:disabled { opacity: 0.5; cursor: not-allowed; }

    .storage-note {
        grid-column: span 2;
        text-align: center;
        font-size: 0.75rem;
        color: var(--text-muted);
        margin-top: 5px;
    }

    /* Footer Credits */
    .credit {
        flex-shrink: 0;
        padding: 20px 40px;
        color: var(--text-muted);
        font-size: 0.85rem;
        line-height: 1.5;
        border-top: 1px solid var(--key-border);
        background-color: var(--calc-bg);
        display: flex;
        justify-content: center;
        align-items: center;
        width: 100%;
        box-sizing: border-box;
        position: relative;
        min-height: 64px;
        z-index: 10;
    }
    
    .credit .main { 
        font-weight: 600; 
        color: var(--text-main); 
        text-align: center;
    }

    .credit-btn {
        position: absolute;
        right: 40px;
        top: 50%;
        transform: translateY(-50%);
        display: inline-block;
        padding: 8px 16px;
        background-color: var(--accent);
        color: var(--accent-text);
        text-decoration: none;
        border-radius: var(--radius);
        font-size: 0.85rem;
        font-weight: bold;
        transition: all 0.2s;
        box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    }

    .credit-btn:hover {
        filter: brightness(1.1);
        transform: translateY(-50%) scale(1.05);
        box-shadow: 0 4px 8px rgba(0,0,0,0.15);
    }

    /* Responsive Footer */
    @media (max-width: 600px) {
        .credit {
            flex-direction: column;
            gap: 15px;
            padding: 20px;
        }
        .credit-btn {
            position: static;
            transform: none;
        }
        .credit-btn:hover {
            transform: scale(1.05);
        }
    }
