:root {
  --bg-1: #040716;
  --bg-2: #07172a;
  --bg-3: #102741;
  --panel: rgba(8, 18, 34, 0.64);
  --panel-line: rgba(196, 225, 255, 0.16);
  --text: #f4fbff;
  --muted: rgba(225, 240, 255, 0.72);
  --ice: #8fd3ff;
  --gold: #ffd977;
  --danger: #ff7f90;
  --shadow: rgba(0, 0, 0, 0.32);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

html,
body {
  margin: 0;
  min-height: 100%;
  overflow: hidden;
  touch-action: none;
  overscroll-behavior: none;
  color: var(--text);
  font-family: "Avenir Next", "Trebuchet MS", "PingFang TC", "Noto Sans TC", sans-serif;
  background:
    radial-gradient(circle at 20% 12%, rgba(112, 164, 255, 0.18), transparent 24%),
    radial-gradient(circle at 78% 8%, rgba(255, 255, 255, 0.12), transparent 18%),
    linear-gradient(180deg, var(--bg-1), var(--bg-2) 38%, var(--bg-3));
}

body {
  display: grid;
  place-items: center;
  padding:
    max(10px, env(safe-area-inset-top))
    max(10px, env(safe-area-inset-right))
    max(10px, env(safe-area-inset-bottom))
    max(10px, env(safe-area-inset-left));
}

button {
  font: inherit;
  border: 0;
  cursor: pointer;
}

.app {
  position: relative;
  width: min(
    calc(100vw - 24px - env(safe-area-inset-left) - env(safe-area-inset-right)),
    560px,
    calc((100svh - 24px - env(safe-area-inset-top) - env(safe-area-inset-bottom)) * 0.62)
  );
  height: min(
    calc(100svh - 24px - env(safe-area-inset-top) - env(safe-area-inset-bottom)),
    980px
  );
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.topbar {
  min-height: 62px;
  padding: 13px 16px;
  border-radius: 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background:
    linear-gradient(180deg, rgba(13, 26, 48, 0.88), rgba(6, 11, 24, 0.76)),
    radial-gradient(circle at top, rgba(148, 207, 255, 0.22), transparent 60%);
  border: 1px solid var(--panel-line);
  box-shadow:
    0 22px 42px rgba(0, 0, 0, 0.22),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
  backdrop-filter: blur(14px);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.title-wrap {
  min-width: 0;
}

.title {
  font-size: clamp(0.96rem, 3.8vw, 1.12rem);
  font-weight: 900;
  letter-spacing: 0.06em;
  line-height: 1.05;
  text-shadow: 0 0 18px rgba(143, 211, 255, 0.2);
}

.subtitle {
  margin-top: 4px;
  font-size: 0.56rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  color: var(--muted);
}

.action-button {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  color: var(--text);
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(70, 128, 198, 0.96), rgba(16, 30, 59, 0.96));
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: 0 10px 18px rgba(0, 0, 0, 0.26);
  transition: transform 180ms ease, opacity 180ms ease, box-shadow 180ms ease;
}

.action-button:disabled {
  cursor: default;
  opacity: 0.42;
  box-shadow: 0 8px 14px rgba(0, 0, 0, 0.18);
}

.action-button:not(:disabled):active {
  transform: translateY(1px) scale(0.98);
}

.restart {
  min-width: 70px;
  height: 40px;
  padding: 0 16px;
  font-size: 0.8rem;
  font-weight: 900;
  letter-spacing: 0.05em;
  text-transform: none;
}

.frame {
  position: relative;
  flex: 1;
  min-height: 0;
  border-radius: 32px;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% -20%, rgba(163, 220, 255, 0.16), transparent 42%),
    linear-gradient(180deg, rgba(5, 8, 24, 0.94), rgba(4, 12, 26, 0.98));
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow:
    0 30px 68px rgba(0, 0, 0, 0.38),
    inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

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

.hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.space-button {
  position: absolute;
  right: 14px;
  top: 58px;
  width: 54px;
  height: 54px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background:
    radial-gradient(circle at 30% 28%, rgba(242, 252, 255, 0.34), transparent 32%),
    linear-gradient(180deg, rgba(69, 166, 235, 0.94), rgba(8, 46, 85, 0.96));
  color: #f2fcff;
  box-shadow:
    0 16px 26px rgba(0, 0, 0, 0.28),
    0 0 22px rgba(115, 223, 255, 0.26);
  pointer-events: auto;
  display: grid;
  place-items: center;
}

.space-button svg {
  width: 33px;
  height: 33px;
}

.space-button:disabled {
  opacity: 0.36;
  box-shadow: 0 10px 16px rgba(0, 0, 0, 0.22);
}

.space-button:not(:disabled):active {
  transform: translateY(1px) scale(0.98);
}

.hud-row {
  position: absolute;
  top: 12px;
  display: flex;
  gap: 8px;
}

.top-left {
  left: 12px;
}

.top-right {
  right: 12px;
}

.pill {
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(6, 14, 26, 0.48);
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.16);
  backdrop-filter: blur(10px);
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: var(--text);
}

#playerHpPill,
#volleyPill {
  padding: 10px 14px;
  font-size: 0.84rem;
  font-weight: 900;
  box-shadow:
    0 12px 24px rgba(0, 0, 0, 0.2),
    0 0 18px rgba(163, 228, 255, 0.12);
}

#playerHpPill {
  color: #f7fcff;
  text-shadow:
    0 0 8px rgba(255, 247, 192, 0.78),
    0 0 14px rgba(169, 233, 255, 0.46);
  box-shadow:
    0 12px 24px rgba(0, 0, 0, 0.2),
    0 0 22px rgba(252, 245, 189, 0.16),
    0 0 18px rgba(163, 228, 255, 0.12);
}

