:root {
  color-scheme: dark;
  --bg: #151821;
  --panel: #202534;
  --panel-2: #2a3143;
  --text: #f4f6fb;
  --muted: #aeb8c8;
  --blue: #58a6ff;
  --green: #57c785;
  --gold: #ffd166;
  --red: #ff6b5e;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  height: 100dvh;
  overflow: hidden;
  background:
    radial-gradient(circle at 18% 10%, rgba(88, 166, 255, 0.16), transparent 28rem),
    linear-gradient(135deg, #11141b 0%, var(--bg) 58%, #1d2028 100%);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.shell {
  width: 100vw;
  height: 100vh;
  margin: 0 auto;
  padding: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr);
  gap: 0;
}

#menuScreen {
  position: absolute;
  inset: 0;
  z-index: 15;
  display: grid;
  place-items: center;
  gap: 18px;
  padding: 32px;
  background: rgba(7, 10, 16, 0.96);
  text-align: center;
}

#menuScreen h1 {
  margin: 0;
  font-size: clamp(2.8rem, 6vw, 4.4rem);
  letter-spacing: -0.05em;
}

.difficultyButtons {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

.difficultyBtn {
  border: 1px solid rgba(244, 246, 251, 0.16);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  color: inherit;
  padding: 12px 18px;
  min-width: 96px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.16s ease, background 0.16s ease, color 0.16s ease;
}

.difficultyBtn:hover,
.difficultyBtn.selected {
  background: var(--gold);
  color: #111;
  transform: translateY(-1px);
}

#playButton {
  min-width: 220px;
  padding: 16px 24px;
  border-radius: 999px;
  background: var(--blue);
  color: #ffffff;
  border: none;
  font-size: 1rem;
  letter-spacing: 0.02em;
  box-shadow: 0 16px 36px rgba(24, 82, 164, 0.35);
  cursor: pointer;
}

#playButton:hover {
  background: #6ea8ff;
}

.menuInfo {
  max-width: 620px;
  color: var(--muted);
  line-height: 1.75;
  font-size: 0.95rem;
}

.hud,
.toolbar {
  position: absolute;
  left: 0;
  width: 100%;
  background: rgba(32, 37, 52, 0.8);
  border: 1px solid rgba(244, 246, 251, 0.1);
  border-radius: 8px;
  padding: 6px;
  z-index: 10;
}

.hud {
  top: 0;
}

.toolbar {
  bottom: 0;
  display: none !important;
}

.hud {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  margin-bottom: 0;
}

.hud div {
  min-width: 0;
  padding: 4px 7px;
  background: var(--panel-2);
  border-radius: 6px;
}

.label {
  display: block;
  color: var(--muted);
  font-size: 0.68rem;
  line-height: 1.2;
}

strong {
  display: block;
  margin-top: 2px;
  font-size: clamp(0.78rem, 1.4vw, 1rem);
  line-height: 1.2;
  overflow-wrap: anywhere;
}

canvas {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  min-height: 0;
  background: #252a31;
  border: none;
  border-radius: 0;
  box-shadow: none;
  object-fit: contain;
}

.toolbar {
  margin-top: 0;
  flex-wrap: wrap;
  gap: 5px;
  max-height: 24dvh;
  overflow-y: auto;
  scrollbar-width: thin;
}
/* 1. Always hidden by default */
#mobile-controls {
    display: none !important;
}

@media screen and (max-width: 1024px) and (pointer: coarse), (max-width: 720px) {
    #mobile-controls {
        display: flex !important;
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        justify-content: space-between;
        gap: 12px;
        padding: 12px 16px 18px;
        background: linear-gradient(180deg, rgba(20, 24, 34, 0.96), rgba(15, 18, 26, 0.97));
        border-top: 1px solid rgba(244, 246, 251, 0.08);
        box-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.05), 0 -18px 32px rgba(0, 0, 0, 0.28);
        z-index: 9999;
        align-items: flex-end;
        pointer-events: auto;
        touch-action: manipulation;
    }

    #mobile-controls .d-pad,
    #mobile-controls .action-btns {
        display: grid;
        gap: 10px;
    }

    .d-pad {
        grid-template-rows: min-content auto;
        align-items: center;
    }

    .d-pad-row {
        display: flex;
        gap: 10px;
        justify-content: center;
    }

    .ctrl-btn,
    .action-btn,
    .action-btn-fire {
        border: none;
        border-radius: 16px;
        background: rgba(255, 255, 255, 0.08);
        color: var(--text);
        font-size: 1rem;
        font-weight: 700;
        box-shadow: 0 14px 30px rgba(0, 0, 0, 0.18);
        min-width: 52px;
        min-height: 52px;
        transition: transform 120ms ease, background 120ms ease, box-shadow 120ms ease;
        touch-action: manipulation;
    }

    .ctrl-btn {
        width: 56px;
        height: 56px;
    }

    .action-btn {
        width: 50px;
        height: 50px;
        border-radius: 14px;
    }

    .action-btn-fire {
        min-width: 96px;
        min-height: 56px;
        border-radius: 20px;
        background: var(--blue);
        color: #fff;
        letter-spacing: 0.02em;
    }

    .ctrl-btn:active,
    .action-btn:active,
    .action-btn-fire:active {
        transform: translateY(1px);
        background: rgba(255, 255, 255, 0.16);
        box-shadow: 0 10px 18px rgba(0, 0, 0, 0.22);
    }

    .help,
    .toolbar {
        display: none !important;
    }
    
    /* Desktop: also hide toolbar */
    @supports (display: grid) {
        .toolbar {
            display: none !important;
        }
        
        .help {
            display: none !important;
        }
    }

    body {
        overflow: hidden;
    }

    .shell {
        width: calc(100vw - 10px);
        height: 100dvh;
        padding: 4px 0;
        gap: 4px;
        position: relative;
    }

    .hud {
        grid-template-columns: repeat(5, minmax(0, 1fr));
        gap: 4px;
    }

    canvas {
        height: auto;
        max-height: 62dvh;
        width: 100%;
        aspect-ratio: auto;
    }

    .powerup-grid {
        grid-template-columns: 1fr;
    }
}
.navy-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.navy-button::before {
  content: "";
  width: 0;
  height: 0;
  border-left: 7px solid transparent;
  border-right: 7px solid transparent;
  border-bottom: 13px solid #2f8cff;
  filter: drop-shadow(0 0 2px rgba(216, 238, 255, 0.75));
}

