:root{
  --green:#42C920;
  --green-soft:#8cff72;
  --black:#000;
}

*{
  box-sizing:border-box;
}

html,
body{
  margin:0;
  min-height:100%;
  background:#000;
  color:var(--green);
  font-family:"Courier New",monospace;
  overflow-x:hidden;
}

body{
  min-height:100vh;
}


/* =========================================================
   NAVBAR
========================================================= */

.galaga-navbar{
  position:fixed;
  top:0;
  left:0;
  right:0;
  height:60px;

  display:flex;
  align-items:center;
  justify-content:space-between;

  padding:0 22px;

  background:rgba(0,0,0,.97);

  border-bottom:1px solid var(--green);

  z-index:1000;
}

.galaga-brand{
  color:var(--green);
  text-decoration:none;

  font-weight:900;
  font-size:20px;
  letter-spacing:3px;

  text-shadow:
    0 0 7px rgba(66,201,32,.75);
}

.galaga-user{
  position:relative;
}

.galaga-user-btn{
  border:1px solid var(--green);

  background:#000;
  color:var(--green);

  padding:9px 13px;

  font-family:inherit;
  font-weight:700;

  cursor:pointer;
}

.galaga-user-menu{
  display:none;

  position:absolute;

  right:0;
  top:calc(100% + 8px);

  min-width:180px;

  border:1px solid var(--green);

  background:#000;
}

.galaga-user-menu.show{
  display:block;
}

.galaga-user-menu a{
  display:block;

  padding:12px 14px;

  color:var(--green);
  text-decoration:none;
}

.galaga-user-menu a:hover{
  background:var(--green);
  color:#000;
}


/* =========================================================
   PAGE
========================================================= */

.galaga-page{
  width:100%;
  max-width:920px;

  margin:0 auto;

  padding:82px 12px 36px;
}

.galaga-header{
  text-align:center;

  margin-bottom:16px;
}

.galaga-header h1{
  margin:0;

  font-size:clamp(28px,5vw,50px);

  letter-spacing:4px;

  text-shadow:
    0 0 6px var(--green),
    0 0 18px rgba(66,201,32,.55);
}

.galaga-header p{
  margin:7px 0 0;

  opacity:.65;

  font-size:clamp(10px,2.2vw,14px);

  letter-spacing:1px;
}


/* =========================================================
   GAME CONTAINER
========================================================= */

.galaga-game{
  width:100%;
  max-width:820px;

  margin:0 auto;
}


/* =========================================================
   HUD SUPERIOR
========================================================= */

.galaga-hud{
  width:100%;

  display:grid;

  grid-template-columns:
    .8fr
    1.25fr
    1.35fr
    1fr;

  gap:7px;

  margin-bottom:8px;
}

.hud-item{
  min-width:0;

  display:flex;
  flex-direction:column;

  align-items:center;
  justify-content:center;

  min-height:58px;

  padding:7px 8px;

  border:1px solid rgba(66,201,32,.58);

  background:#020702;

  text-align:center;

  box-shadow:
    inset 0 0 12px rgba(66,201,32,.035);
}

.panel-label{
  display:block;

  margin-bottom:5px;

  font-size:10px;

  opacity:.55;

  letter-spacing:1px;
}

.hud-item strong{
  display:block;

  max-width:100%;

  overflow:hidden;

  color:var(--green);

  font-size:clamp(13px,2.5vw,19px);

  letter-spacing:1px;

  text-overflow:ellipsis;
  white-space:nowrap;
}

.life-ships{
  display:flex;

  align-items:center;
  justify-content:center;

  gap:6px;

  min-height:23px;
}

.life-ship{
  color:var(--green-soft);

  font-size:clamp(15px,2.8vw,21px);

  text-shadow:
    0 0 7px var(--green);
}


/* =========================================================
   BOARD
========================================================= */

.game-shell{
  position:relative;

  width:100%;

  /*
    El canvas mantiene su espacio lógico de 720 × 820,
    pero visualmente ocupa todo el ancho disponible.
  */
  aspect-ratio:720 / 820;

  border:1px solid var(--green);

  background:#000;

  box-shadow:
    0 0 14px rgba(66,201,32,.35),
    inset 0 0 22px rgba(66,201,32,.06);

  overflow:hidden;
}

#gameCanvas{
  display:block;

  width:100%;
  height:100%;

  background:#000;

  touch-action:none;
}

.game-message{
  position:absolute;

  left:0;
  right:0;
  top:46%;

  padding:0 10px;

  text-align:center;

  color:var(--green-soft);

  font-size:clamp(16px,4vw,29px);
  font-weight:900;

  letter-spacing:2px;

  pointer-events:none;

  text-shadow:
    0 0 8px var(--green),
    0 0 18px rgba(66,201,32,.85);
}


/* =========================================================
   CONTROLES INFERIORES
========================================================= */

.galaga-controls{
  width:100%;

  display:grid;

  grid-template-columns:minmax(150px,1fr) minmax(120px,.78fr);

  gap:10px;

  margin-top:10px;
}

