/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    height: 100vh;
    overflow: hidden;
}

/* Main container - responsive height */
#main-container {
    width: 100%;
    height: 450px; /* Default iframe height */
    display: grid;
    grid-template-columns: 280px 1fr;
    grid-template-rows: 1fr auto;
    grid-template-areas: 
        "controls graph"
        "legend graph";
    gap: 10px;
    padding: 10px;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
}

/* Responsive height for full browser */
@media (min-height: 600px) {
    body:not(.iframe) #main-container {
        height: 90vh;
    }
}

/* Control Panel */
#control-panel {
    grid-area: controls;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 8px;
    padding: 15px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
    overflow-y: auto;
    max-height: 100%;
}

.control-group {
    margin-bottom: 15px;
}

.control-group label {
    display: block;
    font-weight: 600;
    color: #2c3e50;
    margin-bottom: 5px;
    font-size: 14px;
}

select, input[type="text"] {
    width: 100%;
    padding: 8px 12px;
    border: 2px solid #e0e6ed;
    border-radius: 6px;
    font-size: 14px;
    transition: all 0.3s ease;
    background: white;
}

select:focus, input[type="text"]:focus {
    outline: none;
    border-color: #3498db;
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.1);
}

/* Slider Controls */
.slider-group {
    margin-bottom: 12px;
}

.slider-group label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 14px;
    font-weight: 600;
    color: #2c3e50;
}

input[type="range"] {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: #e0e6ed;
    outline: none;
    margin-top: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
}

input[type="range"]::-webkit-slider-thumb {
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: linear-gradient(135deg, #3498db, #2980b9);
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    transition: all 0.3s ease;
}

input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

/* Equation Display */
.equation-display {
    background: linear-gradient(135deg, #f8f9fa, #e9ecef);
    padding: 12px;
    border-radius: 6px;
    text-align: center;
    font-family: 'Courier New', monospace;
    font-size: 16px;
    font-weight: bold;
    color: #2c3e50;
    border: 2px solid #e0e6ed;
    margin-top: 10px;
}

/* Button Styles */
.button-group {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

button {
    padding: 8px 12px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    background: linear-gradient(135deg, #3498db, #2980b9);
    color: white;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    min-height: 36px;
    white-space: nowrap;
}

button:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

button:active {
    transform: translateY(0);
}

#plot-custom {
    width: 100%;
    margin-top: 8px;
    background: linear-gradient(135deg, #27ae60, #229954);
}

/* Graph Container */
#graph-container {
    grid-area: graph;
    position: relative;
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
    overflow: hidden;
}

#graph-canvas {
    width: 100%;
    height: 100%;
    cursor: crosshair;
    display: block;
}

/* Coordinate Display */
#coordinate-display {
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 6px 12px;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 12px;
    pointer-events: none;
}

/* Function Legend */
#function-legend {
    grid-area: legend;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 8px;
    padding: 12px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    padding: 6px;
    border-radius: 4px;
    transition: background-color 0.3s ease;
}

.legend-item:hover {
    background: rgba(52, 152, 219, 0.1);
}

.legend-color {
    width: 16px;
    height: 16px;
    border-radius: 2px;
    border: 1px solid #ddd;
}

.legend-text {
    flex: 1;
    font-family: 'Courier New', monospace;
    font-size: 14px;
    font-weight: 600;
    color: #2c3e50;
}

.toggle-function {
    padding: 4px 8px;
    font-size: 12px;
    min-height: 28px;
    background: linear-gradient(135deg, #95a5a6, #7f8c8d);
}

.toggle-function.hidden {
    background: linear-gradient(135deg, #e74c3c, #c0392b);
}

/* Mobile Optimizations */
@media (max-width: 768px) {
    #main-container {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr auto;
        grid-template-areas: 
            "controls"
            "graph"
            "legend";
        gap: 8px;
        padding: 8px;
    }
    
    #control-panel {
        max-height: 200px;
    }
    
    .button-group button {
        min-width: 44px;
        min-height: 44px;
    }
    
    .slider-group label {
        font-size: 12px;
    }
    
    input[type="range"]::-webkit-slider-thumb {
        width: 24px;
        height: 24px;
    }
}

/* Tooltip Styles */
[title] {
    position: relative;
}

/* Animation for smooth transitions */
.parameter-controls {
    transition: all 0.3s ease;
}

/* Focus indicators for accessibility */
button:focus, input:focus, select:focus {
    outline: 2px solid #3498db;
    outline-offset: 2px;
}