  * { box-sizing: border-box; margin: 0; padding: 0; user-select: none; -webkit-user-select: none; }
  body {
    background: #06020c;
    color: #e0d0f0;
    font-family: 'Courier New', monospace;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    overflow: hidden;
    touch-action: none;
  }
  #arcade-frame {
    position: relative;
    width: 95vw;
    max-width: 896px;
    height: 53.4vw;
    max-height: 504px;
    background: #000;
    box-shadow: 0 0 50px rgba(138, 43, 226, 0.45);
    border: 3px solid #281242;
  }
  canvas {
    width: 100%;
    height: 100%;
    display: block;
    image-rendering: pixelated;
  }
  .scanlines {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background: linear-gradient(rgba(18, 16, 26, 0) 50%, rgba(0, 0, 0, 0.4) 50%);
    background-size: 100% 4px;
    pointer-events: none;
  }
  #toolbar {
    margin-top: 10px;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px 15px;
    font-size: 12px;
    max-width: 95vw;
  }
  .key {
    background: #201035;
    padding: 3px 6px;
    border-radius: 4px;
    border: 1px solid #7c3aed;
    color: #ffd15c;
  }

  /* Controles táctiles: solo visibles en pantallas táctiles,
     fijados al pie del viewport para no tapar el juego */
  #touch-controls { display: none; }
  @media (pointer: coarse) {
    #touch-controls {
      display: flex;
      position: fixed;
      left: 0; right: 0; bottom: 0;
      justify-content: space-between;
      align-items: flex-end;
      padding: 0 10px 12px;
      pointer-events: none;
      z-index: 50;
    }
    #toolbar { display: none; }
  }
  #touch-move { display: flex; flex-direction: column; align-items: center; gap: 4px; }
  .trowmid { display: flex; gap: 4px; }
  #touch-actions {
    display: grid;
    grid-template-columns: repeat(2, auto);
    gap: 6px;
  }
  .tbtn {
    pointer-events: auto;
    min-width: 44px;
    height: 44px;
    padding: 0 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(32, 16, 53, 0.62);
    border: 1px solid #7c3aed;
    border-radius: 8px;
    color: #ffd15c;
    font-family: 'Courier New', monospace;
    font-size: 13px;
    font-weight: bold;
  }
  .tbtn.tact { font-size: 10px; border-radius: 50%; width: 52px; height: 52px; }
  .tbtn.active { background: rgba(124, 58, 237, 0.85); color: #fff; }

/* Keep the full 16:9 image inside the visible mobile viewport.
   Touch controls live in reserved space, never on top of the canvas. */
@media (pointer: coarse) {
  html { width: 100%; height: 100%; overflow: hidden; }
  body {
    width: 100%; height: 100vh; height: 100dvh; min-height: 0;
    padding: calc(44px + env(safe-area-inset-top, 0px))
             calc(8px + env(safe-area-inset-right, 0px))
             calc(138px + env(safe-area-inset-bottom, 0px))
             calc(8px + env(safe-area-inset-left, 0px));
  }
  #arcade-frame {
    flex: none; border: 0; outline: 2px solid #281242;
    width: min(100%, calc((100dvh - 190px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px)) * 16 / 9));
    height: auto; aspect-ratio: 16 / 9; max-height: none;
  }
  #sound-toggle {
    top: calc(8px + env(safe-area-inset-top, 0px)) !important;
    right: calc(8px + env(safe-area-inset-right, 0px)) !important;
    min-height: 36px;
  }
  #touch-controls {
    padding: 0 calc(10px + env(safe-area-inset-right, 0px))
               calc(10px + env(safe-area-inset-bottom, 0px))
               calc(10px + env(safe-area-inset-left, 0px));
  }
}
@media (pointer: coarse) and (orientation: landscape) {
  body {
    padding: calc(8px + env(safe-area-inset-top, 0px))
             calc(136px + env(safe-area-inset-right, 0px))
             calc(8px + env(safe-area-inset-bottom, 0px))
             calc(152px + env(safe-area-inset-left, 0px));
  }
  #arcade-frame {
    width: min(100%, calc((100dvh - 16px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px)) * 16 / 9));
  }
}
