:root {
  color-scheme: dark;
  --panel: rgba(5, 13, 29, 0.78);
  --ink: #fff5d7;
  --gold: #ffd24d;
  --orange: #ff8b23;
  --blue: #31d7ff;
  --hero-hp: 1;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: radial-gradient(circle at 50% 0%, #1d4d8d 0, #081121 48%, #02040a 100%);
  color: var(--ink);
  font-family: "Microsoft JhengHei", "PingFang TC", system-ui, sans-serif;
  overflow-x: hidden;
}

button {
  color: inherit;
  font: inherit;
  touch-action: manipulation;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

.button-text {
  position: relative;
  z-index: 1;
  display: block;
  width: 100%;
  overflow: hidden;
  line-height: 1.15;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
  pointer-events: none;
  -webkit-user-select: none;
  user-select: none;
}

.button-art {
  position: absolute;
  z-index: 1;
  left: 29px;
  top: 4px;
  width: calc(100% - 39px);
  height: calc(100% - 9px);
  display: block;
  object-fit: contain;
  pointer-events: none;
}

.stage-select .button-art {
  left: 30px;
  top: 4px;
  width: calc(100% - 43px);
  height: calc(100% - 8px);
}

.overlay .button-art,
.death-panel .button-art {
  left: 40px;
  top: 5px;
  width: calc(100% - 56px);
  height: calc(100% - 10px);
}

.game-shell {
  min-height: 100vh;
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: clamp(6px, 1.6vh, 16px);
}

.game-card {
  width: min(1180px, 100%);
  max-height: calc(100svh - clamp(12px, 3.2vh, 32px));
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: clamp(6px, 1.1vh, 12px);
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 0;
}

.title-art {
  width: clamp(190px, 28vw, 360px);
  height: auto;
  filter: drop-shadow(0 10px 12px rgba(0, 0, 0, 0.5)) drop-shadow(0 0 12px rgba(49, 215, 255, 0.22));
}

.stage-select {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
}

.stage-select button {
  position: relative;
  overflow: hidden;
  min-height: 38px;
  padding: 8px 13px 8px 32px;
  border: 2px solid rgba(255, 210, 77, 0.58);
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(14, 38, 82, 0.92), rgba(5, 13, 29, 0.82));
  color: var(--ink);
  font-weight: 800;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.5);
  box-shadow: inset 0 0 14px rgba(49, 215, 255, 0.18), 0 4px 0 rgba(6, 20, 48, 0.9);
}

