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

body {
  background: #0a0a0a;
  color: #33ff66;
  font-family: "Courier New", Courier, monospace;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.cabinet {
  background: #111;
  border: 4px solid #2a2a2a;
  border-radius: 12px;
  padding: 16px;
  box-shadow: 0 0 40px rgba(51, 255, 102, 0.15);
  width: min(92vw, 460px);
}

.hud { text-align: center; }

.back {
  display: inline-block;
  color: #33ff66;
  text-decoration: none;
  font-size: 14px;
  font-weight: bold;
  letter-spacing: 2px;
  margin-bottom: 8px;
  border: 2px solid #33ff66;
  padding: 4px 12px;
  border-radius: 6px;
  background: #000;
}
.back:hover { background: #062b12; }

.title {
  font-size: 24px;
  font-weight: bold;
  letter-spacing: 3px;
  text-shadow: 0 0 8px #33ff66;
  margin-bottom: 8px;
}

.stats {
  display: flex;
  justify-content: space-between;
  font-size: 14px;
  background: #000;
  border: 2px solid #33ff66;
  padding: 6px 10px;
  margin-bottom: 12px;
}

.screen-wrap {
  position: relative;
  background: #000;
  border: 3px solid #33ff66;
  line-height: 0;
  overflow: hidden;
}

/* scanlines CRT */
.screen-wrap::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    transparent 0px,
    transparent 3px,
    rgba(0, 0, 0, 0.25) 4px
  );
}

canvas {
  width: 100%;
  height: auto;
  display: block;
  image-rendering: pixelated;
  touch-action: none;
}

.screen-wrap { touch-action: none; }

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: rgba(0, 0, 0, 0.75);
  line-height: 1.4;
  text-align: center;
  padding: 20px;
  font-weight: bold;
}

.overlay.hidden { display: none; }

#overlay-title { font-size: 20px; text-shadow: 0 0 8px #33ff66; }

.hint { font-size: 12px; font-weight: normal; opacity: 0.9; }

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  justify-content: center;
  margin-top: 12px;
  font-size: 12px;
  color: #9dffb8;
}

/* controles touch */
.touch-ui {
  display: none;
  margin-top: 12px;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
}

.dpad {
  display: grid;
  grid-template-columns: repeat(3, 56px);
  grid-template-rows: repeat(3, 56px);
  gap: 4px;
}

.tbtn {
  background: #000;
  color: #33ff66;
  border: 2px solid #33ff66;
  font-size: 20px;
  font-family: inherit;
  border-radius: 8px;
  touch-action: manipulation;
  cursor: pointer;
}
.tbtn:active { background: #062b12; }

.dpad .up { grid-column: 2; grid-row: 1; }
.dpad .left { grid-column: 1; grid-row: 2; }
.dpad .right { grid-column: 3; grid-row: 2; }
.dpad .down { grid-column: 2; grid-row: 3; }

.actions { display: flex; flex-direction: column; gap: 8px; }
.tbtn.small { width: 64px; height: 48px; font-size: 16px; font-weight: bold; }
a.tbtn.back-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  font-size: 22px;
}

/* mostra touch-ui em telas pequenas ou dispositivos touch */
@media (max-width: 600px), (pointer: coarse) {
  .touch-ui { display: flex; }
  .controls { display: none; }
  .cabinet { padding: 12px; }
  .title { font-size: 20px; }
}

/* tela cheia */
.cabinet:fullscreen {
  width: 100vw;
  height: 100vh;
  border-radius: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.cabinet:fullscreen .screen-wrap {
  width: min(90vmin, 700px);
}
