:root {
  color-scheme: dark;
  --panel: rgba(13, 12, 22, 0.78);
  --panel-strong: rgba(18, 14, 30, 0.94);
  --line: rgba(255, 255, 255, 0.16);
  --text: #f7f0ff;
  --muted: #b9abc9;
  --health: #f25f6b;
  --xp: #35d5c8;
  --boss: #a85cff;
  --gold: #ffd36b;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #09070f;
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "PingFang SC", "Microsoft YaHei", sans-serif;
}

button {
  font: inherit;
}

#game-shell {
  position: relative;
  width: 100vw;
  width: 100dvw;
  height: 100vh;
  height: 100svh;
  height: 100dvh;
  min-width: 320px;
  min-height: 480px;
  overflow: hidden;
  background: #09070f;
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.hud {
  position: absolute;
  z-index: 5;
  pointer-events: none;
}

.hud-top {
  top: 14px;
  left: 14px;
  right: 14px;
  display: grid;
  grid-template-columns: minmax(112px, 0.68fr) minmax(145px, 1fr) minmax(145px, 1fr) minmax(90px, 0.48fr) minmax(120px, 0.62fr);
  gap: 10px;
  align-items: center;
}

.brand,
.meter-group,
.stat-pill,
.boss-hud,
.character-box,
.level-up-box,
.result-box {
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.36);
  backdrop-filter: blur(12px);
}

.brand,
.meter-group,
.stat-pill {
  min-height: 50px;
  border-radius: 8px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 13px;
  font-weight: 800;
  white-space: nowrap;
}

.brand-mark {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 45% 45%, #fff 0 12%, transparent 13%),
    conic-gradient(from 20deg, #35d5c8, #a85cff, #ff5e88, #ffd36b, #35d5c8);
  box-shadow: 0 0 18px rgba(168, 92, 255, 0.9);
  flex: 0 0 auto;
}

.meter-group {
  padding: 8px 10px 10px;
  min-width: 0;
}

.meter-label,
.boss-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 12px;
  line-height: 1.2;
  color: var(--muted);
}

.meter-label span:last-child,
.boss-row strong {
  color: var(--text);
  font-weight: 750;
  white-space: nowrap;
}

.meter {
  width: 100%;
  height: 10px;
  margin-top: 8px;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.09);
}

.meter-fill {
  display: block;
  width: 100%;
  height: 100%;
  transform-origin: left center;
  transition: transform 120ms linear;
}

