*, *::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:   320px;
  --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"
    "sim     panel";
  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;
}
#back-btn {
  color: var(--dim);
  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: 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;
}

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

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

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

/* ── ÁREA DA SIMULAÇÃO ── */
#sim-area {
  grid-area: sim;
  display: flex;
  flex-direction: column;
  padding: 16px 20px 14px;
  gap: 10px;
  overflow: hidden;
}

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

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

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

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--dim);
}

.legend-swatch {
  width: 18px;
  height: 18px;
  border-radius: 3px;
  flex-shrink: 0;
}

.legend-gradient {
  width: 80px;
  height: 12px;
  border-radius: 6px;
  flex-shrink: 0;
}

.legend-sep {
  width: 1px;
  height: 20px;
  background: var(--border);
}

.legend-text strong {
  color: var(--text);
  font-size: 12px;
}

/* ── STATUS DA RODADA ── */
#round-status {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: var(--dim);
  padding: 0 4px;
  flex-shrink: 0;
  min-height: 20px;
}

#round-phase {
  font-weight: 700;
  color: var(--yellow);
  font-size: 13px;
}

/* ── PAINEL LATERAL ── */
#panel {
  grid-area: panel;
  display: flex;
  flex-direction: column;
  padding: 14px 16px;
  border-left: 1px solid var(--border);
  gap: 12px;
  overflow-y: auto;
  overflow-x: hidden;
}

#panel::-webkit-scrollbar { width: 3px; }
#panel::-webkit-scrollbar-thumb { background: var(--border); }

/* ── CONTROLES ── */
.ctrl-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ctrl-title {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--dim);
}

#btn-start {
  padding: 12px;
  border-radius: var(--radius);
  border: 2px solid var(--green);
  background: rgba(104,211,145,.1);
  color: var(--green);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: background .15s, transform .1s;
  width: 100%;
}
#btn-start:hover { background: rgba(104,211,145,.22); }
#btn-start:active { transform: scale(.97); }

#btn-pause {
  padding: 8px;
  border-radius: var(--radius);
  border: 1px solid var(--yellow);
  background: transparent;
  color: var(--yellow);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
  width: 100%;
}
#btn-pause:hover { background: rgba(246,173,85,.15); }

#btn-advance {
  padding: 8px;
  border-radius: var(--radius);
  border: 1px solid var(--teal);
  background: transparent;
  color: var(--teal);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, opacity .15s;
  width: 100%;
  opacity: 0.55;
}
#btn-advance:hover { background: rgba(79,209,197,.12); opacity: 1; }

#btn-reset {
  padding: 8px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--dim);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color .15s, color .15s;
  width: 100%;
}
#btn-reset:hover { border-color: var(--red); color: var(--red); }

/* ── VELOCÍMETRO MÉDIO ── */
.speed-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.speed-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.speed-label {
  font-size: 12px;
  font-weight: 700;
}

.speed-val {
  font-size: 18px;
  font-weight: 800;
  font-family: 'Courier New', monospace;
}

.speed-bar-wrap {
  height: 10px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
}

.speed-bar {
  height: 100%;
  border-radius: 999px;
  transition: width .5s ease;
}

/* Onças: vermelho → amarelo */
.speed-bar.oncas {
  background: linear-gradient(90deg, #f56565, #f6ad55);
}

/* Gazelas: azul → verde */
.speed-bar.gazelas {
  background: linear-gradient(90deg, #4299e1, #68d391);
}

/* ── GRÁFICO DE HISTÓRICO ── */
#history-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex-shrink: 0;
}

.history-title {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--dim);
}

#history-canvas {
  width: 100%;
  height: 90px;
  display: block;
  border-radius: 6px;
}

/* ── CONTAGEM VIVOS ── */
#pop-counts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.pop-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.pop-emoji { font-size: 18px; }

.pop-count {
  font-size: 22px;
  font-weight: 800;
  font-family: 'Courier New', monospace;
}

.pop-name {
  font-size: 10px;
  color: var(--dim);
  text-transform: uppercase;
  letter-spacing: .06em;
}

/* ── CAIXA CONCEITO ── */
#concept-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;
}
#concept-box strong { color: var(--text); }

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

#phase-emoji { font-size: 52px; }
#phase-title {
  font-size: 22px;
  font-weight: 800;
  color: var(--text);
  text-align: center;
}
#phase-sub {
  font-size: 12px;
  color: var(--dim);
  text-align: center;
  max-width: 340px;
  line-height: 1.6;
}

/* ── SOBREVIVENTES ── */
#survivors-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: 100%;
  max-width: 440px;
  margin-top: 4px;
}
#survivors-section.hidden { display: none; }

#survivors-list {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  justify-content: center;
}

.surv-col {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 150px;
}
.surv-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 3px;
  letter-spacing: .02em;
}
.surv-item {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 5px;
  font-family: 'Courier New', monospace;
}
.onca-item  { color: #f6ad55; background: rgba(246,173,85,.1);  border: 1px solid rgba(246,173,85,.18); }
.gazela-item{ color: #68d391; background: rgba(104,211,145,.1); border: 1px solid rgba(104,211,145,.18); }
.surv-none  { color: var(--dim); font-style: italic; }

#btn-next-gen {
  padding: 9px 26px;
  background: var(--accent);
  border: none;
  border-radius: 9px;
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  pointer-events: auto;
  transition: background .2s, transform .12s;
  letter-spacing: .02em;
}
#btn-next-gen:hover  { background: #9681f9; transform: scale(1.04); }
#btn-next-gen:active { transform: scale(.96); }

/* ── SPEED COLOR SCALE LEGEND ── */
.scale-label {
  display: flex;
  justify-content: space-between;
  font-size: 9px;
  color: var(--dim);
  margin-top: 2px;
}
