:root {
    --bg-color: #f4f7f6;
    --panel-bg: #ffffff;
    --primary-color: #4f46e5;
    --primary-hover: #4338ca;
    --secondary-color: #4b5563;
    --secondary-hover: #374151;
    --danger-color: #ef4444;
    --text-color: #1f2937;
    --border-color: #cbd5e1;
}

*:not(mjx-container):not(mjx-container *) {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    padding: 1.25rem 1rem 3rem;
    display: flex;
    justify-content: center;
    user-select: none;
    -webkit-user-select: none;
}

.container {
    max-width: 1140px;
    width: 100%;
}

/* --------------------------------------------------------------------------
   Standard 4.1 Top Navigation Bar
   -------------------------------------------------------------------------- */
.top-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.65rem 1.15rem;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.05);
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
}

.nav-home-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    color: #0284c7;
    font-weight: 600;
    font-size: 0.9rem;
    text-decoration: none;
    transition: color 0.15s ease;
}

.nav-home-btn:hover {
    color: #0369a1;
}

.nav-actions {
    display: flex;
    align-items: center;
    gap: 0.85rem;
}

.nav-pill-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    background: #f8fafc;
    color: #0f172a;
    border: 1px solid #cbd5e1;
    border-radius: 9999px;
    padding: 0.35rem 0.85rem;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
}

.nav-pill-btn:hover {
    background: #f1f5f9;
    border-color: #94a3b8;
}

.nav-dept-tag {
    font-size: 0.82rem;
    color: #64748b;
    font-weight: 500;
}

/* --------------------------------------------------------------------------
   Standard 22 Clean Header Architecture (Zero Badge Rows)
   -------------------------------------------------------------------------- */
.sim-header {
    text-align: center;
    margin-bottom: 1.5rem;
    padding: 0.25rem 0;
}

.sim-title {
    font-size: 2.1rem;
    color: #0f172a;
    font-weight: 800;
    margin-bottom: 0.35rem;
    line-height: 1.25;
}

.sim-subtitle {
    color: #64748b;
    font-size: 0.95rem;
    line-height: 1.5;
    max-width: 900px;
    margin: 0 auto;
}

/* --------------------------------------------------------------------------
   Static Series Card
   -------------------------------------------------------------------------- */
.series-card {
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 1.35rem 1.5rem;
    margin-top: 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.02);
}

