/* ===========================================================
   VOCÊ É O BUG — estética: terminal/debug, minimalista, sombria
   =========================================================== */

:root {
  --bg: #060608;
  --fg: #d8f7e4;
  --accent: #38ffb0;
  --accent-dim: #1c8f66;
  --danger: #ff3b5c;
  --warn: #ffb020;
  --panel: #0b0d12;
  --border: #1e2430;
  --mono: 'Consolas', 'Courier New', ui-monospace, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--mono);
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
}

#app {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  background: #000;
}

#game-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
}

/* ---------- CRT / scanline overlay ---------- */
#crt-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 50;
  background:
    repeating-linear-gradient(
      to bottom,
      rgba(0, 0, 0, 0.12) 0px,
      rgba(0, 0, 0, 0.12) 1px,
      transparent 2px,
      transparent 3px
    );
  mix-blend-mode: overlay;
}
#crt-overlay::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at center, rgba(0,0,0,0) 55%, rgba(0,0,0,0.55) 100%);
}

#glitch-flash {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 60;
  background: rgba(56, 255, 176, 0.08);
  opacity: 0;
}
#glitch-flash.flash {
  animation: flashPulse 0.12s ease-out;
}
@keyframes flashPulse {
  0% { opacity: 0.9; }
  100% { opacity: 0; }
}

/* ---------- HUD ---------- */
#hud {
  position: absolute;
  inset: 0;
  z-index: 40;
  pointer-events: none;
  font-size: 13px;
}
#hud.hidden { display: none; }

#hud-top {
  position: absolute;
  top: 10px;
  left: 12px;
  right: 12px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  text-shadow: 0 0 4px rgba(0,0,0,0.8);
}

#hud-level-name {
  color: var(--fg);
  letter-spacing: 1px;
  opacity: 0.85;
  padding: 4px 10px;
  background: rgba(6,6,8,0.5);
  border: 1px solid var(--border);
}

#hud-integrity {
  text-align: right;
  color: var(--accent);
  padding: 4px 10px;
  background: rgba(6,6,8,0.5);
  border: 1px solid var(--border);
  min-width: 220px;
}
#hud-integrity .label { opacity: 0.7; margin-right: 6px; font-size: 11px; }
#hud-integrity-bar {
  margin-top: 4px;
  height: 5px;
  background: #111;
  border: 1px solid var(--border);
}
#hud-integrity-fill {
  height: 100%;
  width: 100%;
  background: var(--accent);
  transition: width 0.3s ease, background-color 0.3s ease;
}
#hud-integrity.warn #hud-integrity-fill { background: var(--warn); }
#hud-integrity.warn #hud-integrity-value { color: var(--warn); }
#hud-integrity.critical #hud-integrity-fill { background: var(--danger); }
#hud-integrity.critical #hud-integrity-value { color: var(--danger); }
#hud-integrity.critical { animation: integrityBlink 0.6s steps(2) infinite; }
@keyframes integrityBlink { 50% { opacity: 0.55; } }

#hud-glitches {
  position: absolute;
  bottom: 14px;
  left: 12px;
  display: flex;
  gap: 6px;
}
.glitch-icon {
  padding: 4px 8px;
  font-size: 11px;
  border: 1px solid var(--border);
  background: rgba(6,6,8,0.55);
  color: #667;
  letter-spacing: 0.5px;
}
.glitch-icon.active { color: var(--accent); border-color: var(--accent-dim); }
.glitch-icon.on { color: #060608; background: var(--accent); border-color: var(--accent); }
.glitch-icon.blocked { color: var(--danger); border-color: var(--danger); text-decoration: line-through; }

#hud-hint {
  position: absolute;
  bottom: 44px;
  left: 50%;
  transform: translateX(-50%);
  color: var(--fg);
  background: rgba(6,6,8,0.6);
  border: 1px solid var(--border);
  padding: 6px 12px;
  font-size: 12px;
  text-align: center;
  max-width: 70vw;
}
#hud-hint.hidden { display: none; }

#system-messages {
  position: absolute;
  bottom: 14px;
  right: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: flex-end;
  max-width: 42vw;
}
.sys-msg {
  font-size: 12px;
  color: var(--accent);
  background: rgba(6,6,8,0.7);
  border-left: 2px solid var(--accent-dim);
  padding: 4px 8px;
  opacity: 0;
  animation: sysMsgIn 0.25s ease forwards, sysMsgOut 0.4s ease forwards var(--life, 4s);
}
.sys-msg.danger { color: var(--danger); border-left-color: var(--danger); }
@keyframes sysMsgIn { from { opacity: 0; transform: translateX(8px); } to { opacity: 1; transform: translateX(0); } }
@keyframes sysMsgOut { to { opacity: 0; } }

#tutorial-banner {
  position: absolute;
  top: 60px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 45;
  background: rgba(6,6,8,0.75);
  border: 1px solid var(--border);
  padding: 8px 16px;
  font-size: 13px;
  color: var(--fg);
  text-align: center;
  pointer-events: none;
}
#tutorial-banner.hidden { display: none; }

/* ---------- Telas (menus) ---------- */
.screen {
  position: absolute;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(4, 4, 6, 0.88);
  pointer-events: auto;
}
.screen.hidden { display: none; }

