:root {
  color-scheme: light;
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  --ink: #322b65;
  --purple: #6e58f6;
  --deep-purple: #5036ca;
  --pink: #ff5ba8;
  --yellow: #ffd84e;
  --panel: rgba(255, 255, 255, 0.93);
}

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

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #34277d;
  overscroll-behavior: none;
}

button {
  font: inherit;
  border: 0;
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
}

.game-shell {
  position: relative;
  width: min(100vw, 480px);
  height: 100dvh;
  min-height: 560px;
  margin: 0 auto;
  overflow: hidden;
  background: #73dcf5;
  box-shadow: 0 0 50px rgba(13, 7, 57, 0.45);
}

.game-stage,
#gameCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

#gameCanvas {
  display: block;
  touch-action: none;
}

.hud {
  position: absolute;
  z-index: 8;
  top: max(12px, env(safe-area-inset-top));
  left: 14px;
  right: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.hud-pill,
.icon-button {
  height: 38px;
  border: 2px solid rgba(255, 255, 255, 0.88);
  background: rgba(49, 38, 114, 0.76);
  color: #fff;
  box-shadow: 0 5px 14px rgba(54, 40, 135, 0.22), inset 0 1px 0 rgba(255, 255, 255, 0.18);
  backdrop-filter: blur(8px);
}

.hud-pill {
  display: flex;
  align-items: center;
  border-radius: 20px;
  padding: 0 10px;
}

.progress-pill {
  flex: 1;
  min-width: 120px;
  gap: 7px;
}

.progress-track {
  flex: 1;
  height: 9px;
  overflow: hidden;
  border-radius: 8px;
  background: rgba(21, 14, 67, 0.5);
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.35);
}

.progress-track i {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #66f2d1, #fff265);
  box-shadow: 0 0 8px #75f7d9;
  transition: width 0.18s linear;
}

.level-badge {
  display: grid;
  place-items: center;
  min-width: 31px;
  height: 22px;
  padding: 0 6px;
  border-radius: 11px;
  color: #41319c;
  background: #76f1d5;
  font-size: 10px;
  font-weight: 1000;
  letter-spacing: -0.03em;
}

.progress-pill strong {
  width: 32px;
  font-size: 12px;
  text-align: right;
}

.score-pill {
  min-width: 66px;
  justify-content: center;
  gap: 5px;
}

.star-icon {
  color: var(--yellow);
  text-shadow: 0 2px 0 #e99b21;
}

.icon-button {
  position: relative;
  z-index: 9;
  width: 38px;
  flex: 0 0 38px;
  border-radius: 50%;
  font-weight: 900;
  pointer-events: auto;
}

.status-row {
  position: absolute;
  z-index: 7;
  top: calc(max(12px, env(safe-area-inset-top)) + 49px);
  left: 18px;
  right: 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  pointer-events: none;
}

.hearts {
  display: flex;
  gap: 4px;
  filter: drop-shadow(0 2px 2px rgba(68, 27, 85, 0.34));
}

.heart {
  color: #ff579e;
  font-size: 21px;
  -webkit-text-stroke: 2px #fff;
  paint-order: stroke fill;
}

.heart.lost {
  color: rgba(54, 43, 91, 0.28);
}

.buff-badge {
  padding: 5px 11px;
  border: 2px solid #fff;
  border-radius: 15px;
  color: #fff;
  background: linear-gradient(135deg, #ff64ae, #7b57ff);
  box-shadow: 0 4px 10px rgba(80, 50, 180, 0.24);
  font-size: 12px;
  font-weight: 800;
}

.level-banner {
  position: absolute;
  z-index: 11;
  top: 22%;
  left: 50%;
  width: min(78%, 310px);
  padding: 15px 22px 17px;
  border: 3px solid #fff;
  border-radius: 24px;
  color: #fff;
  background: linear-gradient(135deg, rgba(79, 55, 199, 0.94), rgba(255, 83, 165, 0.94));
  box-shadow: 0 8px 0 rgba(49, 31, 126, 0.3), 0 15px 30px rgba(54, 34, 132, 0.28);
  text-align: center;
  pointer-events: none;
}

.level-banner[hidden] { display: none; }

.level-banner.showing { animation: level-banner-in 1.65s both; }

.level-banner small,
.level-banner strong,
.level-banner span {
  display: block;
}

.level-banner small {
  color: #fff36f;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.2em;
}

.level-banner strong {
  margin: 2px 0 3px;
  font-size: 27px;
  font-weight: 1000;
  letter-spacing: 0.08em;
}

.level-banner span {
  color: rgba(255, 255, 255, 0.86);
  font-size: 11px;
}

@keyframes level-banner-in {
  0% { opacity: 0; transform: translate(-50%, -16px) scale(0.82); }
  16%, 72% { opacity: 1; transform: translate(-50%, 0) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -8px) scale(0.95); }
}

