html, body {
  margin: 0;
  height: 100%;
  background: #07040f;
  overflow: hidden;
  overscroll-behavior: none;
}
body {
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-family: "Microsoft YaHei", "PingFang SC", "Noto Sans SC", sans-serif;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
button { -webkit-tap-highlight-color: transparent; }

/* ======================================================================
   桌面端：16:9 画面，界面叠加在画面上
   ====================================================================== */
#app {
  position: relative;
  width: min(100vw, calc(100vh * 16 / 9));
  aspect-ratio: 16 / 9;
  container-type: inline-size;
}
#stage {
  position: absolute;
  inset: 0;
  container-type: inline-size;
}
canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  touch-action: none;
}

.tip-touch { display: none; }
body.touch .tip-touch { display: inline; }
body.touch .tip-desk { display: none; }

/* ---------- HUD ---------- */
#hud {
  position: absolute;
  inset: 1.2cqw 1.2cqw auto 1.2cqw;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  pointer-events: none;
  transition: opacity .3s, transform .3s;
}
.panel {
  background: rgba(14, 8, 30, .78);
  border: .22cqw solid #6a4ab8;
  box-shadow: 0 0 0 .22cqw #140a24, .3cqw .3cqw 0 .22cqw rgba(0,0,0,.6);
  padding: .7cqw 1cqw;
  font-size: 1.05cqw;
  pointer-events: auto;
  box-sizing: border-box;
}
.panel.left, .panel.right { width: 24cqw; }
.panel .title {
  font-weight: 900;
  font-size: 1.35cqw;
  display: flex;
  justify-content: space-between;
  gap: .6em;
  letter-spacing: .1cqw;
  text-shadow: .15cqw .15cqw 0 #000;
}
.panel .label, .panel .stat { color: #c8b8f0; margin-top: .3cqw; font-size: .95cqw; }
.panel.right { border-color: #c8282a; text-align: right; }
#vName { color: #ffd0a0; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#koCount { color: #ffd24a; white-space: nowrap; }

.bar {
  position: relative;
  height: 1.1cqw;
  margin-top: .35cqw;
  background: #1a1024;
  border: .18cqw solid #000;
  overflow: hidden;
}
.bar > div { position: absolute; left: 0; top: 0; bottom: 0; }
#energyFill {
  width: 0;
  background: repeating-linear-gradient(90deg, #7a5aff 0 6px, #9a7aff 6px 12px);
}
#hpGhost { width: 100%; background: #fff2b0; }
#hpFill {
  width: 100%;
  background: repeating-linear-gradient(90deg, #e83a3a 0 6px, #ff5a4a 6px 12px);
}
#ultHint {
  margin-top: .35cqw;
  color: #ffd24a;
  font-weight: 900;
  visibility: hidden;
  animation: blink .5s steps(2) infinite;
}
body.ready #ultHint { visibility: visible; }
body.ready #energyFill {
  background: repeating-linear-gradient(90deg, #ffd24a 0 6px, #fff3a0 6px 12px);
  animation: glow .4s infinite alternate;
}
@keyframes blink { 50% { opacity: .35; } }
@keyframes glow { to { filter: brightness(1.5); } }

.panel.center {
  display: flex;
  align-items: center;
  gap: .6cqw;
}
.panel.center label { color: #c8b8f0; white-space: nowrap; }
#nameInput {
  width: 10cqw;
  min-width: 0;
  font: inherit;
  font-weight: 700;
  color: #ffe9a8;
  background: #1a0e10;
  border: .18cqw solid #c8282a;
  border-radius: 0;
  padding: .25cqw .5cqw;
  outline: none;
}
#nameInput:focus { border-color: #ffd24a; }
#muteBtn {
  font-size: 1.1cqw;
  background: #1a1024;
  border: .18cqw solid #6a4ab8;
  color: #fff;
  cursor: pointer;
  padding: .15cqw .45cqw;
}

/* ---------- 连击 ---------- */
#combo {
  position: absolute;
  right: 3cqw;
  top: 12cqw;
  text-align: right;
  font-weight: 900;
  font-style: italic;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
}
#combo.show { opacity: 1; }
#comboNum {
  display: block;
  font-size: 4.2cqw;
  line-height: 1;
  color: #ffd24a;
  -webkit-text-stroke: .2cqw #3a0a0a;
  text-shadow: .3cqw .3cqw 0 #000, 0 0 1.2cqw #ff6a2a;
}
#combo small {
  font-size: 1.5cqw;
  color: #fff;
  -webkit-text-stroke: .1cqw #000;
  text-shadow: .2cqw .2cqw 0 #000;
}
#combo.pop #comboNum { animation: pop .16s ease-out; }
@keyframes pop { from { transform: scale(1.5); filter: brightness(2); } to { transform: scale(1); } }

