:root {
    --bg-color: #f4f7f6;
    --panel-bg: #ffffff;
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --secondary-color: #4b5563;
    --secondary-hover: #374151;
    --danger-color: #dc2626;
    --success-color: #16a34a;
    --text-color: #1f2937;
    --border-color: #cbd5e1;
    --accent-gold: #f59e0b;
}

*: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.2rem 1rem;
    display: flex;
    justify-content: center;
    user-select: none;
    -webkit-user-select: none;
}

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

/* Top Navigation Bar */
.top-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.2rem;
    padding-bottom: 0.8rem;
    border-bottom: 1px solid var(--border-color);
}

.nav-home-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.5rem 1rem;
    background: #ffffff;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: #1e293b;
    font-size: 0.88rem;
    font-weight: 700;
    text-decoration: none;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    transition: all 0.2s ease;
    min-height: 40px;
}

.nav-home-btn:hover {
    background: #f8fafc;
    border-color: #94a3b8;
    color: var(--primary-color);
    transform: translateY(-1px);
}

.nav-dept-tag {
    font-size: 0.82rem;
    font-weight: 600;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

@media (max-width: 600px) {
    .nav-dept-tag {
        display: none;
    }
}

header {
    text-align: center;
    margin-bottom: 1.5rem;
}

header h1 {
    font-size: 2.1rem;
    color: #0f172a;
    font-weight: 800;
    margin-bottom: 0.25rem;
}

header p {
    color: #64748b;
    font-size: 0.95rem;
}

/* Series Overview Card */
.series-card {
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 1.4rem 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.02);
    user-select: text;
    -webkit-user-select: text;
}

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

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

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

/* Rigid Grid Layout Track Guards */
.sim-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr);
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

@media (max-width: 900px) {
    .sim-layout {
        display: flex;
        flex-direction: column;
        gap: 1.25rem;
    }

    /* Option A: Visualizer & Canvas render first on mobile */
    .visualizer-panel {
        order: 1;
    }

    /* Controls follow naturally below without internal scroll traps */
    .controls-panel {
        order: 2;
        max-height: none;
        overflow-y: visible;
        padding-right: 1.4rem;
        padding-bottom: 1.4rem;
    }
}

/* Controls Panel with Internal Scrolling */
.controls-panel {
    background-color: var(--panel-bg);
    padding: 1.4rem;
    border-radius: 12px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 1.1rem;
    max-height: calc(100vh - 140px);
    overflow-y: auto;
    overscroll-behavior: contain;
    touch-action: pan-y;
    -webkit-overflow-scrolling: touch;
    box-sizing: border-box;
}

/* Mode Tabs */
.mode-selector {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
    background: #f1f5f9;
    padding: 0.4rem;
    border-radius: 10px;
}

@media (max-width: 600px) {
    .mode-selector {
        grid-template-columns: 1fr;
    }
}

.mode-btn {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    background: transparent;
    border: none;
    border-radius: 8px;
    padding: 0.55rem 0.65rem;
    font-size: 0.8rem;
    font-weight: 700;
    color: #475569;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: left;
    min-height: 40px;
    white-space: normal;
    word-break: break-word;
}

.mode-btn:hover {
    color: #0f172a;
    background: rgba(255, 255, 255, 0.6);
}

.mode-btn.active {
    background: #ffffff;
    color: var(--primary-color);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.06);
    border: 1px solid rgba(203, 213, 225, 0.6);
}

.mode-num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #e2e8f0;
    color: #475569;
    font-size: 0.72rem;
    font-weight: 800;
    flex-shrink: 0;
}

.mode-btn.active .mode-num {
    background: var(--primary-color);
    color: #ffffff;
}

.panel-section-title {
    font-size: 0.96rem;
    font-weight: 800;
    color: #0f172a;
    border-left: 3px solid var(--primary-color);
    padding-left: 0.5rem;
    margin-top: 0.2rem;
    margin-bottom: 0.3rem;
}

.section-desc {
    font-size: 0.8rem;
    color: #64748b;
    line-height: 1.4;
    margin-bottom: 0.5rem;
}

.section-label {
    display: block;
    font-size: 0.82rem;
    font-weight: 700;
    color: #334155;
    margin-bottom: 0.4rem;
}

