/* =====================================================
   style.css — RoboCode Visual System
   Tema: dark, tech-educational, game-like
   Fonte de display: "Share Tech Mono" (monospace tech)
   Fonte de corpo: "DM Sans" (legível, moderna)
   ===================================================== */

/* ── GOOGLE FONTS ─────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Share+Tech+Mono&family=DM+Sans:wght@400;500;700&display=swap');

/* ── VARIÁVEIS DE DESIGN (Design Tokens) ──────────── */
/* Centralizar aqui facilita mudanças de tema no futuro */
:root {
  /* Cores base */
  --bg-deep:        #0a0c10;   /* fundo mais escuro */
  --bg-panel:       #0f1117;   /* painéis */
  --bg-surface:     #161b22;   /* cards, itens */
  --bg-elevated:    #1c2128;   /* hover, destaque */
  --border:         #30363d;   /* bordas sutis */
  --border-bright:  #484f58;   /* bordas de foco */

  /* Cores de acento — paleta ciano/verde tech */
  --accent:         #00e5ff;   /* ciano primário */
  --accent-dim:     #00b8d4;   /* ciano mais escuro */
  --accent-glow:    rgba(0, 229, 255, 0.15);
  --green:          #39d353;   /* sucesso, executando */
  --yellow:         #e3b341;   /* aviso, wait */
  --red:            #f85149;   /* erro, colisão */
  --purple:         #a371f7;   /* futuro/bloqueado */

  /* Cores de texto */
  --text-primary:   #e6edf3;
  --text-secondary: #8b949e;
  --text-muted:     #484f58;

  /* Tipografia */
  --font-mono:      'Share Tech Mono', 'Courier New', monospace;
  --font-sans:      'DM Sans', sans-serif;

  /* Espaçamento e geometria */
  --radius-sm:      4px;
  --radius-md:      8px;
  --radius-lg:      12px;
  --panel-gap:      12px;
  --header-height:  52px;

  /* Transições */
  --transition:     0.18s ease;
}

/* ── RESET E BASE ─────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  overflow: hidden; /* sem scroll — tudo cabe na tela */
}

body {
  background: var(--bg-deep);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── APP CONTAINER ────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* ── HEADER ───────────────────────────────────────── */
#header {
  height: var(--header-height);
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  flex-shrink: 0;
  /* Linha de luz sutil no topo */
  box-shadow: 0 1px 0 var(--border), inset 0 1px 0 rgba(0, 229, 255, 0.05);
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-icon {
  font-size: 22px;
  color: var(--accent);
  filter: drop-shadow(0 0 6px var(--accent));
  line-height: 1;
}

.brand-name {
  font-family: var(--font-mono);
  font-size: 18px;
  color: var(--text-primary);
  letter-spacing: 2px;
  text-transform: uppercase;
}

.brand-version {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-muted);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  letter-spacing: 1px;
}

/* Badge de status no header */
.status-badge {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 1.5px;
  padding: 4px 12px;
  border-radius: 20px;
  border: 1px solid currentColor;
  transition: all 0.3s ease;
}

.status-idle    { color: var(--text-secondary); border-color: var(--border); }
.status-running { color: var(--green); border-color: var(--green); box-shadow: 0 0 8px rgba(57, 211, 83, 0.3); animation: pulse-green 1s ease infinite; }
.status-done    { color: var(--accent); border-color: var(--accent); box-shadow: 0 0 8px var(--accent-glow); }
.status-error   { color: var(--red); border-color: var(--red); }

@keyframes pulse-green {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.6; }
}

/* ── LAYOUT PRINCIPAL (3 colunas) ─────────────────── */
#main-layout {
  flex: 1;
  display: grid;
  /* Painéis laterais fixos, centro flexível */
  grid-template-columns: 200px 1fr 220px;
  gap: var(--panel-gap);
  padding: var(--panel-gap);
  overflow: hidden;
  min-height: 0; /* importante para grid dentro de flex */
}

/* ── PAINÉIS LATERAIS (shared styles) ────────────── */
aside {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 14px;
  gap: 12px;
}

