*, *::before, *::after { box-sizing: border-box; }

:root {
  --paper: #ede5c7;
  --ink: #10140f;
  --panel: rgba(14, 20, 24, 0.86);
  --panel-strong: rgba(6, 10, 13, 0.95);
  --line: rgba(153, 184, 118, 0.38);
  --amber: #e0bd53;
  --mint: #82ad6e;
  --red: #b0523b;
  --blue: #6e8a7a;
  --ui: "IBM Plex Sans", "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", "IBM Plex Mono", "SF Mono", Consolas, monospace;
}

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #090806;
  color: var(--paper);
  font-family: var(--ui);
}

button, a { font: inherit; }

.game-shell {
  position: relative;
  width: 100vw;
  height: 100dvh;
  min-height: 520px;
  overflow: hidden;
  background:
    linear-gradient(180deg, #32372d 0%, #11140f 100%);
  touch-action: none;
}

.game-shell::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    repeating-linear-gradient(180deg, rgba(0, 0, 0, 0.08) 0 1px, transparent 1px 4px),
    radial-gradient(circle, rgba(0, 0, 0, 0) 58%, rgba(0, 0, 0, 0.42) 100%);
  z-index: 2;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  background: #0a0908;
}

.hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  padding: 18px 24px;
  pointer-events: none;
  z-index: 6;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  font-family: var(--mono);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0;
}

.brand a {
  color: var(--paper);
  text-decoration: none;
  pointer-events: auto;
  border: 1px solid var(--line);
  padding: 7px 9px;
  background: rgba(10, 16, 9, 0.72);
}

.brand span {
  color: rgba(237, 227, 210, 0.76);
  white-space: nowrap;
}

.readouts {
  display: grid;
  grid-template-columns: repeat(4, minmax(54px, auto));
  gap: 8px;
  font-family: var(--mono);
  font-size: 13px;
}

.readouts span {
  min-height: 34px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  background: rgba(8, 18, 7, 0.72);
  color: var(--paper);
  text-align: center;
  white-space: nowrap;
}

.readouts span::before {
  display: inline-block;
  margin-right: 6px;
  color: var(--amber);
}

#health::before { content: "HP"; }
#ammo::before { content: "AM"; }
#cores::before { content: "OBJ"; }
#alert::before { content: "SIG"; }

.mission-panel {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(560px, calc(100vw - 36px));
  transform: translate(-50%, -50%);
  padding: 28px;
  border: 1px solid rgba(237, 227, 210, 0.24);
  background: linear-gradient(180deg, rgba(28, 34, 24, 0.98), rgba(7, 10, 7, 0.98));
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.42);
  z-index: 8;
}

.mission-panel.hidden { display: none; }

.kicker {
  margin: 0 0 12px;
  color: var(--amber);
  font: 700 12px var(--mono);
  letter-spacing: 0;
  text-transform: uppercase;
}

h1, h2 {
  margin: 0;
  color: var(--paper);
  font-size: 46px;
  line-height: 1;
  letter-spacing: 0;
}

h2 { font-size: 38px; }

.brief {
  margin: 16px 0 0;
  max-width: 44em;
  color: rgba(237, 227, 210, 0.78);
  font-size: 17px;
  line-height: 1.5;
}

.objectives {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 22px 0;
}

.objectives span {
  border: 1px solid rgba(237, 227, 210, 0.18);
  background: rgba(237, 227, 210, 0.08);
  padding: 7px 9px;
  color: rgba(237, 227, 210, 0.82);
  font: 600 12px var(--mono);
  text-transform: uppercase;
}

.mission-panel button {
  min-height: 44px;
  border: 0;
  background: var(--amber);
  color: var(--ink);
  padding: 12px 18px;
  font-weight: 800;
  cursor: pointer;
}

.mission-panel button:hover,
.mission-panel button:focus-visible {
  background: #efbd54;
}

.crosshair {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 28px;
  height: 28px;
  transform: translate(-50%, -50%);
  pointer-events: none;
  z-index: 4;
}

.crosshair::before,
.crosshair::after {
  content: "";
  position: absolute;
  background: rgba(237, 227, 210, 0.72);
}

