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

:root {
    --bg: #030a1a;
    --panel: rgba(5, 15, 40, 0.92);
    --border: rgba(255,255,255,0.07);
    --blue: #3b82f6;
    --blue-lt: #60a5fa;
    --blue-glow: rgba(59,130,246,0.15);
    --orange: #f97316;
    --teal: #06b6d4;
    --purple: #a855f7;
    --green: #10b981;
    --red: #ef4444;
    --text: #f1f5f9;
    --muted: #64748b;
}
#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;
}

body.ionic-page {
    font-family: 'Outfit', sans-serif;
    background: var(--bg);
    margin: 0;
    padding: 0;
    overflow: hidden;
}

body.ionic-page::before {
    content: '';
    position: fixed; inset: 0;
    background:
        radial-gradient(ellipse 55% 45% at 10% 20%, rgba(59,130,246,0.08) 0%, transparent 65%),
        radial-gradient(ellipse 50% 60% at 90% 75%, rgba(249,115,22,0.06) 0%, transparent 65%);
    pointer-events: none; z-index: 0;
}

/* NAV */
.ionic-nav {
    position: relative !important;
    display: flex; align-items: center; justify-content: space-between;
    padding: 0.55rem 1.4rem;
    background: rgba(3,10,26,0.94); backdrop-filter: blur(18px);
    border-bottom: 1px solid var(--border);
    z-index: 300;
}
.ionic-nav .logo { font-size: 1rem; font-weight: 800; }
.nav-crumb { font-size: 0.78rem; color: #94a3b8; display: flex; align-items: center; gap: 0.5rem; }
.nav-crumb strong { color: var(--text); }
.crumb-sep { opacity: 0.3; }
.nav-right { display: flex; gap: 0.6rem; align-items: center; }
.back-btn {
    border-radius: 50px; padding: 0.32rem 0.9rem; font-size: 0.78rem;
    color: #94a3b8; border: 1px solid rgba(255,255,255,0.1);
    text-decoration: none; display: flex; align-items: center; gap: 0.4rem; transition: 0.2s;
}
.back-btn:hover { border-color: var(--blue); color: var(--blue); }

/* MAIN */
.ionic-main {
    flex: 1;
    padding: 6px 14px 10px;
    display: flex; flex-direction: column;
    gap: 0.45rem; position: relative; z-index: 1;
    overflow: hidden;
}

/* TOP BAR */
.top-bar {
    background: linear-gradient(135deg, rgba(5,15,40,0.95), rgba(59,130,246,0.06));
    border: 1px solid rgba(59,130,246,0.2); border-radius: 14px;
    padding: 0.7rem 1.2rem; display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
}
.top-bar h1 { font-size: 1.1rem; font-weight: 800; color: var(--text); }
.phase-badge {
    padding: 0.22rem 0.75rem; border-radius: 20px; font-size: 0.7rem; font-weight: 700;
    background: rgba(59,130,246,0.12); border: 1px solid rgba(59,130,246,0.3); color: var(--blue);
}

/* TABS */
.tab-row {
    display: flex; gap: 0.4rem; flex-wrap: wrap;
    background: rgba(5,15,40,0.7); border: 1px solid var(--border);
    border-radius: 12px; padding: 0.4rem;
}
.tab-btn {
    background: transparent; border: 1px solid transparent;
    color: var(--muted); padding: 0.45rem 1.1rem; border-radius: 9px;
    font-size: 0.78rem; font-weight: 700; cursor: pointer; transition: 0.2s; font-family: inherit;
    display: flex; align-items: center; gap: 0.4rem;
}
.tab-btn:hover { color: var(--blue); border-color: rgba(59,130,246,0.3); }
.tab-btn.active { background: rgba(59,130,246,0.15); border-color: rgba(59,130,246,0.4); color: var(--blue); }

/* LAYOUT */
.ionic-layout {
    display: grid;
    grid-template-columns: 240px 1fr 240px;
    gap: 0.55rem; 
    align-items: stretch;
    flex: 1;
    min-height: 0;
}

.left-panel, .center-panel, .right-panel {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
}
.right-panel { 
    gap: 0.1rem; 
    overflow-y: auto;
    overflow-x: hidden;
    padding-right: 4px; /* Space for scrollbar */
    scrollbar-width: thin;
    scrollbar-color: rgba(59,130,246,0.3) transparent;
}

/* Custom Scrollbar for Right Panel */
.right-panel::-webkit-scrollbar {
    width: 4px;
}
.right-panel::-webkit-scrollbar-track {
    background: transparent;
}
.right-panel::-webkit-scrollbar-thumb {
    background: rgba(59,130,246,0.25);
    border-radius: 10px;
}
.right-panel::-webkit-scrollbar-thumb:hover {
    background: var(--blue);
}

.center-panel { gap: 0.4rem; }

.panel-box {
    background: var(--panel); border: 1px solid var(--border);
    border-radius: 11px; padding: 0.45rem 0.75rem;
    backdrop-filter: blur(14px); margin-bottom: 0.45rem;
}
.panel-title {
    font-size: 0.62rem; font-weight: 800; text-transform: uppercase;
    letter-spacing: 0.7px; color: var(--muted);
    display: flex; align-items: center; gap: 0.35rem; margin-bottom: 0.45rem;
}
.panel-title .pt-icon { font-size: 0.8rem; }

/* COMPOUND PILLS SELECTOR */
.compound-pills {
    display: flex; gap: 0.3rem; flex-wrap: wrap;
}
.compound-pill {
    display: flex; align-items: center; gap: 0.35rem;
    padding: 0.25rem 0.65rem; border-radius: 30px;
    border: 1px solid var(--border); cursor: pointer; transition: 0.2s;
    background: rgba(255,255,255,0.03); font-family: inherit;
    font-size: 0.65rem; font-weight: 700; color: var(--muted);
}
.compound-pill:hover { border-color: var(--blue); color: var(--blue); background: rgba(59,130,246,0.06); }
.compound-pill.active {
    background: rgba(59,130,246,0.15); border-color: var(--blue); color: var(--blue-lt);
}
.compound-pill .pill-formula {
    font-family: 'JetBrains Mono', monospace; font-size: 0.72rem; font-weight: 700;
}
.compound-pill .pill-name {
    font-size: 0.58rem; color: inherit; opacity: 0.75;
}
.compound-pill .pill-emoji { font-size: 0.85rem; }

/* ATOM CARDS (color overrides applied via JS) */
.atom-card {
    border-radius: 10px; padding: 0.45rem; text-align: center;
    border: 1px solid; margin-bottom: 0.35rem; position: relative; overflow: hidden;
}
.atom-card.sodium { background: rgba(249,115,22,0.08); border-color: rgba(249,115,22,0.3); }
.atom-card.chlorine { background: rgba(59,130,246,0.08); border-color: rgba(59,130,246,0.3); }
.atom-symbol { font-size: 1.5rem; font-weight: 900; font-family: 'JetBrains Mono', monospace; line-height: 1; }
.atom-card.sodium .atom-symbol { color: var(--orange); }
.atom-card.chlorine .atom-symbol { color: var(--blue); }
.atom-name-row { font-size: 0.65rem; color: #94a3b8; margin-top: 0.15rem; }
.atom-props { margin-top: 0.4rem; display: flex; flex-direction: column; gap: 0.1rem; }
.atom-prop { display: flex; justify-content: space-between; font-size: 0.62rem; }
.atom-prop .lbl { color: var(--muted); }
.atom-prop .val { font-weight: 700; font-family: 'JetBrains Mono', monospace; }
.atom-card.sodium .val { color: var(--orange); }
.atom-card.chlorine .val { color: var(--blue); }

/* CONFIG DISPLAY */
.config-display {
    font-family: 'JetBrains Mono', monospace; font-size: 0.65rem;
    background: rgba(255,255,255,0.03); border: 1px solid var(--border);
    border-radius: 7px; padding: 0.3rem 0.6rem; color: #94a3b8;
    margin-top: 0.25rem; letter-spacing: 0.5px; text-align: center;
}

/* ENERGY LEVEL */
.energy-bar-wrap { margin-top: 0.3rem; }
.energy-label { font-size: 0.6rem; color: var(--muted); display: flex; justify-content: space-between; margin-bottom: 0.15rem; }
.energy-bar { height: 4px; border-radius: 4px; background: rgba(255,255,255,0.06); overflow: hidden; }
.energy-bar .fill { height: 100%; border-radius: 4px; transition: width 0.8s ease; }
.sodium-fill { background: linear-gradient(90deg, #f97316, #fb923c); }
.chlorine-fill { background: linear-gradient(90deg, #3b82f6, #60a5fa); }

/* CANVAS */
.canvas-wrap {
    background: rgba(2,6,20,0.85); border: 1px solid rgba(59,130,246,0.15);
    border-radius: 12px; overflow: hidden; position: relative;
    cursor: grab; user-select: none;
}
.canvas-wrap:active { cursor: grabbing; }
#ionic-canvas { display: block; width: 100%; height: auto; }
.canvas-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 0.25rem;
}
.canvas-title { font-size: 0.85rem; font-weight: 800; }
.phase-tag {
    background: rgba(59,130,246,0.12); border: 1px solid rgba(59,130,246,0.3);
    color: var(--blue); padding: 0.12rem 0.55rem; border-radius: 20px;
    font-size: 0.65rem; font-weight: 700;
}

.controls-row {
    display: flex; gap: 0.4rem; flex-wrap: wrap;
    margin-top: 0.3rem; justify-content: center;
}
.ctrl-btn {
    background: rgba(255,255,255,0.04); border: 1px solid var(--border);
    color: var(--muted); padding: 0.3rem 0.65rem; border-radius: 7px;
    font-size: 0.65rem; font-weight: 700; cursor: pointer;
    transition: 0.2s; font-family: inherit;
    display: flex; align-items: center; gap: 0.3rem;
}
.ctrl-btn:hover { border-color: var(--blue); color: var(--blue); }
.ctrl-btn.primary-btn {
    background: rgba(59,130,246,0.15); border-color: rgba(59,130,246,0.4); color: var(--blue);
}
.ctrl-btn.primary-btn:hover { background: var(--blue); color: #030a1a; }

/* FACT BAR */
.fact-bar {
    background: linear-gradient(135deg, rgba(5,15,40,0.94), rgba(59,130,246,0.06));
    border: 1px solid rgba(59,130,246,0.2); border-radius: 10px;
    padding: 0.5rem 0.75rem; display: flex; align-items: center; gap: 0.6rem;
    margin-top: 0.3rem;
}
.fact-icon { font-size: 1.1rem; flex-shrink: 0; }
.fact-text { font-size: 0.68rem; color: #94a3b8; line-height: 1.45; }
.fact-text strong { color: var(--blue); }

/* RIGHT PANEL */
.info-card {
    background: rgba(5,15,40,0.7); border: 1px solid var(--border);
    border-radius: 11px; padding: 0.75rem 0.85rem; margin-bottom: 0.55rem;
}
.info-card h4 { font-size: 0.72rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted); margin-bottom: 0.45rem; }

.prop-row { display: flex; justify-content: space-between; align-items: center; padding: 0.2rem 0; border-bottom: 1px solid rgba(255,255,255,0.04); font-size: 0.65rem; }
.prop-row:last-child { border-bottom: none; }
.prop-label { color: var(--muted); }
.prop-val { font-weight: 700; font-family: 'JetBrains Mono', monospace; color: var(--blue); }

.step-list { display: flex; flex-direction: column; gap: 0.3rem; }
.step-item { display: flex; gap: 0.4rem; align-items: flex-start; font-size: 0.62rem; color: #94a3b8; line-height: 1.45; }
.step-num {
    background: rgba(59,130,246,0.12); color: var(--blue);
    border: 1px solid rgba(59,130,246,0.3); border-radius: 50%;
    width: 20px; height: 20px; min-width: 20px;
    display: flex; align-items: center; justify-content: center;
    font-size: 0.58rem; font-weight: 800; flex-shrink: 0; margin-top: 1px;
}
.step-item strong { color: var(--text); }
.step-item em { color: var(--blue); font-style: normal; font-weight: 700; }

.highlight-box {
    background: rgba(59,130,246,0.07); border-left: 3px solid var(--blue);
    border-radius: 6px; padding: 0.45rem 0.6rem; font-size: 0.65rem;
    color: #93c5fd; line-height: 1.45; margin-top: 0.3rem;
}

/* LEARN MODAL */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(3,10,26,0.92);
    backdrop-filter: blur(14px); z-index: 1000;
    display: flex; align-items: center; justify-content: center;
    padding: 1rem; animation: mfade 0.2s ease;
}
.modal-overlay.hidden { display: none; }
@keyframes mfade { from{opacity:0}to{opacity:1} }
.modal-box {
    background: linear-gradient(145deg, #050f28, #030a1a);
    border: 1px solid rgba(59,130,246,0.25); border-radius: 22px;
    padding: 1.6rem; width: 100%; max-width: 640px; max-height: 88vh;
    overflow-y: auto; position: relative;
    box-shadow: 0 35px 90px rgba(0,0,0,0.8);
    animation: mslide 0.28s cubic-bezier(0.175,0.885,0.32,1.275);
}
@keyframes mslide { from{transform:translateY(22px);opacity:0}to{transform:translateY(0);opacity:1} }
.modal-close {
    position: absolute; top: 0.9rem; right: 0.9rem;
    background: rgba(255,255,255,0.05); border: 1px solid var(--border);
    color: var(--muted); width: 30px; height: 30px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; font-size: 0.8rem; transition: 0.2s;
}
.modal-close:hover { background: var(--red); color: #fff; border-color: var(--red); }
.modal-title { font-size: 1.1rem; font-weight: 800; color: var(--text); margin-bottom: 0.3rem; }
.modal-sub { font-size: 0.72rem; color: var(--muted); margin-bottom: 1rem; }

.learn-section-content { font-size: 0.8rem; color: #94a3b8; line-height: 1.7; }
.learn-section-content h3 { font-size: 0.9rem; color: var(--blue); margin: 0.9rem 0 0.4rem; }
.learn-section-content ul { padding-left: 1.2rem; }
.learn-section-content li { margin-bottom: 0.35rem; }
.learn-section-content strong { color: var(--text); }
.learn-section-content em { color: var(--blue); font-style: normal; font-weight: 700; }

@media(max-width: 480px) {
    .canvas-title { font-size: 0.9rem; }
}
