/* ── PhET Scaling Base ───────────────────────────────────── */
html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

/* PhET Stage — scalable container */
#phet-stage {
    position: absolute;
    top: 0;
    left: 0;
    transform-origin: top left;
    overflow-y: auto;
    background: #020617;
    display: flex;
    flex-direction: column;
}

@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;
}

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

body.sim-page {
    font-family: 'Outfit', sans-serif;
    background: var(--bg);
    color: var(--text);
    overflow: hidden;
    height: 100%;
    touch-action: none;
    overscroll-behavior: none;
}

/* NAV */
.mem-nav {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.55rem 1.5rem;
    background: rgba(15, 23, 42, 0.9);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
}

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

/* MAIN */
.mem-main {
    padding: 80px 40px 40px;
    width: 100%;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    position: relative;
    overflow-y: visible; /* Let the stage handle scrolling or keep it fit */
}

/* ══ WHAT IS THIS Banner ══ */
.what-is-this {
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.12), rgba(168, 85, 247, 0.08));
    border: 1px solid rgba(59, 130, 246, 0.25);
    border-radius: 16px;
    padding: 0.9rem 1.2rem;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.wit-icon {
    font-size: 2rem;
    flex-shrink: 0;
}

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

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

.wit-text em {
    color: var(--cyan);
    font-style: normal;
}

.guided-btn {
    background: linear-gradient(135deg, var(--blue), var(--purple));
    color: #fff;
    border: none;
    padding: 0.5rem 1.2rem;
    border-radius: 10px;
    font-size: 0.82rem;
    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 20px rgba(59, 130, 246, 0.3);
}

/* TOP BAR */
.top-bar {
    display: flex;
    align-items: center;
    gap: 1rem;
    background: rgba(30, 41, 59, 0.5);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 0.6rem 1rem;
    flex-wrap: wrap;
}

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

.strategy-group,
.add-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

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

.strat-btn:hover {
    border-color: var(--cyan);
    color: var(--cyan);
}

.strat-btn.active {
    background: var(--cyan);
    border-color: var(--cyan);
    color: #020617;
}

#proc-name {
    background: rgba(2, 6, 23, 0.5);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.28rem 0.6rem;
    color: var(--text);
    font-family: inherit;
    font-size: 0.82rem;
    width: 110px;
}

#proc-size {
    background: rgba(2, 6, 23, 0.5);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.28rem 0.6rem;
    color: var(--text);
    font-family: inherit;
    font-size: 0.82rem;
    width: 140px;
}

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

.action-btn.primary {
    background: var(--blue);
    color: #fff;
}

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

.action-btn.danger {
    background: rgba(248, 113, 113, 0.1);
    color: var(--red);
    border: 1px solid rgba(248, 113, 113, 0.3);
    margin-left: auto;
}

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

/* MAIN LAYOUT */
.mem-layout {
    display: grid;
    grid-template-columns: 1fr 320px;
    gap: 0.8rem;
    align-items: start;
}

/* PANEL COMMON */
.panel-box {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 0.9rem;
    backdrop-filter: blur(10px);
}

.panel-title {
    font-size: 0.72rem;
    font-weight: 800;
    color: var(--cyan);
    text-transform: uppercase;
    letter-spacing: 1px;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.6rem;
}

/* RAM PANEL */
.ram-panel {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 0.9rem;
    backdrop-filter: blur(10px);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.frag-badge {
    background: rgba(251, 191, 36, 0.15);
    color: var(--amber);
    padding: 0.1rem 0.5rem;
    border-radius: 6px;
    font-size: 0.65rem;
    font-weight: 700;
    animation: pulse-badge 1.5s infinite alternate;
}

@keyframes pulse-badge {
    from {
        opacity: 0.7;
    }

    to {
        opacity: 1;
    }
}

.ram-bar-wrap {
    flex: 1;
    display: flex;
    flex-direction: column;
    margin-bottom: 0.5rem;
}

.ram-bar {
    display: flex;
    border-radius: 10px;
    overflow: hidden;
    border: 1px solid var(--border);
    flex: 1;
    min-height: 80px;
    margin-bottom: 0.3rem;
}

.mem-block {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    min-width: 2px;
    position: relative;
}

.mem-block.free {
    background: rgba(255, 255, 255, 0.03);
    border-right: 1px dashed rgba(255, 255, 255, 0.07);
}

.mem-block.free.frag {
    background: rgba(251, 191, 36, 0.06);
    border-right: 1px dashed rgba(251, 191, 36, 0.2);
}

.block-label {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.68rem;
    font-weight: 700;
    color: rgba(0, 0, 0, 0.75);
    text-align: center;
    line-height: 1.2;
    pointer-events: none;
}

.block-size-lbl {
    font-size: 0.55rem;
    opacity: 0.7;
}

.ram-scale {
    display: flex;
    justify-content: space-between;
    font-size: 0.6rem;
    color: var(--muted);
    font-family: 'JetBrains Mono', monospace;
}

.legend {
    display: flex;
    gap: 1rem;
    margin: 0.5rem 0;
    flex-wrap: wrap;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.72rem;
    color: var(--muted);
}

.dot {
    width: 12px;
    height: 12px;
    border-radius: 3px;
}

.dot.free {
    background: rgba(255, 255, 255, 0.06);
    border: 1px dashed rgba(255, 255, 255, 0.2);
}

.dot.allocated {
    background: var(--blue);
}

.dot.frag-dot {
    background: rgba(251, 191, 36, 0.3);
    border: 1px dashed rgba(251, 191, 36, 0.4);
}

.stats-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.stat-box {
    background: rgba(2, 6, 23, 0.4);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.5rem;
    text-align: center;
}

.stat-val {
    font-family: 'JetBrains Mono', monospace;
    font-size: 1rem;
    font-weight: 700;
    color: var(--cyan);
}

.stat-lbl {
    font-size: 0.6rem;
    color: var(--muted);
    margin-top: 2px;
}

/* Real-time explain */
.realtime-explain {
    margin-top: 0.8rem;
}

.explain-body {
    font-size: 0.82rem;
    color: #cbd5e1;
    line-height: 1.6;
}

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

.explain-body .highlight {
    color: var(--cyan);
    font-weight: 700;
}

/* Why Panel */
.why-panel {
    margin-top: 0.8rem;
}

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

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

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

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

.why-section {
    display: none;
}

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

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

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

.mini-ram-example {
    display: flex;
    height: 36px;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--border);
    margin: 0.4rem 0;
}

