:root {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    --text-primary: #f8fafc;
    --text-secondary: #cbd5e1;
    --text-muted: #94a3b8;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #06b6d4;
    --proportional: #f59e0b;
    --integral: #22c55e;
    --derivative: #3b82f6;
    --setpoint: #22c55e;
    --output: #3b82f6;
    --error-fill: rgba(239, 68, 68, 0.2);
    --border: #334155;
    --shadow: rgba(0, 0, 0, 0.3);
    --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

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

body {
    font-family: var(--font-family);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

.container {
    max-width: 1600px;
    margin: 0 auto;
    padding: 20px;
}

/* Header */
.header {
    text-align: center;
    padding: 30px 20px;
    background: linear-gradient(135deg, var(--bg-secondary) 0%, var(--bg-tertiary) 100%);
    border-radius: 12px;
    margin-bottom: 30px;
    box-shadow: 0 4px 6px var(--shadow);
}

.header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 10px;
    background: linear-gradient(135deg, var(--accent) 0%, var(--info) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle {
    font-size: 1.1rem;
    color: var(--text-secondary);
}

/* Theory Section */
.theory-section {
    background: var(--bg-secondary);
    padding: 25px;
    border-radius: 12px;
    margin-bottom: 30px;
    box-shadow: 0 4px 6px var(--shadow);
}

.theory-section h2 {
    font-size: 1.8rem;
    margin-bottom: 20px;
    color: var(--text-primary);
}

.formula-display {
    background: var(--bg-tertiary);
    padding: 20px;
    border-radius: 8px;
    margin-bottom: 25px;
    text-align: center;
}

.formula {
    font-family: 'Courier New', monospace;
    font-size: 1.3rem;
    font-weight: 600;
    color: var(--accent);
    letter-spacing: 1px;
}

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

.component-card {
    background: var(--bg-tertiary);
    padding: 20px;
    border-radius: 8px;
    border-left: 4px solid;
    transition: transform 0.2s;
}

.component-card:hover {
    transform: translateY(-2px);
}

.component-card.proportional {
    border-color: var(--proportional);
}

.component-card.integral {
    border-color: var(--integral);
}

.component-card.derivative {
    border-color: var(--derivative);
}

.component-card h3 {
    font-size: 1.2rem;
    margin-bottom: 10px;
}

.component-card p {
    color: var(--text-secondary);
    margin-bottom: 12px;
    font-size: 0.95rem;
}

.formula-small {
    font-family: 'Courier New', monospace;
    font-size: 0.9rem;
    color: var(--accent);
    background: var(--bg-secondary);
    padding: 8px 12px;
    border-radius: 4px;
}

/* Main Content Layout */
.main-content {
    display: flex;
    flex-direction: column;
    gap: 30px;
}

.viz-section {
    display: grid;
    grid-template-columns: 350px 1fr;
    gap: 20px;
    align-items: start;
}

/* Left sidebar container */
.left-sidebar {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* Controls Panel */
.controls-panel {
    background: var(--bg-secondary);
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 4px 6px var(--shadow);
    position: static;
}

.controls-panel h3 {
    font-size: 1.1rem;
    margin-bottom: 15px;
    color: var(--text-primary);
    border-bottom: 2px solid var(--border);
    padding-bottom: 8px;
}

.parameter-group,
.system-settings {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-bottom: 25px;
}

.parameter-control,
.setting-control {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.parameter-control label,
.setting-control label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.value-display {
    font-family: 'Courier New', monospace;
    font-weight: 600;
    color: var(--accent);
    background: var(--bg-tertiary);
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 0.85rem;
}

input[type="range"] {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: var(--bg-tertiary);
    outline: none;
    -webkit-appearance: none;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    transition: background 0.2s;
}

input[type="range"]::-webkit-slider-thumb:hover {
    background: var(--accent-hover);
}

input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    border: none;
    transition: background 0.2s;
}

input[type="range"]::-moz-range-thumb:hover {
    background: var(--accent-hover);
}

.action-buttons {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-bottom: 25px;
}

.btn {
    padding: 10px 16px;
    border: none;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    font-family: var(--font-family);
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 8px var(--shadow);
}

.btn:active {
    transform: translateY(0);
}

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

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--border);
}

.btn-accent {
    background: var(--success);
    color: white;
}

.btn-accent:hover {
    background: #16a34a;
}

.btn-warning {
    background: var(--warning);
    color: white;
}

.btn-warning:hover {
    background: #d97706;
}

.btn-info {
    background: var(--info);
    color: white;
}

.btn-info:hover {
    background: #0891b2;
}

/* Visualization Display */
.viz-display {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.chart-container {
    background: var(--bg-secondary);
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 4px 6px var(--shadow);
}

.chart-container.small {
    flex: 1;
}

.chart-container h3,
.animation-container h3 {
    font-size: 1.1rem;
    margin-bottom: 15px;
    color: var(--text-primary);
}

canvas {
    width: 100%;
    background: var(--bg-tertiary);
    border-radius: 8px;
    display: block;
}

#response-canvas {
    height: 350px;
}

#physical-canvas {
    height: 200px;
}

#pid-canvas {
    height: 250px;
}

