:root {
  --bg: #05070d;
  --panel: rgba(7, 15, 30, 0.88);
  --cyan: #37e7ff;
  --green: #4dff9a;
  --red: #ff3d66;
  --text: #ecfbff;
  --muted: #91a9b8;
  --desktop-ad-height: min(72vh, 520px);
  --desktop-ad-width: min(126px, calc(var(--desktop-ad-height) * 126 / 520));
  --desktop-ad-gap: clamp(10px, 1.8vw, 24px);
  --mobile-ad-height: 58px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  touch-action: none;
  overscroll-behavior: none;
  background:
    radial-gradient(circle at 50% 35%, rgba(55, 231, 255, 0.12), transparent 34%),
    linear-gradient(145deg, #03060b 0%, #08101e 48%, #020308 100%);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
}

button {
  font: inherit;
  color: inherit;
  border: 0;
  cursor: pointer;
  touch-action: none;
}

.ad-slot {
  position: fixed;
  z-index: 12;
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  color: inherit;
  overflow: hidden;
}

.ad-slot[hidden] {
  display: none !important;
}

.ad-slot-desktop {
  top: 50%;
  width: var(--desktop-ad-width);
  height: var(--desktop-ad-height);
  transform: translateY(-50%);
}

.ad-slot-left {
  left: clamp(10px, 1.8vw, 20px);
}

.ad-slot-right {
  right: clamp(10px, 1.8vw, 20px);
}

.ad-slot-mobile {
  display: none;
}

.ad-image {
  display: block;
  width: 100%;
  height: auto;
}

.ad-image-vertical {
  width: 100%;
  height: 100%;
  max-height: calc(100vh - 36px);
  aspect-ratio: 126 / 520;
  object-fit: contain;
}

.ad-image-horizontal {
  width: 100%;
  height: 100%;
  aspect-ratio: 32 / 5;
  object-fit: fill;
}

#gameShell {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
}

#canvasWrap {
  display: grid;
  place-items: center;
  width: 100vw;
  height: 100vh;
  padding:
    56px
    calc(var(--desktop-ad-width) + var(--desktop-ad-gap) + 12px)
    16px;
}

#gameCanvas {
  display: block;
  width: min(100%, calc((100vh - 72px) * 16 / 9));
  height: auto;
  max-height: calc(100vh - 72px);
  aspect-ratio: 16 / 9;
  border: 1px solid rgba(55, 231, 255, 0.5);
  background: #010308;
  box-shadow:
    0 0 24px rgba(55, 231, 255, 0.18),
    inset 0 0 18px rgba(55, 231, 255, 0.1);
}

#hud {
  position: fixed;
  top: max(8px, env(safe-area-inset-top));
  left: 50%;
  z-index: 15;
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: repeat(5, minmax(68px, 1fr));
  gap: 8px;
  width: min(720px, calc(100vw - var(--desktop-ad-width) - var(--desktop-ad-width) - var(--desktop-ad-gap) - var(--desktop-ad-gap) - 16px));
  pointer-events: none;
}

#hud div {
  min-width: 0;
  padding: 7px 8px;
  border: 1px solid rgba(55, 231, 255, 0.35);
  background: rgba(3, 8, 18, 0.72);
  box-shadow: inset 0 0 12px rgba(55, 231, 255, 0.09);
  text-align: center;
}

#hud span {
  display: block;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.1;
  text-transform: uppercase;
}

#hud strong {
  display: block;
  margin-top: 2px;
  color: var(--cyan);
  font-size: clamp(13px, 2.4vw, 18px);
  line-height: 1.1;
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: none;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(rgba(1, 5, 12, 0.72), rgba(1, 5, 12, 0.86)),
    repeating-linear-gradient(0deg, rgba(55, 231, 255, 0.06) 0 1px, transparent 1px 5px);
}

.overlay.active {
  display: grid;
}

.panel {
  width: min(760px, 100%);
  padding: clamp(22px, 4vw, 36px);
  border: 1px solid rgba(55, 231, 255, 0.48);
  border-radius: 8px;
  background: var(--panel);
  box-shadow:
    0 0 32px rgba(55, 231, 255, 0.18),
    inset 0 0 28px rgba(55, 231, 255, 0.08);
}

.panel.compact {
  width: min(460px, 100%);
  text-align: center;
}

.panel.danger {
  border-color: rgba(255, 61, 102, 0.6);
  box-shadow:
    0 0 30px rgba(255, 61, 102, 0.18),
    inset 0 0 24px rgba(255, 61, 102, 0.08);
}

.panel.mission {
  border-color: rgba(77, 255, 154, 0.7);
  box-shadow:
    0 0 34px rgba(77, 255, 154, 0.2),
    inset 0 0 26px rgba(55, 231, 255, 0.1);
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--green);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
}