.panel-title {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.panel-icon {
  color: var(--accent);
  font-size: 14px;
}

.section-label {
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 2px;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-bottom: 4px;
}

/* ── PAINEL ESQUERDO: Biblioteca de Comandos ──────── */
#panel-commands {
  gap: 8px;
}

.command-library {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* Bloco de comando (botão clicável) */
.cmd-block {
  display: grid;
  grid-template-columns: 24px 1fr;
  grid-template-rows: auto auto;
  grid-template-areas: "icon label" "icon desc";
  align-items: center;
  gap: 0 8px;
  padding: 10px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  text-align: left;
  transition: all var(--transition);
  position: relative;
  overflow: hidden;
}

/* Linha colorida à esquerda de cada bloco */
.cmd-block::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  border-radius: 0 2px 2px 0;
  transition: var(--transition);
}

.cmd-move::before   { background: var(--accent); }
.cmd-left::before   { background: var(--green); }
.cmd-right::before  { background: var(--yellow); }
.cmd-wait::before   { background: var(--purple); }

.cmd-block:hover {
  background: var(--bg-elevated);
  border-color: var(--border-bright);
  transform: translateX(2px);
}

.cmd-icon {
  grid-area: icon;
  font-size: 18px;
  text-align: center;
  line-height: 1;
}

.cmd-label {
  grid-area: label;
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-primary);
  font-weight: 600;
  letter-spacing: 1px;
}

.cmd-desc {
  grid-area: desc;
  font-size: 10px;
  color: var(--text-muted);
}

/* Seção de blocos futuros (desabilitados) */
.future-section {
  margin-top: auto;
  border-top: 1px solid var(--border);
  padding-top: 10px;
}

.future-block {
  padding: 8px 10px;
  background: var(--bg-deep);
  border: 1px dashed var(--border);
  border-radius: var(--radius-md);
  font-size: 11px;
  color: var(--text-muted);
  cursor: not-allowed;
  font-family: var(--font-mono);
  letter-spacing: 1px;
}

/* ── PAINEL CENTRAL: Simulação ────────────────────── */
#panel-simulation {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 14px;
  gap: 10px;
}

.simulation-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}

.sim-controls {
  display: flex;
  gap: 8px;
}

/* Wrapper do Canvas — centraliza e mantém proporção */
.canvas-wrapper {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-deep);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  /* Efeito de brilho sutil ao redor do canvas */
  box-shadow: inset 0 0 30px rgba(0, 229, 255, 0.03);
  min-height: 0;
}

#simulation-canvas {
  display: block;
  /* Tamanho definido por JS para precisão pixel */
  image-rendering: pixelated;
}

/* Barra de informações abaixo do canvas */
.robot-info-bar {
  display: flex;
  gap: 16px;
  padding: 8px 12px;
  background: var(--bg-deep);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  flex-shrink: 0;
}

.info-item {
  display: flex;
  align-items: center;
  gap: 8px;
}

.info-label {
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 2px;
  color: var(--text-muted);
}

.info-value {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--accent);
  min-width: 60px;
}

/* ── PAINEL DIREITO: Fila de Comandos ─────────────── */
#panel-queue {
  gap: 8px;
}

/* Lista scrollável de comandos */
.command-queue {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 0;
  padding-right: 2px;
}

/* Scrollbar customizada */
.command-queue::-webkit-scrollbar { width: 4px; }
.command-queue::-webkit-scrollbar-track { background: transparent; }
.command-queue::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
.command-queue::-webkit-scrollbar-thumb:hover { background: var(--border-bright); }

/* Mensagem de fila vazia */
.queue-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 11px;
  text-align: center;
  border: 1px dashed var(--border);
  border-radius: var(--radius-md);
  padding: 20px;
}

/* Item na fila de comandos */
.queue-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-family: var(--font-mono);
  font-size: 12px;
  position: relative;
  overflow: hidden;
  animation: slideIn 0.15s ease;
  transition: all var(--transition);
}

