:root {
  color-scheme: dark;
  --panel: rgba(30, 22, 24, 0.9);
  --panel-strong: rgba(41, 27, 28, 0.96);
  --line: rgba(243, 199, 95, 0.42);
  --text: #f6f7fb;
  --muted: #d6c9a8;
  --gold: #f3c75f;
  --danger: #ff5f6d;
  --energy: #62d4ff;
  --green: #8fffe2;
  --lacquer: #6c1f2a;
  --jade: #6be0c8;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
}

body {
  min-height: 100vh;
  overflow: hidden;
  background: #17131b;
  color: var(--text);
  font-family: "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

button {
  font: inherit;
}

.app-shell {
  position: relative;
  width: 100vw;
  height: 100vh;
  background:
    linear-gradient(90deg, rgba(243, 199, 95, 0.07) 1px, transparent 1px),
    linear-gradient(0deg, rgba(243, 199, 95, 0.045) 1px, transparent 1px),
    linear-gradient(145deg, #15131a 0%, #352329 46%, #131820 100%);
  background-size: 46px 46px, 46px 46px, auto;
}

.game-shell {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  padding: clamp(8px, 1.4vw, 16px);
  gap: 8px;
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 0;
  border: 2px solid rgba(243, 199, 95, 0.35);
  border-radius: 8px;
  background: #171b26;
  box-shadow: 0 22px 80px rgba(0, 0, 0, 0.45), inset 0 0 0 1px rgba(255, 242, 180, 0.12);
  image-rendering: auto;
}

.top-hud,
.bottom-hud {
  z-index: 4;
  display: flex;
  align-items: center;
  gap: 12px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 239, 183, 0.12), rgba(83, 20, 27, 0.2)),
    linear-gradient(90deg, rgba(243, 199, 95, 0.12), transparent 18%, transparent 82%, rgba(243, 199, 95, 0.12)),
    var(--panel);
  backdrop-filter: blur(12px);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.32), inset 0 0 0 1px rgba(255,242,180,0.12);
}

.top-hud {
  min-height: 72px;
  padding: 10px 14px;
}

.bottom-hud {
  min-height: 58px;
  justify-content: space-between;
  padding: 9px 12px;
}

.portrait {
  width: 52px;
  height: 52px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border: 2px solid rgba(243, 199, 95, 0.75);
  border-radius: 50%;
  background: linear-gradient(180deg, #8e2b36, #25161b);
  color: #ffe9a6;
  font-size: 26px;
  font-weight: 800;
  box-shadow: inset 0 -8px 0 rgba(0, 0, 0, 0.2), 0 0 0 3px rgba(18, 10, 12, 0.75);
}

.bars {
  flex: 1 1 380px;
  min-width: 220px;
  display: grid;
  gap: 8px;
}

.bar-row {
  display: grid;
  grid-template-columns: 42px minmax(80px, 1fr) 78px;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.bar-row strong {
  color: var(--text);
  font-size: 12px;
  text-align: right;
}

.bar {
  height: 12px;
  overflow: hidden;
  border: 1px solid rgba(243, 199, 95, 0.38);
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.08);
}

.bar i {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #e43f51, #ff9c55);
}

.bar.energy i {
  background: linear-gradient(90deg, #45b6ff, #8fffe2);
}

.stage-info,
.loot-info {
  flex: 0 0 auto;
  min-width: 130px;
  display: grid;
  gap: 4px;
  padding-left: 12px;
  border-left: 1px solid rgba(243, 199, 95, 0.35);
}

.stage-info strong {
  font-size: 16px;
}

.stage-info span,
.loot-info span {
  color: var(--muted);
  font-size: 12px;
}

.loot-info {
  min-width: 116px;
}

.loot-info b {
  color: var(--gold);
}

.audio-btn {
  flex: 0 0 auto;
  min-width: 76px;
  min-height: 38px;
  border: 1px solid rgba(243, 199, 95, 0.42);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(151, 51, 56, 0.9), rgba(41, 20, 24, 0.9));
  color: #ffe9a6;
  cursor: pointer;
}

.audio-btn[aria-pressed="false"] {
  color: #9da6bd;
  background: rgba(255, 255, 255, 0.045);
}

.boss-hud {
  z-index: 5;
  display: grid;
  grid-template-columns: minmax(120px, auto) minmax(160px, 1fr) 92px;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  padding: 8px 12px;
  border: 2px solid rgba(255, 95, 109, 0.48);
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(123, 29, 37, 0.82), rgba(18, 13, 18, 0.9)),
    rgba(10, 12, 18, 0.9);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.32);
}