.strat-explain {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.se-item {
    background: rgba(2, 6, 23, 0.4);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.6rem;
}

.se-title {
    font-size: 0.78rem;
    font-weight: 800;
    margin-bottom: 0.2rem;
}

.se-title.cyan {
    color: var(--cyan);
}

.se-title.purple {
    color: var(--purple);
}

.se-title.amber {
    color: var(--amber);
}

.se-desc {
    font-size: 0.75rem;
    color: #94a3b8;
    line-height: 1.4;
}

.se-desc em {
    color: var(--muted);
    font-style: italic;
}

.real-examples {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: 0.4rem;
}

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

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

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

/* LEFT COL */
.left-col {
    display: flex;
    flex-direction: column;
}

/* RIGHT PANEL */
.right-panel {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    position: sticky;
    top: 70px;
}

/* Strategy Card */
.strat-card {
    display: flex;
    gap: 0.8rem;
    align-items: center;
    background: linear-gradient(135deg, rgba(34, 211, 238, 0.06), rgba(59, 130, 246, 0.06));
    border-color: rgba(34, 211, 238, 0.2);
}

.strat-icon {
    font-size: 1.8rem;
}

.strat-card-title {
    font-size: 0.82rem;
    font-weight: 800;
    color: var(--cyan);
    margin-bottom: 0.2rem;
}

.strat-card-desc {
    font-size: 0.75rem;
    color: #94a3b8;
    line-height: 1.4;
}

.strat-card-desc strong {
    color: var(--text);
}

/* Proc table */
.proc-head {
    display: grid;
    grid-template-columns: 2fr 2fr 2fr 1fr;
    font-size: 0.6rem;
    font-weight: 800;
    color: var(--muted);
    letter-spacing: 1px;
    text-transform: uppercase;
    padding: 0.2rem 0.4rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: 0.3rem;
}

.proc-row {
    display: grid;
    grid-template-columns: 2fr 2fr 2fr 1fr;
    font-size: 0.76rem;
    padding: 0.3rem 0.4rem;
    border-radius: 6px;
    align-items: center;
}

.proc-row:hover {
    background: rgba(255, 255, 255, 0.03);
}

.proc-name-cell {
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.proc-color-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.free-btn {
    background: rgba(248, 113, 113, 0.1);
    border: 1px solid rgba(248, 113, 113, 0.3);
    color: var(--red);
    border-radius: 5px;
    padding: 0.12rem 0.4rem;
    font-size: 0.68rem;
    cursor: pointer;
    transition: 0.2s;
    font-family: inherit;
}

.free-btn:hover {
    background: rgba(248, 113, 113, 0.25);
}

.empty-msg {
    font-size: 0.75rem;
    color: var(--muted);
    text-align: center;
    padding: 0.8rem;
    font-style: italic;
}

/* LOG */
.log-body {
    overflow-y: auto;
    max-height: 150px;
    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.7rem;
    font-family: 'JetBrains Mono', monospace;
    padding: 0.18rem 0.4rem;
    border-radius: 4px;
    margin-bottom: 2px;
    line-height: 1.4;
}

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

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

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

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

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

@keyframes demo-slide-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: 1px solid rgba(34, 211, 238, 0.3);
    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(--cyan);
    letter-spacing: 1px;
    text-transform: uppercase;
    margin-bottom: 0.3rem;
}

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

.demo-body {
    font-size: 0.82rem;
    color: #94a3b8;
    line-height: 1.6;
    margin-bottom: 0.9rem;
}

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

.demo-body .hl-cyan {
    color: var(--cyan);
    font-weight: 700;
}

.demo-body .hl-green {
    color: var(--green);
    font-weight: 700;
}

.demo-body .hl-amber {
    color: var(--amber);
    font-weight: 700;
}

.demo-body .hl-red {
    color: var(--red);
    font-weight: 700;
}

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

/* Mobile responsiveness handled by PhET Scaling Engine */

/* ══ INFO BUTTON (in nav) ══ */
.info-nav-btn {
    background: linear-gradient(135deg, rgba(34, 211, 238, 0.15), rgba(59, 130, 246, 0.15));
    border: 1px solid rgba(34, 211, 238, 0.35);
    color: var(--cyan);
    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(--cyan);
    color: #020617;
    transform: translateY(-1px);
}

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

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

@keyframes modal-fade-in {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

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

@keyframes modal-slide-up {
    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.1rem;
    font-weight: 800;
    color: var(--text);
}

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

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

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