/* ── Reset & Base ── */
* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0d1117;
  --panel:     #161b22;
  --border:    #30363d;
  --text:      #e6edf3;
  --muted:     #8b949e;
  --accent:    #58a6ff;
  --green:     #3fb950;
  --red:       #f85149;
  --yellow:    #d29922;
  --radius:    12px;
  --col-a:     #4d9de0;   /* cor classe 0: azul */
  --col-b:     #e15554;   /* cor classe 1: vermelho */
}

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Header ── */
#header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
#header-left  { display: flex; align-items: center; gap: 12px; }
#back-btn {
  color: var(--muted); text-decoration: none;
  font-size: 13px; padding: 4px 10px;
  border: 1px solid var(--border); border-radius: 6px;
  transition: color .2s, border-color .2s;
}
#back-btn:hover { color: var(--text); border-color: var(--accent); }
#header-title  { font-size: 1rem; font-weight: 700; }
#header-badge  {
  font-size: .7rem; color: var(--muted);
  background: #21262d; padding: 3px 10px;
  border-radius: 20px; border: 1px solid var(--border);
}

/* ── Botões globais ── */
.btn-primary {
  background: var(--accent); color: #0d1117;
  border: none; border-radius: 8px;
  padding: 11px 20px; font-size: .95rem; font-weight: 700;
  cursor: pointer; transition: opacity .2s, transform .1s; flex: 1;
}
.btn-primary:hover  { opacity: .88; }
.btn-primary:active { transform: scale(.97); }

.btn-danger {
  background: var(--red); color: #fff;
  border: none; border-radius: 8px;
  padding: 11px 20px; font-size: .95rem; font-weight: 700;
  cursor: pointer; transition: opacity .2s; flex: 1;
}
.btn-danger:hover { opacity: .88; }

.btn-secondary {
  background: transparent; color: var(--accent);
  border: 1px solid var(--accent); border-radius: 8px;
  padding: 8px 14px; font-size: .82rem; font-weight: 600;
  cursor: pointer; transition: background .2s; width: 100%;
}
.btn-secondary:hover { background: rgba(88,166,255,.08); }

.btn-ghost {
  background: transparent; color: var(--muted);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 6px 12px; font-size: .82rem;
  cursor: pointer; transition: color .2s, border-color .2s;
}
.btn-ghost:hover { color: var(--text); border-color: var(--muted); }

.hidden { display: none !important; }

/* ── App wrapper ── */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ── Layout principal ── */
#main-layout {
  flex: 1;
  display: flex;
  overflow: hidden;
  gap: 0;
}

/* ══════════════════════════════════
   COLUNA ESQUERDA — CANVAS
══════════════════════════════════ */
#canvas-col {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px;
  gap: 10px;
  position: relative;
}

/* Badge de precisão */
#acc-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 18px;
  border-radius: 30px;
  border: 2px solid transparent;
  font-size: .88rem;
  font-weight: 700;
  transition: background .4s, border-color .4s, color .4s;
  align-self: center;
}
#acc-val   { font-size: 1.3rem; font-weight: 900; }
#acc-emoji { font-size: 1.1rem; }
#acc-label { font-size: .72rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }

.acc-none  { background: #21262d; border-color: var(--border); color: var(--muted); }
.acc-bad   { background: rgba(248,81,73,.12); border-color: var(--red);    color: var(--red);    }
.acc-ok    { background: rgba(210,153,34,.12); border-color: var(--yellow); color: var(--yellow); }
.acc-good  { background: rgba(63,185,80,.12);  border-color: var(--green);  color: var(--green);  }

/* Canvas wrap */
#canvas-wrap {
  position: relative;
  --size: min(calc(100vh - 200px), calc(100vw - 380px));
  width: var(--size);
  height: var(--size);
  border-radius: var(--radius);
  overflow: hidden;
  border: 2px solid var(--border);
  background: #0a0e14;
  transition: border-color .3s;
}
#canvas-wrap.training { border-color: var(--accent); }

#canvas-bg, #canvas-pts {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
}
#canvas-bg  { z-index: 1; image-rendering: pixelated; }
#canvas-pts { z-index: 2; cursor: crosshair; }

#canvas-net {
  width: 100%; display: block;
  border-radius: 8px;
  background: #0a0e14;
  border: 1px solid var(--border);
  margin-top: 2px;
}

/* Overlay inicial */
#canvas-hint-overlay {
  position: absolute; inset: 0; z-index: 3;
  display: flex; align-items: center; justify-content: center;
  background: rgba(13,17,23,.75);
  transition: opacity .3s;
}
#canvas-hint-overlay.hidden { opacity: 0; pointer-events: none; }
#canvas-hint-text {
  text-align: center;
  font-size: .95rem; color: var(--muted); line-height: 1.7;
}

/* Mini gráfico de loss */
#loss-row {
  display: flex; align-items: center; gap: 8px;
  width: var(--size, 300px);
}
#loss-label { font-size: .75rem; color: var(--muted); white-space: nowrap; }
#canvas-loss {
  flex: 1; height: 32px;
  border-radius: 6px;
  background: #0a0e14;
  border: 1px solid var(--border);
}
#loss-val   { font-size: .78rem; color: var(--accent); white-space: nowrap; min-width: 42px; text-align: right; }
#epoch-val  { font-size: .72rem; color: var(--muted); white-space: nowrap; min-width: 58px; }