.health-fill {
  background: linear-gradient(90deg, #ff4768, var(--health), #ffb069);
}

.xp-fill {
  background: linear-gradient(90deg, #2bf2dc, var(--xp), #8bffd8);
}

.boss-fill {
  background: linear-gradient(90deg, #702cff, var(--boss), #ff5eaa);
  box-shadow: 0 0 18px rgba(168, 92, 255, 0.55);
}

.stat-pill {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  padding: 0 12px;
  text-align: center;
  color: var(--muted);
  font-size: 11px;
}

.stat-pill strong {
  color: var(--gold);
  font-size: 19px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.ultimate-pill strong {
  color: #8c849a;
  font-size: 16px;
}

.ultimate-pill.ready {
  border-color: rgba(255, 211, 107, 0.5);
  background:
    linear-gradient(135deg, rgba(255, 211, 107, 0.15), rgba(168, 92, 255, 0.13)),
    var(--panel);
}

.ultimate-pill.ready strong {
  color: #ffe494;
  text-shadow: 0 0 14px rgba(255, 211, 107, 0.55);
}

.boss-hud {
  left: 50%;
  bottom: 18px;
  width: min(720px, calc(100vw - 28px));
  transform: translateX(-50%);
  border-radius: 8px;
  padding: 10px 12px 12px;
}

.boss-meter {
  height: 13px;
}

.stage-banner {
  position: absolute;
  z-index: 6;
  top: 86px;
  left: 50%;
  width: min(680px, calc(100vw - 32px));
  transform: translate(-50%, -10px);
  opacity: 0;
  border: 1px solid rgba(255, 211, 107, 0.32);
  border-radius: 8px;
  padding: 11px 16px;
  background: rgba(24, 15, 34, 0.78);
  box-shadow: 0 18px 42px rgba(0, 0, 0, 0.36);
  color: #fff7d8;
  text-align: center;
  font-weight: 800;
  pointer-events: none;
  transition:
    opacity 180ms ease,
    transform 180ms ease;
}

.stage-banner.visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background:
    radial-gradient(circle at center, rgba(168, 92, 255, 0.16), transparent 42%),
    rgba(4, 3, 8, 0.66);
  backdrop-filter: blur(4px);
}

.start-video {
  position: absolute;
  inset: 0;
  z-index: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0.78;
  filter: saturate(1.1) contrast(1.06);
  pointer-events: none;
}

.start-video.is-stopped {
  display: none;
}

#start-panel::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  background:
    linear-gradient(180deg, rgba(4, 3, 8, 0.24), rgba(4, 3, 8, 0.74)),
    radial-gradient(circle at center, rgba(168, 92, 255, 0.18), transparent 48%);
  pointer-events: none;
}

#start-panel .result-box {
  position: relative;
  z-index: 2;
}

.hidden {
  display: none;
}

.mobile-controls {
  position: fixed;
  inset: 0;
  z-index: 12;
  display: block;
  visibility: hidden;
  pointer-events: none;
  opacity: 0;
  transition: opacity 120ms ease;
}

.mobile-controls.active {
  visibility: visible;
  opacity: 1;
}

.move-joystick,
.ultimate-touch-button {
  position: absolute;
  pointer-events: auto;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.move-joystick {
  left: max(14px, env(safe-area-inset-left));
  bottom: max(14px, env(safe-area-inset-bottom));
  width: clamp(96px, 28svh, 126px);
  height: clamp(96px, 28svh, 126px);
  border: 1px solid rgba(159, 255, 244, 0.24);
  border-radius: 50%;
  background:
    radial-gradient(circle at center, rgba(53, 213, 200, 0.16), rgba(16, 14, 24, 0.66) 58%, rgba(16, 14, 24, 0.38));
  box-shadow: 0 16px 34px rgba(0, 0, 0, 0.34);
  backdrop-filter: blur(8px);
}

.joystick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: clamp(42px, 13svh, 58px);
  height: clamp(42px, 13svh, 58px);
  border: 1px solid rgba(255, 255, 255, 0.34);
  border-radius: 50%;
  background:
    radial-gradient(circle at 38% 32%, rgba(255, 255, 255, 0.78), rgba(126, 235, 255, 0.34) 25%, rgba(74, 167, 255, 0.62) 68%),
    rgba(12, 22, 32, 0.92);
  box-shadow: 0 0 20px rgba(126, 235, 255, 0.38);
  transform: translate3d(-50%, -50%, 0);
  will-change: transform;
}

.ultimate-touch-button {
  right: max(16px, env(safe-area-inset-right));
  bottom: max(18px, env(safe-area-inset-bottom));
  display: grid;
  place-items: center;
  width: clamp(76px, 22svh, 96px);
  height: clamp(76px, 22svh, 96px);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 34%, rgba(255, 226, 122, 0.18), transparent 44%),
    rgba(23, 18, 32, 0.78);
  box-shadow: 0 16px 34px rgba(0, 0, 0, 0.34);
  color: #8c849a;
  font-weight: 900;
  backdrop-filter: blur(8px);
}

.ultimate-touch-button span {
  font-size: 28px;
  line-height: 1;
}

.ultimate-touch-button strong {
  margin-top: -20px;
  color: inherit;
  font-size: 14px;
  line-height: 1;
}

.ultimate-touch-button.ready {
  border-color: rgba(255, 211, 107, 0.68);
  background:
    radial-gradient(circle at 50% 34%, rgba(255, 226, 122, 0.44), rgba(168, 92, 255, 0.16) 58%),
    rgba(27, 20, 36, 0.9);
  color: #ffe494;
  text-shadow: 0 0 14px rgba(255, 211, 107, 0.48);
}

.orientation-hint {
  position: absolute;
  top: max(10px, env(safe-area-inset-top));
  left: 50%;
  z-index: 30;
  display: none;
  width: min(260px, calc(100vw - 28px));
  transform: translateX(-50%);
  padding: 10px 14px;
  border: 1px solid rgba(255, 211, 107, 0.36);
  border-radius: 8px;
  background:
    radial-gradient(circle at center, rgba(53, 213, 200, 0.14), transparent 42%),
    rgba(4, 3, 8, 0.72);
  box-shadow: 0 14px 32px rgba(0, 0, 0, 0.34);
  backdrop-filter: blur(10px);
  color: #f7f0ff;
  font-size: 17px;
  font-weight: 900;
  text-align: center;
  pointer-events: none;
}

.level-up-box,
.character-box,
.result-box {
  width: min(820px, 100%);
  border-radius: 8px;
  padding: 20px;
}

.level-up-box h1,
.character-box h1,
.result-box h1 {
  margin: 0;
  font-size: clamp(26px, 4vw, 42px);
  line-height: 1.05;
  letter-spacing: 0;
}

.character-box {
  width: min(1040px, 100%);
}

.character-options {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-top: 18px;
}

.character-card {
  position: relative;
  min-height: 228px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  padding: 18px;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  pointer-events: auto;
  transition:
    transform 140ms ease,
    border-color 140ms ease,
    filter 140ms ease;
}

