@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;700&family=Outfit:wght@400;600;700;800&display=swap');

:root {
    --bg: #020617;
    --panel: rgba(15, 23, 42, 0.75);
    --border: rgba(255, 255, 255, 0.07);
    --cyan: #22d3ee;
    --blue: #3b82f6;
    --purple: #a855f7;
    --green: #4ade80;
    --amber: #fbbf24;
    --red: #f87171;
    --text: #f8fafc;
    --muted: #64748b;
}

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

body.sim-page {
    font-family: 'Outfit', sans-serif;
    color: var(--text);
    margin: 0;
    padding: 0;
    overflow: hidden;
    background: #0f172a;
}

/* NAV */
.sf-nav {
    position: relative !important;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.55rem 1.5rem;
    background: rgba(15, 23, 42, 0.92);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    z-index: 200;
}

.logo {
    font-size: 1rem;
    font-weight: 800;
}

/* NAV INFO BTN */
.info-nav-btn {
    background: linear-gradient(135deg, rgba(168, 85, 247, 0.15), rgba(59, 130, 246, 0.12));
    border: 1px solid rgba(168, 85, 247, 0.35);
    color: var(--purple);
    padding: 0.35rem 1rem;
    border-radius: 50px;
    font-size: 0.8rem;
    font-weight: 700;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    transition: 0.2s;
    font-family: inherit;
}

.info-nav-btn:hover {
    background: var(--purple);
    color: #fff;
    transform: translateY(-1px);
}

/* MAIN */
.sf-main {
    padding: 10px 16px 20px;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    overflow: hidden;
}

/* ANALOGY BANNER */
.analogy-banner {
    background: linear-gradient(135deg, rgba(168, 85, 247, 0.1), rgba(59, 130, 246, 0.08));
    border: 1px solid rgba(168, 85, 247, 0.3);
    border-radius: 18px;
    padding: 1rem 1.4rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.analogy-icon {
    font-size: 2.5rem;
    flex-shrink: 0;
}

.analogy-text {
    flex: 1;
    font-size: 0.9rem;
    color: #cbd5e1;
    line-height: 1.6;
    min-width: 200px;
}

.analogy-text strong {
    color: var(--text);
}

.analogy-text em {
    color: var(--purple);
    font-style: normal;
    font-weight: 700;
}

.guided-btn {
    background: linear-gradient(135deg, var(--purple), var(--blue));
    color: #fff;
    border: none;
    padding: 0.6rem 1.3rem;
    border-radius: 12px;
    font-size: 0.85rem;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: 0.3s;
    flex-shrink: 0;
    font-family: inherit;
}

.guided-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(168, 85, 247, 0.35);
}

/* PROGRAM SELECTOR */
.prog-selector {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
    background: rgba(30, 41, 59, 0.4);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 0.6rem 1rem;
}

.prog-label {
    font-size: 0.72rem;
    font-weight: 800;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    white-space: nowrap;
}

.prog-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--muted);
    padding: 0.3rem 0.9rem;
    border-radius: 9px;
    font-size: 0.82rem;
    font-weight: 700;
    cursor: pointer;
    transition: 0.2s;
    font-family: inherit;
}

.prog-btn:hover {
    border-color: var(--purple);
    color: var(--purple);
}

.prog-btn.active {
    background: var(--purple);
    border-color: var(--purple);
    color: #fff;
}

/* CONTROLS */
.controls-bar {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    flex-wrap: wrap;
}

.ctrl-btn {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 1.2rem;
    border-radius: 10px;
    font-size: 0.9rem;
    font-weight: 700;
    cursor: pointer;
    border: none;
    font-family: inherit;
    transition: all 0.2s;
}

.ctrl-btn.step {
    background: var(--blue);
    color: #fff;
}

.ctrl-btn.step:hover {
    background: #2563eb;
    transform: translateY(-1px);
}

.ctrl-btn.auto {
    background: var(--green);
    color: #020617;
}

.ctrl-btn.auto:hover {
    background: #22c55e;
    transform: translateY(-1px);
}

.ctrl-btn.reset {
    background: rgba(248, 113, 113, 0.1);
    color: var(--red);
    border: 1px solid rgba(248, 113, 113, 0.3);
}

.ctrl-btn.reset:hover {
    background: rgba(248, 113, 113, 0.2);
}

.step-counter {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.78rem;
    color: var(--muted);
    margin-left: auto;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border);
    padding: 0.38rem 0.9rem;
    border-radius: 8px;
}

