/* CSS Variables */
:root {
    --primary-color: #00cc99;
    --primary-hover: #008d66;
    --bg-light: #f5f5f7;
    --bg-dark: #1a1a1a;
    --text-light: #333;
    --text-dark: #e0e0e0;
    --modal-light: #ffffff;
    --modal-dark: #2d2d2d;
    --nav-height: 60px;
    --controls-width: 300px;
}

/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background-color: var(--bg-light);
    color: var(--text-light);
    transition: background-color 0.3s, color 0.3s;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Navigation Styles */
.navbar {
    background-color: rgba(255, 255, 255, 0.98);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    height: var(--nav-height);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 2rem;
    position: fixed;
    top: 0;
    width: 100%;
    z-index: 1000;
}

.nav-brand {
    display: flex;
    align-items: center;
}

.nav-logo {
    color: var(--primary-color);
    font-size: 1.5rem;
    font-weight: 700;
    text-decoration: none;
    transition: color 0.3s;
}

.nav-menu {
    display: flex;
    list-style: none;
    gap: 2rem;
}

.nav-link {
    color: var(--text-light);
    text-decoration: none;
    font-weight: 500;
    transition: color 0.3s;
    padding: 0.5rem 1rem;
    border-radius: 6px;
}

.nav-link:hover {
    color: var(--primary-color);
    background-color: rgba(0, 204, 153, 0.1);
}

/* Responsive Design */
@media (max-width: 768px) {
    .navbar {
        padding: 0 1rem;
    }

    .nav-menu {
        position: fixed;
        left: -100%;
        top: var(--nav-height);
        flex-direction: column;
        background-color: rgba(255, 255, 255, 0.98);
        width: 100%;
        text-align: center;
        transition: 0.3s;
        box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
        padding: 1rem 0;
        gap: 1rem;
    }

    .nav-menu.active {
        left: 0;
    }

    .hamburger {
        display: block;
        cursor: pointer;
    }

    .hamburger .bar {
        display: block;
        width: 25px;
        height: 3px;
        margin: 5px auto;
        transition: all 0.3s ease-in-out;
        background-color: var(--text-light);
    }

    .hamburger.active .bar:nth-child(2) {
        opacity: 0;
    }

    .hamburger.active .bar:nth-child(1) {
        transform: translateY(8px) rotate(45deg);
    }

    .hamburger.active .bar:nth-child(3) {
        transform: translateY(-8px) rotate(-45deg);
    }

    #controls-panel {
        width: 100%;
        right: -100%;
    }

    .modal-content {
        width: 95%;
        margin: 2vh auto;
        padding: 1.5rem;
    }
}

/* Dark mode responsive adjustments */
@media (max-width: 768px) {
    .dark-mode .nav-menu {
        background-color: rgba(26, 26, 26, 0.98);
    }

    .dark-mode .hamburger .bar {
        background-color: var(--text-dark);
    }
}

/* Main Content Area */
.main-content {
    margin-top: var(--nav-height);
    flex: 1;
    position: relative;
}

#container {
    width: 100%;
    height: calc(100vh - var(--nav-height));
    position: relative;
    overflow: hidden;
}

/* Canvas Container Styles */
#canvasContainer {
    position: relative;
    width: calc(100% - var(--controls-width));
    height: calc(100vh - var(--nav-height));
    transition: width 0.3s ease;
    overflow: hidden;
    cursor: grab;
}

#canvasContainer:active {
    cursor: grabbing;
}

#canvasContainer.full-width {
    width: 100%;
}

#canvasContainer.fullscreen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw !important;
    height: 100vh !important;
    z-index: 2000;
    background-color: var(--bg-light);
}

#canvasContainer canvas {
    width: 100% !important;
    height: 100% !important;
    display: block;
}

