*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #070a14;
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", system-ui, sans-serif;
  color: #f1f5f9;
  touch-action: none;
}

#game-shell {
  position: relative;
  width: 100vw;
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at center, #121a30 0%, #05070f 100%);
  overflow: hidden;
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  max-width: calc(100dvh * 16 / 9);
  max-height: calc(100vw * 9 / 16);
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #0b1020;
  box-shadow: 0 0 40px rgba(0, 0, 0, 0.75);
}

/* Overlays */
.overlay {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 20;
}

.overlay.visible {
  display: flex;
}

/* Main Menu */
#main-menu {
  background: #070a14;
  overflow: hidden;
}

#menu-bg-img, #menu-fx-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  pointer-events: none;
}

#menu-fx-canvas {
  z-index: 1;
}

.menu-content {
  position: relative;
  z-index: 2;
  width: min(92vw, 960px);
  padding: clamp(16px, 4vw, 48px);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: clamp(14px, 2.5vh, 26px);
}

.title-block {
  text-shadow: 0 3px 16px rgba(6, 12, 28, 0.9), 0 0 24px rgba(86, 212, 255, 0.45);
}

.title-kicker {
  font-size: clamp(10px, 1.3vw, 13px);
  letter-spacing: 0.24em;
  color: #7dd3fc;
  font-weight: 700;
  margin-bottom: 6px;
}

.game-title {
  font-size: clamp(32px, 6vw, 62px);
  font-weight: 900;
  letter-spacing: 0.12em;
  background: linear-gradient(180deg, #ffffff 15%, #ffd6e7 68%, #93e2ff 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 4px 0 rgba(16, 28, 56, 0.85));
  line-height: 1.1;
}

.game-subtitle {
  margin-top: 6px;
  font-size: clamp(11px, 1.5vw, 15px);
  letter-spacing: 0.26em;
  color: #e2e8f0;
  opacity: 0.92;
}

.menu-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: min(260px, 68vw);
}

.pixel-btn {
  appearance: none;
  border: 2px solid rgba(186, 230, 253, 0.55);
  background: rgba(11, 18, 36, 0.78);
  color: #f8fafc;
  font-size: clamp(14px, 1.8vw, 17px);
  font-weight: 700;
  letter-spacing: 0.08em;
  padding: 11px 18px;
  text-align: left;
  cursor: pointer;
  border-radius: 4px;
  box-shadow: 0 4px 0 rgba(4, 9, 22, 0.85), inset 0 1px 0 rgba(255, 255, 255, 0.16);
  transition: transform 0.08s ease, background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
  backdrop-filter: blur(4px);
}

.pixel-btn .btn-arrow {
  display: inline-block;
  margin-right: 8px;
  color: #7dd3fc;
  opacity: 0.55;
  transition: transform 0.12s ease, opacity 0.12s ease;
}

.pixel-btn:hover,
.pixel-btn.selected,
.pixel-btn:focus-visible {
  outline: none;
  background: rgba(24, 48, 86, 0.92);
  border-color: #7dd3fc;
  transform: translateX(4px);
  box-shadow: 0 4px 0 rgba(4, 9, 22, 0.9), 0 0 18px rgba(56, 189, 248, 0.35);
}

.pixel-btn:hover .btn-arrow,
.pixel-btn.selected .btn-arrow {
  opacity: 1;
  transform: translateX(3px);
}

.pixel-btn:active {
  transform: translateX(4px) translateY(2px);
}

.pixel-btn.primary {
  background: linear-gradient(135deg, rgba(28, 92, 168, 0.9), rgba(14, 52, 108, 0.92));
  border-color: #93e2ff;
}

.pixel-btn.danger {
  border-color: rgba(251, 113, 133, 0.65);
  color: #fecdd3;
}

.pixel-btn.small {
  padding: 8px 18px;
  text-align: center;
  font-size: 14px;
}

.menu-hint {
  font-size: clamp(11px, 1.3vw, 13px);
  color: rgba(226, 232, 240, 0.82);
  background: rgba(9, 14, 28, 0.58);
  padding: 6px 12px;
  border-radius: 4px;
  border-left: 3px solid #f9a8d4;
}

/* Required Brand Signature */
.brand-signature {
  position: absolute;
  right: max(18px, env(safe-area-inset-right, 18px));
  bottom: max(14px, env(safe-area-inset-bottom, 14px));
  z-index: 3;
  font-size: clamp(12px, 1.5vw, 16px);
  font-weight: 700;
  letter-spacing: 0.1em;
  color: #fff1f7;
  text-shadow: 0 2px 8px rgba(5, 8, 20, 0.95), 0 0 12px rgba(249, 168, 212, 0.55);
  background: rgba(10, 15, 30, 0.45);
  padding: 5px 12px;
  border-radius: 4px;
  border: 1px solid rgba(255, 214, 231, 0.35);
}

/* Modals */
.modal-backdrop {
  background: rgba(5, 9, 20, 0.76);
  backdrop-filter: blur(5px);
  z-index: 40;
  padding: 16px;
}

.modal-card {
  width: min(680px, 94vw);
  max-height: 90dvh;
  overflow-y: auto;
  background: linear-gradient(180deg, rgba(16, 25, 48, 0.96), rgba(10, 16, 32, 0.98));
  border: 2px solid rgba(125, 211, 252, 0.55);
  border-radius: 8px;
  padding: 18px 22px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.7);
}

.modal-card.compact {
  width: min(320px, 86vw);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.25);
}