/* ---------- 技能栏 ---------- */
#skillbar {
  position: absolute;
  left: 50%;
  bottom: 1.6cqw;
  transform: translateX(-50%);
  display: flex;
  gap: .7cqw;
  transition: opacity .3s, transform .3s;
}
.group { display: flex; gap: .7cqw; }
.skill {
  position: relative;
  overflow: hidden;
  min-width: 7.4cqw;
  padding: .45cqw .8cqw .5cqw;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .15cqw;
  font: inherit;
  font-size: 1cqw;
  color: #fff;
  background: rgba(18, 10, 36, .85);
  border: .22cqw solid var(--c);
  border-radius: 0;
  box-shadow: inset 0 0 .9cqw color-mix(in srgb, var(--c) 45%, transparent), .25cqw .25cqw 0 #000;
  cursor: pointer;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}
.skill b {
  position: relative;
  font-size: 1.5cqw;
  color: var(--c);
  text-shadow: 0 0 .6cqw var(--c), .12cqw .12cqw 0 #000;
}
.skill span { position: relative; text-shadow: .12cqw .12cqw 0 #000; white-space: nowrap; }
.skill.hit { animation: press .14s ease-out; }
.skill.held { background: color-mix(in srgb, var(--c) 30%, rgba(18, 10, 36, .85)); }
@keyframes press {
  from { transform: translateY(3px) scale(.92); filter: brightness(2); }
  to { transform: none; }
}
.ultFill {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 0;
  background: linear-gradient(0deg, color-mix(in srgb, var(--c) 70%, transparent), color-mix(in srgb, var(--c) 25%, transparent));
}
body.ready .skill.ult { animation: ultReady .5s infinite alternate; }
@keyframes ultReady {
  to { box-shadow: inset 0 0 18px var(--c), 0 0 16px var(--c), 3px 3px 0 #000; }
}

#tip {
  position: absolute;
  right: 1.4cqw;
  bottom: .4cqw;
  font-size: .8cqw;
  color: rgba(220, 200, 255, .55);
  pointer-events: none;
}

/* 大招演出时隐藏界面 */
body.cinema #hud { opacity: 0; transform: translateY(-2cqw); }
body.cinema #skillbar { opacity: 0; transform: translate(-50%, 2cqw); pointer-events: none; }
body.cinema #tip, body.cinema #combo { opacity: 0; }

/* ======================================================================
   竖屏（手机竖握 / 窄窗口）：上 HUD，中画面，下按钮
   ====================================================================== */
@media (orientation: portrait), (max-aspect-ratio: 1/1) {
  body { align-items: stretch; }
  #app {
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    aspect-ratio: auto;
    display: flex;
    flex-direction: column;
    gap: 2.5vw;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
    box-sizing: border-box;
  }
  #stage {
    position: relative;
    inset: auto;
    order: 2;
    flex: none;
    width: 100%;
    aspect-ratio: 16 / 9;
  }
  #hud {
    position: static;
    order: 1;
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-areas: "name name" "p v";
    gap: 2.5vw;
    padding: 2.5vw 2.5vw 0;
  }
  .panel {
    font-size: 3.2vw;
    padding: 2vw 2.6vw;
    border-width: 2px;
    box-shadow: 0 0 0 2px #140a24, 3px 3px 0 2px rgba(0,0,0,.6);
  }
  .panel.left { grid-area: p; width: auto; }
  .panel.right { grid-area: v; width: auto; }
  .panel.center { grid-area: name; justify-content: center; gap: 2vw; }
  .panel .title { font-size: 3.9vw; letter-spacing: 0; text-shadow: 1px 1px 0 #000; }
  .panel .label, .panel .stat { font-size: 2.9vw; margin-top: 1vw; }
  .bar { height: 3.2vw; margin-top: 1.2vw; border-width: 2px; }
  #ultHint { font-size: 3vw; margin-top: 1vw; }
  #nameInput { width: 34vw; border-width: 2px; padding: 1vw 2vw; font-size: 16px; }
  #muteBtn { font-size: 4.4vw; border-width: 2px; padding: .6vw 2vw; }

  #skillbar {
    position: static;
    order: 3;
    flex: 1;
    min-height: 0;
    transform: none;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 3.5vw;
    padding: 0 3.5vw 3vw;
  }
  .group { display: grid; grid-template-columns: repeat(3, 1fr); gap: 2.8vw; }
  .skill {
    min-width: 0;
    min-height: 15vw;
    padding: 2.2vw 1vw;
    gap: 1vw;
    font-size: 3.6vw;
    border-width: 3px;
    box-shadow: inset 0 0 10px color-mix(in srgb, var(--c) 45%, transparent), 3px 3px 0 #000;
  }
  .skill b { font-size: 4.2vw; text-shadow: 0 0 6px var(--c), 1px 1px 0 #000; }
  .skill span { font-size: 4vw; font-weight: 700; }
  .skill.ult { min-height: 17vw; }

  #combo { right: 3vw; top: 3vw; }
  #comboNum { font-size: 9vw; -webkit-text-stroke: 1px #3a0a0a; text-shadow: 2px 2px 0 #000, 0 0 8px #ff6a2a; }
  #combo small { font-size: 3.4vw; -webkit-text-stroke: 0; }
  #tip { font-size: 2.6vw; right: 2vw; bottom: 1vw; }

  body.cinema #hud { transform: none; }
  body.cinema #skillbar { transform: none; }
}