.movement-controls{
  display:grid;

  grid-template-columns:1fr 1fr;

  gap:8px;
}

.control-btn,
.fire-btn,
.matrix-btn{
  appearance:none;

  border:1px solid var(--green);

  background:#000;
  color:var(--green);

  font-family:inherit;
  font-weight:900;

  cursor:pointer;

  transition:
    background .15s,
    color .15s,
    transform .08s,
    box-shadow .15s;

  -webkit-tap-highlight-color:transparent;

  touch-action:manipulation;
}

.control-btn{
  min-height:62px;

  font-size:27px;
}

.fire-btn{
  min-height:62px;

  padding:8px 12px;

  font-size:14px;

  letter-spacing:1px;
}

.control-btn:hover,
.fire-btn:hover,
.matrix-btn:hover{
  background:var(--green);

  color:#000;

  box-shadow:
    0 0 12px rgba(66,201,32,.85);
}

.control-btn:active,
.fire-btn:active{
  transform:scale(.97);
}


/* =========================================================
   ACTIONS
========================================================= */

.bottom-actions{
  display:flex;

  justify-content:center;

  gap:10px;

  margin-top:17px;
}

.matrix-btn{
  display:inline-block;

  min-width:145px;

  padding:10px 18px;

  text-align:center;
  text-decoration:none;
}

.instructions{
  text-align:center;

  margin-top:17px;

  color:var(--green);

  font-size:11px;

  line-height:1.65;

  opacity:.50;
}


/* =========================================================
   VICTORY
========================================================= */

.victory-modal{
  position:fixed;

  inset:0;

  display:none;

  align-items:center;
  justify-content:center;

  padding:20px;

  background:rgba(0,0,0,.82);

  z-index:6000;
}

.victory-modal.show{
  display:flex;
}

.victory-box{
  position:relative;

  width:min(90vw,470px);

  padding:36px 25px;

  border:1px solid var(--green);

  background:#000;

  text-align:center;

  box-shadow:
    0 0 18px rgba(66,201,32,.7),
    0 0 45px rgba(66,201,32,.25);
}

.victory-box h2{
  margin:0;

  font-size:30px;

  letter-spacing:2px;

  text-shadow:
    0 0 9px var(--green);
}

.victory-box p{
  color:var(--green-soft);
}

.close-modal{
  position:absolute;

  right:10px;
  top:6px;

  border:0;

  background:none;

  color:var(--green);

  font-size:28px;

  cursor:pointer;
}


/* =========================================================
   TABLET
========================================================= */

@media(max-width:760px){

  .galaga-page{
    max-width:none;

    padding:
      74px
      5px
      28px;
  }

  .galaga-header{
    margin-bottom:11px;
  }

  .galaga-game{
    max-width:none;
  }

  .galaga-hud{
    gap:4px;

    margin-bottom:5px;
  }

  .hud-item{
    min-height:50px;

    padding:5px 3px;
  }

  .panel-label{
    margin-bottom:3px;

    font-size:8px;
  }

  .hud-item strong{
    font-size:clamp(10px,3vw,15px);
  }

  .life-ships{
    gap:3px;

    min-height:19px;
  }

  .galaga-controls{
    grid-template-columns:1.35fr .8fr;

    gap:6px;

    margin-top:6px;
  }

  .movement-controls{
    gap:5px;
  }

  .control-btn,
  .fire-btn{
    min-height:54px;
  }

  .control-btn{
    font-size:23px;
  }

  .fire-btn{
    padding:5px;

    font-size:11px;
  }

}


/* =========================================================
   MOBILE
========================================================= */

@media(max-width:480px){

  .galaga-navbar{
    height:54px;

    padding:0 9px;
  }

  .galaga-brand{
    font-size:14px;

    letter-spacing:2px;
  }

  .galaga-user-btn{
    padding:7px 8px;

    font-size:10px;
  }

  .galaga-page{
    padding-top:65px;
  }

  .galaga-header h1{
    font-size:clamp(23px,8vw,34px);

    letter-spacing:2px;
  }

  .galaga-header p{
    font-size:9px;
  }

  .galaga-hud{
    grid-template-columns:
      .72fr
      1.15fr
      1.28fr
      .9fr;
  }

  .hud-item{
    min-height:45px;

    padding:4px 2px;
  }

  .panel-label{
    font-size:7px;
  }

  .hud-item strong{
    font-size:10px;
  }

  .life-ship{
    font-size:13px;
  }

  .galaga-controls{
    grid-template-columns:1.45fr .75fr;
  }

  .control-btn,
  .fire-btn{
    min-height:50px;
  }

  .control-btn{
    font-size:21px;
  }

  .fire-btn{
    font-size:9px;

    letter-spacing:0;
  }

  .bottom-actions{
    gap:6px;

    margin-top:12px;
  }

  .matrix-btn{
    min-width:0;

    flex:1;

    padding:9px 12px;

    font-size:11px;
  }

  .instructions{
    margin-top:12px;

    padding:0 5px;

    font-size:9px;
  }

}