@keyframes slideIn {
  from { opacity: 0; transform: translateX(8px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* Indicador de cor no lado esquerdo (mesmo padrão dos blocos) */
.queue-item::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
}

.queue-item[data-cmd="MOVE"]::before  { background: var(--accent); }
.queue-item[data-cmd="LEFT"]::before  { background: var(--green); }
.queue-item[data-cmd="RIGHT"]::before { background: var(--yellow); }
.queue-item[data-cmd="WAIT"]::before  { background: var(--purple); }

/* Número do passo */
.queue-item .step-num {
  font-size: 9px;
  color: var(--text-muted);
  min-width: 16px;
  text-align: right;
}

.queue-item .step-icon {
  font-size: 14px;
  line-height: 1;
}

.queue-item .step-name {
  flex: 1;
  color: var(--text-primary);
  letter-spacing: 1px;
}

/* Botão de remover item */
.queue-item .btn-remove {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  padding: 2px 4px;
  border-radius: 3px;
  transition: all var(--transition);
  line-height: 1;
  opacity: 0;
}

.queue-item:hover .btn-remove { opacity: 1; }
.queue-item .btn-remove:hover { color: var(--red); background: rgba(248, 81, 73, 0.1); }

/* Estado: comando sendo executado agora */
.queue-item.executing {
  background: var(--bg-elevated);
  border-color: var(--accent);
  box-shadow: 0 0 8px var(--accent-glow);
}

/* Estado: comando já executado */
.queue-item.done {
  opacity: 0.4;
}

/* Estado: comando com erro */
.queue-item.error {
  border-color: var(--red);
  background: rgba(248, 81, 73, 0.08);
}

/* Controles da fila */
.queue-controls {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

/* ── BOTÕES ────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 14px;
  height: 36px;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 600;
  transition: all var(--transition);
  white-space: nowrap;
  user-select: none;
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

/* Botão primário — verde, para "Executar" */
.btn-primary {
  background: var(--green);
  color: #0a0c10;
  flex: 1;
  font-size: 14px;
  letter-spacing: 0.5px;
}

.btn-primary:hover:not(:disabled) {
  background: #4de866;
  box-shadow: 0 0 12px rgba(57, 211, 83, 0.4);
  transform: translateY(-1px);
}

.btn-primary:active:not(:disabled) {
  transform: translateY(0);
}

/* Botão ghost — para ações secundárias */
.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border-color: var(--border-bright);
}

.btn-sm {
  height: 30px;
  padding: 0 10px;
  font-size: 12px;
}

/* Estado "rodando" do botão Executar */
.btn-primary.running {
  background: var(--yellow);
  animation: none;
}

/* ── LOG DE EXECUÇÃO ──────────────────────────────── */
.log-section {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 130px;
}

.execution-log {
  flex: 1;
  overflow-y: auto;
  background: var(--bg-deep);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 110px;
}

.execution-log::-webkit-scrollbar { width: 3px; }
.execution-log::-webkit-scrollbar-thumb { background: var(--border); }

.log-entry {
  font-family: var(--font-mono);
  font-size: 10px;
  padding: 2px 0;
  line-height: 1.4;
}

.log-info    { color: var(--text-secondary); }
.log-action  { color: var(--accent); }
.log-success { color: var(--green); }
.log-warn    { color: var(--yellow); }
.log-error   { color: var(--red); }

/* ── RESPONSIVIDADE BÁSICA ────────────────────────── */
@media (max-width: 900px) {
  #main-layout {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto 1fr;
    overflow-y: auto;
  }

  #panel-commands {
    grid-column: 1;
    grid-row: 1;
  }

  #panel-simulation {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  #panel-queue {
    grid-column: 2;
    grid-row: 1;
  }
}

/* =====================================================
   style.css — Adições v2
   • Seletor de nível no header
   • Blocos LOOP e IF
   • Sub-listas de comandos filhos
   • Drag and drop
   • Score na infobarra
   • Celebração de goal
   • Menu flutuante add-child
   ===================================================== */

/* ── HEADER CENTER (seletor de nível) ────────────── */
.header-center {
  flex: 1;
  display: flex;
  justify-content: center;
}

.level-select {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 1px;
  padding: 4px 10px;
  cursor: pointer;
  transition: all var(--transition);
  max-width: 240px;
}

.level-select:hover,
.level-select:focus {
  border-color: var(--accent);
  color: var(--text-primary);
  outline: none;
}

