:root {
    --bg: #050010;
    --panel: rgba(15, 8, 30, 0.9);
    --border: rgba(168, 85, 247, 0.15);
    --primary: #a855f7;
    --primary-glow: rgba(168, 85, 247, 0.25);
    --secondary: #22d3ee;
    --accent: #f472b6;
    --text: #f1f0ff;
    --muted: #64748b;
    --canvas-bg: #050010;
    --grid: rgba(168, 85, 247, 0.08);
    --axes: rgba(168, 85, 247, 0.4);
    --curve-color: #a855f7;
    --ellipse-color: #22d3ee;
    --parabola-color: #f59e0b;
    --hyperbola-color: #f472b6;
}

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

body.sim-page {
    font-family: 'Outfit', sans-serif;
    background: var(--bg) !important;
    color: var(--text);
    overflow: hidden;
}

#bgCanvas {
    background: var(--bg) !important;
}

#phet-stage {
    position: absolute;
    top: 0; left: 0;
    width: 1280px;
    height: 720px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg);
    transform-origin: top left;
}

/* ── NAV ── */
.cs-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    height: 52px;
    background: rgba(10, 1, 24, 0.95);
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(12px);
    z-index: 200;
    flex-shrink: 0;
}

.logo a { text-decoration: none; font-weight: 700; font-size: 1.1rem; }

.nav-breadcrumb {
    display: flex; align-items: center; gap: 0.5rem;
    font-size: 0.82rem; color: #94a3b8;
}
.nav-breadcrumb .sep { opacity: 0.3; }
.nav-breadcrumb .nav-current { color: var(--text); font-weight: 600; }

.cs-btn-outline {
    display: inline-flex; align-items: center; gap: 0.4rem;
    padding: 0.35rem 0.9rem;
    border-radius: 50px;
    border: 1px solid rgba(168, 85, 247, 0.25);
    background: transparent;
    color: #94a3b8;
    font-family: 'Outfit', sans-serif;
    font-size: 0.8rem;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.2s;
}
.cs-btn-outline:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: var(--primary-glow);
}

/* ── EQUATION HEADER ── */
#eq-header {
    background: rgba(20, 10, 40, 0.7);
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(10px);
    padding: 0.55rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    gap: 1rem;
}

#eq-display {
    font-family: 'JetBrains Mono', monospace;
    font-size: 1.0rem;
    color: #e2e8f0;
    display: flex;
    align-items: center;
    gap: 0.35rem;
    flex-wrap: wrap;
}

.eq-equals { color: var(--primary); font-weight: 700; margin-left: 0.25rem; }

#type-badge-wrap { flex-shrink: 0; }

#type-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.3rem 1rem;
    border-radius: 50px;
    border: 1.5px solid var(--primary);
    background: var(--primary-glow);
    font-weight: 700;
    font-size: 0.85rem;
    color: var(--primary);
    letter-spacing: 1px;
    text-transform: uppercase;
    transition: all 0.3s;
}

#type-badge.ellipse   { color: var(--ellipse-color);   border-color: var(--ellipse-color);   background: rgba(34,211,238,0.1); }
#type-badge.parabola  { color: var(--parabola-color);  border-color: var(--parabola-color);  background: rgba(245,158,11,0.1); }
#type-badge.hyperbola { color: var(--hyperbola-color); border-color: var(--hyperbola-color); background: rgba(244,114,182,0.1); }
#type-badge.circle    { color: #34d399;                border-color: #34d399;                background: rgba(52,211,153,0.1); }
#type-badge.degenerate{ color: #94a3b8;                border-color: #94a3b8;                background: rgba(148,163,184,0.1); }

/* ── MAIN LAYOUT ── */
.sim-container {
    display: flex;
    flex: 1;
    overflow: hidden;
    min-height: 0;
}

/* ── CANVAS AREA ── */
.canvas-wrap {
    flex: 1;
    position: relative;
    background: var(--canvas-bg);
    overflow: hidden;
}

#conicCanvas {
    display: block;
    width: 100%;
    height: 100%;
    cursor: crosshair;
}