/* =========================================================
   FIX CONTROLES: MISMA ALTURA, LATERALES OPUESTOS
========================================================= */

.galaga-controls{
  width:100%;

  display:flex;

  align-items:stretch;
  justify-content:space-between;

  gap:10px;

  margin-top:8px;
}

.movement-controls{
  display:flex;

  align-items:stretch;

  gap:6px;

  flex:0 0 auto;
}

.control-btn{
  width:64px;
  min-width:64px;
  min-height:58px;
}

.fire-btn{
  width:120px;
  min-width:120px;
  min-height:58px;

  margin-left:auto;
}


/* Tablet y móvil */

@media(max-width:760px){

  .galaga-controls{
    display:flex;

    align-items:stretch;
    justify-content:space-between;

    gap:6px;
  }

  .movement-controls{
    display:flex;

    gap:4px;
  }

  .control-btn{
    width:58px;
    min-width:58px;
    min-height:54px;
  }

  .fire-btn{
    width:112px;
    min-width:112px;
    min-height:54px;

    margin-left:auto;
  }

}


@media(max-width:480px){

  .galaga-controls{
    display:flex;

    align-items:stretch;
    justify-content:space-between;

    gap:5px;

    margin-top:5px;
  }

  .movement-controls{
    display:flex;

    gap:3px;
  }

  .control-btn{
    width:62px;
    min-width:62px;
    min-height:54px;

    font-size:21px;
  }

  .fire-btn{
    width:112px;
    min-width:112px;
    min-height:54px;

    margin-left:auto;

    font-size:9px;
  }

}


/* VIEWPORT FIT */
@media(max-width:760px){
  .galaga-page{
    height:100dvh;
    min-height:100dvh;
    overflow:hidden;
    padding-top:60px;
    padding-bottom:3px;
  }
  .galaga-header{
    margin-bottom:5px;
  }
  .galaga-header h1{
    font-size:clamp(22px,7vw,31px);
    line-height:1;
  }
  .galaga-header p{
    margin-top:4px;
    font-size:8px;
  }
  .galaga-hud{
    margin-bottom:3px;
  }
  .hud-item{
    min-height:38px;
  }
  .game-shell{
    width:auto;
    height:calc(100dvh - 205px);
    max-height:none;
    aspect-ratio:720/820;
    margin:0 auto;
  }
  .galaga-controls{
    margin-top:3px;
  }
  .control-btn,.fire-btn{
    min-height:44px;
  }
  .bottom-actions,
  .instructions{
    display:none;
  }
}

@media(min-width:900px) and (min-height:650px){
  .galaga-page{
    height:100dvh;
    overflow:hidden;
    padding-top:68px;
    padding-bottom:4px;
  }
  .galaga-header{
    margin-bottom:4px;
  }
  .galaga-header h1{
    font-size:30px;
  }
  .game-shell{
    height:calc(100dvh - 165px);
    width:auto;
    margin:0 auto;
  }
  .bottom-actions,.instructions{
    display:none;
  }
}


@media(max-width:760px){
  .galaga-page{
    width:100% !important;
    max-width:100vw !important;
    padding-left:8px !important;
    padding-right:8px !important;
    margin-left:auto !important;
    margin-right:auto !important;
  }

  .galaga-header,
  .galaga-game,
  .galaga-hud,
  .game-shell,
  .galaga-controls{
    margin-left:auto !important;
    margin-right:auto !important;
    left:auto !important;
    right:auto !important;
    transform:none !important;
  }

  .galaga-hud,
  .galaga-controls{width:100% !important}
  .game-shell{max-width:100% !important}

  .bottom-actions{
    display:flex !important;
    justify-content:center;
    width:100%;
    margin:4px auto 0 !important;
  }

  .bottom-actions #restartBtn{display:none !important}

  .bottom-actions a.matrix-btn{
    display:flex !important;
    align-items:center;
    justify-content:center;
    width:auto !important;
    min-width:105px;
    min-height:29px;
    padding:4px 14px !important;
    font-size:8px !important;
  }
}

@media(max-width:760px){

  .bottom-actions{
    display:flex !important;

    align-items:center !important;
    justify-content:center !important;

    width:100% !important;

    margin:
      10px
      auto
      4px !important;

    padding:0 !important;
  }

  .bottom-actions #restartBtn{
    display:none !important;
  }

  .bottom-actions a.matrix-btn{
    display:flex !important;

    align-items:center !important;
    justify-content:center !important;

    width:auto !important;
    min-width:112px !important;

    height:34px !important;
    min-height:34px !important;

    margin:0 auto !important;

    padding:
      0
      17px !important;

    line-height:1 !important;

    text-align:center !important;

    font-size:9px !important;

    box-sizing:border-box !important;
  }

}


/*
  Reservamos esos píxeles en el área del tablero para que
  INICIO no obligue a hacer scroll.
*/
@media(max-width:760px) and (max-height:900px){

  .game-shell{
    height:
      calc(
        100dvh -
        221px
      ) !important;
  }

}