/* Form Controls & Sliders */
.control-group {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.slider-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    font-size: 0.84rem;
    font-weight: 600;
    color: #334155;
}

.value-display {
    font-family: 'Consolas', 'Courier New', monospace;
    font-weight: 700;
    color: var(--primary-color);
    background: #eff6ff;
    padding: 0.15rem 0.45rem;
    border-radius: 4px;
    font-size: 0.82rem;
    border: 1px solid #dbeafe;
}

input[type="range"] {
    width: 100%;
    height: 6px;
    background: #e2e8f0;
    border-radius: 3px;
    outline: none;
    cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--primary-color);
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
    transition: transform 0.1s ease;
}

input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.15);
}

.control-note {
    font-size: 0.73rem;
    color: #64748b;
    line-height: 1.3;
}

/* Button & Action Rows */
.button-row {
    display: flex;
    gap: 0.6rem;
    margin-top: 0.3rem;
}

.action-btn {
    flex: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.65rem 0.9rem;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 700;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.2s ease;
    min-height: 40px;
    touch-action: manipulation;
}

.primary-btn {
    background: var(--primary-color);
    color: #ffffff;
}

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

.secondary-btn {
    background: #ffffff;
    border-color: var(--border-color);
    color: #334155;
}

.secondary-btn:hover {
    background: #f8fafc;
    border-color: #94a3b8;
}

/* Presets & Chips */
.preset-box {
    margin-top: 0.4rem;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.preset-label {
    font-size: 0.78rem;
    font-weight: 700;
    color: #64748b;
    text-transform: uppercase;
}

.preset-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
}

.chip-btn {
    background: #f1f5f9;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    padding: 0.35rem 0.6rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: #334155;
    cursor: pointer;
    transition: all 0.15s ease;
    touch-action: manipulation;
}

.chip-btn:hover {
    background: #e2e8f0;
    color: #0f172a;
}

.chip-btn.active {
    background: #dbeafe;
    border-color: #93c5fd;
    color: #1e40af;
    font-weight: 700;
}

/* Toggle Switches */
.toggle-group {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.35rem 0;
    min-height: 44px;
    cursor: pointer;
}

.toggle-switch {
    position: relative;
    display: inline-block;
    width: 42px;
    height: 24px;
    flex-shrink: 0;
    touch-action: manipulation;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider.round {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: #cbd5e1;
    transition: .3s;
    border-radius: 34px;
}

.slider.round:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .3s;
    border-radius: 50%;
}

input:checked + .slider.round {
    background-color: var(--primary-color);
}

input:checked + .slider.round:before {
    transform: translateX(18px);
}

.toggle-label {
    font-size: 0.82rem;
    font-weight: 600;
    color: #334155;
    cursor: pointer;
    line-height: 1.35;
}

/* NCERT Ex 5.2 Preset Grid */
.ncert-presets-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.45rem;
}

@media (max-width: 540px) {
    .ncert-presets-grid {
        grid-template-columns: 1fr;
        gap: 0.45rem;
    }
}

.ncert-preset-btn {
    background: #f8fafc;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    padding: 0.55rem 0.65rem;
    font-size: 0.76rem;
    color: #334155;
    cursor: pointer;
    text-align: left;
    transition: all 0.2s ease;
    line-height: 1.35;
    min-height: 42px;
    touch-action: manipulation;
}

.ncert-preset-btn:hover {
    background: #f1f5f9;
    border-color: #94a3b8;
}

.ncert-preset-btn.active {
    background: #eff6ff;
    border-color: #3b82f6;
    color: #1e3a8a;
    box-shadow: 0 1px 3px rgba(37, 99, 235, 0.15);
}

/* Work Calculation Box */
.work-calc-box {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 0.75rem;
}

.calc-box-title {
    font-size: 0.8rem;
    font-weight: 700;
    color: #1e293b;
    margin-bottom: 0.5rem;
}