/* Controls Panel Styles */
#controls-panel {
    position: fixed;
    right: 0;
    top: var(--nav-height);
    width: var(--controls-width);
    height: calc(100vh - var(--nav-height));
    background-color: rgba(255, 255, 255, 0.95);
    box-shadow: -2px 0 10px rgba(0, 0, 0, 0.1);
    transition: transform 0.3s ease, opacity 0.3s ease;
    padding: 1.5rem;
    overflow-y: auto;
    z-index: 2000;
    resize: horizontal;
    min-width: 250px;
    max-width: 50vw;
}


.resize-handle {
    position: absolute;
    left: 0;
    top: 0;
    width: 4px;
    height: 100%;
    cursor: ew-resize;
    background-color: var(--primary-color);
    opacity: 0;
    transition: opacity 0.2s;
}

#controls-panel:hover .resize-handle {
    opacity: 0.5;
}

/* Fullscreen Toggle Button */
.fullscreen-toggle {
    position: fixed;
    left: 1rem;
    bottom: 1rem;
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 0.5rem;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    cursor: pointer;
    z-index: 2001;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

.fullscreen-toggle:hover {
    background-color: var(--primary-hover);
    transform: scale(1.05);
}

.fullscreen-toggle.fullscreen-active {
    bottom: 1rem;
    left: 1rem;
    background-color: rgba(0, 0, 0, 0.5);
}

/* Make sure the fullscreen toggle is visible on mobile */
@media (max-width: 768px) {
    .fullscreen-toggle {
        width: 35px;
        height: 35px;
        left: 0.5rem;
        bottom: 0.5rem;
    }
}

/* Form Controls */
select, input, button {
    width: 100%;
    padding: 0.75rem;
    margin: 0.5rem 0;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 0.9rem;
    background-color: white;
    cursor: pointer;
    transition: all 0.3s;
}

select:hover, input:hover {
    border-color: var(--primary-color);
}

button {
    background-color: var(--primary-color);
    color: white;
    border: none;
    font-weight: 500;
}

button:hover {
    background-color: var(--primary-hover);
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 2000;
    padding: 1rem;
    overflow-y: auto;
}

.modal-content {
    background-color: var(--modal-light);
    margin: 5vh auto;
    padding: 2.5rem;
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    position: relative;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    scroll-behavior: smooth;
}

.form-group {
    margin-bottom: 20px;
}

.close {
    position: sticky;
    top: 0;
    align-self: flex-end;
    font-size: 1.8rem;
    font-weight: bold;
    cursor: pointer;
    color: var(--text-light);
    transition: color 0.3s;
    z-index: 1;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 5px;
}

.dark-mode .close {
    color: var(--text-dark);
    background-color: rgba(255, 255, 255, 0.1);
    border-radius: 50%;
}

.close:hover {
    color: var(--primary-color);
}

/* Progress Bar Styles */
.progress-bar {
    background-color: #f0f0f0;
    border-radius: 4px;
    overflow: hidden;
    margin: 20px 0;
    height: 24px;
    position: relative;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.1);
}

.progress {
    width: 0%;
    height: 100%;
    background-color: #4CAF50;
    background-image: linear-gradient(45deg, 
        rgba(255, 255, 255, 0.15) 25%, 
        transparent 25%, 
        transparent 50%, 
        rgba(255, 255, 255, 0.15) 50%, 
        rgba(255, 255, 255, 0.15) 75%, 
        transparent 75%);
    background-size: 20px 20px;
    transition: width 16ms linear;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 12px;
    font-weight: bold;
    text-shadow: 0 1px 1px rgba(0, 0, 0, 0.2);
    animation: progress-bar-stripes 1s linear infinite;
}

/* Notification Styles */
.notification {
    position: fixed;
    top: 20px;
    left: 20px;
    padding: 15px 25px;
    border-radius: 4px;
    color: white;
    font-size: 14px;
    z-index: 1001;
    animation: slideIn 0.3s ease-out;
}

.notification.success {
    background-color: #4CAF50;
}

.notification.error {
    background-color: #f44336;
}