.chart-legend,
.animation-legend {
    display: flex;
    gap: 20px;
    margin-top: 12px;
    flex-wrap: wrap;
    justify-content: center;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.legend-color {
    width: 24px;
    height: 4px;
    border-radius: 2px;
}

.legend-color.setpoint {
    background: var(--setpoint);
}

.legend-color.output {
    background: var(--output);
}

.legend-color.error {
    background: var(--error-fill);
    border: 2px solid var(--danger);
}

.legend-color.p-component {
    background: var(--proportional);
}

.legend-color.i-component {
    background: var(--integral);
}

.legend-color.d-component {
    background: var(--derivative);
}

.animation-container {
    background: var(--bg-secondary);
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 4px 6px var(--shadow);
}

/* Metrics Panel */
.metrics-panel {
    background: var(--bg-secondary);
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 4px 6px var(--shadow);
}

.metrics-panel h3 {
    font-size: 1.1rem;
    margin-bottom: 15px;
    color: var(--text-primary);
}

.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 15px;
}

.metric-item {
    background: var(--bg-tertiary);
    padding: 15px;
    border-radius: 8px;
    text-align: center;
}

.metric-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.metric-value {
    font-family: 'Courier New', monospace;
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--accent);
}

/* Guide Section */
.guide-section {
    background: var(--bg-secondary);
    padding: 25px;
    border-radius: 12px;
    box-shadow: 0 4px 6px var(--shadow);
}

.guide-section h2 {
    font-size: 1.8rem;
    margin-bottom: 20px;
    color: var(--text-primary);
}

.guide-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
    margin-bottom: 25px;
}

.guide-card {
    background: var(--bg-tertiary);
    padding: 20px;
    border-radius: 8px;
    border-left: 4px solid var(--accent);
}

.guide-card h3 {
    font-size: 1.1rem;
    margin-bottom: 12px;
    color: var(--text-primary);
}

.guide-card ul {
    list-style: none;
    padding: 0;
}

.guide-card li {
    padding: 8px 0;
    color: var(--text-secondary);
    font-size: 0.95rem;
    position: relative;
    padding-left: 20px;
}

.guide-card li::before {
    content: "→";
    position: absolute;
    left: 0;
    color: var(--accent);
    font-weight: bold;
}

.tips-box {
    background: linear-gradient(135deg, var(--bg-tertiary) 0%, var(--bg-secondary) 100%);
    padding: 20px;
    border-radius: 8px;
    border: 2px solid var(--accent);
}

.tips-box h3 {
    font-size: 1.2rem;
    margin-bottom: 15px;
    color: var(--accent);
}

.tips-box ul {
    list-style: none;
}

.tips-box li {
    padding: 10px 0;
    color: var(--text-secondary);
    position: relative;
    padding-left: 30px;
}

.tips-box li::before {
    content: "💡";
    position: absolute;
    left: 0;
}

/* Responsive Design */
@media (max-width: 1200px) {
    .viz-section {
        grid-template-columns: 1fr;
    }

    .left-sidebar {
        gap: 20px;
    }

    .pid-components {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .container {
        padding: 15px;
    }

    .header h1 {
        font-size: 2rem;
    }

    .subtitle {
        font-size: 1rem;
    }

    .action-buttons {
        grid-template-columns: 1fr;
    }

    .metrics-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .guide-grid {
        grid-template-columns: 1fr;
    }

    #response-canvas {
        height: 250px;
    }

    #physical-canvas {
        height: 150px;
    }

    #pid-canvas {
        height: 200px;
    }
}

@media (max-width: 480px) {
    .header h1 {
        font-size: 1.5rem;
    }

    .theory-section h2,
    .guide-section h2 {
        font-size: 1.4rem;
    }

    .formula {
        font-size: 1rem;
    }

    .metrics-grid {
        grid-template-columns: 1fr;
    }
}
