@font-face {
    font-family: 'Dedicool';
    src: url('assets/Dedicool.ttf') format('truetype');
}

@font-face {
    font-family: 'Poppkorn';
    src: url('assets/PoppkornRegular-MzKY.ttf') format('truetype');
}

:root{--bg:#120b1b;--ui:#ddd}
    html,body{height:100%;margin:0;background:transparent;-webkit-tap-highlight-color:transparent;touch-action:none;font-family:'Dedicool', sans-serif;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}
    #background {
      position: fixed;
      top: 0;
      left: 0;
      width: 100vw;
      height: 100vh;
      background: var(--bg);
      z-index: -11;
    }
    #gameWrap{position:fixed;top: 0; right: 0; bottom: 0; left: 0;overflow:hidden;z-index:2}
    canvas{display:block;width:100vw;height:100vh;background:transparent;}
    img {
      image-rendering: pixelated;
      image-rendering: crisp-edges;
    }

    #damageFlash {
      position: fixed;
      top: 0;
      left: 0;
      width: 100vw;
      height: 100vh;
      background-color: rgba(255, 0, 0, 0.5); /* Semi-transparent red */
      z-index: 90; /* Above game elements, below modals */
      opacity: 0; /* Hidden by default */
      pointer-events: none; /* Allow clicks to pass through */
      transition: opacity 0.1s ease-out; /* Smooth fade out */
    }

    #motherShipImage {
      position: absolute;
      top: 30%;
      left: 50%;
      transform: translateX(-50%);
      width: 80%;
      max-width: 300px;
      animation: float 6s ease-in-out infinite;
      z-index: 50;
    }
    @keyframes float {
      0% { transform: translate(-50%, 0px); }
      50% { transform: translate(-50%, -20px); }
      100% { transform: translate(-50%, 0px); }
    }
    @keyframes fadeIn {
      from { opacity: 0; }
      to { opacity: 1; }
    }
    /* UI overlay */
    .ui {position:fixed;left:0;top:0;right:0;bottom:0;pointer-events:none;}
    #top-bar {
      position: fixed;
      top: 0;
      left: 0;
      right: 0;
      height: 40px;
      background-color: transparent;
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 0 10px;
      color: white;
      font-family: 'Dedicool', sans-serif;
    }
    #hearts {
      display: flex;
      align-items: center;
      gap: 5px;
    }
    .heart-icon{
      width: 24px;
      height: 24px;
      vertical-align: middle;
    }
    .bossBar{position:fixed;left:50%;top:50px;transform:translateX(-50%);width:60%;height:12px;background:rgba(255,255,255,0.06);border: 2px solid white;box-sizing: border-box;overflow:hidden;display:none}
    .bossBarInner{height:100%;background:#f65c92;width:100%}
    /* joystick + buttons */
    .left-joystick, .right-buttons{position:absolute;pointer-events:auto}
    .left-joystick{left:8px;bottom:8px;width:140px;height:140px;max-width:22vw;max-height:22vw;}
    .right-buttons{right:8px;bottom:8px;width:170px;height:140px;display:flex;gap:12px;justify-content:flex-end;align-items:flex-end;max-width:30vw;max-height:22vw;pointer-events:auto}
    .btn{width:64px;height:64px;border-radius:0;background:transparent;border:2px solid white;display:flex;align-items:center;justify-content:center;touch-action:manipulation}
    .btn:active{transform:translateY(2px) scale(0.98)}
    .btn.cooldown {
      background-color: rgba(255, 0, 0, 0.5);
    }
    .btn.firing {
      background-color: rgba(255, 0, 0, 0.5);
    }
    .btn img{width:36px;height:36px;object-fit:contain}
    .btn-text {
      display: none;
      color: white;
      font-family: 'Dedicool', sans-serif;
      font-size: 12px;
      margin-top: 4px;
    }
    .joystick-base {
      width: 100%;
      height: 100%;
      border: 2px solid white;
      display: flex;
      align-items: center;
      justify-content: center;
    }
    .joystick-knob {
      width: 40px;
      height: 40px;
      background: white;
    }
    /* screens (menu/levels) */
    .screen {position:fixed;inset:0;display:flex;align-items:center;justify-content:center;background: url('assets/nebulitebg1.png') no-repeat center center / cover;color:var(--ui);z-index:40}
    .menu-panel {
      width: 100%;
      height: 100%;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      text-align: center;
    }
    .game-title {
      font-family: 'Dedicool', sans-serif;
      font-size: clamp(3rem, 15vw, 6rem);
      color: var(--ui);
      text-shadow: 4px 4px 0px #4b8bcf, 8px 8px 0px #e641ba;
      margin-bottom: 40px;
    }

    .menu-panel > div {
      display: flex;
      flex-direction: column;
      gap: 10px;
    }

    .panel {
      background: rgba(10, 8, 15, 0.9);
      padding: 20px;
      border-radius: 0;
      border: 2px solid white;
      width: 92%;
      max-width: 420px;
      display: flex;
      flex-direction: column;
      align-items: center;
    }

    .btn-ui {
      font-family: 'Dedicool', sans-serif;
      color: #fff;
      background: rgba(0,0,0,0.4);
      border: 2px solid #fff;
      padding: 10px 18px;
      font-size: 1.2rem;
      cursor: pointer;
      box-shadow: 0 4px 12px rgba(0,0,0,0.3);
      transition: all .1s ease;
    }

#scores-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  max-width: 400px;
}