/* Dark Mode Styles */
.dark-mode {
    background-color: var(--bg-dark);
    color: var(--text-dark);
}

.dark-mode .navbar {
    background-color: rgba(26, 26, 26, 0.98);
}

.dark-mode .nav-link {
    color: var(--text-dark);
}

.dark-mode #controls-panel {
    background-color: rgba(45, 45, 45, 0.95);
    color: var(--text-dark);
}

.dark-mode .modal-content {
    background-color: var(--modal-dark);
    color: var(--text-dark);
}

.dark-mode select,
.dark-mode input {
    background-color: #3d3d3d;
    color: var(--text-dark);
    border-color: #555;
}

/* Animations */
@keyframes progress-bar-stripes {
    from { background-position: 20px 0; }
    to { background-position: 0 0; }
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* Media Queries */
@media (max-width: 768px) {
    .navbar {
        padding: 0 1rem;
    }

    .nav-menu {
        position: fixed;
        left: -100%;
        top: var(--nav-height);
        flex-direction: column;
        background-color: rgba(255, 255, 255, 0.98);
        width: 100%;
        text-align: center;
        transition: 0.3s;
        box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
        padding: 1rem 0;
        gap: 1rem;
    }

    #controls-panel {
        width: 80% !important;
        transform: translateX(100%);
        resize: none;
    }

    #controls-panel.hidden {
        transform: translateX(100%);
    }

    #controls-panel:not(.hidden) {
        transform: translateX(0);
    }

    #canvasContainer {
        width: 100% !important;
    }

    .controls-toggle {
        position: fixed;
        right: 1rem;
        top: calc(var(--nav-height) + 1rem);
        width: 40px;
        height: 40px;
        background-color: var(--primary-color);
        color: white;
        border: none;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        z-index: 2001;
        box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
        transition: transform 0.3s ease, background-color 0.3s ease;
    }
    
    .controls-toggle:hover {
        transform: scale(1.05);
        background-color: var(--primary-hover);
    }
    
    .controls-toggle:active {
        transform: scale(0.95);
    }
    
    .controls-toggle svg {
        width: 24px;
        height: 24px;
        stroke: currentColor;
        transition: transform 0.3s ease;
    }
    
    /* Toggle icon state transitions */
    .controls-toggle[aria-expanded="true"] svg {
        transform: rotate(45deg);
    }
    
    /* Panel overlay for mobile */
    .panel-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 1999;
        opacity: 0;
        transition: opacity 0.3s ease;
    }
    
    .panel-overlay.active {
        display: block;
        opacity: 1;
    }
    
    /* Media query adjustments */
    @media (max-width: 768px) {
        .controls-toggle {
            display: flex;
        }
    }
    
    @media (min-width: 769px) {
        .controls-toggle {
            display: none;
        }
    }

    .resize-handle {
        display: none;
    }

    .modal-content {
        width: 95%;
        margin: 2vh auto;
        padding: 1.5rem;
    }

    .panel-overlay.active {
        display: block;
    }
}

@media (min-width: 769px) {
    .controls-toggle {
        display: none;
    }

    #controls-panel {
        transform: none;
        width: var(--controls-width);
    }
}

/* Footer Styles */
.footer {
    background-color: #200f46;
    color: var(--text-dark);
    padding: 2rem 0;
    margin-top: auto;
}

.footer-content {
    max-width: 1200px;
    margin: 0 auto;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 2rem;
    padding: 0 1rem;
}

.footer-section h3 {
    margin-bottom: 1rem;
    color: var(--primary-color);
}

.footer-section ul {
    list-style: none;
}

.footer-section ul li {
    margin-bottom: 0.5rem;
}

.footer-section a {
    color: var(--text-dark);
    text-decoration: none;
    transition: color 0.3s;
}

.footer-section a:hover {
    color: var(--primary-color);
}