.character-card::before {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.55;
  pointer-events: none;
}

.storm-card {
  background:
    linear-gradient(140deg, rgba(28, 213, 205, 0.18), rgba(105, 64, 180, 0.2)),
    rgba(18, 14, 30, 0.98);
}

.storm-card::before {
  background:
    radial-gradient(circle at 78% 20%, rgba(255, 226, 122, 0.24), transparent 22%),
    radial-gradient(circle at 18% 78%, rgba(53, 213, 200, 0.24), transparent 30%);
}

.windman-card {
  background:
    linear-gradient(140deg, rgba(74, 167, 255, 0.2), rgba(18, 28, 45, 0.92)),
    rgba(16, 18, 26, 0.98);
}

.windman-card::before {
  background:
    radial-gradient(circle at 84% 20%, rgba(126, 235, 255, 0.26), transparent 26%),
    radial-gradient(circle at 14% 82%, rgba(58, 117, 255, 0.2), transparent 34%);
}

.childzed-card {
  background:
    linear-gradient(140deg, rgba(198, 36, 66, 0.22), rgba(12, 11, 18, 0.94)),
    rgba(16, 13, 20, 0.98);
}

.childzed-card::before {
  background:
    radial-gradient(circle at 80% 18%, rgba(255, 62, 92, 0.24), transparent 27%),
    radial-gradient(circle at 16% 84%, rgba(20, 20, 24, 0.7), transparent 34%),
    linear-gradient(135deg, transparent 48%, rgba(255, 255, 255, 0.1) 49%, transparent 52%);
}

.character-card:hover,
.character-card:focus-visible {
  transform: translateY(-2px);
  border-color: rgba(132, 238, 255, 0.72);
  filter: brightness(1.08);
  outline: none;
}

.character-card strong,
.character-card small,
.character-card p,
.character-hotkey {
  position: relative;
  z-index: 1;
}

.character-card strong {
  display: block;
  margin-top: 38px;
  font-size: 27px;
  line-height: 1.05;
  letter-spacing: 0;
}

.character-card small {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  margin-top: 10px;
  padding: 0 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  color: #dffcff;
  font-size: 12px;
}

.character-card p {
  max-width: 310px;
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
}

.character-hotkey {
  position: absolute;
  top: 14px;
  right: 14px;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  font-weight: 850;
}

.upgrade-options {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-top: 18px;
}

.upgrade-card {
  min-height: 168px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  padding: 14px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.02)),
    rgba(19, 15, 30, 0.96);
  color: var(--text);
  text-align: left;
  cursor: pointer;
  pointer-events: auto;
  transition:
    transform 140ms ease,
    border-color 140ms ease,
    background 140ms ease;
}

.upgrade-card:hover,
.upgrade-card:focus-visible {
  transform: translateY(-2px);
  border-color: rgba(53, 213, 200, 0.68);
  background:
    linear-gradient(180deg, rgba(53, 213, 200, 0.13), rgba(168, 92, 255, 0.08)),
    rgba(19, 15, 30, 0.98);
  outline: none;
}

.upgrade-card small {
  display: inline-flex;
  align-items: center;
  height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: rgba(53, 213, 200, 0.14);
  color: #9ffff4;
  font-size: 12px;
}

.upgrade-card h2 {
  margin: 12px 0 8px;
  font-size: 22px;
  line-height: 1.1;
  letter-spacing: 0;
}

.upgrade-card p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.result-box {
  width: min(560px, 100%);
  text-align: center;
}

#result-panel .result-with-art {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(330px, 0.75fr);
  gap: 18px;
  align-items: stretch;
  width: min(1080px, calc(100vw - 34px));
  max-height: min(86vh, 760px);
  padding: 14px;
  overflow: hidden;
  text-align: left;
}

.result-art-frame {
  position: relative;
  min-height: 360px;
  margin: 0;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  background: rgba(4, 3, 8, 0.7);
}

.result-art-frame::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(90deg, rgba(4, 3, 8, 0.02), rgba(4, 3, 8, 0.48)),
    linear-gradient(180deg, transparent 56%, rgba(4, 3, 8, 0.72));
  pointer-events: none;
}

.result-image {
  display: block;
  width: 100%;
  height: 100%;
  min-height: inherit;
  object-fit: cover;
}

.result-caption {
  position: absolute;
  left: 14px;
  bottom: 12px;
  z-index: 2;
  color: rgba(247, 240, 255, 0.82);
  font-size: 13px;
  font-weight: 800;
}

.result-summary {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 0;
  padding: 10px 12px;
}

#result-panel.result-victory .result-art-frame {
  box-shadow: 0 0 34px rgba(168, 92, 255, 0.3);
}

