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

:root {
  --bg:       #0f1117;
  --surface:  #1a1d27;
  --border:   #2e3148;
  --accent:   #7c6af7;
  --green:    #68d391;
  --red:      #f56565;
  --yellow:   #f6ad55;
  --teal:     #4fd1c5;
  --text:     #e2e8f0;
  --dim:      #718096;
  --panel-w:  360px;
  --header-h: 50px;
  --radius:   14px;
}

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

/* ── LAYOUT PRINCIPAL ── */
#app {
  display: grid;
  grid-template-rows: var(--header-h) 1fr;
  grid-template-columns: 1fr var(--panel-w);
  grid-template-areas:
    "header  header"
    "game    network";
  width: 100vw;
  height: 100vh;
}

/* ── HEADER ── */
#header {
  grid-area: header;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

#header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

#header-title {
  font-size: 15px;
  font-weight: 800;
  color: var(--accent);
}

#header-badge {
  font-size: 11px;
  color: var(--dim);
  background: rgba(255,255,255,.04);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 3px 10px;
}

#score-box {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

#score-val {
  font-size: 22px;
  font-weight: 800;
  font-family: 'Courier New', monospace;
  color: var(--teal);
}

#best-val {
  font-size: 11px;
  color: var(--dim);
  font-family: 'Courier New', monospace;
}

/* ── ÁREA DO JOGO ── */
#game-area {
  grid-area: game;
  display: flex;
  flex-direction: column;
  padding: 16px 20px 14px;
  gap: 12px;
  overflow: hidden;
}

#game-canvas-wrap {
  position: relative;
  flex: 1;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1.5px solid var(--border);
  overflow: hidden;
  min-height: 0;
}

#game-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* ── Overlay ── */
#overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: rgba(15,17,23,.85);
  backdrop-filter: blur(4px);
  border-radius: var(--radius);
  transition: opacity .25s;
}
#overlay.hidden { opacity: 0; pointer-events: none; }

#overlay-emoji { font-size: 52px; }
#overlay-title {
  font-size: 20px;
  font-weight: 800;
  color: var(--text);
}
#overlay-sub {
  font-size: 12px;
  color: var(--dim);
  text-align: center;
  max-width: 280px;
  line-height: 1.5;
}

/* ── Sensor bar ── */
#sensor-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 16px;
  flex-shrink: 0;
}

.sensor-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--dim);
  white-space: nowrap;
}

.sensor-track {
  flex: 1;
  height: 8px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
  position: relative;
}

.sensor-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: var(--green);
  transition: width .06s linear, background .2s;
}

.sensor-fill.danger {
  background: var(--red);
}

.sensor-far, .sensor-near {
  font-size: 10px;
  color: var(--dim);
  white-space: nowrap;
}
.sensor-near { color: var(--red); }

/* ── Controles ── */
#controls {
  display: flex;
  gap: 10px;
  flex-shrink: 0;
}

#mode-toggle {
  display: flex;
  border-radius: 10px;
  border: 1px solid var(--border);
  overflow: hidden;
}

.mode-btn {
  flex: 1;
  padding: 8px 14px;
  background: transparent;
  border: none;
  color: var(--dim);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.mode-btn.active {
  background: rgba(124,106,247,.2);
  color: var(--accent);
}

#btn-restart {
  padding: 8px 16px;
  border-radius: 10px;
  border: 1.5px solid var(--green);
  background: rgba(104,211,145,.08);
  color: var(--green);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}
#btn-restart:hover {
  background: rgba(104,211,145,.2);
}

/* ── PAINEL DA REDE ── */
#network-panel {
  grid-area: network;
  display: flex;
  flex-direction: column;
  padding: 14px 16px;
  border-left: 1px solid var(--border);
  gap: 12px;
  overflow-y: auto;
  overflow-x: hidden;
}
#network-panel::-webkit-scrollbar { width: 3px; }
#network-panel::-webkit-scrollbar-thumb { background: var(--border); }

/* ── SVG da rede ── */
#network-svg-wrap {
  border-radius: var(--radius);
  background: rgba(255,255,255,.015);
  border: 1px solid var(--border);
  overflow: hidden;
  flex-shrink: 0;
  height: 200px;
}
#network-svg { width: 100%; height: 100%; display: block; }

/* ── Sliders ── */
#sliders {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.slider-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: border-color .2s;
}
.slider-row:hover { border-color: var(--accent); }

.slider-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.slider-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
}

.slider-val {
  font-size: 17px;
  font-weight: 800;
  font-family: 'Courier New', monospace;
  color: var(--accent);
  min-width: 50px;
  text-align: right;
}

input[type=range] {
  -webkit-appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: var(--border);
  outline: none;
  cursor: pointer;
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg);
  box-shadow: 0 0 8px rgba(124,106,247,.5);
  cursor: grab;
  transition: transform .1s;
}
input[type=range]::-webkit-slider-thumb:active {
  cursor: grabbing;
  transform: scale(1.2);
}

.slider-desc {
  font-size: 10px;
  color: var(--dim);
  line-height: 1.4;
}

/* ── Cartão de decisão ── */
#decision-card {
  border-radius: var(--radius);
  padding: 16px;
  border: 2.5px solid var(--border);
  display: flex;
  align-items: center;
  gap: 14px;
  transition: border-color .25s, background .25s;
  flex-shrink: 0;
}
#decision-card.yes {
  border-color: var(--green);
  background: rgba(104,211,145,.08);
}
#decision-card.no {
  border-color: var(--red);
  background: rgba(245,101,101,.06);
}

#decision-emoji {
  font-size: 36px;
  line-height: 1;
}

#decision-text {
  flex: 1;
  font-size: 16px;
  font-weight: 800;
  transition: color .25s;
}
#decision-card.yes #decision-text { color: var(--green); }
#decision-card.no  #decision-text { color: var(--red); }

#decision-bar-wrap {
  width: 10px;
  height: 60px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}
#decision-bar {
  width: 100%;
  border-radius: 999px;
  transition: height .1s ease, background .25s;
}

/* ── Caixa de desafio ── */
#challenge-box {
  background: rgba(124,106,247,.05);
  border: 1px solid rgba(124,106,247,.18);
  border-radius: var(--radius);
  padding: 12px 14px;
  font-size: 11px;
  color: var(--dim);
  line-height: 1.7;
  flex-shrink: 0;
}
#challenge-box strong { color: var(--text); }

/* ── Keyboard hint ── */
#kb-hint {
  font-size: 10px;
  color: var(--dim);
  text-align: center;
  flex-shrink: 0;
}
#kb-hint kbd {
  background: rgba(255,255,255,.06);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 10px;
}
