* {
      box-sizing: border-box;
      margin: 0;
      padding: 0;
      user-select: none;
      -webkit-user-select: none;
      -webkit-touch-callout: none;
      touch-action: none;
    }

    html, body {
      width: 100%;
      height: 100dvh;
      overflow: hidden;
      background-color: #090d16;
      font-family: 'Press Start 2P', monospace;
      color: #f8fafc;
      image-rendering: pixelated;
    }

    #gameCanvas {
      display: block;
      width: 100vw;
      height: 100dvh;
      image-rendering: pixelated;
      image-rendering: crisp-edges;
    }

    .hidden {
      display: none !important;
    }

    /* Aviso de orientación en móviles */
    #rotate-overlay {
      display: none;
      position: fixed;
      inset: 0;
      background: #090d16;
      z-index: 9999;
      align-items: center;
      justify-content: center;
      text-align: center;
      padding: 20px;
    }
    .rotate-box {
      border: 4px solid #facc15;
      background: #131c31;
      padding: 24px;
      box-shadow: 0 0 0 4px #090d16, 0 0 0 8px #dc2626;
      max-width: 340px;
      line-height: 1.6;
      font-size: 11px;
    }
    .rotate-box h2 {
      color: #facc15;
      font-size: 13px;
      margin-bottom: 12px;
    }
    @media screen and (orientation: portrait) and (max-width: 768px) {
      #rotate-overlay {
        display: flex;
      }
    }

    /* ==========================================================================
       HUD SUPERIOR 8-BIT (UNA SOLA LÍNEA CON DIBUJITOS PIXEL ART)
       ========================================================================== */
    #top-hud {
      position: fixed;
      top: max(8px, env(safe-area-inset-top));
      left: max(10px, env(safe-area-inset-left));
      right: max(10px, env(safe-area-inset-right));
      display: flex;
      justify-content: space-between;
      align-items: center;
      gap: 8px;
      z-index: 20;
      pointer-events: none;
    }

    .hud-left, .hud-right {
      display: flex;
      flex-direction: row;
      align-items: center;
      gap: 6px;
      pointer-events: auto;
      flex-shrink: 0;
    }

    .retro-box {
      background: #111827;
      border: 3px solid #facc15;
      box-shadow: inset 0 0 0 2px #1f2937, 0 4px 0 #030712;
      padding: 5px 8px;
      font-size: 10px;
      display: flex;
      align-items: center;
      gap: 5px;
      white-space: nowrap;
    }

    #lives-container {
      display: flex;
      align-items: center;
      gap: 4px;
    }
    #lives-container canvas {
      width: 18px;
      height: 18px;
      image-rendering: pixelated;
    }

    /* Barra de Fórmula 100% Pixel Art en una sola línea */
    .formula-bar {
      background: #0f172a;
      border: 3px solid #ef4444;
      box-shadow: inset 0 0 0 2px #7f1d1d, 0 4px 0 #030712;
      padding: 4px 8px;
      display: flex;
      flex-direction: row;
      align-items: center;
      justify-content: center;
      gap: 4px;
      overflow-x: auto;
      scrollbar-width: none;
      max-width: calc(100vw - 260px);
    }
    .formula-bar::-webkit-scrollbar {
      display: none;
    }

    .formula-slot {
      position: relative;
      width: 28px;
      height: 28px;
      background: #1e293b;
      border: 2px solid #475569;
      display: flex;
      align-items: center;
      justify-content: center;
      flex-shrink: 0;
      transition: transform 0.12s steps(2);
    }

    .formula-slot canvas {
      width: 22px;
      height: 22px;
      image-rendering: pixelated;
      opacity: 0.45;
      filter: grayscale(60%);
    }

    /* Siguiente dibujito a recoger (parpadeo retro dorado) */
    .formula-slot.next-target {
      border-color: #facc15;
      background: #422006;
      box-shadow: 0 0 0 2px #facc15;
      animation: blinkTarget 0.55s steps(2) infinite;
      transform: scale(1.08);
    }
    .formula-slot.next-target canvas {
      opacity: 1;
      filter: none;
    }

    /* Dibujito ya recogido */
    .formula-slot.collected {
      border-color: #22c55e;
      background: #052e16;
    }
    .formula-slot.collected canvas {
      opacity: 1;
      filter: none;
    }

    @keyframes blinkTarget {
      0%, 100% { border-color: #facc15; box-shadow: 0 0 0 1px #facc15; }
      50% { border-color: #ffffff; box-shadow: 0 0 0 2px #ef4444; }
    }

    .hud-icon-btn {
      background: #1e293b;
      border: 3px solid #facc15;
      color: #facc15;
      width: 34px;
      height: 34px;
      font-family: inherit;
      font-size: 11px;
      cursor: pointer;
      box-shadow: 0 3px 0 #030712;
      display: flex;
      align-items: center;
      justify-content: center;
    }
    .hud-icon-btn:active {
      transform: translateY(2px);
      box-shadow: 0 1px 0 #030712;
    }

    /* ==========================================================================
       CARTEL DE INICIO DE MISIÓN (1.2 SEGUNDOS EN GRANDE)
       ========================================================================== */
    #mission-banner {
      position: fixed;
      inset: 0;
      background: rgba(9, 13, 22, 0.78);
      z-index: 40;
      display: flex;
      align-items: center;
      justify-content: center;
      padding: 16px;
      pointer-events: none;
    }

    .banner-box {
      background: #111827;
      border: 4px solid #facc15;
      box-shadow: 0 0 0 4px #dc2626, 0 8px 0 #030712;
      padding: 20px 26px;
      text-align: center;
      max-width: 92vw;
      animation: bannerPop 0.18s steps(3);
    }

    @keyframes bannerPop {
      from { transform: scale(0.75); opacity: 0; }
      to { transform: scale(1); opacity: 1; }
    }

    .banner-title {
      color: #facc15;
      font-size: 15px;
      margin-bottom: 10px;
      text-shadow: 2px 2px 0 #7f1d1d;
    }

    .banner-sub {
      color: #93c5fd;
      font-size: 10px;
      margin-bottom: 16px;
    }

    .banner-formula-row {
      display: flex;
      align-items: center;
      justify-content: center;
      flex-wrap: wrap;
      gap: 8px;
      background: #090d16;
      border: 3px solid #38bdf8;
      padding: 12px 16px;
    }

    .banner-item {
      display: flex;
      flex-direction: column;
      align-items: center;
      gap: 4px;
    }

    .banner-item canvas {
      width: 44px;
      height: 44px;
      image-rendering: pixelated;
    }

    .banner-step-num {
      font-size: 8px;
      color: #facc15;
    }

    /* Toast rápido de feedback */
    .feedback-toast {
      position: fixed;
      top: 54px;
      left: 50%;
      transform: translateX(-50%);
      background: #111827;
      border: 3px solid #22c55e;
      padding: 6px 12px;
      font-size: 10px;
      color: #86efac;
      z-index: 30;
      box-shadow: 0 4px 0 #030712;
      white-space: nowrap;
    }
    .feedback-toast.error {
      border-color: #ef4444;
      color: #fca5a5;
    }

    /* ==========================================================================
       CONTROLES TÁCTILES RETRO
       ========================================================================== */
    #touch-controls {
      position: fixed;
      inset: 0;
      pointer-events: none;
      z-index: 15;
    }

    #joystick-zone {
      position: absolute;
      bottom: max(16px, env(safe-area-inset-bottom));
      left: max(20px, env(safe-area-inset-left));
      width: 112px;
      height: 112px;
      pointer-events: auto;
    }

    #joystick-base {
      width: 100%;
      height: 100%;
      border-radius: 50%;
      background: rgba(17, 24, 39, 0.45);
      border: 3px solid rgba(250, 204, 21, 0.6);
      position: relative;
      display: flex;
      align-items: center;
      justify-content: center;
    }

    #joystick-stick {
      width: 44px;
      height: 44px;
      border-radius: 50%;
      background: #dc2626;
      border: 3px solid #facc15;
      position: absolute;
      box-shadow: 0 3px 0 #030712;
    }

    #action-buttons {
      position: absolute;
      bottom: max(18px, env(safe-area-inset-bottom));
      right: max(22px, env(safe-area-inset-right));
      display: flex;
      gap: 12px;
      align-items: flex-end;
      pointer-events: auto;
    }

    .action-btn {
      width: 68px;
      height: 68px;
      border-radius: 50%;
      border: 3px solid #facc15;
      background: #1d4ed8;
      color: #fff;
      font-family: inherit;
      font-size: 9px;
      line-height: 1.3;
      cursor: pointer;
      box-shadow: 0 4px 0 #030712;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
    }
    .action-btn:active {
      transform: translateY(2px);
      box-shadow: 0 2px 0 #030712;
    }

    /* ==========================================================================
       MODALES RETRO (INICIO / NIVEL / GAME OVER)
       ========================================================================== */
    .modal-overlay {
      display: none;
      position: fixed;
      inset: 0;
      background: rgba(9, 13, 22, 0.86);
      z-index: 50;
      align-items: center;
      justify-content: center;
      padding: 16px;
    }
    .modal-overlay.active {
      display: flex;
    }

    .pixel-panel {
      background: #111827;
      border: 4px solid #facc15;
      box-shadow: 0 0 0 4px #dc2626, 0 8px 0 #030712;
      padding: 20px 24px;
      max-width: 580px;
      width: 100%;
      text-align: center;
    }

    .pixel-panel h1, .pixel-panel h2 {
      color: #facc15;
      margin-bottom: 14px;
      font-size: 15px;
      line-height: 1.5;
      text-shadow: 2px 2px 0 #7f1d1d;
    }

    .subtitle {
      font-size: 10px;
      line-height: 1.7;
      margin-bottom: 16px;
      color: #e2e8f0;
    }

    .controls-legend {
      display: flex;
      flex-wrap: wrap;
      justify-content: center;
      gap: 10px;
      margin-bottom: 18px;
      font-size: 9px;
      background: #090d16;
      border: 2px solid #334155;
      padding: 10px;
      color: #93c5fd;
    }

    .pixel-btn {
      font-family: inherit;
      font-size: 12px;
      padding: 12px 20px;
      border: 3px solid #facc15;
      background: #dc2626;
      color: #fff;
      cursor: pointer;
      box-shadow: 0 4px 0 #030712;
    }
    .pixel-btn:active {
      transform: translateY(2px);
      box-shadow: 0 2px 0 #030712;
    }

    .summary-box {
      background: #090d16;
      border: 3px solid #22c55e;
      padding: 12px;
      margin: 14px 0 18px;
      display: flex;
      flex-wrap: wrap;
      align-items: center;
      justify-content: center;
      gap: 8px;
    }
    .summary-box canvas {
      width: 30px;
      height: 30px;
      image-rendering: pixelated;
    }
