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

:root {
  --bg:        #0f1117;
  --panel:     #1a1d2e;
  --panel2:    #22263a;
  --border:    #2e3354;
  --accent:    #7c6af7;
  --accent2:   #f6c90e;
  --human:     #f56565;
  --ai:        #68d391;
  --draw:      #90cdf4;
  --text:      #e2e8f0;
  --muted:     #718096;
  --radius:    12px;
  --header-h:  60px;
}

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

/* ── Header ── */
#header {
  height: var(--header-h);
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  flex-shrink: 0;
}
#header-left { display: flex; align-items: center; gap: 16px; }
#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: 16px; font-weight: 700; }
#header-sub   { font-size: 13px; color: var(--muted); }

#score-tracker { display: flex; align-items: center; gap: 12px; }
.score-block   { display: flex; flex-direction: column; align-items: center; }
.score-label   { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.score-num     { font-size: 22px; font-weight: 800; line-height: 1; }
.score-num.human { color: var(--human); }
.score-num.ai    { color: var(--ai); }
.score-num.draw  { color: var(--draw); }
.score-sep { color: var(--border); font-size: 20px; }

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

/* ── Main layout ── */
#main {
  display: flex;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

/* ── Left panel ── */
#left-panel {
  width: 380px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 20px;
  padding: 32px 24px;
  border-right: 1px solid var(--border);
  overflow-y: auto;
}

#status-bar {
  font-size: 15px;
  font-weight: 600;
  padding: 10px 24px;
  border-radius: 30px;
  background: var(--panel2);
  border: 1px solid var(--border);
  text-align: center;
  min-width: 280px;
  transition: background .3s;
}
#status-bar.ai-turn    { background: #1a2f1f; border-color: var(--ai); color: var(--ai); }
#status-bar.game-over  { background: #2d1f1f; border-color: var(--human); color: var(--accent2); }
#status-bar.draw-state { background: #1a2030; border-color: var(--draw); color: var(--draw); }

/* ── Board ── */
#board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.cell {
  width: 100px;
  height: 100px;
  background: var(--panel2);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 44px;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .1s;
  user-select: none;
}
.cell:hover:not(.taken) { background: #2a2f4a; border-color: var(--accent); transform: scale(1.04); }
.cell.taken { cursor: default; }
.cell.human { color: var(--human); border-color: #c05050; }
.cell.ai    { color: var(--ai);    border-color: #4a9968; }
.cell.win-cell { animation: pulse-win .5s ease infinite alternate; }
@keyframes pulse-win { from { box-shadow: 0 0 0 transparent; } to { box-shadow: 0 0 16px var(--accent2); border-color: var(--accent2); } }

#board-legend {
  display: flex;
  gap: 32px;
  font-size: 13px;
  color: var(--muted);
}
#board-legend span { display: flex; align-items: center; gap: 6px; }

#new-game-btn {
  padding: 12px 36px;
  border-radius: 30px;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: opacity .2s, transform .1s;
}
#new-game-btn:hover { opacity: .85; transform: scale(1.03); }

/* ── Right panel ── */
#right-panel {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.rp-section {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.rp-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
  margin-bottom: 14px;
}

/* ── Level / train bar ── */
#level-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
#level-label { font-size: 14px; color: var(--muted); }
#level-badge {
  font-size: 13px;
  font-weight: 700;
  padding: 3px 12px;
  border-radius: 20px;
  background: var(--panel2);
  border: 1px solid var(--border);
  color: var(--accent2);
}
#train-bar-bg {
  height: 12px;
  background: var(--panel2);
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 18px;
}
#train-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  border-radius: 8px;
  transition: width .5s ease;
}

/* ── Stats grid ── */
#stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}
.stat-box {
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 6px;
  text-align: center;
}
.stat-num   { font-size: 24px; font-weight: 800; color: var(--accent2); }
.stat-label { font-size: 11px; color: var(--muted); margin-top: 2px; }