.stage-select button::before,
.overlay button::before,
.death-panel button::before,
.controls button::before {
  content: "";
  position: absolute;
  left: 9px;
  top: 50%;
  width: 17px;
  height: 15px;
  border-radius: 58% 58% 48% 48%;
  background:
    radial-gradient(circle at 26% 0%, #fff8cf 0 16%, transparent 18%),
    radial-gradient(circle at 50% -6%, #fff8cf 0 17%, transparent 19%),
    radial-gradient(circle at 74% 0%, #fff8cf 0 16%, transparent 18%),
    radial-gradient(ellipse at 50% 72%, #fff8cf 0 46%, transparent 48%);
  filter: drop-shadow(0 1px 0 rgba(90, 32, 0, 0.55));
  transform: translateY(-50%);
  opacity: 0.95;
  pointer-events: none;
}

.stage-select button.active {
  border-color: rgba(255, 210, 77, 0.85);
  background: linear-gradient(180deg, rgba(255, 220, 95, 0.96), rgba(255, 139, 35, 0.88));
  color: #fffbe7;
  box-shadow: inset 0 0 14px rgba(255, 245, 215, 0.45), 0 5px 0 #8f3600, 0 0 18px rgba(255, 210, 77, 0.28);
}

.stage-select button:disabled {
  cursor: not-allowed;
  opacity: 0.52;
}

.hud {
  display: flex;
  flex-wrap: wrap;
  justify-content: end;
  gap: 8px;
  font-weight: 800;
}

.hud span {
  position: relative;
  overflow: hidden;
  min-width: 86px;
  padding: 8px 10px;
  border: 2px solid rgba(255, 210, 77, 0.58);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(14, 38, 82, 0.92), rgba(5, 13, 29, 0.82));
  text-align: center;
  box-shadow: inset 0 0 18px rgba(49, 215, 255, 0.18), 0 4px 0 rgba(2, 7, 18, 0.8);
}

.hud b {
  color: var(--gold);
  position: relative;
  z-index: 1;
}

.hud .hp-panel {
  min-width: 128px;
  padding-right: 14px;
  border-color: rgba(255, 232, 116, 0.82);
}

.hud .hp-panel::before {
  content: "";
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 5px;
  height: 8px;
  border-radius: 999px;
  background: rgba(2, 4, 10, 0.62);
  box-shadow: inset 0 0 0 1px rgba(255, 245, 215, 0.22);
}

.hud .hp-panel::after {
  content: "";
  position: absolute;
  left: 10px;
  bottom: 7px;
  width: calc((100% - 20px) * var(--hero-hp, 1));
  height: 4px;
  border-radius: 999px;
  background: linear-gradient(90deg, #ff4f4f, #ffe274, #7ff0ff);
  box-shadow: 0 0 10px rgba(255, 210, 77, 0.75);
}

.stage-wrap {
  position: relative;
  overflow: hidden;
  aspect-ratio: 16 / 9;
  width: min(100%, calc(66svh * 16 / 9));
  justify-self: center;
  border: 2px solid rgba(255, 210, 77, 0.58);
  border-radius: 8px;
  background: #02040a;
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.52), 0 0 40px rgba(49, 215, 255, 0.14);
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
}

.overlay {
  position: absolute;
  z-index: 9;
  inset: 0;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 14px;
  padding: 24px;
  background: linear-gradient(180deg, rgba(2, 4, 10, 0.12), rgba(2, 4, 10, 0.62));
  text-align: center;
}

.overlay.hidden {
  display: none;
}

.overlay img {
  width: min(520px, 72vw, 72%);
}

.overlay button,
.death-panel button,
.controls button,
.skill-pad button {
  position: relative;
  overflow: hidden;
  border: 2px solid rgba(255, 245, 215, 0.85);
  border-radius: 16px 16px 18px 18px;
  background:
    radial-gradient(circle at 22% 18%, rgba(255, 255, 255, 0.48) 0 10%, transparent 12%),
    linear-gradient(180deg, #fff4a8, #ff9d2f 70%, #f0761e);
  color: #351200;
  font-weight: 900;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.6);
  box-shadow: inset 0 -5px 0 rgba(143, 54, 0, 0.22), 0 7px 0 #8f3600, 0 0 18px rgba(255, 210, 77, 0.28);
}

.overlay button {
  padding: 14px 24px 14px 48px;
  font-size: 1.1rem;
}

.death-panel {
  position: absolute;
  z-index: 12;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 50% 42%, rgba(255, 210, 77, 0.12), transparent 31%),
    linear-gradient(180deg, rgba(2, 4, 10, 0.2), rgba(2, 4, 10, 0.94) 78%);
  text-align: center;
  animation: deathFade 0.95s ease-out both;
}

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

.death-card {
  position: relative;
  width: min(520px, 86%);
  padding: 22px 24px 24px;
  border: 2px solid rgba(255, 210, 77, 0.86);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(49, 215, 255, 0.16), transparent 28%),
    linear-gradient(180deg, rgba(8, 24, 54, 0.95), rgba(3, 8, 22, 0.96));
  box-shadow:
    inset 0 0 28px rgba(255, 210, 77, 0.12),
    0 0 34px rgba(49, 215, 255, 0.22),
    0 18px 50px rgba(0, 0, 0, 0.72);
  animation: scorePop 0.92s 0.28s cubic-bezier(.2, 1.25, .26, 1) both;
}

.death-card::before,
.death-card::after {
  content: "";
  position: absolute;
  left: 28px;
  right: 28px;
  height: 3px;
  border-radius: 999px;
  background: linear-gradient(90deg, transparent, #31d7ff, #ffd24d, transparent);
  box-shadow: 0 0 14px rgba(255, 210, 77, 0.68);
}

.death-card::before {
  top: 12px;
}

.death-card::after {
  bottom: 12px;
}

.death-kicker {
  display: inline-block;
  margin-bottom: 8px;
  color: #7ff0ff;
  font-weight: 900;
  letter-spacing: 0.08em;
}

.death-card h2 {
  margin: 0 0 10px;
  color: #fff5d7;
  font-size: clamp(1.3rem, 4vw, 2.4rem);
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.58), 0 0 18px rgba(255, 210, 77, 0.38);
}

.death-score {
  display: grid;
  gap: 2px;
  margin: 8px auto 16px;
  color: #ffd24d;
  text-shadow: 0 0 18px rgba(255, 210, 77, 0.44);
}

.death-score span {
  color: #c7f6ff;
  font-weight: 900;
}

.death-score strong {
  font-size: clamp(3rem, 9vw, 5.8rem);
  line-height: 0.98;
}

.death-rank {
  display: inline-block;
  margin: 0 0 16px;
  padding: 7px 16px;
  border: 1px solid rgba(255, 210, 77, 0.65);
  border-radius: 999px;
  background: rgba(255, 210, 77, 0.12);
  color: #fff5d7;
  font-weight: 900;
  box-shadow: 0 0 18px rgba(255, 210, 77, 0.18);
}

.death-rescue {
  display: inline-grid;
  grid-template-columns: 46px minmax(0, auto);
  align-items: center;
  gap: 10px;
  max-width: min(420px, 100%);
  margin: 0 0 16px;
  padding: 7px 15px 7px 7px;
  border: 1px solid rgba(255, 210, 77, 0.72);
  border-radius: 999px;
  background:
    radial-gradient(circle at 13% 28%, rgba(255, 210, 77, 0.22), transparent 28%),
    rgba(255, 210, 77, 0.12);
  color: #fff5d7;
  font-weight: 900;
  box-shadow: 0 0 18px rgba(255, 210, 77, 0.18);
}

.death-victim-avatar {
  width: 42px;
  height: 42px;
  border: 2px solid rgba(255, 245, 215, 0.9);
  border-radius: 50%;
  background:
    url("./assets/npc_frames/victim_happy.png?v=35") center 18% / 148% auto no-repeat,
    linear-gradient(180deg, rgba(255, 210, 77, 0.95), rgba(49, 215, 255, 0.82));
  box-shadow: 0 0 0 2px rgba(255, 210, 77, 0.38), 0 0 14px rgba(49, 215, 255, 0.24);
}

.death-panel button {
  padding: 12px 24px 12px 48px;
  font-size: 1.02rem;
}

.intro-dialog {
  position: relative;
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr);
  align-items: center;
  width: min(760px, calc(100% - 48px));
  margin-right: 0;
  padding: 12px 18px 12px 12px;
  border: 2px solid rgba(255, 210, 77, 0.82);
  border-radius: 8px 8px 8px 18px;
  background:
    radial-gradient(circle at 8% 18%, rgba(255, 210, 77, 0.22), transparent 26%),
    linear-gradient(180deg, rgba(3, 8, 22, 0.88), rgba(3, 8, 22, 0.74));
  box-shadow:
    inset 0 0 22px rgba(49, 215, 255, 0.1),
    0 12px 30px rgba(0, 0, 0, 0.42);
}

