* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  min-width: 0;
  margin: 0;
  padding: 0;

  overflow: hidden;

  background: #05030d;
}

body {
  font-family:
    Arial,
    Helvetica,
    sans-serif;

  color: #ffffff;

  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button {
  font: inherit;
}


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

#game {
  position: relative;

  width: 100%;
  height: 100%;

  min-height: 100vh;
  min-height: 100dvh;

  overflow: hidden;

  background:
    radial-gradient(
      circle at 50% 45%,
      rgba(95, 54, 180, 0.16),
      transparent 35%
    ),
    radial-gradient(
      circle at 20% 20%,
      rgba(124, 78, 255, 0.08),
      transparent 30%
    ),
    #05030d;
}


/* =========================================================
   GAME CANVAS
   ========================================================= */

#gameCanvas {
  position: absolute;

  inset: 0;

  display: block;

  width: 100%;
  height: 100%;

  z-index: 1;

  pointer-events: auto;
}


/* =========================================================
   GAME-ONLY ELEMENTS
   Hidden until actual gameplay begins.
   ========================================================= */

.game-only {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
}

#game.playing .game-only {
  visibility: visible;
  opacity: 1;
  pointer-events: auto;
}


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

#hud {
  position: absolute;

  top: 0;
  left: 0;
  right: 0;

  z-index: 20;

  display: grid;

  grid-template-columns:
    1fr
    1fr;

  align-items: start;

  gap: 20px;

  padding:
    max(20px, env(safe-area-inset-top))
    clamp(18px, 5vw, 60px)
    20px;

  transition:
    opacity 180ms ease;
}

.hud-item {
  display: flex;

  flex-direction: column;

  gap: 5px;

  min-width: 90px;
}

.hud-score {
  align-items: flex-start;
  text-align: left;
}

.hud-shield {
  align-items: center;
  text-align: center;
}

.hud-energy {
  align-items: flex-end;
  text-align: right;
}

.hud-label {
  font-size: 10px;

  font-weight: 700;

  letter-spacing: 0.22em;

  opacity: 0.55;
}

.hud-item > span:not(.hud-label) {
  font-size:
    clamp(18px, 3.5vw, 28px);

  font-weight: 700;

  letter-spacing: 0.04em;

  line-height: 1;
}


/* =========================================================
   ALL SCREENS
   ========================================================= */

.screen {
  position: absolute;

  inset: 0;

  z-index: 50;

  display: flex;

  flex-direction: column;

  align-items: center;

  justify-content: center;

  width: 100%;
  height: 100%;

  min-height: 100vh;
  min-height: 100dvh;

  padding:
    max(30px, env(safe-area-inset-top))
    30px
    max(90px, env(safe-area-inset-bottom));

  overflow: hidden;

  text-align: center;

  background:
    radial-gradient(
      circle at center,
      rgba(30, 15, 70, 0.78),
      rgba(5, 3, 13, 0.97) 72%
    );
}

.screen.hidden {
  display: none;
}

.screen-content {
  position: relative;

  z-index: 2;

  width: min(900px, 100%);

  max-height: 100%;

  display: flex;

  flex-direction: column;

  align-items: center;

  justify-content: center;
}


/* =========================================================
   EYEBROW
   ========================================================= */

.eyebrow {
  margin: 0 0 14px;

  font-size: 11px;

  font-weight: 700;

  letter-spacing: 0.3em;

  opacity: 0.6;
}


/* =========================================================
   HEADINGS
   ========================================================= */

.screen h1,
.screen h2 {
  margin: 0;

  letter-spacing: 0.08em;

  line-height: 1;
}

.screen h1 {
  font-size:
    clamp(44px, 10vw, 92px);
}

.screen h2 {
  font-size:
    clamp(28px, 7vw, 56px);
}


/* =========================================================
   STORY SCREEN
   ========================================================= */