.powerup-panel {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(7, 10, 16, 0.72);
}

.powerup-panel.hidden,
.hidden {
  display: none;
}

#restartButton {
  position: fixed;
  right: 22px;
  top: 22px;
  z-index: 30;
  background: var(--red);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 14px 22px;
  font-weight: 700;
  box-shadow: 0 16px 36px rgba(255, 107, 94, 0.28);
  cursor: pointer;
  transition: transform 0.16s ease, opacity 0.2s ease, box-shadow 0.2s ease;
}

#restartButton:hover {
  transform: translateY(-1px);
  box-shadow: 0 18px 40px rgba(255, 107, 94, 0.34);
}

.powerup-dialog {
  width: min(760px, 100%);
  padding: 22px;
  background: #202534;
  border: 1px solid rgba(244, 246, 251, 0.16);
  border-radius: 8px;
  box-shadow: 0 22px 70px rgba(0, 0, 0, 0.45);
}

.powerup-kicker {
  color: var(--gold);
  font-weight: 800;
  letter-spacing: 0;
}

.powerup-dialog h2 {
  margin: 4px 0 16px;
  font-size: 1.6rem;
}

.powerup-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.powerup-card {
  height: auto;
  min-height: 150px;
  padding: 14px;
  text-align: left;
  background: #2a3143;
}

.powerup-card strong,
.powerup-card span,
.powerup-card em {
  display: block;
}

.powerup-card strong {
  margin: 0 0 8px;
  font-size: 1.05rem;
}

.powerup-card span {
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.35;
}

.powerup-card em {
  margin-top: 12px;
  color: var(--gold);
  font-size: 0.78rem;
  font-style: normal;
}

/* 1. The "Off" Switch for Desktop */
#mobile-controls {
    display: none !important;
}

/* 2. The "On" Switch for Mobile */
@media (max-width: 932px) and (max-height: 450px), (max-width: 720px) {
  
  #mobile-controls {
    display: flex !important;
    bottom: 10px;
    /* Added z-index to make sure it stays ABOVE the canvas */
    z-index: 9999; 
  }

  body {
    overflow: hidden;
  }

  .shell {
    width: calc(100vw - 10px);
    height: 100dvh;
    padding: 4px 0;
    gap: 4px;
    /* This ensures the shell doesn't push the mobile controls out of view */
    position: relative; 
  }

  .hud {
    /* Keeping 5 columns is fine, but font-size might need to be tiny */
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 4px;
  }

  canvas {
    height: auto;
    max-height: 65dvh; /* Prevents the game from covering the whole screen */
    width: 100%;
    aspect-ratio: auto;
  }

  .powerup-grid {
    grid-template-columns: 1fr;
  }
}
#menuScreen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;

  background: rgba(0, 0, 0, 0.92);

  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;

  z-index: 9999;

  color: white;
}

#menuScreen h1 {
  font-size: 4rem;
  margin-bottom: 20px;
}

#playButton {
  padding: 15px 40px;
  font-size: 24px;
  border: none;
  border-radius: 12px;
  cursor: pointer;
}

.menuTagline {
  margin-top: 16px;
  font-size: 1.1rem;
  color: #ffd166;
  text-transform: uppercase;
  letter-spacing: 0.14em;
}

.difficultyButtons {
  display: flex;
  gap: 15px;
  margin-bottom: 25px;
}

.difficultyBtn {
  padding: 12px 24px;
  font-size: 18px;
  cursor: pointer;
  border-radius: 10px;
  border: none;
}

.difficultyBtn.selected {
  outline: 3px solid white;
}