.boss-hud.hidden {
  visibility: hidden;
}

.boss-hud span {
  color: #ffe3ae;
  font-size: 14px;
  font-weight: 800;
  white-space: nowrap;
}

.boss-hud b {
  color: #fff;
  font-size: 12px;
  text-align: right;
}

.boss-bar {
  height: 12px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.16);
  border-radius: 99px;
  background: rgba(0,0,0,0.34);
}

.boss-bar i {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #ff4056, #f3c75f);
}

#objectiveText {
  min-width: 180px;
  color: #d8deef;
  font-size: 14px;
}

.skill-strip {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.skill-chip {
  min-width: 72px;
  padding: 6px 8px;
  border: 1px solid rgba(243, 199, 95, 0.36);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(91, 39, 44, 0.86), rgba(26, 18, 22, 0.84));
  color: #f8e7b0;
  font-size: 12px;
  text-align: center;
  box-shadow: inset 0 -4px 0 rgba(0,0,0,0.16);
}

.skill-chip.ready {
  border-color: rgba(126, 255, 216, 0.52);
  color: #bfffe9;
}

.skill-chip.locked {
  opacity: 0.55;
}

.select-screen {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background:
    linear-gradient(180deg, rgba(9, 11, 17, 0.58), rgba(9, 11, 17, 0.78)),
    linear-gradient(135deg, rgba(116, 28, 39, 0.58), rgba(17, 22, 29, 0.82));
}

.select-screen.hidden {
  display: none;
}

.story-panel {
  width: min(1060px, 100%);
  max-height: calc(100vh - 40px);
  overflow: auto;
  border: 2px solid rgba(243, 199, 95, 0.45);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 239, 183, 0.08), rgba(0, 0, 0, 0.04)),
    var(--panel-strong);
  padding: clamp(18px, 3vw, 34px);
  box-shadow: 0 28px 90px rgba(0, 0, 0, 0.48);
}

.eyebrow {
  margin: 0 0 8px;
  color: #8fffe2;
  font-size: 13px;
  letter-spacing: 0;
}

h1 {
  margin: 0;
  font-size: clamp(34px, 7vh, 70px);
  line-height: 0.98;
  letter-spacing: 0;
}

.story-text {
  max-width: 760px;
  margin: 14px 0 22px;
  color: #cbd3e8;
  font-size: 16px;
  line-height: 1.7;
}

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

.hero-card {
  position: relative;
  min-height: 270px;
  display: grid;
  grid-template-rows: 126px auto;
  gap: 12px;
  padding: 14px;
  border: 2px solid rgba(243, 199, 95, 0.28);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 239, 183, 0.08), rgba(74, 23, 31, 0.22)),
    rgba(21, 17, 22, 0.78);
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.hero-card.selected {
  border-color: rgba(143, 255, 226, 0.78);
  background:
    linear-gradient(180deg, rgba(143, 255, 226, 0.14), rgba(151, 51, 56, 0.2)),
    rgba(24, 22, 27, 0.82);
  box-shadow: inset 0 0 0 1px rgba(143, 255, 226, 0.24), 0 0 0 2px rgba(243, 199, 95, 0.18);
}

.hero-card canvas {
  width: 100%;
  height: 126px;
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(243, 199, 95, 0.13), rgba(107, 31, 42, 0.18)),
    rgba(8, 10, 17, 0.42);
}

.hero-card h2 {
  margin: 0 0 6px;
  font-size: 22px;
}

.hero-card p {
  margin: 0 0 10px;
  color: #c9d1e6;
  font-size: 13px;
  line-height: 1.55;
}

.stat-line {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  color: #f4d484;
  font-size: 12px;
}