.story-screen {
  justify-content: flex-start;

  padding-top:
    max(38px, env(safe-area-inset-top));

  padding-right:
    clamp(20px, 6vw, 70px);

  padding-left:
    clamp(20px, 6vw, 70px);

  padding-bottom:
    calc(
      110px +
      env(safe-area-inset-bottom)
    );

  background:
    radial-gradient(
      ellipse at 50% 25%,
      rgba(52, 26, 115, 0.22),
      transparent 52%
    ),
    linear-gradient(
      to bottom,
      rgba(5, 3, 13, 0.94),
      rgba(5, 3, 13, 0.99)
    );
}


/* =========================================================
   STORY CONTENT
   ========================================================= */

.story-content {
  position: relative;

  z-index: 2;

  width: min(850px, 100%);

  height: 100%;

  display: flex;

  flex-direction: column;

  align-items: center;

  justify-content: flex-start;

  padding-top:
    clamp(20px, 5vh, 55px);

  overflow: hidden;
}

.story-screen .eyebrow {
  margin-bottom: 14px;
}

.story-screen h1 {
  flex-shrink: 0;

  text-shadow:
    0 0 20px rgba(160, 120, 255, 0.18),
    0 0 50px rgba(100, 60, 200, 0.12);
}


/* =========================================================
   STORY DIVIDER
   ========================================================= */

.story-divider {
  width:
    min(260px, 50vw);

  height: 1px;

  margin:
    24px
    0
    22px;

  background:
    linear-gradient(
      90deg,
      transparent,
      rgba(190, 160, 255, 0.65),
      transparent
    );
}


/* =========================================================
   STORY TITLE
   ========================================================= */

.story-screen h2 {
  flex-shrink: 0;

  font-size:
    clamp(18px, 3vw, 30px);

  font-weight: 700;

  letter-spacing: 0.22em;

  color: #d8caff;

  text-shadow:
    0 0 18px rgba(180, 150, 255, 0.22);
}


/* =========================================================
   STORY TEXT
   ========================================================= */

.story-text {
  width: min(760px, 100%);

  margin-top:
    clamp(20px, 3vh, 30px);

  padding:
    0 10px
    120px;

  overflow: hidden;

  text-align: center;
}

.story-text p {
  margin:
    0 auto
    18px;

  max-width: 720px;

  font-size:
    clamp(14px, 1.7vw, 19px);

  font-weight: 500;

  line-height: 1.55;

  letter-spacing: 0.025em;

  color: rgba(255, 255, 255, 0.82);

  text-shadow:
    0 0 12px rgba(150, 110, 255, 0.08);
}

.story-text p:last-child {
  margin-bottom: 0;
}

.story-text .story-final {
  margin-top: 26px;

  font-size:
    clamp(17px, 2vw, 23px);

  font-weight: 700;

  letter-spacing: 0.16em;

  color: #d9c9ff;

  text-transform: uppercase;

  text-shadow:
    0 0 18px rgba(170, 130, 255, 0.25);
}


/* =========================================================
   BEGIN MISSION BUTTON
   FIXED — DOES NOT MOVE WITH STORY
   ========================================================= */

.story-button {
  position: fixed;

  left: 50%;

  bottom:
    max(26px, env(safe-area-inset-bottom));

  z-index: 100;

  display: flex;

  align-items: center;

  justify-content: center;

  min-width: 210px;

  min-height: 56px;

  padding:
    15px
    28px;

  transform:
    translateX(-50%);

  border:
    1px solid
    rgba(190, 160, 255, 0.55);

  border-radius: 999px;

  background:
    rgba(85, 45, 160, 0.35);

  color: #ffffff;

  cursor: pointer;

  font-weight: 700;

  letter-spacing: 0.13em;

  box-shadow:
    0 8px 35px
    rgba(75, 40, 150, 0.2);

  transition:
    background 160ms ease,
    border-color 160ms ease,
    box-shadow 160ms ease,
    transform 160ms ease;
}

.story-button:hover {
  transform:
    translateX(-50%)
    translateY(-2px);

  background:
    rgba(120, 75, 220, 0.45);

  border-color:
    rgba(215, 200, 255, 0.85);

  box-shadow:
    0 10px 40px
    rgba(100, 60, 220, 0.3);
}

