:root {
  color-scheme: dark;
  --bg: #0f1020;
  --panel: #1a1b28;
  --panel-2: #212233;
  --accent: #6842ff;
  --accent-2: #8a6dff;
  --green: #2fd67b;
  --red: #ff4d5e;
  --gold: #ffcf3a;
  --text: #fff;
  --muted: #aaadbe;
  --line: rgba(255, 255, 255, 0.08);
  font-family: "Nunito", ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", sans-serif;
}
* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  width: 100%;
  min-width: 0;
  background: var(--bg);
  color: var(--text);
  overflow-x: hidden;
}
body {
  padding: 8px;
}
button {
  font: inherit;
  color: inherit;
}
.pk-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
.pk-shell {
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

/* ---------- HUD ---------- */
.pk-hud {
  width: 100%;
  display: flex;
  gap: 6px;
  align-items: stretch;
  min-width: 0;
}
.pk-chip {
  flex: 0 1 86px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 5px 8px;
  border-radius: 999px;
  background: linear-gradient(180deg, #26273a, var(--panel));
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.08),
    0 4px 10px rgba(0, 0, 0, 0.25);
  line-height: 1.05;
}
.pk-chip[hidden],
.pk-board[hidden] {
  display: none;
}
.pk-chip span {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  white-space: nowrap;
}
.pk-chip strong {
  font-size: 18px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
#pk-p-score-chip,
#pk-p-time-chip,
#pk-p-best-chip {
  flex: 1 1 0;
}
.pk-chip.is-warn strong {
  color: var(--red);
}
.pk-chip.is-bump,
.pk-board.is-bump {
  animation: pk-bump 0.35s ease;
}
.pk-board {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 4px 10px;
  border-radius: 999px;
  background: linear-gradient(180deg, #26273a, var(--panel));
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.08),
    0 4px 10px rgba(0, 0, 0, 0.25);
}
.pk-side {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}
.pk-team {
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.06em;
  padding: 3px 7px;
  border-radius: 999px;
  background: var(--accent);
  white-space: nowrap;
}
.pk-team-ai {
  background: #ff3b4e;
}
.pk-dots {
  display: flex;
  gap: 3px;
}
.pk-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: #34364d;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.5);
}
.pk-dot.is-goal {
  background: radial-gradient(circle at 35% 30%, #9dffc8, var(--green) 60%, #0d8a46);
  box-shadow: 0 0 6px rgba(47, 214, 123, 0.6);
}
.pk-dot.is-miss {
  background: radial-gradient(circle at 35% 30%, #ffb0b8, var(--red) 60%, #a4121f);
}
.pk-dot.is-next {
  box-shadow: 0 0 0 2px #fff inset;
  animation: pk-pulse 1s ease-in-out infinite;
}
.pk-score {
  font-size: 22px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.pk-icon {
  flex: 0 0 auto;
  width: 44px;
  min-height: 44px;
  border: 0;
  border-radius: 999px;
  background: #2a2b3d;
  display: grid;
  place-items: center;
  cursor: pointer;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.1),
    0 4px 10px rgba(0, 0, 0, 0.25);
}
.pk-icon svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}
.pk-icon:disabled {
  opacity: 0.45;
  cursor: default;
}
.pk-icon .pk-x {
  display: none;
}
.pk-icon[aria-pressed="true"] .pk-x {
  display: block;
}
.pk-icon[aria-pressed="true"] .pk-wave {
  display: none;
}

/* ---------- Stage ---------- */
.pk-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 800 / 470;
  border-radius: 22px;
  overflow: hidden;
  background: #111a33;
  box-shadow:
    0 0 0 1px var(--line),
    0 18px 40px rgba(0, 0, 0, 0.45);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.pk-stage.is-portrait {
  aspect-ratio: 600 / 800;
}
.pk-stage.is-shake {
  animation: pk-shake 0.35s ease;
}
#pk-canvas {
  display: block;
  width: 100%;
  height: 100%;
  outline: none;
  cursor: crosshair;
}
.pk-stage:has(#pk-canvas:focus-visible) {
  box-shadow:
    0 0 0 3px var(--accent-2),
    0 18px 40px rgba(0, 0, 0, 0.45);
}

