:root {
    --bg-primary: #060a12;
    --bg-secondary: #0d1423;
    --bg-tertiary: #141f36;
    --border: #203153;
    --text: #e8eaed;
    --muted: #8b95a5;
    --cyan: #00e5ff;
    --pink: #ff4081;
    --orange: #ff9100;
    --green: #76ff03;
    --yellow: #ffd740;
    --danger: #ff1744;
    --font-display: 'Orbitron', sans-serif;
    --font-body: 'Rajdhani', sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
}

* { box-sizing: border-box; }
html, body {
    margin: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background:
        radial-gradient(ellipse at 25% 25%, rgba(40,10,80,0.55) 0%, transparent 55%),
        radial-gradient(ellipse at 75% 75%, rgba(0,30,60,0.4) 0%, transparent 55%),
        #060a12;
    color: var(--text);
    font-family: var(--font-body);
}

#app {
    height: 100%;
    display: grid;
    grid-template-rows: auto 1fr;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    background: rgba(13, 20, 35, 0.92);
    border-bottom: 1px solid var(--border);
}

.brand {
    display: flex;
    align-items: center;
    gap: 14px;
}

.back-link {
    color: var(--cyan);
    text-decoration: none;
    font-weight: 600;
    font-size: 14px;
}

.brand h1 {
    margin: 0;
    font-family: var(--font-display);
    font-size: 18px;
    letter-spacing: 1px;
}

.main-grid {
    min-height: 0;
    display: grid;
    grid-template-columns: 280px 1fr 280px;
}

.panel {
    min-height: 0;
    overflow: auto;
    padding: 12px;
    background: rgba(13, 20, 35, 0.92);
}

.controls { border-right: 1px solid var(--border); }
.readout  { border-left:  1px solid var(--border); }

.group {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px;
    margin-bottom: 10px;
    background: rgba(20, 31, 54, 0.45);
}

.group h2 {
    margin: 0 0 8px;
    font-family: var(--font-display);
    font-size: 11px;
    color: var(--cyan);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.group.hidden { display: none; }

.tool-row,
.preset-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0,1fr));
    gap: 6px;
}

.btn {
    border: 1px solid var(--border);
    background: var(--bg-tertiary);
    color: var(--text);
    border-radius: 8px;
    padding: 8px;
    cursor: pointer;
    font-family: var(--font-body);
    font-weight: 600;
    font-size: 12px;
}
.btn:hover  { border-color: var(--cyan); color: var(--cyan); }
.btn.active { border-color: var(--cyan); color: var(--cyan); background: rgba(0,229,255,0.1); }
.btn.danger:hover { border-color: var(--danger); color: var(--danger); }

.pole-btn { padding: 5px 12px; font-family: var(--font-display); font-size: 12px; font-weight: 700; }
#btn-pole-n.active { border-color: #ff4422; color: #ff4422; background: rgba(255,68,34,0.12); }
#btn-pole-s.active { border-color: #3366ff; color: #3366ff; background: rgba(51,102,255,0.12); }

.slider-label {
    display: block;
    margin-top: 8px;
    margin-bottom: 2px;
    color: var(--muted);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.6px;
}
input[type="range"] { width: 100%; }

.kv {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 5px 0;
    color: var(--muted);
    font-size: 12px;
}
.kv select {
    background: var(--bg-tertiary);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 3px 5px;
    font-family: var(--font-body);
    font-size: 11px;
}

.hint {
    color: var(--muted);
    font-size: 11px;
    line-height: 1.4;
    margin: 8px 0 0;
}

.sim-wrap {
    position: relative;
    min-width: 0;
    min-height: 0;
}

#sim-canvas {
    width: 100%;
    height: 100%;
    display: block;
    cursor: grab;
}
#sim-canvas.dragging { cursor: grabbing; }

.overlay {
    position: absolute;
    top: 10px;
    left: 10px;
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--green);
    border: 1px solid rgba(118,255,3,0.4);
    background: rgba(8,16,24,0.72);
    border-radius: 8px;
    padding: 6px 10px;
    pointer-events: none;
}

.overlay.legend {
    top: auto;
    left: auto;
    right: 10px;
    bottom: 10px;
    color: #d9e7ff;
    border-color: rgba(0,229,255,0.35);
    line-height: 1.6;
    max-width: 280px;
    pointer-events: none;
    font-size: 11px;
}

.mono {
    font-family: var(--font-mono);
    font-size: 11px;
    color: #c6d2e3;
    white-space: pre-line;
    background: rgba(6,10,18,0.78);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px;
    margin-bottom: 8px;
    line-height: 1.5;
}

.formula-block { margin-top: 4px; }
.formula {
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--yellow);
    margin-top: 4px;
}
.formula-note {
    font-size: 11px;
    color: var(--muted);
    margin-top: 4px;
}

#emf-graph {
    width: 100%;
    height: 110px;
    border-radius: 6px;
    display: block;
}

/* Dual graph */
#dual-graph {
    width: 100%;
    height: 140px;
    border-radius: 6px;
    display: block;
}
.graph-legend {
    display: flex;
    gap: 12px;
    justify-content: center;
    margin-top: 4px;
}
.gl-item {
    font-family: var(--font-mono);
    font-size: 10px;
}

