:root {
  --bg: #12141a;
  --panel: #1a1d26;
  --panel2: #222633;
  --line: #2e3446;
  --text: #e7e9f0;
  --dim: #969db4;
  --accent: #ffb86b;
  --accent2: #6ba9ff;
  --ok: #58c98a;
  --bad: #ff6b6b;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.5 ui-sans-serif, system-ui, "Segoe UI", sans-serif;
  display: flex; flex-direction: column;
}
code, kbd { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: .92em; }
kbd { background: var(--panel2); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; }

header {
  display: flex; align-items: baseline; gap: 12px;
  padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--panel);
}
header h1 { font-size: 16px; margin: 0; letter-spacing: .2px; }
header .sub { color: var(--dim); font-size: 12px; }
.spacer { flex: 1; }
.status { font-size: 12px; color: var(--dim); }
.status.busy { color: var(--accent); }
.status.ok { color: var(--ok); }
.status.bad { color: var(--bad); }

main { flex: 1; display: grid; grid-template-columns: 290px 1fr 330px; min-height: 0; }
aside { overflow: auto; background: var(--panel); border-right: 1px solid var(--line); }
#info { border-right: 0; border-left: 1px solid var(--line); }
aside section { padding: 12px 14px; border-bottom: 1px solid var(--line); }
aside h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--dim); margin: 0 0 10px; }

label { display: block; font-size: 12px; color: var(--dim); margin-bottom: 8px; }
label.check { display: flex; align-items: center; gap: 7px; color: var(--text); }
input[type=number], input[type=text], select {
  width: 100%; margin-top: 3px; background: var(--panel2); color: var(--text);
  border: 1px solid var(--line); border-radius: 6px; padding: 5px 7px; font: inherit;
}
input[type=range] { width: 100%; accent-color: var(--accent); }
.val { color: var(--text); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.hint { color: var(--dim); font-size: 11.5px; margin: 6px 0 0; }

button {
  background: var(--panel2); color: var(--text); border: 1px solid var(--line);
  border-radius: 7px; padding: 7px 11px; font: inherit; cursor: pointer;
}
button:hover { border-color: var(--accent2); }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--accent); color: #241a0a; border-color: var(--accent); font-weight: 600; }
button.ghost { background: transparent; font-size: 12.5px; padding: 5px 9px; }
.actions { display: flex; flex-direction: column; gap: 8px; }

.drop {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  border: 1.5px dashed var(--line); border-radius: 10px; padding: 16px 10px;
  text-align: center; cursor: pointer; color: var(--dim); margin-bottom: 10px;
}
.drop.over { border-color: var(--accent); color: var(--accent); }
.drop strong { color: var(--text); font-size: 13px; }
/* "?" com a explicacao no hover: o texto continua inteiro, mas so aparece quando
   alguem quer. `tabindex` no span faz o mesmo valer para quem navega por teclado. */
.ajuda {
  display: inline-flex; align-items: center; justify-content: center;
  width: 15px; height: 15px; border-radius: 50%; border: 1px solid var(--line);
  color: var(--dim); font-size: 10px; font-weight: 600; line-height: 1;
  margin-left: 6px; vertical-align: middle; cursor: help; position: relative;
  user-select: none; flex: none;
}
.ajuda:hover, .ajuda:focus-visible { color: var(--text); border-color: var(--dim); outline: none; }
.ajuda .dica {
  /* `fixed` de proposito: dentro do painel, que tem overflow, qualquer sobra do
     balao era cortada. Fixo ele fica por cima de tudo e o JS o encaixa na tela. */
  display: none; position: fixed; left: 0; top: 0; z-index: 90;
  width: 260px; max-width: calc(100vw - 20px); padding: 10px 12px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--panel2);
  color: var(--dim); font-size: 11.5px; font-weight: 400; line-height: 1.5;
  text-align: left; text-transform: none; letter-spacing: 0;
  box-shadow: 0 10px 28px rgba(0, 0, 0, .5); cursor: default;
}
.ajuda:hover .dica, .ajuda:focus-within .dica { display: block; }
.ajuda .dica b { color: var(--text); }
.ajuda .dica table { margin-top: 8px; }

