/* ==========================================================================
   ML Basics · mlb-06 · Circuito Elétrico (prefixo mci-) · tema pixel
   O quadro é pixel art (epoch/js/pixel.js) ampliada sem suavização, com os números
   e o gráfico de erros limpos por cima (epoch/js/chart.js). Aqui ficam os
   interruptores, a tabela verdade, o registro e o álbum.
   ========================================================================== */

.mci { --mci-hard: 3px 3px 0 0 rgba(0, 0, 0, 0.5); }

/* ---------- quadro ---------- */

.mci .sg-canvas {
  border-radius: 0;
  border: 2px solid #000;
  background: #141320;
  box-shadow: var(--mci-hard);
  cursor: pointer;
  /* tocar liga um interruptor; arrastar ainda rola a página */
  touch-action: pan-y;
}

.mci .sg-caption { justify-content: flex-start; gap: 6px; font: 400 11px/1.3 var(--pixel-ui); color: var(--muted); }
.mci .sg-caption span { display: inline-flex; align-items: baseline; gap: 4px; padding: 4px 8px; border: 2px solid var(--line-2); background: var(--bg-2); white-space: nowrap; }
.mci .sg-caption b { font-weight: 400; color: var(--accent); }

/* ---------- controles ---------- */

.mci-controls { display: flex; flex-direction: column; gap: 14px; }
.mci-msg:empty { display: none; }
.mci .sg-formula { border-radius: 0; border: 2px solid var(--line-2); background: var(--bg); box-shadow: var(--mci-hard); }
.mci .sg-formula b.neg { color: var(--bad); }
.mci .sg-slider > .mono { font-family: var(--pixel); font-size: 15px; color: var(--accent); }
.mci .sg-slider output { font-family: var(--pixel-ui); font-size: 11px; }
.mci .sg-sliders.mci-off { opacity: 0.55; }
.mci .sg-goal, .mci .sg-msg { border-radius: 0; }
.mci .btn { border-radius: 0; }
.mci-note { margin: 0; font: 400 11px/1.4 var(--pixel-ui); color: var(--muted); }