/* ── Thought board ── */
#thought-board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 10px;
}
.thought-cell {
  aspect-ratio: 1;
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 700;
  color: var(--muted);
  transition: background .3s, color .3s;
  position: relative;
}
.thought-cell.best {
  background: #1a2f1f;
  border-color: var(--ai);
  color: var(--ai);
  font-size: 22px;
}
.thought-cell.worst {
  background: #1c1c1c;
  border-color: var(--border);
  color: transparent;
}
.thought-cell.neutral {
  background: var(--panel2);
  border-color: var(--border);
  color: transparent;
}
.thought-cell.mid {
  background: rgba(104,211,145, calc(var(--cell-t, 0) * 0.18));
  border-color: rgba(104,211,145, calc(var(--cell-t, 0) * 0.5));
  color: transparent;
}
.thought-cell.occupied {
  background: var(--bg);
  border-color: var(--bg);
  color: var(--border);
  font-size: 12px;
}
#thought-caption {
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  line-height: 1.5;
}

/* ── Action buttons ── */
#actions-section { display: flex; flex-direction: column; gap: 10px; }
#actions-section button {
  padding: 12px 20px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel2);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
  transition: background .2s, border-color .2s;
}
#fast-train-btn:hover  { background: #2a2040; border-color: var(--accent); }
#mega-train-btn:hover  { background: #2a2040; border-color: var(--accent2); }
#reset-btn             { color: var(--human); }
#reset-btn:hover       { background: #2d1a1a; border-color: var(--human); }

#training-msg {
  font-size: 13px;
  color: var(--ai);
  text-align: center;
  min-height: 20px;
  font-weight: 600;
}

/* ── Insight ── */
#insight-text {
  font-size: 14px;
  color: var(--text);
  line-height: 1.7;
}
#insight-text strong { color: var(--accent2); }

/* ── Neural Network diagram ── */
#nn-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

#nn-svg {
  width: 100%;
  max-height: 240px;
}

.nn-layer-label {
  font-size: 11px;
  fill: var(--muted);
  text-anchor: middle;
  font-family: 'Segoe UI', system-ui, sans-serif;
  letter-spacing: .06em;
  text-transform: uppercase;
}

#nn-legend {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
  font-size: 11px;
  color: var(--muted);
}

.nn-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

#nn-status {
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  margin-top: 6px;
  min-height: 18px;
  font-style: italic;
}

/* Animação de backprop */
@keyframes backprop-pulse {
  0%   { opacity: 0.2; stroke-width: 1px; }
  50%  { opacity: 1;   stroke-width: 2.5px; }
  100% { opacity: 0.2; stroke-width: 1px; }
}
.conn-backprop {
  animation: backprop-pulse 0.6s ease-in-out;
}

/* Animação de node aprendendo */
@keyframes node-learn {
  0%   { r: 10; }
  50%  { r: 15; }
  100% { r: 10; }
}
.node-learning {
  animation: node-learn 0.5s ease-in-out;
}

/* ── Curva de aprendizagem ── */
#learn-curve-wrap {
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.rp-subtitle {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--muted);
}
#learn-curve {
  width: 100%;
  height: 80px;
  display: block;
  border-radius: 6px;
}
.scale-label {
  display: flex;
  justify-content: space-between;
  font-size: 9px;
  color: #444;
}
.rp-caption {
  font-size: 11px;
  color: var(--muted);
  margin-top: 8px;
  line-height: 1.5;
}

/* ── Maps row: Onde prefere + O que está pensando lado a lado ── */
#maps-row {
  display: flex;
  gap: 12px;
}
#maps-row .rp-section {
  flex: 1;
  min-width: 0;
  padding: 14px;
}
#maps-row .rp-title {
  font-size: 11px;
  margin-bottom: 10px;
}
#maps-row #thought-caption,
#maps-row #opening-map-caption {
  font-size: 10px;
  margin-top: 6px;
}

/* ── Mapa de abertura ── */
#opening-map {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-bottom: 8px;
}
.om-cell {
  aspect-ratio: 1;
  border-radius: 8px;
  border: 1.5px solid #2e3354;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  padding: 4px;
  position: relative;
  overflow: hidden;
  background: rgba(124,106,247,.04);
}
.om-bar {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  border-radius: 6px 6px 0 0;
  transition: height .4s ease;
  min-height: 4px;
}
.om-val {
  position: relative;
  font-size: 10px;
  font-weight: 700;
  font-family: 'Courier New', monospace;
  z-index: 1;
  line-height: 1;
  margin-bottom: 2px;
}
.om-star {
  position: absolute;
  top: 3px; right: 5px;
  font-size: 10px;
  color: #7c6af7;
}

/* ── Scrollbar ── */
#right-panel::-webkit-scrollbar { width: 6px; }
#right-panel::-webkit-scrollbar-track { background: transparent; }
#right-panel::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