.work-inputs-row {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

@media (max-width: 540px) {
    .work-inputs-row {
        flex-wrap: wrap;
        gap: 0.6rem;
    }
    .work-inputs-row .calc-cta {
        flex: 1 1 100%;
        min-height: 42px;
        margin-top: 0.2rem;
    }
}

.work-inputs-row div {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: #475569;
}

.work-inputs-row input[type="number"] {
    width: 60px;
    padding: 0.35rem 0.4rem;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    font-size: 0.8rem;
    font-weight: 700;
}

.calc-cta {
    padding: 0.45rem 0.75rem;
    background: var(--primary-color);
    color: #ffffff;
    border-color: var(--primary-color);
    border-radius: 6px;
    font-weight: 700;
    cursor: pointer;
    touch-action: manipulation;
    transition: all 0.2s ease;
}

.calc-cta:hover {
    background: var(--primary-hover);
    color: #ffffff;
}

.work-result-display {
    font-size: 0.78rem;
    font-family: 'Consolas', monospace;
    color: #0f766e;
    background: #f0fdfa;
    border: 1px solid #ccfbf1;
    border-radius: 6px;
    padding: 0.4rem 0.6rem;
    line-height: 1.4;
}

/* Analogy Table Styling */
.analogy-table-wrapper {
    overflow-x: auto;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    margin-top: 0.5rem;
    user-select: text;
    -webkit-user-select: text;
}

.analogy-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.76rem;
    text-align: left;
}

.analogy-table th {
    background: #f1f5f9;
    padding: 0.5rem 0.6rem;
    font-weight: 700;
    color: #1e293b;
    border-bottom: 2px solid #cbd5e1;
}

.analogy-table td {
    padding: 0.45rem 0.6rem;
    border-bottom: 1px solid #f1f5f9;
    color: #334155;
    vertical-align: middle;
}

@media (max-width: 600px) {
    .analogy-table th, .analogy-table td {
        padding: 0.4rem 0.4rem;
        font-size: 0.72rem;
    }
}

.analogy-table tr:hover td {
    background: #f8fafc;
}

/* Visualizer Panel */
.visualizer-panel {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
    align-items: stretch;
}

/* Status Banner Badge */
#status-badge {
    width: 100%;
    min-height: 34px;
    height: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 0.45rem 0.85rem;
    font-size: 0.78rem;
    font-weight: 700;
    line-height: 1.35;
    white-space: normal;
    word-break: break-word;
    overflow-wrap: break-word;
    box-sizing: border-box;
    border-radius: 8px;
    background: #eff6ff;
    color: #1e40af;
    border: 1px solid #bfdbfe;
}

.info-pulse {
    border-color: #93c5fd;
}

/* Canvas Container */
.canvas-container {
    position: relative;
    background: #ffffff;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

#simCanvas {
    display: block;
    width: 100%;
    height: auto;
    aspect-ratio: 700 / 480;
    touch-action: none;
    cursor: grab;
}

#simCanvas:active {
    cursor: grabbing;
}

@media (max-width: 600px) {
    #simCanvas {
        max-height: 48vh;
        aspect-ratio: 4 / 3;
    }
}

.gesture-overlay {
    position: absolute;
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(15, 23, 42, 0.85);
    color: #f8fafc;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.35rem 0.75rem;
    border-radius: 20px;
    pointer-events: none;
    transition: opacity 0.5s ease;
    backdrop-filter: blur(4px);
    white-space: nowrap;
}

/* Pinned Telemetry Stats Bar */
.stats-bar {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.6rem;
    background: #ffffff;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 0.7rem 0.9rem;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.03);
}

@media (max-width: 820px) {
    .stats-bar {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 480px) {
    .stats-bar {
        grid-template-columns: 1fr;
    }
}

.stat-item {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.stat-label {
    font-size: 0.72rem;
    font-weight: 700;
    color: #64748b;
    letter-spacing: 0.03em;
}

.stat-data {
    font-family: 'Consolas', monospace;
    font-size: 0.96rem;
    font-weight: 700;
    color: #0f172a;
}

.stat-data.highlight {
    color: var(--primary-color);
}

/* Auxiliary Dynamic Plot Card */
.plot-card {
    background: #ffffff;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 0.75rem 0.9rem;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.plot-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.plot-title {
    font-size: 0.78rem;
    font-weight: 700;
    color: #334155;
}

.plot-legend {
    display: flex;
    gap: 0.4rem;
}

.legend-badge {
    font-size: 0.68rem;
    font-weight: 700;
    padding: 0.15rem 0.45rem;
    border-radius: 4px;
}

.badge-theta {
    background: #dbeafe;
    color: #1d4ed8;
    border: 1px solid #bfdbfe;
}

.badge-omega {
    background: #fef3c7;
    color: #b45309;
    border: 1px solid #fde68a;
}

.badge-shm {
    background: #f1f5f9;
    color: #64748b;
    border: 1px dashed #cbd5e1;
}

#plotCanvas {
    width: 100%;
    height: auto;
    aspect-ratio: 700 / 150;
    display: block;
    background: #f8fafc;
    border-radius: 6px;
    border: 1px solid #e2e8f0;
}

@media (max-width: 600px) {
    #plotCanvas {
        aspect-ratio: 700 / 220;
        min-height: 95px;
    }
}