.intro-dialog::after {
  content: "";
  position: absolute;
  left: 54px;
  bottom: -13px;
  width: 24px;
  height: 24px;
  border-right: 2px solid rgba(255, 210, 77, 0.82);
  border-bottom: 2px solid rgba(255, 210, 77, 0.82);
  background: rgba(3, 8, 22, 0.78);
  transform: rotate(45deg);
}

.intro-avatar {
  position: relative;
  z-index: 1;
  width: 62px;
  height: 62px;
  border: 3px solid rgba(255, 245, 215, 0.92);
  border-radius: 50%;
  background:
    url("./assets/hero_frames/idle.png?v=34") center 20% / 142% auto no-repeat,
    linear-gradient(180deg, rgba(255, 210, 77, 0.94), rgba(49, 215, 255, 0.9));
  box-shadow: 0 0 0 3px rgba(255, 210, 77, 0.42), 0 0 18px rgba(49, 215, 255, 0.3);
}

.intro-dialog p {
  position: relative;
  z-index: 1;
  margin: 0;
  color: #fff5d7;
  font-size: clamp(0.86rem, 1.4vw, 1.05rem);
  font-weight: 800;
  line-height: 1.52;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.6);
}

@keyframes deathFade {
  from {
    background-color: rgba(2, 4, 10, 0);
  }
  to {
    background-color: rgba(2, 4, 10, 0.88);
  }
}