.level-select option {
  background: var(--bg-panel);
}

/* ── BLOCOS LOOP e IF ────────────────────────────── */
.cmd-loop::before { background: #ff7b54; }
.cmd-if::before   { background: #58a6ff; }

/* ── SCORE NA INFOBARRA ──────────────────────────── */
.info-score-item {
  margin-left: auto;  /* empurra para a direita */
}

.info-score {
  color: #e3b341 !important;
  font-size: 15px !important;
  font-weight: bold;
}

/* ── ITENS DE FILA: sub-listas (LOOP/IF) ─────────── */
.qi-header {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
}

.qi-header .step-num  { font-size: 9px; color: var(--text-muted); min-width: 16px; text-align: right; }
.qi-header .step-icon { font-size: 14px; line-height: 1; }
.qi-header .step-name { flex: 1; font-family: var(--font-mono); font-size: 12px; color: var(--text-primary); letter-spacing: 1px; }
.qi-header .btn-remove {
  background: none; border: none; color: var(--text-muted);
  cursor: pointer; font-size: 14px; padding: 2px 4px;
  border-radius: 3px; opacity: 0; transition: all var(--transition); line-height: 1;
}
.queue-item:hover .btn-remove { opacity: 1; }
.qi-header .btn-remove:hover  { color: var(--red); background: rgba(248,81,73,0.1); }

/* Sub-lista de comandos filhos */
.qi-sublist {
  margin-top: 6px;
  padding: 6px 8px;
  background: var(--bg-deep);
  border: 1px dashed var(--border);
  border-radius: var(--radius-md);
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
}

/* Sub-lista do IF tem label de branch */
.qi-if {
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
}

.qi-branch-label {
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 1px;
  margin-bottom: 2px;
}

.qi-branch-then { color: #39d353; }
.qi-branch-else { color: #f85149; }

.qi-branch-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
  width: 100%;
}

/* Chips de comandos filhos */
.qi-chip {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 6px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-primary);
  letter-spacing: 0.5px;
}

.qi-chip-rm {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 11px;
  padding: 0 2px;
  line-height: 1;
}

.qi-chip-rm:hover { color: var(--red); }

/* Botão + cmd dentro do loop/if */
.qi-add-child {
  background: none;
  border: 1px dashed var(--border);
  border-radius: 20px;
  color: var(--text-muted);
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 9px;
  padding: 2px 7px;
  transition: all var(--transition);
  letter-spacing: 1px;
}

.qi-add-child:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ── DRAG AND DROP ───────────────────────────────── */
.queue-item[draggable="true"] {
  cursor: grab;
}

.queue-item.dragging {
  opacity: 0.4;
  cursor: grabbing;
}

.queue-item.drag-over {
  border-color: var(--accent);
  background: var(--bg-elevated);
  box-shadow: 0 0 8px var(--accent-glow);
}

/* ── MENU FLUTUANTE add-child ─────────────────────── */
.add-child-menu {
  position: fixed;
  z-index: 9999;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 120px;
  animation: fadeInDown 0.12s ease;
}

@keyframes fadeInDown {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.add-child-menu button {
  background: none;
  border: none;
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 8px 14px;
  text-align: left;
  letter-spacing: 1px;
  transition: background var(--transition);
}

.add-child-menu button:last-child { border-bottom: none; }
.add-child-menu button:hover { background: var(--bg-elevated); color: var(--accent); }

/* ── STATUS GOAL ──────────────────────────────────── */
.status-goal {
  color: #e3b341;
  border-color: #e3b341;
  box-shadow: 0 0 10px rgba(227, 179, 65, 0.4);
  animation: pulse-gold 0.8s ease infinite;
}

@keyframes pulse-gold {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.6; }
}

/* ── CELEBRAÇÃO DE GOAL ───────────────────────────── */
.goal-particles {
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: 9000;
  overflow: hidden;
}

/* Partículas geradas via CSS @keyframes + JS */
.particle {
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  animation: particle-fall 1.5s ease-out forwards;
}

@keyframes particle-fall {
  0%   { opacity: 1; transform: translateY(0) scale(1) rotate(0deg); }
  100% { opacity: 0; transform: translateY(300px) scale(0.3) rotate(360deg); }
}

/* Flash geral quando goal é alcançado */
@keyframes goal-flash {
  0%   { background: rgba(163, 113, 247, 0); }
  20%  { background: rgba(163, 113, 247, 0.12); }
  100% { background: rgba(163, 113, 247, 0); }
}

body.goal-reached::after {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 8999;
  animation: goal-flash 0.8s ease forwards;
  pointer-events: none;
}

/* Banner de parabéns */
body.goal-reached::before {
  content: '★  OBJETIVO ALCANÇADO!  ★';
  position: fixed;
  top: 80px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9001;
  background: linear-gradient(135deg, #a371f7, #e3b341);
  color: #0a0c10;
  font-family: var(--font-mono);
  font-size: 18px;
  letter-spacing: 3px;
  font-weight: bold;
  padding: 14px 32px;
  border-radius: 40px;
  box-shadow: 0 0 30px rgba(163, 113, 247, 0.6);
  pointer-events: none;
  animation: banner-in 0.4s cubic-bezier(0.34,1.56,0.64,1) forwards,
             banner-out 0.4s ease 2s forwards;
}

@keyframes banner-in {
  from { opacity: 0; transform: translateX(-50%) scale(0.6); }
  to   { opacity: 1; transform: translateX(-50%) scale(1); }
}

@keyframes banner-out {
  from { opacity: 1; }
  to   { opacity: 0; }
}

/* =====================================================
   style.css — Adições v3
   • Header: slider de velocidade, botão Step
   • Bloco SENSOR
   • Campo loop-times-input editável
   • Tabs Programa | Histórico
   • Histórico visual
   • Tooltip global
   • Sensor na infobarra
   • Badge de edição
   • Botão full-width
   ===================================================== */

/* ── HEADER: controles de execução ──────────────────── */
.exec-controls {
  display: flex;
  gap: 6px;
  align-items: center;
}

/* ── SPEED SLIDER ─────────────────────────────────── */
.speed-control {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 3px 10px;
}

.speed-label {
  font-size: 13px;
  line-height: 1;
}

.speed-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 80px;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  outline: none;
  cursor: pointer;
}

.speed-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 6px var(--accent-glow);
  cursor: pointer;
  transition: transform 0.15s ease;
}

.speed-slider::-webkit-slider-thumb:hover { transform: scale(1.3); }

/* ── BLOCO SENSOR ─────────────────────────────────── */
.cmd-sensor::before { background: #ffe066; }

/* ── CAMPO EDITÁVEL DO LOOP ──────────────────────── */
.loop-times-input {
  width: 44px;
  background: var(--bg-deep);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: #ff7b54;
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: bold;
  text-align: center;
  padding: 2px 4px;
  cursor: text;
  transition: border-color var(--transition);
}

.loop-times-input:focus {
  outline: none;
  border-color: #ff7b54;
  box-shadow: 0 0 6px rgba(255,123,84,0.3);
}

/* Remove setas do input number */
.loop-times-input::-webkit-inner-spin-button,
.loop-times-input::-webkit-outer-spin-button { -webkit-appearance: none; }

/* ── TABS ─────────────────────────────────────────── */
.panel-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
  flex-shrink: 0;
}

.tab-btn {
  flex: 1;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 1px;
  padding: 8px 4px;
  text-transform: uppercase;
  transition: all var(--transition);
}

.tab-btn:hover   { color: var(--text-secondary); }
.tab-btn.tab-active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.tab-content { display: none; flex-direction: column; flex: 1; min-height: 0; gap: 8px; }
.tab-content.active { display: flex; }

/* ── HISTÓRICO ────────────────────────────────────── */
.history-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 0;
}

