:root {
  --green: #63f397;
  --cyan: #5fdcff;
  --orange: #ff9c6a;
  --violet: #a989ff;
  --ink: #020605;
  --panel: #07110c;
  --line: #1b3b2c;
  --muted: #789085;
  --game-ratio: 16 / 9;
}

* { box-sizing: border-box; }

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--ink);
  color: #eefcf4;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overscroll-behavior: none;
}

body { min-height: 100dvh; }

button,
a { -webkit-tap-highlight-color: transparent; }

.game-shell {
  width: min(100%, 1500px);
  min-height: 100dvh;
  margin: auto;
  display: flex;
  flex-direction: column;
  background: #020605;
}

.topbar {
  min-height: 68px;
  padding: 0 18px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  border-bottom: 1px solid #163024;
  background: #050b08;
  flex: 0 0 auto;
}

.back {
  color: var(--green);
  text-decoration: none;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: .14em;
}

.title { text-align: center; line-height: 1; }
.title strong { display: block; font-size: 16px; letter-spacing: .07em; }
.title small {
  display: block;
  margin-top: 6px;
  color: #688176;
  font-size: 7px;
  font-weight: 900;
  letter-spacing: .18em;
}

.hud-button {
  justify-self: end;
  min-height: 38px;
  padding: 0 13px;
  border: 1px solid #2a5741;
  background: #07110c;
  color: #a3baaf;
  font: 900 9px/1 inherit;
  letter-spacing: .12em;
  cursor: pointer;
}

.hud-button:focus-visible,
.mobile-controls button:focus-visible,
.back:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 3px;
}

.game-wrap {
  position: relative;
  flex: 1 0 auto;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  background:
    linear-gradient(rgba(28, 73, 52, .08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(28, 73, 52, .08) 1px, transparent 1px),
    #020605;
  background-size: 24px 24px;
  overflow: hidden;
}

.game-stage {
  position: relative;
  width: min(100%, calc((100dvh - 118px) * 1.7777778));
  aspect-ratio: var(--game-ratio);
  margin: 0 auto;
  flex: 0 0 auto;
  overflow: hidden;
  background: #020504;
  box-shadow: 0 20px 70px rgba(0, 0, 0, .42);
  touch-action: none;
}

#phaserGame,
#phaserGame canvas {
  width: 100% !important;
  height: 100% !important;
}

#phaserGame canvas { display: block; touch-action: none; }

.load-error {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: grid;
  place-content: center;
  padding: 24px;
  text-align: center;
  gap: 9px;
  background: #030706;
  color: #dfffe9;
}

