/* Maddison Circuit Simulator — Lab v1.2 — dark lab polish */
.mad-sim-wrap {
  --sim-red: #ef4444;
  --sim-red-dark: #b91c1c;
  --sim-red-light: #3f1d1d;
  --sim-slate-900: #0b1220;
  --sim-slate-800: #111827;
  --sim-slate-700: #1f2937;
  --sim-slate-600: #94a3b8;
  --sim-slate-200: #334155;
  --sim-slate-100: #1e293b;
  --sim-slate-50: #0f172a;
  --sim-board: #121826;
  --sim-hole: #070b12;
  --sim-rail-pos: #f87171;
  --sim-rail-neg: #60a5fa;
  --sim-accent: #38bdf8;
  --sim-glow: #22d3ee;
  --sim-panel: #0f172aee;
  --sim-text: #e2e8f0;
  --sim-muted: #94a3b8;
  --sim-ok: #22c55e;
  --sim-warn: #fbbf24;
  font-family: "Segoe UI", ui-sans-serif, system-ui, sans-serif;
  color: var(--sim-text);
  display: flex;
  flex-direction: column;
  min-height: 520px;
  background: radial-gradient(1200px 600px at 20% -10%, #1e293b 0%, transparent 55%),
              radial-gradient(900px 500px at 90% 0%, #1a1030 0%, transparent 50%),
              linear-gradient(180deg, #0b1220 0%, #0a0f1a 100%);
  border-radius: 18px;
  padding: 10px;
}
.mad-sim-wrap * { box-sizing: border-box; }

.mad-sim-wrap.mad-sim-fullpage,
.mad-sim-page .mad-sim-wrap {
  min-height: calc(100vh - 100px);
  max-width: 1480px;
  margin: 0 auto;
  padding: 10px 12px 20px;
}
.mad-sim-page {
  background: #070b12 !important;
  padding: 8px 0 32px;
}
.mad-sim-page .entry-header,
.mad-sim-page .page-title,
.mad-sim-page .breadcrumbs { display: none !important; }
body.mad-sim-page,
body.mad-sim-focus {
  background: #070b12 !important;
}

.mad-sim-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}
.mad-sim-header h2 {
  margin: 0 0 4px;
  font-size: 1.55rem;
  color: #f8fafc;
  letter-spacing: -0.02em;
}
.mad-sim-header p {
  margin: 0;
  color: var(--sim-muted);
  font-size: 0.92rem;
  max-width: 62ch;
}
.mad-sim-badge {
  display: inline-block;
  background: linear-gradient(90deg, #7f1d1d, #991b1b);
  color: #fecaca;
  font-weight: 800;
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  padding: 5px 12px;
  border-radius: 999px;
  margin-bottom: 8px;
  border: 1px solid #ef444466;
  box-shadow: 0 0 20px rgba(239,68,68,0.25);
}
.mad-sim-ver {
  display: inline-block;
  margin-left: 8px;
  font-size: 0.68rem;
  font-weight: 700;
  color: #67e8f9;
  background: #083344;
  border: 1px solid #0891b2;
  padding: 2px 8px;
  border-radius: 999px;
  vertical-align: middle;
}
.mad-sim-open-full {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
  font-weight: 700;
  font-size: 0.85rem;
  color: #fecaca;
  border: 1px solid #ef4444aa;
  background: #3f1d1d;
  padding: 8px 14px;
  border-radius: 8px;
}
.mad-sim-open-full:hover { background: #7f1d1d; color: #fff; }

.mad-sim-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
  padding: 10px 12px;
  background: linear-gradient(180deg, #1e293bcc, #0f172acc);
  border: 1px solid #334155;
  border-radius: 14px;
  position: sticky;
  top: 0;
  z-index: 40;
  backdrop-filter: blur(10px);
  box-shadow: 0 8px 28px rgba(0,0,0,0.35);
}
.mad-sim-btn {
  appearance: none;
  border: 1px solid #334155;
  background: #1e293b;
  color: #e2e8f0;
  font-weight: 700;
  font-size: 0.86rem;
  padding: 9px 12px;
  min-height: 40px;
  border-radius: 10px;
  cursor: pointer;
  transition: 0.15s ease;
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.mad-sim-btn:hover { border-color: #ef4444; color: #fecaca; background: #3f1d1d; }
.mad-sim-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.mad-sim-btn-primary {
  background: linear-gradient(135deg, #ef4444, #b91c1c);
  color: #fff !important;
  border-color: transparent;
  box-shadow: 0 0 18px rgba(239,68,68,0.35);
}
.mad-sim-btn-primary:hover { filter: brightness(1.08); color: #fff !important; }
.mad-sim-btn-danger { border-color: #7f1d1d; color: #fecaca; }
.mad-sim-btn-ghost { background: #0f172a; }
.mad-sim-btn.active {
  background: #083344;
  border-color: #22d3ee;
  color: #a5f3fc;
  box-shadow: 0 0 12px rgba(34,211,238,0.25);
}
.mad-sim-status {
  margin-left: auto;
  font-size: 0.84rem;
  font-weight: 650;
  color: var(--sim-muted);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.mad-sim-status .dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: #64748b;
  display: inline-block;
}
.mad-sim-status.running .dot {
  background: #22c55e;
  box-shadow: 0 0 0 3px rgba(34,197,94,0.3);
  animation: mad-sim-pulse 1.1s infinite;
}
.mad-sim-status.warn .dot {
  background: #f59e0b;
  box-shadow: 0 0 0 3px rgba(245,158,11,0.3);
}
@keyframes mad-sim-pulse {
  0%,100% { box-shadow: 0 0 0 3px rgba(34,197,94,0.25); }
  50% { box-shadow: 0 0 0 7px rgba(34,197,94,0.05); }
}

.mad-sim-layout {
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr) 300px;
  gap: 12px;
  align-items: stretch;
  flex: 1;
}
@media (max-width: 1180px) {
  .mad-sim-layout { grid-template-columns: 210px minmax(0, 1fr); }
  .mad-sim-side-right { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
}
@media (max-width: 760px) {
  .mad-sim-layout { grid-template-columns: 1fr; }
  .mad-sim-side-right { grid-template-columns: 1fr; }
  .mad-sim-toolbar { position: static; }
}

.mad-sim-panel {
  background: linear-gradient(180deg, #111827f2, #0b1220f2);
  border: 1px solid #334155;
  border-radius: 14px;
  padding: 12px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.04), 0 8px 24px rgba(0,0,0,0.25);
}
.mad-sim-panel h3 {
  margin: 0 0 10px;
  font-size: 0.92rem;
  color: #f1f5f9;
  display: flex;
  align-items: center;
  gap: 6px;
}
.mad-sim-palette {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: min(72vh, 860px);
  overflow-y: auto;
  padding-right: 4px;
}
.mad-sim-fullpage .mad-sim-palette { max-height: calc(100vh - 210px); }
.mad-sim-palette-group {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: #64748b;
  font-weight: 800;
  margin: 10px 0 3px;
  padding-bottom: 2px;
  border-bottom: 1px dashed #334155;
}
.mad-sim-comp {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  text-align: left;
  border: 1px solid #334155;
  background: #0f172a;
  border-radius: 10px;
  padding: 8px 10px;
  min-height: 42px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  color: #cbd5e1;
  transition: 0.12s ease;
}
.mad-sim-comp:hover, .mad-sim-comp.selected {
  border-color: #22d3ee;
  background: #083344;
  color: #ecfeff;
  box-shadow: 0 0 0 1px #22d3ee55;
}
.mad-sim-comp .ico {
  width: 30px; height: 24px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 0.95rem; flex-shrink: 0;
}
.mad-sim-comp select, .mad-sim-value-select {
  margin-left: auto;
  font-size: 0.7rem;
  border: 1px solid #475569;
  border-radius: 6px;
  padding: 3px 4px;
  max-width: 88px;
  background: #1e293b;
  color: #e2e8f0;
  min-height: 26px;
}

.mad-sim-center { display: flex; flex-direction: column; min-width: 0; gap: 8px; }
.mad-sim-board-wrap {
  overflow: auto;
  border-radius: 14px;
  border: 1px solid #334155;
  background:
    linear-gradient(180deg, #1a2336 0%, var(--sim-board) 100%);
  padding: 10px;
  min-height: 520px;
  height: min(62vh, 700px);
  touch-action: none;
  position: relative;
  cursor: grab;
  box-shadow: inset 0 0 80px rgba(0,0,0,0.35);
}
.mad-sim-fullpage .mad-sim-board-wrap,
.mad-sim-page .mad-sim-board-wrap {
  height: calc(100vh - 320px);
  min-height: 540px;
}
.mad-sim-board-wrap.is-panning { cursor: grabbing; }
.mad-sim-board-wrap.svg-sel .mad-sim-sel-ring { animation: mad-sel 1.2s ease-in-out infinite; }
@keyframes mad-sel {
  0%,100% { opacity: 0.9; }
  50% { opacity: 0.45; }
}
.mad-sim-board-wrap svg {
  display: block;
  margin: 0 auto;
  transform-origin: 0 0;
  user-select: none;
  -webkit-user-select: none;
}
.mad-sim-zoombar {
  position: absolute;
  right: 12px;
  bottom: 12px;
  display: flex;
  gap: 6px;
  z-index: 5;
}
.mad-sim-zoombar .mad-sim-btn {
  min-height: 34px;
  padding: 5px 10px;
  background: rgba(15,23,42,0.9);
  color: #fff;
  border-color: #475569;
}

.mad-sim-hint-bar {
  padding: 10px 12px;
  border-radius: 10px;
  background: #422006;
  border: 1px solid #a16207;
  color: #fde68a;
  font-size: 0.88rem;
  min-height: 2.4em;
}
.mad-sim-hint-bar.error {
  background: #450a0a;
  border-color: #ef4444;
  color: #fecaca;
  box-shadow: 0 0 20px rgba(239,68,68,0.2);
}
.mad-sim-hint-bar.ok {
  background: #052e16;
  border-color: #16a34a;
  color: #bbf7d0;
}
.mad-sim-hint-bar.warn {
  background: #451a03;
  border-color: #f59e0b;
  color: #fde68a;
}

.mad-sim-presets { display: flex; flex-direction: column; gap: 8px; max-height: 380px; overflow-y: auto; }
.mad-sim-preset {
  text-align: left;
  border: 1px solid #334155;
  background: #0f172a;
  border-radius: 10px;
  padding: 10px 12px;
  cursor: pointer;
  font-family: inherit;
  transition: 0.12s;
  min-height: 64px;
  color: inherit;
  position: relative;
}
.mad-sim-preset:hover { border-color: #22d3ee; background: #083344; }
.mad-sim-preset.done { border-color: #16a34a66; }
.mad-sim-preset.done::after {
  content: "✓";
  position: absolute;
  top: 8px; right: 10px;
  color: #22c55e;
  font-weight: 800;
}
.mad-sim-preset.active {
  border-color: #ef4444;
  box-shadow: 0 0 0 1px #ef444455;
}
.mad-sim-preset strong { display: block; color: #f8fafc; font-size: 0.88rem; margin-bottom: 3px; padding-right: 18px; }
.mad-sim-preset span { display: block; color: #94a3b8; font-size: 0.76rem; line-height: 1.35; }
.mad-sim-preset .mad-sim-load-lab {
  margin-top: 8px;
  display: inline-flex;
  background: #991b1b;
  color: #fff;
  border: none;
  border-radius: 7px;
  padding: 5px 10px;
  font-size: 0.75rem;
  font-weight: 800;
  cursor: pointer;
}
.mad-sim-preset .mad-sim-load-lab:hover { background: #dc2626; }

.mad-sim-progress {
  position: sticky;
  top: 62px;
  z-index: 35;
  margin-bottom: 8px;
  padding: 8px 12px;
  border-radius: 10px;
  background: #0f172add;
  border: 1px solid #334155;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.8rem;
  color: #cbd5e1;
  backdrop-filter: blur(8px);
}
.mad-sim-progress .bar {
  flex: 1;
  height: 8px;
  background: #1e293b;
  border-radius: 999px;
  overflow: hidden;
}
.mad-sim-progress .bar > i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #22c55e, #38bdf8);
  width: 0%;
  transition: width 0.3s ease;
}

.mad-sim-parts { display: flex; flex-direction: column; gap: 6px; margin-top: 4px; max-height: 220px; overflow-y: auto; }
.mad-sim-parts a {
  display: flex; align-items: center; gap: 8px;
  text-decoration: none;
  color: #cbd5e1;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid #334155;
  background: #0f172a;
}
.mad-sim-parts a:hover { border-color: #ef4444; color: #fecaca; background: #3f1d1d; }

.mad-sim-inspect {
  font-size: 0.82rem;
  color: #94a3b8;
  line-height: 1.45;
  margin-top: 4px;
  padding: 10px;
  background: #020617;
  border-radius: 10px;
  min-height: 4em;
  border: 1px solid #1e293b;
}
.mad-sim-inspect .probe {
  font-weight: 800;
  color: #38bdf8;
  font-size: 1.05rem;
  margin-bottom: 6px;
}
.mad-sim-inspect .freq {
  color: #a78bfa;
  font-weight: 800;
}
.mad-sim-inspect .short {
  color: #fecaca;
  font-weight: 800;
  background: #7f1d1d;
  padding: 4px 8px;
  border-radius: 6px;
}

.mad-sim-slider-row {
  display: flex; align-items: center; gap: 8px;
  margin: 4px 0;
  font-size: 0.8rem;
  font-weight: 600;
  color: #cbd5e1;
  flex-wrap: wrap;
}
.mad-sim-slider-row input[type=range] { flex: 1; min-width: 120px; }
.mad-sim-mode-label {
  font-size: 0.78rem;
  font-weight: 700;
  color: #94a3b8;
  padding: 0 4px;
}
.mad-sim-legend {
  display: flex; flex-wrap: wrap; gap: 10px;
  font-size: 0.72rem; color: #94a3b8; margin: 4px 2px 0;
}
.mad-sim-legend span { display: inline-flex; align-items: center; gap: 4px; }
.mad-sim-legend i {
  width: 10px; height: 10px; border-radius: 2px; display: inline-block;
}

/* Scope + meter */
.mad-sim-scope-wrap {
  background: #020617;
  border: 1px solid #1e293b;
  border-radius: 10px;
  padding: 8px;
  margin-top: 8px;
}
.mad-sim-scope-wrap canvas {
  width: 100%;
  height: 110px;
  display: block;
  background: #000;
  border-radius: 6px;
  border: 1px solid #164e63;
  box-shadow: inset 0 0 30px rgba(34,211,238,0.08);
}
.mad-sim-scope-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.72rem;
  color: #67e8f9;
  margin-top: 4px;
  font-family: ui-monospace, monospace;
}
.mad-sim-meter {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-top: 8px;
}
.mad-sim-meter button {
  border: 1px solid #334155;
  background: #0f172a;
  color: #cbd5e1;
  border-radius: 8px;
  padding: 8px;
  font-weight: 800;
  cursor: pointer;
  font-family: inherit;
}
.mad-sim-meter button.active {
  border-color: #22d3ee;
  background: #083344;
  color: #a5f3fc;
}
.mad-sim-meter-readout {
  margin-top: 8px;
  font-family: ui-monospace, Menlo, monospace;
  font-size: 1.25rem;
  font-weight: 800;
  color: #67e8f9;
  text-align: center;
  padding: 10px;
  background: #000;
  border-radius: 8px;
  border: 1px solid #164e63;
  min-height: 48px;
}

.mad-sim-arduino-panel {
  margin-top: 8px;
  padding: 10px;
  border-radius: 10px;
  background: #020617;
  border: 1px dashed #475569;
}
.mad-sim-arduino-panel pre {
  margin: 6px 0 0;
  padding: 8px;
  background: #0b1220;
  border-radius: 6px;
  font-size: 0.72rem;
  color: #a5f3fc;
  overflow: auto;
  max-height: 120px;
  border: 1px solid #1e293b;
}
.mad-sim-arduino-panel label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  color: #cbd5e1;
  margin: 4px 0;
}
.mad-sim-arduino-panel input[type=number] {
  width: 70px;
  background: #1e293b;
  border: 1px solid #475569;
  color: #e2e8f0;
  border-radius: 6px;
  padding: 4px 6px;
}

.mad-sim-side-right .mad-sim-panel + .mad-sim-panel { margin-top: 12px; }
@media (max-width: 1180px) {
  .mad-sim-side-right .mad-sim-panel + .mad-sim-panel { margin-top: 0; }
}

#content-sim:not(.hidden) .mad-sim-wrap {
  min-height: calc(100vh - 200px);
}
#content-sim:not(.hidden) .mad-sim-board-wrap {
  height: min(58vh, 640px);
}
body.mad-sim-focus #content-sim .finder-header { display: none; }

.mad-sim-toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  background: #0f172a;
  border: 1px solid #22d3ee;
  color: #e2e8f0;
  padding: 12px 16px;
  border-radius: 10px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.4);
  max-width: 320px;
  font-size: 0.88rem;
}