.crosshair::before {
  left: 13px;
  top: 4px;
  width: 2px;
  height: 20px;
}

.crosshair::after {
  left: 4px;
  top: 13px;
  width: 20px;
  height: 2px;
}

.screen-fx {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 58% 63%, rgba(215, 178, 90, calc(var(--muzzle-flash, 0) * 0.48)) 0 4%, rgba(215, 178, 90, 0) 13%),
    radial-gradient(circle, rgba(200, 107, 87, 0) 54%, rgba(200, 107, 87, calc(var(--damage-flash, 0) * 0.46)) 100%);
  mix-blend-mode: screen;
  z-index: 3;
}

.prompt {
  position: absolute;
  left: 50%;
  bottom: 128px;
  min-height: 28px;
  transform: translateX(-50%);
  padding: 7px 11px;
  border: 1px solid rgba(233, 237, 240, 0.18);
  background: rgba(8, 18, 7, 0.72);
  color: rgba(233, 237, 240, 0.9);
  font: 700 11px var(--mono);
  letter-spacing: 0;
  text-transform: uppercase;
  opacity: 0;
  pointer-events: none;
  z-index: 6;
  transition: opacity .12s;
}

.prompt.visible { opacity: 1; }

.touch-zone,
.touch-fire,
.touch-action {
  position: absolute;
  display: none;
  z-index: 6;
}