.load-error strong { color: var(--orange); letter-spacing: .1em; }
.load-error span { color: #789085; font-size: 13px; }

.instructions {
  min-height: 50px;
  padding: 11px 16px;
  display: flex;
  gap: 22px;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  flex: 0 0 auto;
  border-top: 1px solid #163024;
  color: #647b70;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: .08em;
}

.instructions b { color: #a6c4b5; margin-right: 4px; }

.mobile-controls {
  display: none;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
}

.control-cluster {
  display: flex;
  align-items: center;
  gap: 10px;
}

.mobile-controls button {
  position: relative;
  pointer-events: auto;
  display: grid;
  place-items: center;
  width: 72px;
  height: 72px;
  padding: 0;
  border: 1px solid rgba(110, 246, 164, .55);
  border-radius: 24px;
  background: linear-gradient(145deg, rgba(14, 35, 25, .96), rgba(3, 10, 7, .96));
  box-shadow: inset 0 1px 0 rgba(220, 255, 235, .1), 0 8px 22px rgba(0, 0, 0, .32);
  color: #e5fff0;
  font: 1000 24px/1 inherit;
  touch-action: none;
}

.mobile-controls button::after {
  content: "";
  position: absolute;
  inset: 7px;
  border: 1px solid rgba(99, 243, 151, .12);
  border-radius: 17px;
}

.mobile-controls .action {
  width: 78px;
  height: 78px;
  border-radius: 50%;
  font-size: 10px;
  letter-spacing: .08em;
}

.mobile-controls .action::after { border-radius: 50%; }
.mobile-controls .jump { border-color: rgba(95, 220, 255, .65); color: #cff7ff; }
.mobile-controls .fire {
  border-color: rgba(255, 156, 106, .78);
  color: #ffddca;
  background: linear-gradient(145deg, rgba(55, 23, 13, .98), rgba(20, 7, 5, .98));
}

.mobile-controls button.pressed,
.mobile-controls button[aria-pressed="true"] {
  transform: translateY(3px) scale(.95);
  border-color: var(--green);
  background: linear-gradient(145deg, rgba(38, 105, 69, .98), rgba(7, 25, 15, .98));
  box-shadow: inset 0 2px 10px rgba(0, 0, 0, .38), 0 0 24px rgba(99, 243, 151, .16);
}

.mobile-controls .fire.pressed,
.mobile-controls .fire[aria-pressed="true"] {
  border-color: var(--orange);
  background: linear-gradient(145deg, rgba(126, 49, 27, .98), rgba(31, 9, 5, .98));
  box-shadow: inset 0 2px 10px rgba(0, 0, 0, .38), 0 0 24px rgba(255, 156, 106, .2);
}

.touch-tip {
  display: none;
  pointer-events: none;
  color: #537064;
  font-size: 8px;
  font-weight: 900;
  letter-spacing: .16em;
  text-align: center;
  white-space: nowrap;
}

.touch-device .instructions { display: none; }

.touch-device:not(.portrait-game) .game-stage {
  width: min(100%, calc((100dvh - 68px) * 1.7777778));
}

.touch-device:not(.portrait-game) .mobile-controls {
  position: absolute;
  z-index: 9;
  left: 0;
  right: 0;
  bottom: max(14px, env(safe-area-inset-bottom));
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  padding: 0 max(16px, env(safe-area-inset-left)) 0 max(16px, env(safe-area-inset-right));
}

.touch-device:not(.portrait-game) .mobile-controls button {
  background: rgba(3, 12, 8, .7);
  backdrop-filter: blur(8px);
}

.portrait-game .topbar {
  min-height: 58px;
  padding: 0 12px;
  grid-template-columns: 1fr auto;
}

.portrait-game .title { display: none; }
.portrait-game .back { font-size: 10px; }
.portrait-game .hud-button { min-height: 36px; }

.portrait-game .game-stage {
  width: 100%;
  aspect-ratio: 4 / 3;
  margin: 0;
  box-shadow: 0 16px 44px rgba(0, 0, 0, .5);
}

.portrait-game .mobile-controls {
  position: relative;
  z-index: 9;
  flex: 1 1 180px;
  min-height: 154px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding:
    38px
    max(14px, env(safe-area-inset-right))
    max(20px, env(safe-area-inset-bottom))
    max(14px, env(safe-area-inset-left));
  border-top: 1px solid #1c4935;
  background:
    radial-gradient(circle at 16% 45%, rgba(99, 243, 151, .08), transparent 30%),
    radial-gradient(circle at 84% 45%, rgba(255, 156, 106, .08), transparent 30%),
    linear-gradient(180deg, #06100b, #020605 74%);
}

.portrait-game .mobile-controls::before {
  content: "TOUCH CONTROLS // MULTI-TOUCH READY";
  position: absolute;
  top: 17px;
  left: 50%;
  transform: translateX(-50%);
  color: #49695b;
  font-size: 8px;
  font-weight: 900;
  letter-spacing: .13em;
  white-space: nowrap;
}

.portrait-game .touch-tip {
  position: absolute;
  top: 17px;
  left: 50%;
  transform: translateX(-50%);
}

@media (max-width: 390px) {
  .portrait-game .mobile-controls { padding-left: 10px; padding-right: 10px; }
  .portrait-game .control-cluster { gap: 7px; }
  .portrait-game .mobile-controls button { width: 64px; height: 64px; border-radius: 21px; }
  .portrait-game .mobile-controls .action { width: 70px; height: 70px; border-radius: 50%; }
}

@media (max-height: 520px) and (orientation: landscape) {
  .topbar { min-height: 48px; }
  .touch-device:not(.portrait-game) .game-stage { width: min(100%, calc((100dvh - 48px) * 1.7777778)); }
  .touch-device:not(.portrait-game) .mobile-controls button { width: 58px; height: 58px; border-radius: 18px; }
  .touch-device:not(.portrait-game) .mobile-controls .action { width: 64px; height: 64px; border-radius: 50%; }
}

[hidden] { display: none !important; }


.death-overlay[hidden] { display: none !important; }
.death-overlay {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 12px;
  padding: 28px;
  text-align: center;
  background: rgba(1, 3, 2, .88);
  color: #eafff1;
}
.death-overlay strong { font-size: clamp(28px, 6vw, 54px); letter-spacing: .06em; }
.death-overlay span { color: #ff9c82; font-size: 12px; font-weight: 900; letter-spacing: .08em; }
.death-overlay b { color: #63f397; font-size: 11px; letter-spacing: .12em; }
.death-overlay i {
  margin-top: 8px;
  color: #8aa498;
  font-size: 9px;
  font-style: normal;
  font-weight: 900;
  letter-spacing: .2em;
}


/* V18.2: fixed browser-level clear screen. The Level 2 control is a plain anchor link. */
.level-clear-overlay {
  position: fixed;
  inset: 0;
  z-index: 2147483647;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(1, 3, 2, .84);
  pointer-events: auto;
  touch-action: auto;
}
.level-clear-overlay[hidden] { display: none !important; }
.level-clear-panel {
  width: min(76%, 720px);
  min-height: 250px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  padding: 34px 28px;
  border: 2px solid rgba(99, 243, 151, .72);
  border-top-width: 7px;
  background: rgba(6, 16, 11, .985);
  box-shadow: 0 24px 80px rgba(0,0,0,.62);
  text-align: center;
  pointer-events: auto;
}
.level-clear-panel strong {
  font-size: clamp(24px, 5vw, 48px);
  line-height: 1;
  color: #effff5;
}
.level-clear-panel span {
  color: #8fffb7;
  font-size: clamp(10px, 1.7vw, 14px);
  font-weight: 900;
}
.level-clear-panel b {
  color: #718f80;
  font-size: 10px;
  letter-spacing: .16em;
}
#enterReactorBtn {
  position: relative;
  z-index: 2147483647;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  min-width: 230px;
  min-height: 58px;
  padding: 16px 28px;
  border: 0;
  border-radius: 0;
  background: #63f397;
  color: #031008;
  font: 1000 15px/1 system-ui, sans-serif;
  cursor: pointer;
  pointer-events: auto;
  touch-action: auto;
  user-select: none;
  -webkit-user-select: none;
}
#enterReactorBtn:active { transform: scale(.97); background: #8cffb2; }
@media (max-width: 700px) {
  .level-clear-panel { width: min(92%, 620px); gap: 18px; padding: 26px 18px; }
  #enterReactorBtn { min-width: 210px; min-height: 56px; }
}