.level-score-row {
  display: flex;
  justify-content: space-between;
  padding: 5px 10px;
  background-color: rgba(0, 0, 0, 0.2);
  border-radius: 5px;
}

#scores-list h3 {
  margin-top: 10px;
  margin-bottom: 5px;
  text-align: left;
}

    .btn-ui:hover {
      background: white;
      color: var(--bg);
    }

    .btn-danger {
      background-color: #992222;
      border-color: #cc4444;
    }
    .btn-danger:hover {
      background-color: #cc4444;
      border-color: #ff6666;
    }

    #screenGameOver .panel .btn-ui {
      width: 180px; /* Adjust as needed to fit 'Level Select' */
      margin: 10px auto; /* Center block-level buttons */
      display: block;
    }

    .player-area-btn {
      width: 220px; /* Increased width to accommodate longer text */
      margin: 10px auto; /* Center buttons */
      display: block;
    }
    .dialogue-panel {
      width: 100%;
      max-width: 100%;
      height: 33.33vh;
      position: absolute;
      bottom: 0;
      border-radius: 0;
      border-top: 2px solid white;
      border-bottom: none;
      border-left: none;
      border-right: none;
      display: flex;
      flex-direction: row; /* Override panel's column direction */
      align-items: flex-start;
      padding: 15px;
      box-sizing: border-box;
    }
    #dialogueImage {
      width: 100px;
      height: 100px;
      margin-right: 15px;
      object-fit: cover;
      border: 2px solid white;
      flex-shrink: 0;
    }
    .dialogue-content {
      display: flex;
      flex-direction: column;
      align-items: flex-start; /* Align text to the left */
      flex-grow: 1;
    }
    #dialogueText {
      font-size: 18px;
      margin: 0;
      color: var(--ui);
      text-align: left; /* Ensure text is left-aligned */
    }
    #btnDialogueGo {
      margin-top: 10px; /* Added margin for spacing */
    }
    .sectors-grid {
      display: flex;
      gap: 16px;
      flex-wrap: wrap;
      justify-content: center;
      margin-top: 12px;
    }
    .sector-btn {
      width: 140px;
      cursor: pointer;
      text-align: center;
      transition: transform 0.2s;
    }
    .sector-btn:hover {
      transform: scale(1.05);
    }
    .sector-btn.locked {
      opacity: 0.4;
      filter: grayscale(80%);
      pointer-events: none;
    }
    .sector-image {
      width: 100%;
      height: 140px;
      object-fit: cover;
      border-radius: 10px;
      border: 2px solid rgba(255,255,255,0.1);
      margin-bottom: 8px;
    }
    .sector-title {
      font-size: 18px;
      color: var(--ui);
      font-family: 'Dedicool', sans-serif;
    }
    .levels-grid{display:flex;gap:8px;flex-wrap:wrap;justify-content:center;margin-top:12px}
    .level-btn{width:88px;height:88px;border-radius:10px;background:rgba(255,255,255,0.03);display:flex;align-items:center;justify-content:center;font-size:16px;color:var(--ui);border:2px solid rgba(255,255,255,0.04)}
    .level-btn.locked{opacity:0.35}
    .small{font-size:12px;color:#aaa;margin-top:6px}
    .setting .small {
  text-align: center;
}

.debug{
  position:fixed;
  left:50%;
  top:70px;
  transform:translateX(-50%);
  color:#999;
  font-size:12px;
  pointer-events:none;
  background: rgba(0,0,0,0.5);
  padding: 4px 8px;
  border-radius: 4px;
  z-index: 10;
}

.bossName {
  position: fixed;
  left: 50%;
  top: 70px;
  transform: translateX(-50%);
  color: var(--ui);
  font-size: 14px;
  display: none;
  font-family: "Dedicool", sans-serif;
}

.settings-container {
  display: flex;
  flex-direction: column;
  gap: 20px;
  width: 100%;
  padding: 10px;
}

.setting {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center; /* Center content horizontally */
  gap: 10px;
}

.setting label {
  font-size: 18px;
  font-family: "Dedicool", sans-serif;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 90%; /* Adjusted width */
  height: 8px;
  background: transparent;
  border: 2px solid white;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 20px;
  height: 20px;
  background: white;
  cursor: pointer;
}

input[type="range"]::-moz-range-thumb {
  width: 20px;
  height: 20px;
  background: white;
  cursor: pointer;
  border: none;
}

.setting input[type="checkbox"] {
  -webkit-appearance: none;
  appearance: none;
  position: relative;
  width: 24px;
  height: 24px;
  border: 2px solid white;
  cursor: pointer;
  outline: none;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.setting input[type="checkbox"]::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 16px;
  height: 16px;
  background-color: transparent;
  transition: background-color 0.2s ease;
}

.setting input[type="checkbox"]:checked::before {
  background-color: white;
}

.setting input[type="checkbox"]::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0);
  width: 16px;
  height: 16px;
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="white"><path d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"/></svg>');
  background-size: cover;
  background-repeat: no-repeat;
  transition: transform 0.2s ease;
}

