:root {
    --bg: #020617;
    --surface: #0f172a;
    --panel: #1e293b;
    --border: rgba(99,102,241,0.2);
    --primary: #6366f1;
    --secondary: #10b981;
    --accent: #f59e0b;
    --danger: #ef4444;
    --text: #e2e8f0;
    --muted: #94a3b8;
    --p-color: #ef4444;
    --n-color: #3b82f6;
    --glow-p: rgba(239,68,68,0.3);
    --glow-n: rgba(59,130,246,0.3);
}

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

body {
    font-family: 'Outfit', sans-serif;
    background: #000;
    color: var(--text);
    width: 100%; height: 100%;
    overflow: hidden; margin: 0; padding: 0;
}

#phet-stage {
    position: absolute; top: 0; left: 0;
    width: 1280px; height: 720px;
    background: var(--bg);
    overflow: hidden; transform-origin: 0 0;
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.4);
    touch-action: none;
    display: flex; flex-direction: column;
}

/* NAV */
.sim-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.8rem 2rem;
    background: rgba(15,23,42,0.95);
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(12px);
    z-index: 100;
    height: 60px;
    flex-shrink: 0;
}
.nav-left { display: flex; align-items: center; gap: 1.5rem; }
.sim-logo { display: flex; align-items: center; gap: 0.6rem; font-size: 1.1rem; font-weight: 700; color: #fff; }
.logo-thin { font-weight: 300; }
.nav-breadcrumbs { display: flex; align-items: center; gap: 0.5rem; font-size: 0.82rem; color: var(--muted); }
.nav-breadcrumbs a { color: var(--muted); text-decoration: none; }
.nav-breadcrumbs a:hover { color: var(--primary); }
.nav-breadcrumbs .sep { color: #334155; }
.nav-breadcrumbs .current { color: var(--primary); font-weight: 600; }
.nav-back {
    display: flex; align-items: center; gap: 0.5rem;
    padding: 0.45rem 1rem;
    background: rgba(99,102,241,0.1);
    color: var(--primary);
    text-decoration: none;
    border-radius: 8px;
    font-size: 0.82rem;
    font-weight: 600;
    border: 1px solid var(--border);
    transition: all 0.2s;
}
.nav-back:hover { background: rgba(99,102,241,0.2); transform: translateY(-1px); }

/* TABS */
.tabs-bar {
    display: flex;
    gap: 0;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 2rem;
    overflow-x: auto;
    height: 50px;
    flex-shrink: 0;
}
.tab-btn {
    padding: 0.9rem 1.4rem;
    background: none;
    border: none;
    border-bottom: 3px solid transparent;
    color: var(--muted);
    font-family: 'Outfit', sans-serif;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.25s;
    display: flex; align-items: center; gap: 0.5rem;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }

/* PAGE LAYOUT */
.page-content { display: none; height: calc(100% - 110px); overflow-y: auto; flex-grow: 1; }
.page-content.active { display: block; }

/* OVERVIEW PAGE */
.overview-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    padding: 2rem;
    max-width: 1400px;
    margin: 0 auto;
}

.info-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 1.5rem;
}
.info-card h2 {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 1rem;
    color: var(--primary);
    display: flex; align-items: center; gap: 0.5rem;
}
.info-card p { color: var(--muted); line-height: 1.7; font-size: 0.92rem; margin-bottom: 0.8rem; }
.info-card p:last-child { margin-bottom: 0; }

/* Diode symbol SVG card */
.symbol-card { display: flex; flex-direction: column; align-items: center; }
.symbol-card svg { max-width: 320px; width: 100%; }

/* PN Diagram */
.pn-diagram { width: 100%; margin: 1rem 0; }