.history-list::-webkit-scrollbar { width: 3px; }
.history-list::-webkit-scrollbar-thumb { background: var(--border); }

.history-empty {
  color: var(--text-muted);
  font-size: 11px;
  text-align: center;
  font-family: var(--font-mono);
  padding: 20px;
  line-height: 1.6;
}

.history-entry {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 8px 10px;
  font-family: var(--font-mono);
  font-size: 10px;
  transition: border-color var(--transition);
}

.history-entry:hover { border-color: var(--border-bright); }

.history-latest {
  border-color: var(--accent);
  box-shadow: 0 0 6px var(--accent-glow);
}

.history-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 4px;
}

.history-level { color: var(--text-secondary); font-size: 10px; }
.history-score { color: #e3b341; font-size: 13px; font-weight: bold; }

.history-details {
  display: flex;
  gap: 10px;
  color: var(--text-muted);
  font-size: 9px;
}

.history-date {
  color: var(--text-muted);
  font-size: 9px;
  margin-top: 4px;
}

/* ── TOOLTIP GLOBAL ───────────────────────────────── */
.global-tooltip {
  position: fixed;
  z-index: 10000;
  max-width: 260px;
  background: var(--bg-panel);
  border: 1px solid var(--border-bright);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 11px;
  line-height: 1.5;
  padding: 8px 12px;
  pointer-events: none;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
  animation: fadeInDown 0.1s ease;
}

/* ── LOG DESCRITIVO ───────────────────────────────── */
.log-desc {
  color: var(--text-muted);
  font-size: 9px;
}

/* ── SENSOR NA INFOBARRA ──────────────────────────── */
.info-sensor { color: #ffe066 !important; }

/* ── BADGE MODO EDIÇÃO ────────────────────────────── */
.edit-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 1px;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 20px;
  padding: 3px 10px;
  animation: pulse-cyan 1s ease infinite;
}

@keyframes pulse-cyan {
  0%,100% { opacity: 1; }
  50%     { opacity: 0.5; }
}

/* ── BOTÃO FULL WIDTH ─────────────────────────────── */
.btn-full { width: 100%; margin-top: 4px; justify-content: center; }

/* ── STATUS STEP ──────────────────────────────────── */
.status-step {
  color: #58a6ff;
  border-color: #58a6ff;
  box-shadow: 0 0 8px rgba(88,166,255,0.3);
}

/* ── DRAG HINT ────────────────────────────────────── */
.drag-hint {
  display: flex;
  align-items: center;
  gap: 4px;
}

.drag-hint::before {
  content: '⠿';
  color: var(--text-muted);
  font-size: 10px;
}

/* =====================================================
   RESPONSIVIDADE COMPLETA v3
   Mobile-first: cada breakpoint adiciona complexidade
   
   Breakpoints:
     ≤600px  → mobile  (abas, canvas compacto)
     601–900px → tablet portrait
     901–1200px → tablet landscape / laptop pequeno
     ≥1201px → desktop (layout original)
   ===================================================== */

/* ── CANVAS: sempre ocupa o espaço disponível ─────── */
/* O JS vai redimensionar o canvas internamente,
   mas aqui garantimos que ele nunca transborde */
#simulation-canvas {
  max-width: 100%;
  max-height: 100%;
}