.overlay-panel {
  position: absolute;
  z-index: 12;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 28px 34px max(28px, env(safe-area-inset-bottom));
  color: var(--ink);
  text-align: center;
  background: linear-gradient(180deg, rgba(76, 72, 181, 0.08), rgba(35, 22, 98, 0.36));
  backdrop-filter: blur(2px);
}

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

.start-panel::before,
.start-panel::after {
  content: "";
  position: absolute;
  z-index: -1;
  width: 150px;
  height: 150px;
  border: 26px solid rgba(255, 255, 255, 0.1);
  border-radius: 50%;
}

.start-panel::before {
  top: -68px;
  right: -68px;
}

.start-panel::after {
  left: -88px;
  bottom: 90px;
}

.logo-mark {
  position: relative;
  width: 96px;
  height: 86px;
  margin-bottom: 14px;
  border: 5px solid #fff;
  border-radius: 48% 48% 44% 44%;
  background: linear-gradient(145deg, #ffd45d 0 25%, #ff78af 26% 100%);
  box-shadow: 0 9px 0 rgba(77, 54, 174, 0.25), 0 16px 30px rgba(81, 43, 159, 0.25);
  transform: rotate(-4deg);
}

.logo-crown {
  position: absolute;
  top: -31px;
  left: 27px;
  color: #ffe266;
  font-size: 39px;
  -webkit-text-stroke: 3px #fff;
  paint-order: stroke fill;
}

.logo-face {
  position: absolute;
  inset: 0;
}

.logo-face i {
  position: absolute;
  top: 37px;
  width: 10px;
  height: 14px;
  border-radius: 50%;
  background: #45347d;
}

.logo-face i:first-child { left: 25px; }
.logo-face i:nth-child(2) { right: 25px; }

.logo-face b {
  position: absolute;
  left: 38px;
  top: 55px;
  width: 20px;
  height: 9px;
  border-bottom: 4px solid #45347d;
  border-radius: 50%;
}

.eyebrow {
  margin: 0 0 6px;
  color: #fff;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.2em;
  text-shadow: 0 2px 6px rgba(71, 47, 160, 0.35);
}

h1 {
  margin: 0;
  color: #fff;
  font-size: clamp(48px, 15vw, 68px);
  font-weight: 1000;
  line-height: 0.87;
  letter-spacing: -0.08em;
  text-shadow: 0 5px 0 #573bcb, 0 10px 24px rgba(57, 31, 141, 0.32);
  transform: rotate(-2deg);
}

h1 em {
  color: #fff16a;
  font-style: normal;
  letter-spacing: -0.03em;
}

.intro {
  max-width: 310px;
  margin: 18px 0 13px;
  color: #fff;
  font-size: 13px;
  font-weight: 650;
  line-height: 1.55;
  text-shadow: 0 2px 8px rgba(53, 34, 121, 0.3);
}

.character-picker {
  width: min(100%, 294px);
  margin: 0 0 16px;
}

.character-picker > p {
  margin: 0 0 8px;
  color: rgba(255, 255, 255, 0.92);
  font-size: 11px;
  font-weight: 850;
  letter-spacing: 0.16em;
}

.character-list {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 9px;
}

.character-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  height: 86px;
  padding: 3px 4px 6px;
  overflow: hidden;
  border: 3px solid rgba(255, 255, 255, 0.75);
  border-radius: 19px;
  color: #5b47b5;
  background: rgba(255, 255, 255, 0.76);
  box-shadow: 0 5px 0 rgba(74, 51, 165, 0.3);
  transition: transform 0.12s, border-color 0.12s, background 0.12s;
}