#canvas-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

#coord-display {
    position: absolute;
    bottom: 12px;
    left: 12px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.72rem;
    color: rgba(168, 85, 247, 0.7);
    pointer-events: none;
}

#zoom-controls {
    position: absolute;
    top: 12px;
    right: 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    pointer-events: all;
}

#zoom-controls button {
    width: 30px; height: 30px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: rgba(20, 10, 40, 0.8);
    color: #94a3b8;
    cursor: pointer;
    font-size: 0.75rem;
    display: flex; align-items: center; justify-content: center;
    transition: all 0.2s;
    backdrop-filter: blur(6px);
}
#zoom-controls button:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: var(--primary-glow);
}

/* ── CONTROL PANEL & ANALYSIS PANEL (Left & Right) ── */
.control-panel, .analysis-panel {
    width: 280px;
    flex-shrink: 0;
    background: rgba(10, 5, 20, 0.95);
    backdrop-filter: blur(16px);
    padding: 1.25rem;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    height: 100%;
    min-height: 0;
    touch-action: pan-y;
}

.control-panel { border-right: 1px solid var(--border); }
.analysis-panel { border-left: 1px solid var(--border); }

.control-panel::-webkit-scrollbar, .analysis-panel::-webkit-scrollbar { width: 4px; }
.control-panel::-webkit-scrollbar-track, .analysis-panel::-webkit-scrollbar-track { background: transparent; }
.control-panel::-webkit-scrollbar-thumb, .analysis-panel::-webkit-scrollbar-thumb { background: #2d1a5a; border-radius: 10px; }

.phet-box {
    background: transparent;
    border: 1px solid rgba(168, 85, 247, 0.25);
    border-radius: 8px;
    padding: 1rem;
    box-shadow: inset 0 0 20px rgba(168,85,247,0.02);
}

.section-header {
    font-size: 0.75rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--secondary);
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid rgba(34, 211, 238, 0.2);
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

#large-type-display {
    text-align: center;
    margin: 1.5rem 0;
}

#type-label-large {
    font-size: 2rem;
    font-weight: 700;
    color: var(--secondary);
    letter-spacing: 1px;
    text-transform: uppercase;
    text-shadow: 0 0 15px rgba(34,211,238,0.4);
}

.props-title {
    font-size: 0.75rem;
    color: #e2e8f0;
    margin-bottom: 0.5rem;
}

.coeff-row {
    display: grid;
    grid-template-columns: 22px 60px 1fr;
    align-items: center;
    gap: 0.5rem;
}

.coeff-label {
    font-family: 'JetBrains Mono', monospace;
    font-size: 1rem;
    font-weight: 700;
    color: var(--primary);
    text-align: center;
}

.coeff-term {
    font-size: 0.7rem;
    color: #64748b;
    font-family: 'JetBrains Mono', monospace;
}

.coeff-input {
    width: 100%;
    padding: 0.32rem 0.6rem;
    background: rgba(10, 1, 24, 0.8);
    border: 1px solid rgba(168, 85, 247, 0.25);
    border-radius: 7px;
    color: var(--text);
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.88rem;
    text-align: center;
    outline: none;
    transition: all 0.2s;
    -moz-appearance: textfield;
    appearance: textfield;
}
.coeff-input::-webkit-inner-spin-button,
.coeff-input::-webkit-outer-spin-button { -webkit-appearance: none; }
.coeff-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--primary-glow);
    background: rgba(20, 5, 45, 0.9);
}