.mci-sws { display: flex; flex-wrap: wrap; gap: 8px; }
.mci-sw {
  flex: 1 1 0; min-width: 0; min-height: 48px;
  display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 2px 8px;
  padding: 6px 10px;
  border: 2px solid var(--line-2); border-radius: 0;
  background: var(--bg-2); color: var(--text-2);
  font: 400 11px/1.2 var(--pixel-ui); text-align: left;
  box-shadow: 2px 2px 0 0 #000;
  cursor: pointer;
}
.mci-sw > span:not(.mci-led) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mci-sw b { grid-column: 2; font-weight: 400; color: var(--muted); }
.mci-led { grid-row: span 2; width: 10px; height: 10px; background: var(--surface-2); border: 2px solid #000; }
.mci-sw[aria-pressed='true'] { border-color: var(--accent); color: var(--text); }
.mci-sw[aria-pressed='true'] b { color: var(--accent); }
.mci-sw[aria-pressed='true'] .mci-led { background: var(--accent); }
.mci-sw:active:not(:disabled) { transform: translate(2px, 2px); box-shadow: none; }
.mci-sw:disabled { cursor: default; opacity: 0.7; }
.mci-sw:focus-visible, .mci-tr:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.mci-group { display: flex; flex-direction: column; gap: 8px; padding: 10px 12px; border: 2px solid var(--line-2); background: var(--bg-2); }

/* o motor do Mark I */
.mci-event { display: flex; flex-direction: column; gap: 6px; padding: 10px 12px; border: 2px dashed var(--line-2); background: var(--bg-2); font: 400 12px/1.4 var(--pixel-ui); color: var(--text-2); }
.mci-event b { font-weight: 400; color: var(--text); }
.mci-event b.mci-on { color: var(--warn); }
.mci-dirs { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.mci-dir { min-height: 46px; justify-content: center; box-shadow: 2px 2px 0 0 #000; }
.mci-dir:active { transform: translate(2px, 2px); box-shadow: none; }
.mci-motor { width: 100%; min-height: 48px; justify-content: center; }

/* ---------- tabela verdade ---------- */

.mci-table { display: flex; flex-direction: column; gap: 8px; }
.mci-thead { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 12px; }
.mci-thead .mono { font-size: 11px; color: var(--muted); }
.mci-thead .mono b { color: var(--accent); font-weight: 500; }

.mci-tt { display: flex; flex-direction: column; gap: 3px; }
.mci-tr {
  display: grid;
  grid-template-columns: 26px repeat(var(--n), minmax(0, 1fr)) repeat(var(--mid), minmax(0, 0.9fr)) minmax(0, 1.2fr) minmax(0, 0.8fr);
  align-items: center; gap: 4px;
  width: 100%; min-height: 34px; padding: 3px 8px;
  border: 2px solid var(--line); border-radius: 0;
  background: var(--bg-2); color: var(--text-2);
  font: 400 12px/1 var(--pixel-ui); text-align: center;
  cursor: pointer;
}
.mci-tr > span { display: inline-flex; align-items: center; justify-content: center; gap: 4px; min-width: 0; }
.mci-tr > span:first-child { color: var(--faint); }
.mci-th { min-height: 0; padding-top: 0; padding-bottom: 0; border: 0; background: none; cursor: default; font-size: 10px; color: var(--muted); text-transform: lowercase; }
.mci-th > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }
.mci-tr.cur { border-color: var(--accent); background: var(--accent-soft); color: var(--text); }
.mci-tr.scan { border-color: var(--warn); }
.mci-tr.ok .icon { color: var(--good); }
.mci-tr.err { border-color: var(--bad); }
.mci-tr.err .icon { color: var(--bad); }
.mci-tr .icon { width: 12px; height: 12px; }
.mci-tr:disabled { cursor: default; }
.mci-bit { width: 22px; height: 20px; margin: 0 auto; border: 2px solid var(--line-2); background: var(--bg); color: var(--muted); }
.mci-bit.on { border-color: var(--accent); color: var(--accent); }
.mci-dot { display: inline-block; width: 12px; height: 12px; border: 2px solid #000; background: var(--surface-2); }
.mci-dot.on { background: var(--warn); }
.mci-dot.q { background: none; border-style: dashed; border-color: var(--line-2); }

/* registro do alarme (fase do motor) */
.mci-reg { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 4px; }
.mci-ev { display: flex; align-items: center; justify-content: center; gap: 4px; padding: 6px 2px; border: 2px solid var(--line); background: var(--bg-2); font: 400 11px/1 var(--pixel-ui); color: var(--text-2); }
.mci-ev b { font-weight: 400; letter-spacing: 0.05em; }
.mci-ev i { font-style: normal; color: var(--muted); }
.mci-ev i.on { color: var(--warn); }
.mci-ev.cur { border-color: var(--accent); background: var(--accent-soft); color: var(--text); }
.mci-ev.ok { border-color: var(--good); }
.mci-ev.err { border-color: var(--bad); background: var(--bad-soft); }

/* álbum dos 16 jeitos de acender (fase da escada) */
.mci-album { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 4px; }
.mci-fn { display: grid; grid-template-columns: repeat(4, 1fr); gap: 2px; padding: 4px; border: 2px dashed var(--line); background: var(--bg-2); opacity: 0.45; }
.mci-fn i { display: block; height: 10px; background: var(--surface-2); }
.mci-fn i.on { background: var(--warn); }
.mci-fn.on { opacity: 1; border-style: solid; border-color: var(--good); }
.mci-fn.alvo { opacity: 1; border-style: solid; border-color: var(--accent); }
.mci-fn.no { opacity: 1; border-style: solid; border-color: var(--bad); background: var(--bad-soft); }

/* ---------- celular: o quadro e os controles ficam juntos ---------- */

@media (max-width: 920px) {
  .mci .sg-body { display: flex; flex-direction: column; gap: 12px; }
  .mci .sg-main, .mci .sg-ctrl { display: contents; }
  .mci .sg-head { order: 0; }
  .mci .sg-goal { order: 1; }
  .mci .sg-canvas { order: 2; }
  .mci .sg-caption { order: 3; }
  .mci-controls { order: 4; }
  .mci .sg-formula { order: 5; }
  .mci-msg { order: 6; }
  .mci .sg-actions { order: 7; }
  .mci-table { order: 8; }
}

@media (max-width: 640px) {
  .mci .sg-canvas { height: 300px; }
  .mci .sg-caption { font-size: 10px; gap: 4px; }
  .mci .sg-caption span { padding: 3px 6px; white-space: normal; }
  .mci-reg { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .mci-album { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .mci-dir { padding-left: 4px; padding-right: 4px; font-size: 12px; }
  .mci-tr { padding: 3px 4px; gap: 2px; }
  .mci-bit { width: 20px; }
}

/* ---------- demos da aula (js/games/mlb-circuito/aula.js) ---------- */

.mci-ls-scroll { max-width: 100%; overflow-x: auto; }
.mci-ls-fns { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 6px; }
.mci-ls-fns .ls-bit { min-width: 0; padding: 0 4px; font-size: 13px; }
@media (max-width: 640px) { .mci-ls-fns { grid-template-columns: repeat(4, minmax(0, 1fr)); } }

@media (prefers-reduced-motion: reduce) {
  .mci-sw:active:not(:disabled), .mci-dir:active { transform: none; }
}