.setting input[type="checkbox"]:checked::after {
  transform: translate(-50%, -50%) scale(1);
}


#resetConfirmationModal {
  z-index: 99;
}

.custom-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
}

#currentControl {
  font-family: "Dedicool", sans-serif;
  font-size: 18px;
  color: white;
}

.toggle-arrow {
  background: transparent;
  border: none;
  color: white;
  font-size: 24px;
  cursor: pointer;
}
#btnPlayer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px; /* Space between text and icon */
}

.btn-player-icon {
  width: 24px;
  height: 24px;
  animation: wiggle 2s ease-in-out infinite;
}

    @keyframes wiggle {
      0%, 100% { transform: rotate(-5deg); }
      50% { transform: rotate(5deg); }
    }

.btn-icon {
    background: transparent;
    border: none;
    color: white;
    cursor: pointer;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: auto;
}
.btn-icon img {
    width: 24px;
    height: 24px;
}

#achievements-list {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 10px;
}

.achievement-item {
  background: rgba(255, 255, 255, 0.1);
  padding: 10px;
  border-radius: 5px;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.achievement-item.locked {
  opacity: 0.5;
  background: rgba(0, 0, 0, 0.2);
  border-color: rgba(255, 255, 255, 0.1);
}

.achievement-title {
  font-family: 'Dedicool', sans-serif;
  font-size: 18px;
  margin: 0;
}

.achievement-title.unlocked-blue {
  color: #4b8bcf;
}

.achievement-title.unlocked-orange {
  color: #ffa500;
}

.achievement-description {
  font-size: 14px;
  margin: 5px 0 0 0;
  color: #ccc;
}

.achievement-title-container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.present-icon {
  width: 24px;
  height: 24px;
  animation: wiggle 2s ease-in-out infinite;
}

.present-icon.locked {
  opacity: 0.3;
  filter: grayscale(1);
  animation: none;
}

.skin-selector-container {
  margin-top: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.skin-selector {
  display: flex;
  align-items: center;
  gap: 15px;
}

.skin-nav-btn {
  background: transparent;
  border: none;
  cursor: pointer;
}

.skin-nav-btn img {
  width: 32px;
  height: 32px;
}

#prevSkinBtn img {
  transform: scaleX(-1);
}

#playerSkin {
  width: 64px;
  height: 64px;
  border: 2px solid white;
  padding: 5px;
}

@media (min-width: 600px) and (orientation: landscape), (min-width: 600px) and (min-aspect-ratio: 1/1) {
  .btn {
    flex-direction: column;
    height: auto;
    padding-bottom: 4px;
  }
  .btn-text {
    display: block;
  }
  body {
    background-color: black;
  }

  #gameWrap {
    position: relative;
    top: unset;
    right: unset;
    bottom: unset;
    left: unset;
    margin: 0 auto;
    max-width: min(100vh * (9 / 16), 100vw);
    height: 100vh;
    display: flex;
    justify-content: center;
  }

  canvas {
    width: 100%;
    height: 100%;
  }
}