/* Real-world applications */
.realworld-list {
    display: flex;
    flex-direction: column;
    gap: 5px;
}
.rw-item {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 6px 8px;
    border-radius: 6px;
    background: rgba(6,10,18,0.6);
    border: 1px solid var(--border);
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s;
}
.rw-item:hover, .rw-item.active {
    border-color: var(--cyan);
    background: rgba(0,229,255,0.06);
}
.rw-icon { font-size: 18px; flex-shrink: 0; line-height: 1.3; }
.rw-text { flex: 1; }
.rw-title { font-family: var(--font-display); font-size: 10px; color: var(--cyan); text-transform: uppercase; letter-spacing: 0.5px; }
.rw-desc  { font-size: 10px; color: var(--muted); line-height: 1.4; margin-top: 2px; }

/* Challenge mode */
.challenge-box {
    background: rgba(6,10,18,0.7);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px;
    margin-bottom: 8px;
    min-height: 72px;
}
.challenge-text {
    font-size: 12px;
    color: #d0ddf0;
    line-height: 1.5;
    margin-bottom: 6px;
}
.challenge-hint {
    font-size: 11px;
    color: var(--muted);
    font-style: italic;
    line-height: 1.4;
}
.challenge-result {
    margin-top: 6px;
    font-family: var(--font-mono);
    font-size: 11px;
    min-height: 16px;
}
.challenge-result.pass { color: var(--green); }
.challenge-result.fail { color: #ff6060; }

.challenge-btns {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    margin-bottom: 8px;
}
.challenge-progress {
    font-size: 11px;
    color: var(--muted);
    text-align: center;
}
.progress-bar {
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    margin-top: 5px;
    overflow: hidden;
}
.progress-fill {
    height: 100%;
    background: var(--green);
    border-radius: 2px;
    transition: width 0.4s ease;
    width: 0%;
}

/* Canvas insight callouts */
.insight-callout {
    position: absolute;
    background: rgba(8,14,28,0.92);
    border: 1px solid var(--yellow);
    border-radius: 10px;
    padding: 8px 12px;
    font-size: 11px;
    color: #e0ecff;
    pointer-events: none;
    max-width: 220px;
    line-height: 1.5;
    transition: opacity 0.4s;
    z-index: 10;
}
.insight-callout .ic-title {
    font-family: var(--font-display);
    font-size: 10px;
    color: var(--yellow);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 3px;
}

/* Speed-o-meter strip */
.speed-strip {
    position: absolute;
    bottom: 44px;
    left: 12px;
    right: 12px;
    height: 8px;
    background: rgba(20,31,54,0.7);
    border: 1px solid var(--border);
    border-radius: 4px;
    overflow: hidden;
}
.speed-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.1s, background 0.2s;
}

.lenz-indicator {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 8px;
    background: rgba(6,10,18,0.78);
    border: 1px solid var(--border);
    border-radius: 8px;
    min-height: 52px;
    justify-content: center;
}

.lenz-arrow {
    font-size: 22px;
    transition: color 0.3s;
    font-family: var(--font-mono);
}
.lenz-label {
    font-size: 11px;
    color: var(--muted);
    text-align: center;
    line-height: 1.3;
}

.top-actions { display: flex; gap: 8px; }

#mobile-backdrop,
#mobile-dock { display: none; }

@media (max-width: 1150px) {
    .main-grid { grid-template-columns: 260px 1fr; }
    .readout { display: none; }
}

@media (max-width: 760px) {
    html, body { overflow: hidden; }
    #app { position: relative; }

    .topbar { padding: 8px 10px; }
    .brand h1 { font-size: 14px; }
    .back-link { font-size: 12px; }

    .main-grid { grid-template-columns: 1fr; }
    .sim-wrap { min-height: calc(100dvh - 52px - 66px); }

    .controls,
    .readout {
        display: block;
        position: fixed;
        left: 0; right: 0;
        top: 52px; bottom: 66px;
        z-index: 40;
        border: none;
        border-top: 1px solid var(--border);
        transform: translateY(105%);
        transition: transform 0.24s ease;
        box-shadow: 0 -8px 28px rgba(0,0,0,0.45);
        background: rgba(13,20,35,0.98);
    }

    #app.show-controls #controls-panel,
    #app.show-readout  #readout-panel {
        transform: translateY(0);
    }

    #mobile-backdrop {
        display: block;
        position: fixed; inset: 0;
        z-index: 35;
        background: rgba(6,10,18,0.65);
        opacity: 0; pointer-events: none;
        transition: opacity 0.2s ease;
    }
    #app.mobile-panel-open #mobile-backdrop {
        opacity: 1; pointer-events: auto;
    }

    #mobile-dock {
        display: grid;
        grid-template-columns: repeat(2, minmax(0,1fr));
        gap: 8px;
        position: fixed;
        left: 10px; right: 10px; bottom: 8px;
        z-index: 45;
        padding: 8px;
        border: 1px solid var(--border);
        border-radius: 12px;
        background: rgba(8,14,22,0.94);
        backdrop-filter: blur(4px);
    }
    .mobile-btn { min-height: 42px; font-size: 14px; }
    .mobile-btn.active {
        border-color: var(--cyan);
        color: var(--cyan);
        background: rgba(0,229,255,0.12);
    }

    .overlay.legend {
        right: 8px; left: 8px;
        bottom: 72px;
        max-width: none;
    }
}