.character-card::after {
  content: "✓";
  position: absolute;
  top: 4px;
  right: 5px;
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  color: #fff;
  background: #ff58a6;
  font-size: 11px;
  font-weight: 900;
  opacity: 0;
  transform: scale(0.5);
  transition: inherit;
}

.character-card.selected {
  border-color: #fff26b;
  background: #fff;
  transform: translateY(-3px);
  box-shadow: 0 7px 0 #e6b638, 0 9px 16px rgba(68, 39, 145, 0.24);
}

.character-card.selected::after {
  opacity: 1;
  transform: scale(1);
}

.character-card img {
  position: absolute;
  top: 1px;
  width: 55px;
  height: 70px;
  object-fit: contain;
  object-position: center;
  filter: drop-shadow(0 3px 2px rgba(56, 35, 115, 0.16));
  transform-origin: 50% 90%;
}

.character-card.selected img {
  animation: card-run 0.7s ease-in-out infinite;
}

.character-card:not(.selected) img {
  animation: card-idle 2.4s ease-in-out infinite;
}

.character-card strong {
  position: relative;
  z-index: 1;
  display: block;
  width: 100%;
  padding: 2px 0;
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.86);
  font-size: 11px;
  line-height: 1;
}

.default-avatar {
  position: absolute;
  top: 11px;
  width: 48px;
  height: 54px;
  border: 3px solid #fff;
  border-radius: 50% 50% 46% 46%;
  background: linear-gradient(145deg, #fff36a, #ff7eaa);
  box-shadow: 0 3px 0 rgba(88, 54, 159, 0.2);
  transform-origin: 50% 100%;
  animation: card-idle 2.4s ease-in-out infinite -0.6s;
}

.character-card.selected .default-avatar {
  animation: card-run 0.7s ease-in-out infinite;
}

.default-avatar i,
.default-avatar b {
  position: absolute;
  top: 22px;
  width: 5px;
  height: 7px;
  border-radius: 50%;
  background: #493b82;
}

.default-avatar i { left: 12px; }
.default-avatar b { right: 12px; }

@keyframes card-idle {
  0%, 100% { transform: translateY(0) rotate(-1.5deg); }
  50% { transform: translateY(-3px) rotate(1.5deg); }
}

@keyframes card-run {
  0%, 100% { transform: translateY(0) rotate(-3deg) scaleY(0.98); }
  50% { transform: translateY(-5px) rotate(3deg) scaleY(1.03); }
}

@media (prefers-reduced-motion: reduce) {
  .character-card img,
  .default-avatar {
    animation: none !important;
  }
}

.primary-button {
  position: relative;
  min-width: 218px;
  height: 59px;
  padding: 0 22px;
  border: 4px solid #fff;
  border-radius: 32px;
  color: #fff;
  background: linear-gradient(180deg, #ff70b4, #f44592);
  box-shadow: 0 8px 0 #b82d80, 0 13px 22px rgba(65, 38, 135, 0.28), inset 0 3px 0 rgba(255, 255, 255, 0.28);
  font-size: 20px;
  font-weight: 900;
  letter-spacing: 0.08em;
  transition: transform 0.08s, box-shadow 0.08s;
}

.primary-button:active {
  transform: translateY(5px) scale(0.98);
  box-shadow: 0 3px 0 #b82d80, 0 7px 14px rgba(65, 38, 135, 0.25);
}

.primary-button i {
  position: absolute;
  right: 18px;
  top: 8px;
  font-size: 34px;
  font-style: normal;
}

.primary-button.small {
  min-width: 190px;
  height: 52px;
  margin-top: 18px;
  font-size: 17px;
}

.mini-tip {
  margin: 20px 0 0;
  color: rgba(255, 255, 255, 0.82);
  font-size: 11px;
}

.compact-panel {
  inset: 16% 8%;
  height: max-content;
  margin: auto;
  padding: 34px 24px 38px;
  border: 4px solid #fff;
  border-radius: 34px;
  background: var(--panel);
  box-shadow: 0 18px 0 rgba(58, 42, 137, 0.25), 0 30px 50px rgba(34, 22, 92, 0.3);
  backdrop-filter: blur(14px);
}

.compact-panel h2 {
  margin: 4px 0 8px;
  font-size: 31px;
  font-weight: 1000;
}

.compact-panel p:not(.eyebrow) {
  margin: 0;
  color: #77709d;
  font-size: 14px;
}

.compact-panel .eyebrow {
  color: var(--purple);
  text-shadow: none;
}

.panel-emoji,
.result-medal {
  display: grid;
  place-items: center;
  width: 74px;
  height: 74px;
  margin: -69px auto 14px;
  border: 4px solid #fff;
  border-radius: 50%;
  color: #fff;
  background: linear-gradient(145deg, #86e9f7, #6e5bf2);
  box-shadow: 0 8px 0 rgba(75, 52, 173, 0.25);
  font-size: 34px;
}

.result-medal {
  color: #fff271;
  background: linear-gradient(145deg, #ff91c3, #7558f7);
}

.result-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  width: 100%;
  margin: 18px 0 2px;
  overflow: hidden;
  border-radius: 18px;
  background: #f0ecff;
}

.result-stats div {
  padding: 13px 8px;
}

.result-stats div + div {
  border-left: 2px solid #fff;
}

.result-stats span,
.result-stats strong {
  display: block;
}

.result-stats span {
  color: #8881ad;
  font-size: 11px;
}

.result-stats strong {
  margin-top: 2px;
  color: var(--deep-purple);
  font-size: 21px;
}

.text-button {
  margin-top: 20px;
  color: #7c73a4;
  background: transparent;
  font-size: 13px;
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 4px;
}

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

.move-controls {
  display: flex;
  gap: 10px;
}

.control-button {
  display: grid;
  place-items: center;
  color: #fff;
  border: 3px solid rgba(255, 255, 255, 0.9);
  background: rgba(72, 52, 164, 0.68);
  box-shadow: 0 6px 0 rgba(48, 34, 119, 0.55), inset 0 2px 0 rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(6px);
  pointer-events: auto;
}

.move-button {
  width: 78px;
  height: 78px;
  border-radius: 25px;
  font-family: Arial, sans-serif;
  font-size: 58px;
  font-weight: 900;
  line-height: 1;
}

.jump-button {
  width: 76px;
  height: 76px;
  border-radius: 50%;
  background: linear-gradient(145deg, rgba(255, 111, 180, 0.92), rgba(237, 59, 143, 0.92));
}

.jump-button span,
.jump-button small {
  grid-area: 1 / 1;
}

.jump-button span {
  margin-top: -10px;
  font-size: 25px;
  font-weight: 1000;
}

.jump-button small {
  margin-top: 37px;
  font-size: 8px;
  font-weight: 900;
  letter-spacing: 0.1em;
}

.control-button.pressed,
.control-button:active {
  transform: translateY(4px) scale(0.96);
  box-shadow: 0 2px 0 rgba(48, 34, 119, 0.55);
}

body[data-state="ready"] .hud,
body[data-state="ready"] .status-row,
body[data-state="ready"] .controls,
body[data-state="won"] .controls,
body[data-state="lost"] .controls,
body[data-state="paused"] .controls {
  opacity: 0;
  pointer-events: none;
}

@media (max-height: 620px) {
  .logo-mark { transform: scale(0.8) rotate(-4deg); margin-bottom: 4px; }
  h1 { font-size: 46px; }
  .intro { margin: 9px 0; font-size: 12px; }
  .character-picker { margin-bottom: 11px; }
  .character-picker > p { margin-bottom: 5px; }
  .character-card { height: 72px; border-radius: 16px; }
  .character-card img { width: 44px; height: 56px; }
  .default-avatar { top: 7px; transform: scale(0.8); }
  .mini-tip { display: none; }
  .control-button.move-button { width: 68px; height: 68px; }
  .jump-button { width: 66px; height: 66px; }
}