#result-panel.result-defeat .result-art-frame {
  box-shadow: 0 0 34px rgba(53, 213, 200, 0.2);
}

.result-kicker {
  margin: 0 0 10px;
  color: var(--gold);
  font-weight: 800;
}

.result-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 20px 0;
}

.result-stats div {
  min-height: 74px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 8px;
  background: rgba(255, 255, 255, 0.06);
}

.result-stats dt {
  color: var(--muted);
  font-size: 12px;
}

.result-stats dd {
  margin: 6px 0 0;
  color: var(--text);
  font-size: 25px;
  font-weight: 850;
  font-variant-numeric: tabular-nums;
}

#restart-button,
#start-button {
  min-width: 148px;
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  background: linear-gradient(135deg, #2bd4c9, #a85cff);
  color: #fff;
  font-weight: 850;
  cursor: pointer;
  pointer-events: auto;
}

#restart-button:hover,
#restart-button:focus-visible,
#start-button:hover,
#start-button:focus-visible {
  filter: brightness(1.08);
  outline: 2px solid rgba(255, 255, 255, 0.42);
  outline-offset: 2px;
}

@media (max-width: 760px) {
  .hud-top {
    grid-template-columns: 1fr 1fr;
  }

  .brand {
    display: none;
  }

  .stat-pill {
    grid-column: 2;
    grid-row: 1;
  }

  .ultimate-pill {
    grid-column: 1 / -1;
    min-height: 42px;
  }

  .upgrade-options,
  .character-options,
  .result-stats {
    grid-template-columns: 1fr;
  }

  #result-panel .result-with-art {
    grid-template-columns: 1fr;
    max-height: calc(100dvh - 28px);
    overflow: auto;
  }

  .result-art-frame {
    min-height: 220px;
  }

  .upgrade-card {
    min-height: 132px;
  }

  .character-card {
    min-height: 170px;
  }

  .character-card strong {
    margin-top: 18px;
  }

  .boss-row {
    align-items: flex-start;
    flex-direction: column;
    gap: 4px;
  }
}

@media (max-height: 620px) {
  .stage-banner {
    top: 72px;
  }

  .boss-hud {
    bottom: 10px;
  }
}

@media (pointer: coarse) and (orientation: landscape), (orientation: landscape) and (max-height: 520px) {
  #game-shell {
    min-height: 0;
  }

  .hud-top {
    top: max(8px, env(safe-area-inset-top));
    left: max(10px, env(safe-area-inset-left));
    right: max(10px, env(safe-area-inset-right));
    grid-template-columns: minmax(132px, 1fr) minmax(132px, 1fr) minmax(76px, 0.48fr) minmax(102px, 0.62fr);
    gap: 8px;
  }

  .brand {
    display: none;
  }

  .meter-group,
  .stat-pill {
    min-height: 42px;
  }

  .meter-group {
    padding: 6px 8px 8px;
  }

  .stat-pill strong {
    font-size: 16px;
  }

  .ultimate-pill strong {
    font-size: 14px;
  }

  .boss-hud {
    bottom: max(8px, env(safe-area-inset-bottom));
    width: min(520px, calc(100vw - 300px));
    padding: 8px 10px 10px;
  }

  .stage-banner {
    top: 58px;
    width: min(560px, calc(100vw - 220px));
    padding: 8px 12px;
  }

  #result-panel {
    padding: 8px;
  }

  #result-panel .result-with-art {
    grid-template-columns: 1fr;
    gap: 10px;
    width: min(620px, calc(100vw - 18px));
    max-height: calc(100dvh - 18px);
    padding: 10px;
    overflow: auto;
  }

  #result-panel .result-art-frame {
    min-height: 132px;
    max-height: 34dvh;
  }

  #result-panel .result-summary {
    padding: 0;
    text-align: center;
  }

  #result-panel .result-summary h1 {
    font-size: clamp(24px, 7dvh, 34px);
  }

  #result-panel .result-stats {
    grid-template-columns: repeat(3, 1fr);
    margin: 10px 0;
  }

  #result-panel .result-stats div {
    min-height: 54px;
    padding: 7px 6px;
  }

  #result-panel .result-stats dd {
    font-size: 20px;
  }

  .move-joystick {
    left: max(14px, env(safe-area-inset-left));
    bottom: max(14px, env(safe-area-inset-bottom));
  }

  .ultimate-touch-button {
    right: max(16px, env(safe-area-inset-right));
    bottom: max(18px, env(safe-area-inset-bottom));
  }
}

@media (pointer: coarse) and (orientation: portrait), (orientation: portrait) and (max-width: 760px) {
  .orientation-hint {
    display: block;
  }
}

@media (hover: hover) and (pointer: fine) and (min-width: 900px) and (min-height: 620px) {
  .mobile-controls {
    display: none;
  }
}
