*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0f1117;
  --surface:   #1a1d27;
  --surface2:  #20243a;
  --border:    #2e3148;
  --accent:    #7c6af7;
  --accent2:   #4fd1c5;
  --human:     #f56565;
  --ai:        #68d391;
  --wire:      #f6ad55;
  --text:      #e2e8f0;
  --text-dim:  #718096;

  /* tabuleiro */
  --cell-size: 90px;
  --cell-gap:  8px;
  --board-w: calc(3 * var(--cell-size) + 2 * var(--cell-gap)); /* 286px */

  --left-w:    330px;
  --header-h:  52px;
  --drawer-h:  42px;
}

html, body {
  width: 100%; height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, sans-serif;
  overflow: hidden;
}

/* ─────────────────────────────────────────
   APP LAYOUT
───────────────────────────────────────── */
#app {
  display: grid;
  grid-template-columns: var(--left-w) 1fr;
  grid-template-rows: var(--header-h) 1fr var(--drawer-h);
  grid-template-areas:
    "header  header"
    "left    right"
    "drawer  drawer";
  width: 100vw;
  height: 100vh;
  transition: grid-template-rows .3s ease;
}
#app.drawer-open {
  grid-template-rows: var(--header-h) 1fr 220px;
}

/* ─────────────────────────────────────────
   HEADER
───────────────────────────────────────── */
#header {
  grid-area: header;
  display: flex;
  align-items: center;
  gap: 0;
  padding: 0 22px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 10;
  flex-shrink: 0;
  position: relative;
}

/* Left section: title + subtitle */
#header-left {
  display: flex;
  align-items: center;
  gap: 14px;
  flex: 1;
}

#header-title {
  font-size: 16px;
  font-weight: 800;
  color: var(--accent);
  letter-spacing: .3px;
  white-space: nowrap;
}
#header-sub {
  font-size: 12px;
  color: var(--text-dim);
}

/* Score tracker — centre of header */
#score-tracker {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(255,255,255,.04);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 5px 18px;
}

.score-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
}
.score-label {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-dim);
}
.score-num {
  font-size: 18px;
  font-weight: 800;
  font-family: 'Courier New', monospace;
  line-height: 1;
}
.score-num.human { color: var(--human); }
.score-num.ai    { color: var(--ai);    }
.score-num.draws { color: var(--text-dim); }
.score-sep {
  font-size: 18px;
  color: var(--border);
  font-weight: 300;
  padding: 0 4px;
  margin-top: 10px;
}

/* ─────────────────────────────────────────
   LEFT PANEL
───────────────────────────────────────── */
#left-panel {
  grid-area: left;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 14px 22px;
  border-right: 1px solid var(--border);
  gap: 12px;
  overflow: visible;
}

/* ── Status bar ── */
#status-bar {
  font-size: 13px;
  font-weight: 700;
  padding: 8px 16px;
  border-radius: 20px;
  background: var(--border);
  transition: background .3s, color .3s, box-shadow .3s;
  white-space: nowrap;
  width: 100%;
  text-align: center;
  letter-spacing: .3px;
}
#status-bar.human-turn   { background: rgba(245,101,101,.15);  color: var(--human); }
#status-bar.ai-turn      { background: rgba(104,211,145,.15);  color: var(--ai);    }
#status-bar.game-over    { background: rgba(124,106,247,.18);  color: var(--accent); }
#status-bar.connect-mode {
  background: rgba(246,173,85,.15);
  color: var(--wire);
  animation: pulse-badge .9s ease-in-out infinite alternate;
}
@keyframes pulse-badge {
  from { box-shadow: 0 0 0 0 rgba(246,173,85,0); }
  to   { box-shadow: 0 0 0 8px rgba(246,173,85,.22); }
}

/* ─────────────────────────────────────────
   TABULEIRO
───────────────────────────────────────── */
#board {
  display: grid;
  grid-template-columns: repeat(3, var(--cell-size));
  grid-template-rows:    repeat(3, var(--cell-size));
  gap: var(--cell-gap);
  width: var(--board-w);
  flex-shrink: 0;
}

