:root {
  --ink: #050811;
  --panel: rgba(5, 10, 24, 0.9);
  --cyan: #39f6ff;
  --violet: #a969ff;
  --pink: #ff3abf;
  --acid: #b8ff43;
  --danger: #ff476f;
  --white: #ebffff;
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  background: var(--ink);
  color: var(--white);
  font-family: "Courier New", ui-monospace, monospace;
  image-rendering: pixelated;
  user-select: none;
}

button { font: inherit; }

.game-shell {
  position: relative;
  width: 100dvw;
  height: var(--app-height, 100dvh);
  min-height: 100svh;
  overflow: hidden;
  background: radial-gradient(circle at 50% 50%, #10204d 0, #050812 66%);
}

.arena {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
}

.scanlines, .vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
}

.scanlines {
  opacity: .13;
  background: repeating-linear-gradient(0deg, rgba(255,255,255,.13) 0 1px, transparent 1px 4px);
  mix-blend-mode: overlay;
}

.vignette { box-shadow: inset 0 0 10vw 2vw #000c; }

.topbar {
  position: absolute;
  z-index: 5;
  top: 14px;
  left: 16px;
  right: 16px;
  display: grid;
  grid-template-columns: minmax(250px, 430px) 1fr minmax(170px, 260px);
  gap: 14px;
  align-items: start;
  pointer-events: none;
}

.brand-line, .score-box, .wave-box, .mutation-strip, .controls-hint {
  border: 1px solid color-mix(in srgb, var(--phase, var(--cyan)) 52%, transparent);
  background: linear-gradient(135deg, rgba(5,10,25,.92), rgba(7,13,31,.72));
  box-shadow: 0 0 16px color-mix(in srgb, var(--phase, var(--cyan)) 18%, transparent), inset 0 0 18px #0008;
  backdrop-filter: blur(5px);
}

.brand-line { padding: 8px 10px 9px; }
.brand-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.mini-logo { color: var(--phase, var(--cyan)); font-weight: 900; letter-spacing: .14em; text-shadow: 0 0 8px currentColor; }
.phase-label { color: #a9bed0; font-size: 10px; letter-spacing: .16em; }

.bars { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; margin-top: 7px; }
.bar-label { display: flex; justify-content: space-between; font-size: 9px; color: #b5cad8; margin-bottom: 3px; }
.bar-track { height: 7px; border: 1px solid #ffffff24; background: #000a; overflow: hidden; }
.bar-fill { height: 100%; transition: width .12s linear; box-shadow: 0 0 7px currentColor; }
.hp .bar-fill { color: var(--danger); background: var(--danger); }
.energy .bar-fill { color: var(--cyan); background: var(--cyan); }
.heat .bar-fill { color: #ff9e36; background: #ff9e36; }
.heat.danger .bar-track { animation: dangerPulse .5s steps(2) infinite; }

.center-status { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.wave-box { padding: 8px 18px; text-align: center; min-width: 190px; }
.wave-box strong { display: block; color: var(--phase, var(--cyan)); font-size: 18px; letter-spacing: .16em; text-shadow: 0 0 9px currentColor; }
.wave-box span { color: #b5c9d7; font-size: 9px; letter-spacing: .13em; }
.event-chip { color: #fff; background: #b31866cc; border: 1px solid var(--pink); padding: 4px 10px; font-size: 9px; letter-spacing: .11em; box-shadow: 0 0 12px #ff3abf88; }

.score-box { padding: 8px 11px; text-align: right; }
.score-box span { display: block; color: #8294a7; font-size: 9px; letter-spacing: .13em; }
.score-box strong { font-size: 20px; letter-spacing: .08em; }
.score-box em { display: block; color: var(--acid); font-style: normal; font-size: 9px; margin-top: 2px; }

.bottom-ui {
  position: absolute;
  z-index: 5;
  left: 16px;
  right: 16px;
  bottom: 14px;
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
  pointer-events: none;
}

.weapon-card { width: min(430px, 46vw); }
.weapon-name { display: flex; align-items: baseline; gap: 9px; }
.weapon-name strong { color: var(--pink); font-size: 18px; text-shadow: 0 0 10px var(--pink); letter-spacing: .08em; }
.weapon-name span { color: #8ca1b2; font-size: 9px; }
.ammo-line { margin-top: 3px; display: flex; align-items: baseline; gap: 8px; }
.ammo-line strong { font-size: 25px; color: #fff; }
.ammo-line span { color: #758b9b; font-size: 10px; }
.mutation-strip { margin-top: 5px; padding: 6px 8px; font-size: 9px; color: #bfd0db; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mutation-strip b { color: var(--acid); }

.controls-hint { padding: 7px 9px; font-size: 9px; line-height: 1.55; color: #8fa5b5; text-align: right; }
.controls-hint b { color: var(--phase, var(--cyan)); }

.icon-buttons { position: absolute; z-index: 7; right: 16px; top: 102px; display: flex; gap: 6px; }
.icon-button {
  width: 35px; height: 35px; border: 1px solid #ffffff33; color: #c8e4ef; background: #060b19cc;
  cursor: pointer; box-shadow: inset 0 0 10px #000; pointer-events: auto;
}
.icon-button:hover, .icon-button:focus-visible { border-color: var(--cyan); color: var(--cyan); outline: none; }

.overlay {
  position: absolute;
  inset: 0;
  z-index: 12;
  display: grid;
  place-items: center;
  padding: 18px;
  background: radial-gradient(circle at center, rgba(16,31,71,.68), rgba(1,3,9,.95) 72%);
}

.start-card, .pause-card, .end-card {
  width: min(720px, 94vw);
  border: 1px solid #39f6ff88;
  background: linear-gradient(145deg, rgba(6,10,24,.96), rgba(14,7,28,.97));
  box-shadow: 0 0 40px #1bd9ff30, inset 0 0 36px #0009;
  padding: clamp(22px, 4vw, 44px);
  position: relative;
}
.start-card::before, .end-card::before { content: ""; position: absolute; inset: 7px; border: 1px dashed #ffffff14; pointer-events: none; }
.kicker { color: var(--cyan); letter-spacing: .28em; font-size: 10px; text-transform: uppercase; }
.title { margin: 9px 0 0; font-size: clamp(46px, 10vw, 92px); line-height: .83; letter-spacing: -.08em; color: white; text-shadow: 3px 3px 0 #ff3abf, 0 0 26px #39f6ff66; }
.title span { color: var(--cyan); }
.subtitle { margin: 15px 0 22px; color: #a8bcc9; font-size: 12px; max-width: 540px; line-height: 1.6; }

.awakening { display: grid; grid-template-columns: 105px 1fr; gap: 15px; align-items: center; border-block: 1px solid #ffffff1c; padding: 15px 0; }
.organism { height: 82px; position: relative; filter: drop-shadow(0 0 10px var(--pink)); }
.organism::before { content: ""; position: absolute; width: 78px; height: 28px; left: 10px; top: 27px; background: var(--pink); clip-path: polygon(0 35%, 15% 0, 55% 12%, 78% 0, 100% 35%, 77% 64%, 58% 100%, 20% 82%); box-shadow: 0 0 15px var(--pink); animation: breathe 1.4s steps(4) infinite; }
.organism::after { content: "◆"; position: absolute; color: #fff; left: 43px; top: 31px; font-size: 19px; text-shadow: 0 0 8px white; }
.awakening strong { display: block; color: var(--pink); letter-spacing: .1em; font-size: 17px; }
.awakening p { color: #8fa6b5; font-size: 10px; line-height: 1.5; margin: 5px 0 0; }

.tutorial-grid { display: grid; grid-template-columns: repeat(3,1fr); gap: 9px; margin: 16px 0 21px; }
.tutorial-item { border-left: 2px solid var(--cyan); background: #ffffff08; padding: 9px; }
.tutorial-item b { display: block; color: #eaffff; font-size: 10px; margin-bottom: 3px; }
.tutorial-item span { color: #8296a5; font-size: 9px; line-height: 1.4; }

.primary-button {
  width: 100%; border: 1px solid var(--cyan); padding: 13px 18px; color: #031016; background: var(--cyan);
  font-weight: 900; letter-spacing: .16em; cursor: pointer; box-shadow: 0 0 22px #39f6ff66;
}
.primary-button:hover, .primary-button:focus-visible { background: #fff; border-color: #fff; outline: none; }
.start-foot { text-align: center; color: #5e7181; font-size: 8px; margin-top: 10px; letter-spacing: .1em; }

.pause-card { width: min(440px, 90vw); text-align: center; }
.pause-card h2, .end-card h2 { margin: 4px 0 10px; color: var(--cyan); font-size: 27px; letter-spacing: .12em; }
.pause-card p, .end-card p { color: #90a6b4; font-size: 11px; line-height: 1.6; }

.end-head { display: flex; justify-content: space-between; gap: 18px; align-items: end; border-bottom: 1px solid #ffffff22; padding-bottom: 15px; }
.end-score { text-align: right; }
.end-score span { display: block; color: #7e93a5; font-size: 9px; }
.end-score strong { font-size: 32px; color: var(--acid); }
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 17px 0; }
.stat { padding: 10px; background: #ffffff08; border-top: 1px solid #ffffff28; }
.stat span { display: block; color: #728899; font-size: 8px; }
.stat b { display: block; margin-top: 3px; color: #e9ffff; font-size: 16px; }
.legacy { color: var(--pink); font-size: 10px; margin: 0 0 17px; }

.announcement {
  position: absolute; z-index: 6; left: 50%; top: 28%; transform: translate(-50%,-50%);
  text-align: center; pointer-events: none; animation: announce 2.5s ease both;
}
.announcement strong { display: block; color: var(--phase, var(--cyan)); font-size: clamp(21px, 4vw, 38px); letter-spacing: .12em; text-shadow: 0 0 16px currentColor, 2px 2px #000; }
.announcement span { display: block; margin-top: 6px; color: #eaffff; font-size: 10px; letter-spacing: .16em; }

.mobile-badge { display: none; }

.touch-controls {
  display: none;
  position: absolute;
  inset: 0;
  z-index: 8;
  pointer-events: none;
}

.orientation-lock { display: none; }

.touch-joystick,
.touch-action {
  position: absolute;
  pointer-events: none;
  color: #eaffff;
  background: rgba(3, 8, 20, .54);
  border: 2px solid rgba(57, 246, 255, .58);
  box-shadow: 0 0 18px rgba(57, 246, 255, .18), inset 0 0 22px rgba(0, 0, 0, .72);
  backdrop-filter: blur(2px);
}

.touch-joystick {
  bottom: max(20px, env(safe-area-inset-bottom));
  width: 116px;
  height: 116px;
  border-radius: 50%;
}

.touch-joystick-left { left: max(20px, env(safe-area-inset-left)); }

.touch-joystick-right {
  right: max(20px, env(safe-area-inset-right));
  border-color: rgba(255, 58, 191, .7);
  box-shadow: 0 0 18px rgba(255, 58, 191, .2), inset 0 0 22px rgba(0, 0, 0, .72);
}

.touch-joystick::before,
.touch-joystick::after {
  content: "";
  position: absolute;
  background: rgba(57, 246, 255, .24);
}

.touch-joystick::before { width: 1px; height: 72%; left: 50%; top: 14%; }
.touch-joystick::after { width: 72%; height: 1px; left: 14%; top: 50%; }

.touch-joystick-knob {
  position: absolute;
  width: 45px;
  height: 45px;
  left: 50%;
  top: 50%;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  border: 2px solid var(--cyan);
  background: rgba(57, 246, 255, .15);
  box-shadow: 0 0 14px rgba(57, 246, 255, .42);
}

.touch-joystick-right .touch-joystick-knob {
  border-color: var(--pink);
  background: rgba(255, 58, 191, .16);
  box-shadow: 0 0 14px rgba(255, 58, 191, .45);
}

.touch-joystick b {
  position: absolute;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  color: rgba(234, 255, 255, .72);
  font-size: 8px;
  letter-spacing: .12em;
}

.touch-action {
  display: grid;
  place-items: center;
  border-radius: 50%;
  font-size: 10px;
  font-weight: 900;
  letter-spacing: .08em;
  transition: transform .08s linear, filter .08s linear;
}

.touch-action.is-active {
  transform: scale(.9);
  filter: brightness(1.65);
}

.touch-dash {
  right: max(138px, calc(env(safe-area-inset-right) + 122px));
  bottom: max(18px, env(safe-area-inset-bottom));
  width: 58px;
  height: 58px;
  color: var(--acid);
  border-color: rgba(184, 255, 67, .7);
  background: rgba(26, 55, 8, .54);
  box-shadow: 0 0 18px rgba(184, 255, 67, .22), inset 0 0 18px rgba(0, 0, 0, .72);
}

.touch-reload {
  right: max(138px, calc(env(safe-area-inset-right) + 122px));
  bottom: max(84px, calc(env(safe-area-inset-bottom) + 66px));
  width: 58px;
  height: 58px;
  color: var(--cyan);
  border-color: rgba(57, 246, 255, .72);
  background: rgba(5, 48, 62, .58);
}

.touch-autoaim {
  position: absolute;
  right: max(28px, calc(env(safe-area-inset-right) + 8px));
  bottom: max(144px, calc(env(safe-area-inset-bottom) + 126px));
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 96px;
  padding: 7px 9px;
  color: #9cb0bd;
  background: rgba(3, 8, 20, .72);
  border: 1px solid rgba(255, 255, 255, .22);
  box-shadow: inset 0 0 12px rgba(0, 0, 0, .72);
  font-size: 7px;
  letter-spacing: .05em;
}

.touch-autoaim b { color: #8999a4; font-size: 9px; }
.touch-autoaim.is-on { border-color: rgba(184, 255, 67, .58); }
.touch-autoaim.is-on b { color: var(--acid); text-shadow: 0 0 7px var(--acid); }
.touch-autoaim.is-active { filter: brightness(1.55); }

.orientation-lock {
  position: fixed;
  inset: 0;
  z-index: 50;
  place-items: center;
  align-content: center;
  gap: 10px;
  padding: 28px;
  text-align: center;
  background: radial-gradient(circle, #121b3b 0, #03050c 72%);
}

.orientation-lock strong {
  color: var(--cyan);
  font-size: clamp(18px, 6vw, 30px);
  letter-spacing: .12em;
  text-shadow: 0 0 14px var(--cyan);
}

.orientation-lock span { color: #91a7b6; font-size: 10px; line-height: 1.5; }

.orientation-device {
  width: 48px;
  height: 78px;
  border: 3px solid var(--pink);
  border-radius: 8px;
  box-shadow: 0 0 16px rgba(255, 58, 191, .5);
  animation: rotateDevice 1.8s ease-in-out infinite;
}

@keyframes breathe { 50% { transform: scaleX(1.08) scaleY(.88); } }
@keyframes announce { 0% { opacity:0; transform:translate(-50%,-20%) scale(.8); } 12%,70% { opacity:1; transform:translate(-50%,-50%) scale(1); } 100% { opacity:0; transform:translate(-50%,-80%) scale(1.05); } }
@keyframes dangerPulse { 50% { border-color: var(--danger); box-shadow: 0 0 10px var(--danger); } }
@keyframes rotateDevice { 0%,25% { transform: rotate(0); } 65%,100% { transform: rotate(90deg); } }

@media (max-width: 760px) {
  .topbar { top: 8px; left: 8px; right: 8px; grid-template-columns: 1fr 112px; gap: 7px; }
  .center-status { position: absolute; top: 77px; left: 50%; transform: translateX(-50%); }
  .brand-line { padding: 6px; }
  .score-box { padding: 7px; }
  .score-box strong { font-size: 16px; }
  .bars { gap: 3px; }
  .bar-label { font-size: 7px; }
  .wave-box { min-width: 145px; padding: 6px 10px; }
  .wave-box strong { font-size: 14px; }
  .icon-buttons { right: 8px; top: 72px; }
  .bottom-ui { left: 8px; right: 8px; bottom: 8px; }
  .weapon-card { width: 64vw; }
  .controls-hint { display: none; }
  .mobile-badge { display: block; color: #6f8797; font-size: 8px; border: 1px solid #ffffff24; background:#030711bb; padding:5px; text-align:right; }
  .tutorial-grid { grid-template-columns: 1fr; }
  .tutorial-item:nth-child(3) { display:none; }
  .awakening { grid-template-columns: 75px 1fr; }
  .organism { transform: scale(.78); transform-origin: left center; }
  .stats-grid { grid-template-columns: repeat(2,1fr); }
  .start-card, .end-card { padding: 24px 20px; max-height: 94dvh; overflow:auto; }
}

@media (pointer: coarse) {
  .is-touch-device .mobile-badge,
  .is-touch-device .controls-hint { display: none; }
}

@media (pointer: coarse) and (orientation: portrait) {
  .is-touch-device .orientation-lock { display: grid; }
  .is-touch-device .touch-controls { display: none; }
}

@media (pointer: coarse) and (orientation: landscape) {
  .is-touch-device .touch-controls { display: block; }

  .is-touch-device .topbar {
    top: max(7px, env(safe-area-inset-top));
    left: max(8px, env(safe-area-inset-left));
    right: max(8px, env(safe-area-inset-right));
    display: block;
    height: 0;
  }

  .is-touch-device .brand-line {
    position: absolute;
    inset: 0;
    padding: 0;
    border: 0;
    background: none;
    box-shadow: none;
    backdrop-filter: none;
  }

  .is-touch-device .brand-row { display: none; }
  .is-touch-device .bars { display: block; margin: 0; }

  .is-touch-device .hp,
  .is-touch-device .energy,
  .is-touch-device .heat {
    position: absolute;
    padding: 6px 8px;
    background: rgba(4, 9, 22, .82);
    border: 1px solid rgba(255, 255, 255, .2);
    box-shadow: inset 0 0 12px rgba(0, 0, 0, .72);
  }

  .is-touch-device .hp { left: 0; top: 0; width: min(27vw, 190px); }
  .is-touch-device .energy { right: 0; top: 0; width: min(22vw, 158px); }
  .is-touch-device .heat { right: 0; top: 33px; width: min(22vw, 158px); }
  .is-touch-device .bar-label { font-size: 7px; }
  .is-touch-device .bar-track { height: 6px; }

  .is-touch-device .score-box {
    position: absolute;
    top: 0;
    left: 50%;
    width: 158px;
    padding: 6px 10px;
    transform: translateX(-50%);
    text-align: center;
  }

  .is-touch-device .score-box strong { font-size: 17px; }

  .is-touch-device .center-status {
    position: fixed;
    left: 50%;
    top: auto;
    bottom: max(6px, env(safe-area-inset-bottom));
    transform: translateX(-50%);
  }

  .is-touch-device .wave-box {
    min-width: 142px;
    padding: 5px 9px;
  }

  .is-touch-device .wave-box strong { font-size: 13px; }
  .is-touch-device .event-chip {
    position: absolute;
    left: 50%;
    bottom: 37px;
    transform: translateX(-50%);
    white-space: nowrap;
  }

  .is-touch-device .icon-buttons {
    top: max(76px, calc(env(safe-area-inset-top) + 69px));
    right: max(8px, env(safe-area-inset-right));
  }

  .is-touch-device .bottom-ui {
    left: 50%;
    right: auto;
    bottom: max(48px, calc(env(safe-area-inset-bottom) + 41px));
    width: min(260px, 34vw);
    transform: translateX(-50%);
    justify-content: center;
    text-align: center;
  }

  .is-touch-device .weapon-card { width: 100%; }
  .is-touch-device .weapon-name,
  .is-touch-device .ammo-line { justify-content: center; }
  .is-touch-device .mutation-strip { display: none; }

  .is-touch-device .touch-joystick { width: 108px; height: 108px; bottom: max(14px, env(safe-area-inset-bottom)); }
  .is-touch-device .touch-joystick-left { left: max(18px, env(safe-area-inset-left)); }
  .is-touch-device .touch-joystick-right { right: max(18px, env(safe-area-inset-right)); }
}

@media (max-height: 650px) and (orientation: landscape) {
  .start-card { padding: 18px 25px; }
  .title { font-size: 48px; }
  .subtitle { margin: 8px 0; }
  .awakening { padding: 7px 0; }
  .tutorial-grid { margin: 8px 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