.story-button:active {
  transform:
    translateX(-50%);
}

.story-button:focus-visible {
  outline:
    2px solid #ffffff;

  outline-offset: 4px;
}


/* =========================================================
   MISSION READY SCREEN
   ========================================================= */

#startScreen {
  background:
    radial-gradient(
      circle at center,
      rgba(45, 25, 100, 0.55),
      rgba(5, 3, 13, 0.97) 72%
    );
}


/* =========================================================
   INSTRUCTIONS
   ========================================================= */

.instructions {
  width:
    min(760px, 100%);

  display: grid;

  grid-template-columns:
    repeat(2, minmax(0, 1fr));

  gap: 12px;

  margin:
    28px 0
    18px;
}

.instruction {
  display: flex;

  flex-direction: column;

  gap: 8px;

  min-height: 96px;

  padding:
    16px
    18px;

  border:
    1px solid
    rgba(180, 150, 255, 0.16);

  border-radius: 14px;

  background:
    linear-gradient(
      145deg,
      rgba(100, 60, 180, 0.12),
      rgba(40, 20, 80, 0.08)
    );

  text-align: left;
}

.instruction strong {
  font-size: 11px;

  letter-spacing: 0.12em;

  color: #e7ddff;
}

.instruction span {
  font-size: 12px;

  line-height: 1.5;

  opacity: 0.62;
}


/* =========================================================
   MISSION INSTRUCTION
   ========================================================= */

.mission-instruction {
  max-width: 600px;

  margin:
    8px 0
    20px;

  font-size:
    clamp(13px, 1.7vw, 16px);

  line-height: 1.5;

  opacity: 0.62;
}


/* =========================================================
   GENERAL SCREEN BUTTONS
   ========================================================= */

.screen button:not(.story-button) {
  min-width: 190px;

  min-height: 52px;

  padding:
    14px
    24px;

  border:
    1px solid
    rgba(180, 150, 255, 0.45);

  border-radius: 999px;

  background:
    rgba(120, 75, 220, 0.18);

  color: #ffffff;

  cursor: pointer;

  font-weight: 700;

  letter-spacing: 0.12em;

  transition:
    transform 160ms ease,
    background 160ms ease,
    border-color 160ms ease,
    box-shadow 160ms ease;
}

.screen button:not(.story-button):hover {
  transform:
    translateY(-2px);

  background:
    rgba(120, 75, 220, 0.32);

  border-color:
    rgba(200, 180, 255, 0.75);

  box-shadow:
    0 8px 30px
    rgba(100, 60, 220, 0.18);
}

.screen button:not(.story-button):active {
  transform:
    translateY(0);
}

.screen button:focus-visible {
  outline:
    2px solid #ffffff;

  outline-offset: 4px;
}


/* =========================================================
   GENERAL SCREEN PARAGRAPHS
   ========================================================= */

.screen-content > p:not(.eyebrow) {
  max-width: 560px;

  margin:
    16px 0;

  font-size:
    clamp(14px, 2vw, 18px);

  line-height: 1.6;

  opacity: 0.72;
}

.screen-content strong {
  color: #ffffff;
}


/* =========================================================
   GAME OVER
   ========================================================= */

#gameOverScreen {
  background:
    radial-gradient(
      circle at center,
      rgba(60, 20, 90, 0.5),
      rgba(5, 3, 13, 0.97) 72%
    );
}

#achievementMessage {
  color: #d8caff;
}


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

#victoryScreen {
  background:
    radial-gradient(
      circle at center,
      rgba(70, 35, 150, 0.5),
      rgba(5, 3, 13, 0.97) 72%
    );
}

#victoryScreen h2 {
  text-shadow:
    0 0 30px
    rgba(170, 130, 255, 0.45);
}

#victoryReward {
  color: #d8caff;
}


/* =========================================================
   MILESTONE MESSAGE
   ========================================================= */