.cell {
  width:  var(--cell-size);
  height: var(--cell-size);
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  pointer-events: all;
  position: relative;
  user-select: none;
  transition: border-color .18s, background .18s, transform .12s, box-shadow .18s;
}

/* Hover só em células livres */
.cell:hover:not(.taken) {
  border-color: var(--accent);
  background: rgba(124,106,247,.13);
  transform: scale(1.06);
  box-shadow: 0 0 22px 5px rgba(124,106,247,.2);
  z-index: 2;
}
.cell.taken { cursor: default; }

/* Células ocupadas */
.cell.human { border-color: rgba(245,101,101,.6); background: rgba(245,101,101,.1); }
.cell.ai    { border-color: rgba(104,211,145,.6); background: rgba(104,211,145,.1); }

/* Símbolo ✕ / ○ */
.cell .symbol {
  font-size: 42px;
  font-weight: 900;
  line-height: 1;
  transition: transform .18s;
}
.cell.human .symbol { color: var(--human); }
.cell.ai    .symbol { color: var(--ai);    }

/* Letra A–I */
.cell .cell-letter {
  position: absolute; top: 5px; left: 8px;
  font-size: 11px; font-weight: 700;
  color: transparent;
  font-family: 'Courier New', monospace;
  pointer-events: none;
  transition: color .15s;
}
.cell:hover .cell-letter      { color: var(--accent); }
.cell.node-hover .cell-letter { color: var(--accent); }

/* Score badge */
.cell .cell-score {
  position: absolute;
  bottom: 4px; right: 5px;
  font-size: 18px;
  opacity: 0;
  transition: opacity .25s;
  pointer-events: none;
  line-height: 1;
}
.cell .cell-score.visible { opacity: 1; }

/* Vitória */
.cell.winner {
  border-color: gold !important;
  background: rgba(255,215,0,.13) !important;
  animation: pulse-win .6s ease-in-out infinite alternate;
}
.cell.ai-choice {
  border-color: var(--ai) !important;
  box-shadow: 0 0 22px 7px rgba(104,211,145,.4);
}
@keyframes pulse-win {
  from { box-shadow: 0 0 0 0 rgba(255,215,0,0); }
  to   { box-shadow: 0 0 16px 6px rgba(255,215,0,.5); }
}

/* ── Legenda de cores ── */
#legend {
  display: flex;
  gap: 18px;
  font-size: 11px;
  color: var(--text-dim);
}
#legend span { display: flex; align-items: center; gap: 5px; }
.dot { width: 10px; height: 10px; border-radius: 50%; }

/* ── Divider ── */
.panel-divider {
  width: 100%;
  height: 1px;
  background: var(--border);
  opacity: .5;
  flex-shrink: 0;
}

/* ── Botões gerais ── */
.btn-action {
  display: flex; align-items: center; justify-content: center;
  gap: 7px; padding: 10px 14px; border-radius: 12px;
  border: 1.5px solid var(--border); background: var(--surface);
  color: var(--text); font-size: 13px; font-weight: 600;
  cursor: pointer;
  transition: border-color .15s, background .15s, transform .1s;
  width: 100%;
}
.btn-action:hover {
  border-color: var(--accent);
  background: rgba(124,106,247,.1);
  transform: scale(1.02);
}
.btn-action:active { transform: scale(.97); }

.btn-icon {
  width: 30px; height: 30px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text); font-size: 17px; font-weight: 700;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: border-color .15s, background .15s;
  flex-shrink: 0;
}
.btn-icon:hover { border-color: var(--accent); background: rgba(124,106,247,.1); }
.btn-icon.danger:hover {
  border-color: var(--human);
  background: rgba(245,101,101,.1);
  color: var(--human);
}