h1 {
  margin: 0 0 14px;
  color: var(--text);
  font-size: clamp(32px, 8vw, 58px);
  line-height: 1;
  text-shadow: 0 0 18px rgba(55, 231, 255, 0.55);
}

h2 {
  margin: 0 0 8px;
  color: var(--cyan);
  font-size: 16px;
}

p {
  margin: 8px 0;
  color: #c9dbe4;
  line-height: 1.55;
}

.story {
  max-width: 680px;
}

.helpGrid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin: 20px 0 24px;
}

.helpGrid > div {
  padding: 14px;
  border: 1px solid rgba(77, 255, 154, 0.22);
  background: rgba(2, 10, 22, 0.55);
}

.primaryButton {
  min-width: 180px;
  min-height: 46px;
  padding: 12px 18px;
  border: 1px solid rgba(77, 255, 154, 0.7);
  border-radius: 6px;
  background: linear-gradient(180deg, rgba(77, 255, 154, 0.3), rgba(55, 231, 255, 0.18));
  color: var(--text);
  font-weight: 800;
  text-transform: uppercase;
  box-shadow: 0 0 18px rgba(77, 255, 154, 0.25);
}

.primaryButton:active {
  transform: translateY(1px);
}

#mobileControls {
  position: fixed;
  z-index: 20;
  left: 0;
  right: 0;
  bottom: max(12px, env(safe-area-inset-bottom));
  display: none;
  align-items: end;
  justify-content: space-between;
  padding: 0 18px;
  pointer-events: none;
}

#dpad {
  position: relative;
  width: 146px;
  height: 146px;
  pointer-events: auto;
}

.padButton,
.hackButton {
  border: 1px solid rgba(55, 231, 255, 0.55);
  border-radius: 8px;
  background: rgba(4, 14, 30, 0.72);
  color: var(--cyan);
  font-weight: 900;
  box-shadow: inset 0 0 14px rgba(55, 231, 255, 0.14), 0 0 14px rgba(55, 231, 255, 0.1);
  user-select: none;
}

.padButton {
  position: absolute;
  width: 48px;
  height: 48px;
  font-size: 20px;
}

.padButton.up {
  top: 0;
  left: 49px;
}

.padButton.left {
  top: 49px;
  left: 0;
}

.padButton.right {
  top: 49px;
  right: 0;
}

.padButton.down {
  bottom: 0;
  left: 49px;
}

.hackButton {
  width: 104px;
  height: 104px;
  border-radius: 50%;
  border-color: rgba(77, 255, 154, 0.75);
  color: var(--green);
  font-size: 18px;
  pointer-events: auto;
}

.padButton.active,
.hackButton.active {
  background: rgba(55, 231, 255, 0.28);
  box-shadow: 0 0 20px rgba(77, 255, 154, 0.32), inset 0 0 18px rgba(77, 255, 154, 0.18);
}

@media (pointer: coarse), (max-width: 900px) {
  .ad-slot-desktop {
    display: none;
  }

  .ad-slot-mobile {
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 18;
    display: flex;
    width: 100vw;
    height: calc(var(--mobile-ad-height) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: #05070d;
  }

  #canvasWrap {
    padding: 52px 8px calc(154px + var(--mobile-ad-height) + env(safe-area-inset-bottom));
  }

  #gameCanvas {
    width: min(100%, calc((100vh - 264px - env(safe-area-inset-bottom)) * 16 / 9));
    max-height: calc(100vh - 264px - env(safe-area-inset-bottom));
  }

  #mobileControls {
    display: flex;
    bottom: calc(var(--mobile-ad-height) + max(12px, env(safe-area-inset-bottom)));
  }
}

@media (max-width: 620px) {
  #hud {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 4px;
  }

  #hud div {
    padding: 6px 3px;
  }

  #hud span {
    font-size: 9px;
  }

  .helpGrid {
    grid-template-columns: 1fr;
  }

  .overlay {
    padding: 16px;
  }
}

@media (orientation: landscape) and (max-height: 520px) {
  #canvasWrap {
    padding: 44px 132px calc(var(--mobile-ad-height) + 8px);
  }

  #gameCanvas {
    width: min(100%, calc((100vh - 112px) * 16 / 9));
    max-height: calc(100vh - 112px);
  }

  #mobileControls {
    top: 54px;
    bottom: calc(var(--mobile-ad-height) + 12px);
    align-items: center;
  }

  #dpad {
    width: 124px;
    height: 124px;
  }

  .padButton {
    width: 42px;
    height: 42px;
  }

  .padButton.up,
  .padButton.down {
    left: 41px;
  }

  .padButton.left,
  .padButton.right {
    top: 41px;
  }

  .hackButton {
    width: 88px;
    height: 88px;
  }
}
