:root {
    --primary-color: #2563eb;
    --secondary-color: #3b82f6;
    --success-color: #10b981;
    --warning-color: #f59e0b;
    --danger-color: #ef4444;
    --background: #f8fafc;
    --surface: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --grid-line: rgba(37, 99, 235, 0.3);
    --grid-filled: rgba(16, 185, 129, 0.3);
    --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--background);
    color: var(--text-primary);
    line-height: 1.6;
}

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

header {
    text-align: center;
    margin-bottom: 40px;
    padding: 30px 20px;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
}

header h1 {
    font-size: 2.5rem;
    margin-bottom: 10px;
    font-weight: 700;
}

header .subtitle {
    font-size: 1.1rem;
    opacity: 0.95;
}

main {
    display: flex;
    flex-direction: column;
    gap: 30px;
}

/* Controls Section */
.controls {
    background: var(--surface);
    padding: 25px;
    border-radius: 12px;
    box-shadow: var(--shadow);
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    align-items: flex-end;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 200px;
    flex: 1;
}

.control-group label {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.95rem;
}

.control-group select,
.control-group input[type="range"] {
    padding: 10px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-size: 1rem;
    transition: border-color 0.2s;
}

.control-group select:focus,
.control-group input[type="range"]:focus {
    outline: none;
    border-color: var(--primary-color);
}

.control-group span {
    font-size: 0.9rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.control-group button {
    padding: 12px 20px;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    background: var(--primary-color);
    color: white;
}

.control-group button:hover {
    background: var(--secondary-color);
    transform: translateY(-1px);
    box-shadow: var(--shadow);
}

.control-group button:active {
    transform: translateY(0);
}

#reset-btn {
    background: var(--danger-color);
}

#reset-btn:hover {
    background: #dc2626;
}

#draw-controls {
    display: none;
}

.draw-hint {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-style: italic;
}

/* Visualization Area */
.visualization-area {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 30px;
}

@media (max-width: 1024px) {
    .visualization-area {
        grid-template-columns: 1fr;
    }
}

.fractal-panel,
.log-log-panel {
    background: var(--surface);
    padding: 25px;
    border-radius: 12px;
    box-shadow: var(--shadow);
}

.fractal-panel h2,
.log-log-panel h2 {
    font-size: 1.5rem;
    margin-bottom: 20px;
    color: var(--text-primary);
}

#fractal-canvas,
#loglog-canvas {
    width: 100%;
    height: auto;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    background: #fafafa;
    cursor: crosshair;
}

.stats,
.plot-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 15px;
    margin-top: 20px;
}

.stat-item {
    padding: 15px;
    background: var(--background);
    border-radius: 8px;
    border-left: 4px solid var(--primary-color);
}

.stat-item span:first-child {
    display: block;
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 5px;
}

.stat-item span:last-child {
    display: block;
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--primary-color);
}

/* Data Table Section */
.data-section {
    background: var(--surface);
    padding: 25px;
    border-radius: 12px;
    box-shadow: var(--shadow);
}

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

#data-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 15px;
}

#data-table th,
#data-table td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

#data-table th {
    background: var(--background);
    font-weight: 600;
    color: var(--text-primary);
}

#data-table tr:hover {
    background: var(--background);
}

#data-table td {
    font-family: 'Courier New', monospace;
    font-size: 0.95rem;
}

/* Algorithm Steps */
.algorithm-section {
    background: var(--surface);
    padding: 25px;
    border-radius: 12px;
    box-shadow: var(--shadow);
}

.algorithm-section h2 {
    font-size: 1.5rem;
    margin-bottom: 25px;
    color: var(--text-primary);
}

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

.step {
    display: flex;
    gap: 15px;
    padding: 20px;
    background: var(--background);
    border-radius: 8px;
    border-left: 4px solid var(--primary-color);
}

.step-number {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--primary-color);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1.1rem;
}

.step-content h3 {
    font-size: 1.1rem;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.step-content p {
    color: var(--text-secondary);
    font-size: 0.95rem;
}

/* Formula Section */
.formula-section {
    background: var(--surface);
    padding: 25px;
    border-radius: 12px;
    box-shadow: var(--shadow);
}

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

.formula-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 30px;
    align-items: center;
}

@media (max-width: 768px) {
    .formula-container {
        grid-template-columns: 1fr;
    }
}

.formula {
    padding: 30px;
    background: var(--background);
    border-radius: 8px;
    text-align: center;
    font-size: 1.2rem;
}

.formula-explanation h3 {
    font-size: 1.2rem;
    margin-bottom: 15px;
    color: var(--text-primary);
}

.formula-explanation ul {
    list-style: none;
    padding: 0;
}

.formula-explanation li {
    padding: 10px 0;
    border-bottom: 1px solid var(--border-color);
}

.formula-explanation li:last-child {
    border-bottom: none;
}

.formula-explanation strong {
    color: var(--primary-color);
}

/* Practice Section */
.practice-section {
    background: var(--surface);
    padding: 25px;
    border-radius: 12px;
    box-shadow: var(--shadow);
}

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

.practice-problems {
    display: grid;
    gap: 25px;
}

.problem {
    padding: 20px;
    background: var(--background);
    border-radius: 8px;
    border-left: 4px solid var(--warning-color);
}

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

.problem p {
    color: var(--text-secondary);
    margin-bottom: 15px;
}

.solution {
    margin-top: 15px;
}

.show-solution {
    padding: 8px 16px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.show-solution:hover {
    background: var(--secondary-color);
}

.solution-content {
    margin-top: 15px;
    padding: 15px;
    background: white;
    border-radius: 6px;
    border-left: 3px solid var(--success-color);
}

.solution-content p {
    color: var(--text-primary);
    margin: 0;
}

/* Footer */
footer {
    text-align: center;
    padding: 30px 20px;
    margin-top: 40px;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* Responsive Design */
@media (max-width: 768px) {
    header h1 {
        font-size: 1.8rem;
    }

    header .subtitle {
        font-size: 1rem;
    }

    .controls {
        flex-direction: column;
    }

    .control-group {
        min-width: 100%;
    }

    .stats,
    .plot-stats {
        grid-template-columns: 1fr;
    }

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

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.fractal-panel,
.log-log-panel,
.data-section,
.algorithm-section,
.formula-section,
.practice-section {
    animation: fadeIn 0.3s ease-out;
}

/* Canvas Drawing Mode */
#fractal-canvas.drawing-mode {
    cursor: crosshair;
}

/* Data point animation */
.data-point-new {
    animation: pulse 0.5s ease-out;
}

@keyframes pulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.2);
    }
}