/* ======================================================================
   横屏触屏（手机 / 平板横握）：左侧奥义，中间画面，右侧技能
   ====================================================================== */
@media (pointer: coarse) and (orientation: landscape) and (min-aspect-ratio: 1/1) {
  #app {
    --side: clamp(104px, 16vw, 200px);
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    aspect-ratio: auto;
    display: grid;
    grid-template-columns: var(--side) 1fr var(--side);
    grid-template-rows: auto auto 1fr;
    grid-template-areas:
      "name stage v"
      "p    stage skills"
      "ults stage skills";
    column-gap: 8px;
    row-gap: 6px;
    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));
    box-sizing: border-box;
  }
  #hud, #skillbar { display: contents; }
  #stage {
    position: relative;
    inset: auto;
    grid-area: stage;
    align-self: center;
    justify-self: center;
    width: min(100%, calc((100dvh - 12px) * 16 / 9));
    aspect-ratio: 16 / 9;
  }
  .panel {
    font-size: clamp(10px, 3vh, 14px);
    padding: 5px 7px;
    border-width: 2px;
    box-shadow: 0 0 0 2px #140a24, 2px 2px 0 2px rgba(0,0,0,.6);
    transition: opacity .3s;
  }
  .panel.left { grid-area: p; width: auto; }
  .panel.right { grid-area: v; width: auto; }
  .panel.center { grid-area: name; gap: 5px; }
  .panel.center label { display: none; }
  .panel .title { font-size: clamp(11px, 3.4vh, 16px); letter-spacing: 0; text-shadow: 1px 1px 0 #000; }
  .panel .label { display: none; }
  .panel .stat { font-size: clamp(9px, 2.7vh, 12px); margin-top: 3px; }
  .bar { height: clamp(7px, 2.4vh, 12px); margin-top: 4px; border-width: 2px; }
  #ultHint { font-size: clamp(9px, 2.7vh, 12px); margin-top: 3px; }
  #nameInput { flex: 1; width: auto; border-width: 2px; padding: 3px 5px; font-size: 16px; }
  #muteBtn { font-size: 16px; border-width: 2px; padding: 2px 5px; }

  .group { display: grid; gap: 6px; align-self: end; }
  .group.ults { grid-area: ults; grid-template-columns: 1fr; }
  .group.skills { grid-area: skills; grid-template-columns: 1fr 1fr; }
  .skill {
    min-width: 0;
    min-height: clamp(40px, 13vh, 72px);
    padding: 4px 2px;
    gap: 2px;
    font-size: clamp(10px, 3vh, 14px);
    border-width: 2px;
    box-shadow: inset 0 0 8px color-mix(in srgb, var(--c) 45%, transparent), 2px 2px 0 #000;
  }
  .skill b { font-size: clamp(10px, 3.2vh, 15px); text-shadow: 0 0 5px var(--c), 1px 1px 0 #000; }
  .skill span { font-weight: 700; }
  .group.skills .skill { min-height: clamp(44px, 17vh, 90px); }

  #combo { right: 2.5cqw; top: 3cqw; }
  #comboNum { font-size: 6cqw; -webkit-text-stroke: 1px #3a0a0a; text-shadow: 2px 2px 0 #000, 0 0 8px #ff6a2a; }
  #combo small { font-size: 2.2cqw; -webkit-text-stroke: 0; }
  #tip { font-size: 10px; }

  body.cinema #hud .panel { opacity: 0; }
  body.cinema .group { opacity: 0; pointer-events: none; transition: opacity .3s; }
  body.cinema #hud { transform: none; }
}