/* ── Botão "Jogar pela IA" ── */
#ai-play-btn {
  display: none;
  align-items: center; justify-content: center;
  gap: 8px; padding: 12px 20px; border-radius: 14px;
  border: 2px solid var(--ai); background: rgba(104,211,145,.08);
  color: var(--ai); font-size: 14px; font-weight: 700;
  cursor: pointer;
  transition: background .2s, box-shadow .2s, transform .1s;
  width: 100%;
}
#ai-play-btn:hover {
  background: rgba(104,211,145,.2);
  box-shadow: 0 0 24px 6px rgba(104,211,145,.25);
  transform: scale(1.03);
}
#ai-play-btn:active  { transform: scale(.97); }
#ai-play-btn.animating { pointer-events: none; opacity: .7; }

#game-actions { display: flex; gap: 8px; width: 100%; }
#game-actions .btn-action { flex: 1; font-size: 12px; padding: 9px 8px; }

/* ─────────────────────────────────────────
   RIGHT PANEL
───────────────────────────────────────── */
#right-panel {
  grid-area: right;
  display: flex; flex-direction: column;
  padding: 12px 18px 8px;
  gap: 8px;
  min-height: 0;
  min-width: 0;
}

#right-panel-header {
  display: flex; align-items: center; justify-content: space-between;
  flex-shrink: 0;
  padding-bottom: 2px;
}
#rp-title {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 1.8px; color: var(--text-dim);
}
#hidden-controls {
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; color: var(--text-dim);
}
#hidden-count {
  font-family: 'Courier New', monospace; font-weight: 700;
  color: var(--text); min-width: 18px; text-align: center;
}

/* ── Wire hint ── */
#wire-hint {
  display: none;
  font-size: 11px; color: var(--wire);
  background: rgba(246,173,85,.08);
  border: 1px solid rgba(246,173,85,.22);
  border-radius: 8px; padding: 7px 14px;
  flex-shrink: 0;
}
#wire-hint.visible { display: block; }
#wire-hint kbd {
  background: rgba(246,173,85,.15); border-radius: 4px;
  padding: 1px 5px; font-size: 10px;
}

/* ── Network container ── */
#network-container {
  flex: 1;
  min-height: 0;
  position: relative;
  border-radius: 14px;
  background: rgba(255,255,255,.018);
  border: 1px solid var(--border);
  overflow: hidden;
}

#network-svg {
  width: 100%; height: 100%;
  display: block;
  overflow: visible;
}

/* ── SVG styles ── */
.col-label {
  font-size: 10px; fill: var(--text-dim);
  text-anchor: middle;
  font-family: 'Segoe UI', system-ui, sans-serif;
  text-transform: uppercase; letter-spacing: 1.2px;
}

.col-label-bg {
  fill: rgba(255,255,255,.04);
  rx: 6;
}

.link-visible {
  fill: none;
  stroke-width: 2px;
  stroke-linecap: round;
  transition: stroke .2s;
}
.link-highlight {
  stroke-width: 3px !important;
}
.link-hit {
  fill: none;
  stroke: transparent;
  stroke-width: 22px;
  cursor: pointer;
}

.node-group { transition: opacity .2s; }
.node-circle { transition: fill .25s; }

.node-label {
  text-anchor: middle;
  font-size: 11px;
  font-weight: 800;
  fill: #fff;
  pointer-events: none;
  font-family: 'Courier New', monospace;
}
.node-label-sub {
  text-anchor: middle;
  font-size: 8px;
  fill: rgba(255,255,255,.5);
  pointer-events: none;
}
.node-connect-ring {
  fill: none;
  stroke: var(--wire);
  stroke-width: 2.5;
  stroke-dasharray: 5,3;
  animation: spin-ring 3s linear infinite;
}
@keyframes spin-ring {
  from { stroke-dashoffset: 0; }
  to   { stroke-dashoffset: -40; }
}

.link-badge { pointer-events: none; }

/* ── Drag cursor para nós ocultos ── */
.node-group[data-layer="1"] { cursor: grab; }
.node-group[data-layer="1"]:active { cursor: grabbing; }