.srcinfo { font-size: 11.5px; color: var(--dim); margin-top: 8px; }
.srcinfo a { color: var(--accent2); }
.srcinfo .aviso { color: var(--bad); }

#canvas { display: flex; flex-direction: column; min-width: 0; background: #0e1015; }
.tabs { display: flex; align-items: center; gap: 6px; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.tab { background: transparent; border-color: transparent; color: var(--dim); font-size: 12.5px; }
.tab.active { background: var(--panel2); color: var(--text); border-color: var(--line); }
.legend { font-size: 11.5px; color: var(--dim); display: flex; align-items: center; gap: 4px; }
.sw { display: inline-block; width: 16px; height: 4px; border-radius: 2px; vertical-align: middle; }
.sw.trace { background: #6ba9ff; opacity: .5; }
.sw.jump { background: #ffb86b; }
.sw.lock { background: #e8b53a; height: 10px; width: 10px; border-radius: 2px; }

#views { flex: 1; overflow: auto; padding: 14px; display: flex; gap: 18px; flex-wrap: wrap; align-content: flex-start; }
#views figure { margin: 0; }
#views figcaption { font-size: 11.5px; color: var(--dim); margin-bottom: 6px; }
.svgbox { background: #0b0d11; border: 1px solid var(--line); border-radius: 8px; padding: 6px; display: inline-block; }
.svgbox svg { display: block; }
#views.only-top #viewBottom, #views.only-bottom #viewTop { display: none; }

.comp { cursor: grab; }
.comp.dragging { cursor: grabbing; opacity: .8; }
.comp.sel rect { stroke: #6ba9ff !important; stroke-width: 2.5 !important; }

/* peca ja movida, esperando o roteamento novo: fica onde voce soltou, piscando de leve */
.comp.pendente rect { stroke: var(--accent) !important; stroke-width: 2.5 !important;
                      stroke-dasharray: 4 3; }
.comp.pendente { animation: pulsa 1.1s ease-in-out infinite; }
@keyframes pulsa { 0%, 100% { opacity: 1; } 50% { opacity: .55; } }

/* Enquanto rotea, a fiacao na tela ainda e a antiga. O veu cobre a area do desenho
   para nao dar a impressao de que aquele resultado ja e o novo, e o spinner deixa
   claro que algo esta acontecendo. */
#canvas { position: relative; }

/* fixed, nao absolute: em tela estreita a pagina rola e um veu ancorado no canvas
   sairia de vista justamente quando ele mais precisa aparecer */
.overlay {
  position: fixed; inset: 0; z-index: 200;
  display: flex; align-items: center; justify-content: center;
  background: rgba(10, 12, 16, .58);
  backdrop-filter: blur(2.5px); -webkit-backdrop-filter: blur(2.5px);
  animation: aparece .16s ease-out;
  cursor: progress;
}
.overlay[hidden] { display: none; }
@keyframes aparece { from { opacity: 0; } to { opacity: 1; } }

.overlay-card {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 20px 28px; box-shadow: 0 8px 30px rgba(0, 0, 0, .45);
}
.overlay-txt { font-size: 13.5px; font-weight: 600; color: var(--text); }
.overlay-sub { font-size: 11.5px; color: var(--dim); text-align: center;
               max-width: 36ch; min-height: 2.6em; line-height: 1.3; }
.overlay-placar { font-size: 12px; font-weight: 600; }
.overlay-placar.bom { color: var(--ok); }
.overlay-placar.ruim { color: var(--accent); }
.overlay-medida { font-size: 11.5px; color: var(--dim); text-align: center; }
.overlay-medida b { color: var(--text); font-size: 15px; font-variant-numeric: tabular-nums; }
.overlay-medida .ganho { color: var(--ok); }
.overlay-nota { font-size: 11px; color: var(--dim); text-align: center; max-width: 260px;
                line-height: 1.4; }
.overlay-curva { width: 240px; height: 54px; }
.overlay-curva:empty { display: none; }
.curva-svg { display: block; width: 100%; height: auto; overflow: visible; }
.overlay-tempo { font-size: 11px; color: var(--dim); font-variant-numeric: tabular-nums; }
#overlayParar { margin-top: 4px; }

.spinner {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--accent);
  animation: gira .8s linear infinite;
}
@keyframes gira { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 2.4s; }
  .comp.pendente { animation: none; }
  .overlay { animation: none; }
}

.statgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 10px; }
.statgrid div { background: var(--panel2); border-radius: 6px; padding: 6px 8px; }
.statgrid b { display: block; font-size: 15px; }
.statgrid span { font-size: 11px; color: var(--dim); }

.msg { border-radius: 6px; padding: 7px 9px; margin-bottom: 6px; font-size: 12px; }
.msg.warn { background: #3a2f14; color: #ffd894; }
.msg.err { background: #3d1d1d; color: #ffb3b3; }
.msg.ok { background: #16331f; color: #b6f0cb; }

.complist { display: flex; flex-direction: column; gap: 4px; }
.crow { display: grid; grid-template-columns: 46px 1fr auto auto; gap: 6px; align-items: center;
        background: var(--panel2); border-radius: 6px; padding: 5px 7px; font-size: 12px; }
.crow.sel { outline: 1px solid var(--accent2); }
.crow b { color: var(--text); }
.crow .meta { color: var(--dim); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.crow button { padding: 2px 6px; font-size: 11px; border-radius: 5px; }
.crow { grid-template-columns: 46px 1fr auto auto auto; }
.crow button.on { background: var(--accent); color: #241a0a; border-color: var(--accent); }

.sizer { background: var(--panel2); border: 1px solid var(--accent2); border-radius: 6px;
         padding: 9px; margin: -2px 0 6px; }
.sizer-help { font-size: 11px; color: var(--dim); margin-bottom: 8px; }
.sizer-grid { display: grid; grid-template-columns: 56px 1fr 56px; gap: 4px;
              align-items: center; justify-items: center; margin-bottom: 6px; }
.sizer-grid input { width: 52px; text-align: center; margin: 0; }
.sizer-mid { font-size: 10.5px; color: var(--dim); text-align: center; line-height: 1.25; }
.sizer-note { font-size: 11px; color: var(--dim); margin-bottom: 8px; font-style: italic; }

.tradeoff { width: 100%; border-collapse: collapse; font-size: 11px; color: var(--dim);
            margin: 6px 0 2px; }
.tradeoff th, .tradeoff td { padding: 2px 4px; text-align: right; }
.tradeoff td:first-child, .tradeoff th:first-child { text-align: left; }
.tradeoff b { color: var(--ok); }

.dec { display: grid; grid-template-columns: auto 1fr auto; gap: 6px; align-items: center;
       background: var(--panel2); border-radius: 6px; padding: 5px 7px; font-size: 12px;
       margin-bottom: 4px; }
.dec .par { color: var(--text); }
.dec .dist { font-size: 11px; text-align: right; white-space: nowrap; }
.dec .dist.bom { color: var(--ok); }
.dec .dist.ruim { color: var(--bad); }
.dec button { padding: 2px 6px; font-size: 11px; border-radius: 5px; }

.build { font-size: 12px; }
.build h3 { font-size: 12px; margin: 10px 0 5px; color: var(--dim); }
.build ol { margin: 0; padding-left: 18px; }
.build li { margin-bottom: 3px; }
.build .netdot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 5px; }

@media (max-width: 1200px) { main { grid-template-columns: 260px 1fr; } #info { grid-column: 1 / -1; border-left: 0; border-top: 1px solid var(--line); } }