@keyframes scorePop {
  from {
    opacity: 0;
    transform: translateY(22px) scale(0.86);
    filter: blur(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
    filter: blur(0);
  }
}

.controls {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-top: 0;
}

.system-pad {
  display: flex;
  gap: 8px;
}

.move-pad {
  display: flex;
  gap: 8px;
}

.skill-pad {
  position: absolute;
  z-index: 7;
  right: 18px;
  top: 50%;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  transform: translateY(-50%);
  pointer-events: auto;
}

.controls button {
  min-width: 72px;
  min-height: 50px;
  padding: 10px 13px 10px 31px;
  font-size: 1rem;
  white-space: nowrap;
}

.system-pad button {
  min-width: 112px;
}

.system-pad button.muted {
  background:
    radial-gradient(circle at 22% 18%, rgba(255, 255, 255, 0.35) 0 10%, transparent 12%),
    linear-gradient(180deg, #e1edf3, #7792a4 72%, #4d6577);
  color: #081725;
  box-shadow: inset 0 -5px 0 rgba(9, 22, 34, 0.18), 0 7px 0 #253746, 0 0 16px rgba(199, 246, 255, 0.22);
}

#pauseBtn.active {
  background:
    radial-gradient(circle at 22% 18%, rgba(255, 255, 255, 0.54) 0 10%, transparent 12%),
    linear-gradient(180deg, #c7f6ff, #31d7ff 72%, #0870d8);
  color: #03142f;
  box-shadow: inset 0 -5px 0 rgba(7, 76, 157, 0.22), 0 7px 0 #074c9d, 0 0 18px rgba(49, 215, 255, 0.42);
}

.skill-pad button {
  display: grid;
  place-items: center;
  align-content: center;
  width: clamp(54px, 5.2vw, 66px);
  height: clamp(54px, 5.2vw, 66px);
  padding: 5px;
  border-radius: 50%;
  color: #351200;
  line-height: 1;
}

.skill-pad .button-art {
  position: relative;
  left: auto;
  right: auto;
  top: auto;
  bottom: auto;
  width: 100%;
  height: 100%;
}

.skill-pad button::before {
  content: "";
  position: absolute;
  inset: 7px;
  border-radius: 50%;
  border: 1px solid rgba(255, 245, 215, 0.62);
  box-shadow: inset 0 0 15px rgba(255, 255, 255, 0.25);
  pointer-events: none;
}

.skill-icon,
.skill-label,
.button-text,
.cooldown-text {
  position: relative;
  z-index: 1;
}

.skill-icon {
  font-size: 1.55rem;
  font-weight: 900;
  text-shadow: 0 2px 0 rgba(255, 255, 255, 0.48), 0 0 8px rgba(255, 245, 215, 0.34);
}

.skill-label {
  max-width: 58px;
  margin-top: 2px;
  overflow: hidden;
  font-size: 0.68rem;
  font-weight: 900;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cooldown-text {
  position: absolute;
  right: 3px;
  bottom: 3px;
  min-width: 24px;
  min-height: 18px;
  padding: 2px 4px;
  border-radius: 999px;
  background: rgba(2, 4, 10, 0.76);
  color: #fff5d7;
  font-size: 0.66rem;
  line-height: 1;
  text-shadow: none;
  opacity: 0;
  pointer-events: none;
}

.cooldown-art {
  display: block;
  width: 100%;
  height: 18px;
  object-fit: contain;
  pointer-events: none;
}

.cooldown-text.show {
  opacity: 1;
}

.controls .button-art,
.stage-select .button-art,
.overlay .button-art,
.death-panel .button-art {
  position: absolute;
  z-index: 1;
  display: block;
  object-fit: contain;
  pointer-events: none;
}

.controls .button-art {
  left: 29px;
  top: 4px;
  width: calc(100% - 39px);
  height: calc(100% - 9px);
}

.stage-select .button-art {
  left: 30px;
  top: 4px;
  width: calc(100% - 43px);
  height: calc(100% - 8px);
}

.overlay .button-art,
.death-panel .button-art {
  left: 40px;
  top: 5px;
  width: calc(100% - 56px);
  height: calc(100% - 10px);
}

.skill-pad .button-art {
  position: relative;
  left: auto;
  top: auto;
  width: 100%;
  height: 100%;
}

.controls button::after,
.skill-pad button::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: rgba(2, 4, 10, 0.56);
  transform: scaleY(var(--cooldown, 0));
  transform-origin: bottom;
  transition: transform 0.08s linear;
  z-index: 0;
}

.controls button.cooling,
.skill-pad button.cooling {
  color: rgba(255, 245, 215, 0.92);
  cursor: wait;
  filter: saturate(0.72);
}

.controls button:disabled,
.skill-pad button:disabled {
  opacity: 0.82;
}

.controls button:active,
.controls button.active,
.skill-pad button:active,
.skill-pad button.active {
  transform: translateY(5px);
  box-shadow: 0 2px 0 #8f3600, 0 0 18px rgba(49, 215, 255, 0.42);
}

.controls .special,
.skill-pad .special {
  background:
    radial-gradient(circle at 22% 18%, rgba(255, 255, 255, 0.5) 0 10%, transparent 12%),
    linear-gradient(180deg, #a8f7ff, #218cff 74%, #0870d8);
  color: #03142f;
  box-shadow: 0 7px 0 #074c9d, 0 0 18px rgba(49, 215, 255, 0.4);
}

.controls .summon,
.skill-pad .summon {
  background:
    radial-gradient(circle at 22% 18%, rgba(255, 255, 255, 0.5) 0 10%, transparent 12%),
    linear-gradient(180deg, #fff6b2, #ff6f52 72%, #df3c3c);
  color: #310707;
  box-shadow: 0 7px 0 #8f1b1b, 0 0 18px rgba(255, 98, 82, 0.4);
}

.controls .heal,
.skill-pad .heal {
  background:
    radial-gradient(circle at 22% 18%, rgba(255, 255, 255, 0.54) 0 10%, transparent 12%),
    linear-gradient(180deg, #c9ffdc, #35c97b 72%, #16a45d);
  color: #042111;
  box-shadow: 0 7px 0 #08733c, 0 0 18px rgba(86, 255, 151, 0.34);
}

.controls .shield,
.skill-pad .shield {
  background:
    radial-gradient(circle at 22% 18%, rgba(255, 255, 255, 0.56) 0 10%, transparent 12%),
    linear-gradient(180deg, #e5fbff, #64dfff 48%, #2f7dff 78%, #1846c8);
  color: #03142f;
  box-shadow: 0 7px 0 #123c91, 0 0 20px rgba(100, 223, 255, 0.48);
}

@media (max-width: 740px) {
  .game-shell {
    align-items: center;
    padding: 6px;
  }

  .game-card {
    max-height: calc(100svh - 12px);
    gap: 5px;
  }

  .topbar {
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 7px;
  }

  .title-art {
    width: min(94vw, 430px);
  }

  .stage-select {
    order: 3;
    width: 100%;
  }

  .hud {
    width: 100%;
    justify-content: center;
    gap: 5px;
    font-size: 0.74rem;
  }

  .hud span {
    min-width: 62px;
    padding: 6px 7px;
  }

  .hud .hp-panel {
    min-width: 108px;
  }

  .stage-wrap {
    width: min(100%, calc(52svh * 16 / 9));
  }

  .stage-select button {
    min-height: 34px;
  }

  canvas {
    max-height: none;
    touch-action: none;
  }

  .controls {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    margin-top: 0;
  }

  .move-pad,
  .system-pad,
  .action-pad {
    flex: 1;
    flex-wrap: wrap;
    justify-content: center;
  }

  .skill-pad {
    right: 7px;
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
  }

  .skill-pad button {
    width: 52px;
    height: 52px;
    border-width: 2px;
  }

  .skill-icon {
    font-size: 1.08rem;
  }

  .skill-label {
    max-width: 43px;
    font-size: 0.55rem;
  }

  .cooldown-text {
    min-width: 20px;
    font-size: 0.55rem;
  }

  .controls button {
    flex: 1 1 calc(33.333% - 8px);
    min-width: 0;
    min-height: 40px;
    padding: 6px 5px 6px 24px;
    font-size: 0.82rem;
  }

  .system-pad button {
    flex-basis: calc(50% - 8px);
  }

  .controls button::before {
    left: 6px;
    width: 14px;
    height: 13px;
  }

  .overlay {
    gap: 7px;
    padding: 10px;
  }

  .overlay img {
    width: min(76vw, 430px, 74%);
  }

  .overlay button {
    padding: 10px 16px 10px 40px;
    font-size: 0.92rem;
  }

  .intro-dialog {
    grid-template-columns: 58px minmax(0, 1fr);
    width: min(82vw, 560px);
    margin-right: 0;
    padding: 8px 12px 8px 8px;
  }

  .intro-avatar {
    width: 48px;
    height: 48px;
  }

  .intro-dialog p {
    font-size: 0.74rem;
    line-height: 1.38;
  }
}

@media (max-width: 520px) {
  .stage-select button {
    flex: 1 1 30%;
    padding: 7px 8px 7px 27px;
    font-size: 0.78rem;
  }

  .controls button {
    flex-basis: calc(50% - 8px);
    font-size: 0.78rem;
  }

  .move-pad button {
    flex-basis: calc(33.333% - 8px);
  }

  .skill-pad {
    right: 5px;
    gap: 4px;
  }

  .skill-pad button {
    width: 48px;
    height: 48px;
    padding: 3px;
  }

  .skill-label {
    max-width: 39px;
  }
}

@media (orientation: landscape) and (max-height: 620px) {
  body {
    overflow: hidden;
  }

  .game-shell {
    padding: 4px 8px;
  }

  .game-card {
    width: 100%;
    max-height: calc(100svh - 8px);
    grid-template-areas:
      "topbar stage"
      "controls stage";
    grid-template-columns: minmax(184px, 30vw) minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) auto;
    gap: 4px;
  }

  .topbar {
    grid-area: topbar;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
  }

  .title-art {
    order: 1;
    width: min(26vw, 210px);
  }

  .stage-select {
    order: 2;
    width: 100%;
    gap: 4px;
  }

  .stage-select button {
    flex: 1 1 100%;
    min-height: 30px;
    padding: 5px 8px 5px 25px;
    font-size: 0.72rem;
  }

  .hud {
    order: 3;
    justify-content: center;
    gap: 4px;
    font-size: 0.72rem;
  }

  .hud span {
    min-width: 58px;
    padding: 5px 6px;
  }

  .hud .hp-panel {
    min-width: 98px;
  }

  .stage-wrap {
    grid-area: stage;
    align-self: center;
    width: min(100%, calc((100svh - 8px) * 16 / 9));
  }

  .skill-pad {
    right: 7px;
    grid-template-columns: repeat(2, 1fr);
    gap: 5px;
  }

  .skill-pad button {
    width: clamp(44px, 10.5vh, 58px);
    height: clamp(44px, 10.5vh, 58px);
    padding: 3px;
  }

  .skill-icon {
    font-size: clamp(0.95rem, 3.6vh, 1.2rem);
  }

  .skill-label {
    max-width: 46px;
    font-size: 0.55rem;
  }

  .controls button {
    min-height: 34px;
    padding: 5px 10px 5px 28px;
    font-size: 0.78rem;
  }

  .controls {
    grid-area: controls;
  }

  .overlay {
    gap: 5px;
    padding: 8px 12px;
  }

  .overlay img {
    width: min(44vw, 320px, 68%);
  }

  .overlay button {
    padding: 8px 16px 8px 40px;
    font-size: 0.82rem;
  }

  .intro-dialog {
    grid-template-columns: 48px minmax(0, 1fr);
    width: min(78vw, 560px);
    margin-right: 0;
    padding: 7px 10px 7px 7px;
  }

  .intro-avatar {
    width: 40px;
    height: 40px;
    border-width: 2px;
  }

  .intro-dialog p {
    font-size: 0.66rem;
    line-height: 1.35;
  }
}

@media (orientation: portrait) and (max-width: 740px) {
  body {
    overflow: hidden;
  }

  .game-card {
    width: 100%;
    height: calc(100svh - 12px);
    height: calc(100dvh - 12px);
    max-height: none;
    grid-template-rows: auto minmax(0, 1fr) auto;
    align-content: stretch;
    gap: 5px;
  }

  .topbar {
    display: grid;
    grid-template-columns: 1fr;
    justify-items: center;
    gap: 4px;
  }

  .title-art {
    width: min(58vw, 270px);
  }

  .stage-select {
    order: 2;
    gap: 4px;
  }

  .hud {
    order: 3;
    gap: 4px;
  }

  .stage-wrap {
    width: 100%;
    height: 100%;
    min-height: 340px;
    aspect-ratio: auto;
    align-self: stretch;
  }

  .stage-wrap canvas {
    position: absolute;
    top: 0;
    left: 50%;
    width: auto;
    height: 100%;
    min-width: 100%;
    max-width: none;
    transform: translateX(calc(-50% + var(--mobile-pan, 0px)));
  }

  .controls {
    align-self: end;
    gap: 5px;
    margin-bottom: env(safe-area-inset-bottom);
  }

  .system-pad {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 5px;
  }

  .move-pad {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 5px;
  }
}

@media (max-height: 700px) and (orientation: portrait) {
  .title-art {
    width: min(50vw, 220px);
  }

  .stage-select button {
    min-height: 30px;
    padding-top: 5px;
    padding-bottom: 5px;
    font-size: 0.72rem;
  }

  .hud {
    font-size: 0.68rem;
  }

  .hud span {
    padding-top: 4px;
    padding-bottom: 4px;
  }

  .stage-wrap {
    width: 100%;
    min-height: 310px;
  }

  .controls button {
    min-height: 36px;
  }
}