.pk-banner {
  position: absolute;
  left: 50%;
  top: 38%;
  transform: translate(-50%, -50%) scale(0);
  font-size: clamp(38px, 9vw, 76px);
  font-weight: 900;
  letter-spacing: 0.02em;
  line-height: 1;
  white-space: nowrap;
  pointer-events: none;
  color: #fff;
  -webkit-text-stroke: 2px rgba(0, 0, 0, 0.25);
  text-shadow:
    0 5px 0 var(--banner-shadow, #3f22b8),
    0 12px 26px rgba(0, 0, 0, 0.5);
  opacity: 0;
}
.pk-banner.is-show {
  animation: pk-banner 1.25s cubic-bezier(0.2, 1.4, 0.4, 1) forwards;
}
.pk-banner small {
  display: block;
  margin-top: 6px;
  font-size: 0.32em;
  letter-spacing: 0.1em;
  text-align: center;
  -webkit-text-stroke: 0;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.6);
}

.pk-turn {
  position: absolute;
  left: 50%;
  top: 10px;
  transform: translateX(-50%);
  padding: 6px 14px;
  border-radius: 999px;
  font-weight: 900;
  font-size: 13px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  background: rgba(15, 16, 32, 0.72);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12);
  pointer-events: none;
  white-space: nowrap;
}
.pk-turn[hidden] {
  display: none;
}
.pk-turn.is-save {
  background: linear-gradient(180deg, #ff6b3d, #e0381f);
}
.pk-turn.is-shoot {
  background: linear-gradient(180deg, #8163ff, var(--accent));
}

.pk-keeper-pad {
  position: absolute;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  display: flex;
  gap: 10px;
  padding: 6px;
  border-radius: 999px;
  background: rgba(15, 16, 32, 0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.pk-keeper-pad[hidden] {
  display: none;
}
.pk-dive {
  width: 52px;
  height: 52px;
  border: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  cursor: pointer;
  background: linear-gradient(180deg, #ff8a4a, #f0561f);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.35),
    0 4px 0 #a8330b,
    0 8px 14px rgba(0, 0, 0, 0.35);
  transition: transform 0.08s ease;
}
.pk-dive svg {
  width: 26px;
  height: 26px;
  fill: none;
  stroke: #fff;
  stroke-width: 3.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.pk-dive[data-dive="stay"] svg {
  fill: #fff;
  stroke: none;
}
.pk-dive:active,
.pk-dive.is-picked {
  transform: translateY(3px);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.35),
    0 1px 0 #a8330b;
}
.pk-dive.is-picked {
  background: linear-gradient(180deg, #ffe066, #ffb800);
}
.pk-dive:disabled {
  cursor: default;
}

/* ---------- Overlays ---------- */
.pk-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 12px;
  overflow-y: auto;
  background: radial-gradient(ellipse at 50% 40%, rgba(24, 16, 60, 0.5), rgba(8, 8, 20, 0.82));
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}
.pk-overlay[hidden] {
  display: none;
}
.pk-card {
  width: min(360px, 100%);
  text-align: center;
  padding: 18px 18px 16px;
  border-radius: 24px;
  background: linear-gradient(180deg, #262740, var(--panel));
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.1),
    0 20px 50px rgba(0, 0, 0, 0.5);
  animation: pk-pop-in 0.35s cubic-bezier(0.2, 1.4, 0.4, 1);
}
.pk-logo {
  display: grid;
  place-items: center;
  margin: -2px auto 2px;
}
.pk-logo-ball {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 32% 26%, rgba(255, 255, 255, 0.95) 0 10%, transparent 30%),
    radial-gradient(circle at 50% 50%, #1b1d2e 0 15%, transparent 16%),
    radial-gradient(circle at 18% 70%, #1b1d2e 0 10%, transparent 11%),
    radial-gradient(circle at 82% 70%, #1b1d2e 0 10%, transparent 11%),
    radial-gradient(circle at 50% 5%, #1b1d2e 0 9%, transparent 10%),
    radial-gradient(circle at 40% 35%, #ffffff, #e6e8f2 55%, #9ea3bd 100%);
  box-shadow:
    0 10px 22px rgba(104, 66, 255, 0.45),
    inset -6px -8px 14px rgba(20, 20, 60, 0.35);
  animation: pk-float 1.4s ease-in-out infinite;
}
.pk-title {
  margin: 0;
  font-size: 40px;
  font-weight: 900;
  letter-spacing: -0.01em;
  line-height: 1;
  background: linear-gradient(180deg, #fff 30%, #c9f7d8);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 3px 0 #1b8a4c) drop-shadow(0 8px 14px rgba(0, 0, 0, 0.4));
}
.pk-title-small {
  font-size: 32px;
  margin-bottom: 14px;
}
.pk-lead {
  margin: 10px 0 14px;
  color: var(--muted);
  font-weight: 700;
  font-size: 14px;
  line-height: 1.4;
}
.pk-lead-tight {
  margin: 4px 0 10px;
}
.pk-modes,
.pk-actions {
  display: grid;
  gap: 10px;
}
.pk-btn {
  min-height: 48px;
  padding: 8px 18px;
  border: 0;
  border-radius: 999px;
  background: #2a2b3d;
  font-weight: 900;
  font-size: 17px;
  cursor: pointer;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.12),
    0 4px 0 #17182a,
    0 8px 16px rgba(0, 0, 0, 0.3);
  transition:
    transform 0.1s ease,
    box-shadow 0.1s ease,
    filter 0.15s ease;
}
.pk-btn:hover {
  filter: brightness(1.1);
}
.pk-btn:active {
  transform: translateY(3px);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.12),
    0 1px 0 #17182a;
}
.pk-btn-primary {
  background: linear-gradient(180deg, #8163ff, var(--accent));
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.3),
    0 4px 0 #3f22b8,
    0 8px 18px rgba(104, 66, 255, 0.4);
}
.pk-btn-primary:active {
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.3),
    0 1px 0 #3f22b8;
}
.pk-btn-green {
  background: linear-gradient(180deg, #4be08f, #16a95b);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.35),
    0 4px 0 #0b6e39,
    0 8px 18px rgba(30, 200, 110, 0.3);
}
.pk-btn-green:active {
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.35),
    0 1px 0 #0b6e39;
}
.pk-btn-wide {
  width: 100%;
}
.pk-modes .pk-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 54px;
}
.pk-mode-best {
  font-size: 12px;
  font-weight: 800;
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.22);
  white-space: nowrap;
}
.pk-keys {
  margin: 12px 0 0;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  line-height: 1.8;
}
kbd {
  display: inline-block;
  min-width: 20px;
  padding: 0 5px;
  margin: 0 1px;
  border-radius: 6px;
  background: #2a2b3d;
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.35);
  font: inherit;
  font-weight: 900;
  color: var(--text);
  line-height: 1.5;
}
.pk-kicker {
  margin: 0;
  font-weight: 900;
  font-size: 20px;
  color: var(--gold);
  letter-spacing: 0.02em;
}
.pk-versus {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin: 12px 0 6px;
}
.pk-crest {
  width: 62px;
  height: 70px;
  display: grid;
  place-items: center;
  font-size: 28px;
  font-weight: 900;
  color: #fff;
  clip-path: polygon(50% 0, 100% 14%, 100% 58%, 50% 100%, 0 58%, 0 14%);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.35), rgba(255, 255, 255, 0) 55%), var(--crest, var(--accent));
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.3);
}
.pk-vs {
  font-weight: 900;
  font-size: 20px;
  color: var(--muted);
}
.pk-intro-team {
  margin: 4px 0 0;
  font-weight: 900;
  font-size: 20px;
}
.pk-ladder {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin: 0 0 14px;
}
.pk-rung {
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 900;
  background: #2a2b3d;
  color: var(--muted);
}
.pk-rung.is-done {
  background: #1d6b43;
  color: #c9f7d8;
}
.pk-rung.is-now {
  background: var(--gold);
  color: #3a2800;
}
.pk-trophy {
  display: block;
  width: 96px;
  height: 96px;
  margin: -6px auto 2px;
  animation: pk-float 1.6s ease-in-out infinite;
}
.pk-trophy[hidden] {
  display: none;
}
.pk-big {
  margin: 4px 0 0;
  font-size: 56px;
  font-weight: 900;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  text-shadow:
    0 4px 0 #3f22b8,
    0 10px 24px rgba(104, 66, 255, 0.55);
}
.pk-newbest {
  display: inline-block;
  margin: 10px 0 0;
  padding: 4px 12px;
  border-radius: 999px;
  background: linear-gradient(180deg, #ffe066, #ffb800);
  color: #4a2c00;
  font-weight: 900;
  font-size: 13px;
  animation: pk-bump 0.6s ease 0.2s both;
}
.pk-newbest[hidden] {
  display: none;
}
.pk-over-stats {
  margin: 10px 0 14px;
  color: var(--muted);
  font-weight: 700;
  font-size: 14px;
  line-height: 1.4;
}

.pk-help {
  margin: 0;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  text-align: center;
  line-height: 1.5;
}

button:focus-visible {
  outline: 3px solid #b9a8ff;
  outline-offset: 3px;
}

@keyframes pk-bump {
  0% {
    transform: scale(1);
  }
  40% {
    transform: scale(1.12);
  }
  100% {
    transform: scale(1);
  }
}
@keyframes pk-pulse {
  50% {
    transform: scale(1.25);
  }
}
@keyframes pk-shake {
  0%,
  100% {
    transform: translate(0, 0);
  }
  20% {
    transform: translate(-7px, 2px);
  }
  40% {
    transform: translate(6px, -2px);
  }
  60% {
    transform: translate(-4px, 1px);
  }
  80% {
    transform: translate(2px, 0);
  }
}
@keyframes pk-pop-in {
  from {
    transform: scale(0.85);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}
@keyframes pk-float {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-7px);
  }
}
@keyframes pk-banner {
  0% {
    transform: translate(-50%, -50%) scale(0.2) rotate(-8deg);
    opacity: 0;
  }
  18% {
    transform: translate(-50%, -50%) scale(1.15) rotate(2deg);
    opacity: 1;
  }
  30% {
    transform: translate(-50%, -50%) scale(1) rotate(0);
  }
  80% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -64%) scale(0.95);
  }
}