.canvas-wrapper {
  min-height: 0;
  min-width: 0;
}

/* ══════════════════════════════════════════════════════
   TABLET PORTRAIT  601px – 900px
══════════════════════════════════════════════════════ */
@media (max-width: 900px) {

  /* Header: compacta o centro */
  #header {
    flex-wrap: wrap;
    height: auto;
    padding: 8px 12px;
    gap: 6px;
  }

  .header-center {
    order: 3;
    width: 100%;
    flex-wrap: wrap;
    gap: 8px;
  }

  .speed-control { flex: 1; justify-content: center; }
  .exec-controls { flex: 1; justify-content: flex-end; }
  .level-select  { flex: 1; max-width: none; }

  /* Layout: 2 colunas + simulação embaixo */
  #main-layout {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto 1fr;
    overflow-y: auto;
    height: auto;         /* permite scroll vertical */
  }

  #panel-commands   { grid-column: 1; grid-row: 1; max-height: 260px; overflow-y: auto; }
  #panel-queue      { grid-column: 2; grid-row: 1; max-height: 260px; }
  #panel-simulation { grid-column: 1 / -1; grid-row: 2; min-height: 340px; }

  /* Painéis laterais: scroll horizontal em comandos */
  .command-library {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
  }

  .command-library .section-label { grid-column: 1 / -1; }

  /* Oculta seções "Em breve" em telas menores */
  .future-section { display: none; }

  /* Infobarra: wrapping */
  .robot-info-bar {
    flex-wrap: wrap;
    gap: 8px;
  }

  .info-score-item { margin-left: 0; }
}

