/* Electromagnetism lab — charges, circuits, right-hand rule, matching, quiz */

.em-lab {
  --em-accent: var(--chip-physics);
  --em-accent2: #5ba8b0;
  --em-muted: var(--color-text-muted);
  --em-pos: #e05252;
  --em-neg: #4a9eff;
  --em-ok: #4caf50;
  max-width: 920px;
  font-family: var(--font-body);
}

/* ── header ─────────────────────────────────────────────── */

.em-lab__header { margin-bottom: var(--space-6); }

.em-lab__eyebrow {
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--em-accent);
  margin-bottom: var(--space-2);
}

.em-lab__title {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.25;
  margin-bottom: var(--space-3);
}

.em-lab__intro {
  font-size: var(--text-sm);
  color: var(--em-muted);
  line-height: 1.65;
  max-width: 62ch;
}

/* ── tabs ────────────────────────────────────────────────── */

.em-lab__tabs {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-bottom: var(--space-6);
}

.em-lab__tab {
  font-family: var(--font-body);
  font-size: var(--text-xs);
  font-weight: 600;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-full);
  border: 1px solid var(--color-border);
  background: oklch(from var(--color-text) l c h / 0.04);
  color: var(--em-muted);
  cursor: pointer;
  transition: background var(--transition-interactive),
    color var(--transition-interactive),
    border-color var(--transition-interactive),
    box-shadow var(--transition-interactive);
}

.em-lab__tab:hover {
  color: var(--color-text);
  border-color: oklch(from var(--em-accent) l c h / 0.45);
}

.em-lab__tab[aria-selected="true"] {
  color: var(--color-bg);
  background: linear-gradient(125deg, oklch(from var(--em-accent) l c h / 0.88), var(--em-accent2));
  border-color: transparent;
  box-shadow: 0 0 18px oklch(from var(--em-accent) l c h / 0.2);
}

.em-lab__tab:focus-visible {
  outline: 2px solid var(--em-accent);
  outline-offset: 2px;
}

/* ── panels ──────────────────────────────────────────────── */

.em-lab__panel {
  display: none;
  animation: em-lab-in 0.4s cubic-bezier(0.16, 1, 0.3, 1) both;
}
.em-lab__panel.is-active { display: block; }

@keyframes em-lab-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  .em-lab__panel { animation: none; }
}

.em-lab__section-label {
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--color-text-faint);
  margin-bottom: var(--space-4);
}

/* ── canvas stage ────────────────────────────────────────── */

.em-lab__canvas-wrap {
  position: relative;
  border-radius: var(--radius-xl);
  overflow: hidden;
  margin-bottom: var(--space-5);
  background:
    radial-gradient(ellipse at 50% 60%, oklch(from var(--em-accent) l c h / 0.1), transparent 70%),
    var(--color-surface);
  border: 1px solid var(--color-divider);
  box-shadow: 0 0 32px oklch(from var(--em-accent) l c h / 0.08);
}

.em-lab__canvas {
  display: block;
  width: 100%;
  height: auto;
}

/* ── controls ────────────────────────────────────────────── */

.em-lab__controls {
  padding: var(--space-5);
  border-radius: var(--radius-xl);
  border: 1px solid var(--color-divider);
  margin-bottom: var(--space-5);
  background: oklch(from var(--color-text) l c h / 0.03);
}

.em-lab__controls label {
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-text-faint);
  display: block;
  margin-top: var(--space-3);
  margin-bottom: var(--space-2);
}
.em-lab__controls label:first-of-type { margin-top: 0; }

.em-lab__slider { width: 100%; max-width: 22rem; }

.em-lab__readout {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  margin-top: var(--space-4);
  color: var(--color-text);
  line-height: 1.7;
}
.em-lab__readout strong { color: var(--em-accent); }

/* ── charge placement buttons ────────────────────────────── */

.em-lab__charge-btns {
  display: flex;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}

.em-lab__charge-btn {
  font-family: var(--font-body);
  font-size: var(--text-xs);
  font-weight: 600;
  padding: 0.4rem 0.85rem;
  border-radius: var(--radius-full);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--em-muted);
  cursor: pointer;
  transition: all var(--transition-interactive);
}
.em-lab__charge-btn:hover { border-color: oklch(from var(--em-accent) l c h / 0.5); color: var(--color-text); }

.em-lab__charge-btn[data-sign="+1"].is-active {
  border-color: var(--em-pos);
  background: rgba(224,82,82,0.14);
  color: var(--em-pos);
}
.em-lab__charge-btn[data-sign="-1"].is-active {
  border-color: var(--em-neg);
  background: rgba(74,158,255,0.14);
  color: var(--em-neg);
}

/* ── buttons ─────────────────────────────────────────────── */

.em-lab__btn {
  font-family: var(--font-body);
  font-size: var(--text-xs);
  font-weight: 600;
  padding: 0.5rem 1.1rem;
  border-radius: var(--radius-full);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  cursor: pointer;
  transition: all var(--transition-interactive);
}
.em-lab__btn:hover { border-color: oklch(from var(--em-accent) l c h / 0.5); }

.em-lab__btn--primary {
  background: oklch(from var(--em-accent) l c h / 0.18);
  border-color: var(--em-accent);
}

