/* Simulador de partidas — tema claro de alto contraste (sala e projetor) */
:root {
  --fundo: #eef0f3;
  --painel: #ffffff;
  --texto: #15181d;
  --texto-2: #505866;
  --borda: #cfd4dc;
  --traco: #1d2128;
  --mec: #6b7280;

  --cmd-vivo: #e05a00;
  --cmd-neutro: #3b82f6;
  --fase-r: #d32f2f;
  --fase-s: #2e7d32;
  --fase-t: #1565c0;
  --bobina-on: #ffb300;
  --lampada-on: #ffe14d;
  --perigo: #c62828;
  --atencao: #ef6c00;
  --acento: #1565c0;

  --raio: 8px;
  font-family: "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--texto);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--fundo);
}

body {
  display: flex;
  flex-direction: column;
  min-height: 600px;
  overflow: hidden;
}

/* ---------- Topo ---------- */
.topo {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 5px 12px 5px 16px;
  background: #1d2733;
  color: #fff;
}
.topo h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.2px;
}
.partida-nome {
  font-size: 16px;
  color: #ffd180;
  font-weight: 600;
}
.topo-sim {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 6px;
}
.topo .bt { background: #2c3a4a; border-color: #4a5b6e; color: #e8eef5; padding: 3px 9px; font-size: 13px; }
.topo .bt:hover:not(:disabled) { background: #3a4b5f; }
.topo .bt[aria-pressed="true"] { background: #ffb300; border-color: #ffb300; color: #1d2733; }
.relogio {
  min-width: 118px;
  margin-right: 6px;
  font-variant-numeric: tabular-nums;
  font-size: 15px;
  color: #cfd8e3;
}

/* ---------- Controles ---------- */
.controles {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  padding: 6px 12px 8px;
  background: var(--painel);
  border-bottom: 1px solid var(--borda);
}
.grupo {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.grupo-titulo {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--texto-2);
}
.linha {
  display: flex;
  align-items: center;
  gap: 6px;
}
.valor {
  min-width: 36px;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}
input[type="range"] { width: 88px; accent-color: var(--acento); }

.bt {
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 5px 9px;
  border: 1px solid #aeb5c0;
  border-radius: 6px;
  background: #f7f8fa;
  color: var(--texto);
  cursor: pointer;
  white-space: nowrap;
}
.bt:hover:not(:disabled) { background: #e9ecf1; }
.bt:disabled { opacity: 0.45; cursor: default; }
.bt:focus-visible { outline: 3px solid #90caf9; outline-offset: 1px; }
.bt[aria-pressed="true"] { background: var(--acento); border-color: var(--acento); color: #fff; }
.bt-alerta[aria-pressed="true"] { background: var(--atencao); border-color: var(--atencao); }
.bt-perigo { background: var(--perigo); border-color: var(--perigo); color: #fff; }
.bt-perigo:hover:not(:disabled) { background: #a71f1f; }

/* Botoeiras (cogumelo) */
.botoeira {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px 3px 4px;
  border: 1px solid #aeb5c0;
  border-radius: 22px;
  background: #f7f8fa;
  font: inherit;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}
.botoeira .cabeca {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.3), 0 2px 0 rgba(0, 0, 0, 0.25);
  transition: transform 0.04s;
}
.botoeira.na .cabeca { background: #2e9e44; }
.botoeira.nf .cabeca { background: #d32f2f; }
.botoeira .rot { font-weight: 500; color: var(--texto-2); font-size: 13px; }
.botoeira.pressionado .cabeca { transform: translateY(2px) scale(0.92); box-shadow: inset 0 2px 3px rgba(0, 0, 0, 0.4); }
.botoeira.pressionado { background: #e3e7ee; }

.segmentado { display: flex; }
.segmentado .bt { border-radius: 0; margin-left: -1px; padding: 5px 8px; }
.segmentado .bt:first-child { border-radius: 6px 0 0 6px; margin-left: 0; }
.segmentado .bt:last-child { border-radius: 0 6px 6px 0; }

.medidor {
  position: relative;
  width: 92px;
  height: 24px;
  border: 1px solid #aeb5c0;
  border-radius: 6px;
  background: #f1f3f6;
  overflow: hidden;
}
.medidor-barra {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0;
  background: linear-gradient(90deg, #ffca28, #ef6c00 70%, #c62828);
}
.medidor-texto {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* ---------- Área principal ---------- */
.principal {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1.65fr) minmax(0, 1fr);
  gap: 8px;
  padding: 8px;
}

.diagramas, .graficos {
  min-height: 0;
  background: var(--painel);
  border: 1px solid var(--borda);
  border-radius: var(--raio);
}

.diagramas {
  position: relative;
  display: flex;
  flex-direction: column;
  padding: 6px 8px;
}
.folhas {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1.15fr 1fr;
  gap: 8px;
}
.folha {
  margin: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.folha figcaption {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--texto-2);
  padding: 2px 4px 4px;
}
.diagrama {
  flex: 1;
  min-height: 0;
  width: 100%;
  height: 100%;
}
.texto-apoio {
  margin: 6px 4px 2px;
  font-size: 13px;
  line-height: 1.4;
  color: var(--texto-2);
}

/* Alertas sobre o diagrama */
.alertas {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.alertas:not(:empty) { margin-bottom: 6px; }
.alerta {
  padding: 7px 12px;
  border-radius: 8px;
  color: #fff;
  font-size: 14px;
  line-height: 1.35;
}
.alerta strong { font-size: 15px; letter-spacing: 0.3px; margin-right: 8px; }
.alerta.perigo { background: var(--perigo); }
.alerta.atencao { background: var(--atencao); }
.alerta.info { background: #37474f; }

/* ---------- Gráficos ---------- */
.graficos {
  display: flex;
  flex-direction: column;
  padding: 4px 6px 6px;
  gap: 2px;
}
.grafico { position: relative; min-height: 0; }
.grafico canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.grafico-digital { flex: 0 0 auto; }
.graficos-rodape { display: flex; justify-content: flex-end; padding-top: 4px; }

/* ---------- Modal de zoom ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 14, 20, 0.55);
}
.modal[hidden] { display: none; }
.modal-caixa {
  width: min(96vw, 1100px);
  height: min(90vh, 640px);
  display: flex;
  flex-direction: column;
  background: var(--painel);
  border-radius: 10px;
  padding: 10px 14px 14px;
}
.modal-topo { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.modal-topo h2 { margin: 0 auto 0 0; font-size: 17px; }
#g-zoom { flex: 1; min-height: 0; width: 100%; }

/* ---------- Símbolos do diagrama ---------- */
.diagrama line, .diagrama path, .diagrama polyline {
  stroke: var(--traco);
  stroke-width: 2.2;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.diagrama .fino { stroke-width: 1.3; }
.diagrama .acion { stroke-width: 1.9; }
.diagrama .mec { stroke: var(--mec); stroke-width: 1.4; stroke-dasharray: 4 3; fill: none; }
.diagrama text { font-family: inherit; fill: var(--texto); }
.diagrama text.nome { font-size: 15px; font-weight: 700; }
.diagrama text.num { font-size: 10px; fill: #6b7280; }
.diagrama text.rotulo-fonte { font-size: 16px; font-weight: 700; }
.diagrama text.contagem { font-size: 11px; fill: var(--texto-2); font-variant-numeric: tabular-nums; }
.diagrama text.motor-m { font-size: 21px; font-weight: 700; }
.diagrama text.motor-til { font-size: 13px; }
.diagrama text.rpm-motor { font-size: 12px; font-weight: 600; fill: var(--texto-2); font-variant-numeric: tabular-nums; }
.diagrama .borne { fill: #fff; stroke: var(--traco); stroke-width: 2; }
.diagrama circle.juncao { fill: var(--traco); stroke: none; }
.diagrama .corpo-bobina, .diagrama .corpo-temp { fill: #fff; stroke: var(--traco); stroke-width: 2.2; transition: fill 0.12s; }
.diagrama .corpo-lampada { fill: #fff; stroke: var(--traco); stroke-width: 2.2; }
.diagrama .brilho { fill: rgba(255, 214, 0, 0.45); stroke: none; opacity: 0; }
.diagrama .corpo-motor { fill: #fff; stroke: var(--traco); stroke-width: 2.4; transition: fill 0.3s; }
.diagrama .marca-rotor { fill: var(--traco); }
.diagrama .seta { stroke: var(--fase-s); stroke-width: 2.4; }
.diagrama .barra-fundo { fill: #e3e6eb; }
.diagrama .barra-tempo { fill: var(--acento); }
.diagrama .caixa { stroke-dasharray: 4 3; }

/* Condutores (fios e partes internas) com a cor do nó */
.diagrama .viva, .diagrama .viva > * { stroke: var(--cmd-vivo); stroke-width: 3.4; }
.diagrama .neutro, .diagrama .neutro > * { stroke: var(--cmd-neutro); stroke-width: 3.4; }
.diagrama .fase-R, .diagrama .fase-R > * { stroke: var(--fase-r); stroke-width: 3.4; }
.diagrama .fase-S, .diagrama .fase-S > * { stroke: var(--fase-s); stroke-width: 3.4; }
.diagrama .fase-T, .diagrama .fase-T > * { stroke: var(--fase-t); stroke-width: 3.4; }
.diagrama .curto, .diagrama .curto > * { stroke: #ff1744; stroke-width: 4.5; }
.pisca .diagrama .curto, .pisca .diagrama .curto > * { stroke: #5c0011; }
.diagrama circle.juncao.viva { fill: var(--cmd-vivo); }
.diagrama circle.juncao.neutro { fill: var(--cmd-neutro); }
.diagrama circle.juncao.fase-R { fill: var(--fase-r); }
.diagrama circle.juncao.fase-S { fill: var(--fase-s); }
.diagrama circle.juncao.fase-T { fill: var(--fase-t); }

/* Estados */
.elem .atuador { transition: transform 0.06s; }
.elem.pressionado .atuador { transform: translateX(6px); }
.elem.energizado .corpo-bobina { fill: var(--bobina-on); }
.elem.contando .corpo-temp { fill: #bbdefb; }
.elem.temporizado .corpo-temp { fill: var(--acento); }
.elem.aceso .corpo-lampada { fill: var(--lampada-on); }
.elem.aceso .brilho { opacity: 1; }
.elem.atuado .acion, .elem.atuado .caixa { stroke: var(--perigo); stroke-width: 2.2; }
.elem .seta-giro { display: none; }
.elem.girando .seta-giro { display: inline; }
.elem.girando .corpo-motor { fill: #e8f5e9; }
.elem .alvo { fill: transparent; stroke: none; }
.elem.botao { cursor: pointer; }
.elem.botao:hover .alvo { fill: rgba(21, 101, 192, 0.07); }

/* Modo "Quebrar": o elemento retirado some (fica bem translúcido) */
.elem .jumper { display: none; }
.elem.q-jumper .jumper { display: inline; }
.elem > * { transition: opacity 0.25s; }
.elem.quebrado > *:not(.jumper):not(.alvo) { opacity: 0.13; }
.modo-quebrar .elem.quebravel { cursor: pointer; }
.modo-quebrar .elem.quebravel .alvo { fill: rgba(239, 108, 0, 0.08); stroke: var(--atencao); stroke-width: 1.5; stroke-dasharray: 5 3; }
.modo-quebrar .elem.quebravel:hover .alvo { fill: rgba(239, 108, 0, 0.18); }

/* Legenda das cores */
.legenda {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  margin: 4px 4px 0;
  font-size: 12px;
  color: var(--texto-2);
}
.legenda span { display: inline-flex; align-items: center; gap: 5px; }
.legenda i { display: inline-block; width: 18px; height: 4px; border-radius: 2px; }
.dica-quebrar {
  margin: 4px 4px 0;
  padding: 5px 10px;
  border-radius: 6px;
  background: #fff3e0;
  color: #8a4b00;
  font-size: 13px;
}
.dica-quebrar[hidden] { display: none; }

/* Telas menores (1366×768 e abaixo) */
@media (max-height: 700px) {
  .controles { padding-top: 4px; padding-bottom: 5px; }
  .bt { padding: 4px 9px; font-size: 13px; }
}
@media (max-width: 900px) {
  body { overflow: auto; }
  .principal { grid-template-columns: 1fr; }
  .graficos { min-height: 520px; }
}

/* ---------- Tela inicial ---------- */
.topo .subtitulo { font-size: 14px; color: #cfd8e3; }
.inicio {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  width: 100%;
  max-width: 980px;
  margin: 0 auto;
  padding: 22px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.inicio h2 { margin: 0 0 6px; font-size: 18px; }
.inicio-codigo {
  padding: 16px 18px;
  background: var(--painel);
  border: 1px solid var(--borda);
  border-radius: 10px;
}
.inicio-codigo p { margin: 0 0 10px; color: var(--texto-2); }
.form-liberar { display: flex; gap: 8px; max-width: 460px; }
.form-liberar input {
  flex: 1;
  min-width: 0;
  padding: 9px 12px;
  border: 1px solid #aeb5c0;
  border-radius: 8px;
  font: inherit;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
}
.form-liberar input:focus { outline: 3px solid #90caf9; outline-offset: 1px; }
.form-liberar .bt { font-size: 16px; padding: 8px 18px; }
.liberar-msg { min-height: 20px; margin: 8px 0 0 !important; font-size: 14px; font-weight: 600; }
.liberar-msg.erro { color: var(--perigo); }
.liberar-msg.ok { color: #2e7d32; }

.cartoes { display: flex; flex-direction: column; gap: 10px; }
.cartao {
  display: grid;
  grid-template-columns: 36px 96px minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 10px 16px 10px 12px;
  border: 1px solid var(--borda);
  border-radius: 10px;
  background: var(--painel);
  font: inherit;
  text-align: left;
  color: var(--texto);
  cursor: pointer;
}
.cartao.liberada:hover { border-color: var(--acento); box-shadow: 0 2px 10px rgba(21, 101, 192, 0.12); }
.cartao.trancada { background: #f4f5f7; color: var(--texto-2); cursor: default; }
.cartao.destaque { border-color: #2e9e44; box-shadow: 0 0 0 2px rgba(46, 158, 68, 0.35); }
.cartao-num {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: #1d2733;
  color: #fff;
  font-weight: 700;
}
.cartao.trancada .cartao-num { background: #9aa1ab; }
.cartao-mini {
  width: 96px;
  height: 84px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  background: #fbfcfd;
  border: 1px solid #e6e9ee;
}
.cartao-mini .mini-comando.diagrama { flex: none; width: 90px; height: 80px; }
.mini-comando text { display: none; }
.mini-comando line, .mini-comando path, .mini-comando polyline, .mini-comando rect, .mini-comando circle { vector-effect: non-scaling-stroke; stroke-width: 1.4; }
.mini-comando .mec { stroke-width: 0.8; }
.cadeado { font-size: 30px; opacity: 0.6; }
.cartao-texto { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.cartao-texto strong { font-size: 17px; }
.cartao-texto small { font-size: 13px; color: var(--texto-2); line-height: 1.35; }
.cartao-acao { font-weight: 700; color: var(--acento); white-space: nowrap; }
.cartao.trancada .cartao-acao { color: #9aa1ab; }

.inicio-rodape {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-top: auto;
  padding-top: 10px;
  border-top: 1px solid var(--borda);
}
.link {
  padding: 4px 0;
  border: none;
  background: none;
  font: inherit;
  font-size: 13px;
  color: var(--texto-2);
  text-decoration: underline;
  cursor: pointer;
}
.prof-acoes { display: inline-flex; gap: 8px; }
.prof-acoes[hidden] { display: none; }

/* ---------- Ocultar gráficos / leitura rápida ---------- */
.barra-diagramas { display: flex; align-items: center; justify-content: flex-end; gap: 10px; min-height: 0; }
.diagramas .barra-diagramas { margin-bottom: 2px; }
.bt.bt-pequeno { padding: 3px 9px; font-size: 12.5px; }
.leitura { font-size: 14px; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--texto); background: #f1f3f6; border-radius: 6px; padding: 3px 10px; }
.leitura[hidden] { display: none; }
.principal.sem-graficos { grid-template-columns: minmax(0, 1fr); }
.principal.sem-graficos .graficos { display: none; }
.principal.sem-graficos .folhas { grid-template-columns: 1fr 1fr; }
.graficos-rodape { align-items: center; gap: 8px; }
.fixada-rotulo { margin-right: auto; font-size: 12px; color: var(--texto-2); }
#tempo-d1 { width: 64px; font: inherit; font-size: 14px; padding: 4px 6px; border: 1px solid #aeb5c0; border-radius: 6px; }
.grupo[hidden] { display: none; }
.dica-zoom { margin-left: auto; font-size: 11.5px; color: #8a919c; }
.diagrama { cursor: default; touch-action: none; }
.diagrama.ampliado { cursor: grab; }

/* ---------- Só comando / só potência ---------- */
.principal .folhas.so-cmd, .principal .folhas.so-pot { grid-template-columns: minmax(0, 1fr); }
.folhas.so-cmd .folha:nth-child(2), .folhas.so-pot .folha:nth-child(1) { display: none; }
.barra-diagramas .segmentado .bt { margin-left: -1px; }
.barra-diagramas .bt[aria-pressed="true"] { background: #1d2733; border-color: #1d2733; color: #fff; }
.folhas.so-cmd figcaption, .folhas.so-pot figcaption { display: none; }