/* ══════════════════════════════════════════════════════
   MOBILE  ≤600px
   Filosofia: abas na parte inferior (nav mobile)
   1 painel visível por vez
══════════════════════════════════════════════════════ */
@media (max-width: 600px) {

  /* Remove overflow hidden do body para mobile */
  html, body { overflow: auto; }

  /* App não usa mais height: 100vh fixo */
  #app {
    height: auto;
    min-height: 100dvh;  /* dynamic viewport height (iOS safe) */
  }

  /* ── Header mobile: minimalista ───────────────────── */
  #header {
    padding: 8px 10px;
    flex-wrap: nowrap;
    height: auto;
    gap: 8px;
  }

  .brand-version { display: none; }          /* esconde versão */
  .brand-name    { font-size: 14px; letter-spacing: 1px; }
  .brand-icon    { font-size: 18px; }

  .header-center {
    order: unset;
    flex: 1;
    flex-wrap: nowrap;
    justify-content: flex-end;
    gap: 6px;
    width: auto;
  }

  /* Slider de velocidade: compacto */
  .speed-control {
    padding: 2px 6px;
    gap: 4px;
  }
  .speed-slider  { width: 50px; }
  .speed-label   { display: none; }          /* esconde emojis */

  .exec-controls { gap: 4px; }
  #btn-step      { display: none; }          /* step só no desktop */
  .level-select  { display: none; }          /* seletor de nível vai pro mobile-nav */

  /* ── Layout mobile: coluna única + nav de abas ────── */
  #main-layout {
    display: flex;
    flex-direction: column;
    gap: 0;
    padding: 0;
    overflow: visible;
    height: auto;
  }

  /* Todos os painéis ficam ocultos por padrão */
  #panel-commands,
  #panel-queue,
  #panel-simulation {
    display: none;
    border-radius: 0;
    border-left: none;
    border-right: none;
    padding: 10px;
  }

  /* Painel ativo (controlado por JS via classe) */
  #panel-commands.mobile-active,
  #panel-queue.mobile-active,
  #panel-simulation.mobile-active {
    display: flex;
  }

  /* ── Simulação mobile ────────────────────────────── */
  #panel-simulation {
    min-height: 0;
    padding: 8px;
  }

  .simulation-header { padding: 0 0 6px 0; }

  .canvas-wrapper {
    height: calc(100vw - 16px);  /* quadrado baseado na largura */
    min-height: 260px;
    max-height: 380px;
  }

  /* Infobarra mobile: grid 2×2 */
  .robot-info-bar {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 4px;
    padding: 6px 8px;
  }

  .info-score-item { grid-column: 1 / -1; justify-content: center; }
  .info-value      { min-width: unset; font-size: 12px; }
  .info-label      { font-size: 8px; }

  /* ── Comandos mobile: grid 2 cols ─────────────────── */
  #panel-commands { gap: 8px; max-height: none; }

  .command-library {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
  }

  .command-library .section-label { grid-column: 1 / -1; }

  .cmd-block {
    padding: 8px;
    grid-template-columns: 20px 1fr;
    grid-template-rows: auto auto;
  }

  .cmd-desc { font-size: 9px; }

  /* ── Programa/fila mobile ─────────────────────────── */
  #panel-queue {
    max-height: none;
    padding-bottom: 80px;  /* espaço para a nav */
  }

  .queue-controls {
    position: sticky;
    bottom: 0;
    background: var(--bg-panel);
    padding: 8px 0;
    border-top: 1px solid var(--border);
    z-index: 10;
  }

  /* Log menor no mobile */
  .log-section   { max-height: 120px; }
  .execution-log { max-height: 90px; }

  /* ── NAV MOBILE (barra inferior) ─────────────────── */
  #mobile-nav {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: 56px;
    background: var(--bg-panel);
    border-top: 1px solid var(--border);
    display: flex;
    z-index: 1000;
    box-shadow: 0 -4px 20px rgba(0,0,0,0.4);
  }

  .mobile-nav-btn {
    flex: 1;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    font-family: var(--font-mono);
    font-size: 9px;
    letter-spacing: 0.5px;
    transition: all var(--transition);
    padding: 4px;
  }

  .mobile-nav-btn .nav-icon { font-size: 18px; line-height: 1; }
  .mobile-nav-btn .nav-label { text-transform: uppercase; }

  .mobile-nav-btn.nav-active {
    color: var(--accent);
  }

  .mobile-nav-btn.nav-active .nav-icon {
    filter: drop-shadow(0 0 4px var(--accent));
  }

  /* Seletor de nível dentro do painel de simulação no mobile */
  .mobile-level-select {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
  }

  .mobile-level-select .level-select {
    display: block;   /* override do display:none acima */
    flex: 1;
    max-width: none;
    font-size: 11px;
  }

  /* Padding bottom para não ficar atrás da nav */
  #main-layout { padding-bottom: 60px; }

  /* Oculta seção "Em breve" */
  .future-section { display: none; }

  /* Painel de mapa no mobile: mais compacto */
  .command-library:has(#btn-edit-map) { grid-template-columns: 1fr; }

  /* Histórico mobile */
  .history-entry { padding: 6px 8px; }
}