.touch-zone {
  left: 24px;
  bottom: 28px;
  width: 116px;
  height: 116px;
  border: 1px solid rgba(153, 184, 118, 0.28);
  background: rgba(10, 16, 9, 0.38);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.touch-zone.look {
  left: auto;
  right: 24px;
  bottom: 122px;
  width: min(42vw, 220px);
  height: 126px;
  background: rgba(10, 16, 9, 0.44);
}

.touch-zone span {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 38px;
  height: 38px;
  transform: translate(-50%, -50%);
  background: rgba(215, 178, 90, 0.58);
}

.touch-zone.look span {
  width: 30px;
  height: 30px;
  background: rgba(130, 173, 110, 0.68);
}

.turn-button {
  position: absolute;
  top: 50%;
  width: 54px;
  height: 64px;
  transform: translateY(-50%);
  border: 1px solid rgba(153, 184, 118, 0.34);
  background: rgba(130, 173, 110, 0.22);
  color: rgba(233, 237, 240, 0.88);
  font: 900 24px var(--mono);
  line-height: 1;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.turn-button:active {
  background: rgba(130, 173, 110, 0.52);
}

.turn-left { left: 10px; }
.turn-right { right: 10px; }

.touch-zone b {
  position: absolute;
  left: 8px;
  bottom: 7px;
  color: rgba(233, 237, 240, 0.54);
  font: 700 10px var(--mono);
  letter-spacing: 0;
  text-transform: uppercase;
}

.touch-fire,
.touch-action {
  right: 24px;
  bottom: 30px;
  border-radius: 999px;
  border: 1px solid rgba(237, 229, 199, 0.28);
  background: rgba(176, 82, 59, 0.74);
  color: rgba(233, 237, 240, 0.9);
  font: 800 11px var(--mono);
  letter-spacing: 0;
  text-transform: uppercase;
  touch-action: manipulation;
}

.touch-fire {
  width: 72px;
  height: 72px;
}

.touch-action {
  right: 106px;
  bottom: 44px;
  width: 54px;
  height: 54px;
  background: rgba(130, 173, 110, 0.78);
}

@media (pointer: coarse), (max-width: 760px) {
  .game-shell { min-height: 100dvh; }
  .touch-zone,
  .touch-fire,
  .touch-action { display: block; }
  .hud {
    padding: calc(env(safe-area-inset-top, 0px) + 8px) 10px 0;
    align-items: flex-start;
    gap: 8px;
  }
  .brand {
    flex: 0 0 auto;
  }
  .brand a {
    display: grid;
    place-items: center;
    min-width: 34px;
    min-height: 28px;
    padding: 0 7px;
    background: rgba(8, 18, 7, 0.68);
    font-size: 9px;
  }
  .brand span { display: none; }
  .readouts {
    position: absolute;
    top: calc(env(safe-area-inset-top, 0px) + 8px);
    left: 50%;
    width: min(230px, calc(100vw - 76px));
    transform: translateX(-50%);
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 4px;
    font-size: 9px;
  }
  .readouts span {
    min-height: 26px;
    padding: 3px 2px;
    border-color: rgba(233, 237, 240, 0.14);
    background: rgba(8, 18, 7, 0.68);
  }
  .readouts span::before {
    display: block;
    margin: 0 0 1px;
    font-size: 8px;
    line-height: 1;
  }
  .mission-panel {
    top: auto;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 18px);
    transform: translateX(-50%);
    padding: 18px;
    background: rgba(7, 10, 7, 0.99);
  }
  .prompt {
    bottom: calc(env(safe-area-inset-bottom, 0px) + 104px);
    max-width: calc(100vw - 42px);
    text-align: center;
  }
  h1 { font-size: 38px; }
  h2 { font-size: 32px; }
  .brief { font-size: 16px; }
}

body:not(.playing) .touch-zone,
body:not(.playing) .touch-fire,
body:not(.playing) .touch-action {
  display: none !important;
}

@media (max-width: 420px) {
  .readouts {
    gap: 6px;
  }
  .readouts span {
    min-height: 25px;
    padding: 3px 4px;
  }
  .touch-zone {
    left: calc(env(safe-area-inset-left, 0px) + 14px);
    bottom: calc(env(safe-area-inset-bottom, 0px) + 14px);
    width: 94px;
    height: 94px;
    border-radius: 999px;
  }
  .touch-zone span {
    width: 30px;
    height: 30px;
    border-radius: 999px;
  }
  .touch-zone b {
    display: block;
    left: 50%;
    bottom: 6px;
    transform: translateX(-50%);
    font-size: 9px;
  }
  .touch-zone.look {
    left: auto;
    right: calc(env(safe-area-inset-right, 0px) + 14px);
    bottom: calc(env(safe-area-inset-bottom, 0px) + 96px);
    width: min(48vw, 188px);
    height: 116px;
  }
  .turn-button {
    width: 50px;
    height: 66px;
  }
  .touch-fire {
    right: calc(env(safe-area-inset-right, 0px) + 16px);
    bottom: calc(env(safe-area-inset-bottom, 0px) + 18px);
    width: 66px;
    height: 66px;
  }
  .touch-action {
    right: calc(env(safe-area-inset-right, 0px) + 92px);
    bottom: calc(env(safe-area-inset-bottom, 0px) + 28px);
    width: 48px;
    height: 48px;
  }
}

@media (pointer: coarse) and (orientation: landscape) and (max-height: 520px) {
  .hud {
    padding: calc(env(safe-area-inset-top, 0px) + 6px) 10px 0;
  }
  .readouts {
    top: calc(env(safe-area-inset-top, 0px) + 6px);
    grid-template-columns: repeat(4, minmax(50px, auto));
    gap: 5px;
    font-size: 11px;
  }
  .readouts span {
    min-height: 28px;
    padding: 5px 6px;
  }
  .touch-zone {
    bottom: calc(env(safe-area-inset-bottom, 0px) + 10px);
    width: 82px;
    height: 82px;
  }
  .touch-zone.look {
    left: auto;
    right: calc(env(safe-area-inset-right, 0px) + 138px);
    bottom: calc(env(safe-area-inset-bottom, 0px) + 10px);
    width: min(28vw, 190px);
    height: 82px;
  }
  .turn-button {
    width: 46px;
    height: 58px;
    font-size: 22px;
  }
  .touch-fire {
    right: calc(env(safe-area-inset-right, 0px) + 12px);
    bottom: calc(env(safe-area-inset-bottom, 0px) + 12px);
    width: 58px;
    height: 58px;
  }
  .touch-action {
    right: calc(env(safe-area-inset-right, 0px) + 78px);
    bottom: calc(env(safe-area-inset-bottom, 0px) + 18px);
    width: 44px;
    height: 44px;
  }
}