.crt-box {
  background: var(--panel);
  border: 1px solid var(--border);
  box-shadow: 0 0 0 1px rgba(56,255,176,0.05), 0 20px 60px rgba(0,0,0,0.6);
  padding: 32px 40px;
  min-width: 320px;
  max-width: 90vw;
  max-height: 86vh;
  overflow-y: auto;
  text-align: center;
  position: relative;
}
.crt-box::before {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(to bottom, rgba(255,255,255,0.02) 0px, transparent 2px);
}

.menu-box { min-width: 380px; }

h1, h2 { margin: 0 0 10px; letter-spacing: 2px; }
h1 { font-size: 34px; color: var(--accent); }
h2 { font-size: 22px; color: var(--accent); }

.subtitle { opacity: 0.6; font-size: 13px; margin-bottom: 24px; }

.glitch-title {
  position: relative;
  display: inline-block;
}
.glitch-title::before, .glitch-title::after {
  content: attr(data-text);
  position: absolute;
  left: 0; top: 0;
  width: 100%;
  opacity: 0.7;
  clip-path: inset(0 0 0 0);
}
.glitch-title::before { color: #ff3b5c; animation: glitchShift1 3.2s infinite linear; }
.glitch-title::after { color: #3bd0ff; animation: glitchShift2 2.6s infinite linear; }
@keyframes glitchShift1 {
  0%, 92% { transform: translate(0,0); clip-path: inset(0 0 0 0); opacity: 0; }
  93% { transform: translate(-3px,1px); clip-path: inset(10% 0 60% 0); opacity: 0.8; }
  95% { transform: translate(3px,-1px); clip-path: inset(60% 0 5% 0); opacity: 0.6; }
  97% { transform: translate(0,0); opacity: 0; }
  100% { opacity: 0; }
}
@keyframes glitchShift2 {
  0%, 90% { transform: translate(0,0); clip-path: inset(0 0 0 0); opacity: 0; }
  91% { transform: translate(3px,0); clip-path: inset(30% 0 30% 0); opacity: 0.7; }
  94% { transform: translate(-2px,1px); clip-path: inset(0 0 80% 0); opacity: 0.5; }
  96% { transform: translate(0,0); opacity: 0; }
  100% { opacity: 0; }
}

.menu-buttons { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }

button {
  font-family: var(--mono);
  background: transparent;
  color: var(--fg);
  border: 1px solid var(--border);
  padding: 10px 18px;
  font-size: 14px;
  cursor: pointer;
  letter-spacing: 1px;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
button:hover, button:focus-visible {
  background: var(--accent);
  color: #060608;
  border-color: var(--accent);
  outline: none;
}
button.minor { opacity: 0.45; font-size: 11px; border-color: transparent; }
button.minor:hover { background: rgba(255,59,92,0.2); color: var(--danger); }

.build-tag {
  margin-top: 26px;
  font-size: 10px;
  opacity: 0.35;
  letter-spacing: 1px;
}

.controls-table { width: 100%; margin: 12px 0 18px; font-size: 13px; border-collapse: collapse; }
.controls-table td { padding: 6px 10px; border-bottom: 1px solid var(--border); text-align: left; }
.controls-table td:first-child { color: var(--accent); white-space: nowrap; }
.small { font-size: 11px; opacity: 0.6; }

.settings-row { display: flex; justify-content: space-between; align-items: center; gap: 20px; margin: 12px 0; font-size: 13px; }

#level-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin: 16px 0; }
#level-grid button { padding: 14px 4px; font-size: 13px; }
#level-grid button.locked { opacity: 0.3; cursor: not-allowed; }
#level-grid button.locked:hover { background: transparent; color: var(--fg); }

.error-box h2 { color: var(--danger); }
.mono-line { font-size: 13px; margin: 6px 0; opacity: 0.85; }
.mono-line.big { font-size: 20px; color: var(--accent); }
.blink { animation: integrityBlink 0.5s steps(2) infinite; }

.victory-box #victory-sequence {
  margin: 16px 0;
  font-size: 12px;
  color: var(--accent-dim);
  min-height: 60px;
  text-align: left;
  white-space: pre-line;
}

/* ---------- Controles touch ---------- */
#touch-controls {
  position: absolute;
  inset: 0;
  z-index: 41;
  pointer-events: none;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding: 20px;
}
#touch-controls.hidden { display: none; }
.touch-left, .touch-right { display: flex; align-items: center; gap: 12px; pointer-events: auto; }
.touch-glitches {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}
.touch-btn {
  width: 56px; height: 56px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: rgba(11,13,18,0.55);
  color: var(--fg);
  font-size: 18px;
  display: flex; align-items: center; justify-content: center;
  touch-action: none;
}
.touch-btn.big { width: 68px; height: 68px; font-size: 22px; }
.touch-btn.small { width: 40px; height: 40px; font-size: 12px; opacity: 0.8; }
.touch-btn:active { background: var(--accent); color: #060608; }

/* ---------- Responsividade ---------- */
@media (max-width: 720px) {
  .crt-box { padding: 20px 18px; min-width: 0; width: 92vw; }
  h1 { font-size: 24px; }
  #hud-integrity { min-width: 160px; font-size: 11px; }
  #level-grid { grid-template-columns: repeat(3, 1fr); }
}