.center-pill {
  position: absolute;
  left: 50%;
  top: 14px;
  transform: translateX(-50%);
  min-width: 124px;
  text-align: center;
  transition: opacity 180ms ease;
}

.center-pill.is-hidden {
  opacity: 0;
}

.message {
  position: absolute;
  left: 50%;
  top: 10%;
  transform: translateX(-50%);
  width: min(76%, 380px);
  padding: 14px 16px;
  border-radius: 24px;
  text-align: center;
  background:
    linear-gradient(180deg, rgba(16, 28, 49, 0.88), rgba(8, 12, 28, 0.78)),
    radial-gradient(circle at top, rgba(171, 218, 255, 0.14), transparent 70%);
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 18px 36px rgba(0, 0, 0, 0.26);
  backdrop-filter: blur(12px);
  opacity: 0;
  translate: 0 -14px;
  transition: opacity 280ms ease, translate 280ms ease;
}

.message.show {
  opacity: 1;
  translate: 0 0;
}

.message-title {
  font-size: 1rem;
  font-weight: 900;
  letter-spacing: 0.06em;
}

.message-body {
  margin-top: 6px;
  font-size: 0.74rem;
  line-height: 1.45;
  color: var(--muted);
}

.princess-card {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 28px;
  background:
    radial-gradient(circle at 50% 36%, rgba(255, 237, 154, 0.24), transparent 30%),
    radial-gradient(circle at 50% 50%, rgba(255, 214, 102, 0.18), transparent 48%),
    rgba(10, 10, 16, 0.28);
  opacity: 0;
  pointer-events: none;
  transition: opacity 220ms ease;
}

.princess-card.show {
  opacity: 1;
  pointer-events: auto;
}

.princess-card-panel {
  width: min(82%, 420px);
  padding: 18px 18px 16px;
  border-radius: 28px;
  text-align: center;
  background:
    linear-gradient(180deg, rgba(126, 95, 28, 0.88), rgba(63, 44, 12, 0.86)),
    radial-gradient(circle at 50% 0%, rgba(255, 251, 215, 0.38), transparent 55%);
  border: 1px solid rgba(255, 240, 189, 0.44);
  box-shadow:
    0 22px 44px rgba(0, 0, 0, 0.34),
    0 0 0 2px rgba(255, 236, 177, 0.18),
    0 0 26px rgba(255, 227, 124, 0.4),
    0 0 68px rgba(255, 206, 77, 0.28),
    0 0 32px rgba(255, 224, 128, 0.22),
    inset 0 1px 0 rgba(255, 251, 230, 0.48);
  backdrop-filter: blur(10px);
  position: relative;
  overflow: hidden;
}

.princess-card-panel::before,
.princess-card-panel::after {
  content: "";
  position: absolute;
  inset: -20%;
  background:
    radial-gradient(circle, rgba(255, 249, 211, 0.28) 0, rgba(255, 249, 211, 0) 56%);
  animation: princess-shimmer 2.8s linear infinite;
  pointer-events: none;
}

.princess-card-panel::after {
  animation-delay: 1.3s;
  transform: scale(0.84);
}

.princess-card-panel::before {
  box-shadow:
    0 0 56px rgba(255, 233, 154, 0.24),
    0 0 104px rgba(255, 203, 76, 0.14);
}

.princess-card-panel::after {
  box-shadow:
    0 0 48px rgba(255, 247, 198, 0.2),
    0 0 88px rgba(255, 214, 92, 0.12);
}

.princess-card-title {
  position: relative;
  z-index: 1;
  font-size: 1rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  color: #fff9dc;
  text-shadow:
    0 0 14px rgba(255, 246, 178, 0.44),
    0 2px 10px rgba(0, 0, 0, 0.24);
}

.princess-card-frame {
  position: relative;
  z-index: 1;
  margin: 14px auto 0;
  width: min(76vw, 260px);
  height: min(76vw, 260px);
  border-radius: 24px;
  background:
    radial-gradient(circle at 50% 22%, rgba(255, 252, 223, 0.42), rgba(255, 222, 137, 0.14) 58%, rgba(56, 33, 9, 0.24) 100%);
  border: 1px solid rgba(255, 244, 203, 0.48);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.42),
    0 18px 32px rgba(0, 0, 0, 0.24);
  display: grid;
  place-items: center;
}

.princess-card-frame img {
  width: 88%;
  height: 88%;
  object-fit: contain;
  filter:
    drop-shadow(0 10px 18px rgba(0, 0, 0, 0.28))
    drop-shadow(0 0 16px rgba(255, 245, 182, 0.2));
}

.princess-card-body {
  position: relative;
  z-index: 1;
  margin-top: 14px;
  font-size: 0.84rem;
  line-height: 1.6;
  color: rgba(255, 248, 228, 0.92);
}

@keyframes princess-shimmer {
  0% {
    transform: translate(-24%, -28%) rotate(0deg);
    opacity: 0;
  }
  20% {
    opacity: 1;
  }
  100% {
    transform: translate(24%, 32%) rotate(24deg);
    opacity: 0;
  }
}

@media (max-width: 480px) {
  .topbar {
    min-height: 58px;
    padding: 12px 14px;
  }

  .pill {
    padding: 7px 10px;
    font-size: 0.7rem;
  }

  .message {
    top: 9%;
    width: min(82%, 360px);
  }

  .princess-card {
    padding: 18px;
  }

  .princess-card-panel {
    width: min(88%, 360px);
    padding: 16px 14px 14px;
  }

  .princess-card-title {
    font-size: 0.92rem;
  }

  .princess-card-body {
    font-size: 0.78rem;
  }
}