/* SIM AREA */
.sim-area {
    display: grid;
    grid-template-columns: 1fr 280px 220px;
    gap: 0.8rem;
    align-items: start;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}
.explain-panel, .right-col {
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    height: 100%;
}
.explain-panel::-webkit-scrollbar, .right-col::-webkit-scrollbar { width: 4px; }
.explain-panel::-webkit-scrollbar-thumb, .right-col::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 10px; }

/* EXPLAIN PANEL (left) */
.explain-panel {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}

/* EVENT BADGE */
.event-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 1rem;
    border-radius: 50px;
    font-size: 0.85rem;
    font-weight: 800;
    animation: badge-pop 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    width: fit-content;
}

@keyframes badge-pop {
    from {
        transform: scale(0.7);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

.event-badge.push {
    background: rgba(168, 85, 247, 0.2);
    color: var(--purple);
    border: 1px solid rgba(168, 85, 247, 0.4);
}

.event-badge.pop {
    background: rgba(34, 211, 238, 0.15);
    color: var(--cyan);
    border: 1px solid rgba(34, 211, 238, 0.3);
}

.event-badge.info {
    background: rgba(251, 191, 36, 0.12);
    color: var(--amber);
    border: 1px solid rgba(251, 191, 36, 0.3);
}

/* BIG EXPLAIN */
.big-explain {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 1.2rem 1.4rem;
    font-size: 1rem;
    color: #e2e8f0;
    line-height: 1.7;
    backdrop-filter: blur(10px);
    min-height: 100px;
}

.big-explain strong {
    color: var(--text);
}

.big-explain .hl {
    color: var(--purple);
    font-weight: 700;
}

.big-explain .hl-g {
    color: var(--green);
    font-weight: 700;
}

.big-explain .hl-r {
    color: var(--red);
    font-weight: 700;
}

.big-explain .hl-a {
    color: var(--amber);
    font-weight: 700;
}

/* WHY BOX */
.why-box {
    background: linear-gradient(135deg, rgba(251, 191, 36, 0.08), rgba(168, 85, 247, 0.06));
    border: 1px solid rgba(251, 191, 36, 0.25);
    border-radius: 14px;
    padding: 0.8rem 1rem;
    display: flex;
    gap: 0.7rem;
    align-items: flex-start;
    animation: why-slide 0.3s ease;
}

@keyframes why-slide {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.why-icon {
    font-size: 1.5rem;
    flex-shrink: 0;
}

.why-text {
    font-size: 0.85rem;
    color: #cbd5e1;
    line-height: 1.5;
}

.why-text strong {
    color: var(--text);
}

/* CODE BOX */
.code-box {
    background: rgba(2, 6, 23, 0.5);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 0.8rem 1rem;
}

.code-box-title {
    font-size: 0.72rem;
    font-weight: 800;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 0.5rem;
}

.code-highlight {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8rem;
    color: #94a3b8;
    line-height: 1.8;
    white-space: pre-wrap;
}

/* STACK VISUAL WRAP (center) */
.stack-visual-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.4rem;
}

.stack-label {
    font-size: 0.68rem;
    font-weight: 700;
    color: var(--muted);
    text-align: center;
    letter-spacing: 0.5px;
}

/* THE STACK ITSELF */
.stack-visual {
    width: 100%;
    min-height: 360px;
    display: flex;
    flex-direction: column-reverse;
    gap: 6px;
    padding: 8px;
    background: rgba(2, 6, 23, 0.3);
    border: 1px dashed rgba(255, 255, 255, 0.1);
    border-radius: 14px;
    position: relative;
    overflow: hidden;
}

/* GROUND */
.stack-ground {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    padding: 0.4rem;
    text-align: center;
    flex-shrink: 0;
}

.ground-label {
    font-size: 0.65rem;
    color: var(--muted);
    letter-spacing: 0.5px;
}

/* STACK FRAME (box) */
.sf-frame {
    border-radius: 10px;
    padding: 0.7rem 0.9rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    border: 2px solid transparent;
    animation: frame-in 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    position: relative;
    overflow: hidden;
    transition: all 0.3s;
}

@keyframes frame-in {
    from {
        opacity: 0;
        transform: translateY(-25px) scale(0.9);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.sf-frame.top-frame {
    transform: scale(1.02);
}

.sf-frame.popping {
    animation: frame-out 0.28s ease forwards;
}

@keyframes frame-out {
    from {
        opacity: 1;
        transform: translateY(0) scale(1);
    }

    to {
        opacity: 0;
        transform: translateY(-25px) scale(0.9);
    }
}

.frame-fn {
    font-size: 1rem;
    font-weight: 800;
    letter-spacing: 0.3px;
}

.frame-detail {
    font-size: 0.75rem;
    opacity: 0.75;
    line-height: 1.4;
}

.frame-badge {
    position: absolute;
    top: 0.4rem;
    right: 0.5rem;
    font-size: 0.6rem;
    font-weight: 800;
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
    background: rgba(0, 0, 0, 0.2);
    color: rgba(255, 255, 255, 0.6);
}

.top-frame .frame-badge {
    display: none;
}

/* PUSH/POP INDICATOR */
.push-pop-indicator {
    font-size: 1.1rem;
    font-weight: 800;
    text-align: center;
    min-height: 28px;
    border-radius: 8px;
    padding: 0.2rem 0.8rem;
    transition: all 0.3s;
}

/* RIGHT COL */
.right-col {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}

.right-col::-webkit-scrollbar { width: 2px; }
.right-col::-webkit-scrollbar-thumb { background: #334155; }

/* PANEL BOX */
.panel-box {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 14px;
    backdrop-filter: blur(10px);
}

/* DEPTH PANEL */
.depth-panel {
    padding: 0.9rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.4rem;
}

.dp-title {
    font-size: 0.72rem;
    font-weight: 800;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    align-self: flex-start;
}

.depth-meter {
    width: 40px;
    height: 120px;
    background: rgba(2, 6, 23, 0.5);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    display: flex;
    align-items: flex-end;
}

.depth-fill {
    width: 100%;
    background: linear-gradient(to top, var(--purple), var(--blue));
    border-radius: 6px;
    transition: height 0.4s ease;
}

.depth-num {
    font-family: 'JetBrains Mono', monospace;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--purple);
}

.depth-max {
    font-size: 0.65rem;
    color: var(--muted);
}

/* SIMPLE LOG */
.simple-log {
    padding: 0.8rem;
    min-height: 0;
}

.log-body {
    overflow-y: auto;
    max-height: 130px;
    margin-top: 0.4rem;
    scrollbar-width: thin;
    scrollbar-color: var(--cyan) transparent;
}

.log-body::-webkit-scrollbar {
    width: 4px;
}
.log-body::-webkit-scrollbar-track {
    background: transparent;
}
.log-body::-webkit-scrollbar-thumb {
    background: rgba(34, 211, 238, 0.3);
    border-radius: 10px;
}

.log-entry {
    font-size: 0.72rem;
    font-family: 'JetBrains Mono', monospace;
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
    margin-bottom: 3px;
    line-height: 1.4;
}

.log-entry.success {
    color: var(--green);
}

.log-entry.error {
    color: var(--red);
}

.log-entry.info {
    color: var(--muted);
}

.log-entry.push {
    color: var(--purple);
}

.log-entry.pop {
    color: var(--cyan);
}

.log-entry.warn {
    color: var(--amber);
}

/* GUIDED DEMO */
.demo-overlay {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 999;
    width: 100%;
    max-width: 480px;
    padding: 0 16px;
    animation: demo-up 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes demo-up {
    from {
        transform: translateX(-50%) translateY(30px);
        opacity: 0;
    }

    to {
        transform: translateX(-50%) translateY(0);
        opacity: 1;
    }
}

.demo-card {
    background: linear-gradient(135deg, #1e293b, #0f172a);
    border: 2px solid rgba(168, 85, 247, 0.4);
    border-radius: 20px;
    padding: 1.2rem 1.5rem;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
}

.demo-step-indicator {
    font-size: 0.65rem;
    font-weight: 800;
    color: var(--purple);
    letter-spacing: 2px;
    text-transform: uppercase;
    margin-bottom: 0.3rem;
}

.demo-title {
    font-size: 1.1rem;
    font-weight: 800;
    color: var(--text);
    margin-bottom: 0.5rem;
}

.demo-body {
    font-size: 0.88rem;
    color: #94a3b8;
    line-height: 1.7;
    margin-bottom: 1rem;
}

.demo-body strong {
    color: var(--text);
}

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

/* INFO MODAL */
.info-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(2, 6, 23, 0.8);
    backdrop-filter: blur(8px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    animation: mfade 0.25s ease;
}

.info-modal-overlay.hidden {
    display: none;
}

@keyframes mfade {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.info-modal-box {
    background: linear-gradient(145deg, #1e293b, #0f172a);
    border: 1px solid rgba(168, 85, 247, 0.25);
    border-radius: 24px;
    padding: 1.8rem;
    width: 100%;
    max-width: 640px;
    max-height: 85vh;
    overflow-y: auto;
    position: relative;
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.7);
    animation: mslide 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes mslide {
    from {
        transform: translateY(30px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.info-modal-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border);
    color: var(--muted);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: 0.2s;
    font-size: 0.85rem;
}

.info-modal-close:hover {
    background: var(--red);
    color: #fff;
    border-color: var(--red);
}

.info-modal-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.2rem;
}

.info-modal-icon {
    font-size: 2.2rem;
}

.info-modal-title {
    font-size: 1.15rem;
    font-weight: 800;
    color: var(--text);
}

.info-modal-subtitle {
    font-size: 0.75rem;
    color: var(--muted);
    margin-top: 0.1rem;
}

.why-tabs {
    display: flex;
    gap: 0.4rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--border);
    padding-bottom: 0.6rem;
}

.why-tab {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--muted);
    padding: 0.3rem 0.8rem;
    border-radius: 8px;
    font-size: 0.78rem;
    font-weight: 700;
    cursor: pointer;
    transition: 0.2s;
    font-family: inherit;
}

.why-tab:hover {
    color: var(--purple);
    border-color: var(--purple);
}

.why-tab.active {
    background: var(--purple);
    border-color: var(--purple);
    color: #fff;
}

.why-section {
    display: none;
}

.why-section.active {
    display: block;
}

.why-section p {
    font-size: 0.85rem;
    color: #94a3b8;
    line-height: 1.6;
    margin-bottom: 0.6rem;
}

.why-section p strong {
    color: var(--text);
}

.why-section p code {
    font-family: 'JetBrains Mono', monospace;
    color: var(--amber);
}

/* ANALOGY INSIDE MODAL */
.modal-big-analogy {
    background: rgba(168, 85, 247, 0.07);
    border: 1px solid rgba(168, 85, 247, 0.2);
    border-radius: 14px;
    padding: 1.2rem;
    text-align: center;
    margin-bottom: 1rem;
}

.modal-big-analogy p {
    color: var(--text);
    font-size: 0.9rem;
    margin: 0;
}

/* BOX CONTENTS */
.box-contents {
    background: rgba(2, 6, 23, 0.4);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 0.8rem;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.bc-item {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    font-size: 0.82rem;
    color: #cbd5e1;
}

/* LIFO DIAGRAM */
.lifo-diagram {
    display: flex;
    flex-direction: column-reverse;
    gap: 4px;
    margin-top: 0.8rem;
    align-items: center;
}

.lifo-plate {
    padding: 0.5rem 1.5rem;
    border-radius: 8px;
    font-size: 0.75rem;
    font-weight: 700;
    width: 100%;
    text-align: center;
}

.lifo-plate.top {
    background: rgba(168, 85, 247, 0.25);
    color: var(--purple);
    border: 1px solid rgba(168, 85, 247, 0.4);
}

.lifo-plate.mid {
    background: rgba(59, 130, 246, 0.2);
    color: var(--blue);
    border: 1px solid rgba(59, 130, 246, 0.3);
}

.lifo-plate.bot {
    background: rgba(34, 211, 238, 0.15);
    color: var(--cyan);
    border: 1px solid rgba(34, 211, 238, 0.3);
}

.lifo-arrow {
    font-size: 0.72rem;
    font-weight: 800;
    color: var(--muted);
    text-align: center;
    margin-top: 0.4rem;
}

/* REAL EXAMPLES */
.real-examples {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    margin-top: 0.4rem;
}

.re-item {
    display: flex;
    align-items: flex-start;
    gap: 0.6rem;
    font-size: 0.8rem;
    color: #94a3b8;
    line-height: 1.5;
}

.re-item strong {
    color: var(--text);
}

.re-icon {
    font-size: 1.2rem;
    flex-shrink: 0;
}

.info-modal-box::-webkit-scrollbar {
    width: 3px;
}

.info-modal-box::-webkit-scrollbar-thumb {
    background: #334155;
    border-radius: 10px;
}

/* RESPONSIVE LOCK — Handled by PhET Stage Scaling Engine */
@media (max-width: 1023px) {
    #bgCanvas { background: #020617 !important; } /* Darker mobile-only background */
}
@media (max-width: 480px) {
    .analogy-icon { font-size: 1.8rem; }
    .analogy-text { font-size: 0.8rem; }
}