.primary-btn {
  margin-top: 18px;
  min-height: 46px;
  min-width: 168px;
  border: 0;
  border-radius: 8px;
  background: linear-gradient(135deg, #ffe08a, #d8454e 58%, #6be0c8);
  color: #1f1308;
  font-weight: 800;
  cursor: pointer;
}

.primary-btn:focus-visible,
.hero-card:focus-visible {
  outline: 3px solid rgba(143, 255, 226, 0.9);
  outline-offset: 2px;
}

.center-message {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 8;
  transform: translate(-50%, -50%);
  max-width: min(620px, calc(100vw - 40px));
  padding: 16px 20px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background: rgba(11, 14, 22, 0.86);
  color: #fff;
  font-size: clamp(18px, 3.4vw, 34px);
  font-weight: 800;
  text-align: center;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.45);
}

.center-message.hidden {
  display: none;
}

.mobile-controls {
  display: none;
}

.touch-btn {
  min-width: 46px;
  min-height: 46px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.16), rgba(255,255,255,0.04)),
    rgba(14, 17, 27, 0.84);
  color: #f7f8ff;
  font-weight: 900;
  box-shadow: 0 8px 16px rgba(0,0,0,0.28), inset 0 -5px 0 rgba(0,0,0,0.2);
  touch-action: none;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 1px;
  line-height: 1;
  overflow: hidden;
}

.touch-btn:active,
.touch-btn.active {
  transform: translateY(2px);
  border-color: rgba(143, 255, 226, 0.72);
  color: var(--green);
  box-shadow: 0 4px 10px rgba(0,0,0,0.26), inset 0 -2px 0 rgba(0,0,0,0.2);
}

.touch-btn b,
.touch-btn span {
  display: block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  pointer-events: none;
}

.touch-btn b {
  font-size: 18px;
}

.touch-btn span {
  font-size: 9px;
  opacity: 0.86;
}

.touch-btn.cooling,
.touch-btn.locked {
  opacity: 0.62;
}

.touch-dpad {
  position: relative;
  width: 186px;
  height: 186px;
  pointer-events: auto;
  touch-action: none;
}

.joystick-ring {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 220px;
  height: 220px;
  border: 0;
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 50%, rgba(143, 255, 226, 0.24) 0 19%, transparent 20%),
    radial-gradient(circle at 50% 50%, rgba(255, 255, 255, 0.12), rgba(14, 17, 27, 0.72) 62%, rgba(14, 17, 27, 0.88));
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.34), inset 0 0 24px rgba(143, 255, 226, 0.12);
  opacity: 0.18;
  pointer-events: none;
  transform: translate(-50%, -50%);
  transition: opacity 0.08s ease-out, box-shadow 0.08s ease-out;
}

.joystick-ring::before,
.joystick-ring::after {
  content: "";
  position: absolute;
  background: rgba(255, 255, 255, 0.16);
  border-radius: 99px;
}

.joystick-ring::before {
  left: 18px;
  right: 18px;
  top: calc(50% - 1px);
  height: 2px;
}

.joystick-ring::after {
  top: 18px;
  bottom: 18px;
  left: calc(50% - 1px);
  width: 2px;
}

.joystick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 68px;
  height: 68px;
  border: 0;
  border-radius: 50%;
  background:
    radial-gradient(circle at 38% 30%, rgba(255, 255, 255, 0.38), transparent 34%),
    linear-gradient(180deg, rgba(143, 255, 226, 0.56), rgba(69, 182, 255, 0.34)),
    rgba(14, 17, 27, 0.92);
  box-shadow: 0 12px 18px rgba(0, 0, 0, 0.28), inset 0 -8px 0 rgba(0, 0, 0, 0.2);
  transform: translate(-50%, -50%);
  transition: transform 0.04s ease-out, box-shadow 0.08s ease-out;
}

.touch-joystick.active .joystick-ring {
  opacity: 0.72;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.34), inset 0 0 30px rgba(143, 255, 226, 0.2);
}

.touch-joystick.active .joystick-knob {
  box-shadow: 0 12px 18px rgba(0, 0, 0, 0.3), inset 0 -8px 0 rgba(0, 0, 0, 0.22), 0 0 18px rgba(143, 255, 226, 0.18);
}

.touch-dpad .touch-btn {
  position: absolute;
}

