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

        :root {
            --primary: #0891b2;
            --secondary: #14b8a6;
            --accent: #06b6d4;
            --success: #10b981;
            --danger: #ef4444;
            --warning: #f59e0b;
            --dark: #0f172a;
            --light: #f8fafc;
            --border: #e2e8f0;
            --text: #0f172a;
            --text-light: #64748b
        }

        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
            line-height: 1.6;
            color: var(--text);
            background: linear-gradient(135deg, #0891b2 0%, #14b8a6 100%);
            min-height: 100vh;
            overflow-x: hidden;
            max-width: 100vw
        }

        nav {
            background: rgba(255, 255, 255, .98);
            backdrop-filter: blur(12px);
            box-shadow: 0 2px 16px rgba(0, 0, 0, .08);
            position: sticky;
            top: 0;
            z-index: 1000;
            border-bottom: 3px solid var(--secondary);
            width: 100%
        }

        .nav-container {
            max-width: 1400px;
            margin: 0 auto;
            padding: 0 24px;
            display: flex;
            justify-content: space-between;
            align-items: center;
            height: 72px
        }

        .logo-container {
            display: flex;
            align-items: center;
            gap: 12px;
            text-decoration: none;
            flex-shrink: 0
        }

        .logo-img {
            width: 46px;
            height: 46px;
            border-radius: 10px;
            object-fit: contain;
            filter: drop-shadow(0 4px 8px rgba(8, 145, 178, .3))
        }

        .logo-text {
            font-size: 20px;
            font-weight: 800;
            background: linear-gradient(135deg, var(--primary), var(--secondary));
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text
        }

        .container {
            max-width: 1400px;
            margin: 0 auto;
            padding: 40px 30px
        }

        .hero {
            background: #fff;
            border-radius: 24px;
            padding: 60px 50px;
            margin-bottom: 40px;
            box-shadow: 0 25px 70px rgba(0, 0, 0, .15);
            text-align: center;
            position: relative;
            overflow: hidden
        }

        .hero::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            height: 5px;
            background: linear-gradient(90deg, var(--primary), var(--secondary), var(--accent))
        }

        h1 {
            font-size: 52px;
            margin-bottom: 20px;
            background: linear-gradient(135deg, var(--primary), var(--secondary));
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
            font-weight: 900;
            letter-spacing: -1px
        }

        .subtitle {
            font-size: 22px;
            color: var(--text-light);
            margin-bottom: 15px;
            font-weight: 500
        }

        .calculator-wrapper {
            background: #fff;
            border-radius: 24px;
            padding: 50px;
            box-shadow: 0 25px 70px rgba(0, 0, 0, .15);
            margin-bottom: 40px;
            border: 1px solid var(--border)
        }

        .section-title {
            font-size: 28px;
            font-weight: 800;
            color: var(--primary);
            margin-bottom: 30px;
            display: flex;
            align-items: center;
            gap: 12px
        }

        input[type="text"] {
            width: 100%;
            padding: 20px 28px;
            border: 2px solid var(--border);
            border-radius: 14px;
            font-size: 19px;
            transition: all .3s;
            font-family: 'Courier New', monospace;
            background: var(--light)
        }

        input[type="text"]:focus {
            outline: none;
            border-color: var(--primary);
            box-shadow: 0 0 0 4px rgba(8, 145, 178, .1);
            background: #fff
        }

        .btn-primary {
            padding: 22px 40px;
            background: linear-gradient(135deg, var(--primary), var(--secondary));
            color: #fff;
            border: none;
            border-radius: 14px;
            font-size: 19px;
            font-weight: 800;
            cursor: pointer;
            transition: all .3s;
            box-shadow: 0 12px 30px rgba(8, 145, 178, .35);
            text-transform: uppercase;
            letter-spacing: .5px
        }

        .btn-primary:hover {
            transform: translateY(-3px);
            box-shadow: 0 18px 40px rgba(8, 145, 178, .45)
        }

        /* Performance: add will-change to frequently animated elements */
        .btn-primary, .btn-secondary, .example-btn, .calc-card, .feature-card, .result-card, .alternate-form-item {
            will-change: transform;
        }

        .mobile-toggle {
            display: none;
            flex-direction: column;
            gap: 5px;
            cursor: pointer;
            padding: 10px;
            z-index: 1001
        }

        .mobile-toggle span {
            width: 28px;
            height: 3px;
            background: var(--primary);
            border-radius: 3px;
            transition: all .3s
        }

        @media (max-width:768px) {
            .nav-menu {
                position: fixed;
                left: 0;
                top: 80px;
                transform: translateX(-100%);
                flex-direction: column;
                background: #fff;
                width: 100%;
                padding: 30px;
                box-shadow: 0 10px 30px rgba(0, 0, 0, .2);
                transition: transform .3s cubic-bezier(0.4,0,0.2,1);
                gap: 20px;
                height: calc(100vh - 80px);
                overflow-y: auto;
                will-change: transform
            }

            .nav-menu.active {
                transform: translateX(0)
            }

            .mobile-toggle {
                display: flex
            }

            .hero,
            .calculator-wrapper {
                padding: 30px 20px
            }

            h1 {
                font-size: 36px
            }

            .subtitle {
                font-size: 18px
            }

            .container {
                padding: 20px 15px
            }
        }

        /* Fix the overlapping issue */
        .math-input-container {
            position: relative;
        }

        #enhancedFunctionInput {
            position: relative;
            z-index: 10;
            background: white;
            color: #0f172a;
        }

        /* NEW CALCULATOR STYLES */
        .calculator-container {
            background: var(--card-bg);
            border-radius: 16px;
            overflow: hidden;
        }

        .input-section {
            background: linear-gradient(to right, #f8fafc, #f1f5f9);
            padding: 30px;
            border-bottom: 2px solid var(--border);
        }

        .input-group {
            margin-bottom: 20px;
        }

        .input-label {
            display: block;
            font-weight: 600;
            margin-bottom: 8px;
            color: var(--text);
            font-size: 0.95rem;
        }

        .function-input {
            width: 100%;
            padding: 16px;
            font-size: 1.1rem;
            border: 2px solid var(--border);
            border-radius: 8px;
            font-family: 'Courier New', monospace;
            transition: all 0.3s;
            background: white;
            color: var(--text);
        }

        .function-input:focus {
            outline: none;
            border-color: var(--primary);
            box-shadow: 0 0 0 3px rgba(8, 145, 178, 0.1);
        }

        .options-row {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
            gap: 15px;
            margin-bottom: 20px;
        }

        .select-wrapper {
            position: relative;
        }

        select {
            width: 100%;
            padding: 12px;
            font-size: 1rem;
            border: 2px solid var(--border);
            border-radius: 8px;
            background: white;
            cursor: pointer;
            transition: all 0.3s;
            color: var(--text);
        }

        select:focus {
            outline: none;
            border-color: var(--primary);
        }

        .button-row {
            display: flex;
            gap: 12px;
            flex-wrap: wrap;
            margin-bottom: 20px;
        }

        .btn-secondary {
            padding: 14px 28px;
            font-size: 1rem;
            font-weight: 600;
            border: 2px solid var(--primary);
            border-radius: 8px;
            cursor: pointer;
            transition: all 0.3s;
            flex: 1;
            min-width: 150px;
            background: white;
            color: var(--primary);
        }

        .btn-secondary:hover {
            background: #f0f9ff;
            transform: translateY(-2px);
        }

        .symbol-buttons {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(52px, 1fr));
            gap: 6px;
            margin-top: 15px;
        }

        .symbol-btn {
            padding: 8px 6px;
            background: white;
            border: 2px solid var(--border);
            border-radius: 6px;
            font-size: 0.82rem;
            min-width: 0;
            width: 100%;
            cursor: pointer;
            transition: all 0.2s;
            color: var(--text);
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            text-align: center;
            line-height: 1.2;
            font-weight: 600;
        }

        .symbol-btn:hover {
            background: var(--primary);
            color: white;
            border-color: var(--primary);
        }

        .examples-section {
            margin-top: 15px;
            padding: 15px;
            background: white;
            border-radius: 8px;
            border: 1px solid var(--border);
        }

        .example-buttons {
            display: flex;
            flex-wrap: wrap;
            gap: 8px;
            margin-top: 10px;
        }

        .example-btn {
            padding: 8px 16px;
            background: #f1f5f9;
            border: 1px solid var(--border);
            border-radius: 6px;
            font-size: 0.9rem;
            cursor: pointer;
            transition: all 0.2s;
            min-width: auto;
            flex: 0;
            color: var(--text);
        }

        .example-btn:hover {
            background: var(--primary);
            color: white;
        }

        .results-section {
            padding: 30px;
        }

        .result-card {
            background: white;
            border: 1px solid var(--border);
            border-radius: 12px;
            padding: 25px;
            margin-bottom: 20px;
            box-shadow: var(--shadow);
        }

        .result-card h3 {
            color: var(--primary);
            margin-bottom: 15px;
            font-size: 1.3rem;
            display: flex;
            align-items: center;
            gap: 10px;
        }

        .math-display {
            background: #f8fafc;
            padding: 20px;
            border-radius: 8px;
            margin: 15px 0;
            overflow-x: auto;
            border-left: 4px solid var(--primary);
        }

        .step {
            background: white;
            padding: 15px;
            margin: 10px 0;
            border-radius: 8px;
            border-left: 4px solid var(--success);
            transition: all 0.3s;
        }

        .step:hover {
            box-shadow: var(--shadow);
            transform: translateX(5px);
        }

        .step-number {
            display: inline-block;
            background: var(--success);
            color: white;
            width: 30px;
            height: 30px;
            border-radius: 50%;
            text-align: center;
            line-height: 30px;
            font-weight: 600;
            margin-right: 10px;
        }

        .rule-badge {
            display: inline-block;
            background: #dbeafe;
            color: var(--primary);
            padding: 4px 12px;
            border-radius: 12px;
            font-size: 0.85rem;
            font-weight: 600;
            margin-left: 10px;
        }

        .chain-rule {
            background: #dbeafe;
            color: #1e40af;
        }

        .product-rule {
            background: #d1fae5;
            color: #065f46;
        }

        .quotient-rule {
            background: #fce7f3;
            color: #9f1239;
        }

        .power-rule {
            background: #fef3c7;
            color: #92400e;
        }

        .error-message {
            background: #fee2e2;
            color: #991b1b;
            padding: 15px;
            border-radius: 8px;
            border-left: 4px solid var(--danger);
            margin: 15px 0;
        }

        .success-message {
            background: #d1fae5;
            color: #065f46;
            padding: 15px;
            border-radius: 8px;
            border-left: 4px solid var(--success);
            margin: 15px 0;
        }

        .loading {
            text-align: center;
            padding: 40px;
        }

        .spinner {
            border: 4px solid #f3f4f6;
            border-top: 4px solid var(--primary);
            border-radius: 50%;
            width: 50px;
            height: 50px;
            animation: spin 1s linear infinite;
            margin: 0 auto;
        }

        @keyframes spin {
            0% {
                transform: rotate(0deg);
            }

            100% {
                transform: rotate(360deg);
            }
        }

        @keyframes fadeInUp {
            from { opacity: 0; transform: translateX(-50%) translateY(10px); }
            to { opacity: 1; transform: translateX(-50%) translateY(0); }
        }

        .syntax-help {
            background: #fffbeb;
            border: 1px solid #fbbf24;
            border-radius: 8px;
            padding: 15px;
            margin-top: 15px;
            font-size: 0.9rem;
        }

        .syntax-help h4 {
            color: #92400e;
            margin-bottom: 10px;
        }

        .syntax-help code {
            background: white;
            padding: 2px 6px;
            border-radius: 4px;
            font-family: 'Courier New', monospace;
        }

        #derivativeChart {
            max-width: 100%;
            height: 400px;
        }

        .properties-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
            gap: 15px;
            margin-top: 15px;
        }

        .property-item {
            background: #f8fafc;
            padding: 15px;
            border-radius: 8px;
            border: 1px solid var(--border);
        }

        .property-label {
            font-weight: 600;
            color: var(--text-light);
            font-size: 0.9rem;
            margin-bottom: 5px;
        }

        .property-value {
            font-size: 1rem;
            color: var(--text);
        }

        .alternate-forms-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
            gap: 20px;
            margin-top: 15px;
        }

        .alternate-form-item {
            background: #f8fafc;
            padding: 20px;
            border-radius: 8px;
            border: 2px solid var(--border);
            transition: all 0.3s;
        }

        .alternate-form-item:hover {
            border-color: var(--primary);
            box-shadow: var(--shadow);
            transform: translateY(-2px);
        }

        .form-label {
            font-weight: 600;
            color: var(--primary);
            margin-bottom: 12px;
            font-size: 0.95rem;
        }

        /* ── DUAL ENGINE ROW ── */
        .engine-row{display:flex;align-items:center;gap:12px;margin-bottom:22px;padding:12px 18px;background:var(--light);border-radius:12px;border:2px solid var(--border);flex-wrap:wrap;}
        .engine-label{font-size:14px;font-weight:700;color:var(--text-light);white-space:nowrap;}
        .engine-btn{padding:9px 18px;border:2px solid var(--border);background:white;border-radius:8px;cursor:pointer;font-size:13px;font-weight:700;color:var(--text);transition:.2s;}
        .engine-btn:hover{border-color:var(--primary);color:var(--primary);}
        .engine-btn.active{background:linear-gradient(135deg,var(--primary),var(--secondary));color:white;border-color:var(--primary);}
        .engine-status{font-size:12px;color:var(--text-light);display:flex;align-items:center;gap:6px;}
        .spinner-sm{width:14px;height:14px;border:2px solid #cbd5e1;border-top-color:var(--primary);border-radius:50%;animation:spin .8s linear infinite;display:inline-block;}

        /* ── VOTING & RATINGS ── */
        .voting-section{margin-top:28px;padding:24px;background:linear-gradient(135deg,#fffbeb,#fef9c3);border-radius:16px;border:2px solid #fbbf24;text-align:center;display:none;}
        .voting-section.show{display:block;}
        .voting-title{font-size:17px;font-weight:800;color:#92400e;margin-bottom:6px;}
        .voting-subtitle{font-size:13px;color:#b45309;margin-bottom:16px;}
        .stars{display:flex;justify-content:center;gap:10px;margin-bottom:10px;}
        .star{font-size:36px;color:#d1d5db;cursor:pointer;transition:color .15s,transform .15s;user-select:none;}
        .star:hover,.star.active{color:#f59e0b;transform:scale(1.2);}
        .vote-labels{display:flex;justify-content:space-between;font-size:11px;color:#92400e;font-weight:600;max-width:220px;margin:0 auto 12px;}
        .vote-thanks{font-size:14px;font-weight:700;color:#15803d;min-height:20px;}
        .ratings-dashboard{background:#fff;border-radius:20px;padding:36px;margin-bottom:40px;box-shadow:0 10px 40px rgba(0,0,0,.1);border:1px solid var(--border);}
        .ratings-dashboard h2{font-size:22px;font-weight:800;color:var(--primary);margin-bottom:8px;}
        .rd-bar-row{display:flex;align-items:center;gap:12px;margin:8px 0;}
        .rd-bar-label{font-size:14px;font-weight:700;color:var(--text);min-width:50px;text-align:right;}
        .rd-bar-track{flex:1;height:12px;background:#f1f5f9;border-radius:6px;overflow:hidden;}
        .rd-bar-fill{height:100%;background:linear-gradient(90deg,var(--primary),var(--secondary));border-radius:6px;transition:width .6s ease;}
        .rd-bar-count{font-size:13px;color:var(--text-light);min-width:30px;}
        .rd-summary{display:flex;gap:30px;align-items:center;margin-bottom:20px;flex-wrap:wrap;}
        .rd-big-score{font-size:52px;font-weight:900;color:var(--primary);line-height:1;}
        .rd-stars-row{font-size:22px;color:#f59e0b;margin-bottom:4px;}
        .rd-total{font-size:14px;color:var(--text-light);}
        .rd-recent{margin-top:20px;}
        .rd-recent h3{font-size:15px;font-weight:700;color:var(--text);margin-bottom:10px;}
        .rd-recent-item{display:flex;align-items:center;gap:10px;padding:8px 0;border-bottom:1px solid var(--border);font-size:13px;color:var(--text-light);}

        /* Print Button */
        .print-button {
            margin-top: 20px;
        }

        .btn-print {
            width: 100%;
            padding: 14px 28px;
            font-size: 1rem;
            font-weight: 600;
            border: none;
            border-radius: 8px;
            cursor: pointer;
            transition: all 0.3s;
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 8px;
            background: linear-gradient(135deg, #8b5cf6, #7c3aed);
            color: white;
            box-shadow: 0 4px 12px rgba(139, 92, 246, 0.3);
        }

        .btn-print:hover {
            background: linear-gradient(135deg, #7c3aed, #6d28d9);
            transform: translateY(-2px);
            box-shadow: 0 6px 16px rgba(139, 92, 246, 0.4);
        }

        /* Responsive adjustments */
        @media (max-width: 768px) {
            .options-row {
                grid-template-columns: 1fr;
            }

            .button-row {
                flex-direction: column;
            }

            .btn-primary,
            .btn-secondary {
                min-width: 100%;
            }

            .symbol-buttons {
                grid-template-columns: repeat(auto-fit, minmax(50px, 1fr));
            }

            .export-buttons {
                flex-direction: column;
            }

            .btn-export {
                min-width: 100%;
            }
        }