@media (max-width: 520px) {
  .pk-chip-round {
    display: none;
  }
  .pk-dot {
    width: 9px;
    height: 9px;
  }
  .pk-score {
    font-size: 18px;
  }
  .pk-board {
    gap: 5px;
    padding: 4px 6px;
  }
  .pk-team {
    font-size: 10px;
    padding: 3px 5px;
  }
  .pk-title {
    font-size: 34px;
  }
}
@media (max-width: 360px) {
  .pk-dots {
    gap: 2px;
  }
  .pk-dot {
    width: 7px;
    height: 7px;
  }
  .pk-chip strong {
    font-size: 15px;
  }
}
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001s !important;
    animation-iteration-count: 1 !important;
    transition: none !important;
  }
}
.pk-pad-group {
  display: flex;
  gap: 10px;
}
.pk-keeper-pad.is-split {
  left: 12px;
  right: 12px;
  transform: none;
  justify-content: space-between;
  padding: 0;
  background: none;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}
.pk-keeper-pad.is-split .pk-pad-group {
  padding: 6px;
  border-radius: 999px;
  background: rgba(15, 16, 32, 0.55);
}
.pk-banner.is-static {
  animation: none;
}
@media (max-width: 360px) {
  .pk-dive {
    width: 46px;
    height: 46px;
  }
  .pk-keeper-pad,
  .pk-pad-group {
    gap: 6px;
  }
}
