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

html, body, #container {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: system-ui, -apple-system, sans-serif;
}

@media (prefers-color-scheme: dark) {
  body {
    background: #08080c;
    color: #ededf5;
  }
}

@media (prefers-color-scheme: light) {
  body {
    background: #f5f5f7;
    color: #1a1a1f;
  }
}

#container {
  position: relative;
  width: 100%;
  height: 100%;
}

/* TELAS */
.tela {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  background: linear-gradient(135deg, #08080c 0%, #101018 100%);
}

.tela.ativa {
  opacity: 1;
  pointer-events: auto;
}

.painel {
  background: rgba(16, 16, 24, 0.95);
  backdrop-filter: blur(8px);
  border: 1px solid #26263a;
  border-radius: 12px;
  padding: 2rem;
  max-width: 540px;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.painel h1 {
  font-size: 1.75rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  color: #7c3aed;
  text-align: center;
}

.painel h2 {
  font-size: 1.125rem;
  font-weight: 600;
  margin: 1.5rem 0 1rem;
  color: #ededf5;
}

.lema {
  font-size: 0.95rem;
  color: #9a9ab0;
  text-align: center;
  margin-bottom: 1.5rem;
  line-height: 1.5;
}

.secaoControles {
  margin: 1.5rem 0;
}

.controles {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-bottom: 1rem;
  background: rgba(124, 58, 237, 0.05);
  padding: 1rem;
  border-radius: 8px;
  border-left: 3px solid #7c3aed;
}

.controle {
  display: flex;
  justify-content: space-between;
  font-size: 0.875rem;
}

.controle strong {
  color: #ededf5;
}

.controle span {
  color: #7c3aed;
  font-weight: 600;
  font-family: 'Cascadia Code', Consolas, monospace;
}

.dica {
  font-size: 0.875rem;
  color: #9a9ab0;
  line-height: 1.6;
  margin-top: 1rem;
  padding: 0.75rem;
  background: rgba(124, 58, 237, 0.05);
  border-radius: 6px;
  border-left: 2px solid #7c3aed;
}

.resultado {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 1rem;
  margin: 2rem 0;
  padding: 1.5rem;
  background: rgba(124, 58, 237, 0.05);
  border-radius: 8px;
  border: 1px solid rgba(124, 58, 237, 0.1);
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.stat .label {
  font-size: 0.75rem;
  color: #9a9ab0;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.stat .valor {
  font-size: 1.75rem;
  font-weight: 700;
  color: #7c3aed;
  font-family: 'Cascadia Code', Consolas, monospace;
}

.licao {
  font-size: 0.875rem;
  color: #9a9ab0;
  line-height: 1.6;
  margin: 1.5rem 0;
  padding: 1rem;
  background: rgba(124, 58, 237, 0.05);
  border-radius: 6px;
  border-left: 2px solid #7c3aed;
}

/* BOTÕES */
button {
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  padding: 0.75rem 1.5rem;
  border-radius: 8px;
  transition: all 0.2s ease;
  display: inline-block;
  text-align: center;
}

button:focus-visible {
  outline: 2px solid #7c3aed;
  outline-offset: 2px;
}

.botao-primario {
  width: 100%;
  background: linear-gradient(135deg, #7c3aed 0%, #6d28d9 100%);
  color: #ededf5;
  margin-top: 1rem;
  padding: 1rem;
  font-size: 1.125rem;
}

.botao-primario:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(124, 58, 237, 0.3);
}

.botao-primario:active {
  transform: translateY(0);
}

.botao-secundario {
  width: 100%;
  background: rgba(154, 154, 176, 0.1);
  color: #ededf5;
  border: 1px solid #26263a;
  margin-top: 0.5rem;
  padding: 0.75rem;
}

.botao-secundario:hover {
  background: rgba(154, 154, 176, 0.2);
  border-color: #9a9ab0;
}

/* ÁREA DE JOGO */
.area-jogo {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: #08080c;
}

.area-jogo.oculta {
  display: none;
}

.hud {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 1rem;
  background: rgba(16, 16, 24, 0.7);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid #26263a;
}

.hud-esq,
.hud-dir {
  display: flex;
  gap: 1.5rem;
}

.hud-centro {
  flex: 1;
  max-width: 300px;
}

.hud-item {
  background: rgba(16, 16, 24, 0.85);
  backdrop-filter: blur(8px);
  border: 1px solid #26263a;
  border-radius: 8px;
  padding: 0.75rem 1rem;
  min-width: fit-content;
}

.hud-item .label {
  display: block;
  font-size: 0.75rem;
  color: #9a9ab0;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 0.25rem;
}

.hud-item .valor {
  display: block;
  font-size: 1.5rem;
  font-weight: 700;
  color: #7c3aed;
  font-family: 'Cascadia Code', Consolas, monospace;
}

/* WORKSPACE */
.workspace-container {
  flex: 1;
  display: flex;
  gap: 1rem;
  padding: 1rem;
  overflow: hidden;
}

.painel-lateral {
  width: 200px;
  background: rgba(16, 16, 24, 0.5);
  border: 1px solid #26263a;
  border-radius: 8px;
  padding: 1rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.painel-lateral h3 {
  font-size: 0.875rem;
  color: #ededf5;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 0.5rem;
}

.painel-lateral.direito {
  width: 250px;
}

.container-entradas,
.container-portas {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.entrada {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem;
  background: rgba(124, 58, 237, 0.1);
  border: 1px solid #26263a;
  border-radius: 4px;
  cursor: pointer;
  user-select: none;
}

.entrada:hover {
  background: rgba(124, 58, 237, 0.15);
}

.entrada-label {
  font-size: 0.75rem;
  color: #9a9ab0;
  flex: 1;
}

.entrada-valor {
  font-size: 1rem;
  font-weight: 700;
  color: #7c3aed;
  min-width: 20px;
  text-align: center;
}

.porta-disponivel {
  padding: 0.5rem;
  background: rgba(124, 58, 237, 0.1);
  border: 1px solid #7c3aed;
  border-radius: 4px;
  cursor: move;
  user-select: none;
  text-align: center;
  font-size: 0.875rem;
  color: #7c3aed;
  font-weight: 600;
  transition: all 0.2s ease;
}

.porta-disponivel:hover {
  background: rgba(124, 58, 237, 0.2);
  box-shadow: 0 0 8px rgba(124, 58, 237, 0.3);
}

.workspace {
  flex: 1;
  background: rgba(16, 16, 24, 0.5);
  border: 1px solid #26263a;
  border-radius: 8px;
  overflow: hidden;
  position: relative;
}

#canvas {
  display: block;
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, rgba(16, 16, 24, 0.8) 0%, rgba(26, 26, 38, 0.8) 100%);
  cursor: crosshair;
}

.container-tabela {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: 300px;
  overflow-y: auto;
  font-size: 0.75rem;
}

.linha-tabela {
  display: grid;
  grid-template-columns: repeat(3, 1fr) 20px;
  gap: 0.25rem;
  align-items: center;
  padding: 0.5rem;
  background: rgba(124, 58, 237, 0.05);
  border-radius: 4px;
  border: 1px solid #26263a;
}

.linha-tabela.testada-ok {
  border-color: #10b981;
  background: rgba(16, 185, 129, 0.05);
}

.linha-tabela.testada-falha {
  border-color: #ef4444;
  background: rgba(239, 68, 68, 0.05);
}

.celula-entrada,
.celula-saida {
  font-family: 'Cascadia Code', Consolas, monospace;
  color: #ededf5;
}

.celula-saida {
  font-weight: 700;
}

.resultado-teste {
  font-weight: 700;
  text-align: center;
}

.resultado-teste.ok {
  color: #10b981;
}

.resultado-teste.falha {
  color: #ef4444;
}

.secao-acoes {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: auto;
}

.botao-testar,
.botao-limpar {
  width: 100%;
  padding: 0.75rem;
  font-size: 0.875rem;
  background: rgba(124, 58, 237, 0.1);
  border: 1px solid #7c3aed;
  border-radius: 6px;
  color: #7c3aed;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.botao-testar:hover {
  background: #7c3aed;
  color: #08080c;
}

.botao-limpar {
  border-color: #9a9ab0;
  color: #9a9ab0;
}

.botao-limpar:hover {
  background: #9a9ab0;
  color: #08080c;
}

/* RESPONSIVIDADE */
@media (max-width: 1200px) {
  .workspace-container {
    flex-direction: column;
  }

  .painel-lateral,
  .painel-lateral.direito {
    width: 100%;
    max-height: 200px;
  }

  .painel-lateral {
    flex-direction: row;
    gap: 1rem;
  }

  .secao-entradas,
  .secao-portas {
    flex: 1;
  }

  .painel-lateral.direito {
    flex-direction: column;
  }
}

@media (max-width: 768px) {
  .hud {
    flex-wrap: wrap;
    font-size: 0.75rem;
  }

  .hud-esq,
  .hud-dir {
    gap: 1rem;
  }

  .painel-lateral {
    width: 100%;
    max-height: 150px;
  }

  .painel-lateral.direito {
    width: 100%;
  }

  .painel h1 {
    font-size: 1.5rem;
  }

  .controles {
    gap: 0.5rem;
    padding: 0.75rem;
  }
}

/* PREFERÊNCIA DE MOVIMENTO REDUZIDO */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