.footer-bottom {
    text-align: center;
    padding-top: 2rem;
    margin-top: 2rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

/* Improved Range Input Styling */
input[type="range"] {
    width: 100%;
    height: 6px;
    background: #ddd;
    border-radius: 3px;
    margin: 10px 0;
    outline: none;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    background: var(--primary-color);
    border-radius: 50%;
    cursor: pointer;
    transition: background 0.2s;
}

input[type="range"]::-moz-range-thumb {
    width: 16px;
    height: 16px;
    background: var(--primary-color);
    border-radius: 50%;
    cursor: pointer;
    border: none;
    transition: background 0.2s;
}

input[type="range"]::-webkit-slider-thumb:hover {
    background: var(--primary-hover);
}

input[type="range"]::-moz-range-thumb:hover {
    background: var(--primary-hover);
}

/* Range value display */
.range-value {
    display: inline-block;
    width: 30px;
    text-align: center;
    margin-left: 10px;
    font-size: 0.9rem;
    color: var(--text-light);
}

.dark-mode .range-value {
    color: var(--text-dark);
}

/* Checkbox Group Styling */
.checkbox-group {
    display: flex;
    align-items: center;
    margin: 8px 0;
}

/* Improved Checkbox Styling */
input[type="checkbox"] {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border: 2px solid #ccc;
    border-radius: 4px;
    margin-right: 10px;
    position: relative;
    cursor: pointer;
    transition: all 0.2s;
    vertical-align: middle;
}

input[type="checkbox"]:checked {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
}

input[type="checkbox"]:checked::after {
    content: '✓';
    position: absolute;
    color: white;
    font-size: 14px;
    top: 0;
    left: 4px;
}

input[type="checkbox"]:hover {
    border-color: var(--primary-color);
}

/* Checkbox label styling */
.checkbox-label {
    display: flex;
    align-items: center;
    cursor: pointer;
    margin: 8px 0;
    user-select: none;
}

.checkbox-label input[type="checkbox"] {
    margin-right: 8px;
}

/* Controls section improvements */
.controls-section {
    padding: 12px 0;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
    margin-bottom: 12px;
}

.controls-section:last-child {
    border-bottom: none;
}

.controls-section h3 {
    margin-bottom: 12px;
    color: var(--primary-color);
    font-size: 1.1rem;
}

/* Dark mode adjustments for controls */
.dark-mode .controls-section {
    border-bottom-color: rgba(255, 255, 255, 0.1);
}

.dark-mode input[type="checkbox"] {
    border-color: #555;
}

.dark-mode input[type="range"] {
    background: #444;
    border-color: #555;
}

.dark-mode input[type="range"]::-webkit-slider-thumb {
    background: var(--primary-color);
}

.dark-mode input[type="range"]::-moz-range-thumb {
    background: var(--primary-color);
}

/* Action Buttons */
.action-button {
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 10px 15px;
    border-radius: 6px;
    margin: 5px 0;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 500;
    display: block;
    width: 100%;
    text-align: center;
}

.action-button:hover {
    background-color: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.action-button:active {
    transform: translateY(0);
}

/* Help and zoom buttons */
.help-button, .zoom-fit-button {
    position: fixed;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-color: var(--primary-color);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    border: none;
    z-index: 1000;
    transition: all 0.2s;
}

.help-button {
    bottom: 20px;
    right: 20px;
}

.zoom-fit-button {
    bottom: 20px;
    right: 70px; /* Position next to help button */
}

.help-button:hover, .zoom-fit-button:hover {
    background-color: var(--primary-hover);
    transform: scale(1.1);
}

.help-button:active, .zoom-fit-button:active {
    transform: scale(0.95);
}

/* Custom Function Input Styling */
.equation-input-container {
    position: relative;
    margin: 12px 0;
}

#customFunction {
    width: 100%;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 14px;
    font-family: monospace;
    transition: border-color 0.3s;
}

#customFunction:focus {
    border-color: var(--primary-color);
    outline: none;
    box-shadow: 0 0 0 2px rgba(0, 204, 153, 0.2);
}