.modal-header h2 {
  font-size: 20px;
  color: #e0f2fe;
  letter-spacing: 0.08em;
}

.icon-close {
  background: transparent;
  border: 1px solid rgba(148, 163, 184, 0.4);
  color: #e2e8f0;
  width: 30px;
  height: 30px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 16px;
}

.controls-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
  margin-bottom: 14px;
}

.ctrl-col h3 {
  font-size: 14px;
  color: #f9a8d4;
  margin-bottom: 8px;
  letter-spacing: 0.06em;
}

.ctrl-col ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
}

.ctrl-col li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 8px;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 4px;
}

.ctrl-col li span {
  color: #cbd5e1;
}

kbd {
  display: inline-block;
  padding: 1px 6px;
  font-size: 11px;
  font-family: ui-monospace, monospace;
  background: rgba(30, 41, 59, 0.95);
  border: 1px solid rgba(125, 211, 252, 0.45);
  border-radius: 3px;
  color: #e0f2fe;
}

.weapon-guide {
  font-size: 12.5px;
  line-height: 1.55;
  color: #cbd5e1;
  background: rgba(56, 189, 248, 0.08);
  border: 1px solid rgba(56, 189, 248, 0.25);
  border-radius: 6px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.weapon-guide strong {
  color: #7dd3fc;
}

.modal-footer {
  margin-top: 14px;
  display: flex;
  justify-content: flex-end;
}

.pause-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.pause-actions .pixel-btn {
  text-align: center;
}

/* Touch Controls for Mobile Landscape */
#touch-controls {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 15;
  display: none;
}

#touch-controls.active {
  display: block;
}

.touch-top-bar {
  position: absolute;
  top: max(10px, env(safe-area-inset-top, 10px));
  right: max(12px, env(safe-area-inset-right, 12px));
  display: flex;
  gap: 8px;
  pointer-events: auto;
}

.tc-pill {
  background: rgba(12, 20, 40, 0.65);
  border: 1.5px solid rgba(147, 226, 255, 0.55);
  color: #f1f5f9;
  font-size: 12px;
  font-weight: 700;
  padding: 6px 12px;
  border-radius: 16px;
  backdrop-filter: blur(3px);
}

.tc-pill.hidden {
  display: none;
}

.tc-pill.pressed {
  background: rgba(56, 189, 248, 0.55);
}

.touch-left {
  position: absolute;
  left: max(18px, env(safe-area-inset-left, 18px));
  bottom: max(18px, env(safe-area-inset-bottom, 18px));
  pointer-events: auto;
}

.dpad-pad {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  background: rgba(10, 16, 34, 0.42);
  border: 1.5px solid rgba(255, 255, 255, 0.22);
  border-radius: 40px;
  backdrop-filter: blur(2px);
}

.dpad-btn {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: rgba(20, 32, 60, 0.68);
  border: 2px solid rgba(186, 230, 253, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  color: #e0f2fe;
}

.dpad-btn.pressed {
  background: rgba(56, 189, 248, 0.58);
  border-color: #ffffff;
  transform: scale(0.94);
}

.dpad-center {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
}

.touch-right {
  position: absolute;
  right: max(18px, env(safe-area-inset-right, 18px));
  bottom: max(16px, env(safe-area-inset-bottom, 16px));
  width: 205px;
  height: 148px;
  pointer-events: auto;
}

.tc-btn {
  position: absolute;
  border-radius: 50%;
  border: 2px solid rgba(226, 232, 240, 0.5);
  background: rgba(15, 24, 48, 0.65);
  color: #f8fafc;
  font-weight: 800;
  font-size: 13px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1.1;
  backdrop-filter: blur(2px);
}

.tc-btn small {
  font-size: 9px;
  opacity: 0.8;
  font-weight: 600;
}

.tc-btn.pressed {
  transform: scale(0.92);
  border-color: #ffffff;
}

.tc-jump {
  width: 64px;
  height: 64px;
  right: 4px;
  bottom: 4px;
  border-color: rgba(134, 239, 172, 0.72);
  background: rgba(18, 62, 52, 0.65);
}

.tc-jump.pressed { background: rgba(52, 211, 153, 0.68); }

.tc-light {
  width: 64px;
  height: 64px;
  right: 76px;
  bottom: 14px;
  border-color: rgba(125, 211, 252, 0.78);
  background: rgba(20, 56, 98, 0.7);
}

.tc-light.pressed { background: rgba(56, 189, 248, 0.72); }

.tc-heavy {
  width: 60px;
  height: 60px;
  right: 12px;
  bottom: 78px;
  border-color: rgba(249, 168, 212, 0.8);
  background: rgba(88, 28, 72, 0.68);
}

.tc-heavy.pressed { background: rgba(244, 114, 182, 0.75); }

.tc-dash {
  width: 52px;
  height: 52px;
  right: 146px;
  bottom: 4px;
  font-size: 12px;
  border-color: rgba(253, 224, 71, 0.65);
  background: rgba(66, 52, 20, 0.62);
}

.tc-dash.pressed { background: rgba(250, 204, 21, 0.7); }

/* Portrait rotation hint */
#rotate-notice {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(7, 10, 20, 0.94);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

@media (max-width: 600px) and (orientation: portrait) {
  #rotate-notice:not(.dismissed) {
    display: flex;
  }
}

.rotate-box {
  text-align: center;
  max-width: 280px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.rotate-icon {
  font-size: 42px;
}

.rotate-box p {
  font-size: 14px;
  line-height: 1.6;
  color: #cbd5e1;
}