/* Institutional Admission Callout Card */
.admission-card {
    background: linear-gradient(135deg, #1e3a8a, #0f172a);
    color: #ffffff;
    padding: 1.5rem 1.6rem;
    border-radius: 12px;
    margin-bottom: 1.5rem;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    gap: 1.1rem;
    border: 1px solid rgba(251, 191, 36, 0.3);
}

.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 22px 5px rgba(251, 191, 36, 0.45);
        border-color: rgba(251, 191, 36, 0.7);
    }
    100% {
        box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
        border-color: transparent;
    }
}

.promo-copy .promo-kicker {
    font-size: 0.8rem;
    color: var(--accent-gold);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.2rem;
}

.promo-copy .promo-lead {
    font-size: 0.95rem;
    color: #93c5fd;
    font-weight: 600;
}

.promo-copy .promo-headline {
    font-size: 1.35rem;
    font-weight: 800;
    color: #ffffff;
}

.program-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 0.8rem;
}

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

.program-card strong {
    font-size: 0.92rem;
    color: #ffffff;
}

.program-card span {
    font-size: 0.78rem;
    color: #cbd5e1;
}

.program-card small {
    font-size: 0.72rem;
    color: var(--accent-gold);
    font-weight: 600;
}

.promo-actions {
    display: flex;
    gap: 0.8rem;
    flex-wrap: wrap;
}

.promo-button {
    padding: 0.6rem 1.2rem;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 700;
    text-decoration: none;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.main-cta {
    background: var(--accent-gold);
    color: #0f172a;
}

.main-cta:hover {
    background: #d97706;
}

.sub-cta {
    background: rgba(255, 255, 255, 0.15);
    color: #ffffff;
    border: 1px solid rgba(255, 255, 255, 0.25);
}

.sub-cta:hover {
    background: rgba(255, 255, 255, 0.25);
}

/* Dedicated Theory & NCERT Concept Box */
.concepts-box {
    background: #ffffff;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.02);
    user-select: text;
    -webkit-user-select: text;
}

.theory-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1.5rem;
}

.theory-col h3 {
    font-size: 0.95rem;
    color: #1e3a8a;
    font-weight: 800;
    margin-bottom: 0.5rem;
    border-bottom: 2px solid #e2e8f0;
    padding-bottom: 0.35rem;
}

.theory-col p {
    font-size: 0.84rem;
    color: #475569;
    line-height: 1.5;
    margin-bottom: 0.5rem;
}

.concept-list {
    list-style-type: disc;
    padding-left: 1.2rem;
    font-size: 0.82rem;
    color: #334155;
    line-height: 1.5;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

/* Feedback Channel Card */
.feedback-card {
    background: #f8fafc;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 1.2rem 1.4rem;
    margin-bottom: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}

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

.feedback-icon {
    color: #0284c7;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

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

.feedback-text p {
    font-size: 0.8rem;
    color: #64748b;
}

.feedback-btn {
    padding: 0.5rem 1rem;
    background: #ffffff;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: #0284c7;
    font-size: 0.82rem;
    font-weight: 700;
    text-decoration: none;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.feedback-btn:hover {
    background: #f0f9ff;
    border-color: #7dd3fc;
    color: #0369a1;
}

/* Standard Series Footer */
.series-footer {
    text-align: center;
    font-size: 0.8rem;
    color: #94a3b8;
    padding: 1rem 0;
    border-top: 1px solid var(--border-color);
}

.hidden {
    display: none !important;
}