.touch-actions {
  display: grid;
  grid-template-columns: repeat(4, 48px);
  grid-auto-rows: 48px;
  gap: 8px;
  align-items: center;
}

.touch-actions .normal {
  grid-column: 3;
  grid-row: 1 / span 2;
  min-width: 62px;
  min-height: 104px;
  background:
    linear-gradient(180deg, rgba(255, 196, 86, 0.28), rgba(255,255,255,0.04)),
    rgba(14, 17, 27, 0.88);
  color: #ffe3ae;
}

.touch-actions .ult {
  background:
    linear-gradient(180deg, rgba(255, 95, 109, 0.38), rgba(255,255,255,0.04)),
    rgba(14, 17, 27, 0.88);
  color: #ffd6dc;
}

.touch-actions .air,
.touch-actions .jump {
  color: #bfffe9;
}

@media (max-width: 900px) {
  body {
    overflow: hidden;
  }

  .app-shell {
    min-height: 100dvh;
    height: 100dvh;
  }

  .game-shell {
    position: absolute;
    min-height: 100dvh;
    display: block;
    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));
  }

  #gameCanvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: 0;
    border-radius: 0;
  }

  .top-hud {
    position: absolute;
    left: max(8px, env(safe-area-inset-left));
    right: max(8px, env(safe-area-inset-right));
    top: max(8px, env(safe-area-inset-top));
    min-height: 54px;
    padding: 6px 8px;
    gap: 8px;
    align-items: center;
  }

  .portrait {
    width: 42px;
    height: 42px;
    font-size: 20px;
  }

  .bars {
    min-width: 120px;
    gap: 5px;
  }

  .bar-row {
    grid-template-columns: 34px minmax(70px, 1fr) 58px;
    gap: 5px;
    font-size: 11px;
  }

  .bar-row strong {
    font-size: 10px;
  }

  .stage-info,
  .loot-info {
    min-width: auto;
    padding-left: 8px;
  }

  .stage-info strong {
    font-size: 13px;
  }

  .stage-info span,
  .loot-info span {
    font-size: 10px;
  }

  .audio-btn {
    min-width: 54px;
    min-height: 34px;
    font-size: 12px;
  }

  .boss-hud {
    position: absolute;
    left: max(12px, env(safe-area-inset-left));
    right: max(12px, env(safe-area-inset-right));
    top: calc(max(8px, env(safe-area-inset-top)) + 62px);
    grid-template-columns: 92px minmax(80px, 1fr) 64px;
    min-height: 34px;
    padding: 6px 8px;
  }

  .boss-hud span {
    font-size: 12px;
  }

  .boss-hud b {
    font-size: 10px;
  }

  .bottom-hud {
    position: absolute;
    left: auto;
    right: max(10px, env(safe-area-inset-right));
    bottom: calc(max(8px, env(safe-area-inset-bottom)) + 118px);
    width: min(320px, 48vw);
    min-height: 0;
    padding: 0;
    gap: 4px;
    flex-direction: column;
    align-items: flex-end;
    border: 0;
    background: transparent;
    box-shadow: none;
    pointer-events: none;
  }

  #objectiveText {
    min-width: 0;
    max-width: 100%;
    padding: 4px 8px;
    border: 1px solid rgba(243, 199, 95, 0.28);
    border-radius: 8px;
    background: rgba(14, 17, 27, 0.74);
    flex: 1 1 auto;
    font-size: 12px;
    text-align: right;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .roster {
    grid-template-columns: 1fr;
  }

  .skill-strip {
    justify-content: flex-end;
    gap: 4px;
    max-width: 100%;
  }

  .skill-chip {
    min-width: 0;
    max-width: 76px;
    padding: 3px 5px;
    font-size: 9px;
    line-height: 1.1;
    opacity: 0.9;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-controls {
    position: absolute;
    left: max(10px, env(safe-area-inset-left));
    right: max(10px, env(safe-area-inset-right));
    bottom: max(8px, env(safe-area-inset-bottom));
    z-index: 7;
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    pointer-events: none;
  }

  .mobile-controls .touch-btn {
    pointer-events: auto;
  }

  .touch-dpad {
    position: absolute;
    left: 18px;
    bottom: 18px;
    width: 250px;
    height: 250px;
    transform: none;
  }

  .joystick-ring {
    width: 220px;
    height: 220px;
  }

  .touch-btn {
    min-width: 50px;
    min-height: 50px;
  }

  .joystick-knob {
    width: 72px;
    height: 72px;
  }

  .touch-joystick.active .joystick-knob {
    transition: none;
  }

  .touch-actions {
    position: absolute;
    right: 0;
    bottom: 0;
    grid-template-columns: repeat(4, 50px);
    grid-auto-rows: 50px;
    gap: 8px;
    z-index: 2;
  }

  .touch-actions .normal {
    min-width: 64px;
    min-height: 108px;
  }

  .story-panel {
    max-height: calc(100dvh - 24px);
  }
}