.em-lab__btn:focus-visible {
  outline: 2px solid var(--em-accent);
  outline-offset: 2px;
}

.em-lab__btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  align-items: center;
  margin-bottom: var(--space-4);
}

/* ── feedback & score ────────────────────────────────────── */

.em-lab__feedback {
  font-size: var(--text-sm);
  color: var(--em-muted);
  line-height: 1.55;
  min-height: 2rem;
  margin-bottom: var(--space-3);
}
.em-lab__feedback--ok { color: var(--em-ok); }
.em-lab__feedback--no { color: var(--em-pos); }

.em-lab__score {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  color: var(--em-muted);
}
.em-lab__score strong { color: var(--em-accent); }

/* ── circuit builder ─────────────────────────────────────── */

.em-lab__circuit-vis {
  margin-bottom: var(--space-5);
}

.em-lab__ckt-diagram {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-5);
  border-radius: var(--radius-xl);
  border: 1px solid var(--color-divider);
  background: oklch(from var(--color-text) l c h / 0.03);
  overflow-x: auto;
}

.em-lab__ckt-batt {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  border: 2px solid var(--em-accent);
  background: oklch(from var(--em-accent) l c h / 0.08);
  flex-shrink: 0;
  min-width: 60px;
}
.em-lab__ckt-batt-plus { color: var(--em-pos); font-weight: 700; font-size: var(--text-lg); }
.em-lab__ckt-batt-minus { color: var(--em-neg); font-weight: 700; font-size: var(--text-lg); }
.em-lab__ckt-batt-label { font-family: var(--font-mono); font-size: var(--text-xs); color: var(--em-accent); }

.em-lab__ckt-wire {
  flex: 1;
  height: 3px;
  min-width: 30px;
  border-radius: 2px;
  background: oklch(from var(--em-accent) l c h / 0.25);
  position: relative;
  overflow: hidden;
}

.em-lab__ckt-wire--flow::after {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(90deg, transparent, transparent 6px, oklch(from var(--em-accent) l c h / 0.55) 6px, oklch(from var(--em-accent) l c h / 0.55) 10px);
  animation: em-flow var(--flow-speed, 0.5s) linear infinite;
}

@keyframes em-flow {
  to { transform: translateX(16px); }
}

@media (prefers-reduced-motion: reduce) {
  .em-lab__ckt-wire--flow::after { animation: none; opacity: 0.4; }
}

.em-lab__ckt-res-area {
  display: flex;
  gap: var(--space-2);
  flex-shrink: 0;
}
.em-lab__ckt-res-area--parallel {
  flex-direction: column;
}

.em-lab__ckt-res {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--color-text);
  min-width: 70px;
}

.em-lab__ckt-zigzag {
  font-size: 0.7rem;
  color: var(--em-muted);
  letter-spacing: -1px;
}

.em-lab__ckt-dir {
  font-size: var(--text-xs);
  color: var(--em-muted);
  margin-top: var(--space-3);
  line-height: 1.5;
}

.em-lab__res-row {
  margin-bottom: var(--space-2);
}
.em-lab__res-row label {
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-text-faint);
  display: block;
  margin-bottom: var(--space-2);
}

/* ── series / parallel toggle ────────────────────────────── */

.em-lab__toggle-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-top: var(--space-3);
  margin-bottom: var(--space-3);
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--em-muted);
}

.em-lab__toggle {
  position: relative;
  width: 40px;
  height: 22px;
  border-radius: 11px;
  background: oklch(from var(--color-text) l c h / 0.12);
  border: 1px solid var(--color-border);
  cursor: pointer;
  flex-shrink: 0;
  transition: background var(--transition-interactive), border-color var(--transition-interactive);
}
.em-lab__toggle.is-on {
  background: oklch(from var(--em-accent) l c h / 0.35);
  border-color: var(--em-accent);
}
.em-lab__toggle::after {
  content: '';
  position: absolute;
  top: 2px; left: 2px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--color-text);
  transition: transform var(--transition-interactive);
}
.em-lab__toggle.is-on::after { transform: translateX(18px); }

/* ── right-hand rule ─────────────────────────────────────── */

.em-lab__rhr-info {
  font-size: var(--text-sm);
  line-height: 1.55;
  margin-bottom: var(--space-4);
  color: var(--color-text);
}

.em-lab__rhr-arrows {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}

.em-lab__rhr-btn {
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: 600;
  padding: 0.6rem 1.2rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  cursor: pointer;
  min-width: 80px;
  transition: all var(--transition-interactive);
}
.em-lab__rhr-btn:hover:not(:disabled) { border-color: var(--em-accent); }
.em-lab__rhr-btn:disabled { cursor: default; opacity: 0.7; }

.em-lab__rhr-btn--correct {
  border-color: var(--em-ok) !important;
  background: rgba(76,175,80,0.15);
  color: var(--em-ok);
}
.em-lab__rhr-btn--wrong {
  border-color: var(--em-pos) !important;
  background: rgba(224,82,82,0.12);
  color: var(--em-pos);
}

/* ── fine print ──────────────────────────────────────────── */

.em-lab__fine {
  font-size: var(--text-xs);
  color: var(--color-text-faint);
  margin-top: var(--space-6);
  line-height: 1.5;
  max-width: 68ch;
}