/* ─────────────────────────────────────────
   INSPECTOR DRAWER
───────────────────────────────────────── */
#inspector-drawer {
  grid-area: drawer;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: all .3s ease;
  z-index: 5;
}

#inspector-tab {
  height: var(--drawer-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 22px;
  cursor: pointer;
  user-select: none;
  flex-shrink: 0;
  transition: background .15s;
}
#inspector-tab:hover { background: rgba(124,106,247,.06); }
#inspector-tab-label {
  font-size: 12px; color: var(--text-dim);
}
#inspector-tab-arrow {
  font-size: 11px; color: var(--text-dim);
  transition: transform .3s;
}
#app.drawer-open #inspector-tab-arrow { transform: rotate(180deg); }

#inspector-body {
  flex: 1;
  overflow-y: auto; overflow-x: hidden;
  padding: 0 22px 16px;
  display: none;
}
#app.drawer-open #inspector-body { display: block; }

/* Scrollbar styling */
#inspector-body::-webkit-scrollbar { width: 4px; }
#inspector-body::-webkit-scrollbar-track { background: transparent; }
#inspector-body::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ── Inspector: ligação ── */
.insp-header {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 0 8px;
  flex-wrap: wrap;
}
.insp-title {
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 1.2px; color: var(--text-dim);
}
.insp-badge {
  font-size: 12px; font-weight: 700;
  background: rgba(124,106,247,.12);
  border: 1px solid rgba(124,106,247,.28);
  border-radius: 6px; padding: 2px 8px;
  color: var(--accent);
  font-family: 'Courier New', monospace;
}

.op-row { display: flex; flex-direction: column; gap: 8px; }
#op-buttons-row {
  display: flex; flex-wrap: wrap; gap: 6px;
}
.op-btn {
  padding: 5px 12px; border-radius: 8px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text); font-size: 12px; font-weight: 600;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.op-btn:hover  { border-color: var(--accent); background: rgba(124,106,247,.1); }
.op-btn.active { border-color: var(--accent); background: rgba(124,106,247,.18); color: #fff; }

#custom-mult-wrap {
  display: none;
  align-items: center; gap: 8px;
  font-size: 12px; color: var(--text-dim);
}
#custom-mult-wrap.visible { display: flex; }
#custom-mult {
  width: 72px; padding: 4px 8px;
  border-radius: 6px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text);
  font-size: 13px;
}

.delete-btn {
  align-self: flex-start;
  background: rgba(245,101,101,.08) !important;
  border-color: rgba(245,101,101,.35) !important;
  color: var(--human) !important;
}
.delete-btn:hover {
  background: rgba(245,101,101,.2) !important;
  border-color: var(--human) !important;
}

/* ── Inspector: nó ── */
.node-insp-body {
  display: flex; flex-direction: column; gap: 8px;
  padding-top: 4px;
}
.node-insp-block { display: flex; flex-direction: column; gap: 4px; }
.node-insp-eq {
  font-family: 'Courier New', monospace;
  font-size: 11px; color: var(--text-dim);
  background: rgba(255,255,255,.025);
  border-radius: 6px; padding: 6px 10px;
  white-space: pre-wrap; word-break: break-all;
}
.node-insp-divider {
  height: 1px; background: var(--border); margin: 2px 0;
}
.conn-list {
  display: flex; flex-direction: column; gap: 3px;
  font-size: 12px; color: var(--text-dim);
}
.conn-list strong { color: var(--text); }

/* ─────────────────────────────────────────
   GLOBAL TOOLTIP
───────────────────────────────────────── */
#global-tooltip {
  position: fixed;
  z-index: 9999;
  background: #1e2235;
  border: 1px solid #3a3d55;
  border-radius: 10px;
  padding: 10px 14px;
  max-width: 260px;
  font-size: 12px;
  color: var(--text);
  line-height: 1.5;
  box-shadow: 0 8px 32px rgba(0,0,0,.5);
  pointer-events: none;
  opacity: 0;
  transition: opacity .15s;
}
#global-tooltip.visible { opacity: 1; }