.equation-preview {
    margin-top: 8px;
    background-color: #f9f9f9;
    padding: 8px;
    border-radius: 6px;
    min-height: 40px;
    border: 1px solid #eee;
}

.dark-mode .equation-preview {
    background-color: #333;
    border-color: #444;
}

/* Help modal styling */
.help-content {
    max-height: 400px;
    overflow-y: auto;
}

.help-content h3 {
    margin-top: 16px;
    color: var(--primary-color);
}

.help-content ul {
    padding-left: 20px;
}

.help-content li {
    margin-bottom: 8px;
}

.help-content code {
    background-color: #f0f0f0;
    padding: 2px 4px;
    border-radius: 3px;
    font-family: monospace;
}

.dark-mode .help-content code {
    background-color: #333;
}


/* Example Cards Styling */
.examples-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 20px;
    margin-top: 20px;
}

.example-card {
    background-color: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    padding: 15px;
    transition: transform 0.2s, box-shadow 0.2s;
}

.example-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.15);
}

.example-card h3 {
    margin-top: 0;
    color: var(--primary-color);
    font-size: 1.2rem;
}

.example-preview {
    width: 100%;
    height: 150px;
    background-color: #f5f5f7;
    border-radius: 6px;
    overflow: hidden;
    margin: 10px 0;
}

.example-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.example-card p {
    font-size: 0.9rem;
    color: #666;
    margin-bottom: 15px;
}

.apply-example-btn {
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 8px 15px;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 500;
    transition: background-color 0.2s;
}

.apply-example-btn:hover {
    background-color: var(--primary-hover);
}

/* Dark mode adjustments for example cards */
.dark-mode .example-card {
    background-color: var(--modal-dark);
}

.dark-mode .example-card p {
    color: #bbb;
}

.dark-mode .example-preview {
    background-color: #333;
}

/* Share modal styling */
.share-link-container {
    display: flex;
    margin: 10px 0;
}

.share-link-container input {
    flex: 1;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 4px 0 0 4px;
    font-size: 0.9rem;
}

.copy-link-btn {
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 0 15px;
    border-radius: 0 4px 4px 0;
    cursor: pointer;
    font-weight: 500;
}

.copy-link-btn:hover {
    background-color: var(--primary-hover);
}

/* Dark mode for share modal */
.dark-mode .share-link-container input {
    background-color: #333;
    color: var(--text-dark);
    border-color: #555;
}

/* About modal */
.about-content {
    max-height: 60vh;
    overflow-y: auto;
    line-height: 1.6;
    padding-right: 10px;
}

.about-content h3 {
    margin-top: 20px;
    margin-bottom: 10px;
    color: var(--primary-color);
    font-size: 1.2rem;
    font-weight: 600;
}

.about-content p {
    margin-bottom: 15px;
}

.about-content ul {
    margin-left: 20px;
    margin-bottom: 20px;
    list-style-type: disc;
}

.about-content li {
    margin-bottom: 8px;
}

.about-content a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
}

.about-content a:hover {
    text-decoration: underline;
}

.dark-mode .about-content {
    color: var(--text-dark);
}

/* Export notes */
.export-note {
    font-size: 0.9rem;
    color: #666;
    margin: 10px 0;
    padding: 10px;
    background-color: rgba(0, 204, 153, 0.1);
    border-radius: 4px;
}

.dark-mode .export-note {
    color: #bbb;
    background-color: rgba(0, 204, 153, 0.2);
}

/* Add these styles to prevent button movement */
.export-button {
    position: relative;
    display: block;
    width: 100%;
    padding: 12px 15px;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 500;
    text-align: center;
    transition: background-color 0.3s ease;
}

.export-button:hover {
    background-color: var(--primary-hover);
}

.export-button:active {
    transform: translateY(1px);
}

.export-options {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
    margin: 15px 0;
}