/* ══════════════════════════════════════════════════════
   LAPTOP PEQUENO / TABLET LANDSCAPE  901–1200px
══════════════════════════════════════════════════════ */
@media (min-width: 901px) and (max-width: 1200px) {

  #main-layout {
    grid-template-columns: 180px 1fr 200px;
  }

  /* Header center: compacta um pouco */
  .header-center { gap: 8px; }
  .speed-slider  { width: 60px; }

  /* Painéis laterais um pouco menores */
  .cmd-block { padding: 8px; }
  .cmd-desc  { font-size: 9px; }
}

/* ══════════════════════════════════════════════════════
   LARGE DESKTOP  ≥1400px
   Aproveita mais espaço
══════════════════════════════════════════════════════ */
@media (min-width: 1400px) {
  #main-layout {
    grid-template-columns: 220px 1fr 260px;
  }

  .cmd-block { padding: 12px; }
}

/* ══════════════════════════════════════════════════════
   TOUCH: remove hover states que "grudam" no mobile
══════════════════════════════════════════════════════ */
@media (hover: none) {
  .cmd-block:hover   { transform: none; }
  .queue-item .btn-remove { opacity: 1; }  /* sempre visível no touch */
}

/* ══════════════════════════════════════════════════════
   NOVOS ESTILOS v4 — Progresso de Nível + Melhorias
══════════════════════════════════════════════════════ */

/* Indicador de progresso de nível */
.level-progress {
  display: flex;
  gap: 4px;
  align-items: center;
}

.level-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #30363d;
  border: 1px solid #484f58;
  transition: all 0.3s ease;
  cursor: default;
}

.level-dot.completed {
  background: #39d353;
  border-color: #39d353;
  box-shadow: 0 0 6px rgba(57,211,83,0.5);
}

.level-dot.current {
  background: #00e5ff;
  border-color: #00e5ff;
  box-shadow: 0 0 8px rgba(0,229,255,0.6);
  transform: scale(1.3);
}

/* Log hint especial */
.log-hint {
  color: #e3b341;
  border-left: 2px solid #e3b341;
  padding-left: 6px;
  font-style: italic;
  opacity: 0.9;
}

/* Badge de dificuldade no select */
.level-select option[data-diff="fácil"]   { color: #39d353; }
.level-select option[data-diff="médio"]   { color: #e3b341; }
.level-select option[data-diff="difícil"] { color: #f85149; }

/* Animação de novo nível desbloqueado */
@keyframes levelUnlock {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.4); box-shadow: 0 0 16px rgba(57,211,83,0.8); }
  100% { transform: scale(1.2); }
}

.level-dot.just-completed {
  animation: levelUnlock 0.6s ease forwards;
}