@media (max-width: 900px) and (max-height: 520px) and (orientation: landscape) {
  .select-screen {
    padding: 8px;
    place-items: stretch;
  }

  .story-panel {
    width: 100%;
    max-height: calc(100dvh - 16px);
    padding: 10px;
  }

  .eyebrow,
  .story-text {
    display: none;
  }

  h1 {
    font-size: 30px;
    margin-bottom: 8px;
  }

  .roster {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
  }

  .hero-card {
    min-height: 192px;
    grid-template-rows: 82px auto;
    gap: 6px;
    padding: 8px;
  }

  .hero-card canvas {
    height: 82px;
  }

  .hero-card h2 {
    font-size: 17px;
    margin-bottom: 2px;
  }

  .hero-card p {
    margin-bottom: 4px;
    font-size: 11px;
    line-height: 1.35;
  }

  .stat-line {
    font-size: 10px;
  }

  .primary-btn {
    position: sticky;
    bottom: 0;
    margin-top: 8px;
    min-height: 38px;
    width: 100%;
  }
}

@media (max-width: 900px) and (orientation: portrait) {
  body {
    background: #0f1118;
  }

  .app-shell {
    position: fixed;
    left: 50%;
    top: 50%;
    width: 100dvh;
    height: 100dvw;
    min-height: 0;
    transform: translate(-50%, -50%) rotate(90deg);
    transform-origin: center center;
  }

  .game-shell {
    min-height: 100dvw;
    height: 100dvw;
    padding: max(4px, env(safe-area-inset-left)) max(4px, env(safe-area-inset-top)) max(4px, env(safe-area-inset-right)) max(4px, env(safe-area-inset-bottom));
  }

  .select-screen {
    padding: 8px;
    place-items: stretch;
  }

  .story-panel {
    width: 100%;
    max-height: calc(100dvw - 16px);
    padding: 8px;
  }

  .eyebrow,
  .story-text {
    display: none;
  }

  h1 {
    font-size: 26px;
    margin-bottom: 6px;
  }

  .roster {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .hero-card {
    min-height: 112px;
    grid-template-columns: 84px minmax(0, 1fr);
    grid-template-rows: auto;
    gap: 6px;
    padding: 6px;
  }

  .hero-card canvas {
    height: 78px;
  }

  .hero-card h2 {
    font-size: 15px;
    margin-bottom: 2px;
  }

  .hero-card p {
    margin-bottom: 3px;
    font-size: 10px;
    line-height: 1.25;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  .stat-line {
    font-size: 9px;
    gap: 4px;
  }

  .primary-btn {
    position: sticky;
    bottom: 0;
    margin-top: 8px;
    min-height: 38px;
    width: 100%;
  }

  .top-hud {
    left: max(8px, env(safe-area-inset-bottom));
    right: max(8px, env(safe-area-inset-top));
    top: max(8px, env(safe-area-inset-left));
  }

  .boss-hud {
    left: max(12px, env(safe-area-inset-bottom));
    right: max(12px, env(safe-area-inset-top));
    top: calc(max(8px, env(safe-area-inset-left)) + 62px);
  }

  .bottom-hud {
    left: auto;
    right: max(10px, env(safe-area-inset-top));
    bottom: calc(max(8px, env(safe-area-inset-right)) + 118px);
  }

  .mobile-controls {
    left: max(10px, env(safe-area-inset-bottom));
    right: max(10px, env(safe-area-inset-top));
    bottom: max(8px, env(safe-area-inset-right));
  }

}