.plot-btn {
    width: 100%;
    padding: 0.6rem;
    border: none;
    border-radius: 8px;
    background: linear-gradient(135deg, #7c3aed, #a855f7);
    color: white;
    font-family: 'Outfit', sans-serif;
    font-weight: 700;
    font-size: 0.9rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    margin-bottom: 0.45rem;
    transition: all 0.25s;
    box-shadow: 0 4px 15px rgba(124, 58, 237, 0.3);
}
.plot-btn:hover {
    box-shadow: 0 6px 20px rgba(168, 85, 247, 0.5);
    transform: translateY(-1px);
}
.plot-btn:active { transform: translateY(0); }

.reset-btn {
    width: 100%;
    padding: 0.45rem;
    border: 1px solid rgba(168, 85, 247, 0.2);
    border-radius: 8px;
    background: transparent;
    color: #94a3b8;
    font-family: 'Outfit', sans-serif;
    font-size: 0.82rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    transition: all 0.2s;
}
.reset-btn:hover { border-color: #94a3b8; color: var(--text); }

/* ── ANALYSIS ── */
.analysis-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.3rem 0;
    border-bottom: 1px solid rgba(255,255,255,0.04);
    font-size: 0.78rem;
}
.analysis-row:last-child { border-bottom: none; }
.analysis-key { color: #64748b; }
.analysis-val { font-family: 'JetBrains Mono', monospace; color: var(--primary); font-weight: 600; }

/* ── LEGEND ── */
.legend-row {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    font-size: 0.8rem;
    margin-bottom: 0.4rem;
    color: #cbd5e1;
}
.legend-dot {
    width: 10px; height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}
.ellipse-dot   { background: var(--ellipse-color);   box-shadow: 0 0 6px var(--ellipse-color); }
.parabola-dot  { background: var(--parabola-color);  box-shadow: 0 0 6px var(--parabola-color); }
.hyperbola-dot { background: var(--hyperbola-color); box-shadow: 0 0 6px var(--hyperbola-color); }

/* ── TOGGLE SWITCHES ── */
.toggle-row {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    cursor: pointer;
    font-size: 0.82rem;
    color: #cbd5e1;
    margin-bottom: 0.55rem;
    user-select: none;
}
.toggle-row input[type=checkbox] { display: none; }
.toggle-track {
    width: 34px; height: 18px;
    background: #1e1040;
    border-radius: 9px;
    border: 1px solid rgba(168,85,247,0.2);
    position: relative;
    transition: background 0.2s;
    flex-shrink: 0;
}
.toggle-thumb {
    position: absolute;
    top: 2px; left: 2px;
    width: 12px; height: 12px;
    border-radius: 50%;
    background: #64748b;
    transition: all 0.2s;
}
.toggle-row input:checked + .toggle-track { background: rgba(168,85,247,0.3); border-color: var(--primary); }
.toggle-row input:checked + .toggle-track .toggle-thumb {
    left: 18px;
    background: var(--primary);
    box-shadow: 0 0 8px var(--primary-glow);
}

/* ── PRESETS MODAL ── */
.modal-bg {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.7);
    backdrop-filter: blur(4px);
    z-index: 500;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-card {
    background: rgba(14, 6, 40, 0.95);
    border: 1px solid rgba(168, 85, 247, 0.3);
    border-radius: 16px;
    padding: 1.5rem;
    width: 520px;
    max-height: 80%;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5), 0 0 80px rgba(168,85,247,0.1);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.25rem;
}
.modal-header h3 { color: var(--primary); font-size: 1.05rem; display: flex; align-items: center; gap: 0.5rem; }
.modal-header button {
    width: 28px; height: 28px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: transparent;
    color: #64748b;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    font-size: 0.75rem;
    transition: all 0.2s;
}
.modal-header button:hover { border-color: var(--primary); color: var(--primary); }

.preset-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.75rem;
}

.preset-btn {
    background: rgba(30,15,60,0.7);
    border: 1px solid rgba(168,85,247,0.15);
    border-radius: 10px;
    padding: 0.85rem 0.5rem;
    cursor: pointer;
    text-align: center;
    font-family: 'Outfit', sans-serif;
    transition: all 0.2s;
    color: var(--text);
}
.preset-btn:hover {
    border-color: var(--primary);
    background: var(--primary-glow);
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(168,85,247,0.2);
}
.preset-icon { font-size: 1.6rem; margin-bottom: 0.3rem; }
.preset-name { font-size: 0.75rem; font-weight: 600; color: #e2e8f0; margin-bottom: 0.2rem; }
.preset-eq   { font-size: 0.6rem; color: #64748b; font-family: 'JetBrains Mono', monospace; }