.series-card h3 {
    font-size: 1rem;
    color: #1e3a8a;
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.series-card p {
    font-size: 0.88rem;
    color: #4b5563;
    line-height: 1.55;
    margin-bottom: 0.5rem;
}

.series-card .series-tagline {
    font-weight: 700;
    color: #111827;
    font-style: italic;
}

/* --------------------------------------------------------------------------
   Main Workspace Layout
   -------------------------------------------------------------------------- */
.sim-layout {
    display: grid;
    grid-template-columns: 1fr 1.3fr;
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.panel {
    background: var(--panel-bg);
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
    border: 1px solid #e2e8f0;
    display: flex;
    flex-direction: column;
}

.controls-panel {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.control-group {
    margin-bottom: 1.25rem;
    padding-bottom: 1.25rem;
    border-bottom: 1px dashed #e2e8f0;
}

.control-group:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

.control-group h3 {
    font-size: 1.05rem;
    margin-bottom: 0.5rem;
    color: #334155;
}

.instruction-text {
    font-size: 0.85rem;
    color: #64748b;
    margin-bottom: 0.75rem;
    line-height: 1.4;
}

.action-buttons-row {
    display: flex;
    gap: 0.5rem;
}

.btn-add-pos, .btn-add-neg, .btn-delete {
    padding: 0.65rem 0.75rem;
    font-weight: 600;
    font-size: 0.85rem;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.2s;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-add-pos { background: #dcfce7; color: #166534; flex: 1; }
.btn-add-pos:hover { background: #bbf7d0; }
.btn-add-neg { background: #dbeafe; color: #1e40af; flex: 1; }
.btn-add-neg:hover { background: #bfdbfe; }
.btn-delete { background: #fee2e2; color: #991b1b; font-size: 0.8rem; }
.btn-delete:hover { background: #fca5a5; }

#modifier-panel {
    background: #f8fafc;
    padding: 1rem;
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

#selected-idle-msg {
    font-size: 0.85rem;
    color: #94a3b8;
    text-align: center;
    font-style: italic;
}

.info-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sliders-container { display: flex; flex-direction: column; gap: 0.75rem; }
.slider-group { display: flex; flex-direction: column; gap: 0.2rem; }
.slider-group label { font-size: 0.88rem; font-weight: 700; color: #475569; }

input[type="range"] { width: 100%; accent-color: var(--primary-color); cursor: pointer; min-height: 36px; }

.problem-grid { display: flex; gap: 0.5rem; margin-bottom: 0.75rem; }
.prob-btn {
    flex: 1; padding: 0.65rem; background: #f1f5f9;
    border: 1px solid var(--border-color); border-radius: 6px;
    font-size: 0.82rem; font-weight: 600; cursor: pointer; transition: all 0.2s;
    min-height: 44px; display: flex; align-items: center; justify-content: center; text-align: center;
}
.prob-btn:hover { background: #e2e8f0; }
.prob-btn.active { background: #1e293b; color: white; border-color: #1e293b; }

.problem-desc-box {
    background: #ffffff; border: 1px dashed var(--border-color);
    padding: 0.75rem; border-radius: 6px; margin-bottom: 0.5rem;
}
.problem-desc-box h4 { font-size: 0.88rem; color: #1e293b; margin-bottom: 0.25rem; }
.problem-desc-box p { font-size: 0.82rem; color: #475569; line-height: 1.4; }

.status-banner {
    background: #dcfce7; color: #166534; padding: 0.5rem;
    border-radius: 4px; font-weight: bold; margin-top: 0.5rem;
    text-align: center; font-size: 0.85rem;
}

.visualizer-panel {
    display: flex;
    flex-direction: column;
    align-items: stretch;
}

.canvas-container {
    background: #030712; border-radius: 8px;
    overflow: hidden; border: 1px solid #1e293b;
    display: flex; justify-content: center; margin-bottom: 1rem;
}
canvas { display: block; max-width: 100%; touch-action: none; }

.stats-display {
    width: 100%; display: flex; justify-content: space-between;
    font-weight: 700; font-size: 0.9rem; margin-bottom: 0.6rem;
}

.math-breakdown-box {
    background: #f8fafc; border: 1px solid #e2e8f0;
    padding: 1rem; border-radius: 8px; font-size: 0.85rem; margin-top: auto;
    overflow-x: auto;
    user-select: text !important;
    -webkit-user-select: text !important;
}
.math-breakdown-box h3 { font-size: 0.95rem; color: #0f172a; margin-bottom: 0.4rem; }
.math-breakdown-box p { color: #475569; margin-bottom: 0.5rem; line-height: 1.4; }

.btn {
    width: 100%; padding: 0.65rem; border: none; border-radius: 6px;
    font-size: 0.95rem; font-weight: 600; cursor: pointer; transition: all 0.2s;
    min-height: 44px; display: flex; align-items: center; justify-content: center;
}
.btn-secondary { background-color: var(--secondary-color); color: white; }
.btn-secondary:hover { background-color: var(--secondary-hover); }
.btn-primary { background-color: var(--primary-color); color: white; }
.btn-primary:hover { background-color: var(--primary-hover); }

/* --------------------------------------------------------------------------
   Standard 4.3 Admission Callout Box
   -------------------------------------------------------------------------- */
.admission-card { 
    background: linear-gradient(135deg, #1e3a8a, #0f172a); 
    color: #ffffff; 
    padding: 1.5rem; 
    border-radius: 12px; 
    display: flex; 
    flex-wrap: wrap; 
    align-items: center; 
    justify-content: space-between; 
    gap: 1.5rem; 
    box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1); 
    position: relative; 
    border: 2px solid transparent; 
}

.attention-flash { 
    animation: bannerGlowPulse 3s infinite ease-in-out; 
}

@keyframes bannerGlowPulse { 
    0% { box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1); border-color: transparent; } 
    50% { box-shadow: 0 0 20px 4px rgba(251, 191, 36, 0.4); border-color: rgba(251, 191, 36, 0.6); } 
    100% { box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1); border-color: transparent; } 
}

.promo-copy .promo-kicker { 
    color: #60a5fa; 
    font-weight: 600; 
    text-transform: uppercase; 
    font-size: 0.8rem; 
    letter-spacing: 0.05em; 
    margin-bottom: 0.2rem; 
}

.promo-copy .promo-lead { 
    color: #ffffff; 
    font-weight: 600; 
    font-size: 1.05rem; 
    margin-bottom: 0.25rem; 
}

.promo-copy .promo-headline { 
    color: #fcd34d; 
    font-weight: 800; 
    font-size: 1.45rem; 
    line-height: 1.25; 
}

.program-grid { 
    display: flex; 
    gap: 1.5rem; 
    flex: 1; 
    justify-content: center; 
}

.program-card { 
    background: rgba(255, 255, 255, 0.08); 
    padding: 0.75rem 1rem; 
    border-radius: 8px; 
    border: 1px solid rgba(255, 255, 255, 0.1); 
    font-size: 0.85rem; 
    display: flex; 
    flex-direction: column; 
    gap: 0.2rem; 
}

.program-card strong { color: #fcd34d; font-size: 0.95rem; } 
.program-card span { color: #e2e8f0; } 
.program-card small { color: #94a3b8; font-style: italic; }

.promo-actions { 
    display: flex; 
    flex-direction: column; 
    gap: 0.5rem; 
    min-width: 160px; 
}

.promo-button { 
    padding: 0.65rem 1.2rem; 
    border-radius: 6px; 
    font-weight: 700; 
    text-decoration: none; 
    transition: all 0.2s ease; 
    text-align: center; 
    font-size: 0.9rem; 
    min-height: 44px; 
    display: flex; 
    align-items: center; 
    justify-content: center; 
}

.main-cta { background-color: #fbbf24; color: #0f172a; } 
.main-cta:hover { background-color: #f59e0b; transform: translateY(-1px); }

.sub-cta { background-color: transparent; color: #e2e8f0; border: 1px solid rgba(255, 255, 255, 0.3); } 
.sub-cta:hover { background-color: rgba(255, 255, 255, 0.1); color: #fff; border-color: #fff; }

/* --------------------------------------------------------------------------
   Standard 4.4 Feedback & Suggestions Channel
   -------------------------------------------------------------------------- */
.feedback-card {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 1.15rem 1.35rem;
    margin-top: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1.25rem;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.05);
}

.feedback-content {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.feedback-icon {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    background: #e0f2fe;
    color: #0284c7;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.feedback-text h4 {
    font-size: 0.95rem;
    font-weight: 700;
    color: #0f172a;
    margin-bottom: 0.2rem;
}

.feedback-text p {
    font-size: 0.84rem;
    color: #64748b;
    line-height: 1.4;
    margin: 0;
}

.feedback-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.55rem 1.15rem;
    border-radius: 8px;
    background: #0284c7;
    color: #ffffff;
    font-weight: 600;
    font-size: 0.85rem;
    text-decoration: none;
    white-space: nowrap;
    transition: background-color 0.15s ease;
    flex-shrink: 0;
}

.feedback-btn:hover {
    background: #0369a1;
}

/* --------------------------------------------------------------------------
   Standard 4.5 Standard Series Footer
   -------------------------------------------------------------------------- */
.series-footer { 
    text-align: center; 
    padding: 1.5rem 0 0; 
    border-top: 1px solid #e5e7eb; 
    margin-top: 2rem; 
}

.series-footer p { 
    font-size: 0.82rem; 
    color: #64748b; 
    font-weight: 500; 
}

/* --------------------------------------------------------------------------
   Standard 4.2 & 19 Accessible Series Modal Architecture
   -------------------------------------------------------------------------- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.25rem;
    box-sizing: border-box;
}

.modal-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.modal-window {
    position: relative;
    background: #ffffff;
    border-radius: 14px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    max-width: 760px;
    width: 100%;
    max-height: 92vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 10000;
    animation: modalFadeIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalFadeIn {
    from { opacity: 0; transform: scale(0.96) translateY(8px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.35rem;
    border-bottom: 1px solid #e2e8f0;
    flex-shrink: 0;
}

.modal-header h3 {
    font-size: 1.1rem;
    font-weight: 700;
    color: #0f172a;
    margin: 0;
}

.modal-close-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    line-height: 1;
    color: #64748b;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    border-radius: 6px;
    transition: all 0.15s ease;
}

.modal-close-btn:hover {
    color: #0f172a;
    background: #f1f5f9;
}

.modal-body {
    padding: 1.15rem 1.35rem;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    flex: 1 1 auto;
}

.modal-admission {
    flex-shrink: 0 !important;
    min-height: fit-content !important;
    height: auto !important;
    margin-top: 0.25rem;
    padding: 0.85rem 1.15rem !important;
    gap: 0.6rem !important;
    border-radius: 10px !important;
}

.modal-admission .promo-copy {
    gap: 0.1rem;
}

.modal-admission .promo-kicker {
    font-size: 0.68rem !important;
    letter-spacing: 0.06em;
}

.modal-admission .promo-lead {
    font-size: 0.82rem !important;
    font-weight: 600;
}

.modal-admission .promo-headline {
    font-size: 1.05rem !important;
    line-height: 1.25 !important;
}

.modal-admission .program-grid {
    display: grid !important;
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 0.55rem !important;
}

.modal-admission .program-card {
    padding: 0.5rem 0.75rem !important;
}

.modal-admission .program-card strong {
    font-size: 0.88rem !important;
}

.modal-admission .program-card span {
    font-size: 0.72rem !important;
}

.modal-admission .program-card small {
    font-size: 0.65rem !important;
}

.modal-admission .promo-actions {
    gap: 0.55rem !important;
    margin-top: 0.15rem !important;
    flex-direction: row !important;
}

.modal-admission .promo-button {
    padding: 0.4rem 1.1rem !important;
    font-size: 0.78rem !important;
    min-height: 36px !important;
}

.modal-series-card {
    padding: 0.85rem 1.15rem;
    gap: 0.45rem;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
}

.modal-series-card h4 {
    font-size: 0.95rem;
    font-weight: 700;
    color: #0f172a;
    margin-bottom: 0.35rem;
}

.modal-series-card p {
    font-size: 0.82rem;
    line-height: 1.5;
    color: #475569;
    margin-bottom: 0.5rem;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    padding: 0.75rem 1.35rem;
    border-top: 1px solid #e2e8f0;
    flex-shrink: 0;
}

.modal-dismiss-btn {
    padding: 0.45rem 1.25rem;
    border-radius: 8px;
    background: #f8fafc;
    border: 1px solid #cbd5e1;
    font-size: 0.85rem;
    font-weight: 600;
    color: #0f172a;
    cursor: pointer;
    transition: all 0.15s ease;
}

.modal-dismiss-btn:hover {
    background: #f1f5f9;
}

/* --------------------------------------------------------------------------
   Standard 11: MathJax Dual-Rule Inline/Display CSS
   -------------------------------------------------------------------------- */
.math-display mjx-container,
mjx-container[display="true"] {
    display: block !important;
    max-width: 100% !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    margin: 0.4rem auto !important;
    text-align: center;
}

mjx-container:not([display="true"]) {
    display: inline-block !important;
    max-width: 100% !important;
    overflow: visible !important;
    margin: 0 0.12em !important;
    vertical-align: -0.15em !important;
    line-height: 0;
}

mjx-container svg {
    max-width: 100% !important;
    height: auto !important;
    display: inline-block;
    vertical-align: middle;
}

/* --------------------------------------------------------------------------
   Standard 7 & 17 Option A Responsive Reordering (Mobile First)
   -------------------------------------------------------------------------- */
@media (max-width: 900px) {
    .sim-layout {
        display: flex !important;
        flex-direction: column !important;
        gap: 1.25rem !important;
    }

    .visualizer-panel {
        order: 1 !important;
        width: 100% !important;
    }

    .controls-panel {
        order: 2 !important;
        width: 100% !important;
        max-height: none !important;
        overflow-y: visible !important;
    }

    .admission-card { 
        flex-direction: column; 
        text-align: center; 
        gap: 1.5rem; 
    } 
    .program-grid { 
        flex-direction: column !important; 
    } 
    .promo-actions { 
        width: 100%; 
    }
}

@media (max-width: 680px) {
    body {
        padding: 0.5rem 0.4rem 2rem;
    }

    .sim-title {
        font-size: 1.5rem;
    }

    .top-nav {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    .nav-actions {
        width: 100%;
        display: flex;
        align-items: center;
        justify-content: space-between;
    }

    .feedback-card {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.85rem;
    }

    .feedback-btn {
        width: 100%;
        text-align: center;
    }

    /* Standard 21 HUD Mode Chip Hiding on Mobile */
    #hud-mode-chip {
        display: none !important;
    }

    /* Standard 19 Option A Priority Admission in Modal on Mobile */
    .modal-overlay {
        padding: 0.65rem;
    }

    .modal-window {
        max-height: 90vh;
    }

    .modal-body {
        padding: 0.75rem 0.85rem;
        gap: 0.6rem;
    }

    .modal-admission {
        order: -1 !important;
        margin-top: 0 !important;
        margin-bottom: 0.5rem !important;
        padding: 0.75rem 0.85rem !important;
        gap: 0.45rem !important;
        height: auto !important;
        min-height: fit-content !important;
    }

    .modal-admission .program-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 0.35rem !important;
    }

    .modal-admission .promo-actions {
        flex-direction: column !important;
    }
}

.hidden { display: none !important; }
