:root {
  color-scheme: dark;
  --cyan: #63e7ff;
  --gold: #ffd35a;
  --green: #5ee077;
  --red: #ff4d5d;
  --ink: #071015;
  --panel: rgba(5, 12, 16, 0.58);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "PingFang SC", "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

#game-shell {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: #05090d;
}

#gameCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

#hud,
#bossHud,
#touchControls,
#modePanel,
.overlay {
  position: absolute;
  z-index: 2;
}

#modePanel {
  top: max(12px, env(safe-area-inset-top));
  left: 50%;
  z-index: 3;
  display: grid;
  grid-template-columns: repeat(3, minmax(74px, auto));
  gap: 4px;
  padding: 4px;
  transform: translateX(-50%);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  background: rgba(3, 9, 13, 0.5);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(12px);
}

#modePanel button {
  height: 32px;
  min-width: 72px;
  padding: 0 12px;
  border: 0;
  border-radius: 6px;
  color: rgba(255, 255, 255, 0.66);
  background: transparent;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
  white-space: nowrap;
}

#modePanel button[aria-pressed="true"] {
  color: #061015;
  background: linear-gradient(180deg, #88f1ff, #ffd35a);
  box-shadow: 0 6px 18px rgba(99, 231, 255, 0.2);
}

#hud {
  top: max(12px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  right: max(12px, env(safe-area-inset-right));
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  pointer-events: none;
  text-shadow: 0 1px 10px rgba(0, 0, 0, 0.72);
}

.hud-left,
.hud-right {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.hp-shell {
  width: min(220px, 42vw);
  height: 14px;
  border: 1px solid rgba(255, 255, 255, 0.78);
  background: rgba(0, 0, 0, 0.32);
  overflow: hidden;
}

#hpFill,
#bossFill {
  display: block;
  width: 100%;
  height: 100%;
  transform-origin: left center;
}

#hpFill {
  background: linear-gradient(90deg, #4bd968, #e7f777);
}

.stat-row {
  width: fit-content;
  min-width: 148px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 4px 7px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: var(--panel);
  border-radius: 6px;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.72);
}

.stat-row strong {
  color: var(--gold);
  font-size: 14px;
}

.stat-label,
.score-label {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.62);
}

.hud-right {
  align-items: flex-end;
}

#scoreText {
  color: #fff;
  font-size: clamp(28px, 4vw, 48px);
  line-height: 0.95;
}

#bossHud {
  top: max(62px, calc(env(safe-area-inset-top) + 56px));
  left: 50%;
  width: min(760px, calc(100vw - 28px));
  transform: translateX(-50%);
  text-align: center;
  pointer-events: none;
}

#bossName {
  margin-bottom: 5px;
  font-size: clamp(13px, 1.9vw, 18px);
  font-weight: 800;
  color: #ffbb62;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.78);
}

.boss-bar {
  height: 14px;
  border: 1px solid rgba(255, 78, 78, 0.9);
  background: rgba(0, 0, 0, 0.42);
  overflow: hidden;
}

#bossFill {
  background: linear-gradient(90deg, #ff334c, #ff8f45);
}

#touchControls {
  right: max(14px, env(safe-area-inset-right));
  bottom: max(14px, env(safe-area-inset-bottom));
  display: flex;
  gap: 10px;
  align-items: center;
}

.icon-button {
  width: 52px;
  height: 52px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  color: white;
  background: var(--panel);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.28);
  font-size: 19px;
  font-weight: 800;
  cursor: pointer;
  backdrop-filter: blur(10px);
}

.icon-button:active {
  transform: translateY(1px) scale(0.98);
}

.bomb-button {
  width: 62px;
  height: 62px;
  color: #2b1600;
  background: linear-gradient(180deg, #ffd35a, #ff8d42);
  border-color: rgba(255, 255, 255, 0.42);
}

.overlay {
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(180deg, rgba(15, 34, 43, 0.32), rgba(2, 6, 10, 0.72)),
    rgba(2, 6, 10, 0.58);
  backdrop-filter: blur(3px);
}

.overlay[hidden] {
  display: none;
}

.overlay-panel {
  width: min(440px, calc(100vw - 32px));
  padding: 26px 24px 24px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(13, 31, 39, 0.82), rgba(5, 12, 17, 0.78)),
    rgba(6, 15, 20, 0.72);
  box-shadow: 0 28px 76px rgba(0, 0, 0, 0.36);
  text-align: center;
}

#overlayKicker {
  margin: 0 0 8px;
  color: var(--cyan);
  font-size: 12px;
  font-weight: 800;
}

#overlayTitle {
  margin: 0;
  color: white;
  font-size: clamp(34px, 8vw, 58px);
  line-height: 1;
}

#overlayScore {
  min-height: 22px;
  margin: 14px 0 18px;
  color: rgba(255, 255, 255, 0.78);
  font-size: 16px;
}

.overlay-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

.overlay-actions button {
  min-width: 118px;
  height: 42px;
  border: 0;
  border-radius: 8px;
  color: #071015;
  background: linear-gradient(180deg, #72efff, #49c5ff);
  font-size: 15px;
  font-weight: 850;
  cursor: pointer;
}

.overlay-actions button[hidden] {
  display: none;
}

.overlay-actions #secondaryAction {
  color: white;
  background: rgba(255, 255, 255, 0.16);
  border: 1px solid rgba(255, 255, 255, 0.22);
}

@media (max-width: 760px) {
  #modePanel {
    top: auto;
    left: max(12px, env(safe-area-inset-left));
    bottom: max(84px, calc(env(safe-area-inset-bottom) + 84px));
    grid-template-columns: repeat(3, minmax(0, 1fr));
    width: min(300px, calc(100vw - 24px));
    transform: none;
  }

  #modePanel button {
    min-width: 0;
    padding: 0 6px;
    font-size: 12px;
  }
}

@media (max-width: 680px) {
  #hud {
    top: max(8px, env(safe-area-inset-top));
    left: max(8px, env(safe-area-inset-left));
    right: max(8px, env(safe-area-inset-right));
  }

  .hp-shell {
    width: min(168px, 45vw);
  }

  .stat-row {
    min-width: 96px;
    gap: 8px;
    padding: 3px 6px;
    font-size: 12px;
  }

  #bossHud {
    top: max(72px, calc(env(safe-area-inset-top) + 66px));
  }

  .icon-button {
    width: 48px;
    height: 48px;
  }

  .bomb-button {
    width: 58px;
    height: 58px;
  }
}