/* Key facts pills */
.fact-pills { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 1rem; }
.pill {
    padding: 0.3rem 0.8rem;
    border-radius: 20px;
    font-size: 0.78rem;
    font-weight: 600;
}
.pill.p-type { background: rgba(239,68,68,0.15); color: #ef4444; border: 1px solid rgba(239,68,68,0.3); }
.pill.n-type { background: rgba(59,130,246,0.15); color: #3b82f6; border: 1px solid rgba(59,130,246,0.3); }
.pill.neutral { background: rgba(99,102,241,0.15); color: #a5b4fc; border: 1px solid rgba(99,102,241,0.3); }

/* SIMULATOR PAGE */
.sim-layout {
    display: grid;
    grid-template-columns: 280px 1fr 260px;
    height: 100%;
    overflow: hidden;
}

.sim-controls {
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 1.2rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}
.sim-canvas-area {
    background: #06101e;
    background-image: radial-gradient(rgba(99,102,241,0.08) 1px, transparent 1px);
    background-size: 30px 30px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    gap: 1rem;
    position: relative;
    overflow: hidden;
}
.sim-readout {
    background: var(--surface);
    border-left: 1px solid var(--border);
    padding: 1.2rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

/* Controls */
.ctrl-section { display: flex; flex-direction: column; gap: 0.75rem; }
.ctrl-label {
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 0.4rem;
}
.ctrl-row { display: flex; flex-direction: column; gap: 0.3rem; }
.ctrl-row label { display: flex; justify-content: space-between; font-size: 0.85rem; color: var(--text); }
.ctrl-row label span { color: var(--primary); font-weight: 700; font-family: 'Space Grotesk', monospace; }
input[type=range] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%; height: 6px;
    background: rgba(99,102,241,0.2);
    border-radius: 3px;
    outline: none;
}
input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px; height: 16px;
    background: var(--primary);
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid var(--bg);
    box-shadow: 0 0 8px rgba(99,102,241,0.5);
}
.mode-btns { display: flex; gap: 0.5rem; }
.mode-btn {
    flex: 1;
    padding: 0.6rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: transparent;
    color: var(--muted);
    font-family: 'Outfit', sans-serif;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}
.mode-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.mode-btn:hover:not(.active) { border-color: var(--primary); color: var(--primary); }
.diode-type-btns { display: flex; gap: 0.5rem; flex-direction: column; }
.dtype-btn {
    padding: 0.5rem 0.8rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: transparent;
    color: var(--muted);
    font-family: 'Outfit', sans-serif;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    text-align: left;
    display: flex; align-items: center; gap: 0.5rem;
}
.dtype-btn.active { background: rgba(99,102,241,0.15); color: var(--primary); border-color: var(--primary); }
.dtype-btn .dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }

/* Canvas */
#diodeCanvas { border-radius: 12px; max-width: 100%; }

/* Bias indicator */
.bias-badge {
    position: absolute; top: 14px; right: 14px;
    padding: 0.4rem 1rem;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    transition: all 0.3s;
}
.bias-badge.forward { background: rgba(16,185,129,0.2); color: #10b981; border: 1px solid rgba(16,185,129,0.4); }
.bias-badge.reverse { background: rgba(239,68,68,0.2); color: #ef4444; border: 1px solid rgba(239,68,68,0.4); }
.bias-badge.zero { background: rgba(148,163,184,0.15); color: var(--muted); border: 1px solid rgba(148,163,184,0.2); }

/* Readout */
.readout-value {
    background: #06101e;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.9rem 1rem;
}
.readout-value .rv-label { font-size: 0.72rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.8px; margin-bottom: 0.3rem; }
.readout-value .rv-num { font-family: 'Space Grotesk', monospace; font-size: 1.4rem; font-weight: 700; }
.rv-num.positive { color: #10b981; }
.rv-num.negative { color: #ef4444; }
.rv-num.zero { color: var(--muted); }

/* VI Chart */
#viChart { border-radius: 10px; background: #06101e; border: 1px solid var(--border); }

/* THEORY PAGE */
.theory-layout {
    max-width: 1000px;
    margin: 0 auto;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}
.theory-section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 1.8rem;
}
.theory-section h2 {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 1.2rem;
    display: flex; align-items: center; gap: 0.6rem;
}
.theory-section p { color: var(--muted); line-height: 1.75; margin-bottom: 0.9rem; font-size: 0.93rem; }
.theory-section p:last-child { margin-bottom: 0; }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 1.2rem; margin-top: 1rem; }

.type-box {
    border-radius: 12px;
    padding: 1.2rem;
    display: flex; flex-direction: column; gap: 0.6rem;
}
.type-box.p-box { background: rgba(239,68,68,0.07); border: 1px solid rgba(239,68,68,0.25); }
.type-box.n-box { background: rgba(59,130,246,0.07); border: 1px solid rgba(59,130,246,0.25); }
.type-box h3 { font-size: 1rem; font-weight: 700; }
.type-box.p-box h3 { color: #ef4444; }
.type-box.n-box h3 { color: #3b82f6; }
.type-box p { color: var(--muted); font-size: 0.88rem; line-height: 1.6; margin: 0; }
.type-box ul { color: var(--muted); font-size: 0.87rem; line-height: 1.7; padding-left: 1.2rem; }

.bias-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-top: 1rem; }
.bias-card {
    border-radius: 12px;
    padding: 1.2rem;
}
.bias-card.fwd { background: rgba(16,185,129,0.08); border: 1px solid rgba(16,185,129,0.25); }
.bias-card.rev { background: rgba(239,68,68,0.08); border: 1px solid rgba(239,68,68,0.25); }
.bias-card h3 { font-size: 0.95rem; font-weight: 700; margin-bottom: 0.5rem; }
.bias-card.fwd h3 { color: #10b981; }
.bias-card.rev h3 { color: #ef4444; }
.bias-card p { color: var(--muted); font-size: 0.87rem; line-height: 1.6; }
.bias-card ul { color: var(--muted); font-size: 0.86rem; line-height: 1.7; padding-left: 1.2rem; }

.formula-box {
    background: #06101e;
    border: 1px solid rgba(99,102,241,0.3);
    border-radius: 10px;
    padding: 1rem 1.2rem;
    margin-top: 0.8rem;
    font-family: 'Space Grotesk', monospace;
    color: #a5b4fc;
    font-size: 0.95rem;
    line-height: 1.8;
}
.formula-box span { color: var(--accent); font-weight: 700; }

.apps-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px,1fr)); gap: 0.8rem; margin-top: 1rem; }
.app-item {
    background: rgba(99,102,241,0.08);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1rem;
    text-align: center;
}
.app-item .app-icon { font-size: 1.8rem; margin-bottom: 0.5rem; }
.app-item h4 { font-size: 0.85rem; color: var(--text); font-weight: 600; margin-bottom: 0.3rem; }
.app-item p { font-size: 0.77rem; color: var(--muted); }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(99,102,241,0.3); border-radius: 3px; }
