:root {
  color-scheme: dark;
  font-family:
    "Microsoft YaHei", "PingFang SC", system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", sans-serif;
  background: #101820;
  color: #e8f6ff;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  touch-action: manipulation;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  display: grid;
  place-items: center;
  overflow-x: hidden;
  padding: 18px 0;
  background:
    radial-gradient(circle at 16% 12%, rgba(42, 212, 255, 0.18), transparent 30%),
    radial-gradient(circle at 88% 20%, rgba(255, 94, 122, 0.14), transparent 32%),
    linear-gradient(135deg, rgba(255, 255, 255, 0.035) 25%, transparent 25%) 0 0 / 20px 20px,
    linear-gradient(135deg, #121c25, #0c1218 58%, #17242c);
}

button {
  border: 0;
  border-radius: 6px;
  padding: 12px 18px;
  color: #1d1710;
  background: linear-gradient(#ffe58b, #f2aa2d);
  font: inherit;
  font-weight: 900;
  cursor: pointer;
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.45),
    inset 0 -3px 0 rgba(0, 0, 0, 0.24),
    0 8px 16px rgba(0, 0, 0, 0.28);
}

button:hover {
  filter: brightness(1.08);
}

button:active {
  transform: translateY(1px);
}

.shell {
  width: min(100vw - 24px, 1150px);
  display: grid;
  grid-template-columns: minmax(520px, 820px) 280px;
  gap: 22px;
  align-items: start;
}

.game-area {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  overflow: hidden;
  border: 3px solid #314653;
  border-radius: 12px;
  background: #172128;
  box-shadow:
    0 30px 70px rgba(0, 0, 0, 0.42),
    inset 0 0 0 5px #1e2e38,
    inset 0 0 35px rgba(42, 212, 255, 0.08);
}

.game-area::before {
  content: "";
  position: absolute;
  inset: 10px;
  pointer-events: none;
  border: 1px solid rgba(109, 226, 255, 0.22);
  box-shadow: inset 0 0 24px rgba(42, 212, 255, 0.08);
}

canvas {
  width: 100%;
  height: 100%;
  display: block;
  outline: none;
  image-rendering: pixelated;
}

canvas:focus-visible {
  box-shadow: inset 0 0 0 3px #ffe58b;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(20, 30, 28, 0.62);
  backdrop-filter: blur(3px);
}

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

.joystick {
  position: absolute;
  left: 18px;
  bottom: 18px;
  width: 112px;
  height: 112px;
  border: 2px solid rgba(140, 236, 255, 0.42);
  border-radius: 50%;
  background:
    radial-gradient(circle, rgba(140, 236, 255, 0.14), rgba(9, 15, 20, 0.62) 62%),
    rgba(9, 15, 20, 0.48);
  box-shadow: inset 0 0 20px rgba(42, 212, 255, 0.18), 0 12px 28px rgba(0, 0, 0, 0.32);
  pointer-events: auto;
  touch-action: none;
}

.joystick span {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: linear-gradient(#8cecff, #2d9cff);
  box-shadow: 0 0 18px rgba(140, 236, 255, 0.35), inset 0 2px 0 rgba(255, 255, 255, 0.45);
  transform: translate(-50%, -50%);
}

.touch-controls button {
  position: absolute;
  min-width: 0;
  padding: 0;
  color: #f8f2dc;
  background: rgba(24, 31, 34, 0.82);
  border: 1px solid rgba(255, 229, 139, 0.45);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.18),
    0 8px 18px rgba(0, 0, 0, 0.35);
  pointer-events: auto;
  touch-action: none;
  user-select: none;
}

.touch-controls button:hover {
  background: rgba(55, 67, 70, 0.9);
}

.fire {
  right: 18px;
  bottom: 22px;
  width: 104px;
  height: 104px;
  border-radius: 50%;
  font-size: 18px;
}

.pause-touch {
  right: 22px;
  top: 22px;
  width: 46px;
  height: 46px;
  border-radius: 50%;
}

.overlay.hidden {
  display: none;
}

.overlay-panel {
  width: min(100%, 360px);
  border: 1px solid rgba(109, 226, 255, 0.4);
  border-radius: 12px;
  padding: 26px;
  text-align: center;
  background:
    linear-gradient(135deg, rgba(42, 212, 255, 0.14), transparent 45%),
    linear-gradient(180deg, #263742, #141f27);
  box-shadow:
    0 20px 45px rgba(0, 0, 0, 0.32),
    inset 0 1px 0 rgba(255, 255, 255, 0.16);
}

.overlay-kicker {
  display: inline-block;
  margin-bottom: 10px;
  color: #ffca4b;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0;
}

.overlay-panel h1 {
  margin: 0 0 10px;
  color: #8cecff;
  font-size: 32px;
  line-height: 1.1;
}

.overlay-panel p {
  margin: 0 0 20px;
  line-height: 1.55;
  color: #d9d0b5;
  color: #c6d8df;
}

.hud {
  border: 1px solid #314653;
  border-radius: 12px;
  padding: 18px;
  background:
    linear-gradient(135deg, rgba(42, 212, 255, 0.1), transparent 44%),
    linear-gradient(180deg, #263742, #141f27);
  box-shadow:
    0 20px 44px rgba(0, 0, 0, 0.28),
    inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  color: #8cecff;
  font-size: 22px;
}

.brand strong,
.brand small {
  display: block;
}

.brand small {
  margin-top: 2px;
  color: #ffb4c1;
  font-size: 11px;
  font-weight: 800;
}

.brand-mark {
  width: 34px;
  height: 26px;
  display: inline-block;
  flex: 0 0 auto;
  border-radius: 5px;
  background:
    linear-gradient(#8cecff 0 0) 14px -1px / 6px 14px no-repeat,
    linear-gradient(#3aa2ff 0 0) 6px 9px / 22px 10px no-repeat,
    linear-gradient(#0e1216 0 0) 0 18px / 34px 6px no-repeat;
  box-shadow: 0 0 18px rgba(42, 212, 255, 0.34);
}

.mission {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  padding: 9px 10px;
  border: 1px solid rgba(109, 226, 255, 0.2);
  border-radius: 6px;
  background: rgba(9, 15, 20, 0.34);
  color: #c6d8df;
  font-size: 13px;
}

.mission b {
  color: #8cecff;
  font-size: 13px;
}

.stats {
  margin: 0;
  display: grid;
  gap: 10px;
}

.stats div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 52px;
  padding: 11px 13px;
  border: 1px solid rgba(109, 226, 255, 0.16);
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(42, 212, 255, 0.08), transparent 55%),
    rgba(9, 15, 20, 0.42);
}

.stats dt {
  color: #b7ccd4;
}

.stats dd {
  margin: 0;
  font-size: 26px;
  font-weight: 900;
  color: #ffcf6c;
  text-shadow: 0 0 12px rgba(255, 207, 108, 0.22);
}

.controls {
  margin-top: 16px;
  display: grid;
  gap: 8px;
  color: #c6d8df;
  font-size: 15px;
  line-height: 1.45;
}

.sound-toggle {
  width: 100%;
  margin-top: 16px;
  padding: 10px 12px;
  color: #e8f6ff;
  background: rgba(9, 15, 20, 0.42);
  border: 1px solid rgba(109, 226, 255, 0.22);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

#fullscreenToggle {
  display: none;
}

@media (max-width: 840px) {
  body {
    align-content: start;
    padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right))
      max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
    overflow: hidden;
  }

  .shell {
    width: 100%;
    min-height: calc(100dvh - 16px);
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    gap: 8px;
  }

  .hud {
    order: -1;
    display: grid;
    gap: 8px;
    padding: 10px;
    border-radius: 10px;
  }

  .brand {
    display: none;
  }

  .mission {
    margin: 0;
    min-height: 34px;
    padding: 6px 8px;
  }

  .stats {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
  }

  .stats div {
    min-height: 42px;
    padding: 6px 7px;
    display: grid;
    place-items: center;
    gap: 2px;
  }

  .stats dt {
    font-size: 11px;
  }

  .stats dd {
    font-size: 18px;
  }

  .controls {
    display: none;
  }

  .sound-toggle {
    margin: 0;
    min-height: 36px;
    padding: 7px 8px;
  }

  #fullscreenToggle {
    display: block;
  }

  .game-area {
    width: min(100%, calc(100dvh - 178px));
    max-width: 100%;
    align-self: start;
    justify-self: center;
    border-width: 2px;
    border-radius: 10px;
  }
}

@media (hover: none), (max-width: 680px) {
  .touch-controls {
    display: block;
  }

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

  .touch-controls button {
    border-color: rgba(140, 236, 255, 0.42);
    background: rgba(9, 15, 20, 0.66);
  }

  .fire {
    width: 104px;
    height: 104px;
    right: max(12px, env(safe-area-inset-right));
    bottom: max(12px, env(safe-area-inset-bottom));
  }

  .pause-touch {
    right: max(12px, env(safe-area-inset-right));
    top: max(12px, env(safe-area-inset-top));
  }
}

@media (max-width: 840px) and (orientation: landscape) {
  body {
    display: block;
    padding: max(6px, env(safe-area-inset-top)) max(6px, env(safe-area-inset-right))
      max(6px, env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-left));
  }

  .shell {
    width: 100%;
    min-height: calc(100dvh - 12px);
    display: block;
    position: relative;
  }

  .hud {
    position: fixed;
    z-index: 5;
    left: max(8px, env(safe-area-inset-left));
    right: max(8px, env(safe-area-inset-right));
    top: max(6px, env(safe-area-inset-top));
    display: grid;
    grid-template-columns: minmax(120px, 1.2fr) 2fr auto auto;
    align-items: center;
    gap: 6px;
    padding: 6px;
    border-radius: 10px;
    background:
      linear-gradient(135deg, rgba(42, 212, 255, 0.12), transparent 44%),
      rgba(12, 18, 24, 0.82);
    backdrop-filter: blur(5px);
  }

  .mission {
    min-height: 32px;
    padding: 5px 7px;
  }

  .stats {
    grid-template-columns: repeat(4, minmax(44px, 1fr));
    gap: 5px;
  }

  .stats div {
    min-height: 32px;
    padding: 3px 5px;
  }

  .stats dt {
    font-size: 10px;
  }

  .stats dd {
    font-size: 15px;
  }

  .sound-toggle {
    width: auto;
    min-width: 58px;
    min-height: 32px;
    padding: 5px 7px;
    font-size: 12px;
  }

  .game-area {
    width: min(calc(100dvh - 14px), calc(100dvw - 188px));
    max-width: calc(100dvw - 188px);
    margin: 0 auto;
    transform: translateY(max(0px, calc((100dvh - min(calc(100dvh - 14px), calc(100dvw - 188px))) / 2)));
    border-width: 2px;
  }

  .mission span {
    display: none;
  }

  .touch-controls {
    position: fixed;
    z-index: 6;
    inset: 0;
    display: block;
  }

  .joystick {
    left: max(10px, env(safe-area-inset-left));
    bottom: max(10px, env(safe-area-inset-bottom));
    width: 96px;
    height: 96px;
  }

  .joystick span {
    width: 42px;
    height: 42px;
  }

  .fire {
    right: max(12px, env(safe-area-inset-right));
    bottom: max(12px, env(safe-area-inset-bottom));
    width: 92px;
    height: 92px;
  }

  .pause-touch {
    right: max(12px, env(safe-area-inset-right));
    top: calc(max(6px, env(safe-area-inset-top)) + 44px);
    width: 40px;
    height: 40px;
  }
}