.milestone-message {
  position: absolute;

  top: 50%;
  left: 50%;

  z-index: 40;

  display: flex;

  flex-direction: column;

  align-items: center;

  gap: 10px;

  width:
    min(90%, 560px);

  padding: 24px;

  border:
    1px solid
    rgba(200, 180, 255, 0.35);

  border-radius: 18px;

  background:
    rgba(10, 5, 25, 0.88);

  box-shadow:
    0 0 50px
    rgba(100, 60, 220, 0.18);

  text-align: center;

  transform:
    translate(-50%, -50%);

  backdrop-filter: blur(10px);
}

.milestone-message.hidden {
  display: none;
}

#milestoneTitle {
  font-size:
    clamp(22px, 5vw, 42px);

  font-weight: 800;

  letter-spacing: 0.1em;
}

#milestoneText {
  font-size: 13px;

  line-height: 1.5;

  letter-spacing: 0.08em;

  opacity: 0.68;
}


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

@media (max-width: 700px) {

  #hud {
    grid-template-columns:
      1fr
      auto
      1fr;

    gap: 10px;

    padding:
      max(15px, env(safe-area-inset-top))
      16px
      15px;
  }

  .hud-item {
    min-width: 0;
  }

  .hud-item > span:not(.hud-label) {
    font-size: 18px;
  }

  .hud-label {
    font-size: 8px;
  }


  /* STORY */

  .story-screen {
    padding-right: 16px;
    padding-left: 16px;

    padding-bottom:
      calc(
        105px +
        env(safe-area-inset-bottom)
      );
  }

  .story-content {
    padding-top:
      clamp(
        12px,
        3vh,
        30px
      );
  }

  .story-screen h1 {
    font-size:
      clamp(
        38px,
        13vw,
        62px
      );
  }

  .story-divider {
    margin:
      18px
      0
      18px;
  }

  .story-screen h2 {
    font-size:
      clamp(
        16px,
        5vw,
        23px
      );

    letter-spacing:
      0.16em;
  }

  .story-text {
    margin-top: 18px;

    padding:
      0
      5px
      100px;
  }

  .story-text p {
    margin-bottom: 14px;

    font-size:
      clamp(
        13px,
        3.7vw,
        17px
      );

    line-height: 1.48;
  }

  .story-text .story-final {
    margin-top: 20px;

    font-size:
      clamp(
        15px,
        4.5vw,
        20px
      );
  }


  /* BEGIN BUTTON */

  .story-button {
    width:
      min(
        calc(100vw - 40px),
        280px
      );

    min-height: 54px;

    bottom:
      max(
        22px,
        env(safe-area-inset-bottom)
      );
  }


  /* INSTRUCTIONS */

  .instructions {
    grid-template-columns: 1fr;

    gap: 8px;

    margin:
      18px 0
      12px;

    width: 100%;
  }

  .instruction {
    min-height: auto;

    padding:
      12px
      14px;

    gap: 5px;
  }

  .instruction strong {
    font-size: 10px;
  }

  .instruction span {
    font-size: 11px;

    line-height: 1.4;
  }

  .mission-instruction {
    font-size: 12px;

    margin:
      4px 0
      14px;
  }


  /* GENERAL BUTTONS */

  .screen button:not(.story-button) {
    width:
      min(
        100%,
        280px
      );

    min-height: 54px;
  }


  /* DASH */

}


/* =========================================================
   VERY SMALL SCREENS
   ========================================================= */

@media (max-height: 650px) {

  .story-content {
    padding-top: 8px;
  }

  .story-screen h1 {
    font-size:
      clamp(
        34px,
        9vw,
        52px
      );
  }

  .story-divider {
    margin:
      12px 0;
  }

  .story-text {
    margin-top: 10px;
  }

  .story-text p {
    margin-bottom: 10px;

    font-size: 13px;

    line-height: 1.35;
  }

  .story-text .story-final {
    margin-top: 14px;
  }

}


/* =========================================================
   ACCESSIBILITY / REDUCED MOTION
   ========================================================= */

@media (prefers-reduced-motion: reduce) {

  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;

    transition-duration: 0.01ms !important;

    animation-duration: 0.01ms !important;

    animation-iteration-count: 1 !important;
  }

}