/* ══════════════════════════════════
   COLUNA DIREITA — CONTROLES
══════════════════════════════════ */
#controls-col {
  width: 300px;
  flex-shrink: 0;
  border-left: 1px solid var(--border);
  background: var(--panel);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0;
}

/* Seções */
.ctrl-section {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex-shrink: 0;   /* impede o flex de encolher as seções em vez de scrollar */
}
.ctrl-title {
  font-size: .8rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted);
}
.ctrl-sub { font-size: .78rem; color: var(--muted); }

/* Dataset buttons */
#dataset-btns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}
.ds-btn {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 8px;
  padding: 10px 6px;
  font-size: .75rem; font-weight: 600;
  cursor: pointer;
  text-align: center; line-height: 1.5;
  transition: border-color .2s, color .2s, background .2s;
}
.ds-btn:hover  { border-color: var(--accent); color: var(--text); }
.ds-btn.active {
  border-color: var(--accent);
  background: rgba(88,166,255,.1);
  color: var(--text);
}

#ds-hint {
  font-size: .75rem; color: var(--muted);
  background: #21262d;
  padding: 7px 10px; border-radius: 6px;
  line-height: 1.5;
  min-height: 0;
}
#ds-hint:empty { display: none; }

/* Diagrama de arquitetura */
#arch-diagram {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 8px 0;
  flex-wrap: nowrap;
  overflow-x: auto;
}
.arch-layer-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  flex-shrink: 0;
}
.arch-node {
  width: 18px; height: 18px;
  border-radius: 50%;
  border: 2px solid;
  transition: background .2s;
}
.arch-node.input  { border-color: var(--muted);   background: transparent; }
.arch-node.hidden { border-color: var(--accent);  background: rgba(88,166,255,.15); }
.arch-node.output.cls0 { border-color: var(--col-a); background: rgba(77,157,224,.25); }
.arch-node.output.cls1 { border-color: var(--col-b); background: rgba(225,85,84,.25); }
.arch-node.extra  { border-color: #30363d; background: transparent; opacity: .4; }
.arch-arrow { font-size: .8rem; color: var(--border); flex-shrink: 0; }
.arch-label { font-size: .6rem; color: var(--muted); text-align: center; margin-top: 2px; }

/* Layer rows */
#arch-layers {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.layer-row {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  padding: 7px 10px;
}
.layer-label { font-size: .75rem; color: var(--muted); flex: 1; }
.layer-neurons { font-size: .88rem; font-weight: 700; min-width: 16px; text-align: center; }
.btn-nn {
  width: 24px; height: 24px;
  background: #21262d; border: 1px solid var(--border);
  color: var(--text); border-radius: 5px;
  font-size: .9rem; font-weight: 700;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: background .15s;
}
.btn-nn:hover { background: #2c3340; }
.btn-del-layer {
  background: transparent; border: none;
  color: var(--muted); font-size: .78rem;
  cursor: pointer; padding: 2px 5px; border-radius: 4px;
  transition: color .2s;
}
.btn-del-layer:hover { color: var(--red); }

#arch-hint {
  font-size: .75rem; line-height: 1.5;
  padding: 6px 10px; border-radius: 6px;
  min-height: 0;
}
#arch-hint:empty { display: none; }
#arch-hint.warn  { background: rgba(210,153,34,.1); color: var(--yellow); border: 1px solid rgba(210,153,34,.3); }
#arch-hint.good  { background: rgba(63,185,80,.08);  color: var(--green);  border: 1px solid rgba(63,185,80,.3);  }

/* Treino */
#train-speed-row {
  display: flex; align-items: center; gap: 8px;
}
#speed-slider { flex: 1; accent-color: var(--accent); }
#speed-label  { font-size: .8rem; color: var(--accent); min-width: 60px; }

#train-btns { display: flex; gap: 8px; flex-wrap: wrap; }
#train-btns .btn-secondary { flex: 1; width: auto; font-size: .88rem; padding: 11px 14px; font-weight: 700; }

#challenge-hint {
  font-size: .78rem; line-height: 1.55;
  padding: 8px 12px; border-radius: 8px;
  background: rgba(88,166,255,.06);
  border: 1px solid rgba(88,166,255,.2);
  color: var(--accent);
}

/* ── Step badges ── */
.step-badge {
  display: inline-flex;
  align-items: center; justify-content: center;
  width: 18px; height: 18px;
  background: var(--accent); color: #0d1117;
  border-radius: 50%; font-size: .65rem; font-weight: 800;
  vertical-align: middle; margin-right: 4px;
}

.section-desc {
  font-size: .74rem; color: var(--muted);
  line-height: 1.5;
  margin-top: -4px;
}

/* ── Intro blurb ── */
#intro-blurb {
  padding: 12px 16px;
  font-size: .78rem;
  color: var(--muted);
  line-height: 1.6;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

/* ── Responsividade ── */
@media (max-width: 700px) {
  #main-layout   { flex-direction: column; }
  #controls-col  { width: 100%; border-left: none; border-top: 1px solid var(--border); max-height: 45vh; }
  #canvas-col    { padding: 10px; }
  #canvas-wrap   { --size: min(60vw, 55vh); }
}
