:root {
  color-scheme: light;
  font-family:
    "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  --ink: #583a5e;
  --pink: #ee6f9f;
  --pink-deep: #d94b85;
  --cream: #fffaf1;
}

* {
  box-sizing: border-box;
}

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

body {
  display: grid;
  place-items: center;
  min-height: 100dvh;
  background:
    radial-gradient(circle at 18% 12%, rgba(255, 255, 255, 0.9), transparent 26%),
    radial-gradient(circle at 85% 82%, rgba(205, 242, 255, 0.85), transparent 32%),
    linear-gradient(145deg, #ffe8f0, #f2eaff 48%, #dcf7ff);
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}

.game-shell {
  position: relative;
  width: min(480px, 100vw, calc((100dvh - 8px) * 0.533333));
  aspect-ratio: 8 / 15;
  max-height: calc(100dvh - 8px);
  overflow: hidden;
  border-radius: clamp(0px, 3vw, 30px);
  background: #fff6fb;
  box-shadow:
    0 24px 70px rgba(79, 49, 90, 0.22),
    inset 0 0 0 1px rgba(255, 255, 255, 0.9);
  isolation: isolate;
}

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

.overlay-panel {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(86, 54, 94, 0.2);
  backdrop-filter: blur(10px);
  transition: opacity 180ms ease;
}

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

.panel-card {
  position: relative;
  width: 100%;
  max-height: 100%;
  overflow: auto;
  padding: 26px 24px;
  border: 2px solid rgba(255, 255, 255, 0.9);
  border-radius: 30px;
  background:
    radial-gradient(circle at 92% 8%, rgba(255, 225, 116, 0.38), transparent 22%),
    linear-gradient(155deg, rgba(255, 255, 255, 0.97), rgba(255, 248, 252, 0.95));
  box-shadow: 0 20px 52px rgba(74, 42, 83, 0.25);
  text-align: center;
  scrollbar-width: none;
}

.panel-card::-webkit-scrollbar {
  display: none;
}

.eyebrow {
  color: #b86890;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.18em;
}

.mascot,
.result-crown {
  display: grid;
  place-items: center;
  width: 66px;
  height: 66px;
  margin: 8px auto 4px;
  border: 2px solid rgba(255, 255, 255, 0.95);
  border-radius: 24px;
  background: linear-gradient(145deg, #ffe490, #ffb8ce);
  box-shadow: 0 9px 20px rgba(214, 105, 145, 0.23);
  font-size: 36px;
  transform: rotate(-3deg);
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 8px;
  color: #583a5e;
  font-size: clamp(27px, 7.2vw, 38px);
  line-height: 1.12;
  letter-spacing: -0.04em;
}

h2 {
  margin-bottom: 8px;
  font-size: 28px;
}

.intro,
.leaderboard-card > p,
#resultMessage {
  margin-bottom: 18px;
  color: #7b627f;
  font-size: 14px;
  line-height: 1.6;
}

.name-field {
  display: block;
  margin-bottom: 13px;
  text-align: left;
}

.name-field span {
  display: block;
  margin: 0 0 6px 4px;
  color: #846987;
  font-size: 12px;
  font-weight: 800;
}

.name-field input {
  width: 100%;
  height: 48px;
  padding: 0 16px;
  border: 2px solid #f3d7e4;
  border-radius: 16px;
  outline: none;
  background: #fff;
  color: #593d60;
  font: inherit;
  font-size: 16px;
  font-weight: 800;
  text-align: center;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

.name-field input:focus {
  border-color: #ec83aa;
  box-shadow: 0 0 0 4px rgba(236, 131, 170, 0.15);
}

button {
  font: inherit;
}

.primary-button {
  width: 100%;
  min-height: 50px;
  border: 0;
  border-radius: 17px;
  background: linear-gradient(135deg, #f27ca7, #dc4e8a);
  box-shadow: 0 9px 20px rgba(216, 75, 133, 0.28);
  color: white;
  font-size: 16px;
  font-weight: 900;
  letter-spacing: 0.04em;
  cursor: pointer;
}

.primary-button:active {
  transform: translateY(2px);
  box-shadow: 0 5px 12px rgba(216, 75, 133, 0.24);
}

.rules {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 17px 0;
}

.rules div {
  min-width: 0;
  padding: 10px 5px 9px;
  border: 1px solid #f3e1e9;
  border-radius: 16px;
  background: #fffafd;
}

.rules div > span {
  display: block;
  margin-bottom: 3px;
  font-size: 21px;
}

.rules b,
.rules small {
  display: block;
}

.rules b {
  font-size: 12px;
}

.rules small {
  margin-top: 3px;
  color: #947c97;
  font-size: 9px;
  line-height: 1.3;
}

.mini-ranking,
.result-ranking {
  padding: 12px 14px;
  border-radius: 17px;
  background: #fff3f8;
  text-align: left;
}

.mini-ranking h2,
.result-ranking h3 {
  margin-bottom: 7px;
  color: #8b5877;
  font-size: 12px;
  text-align: center;
}

ol {
  margin: 0;
  padding: 0;
  list-style: none;
}

.ranking-row {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) auto;
  align-items: center;
  min-height: 28px;
  gap: 7px;
  color: #715674;
  font-size: 12px;
}

.ranking-row .rank {
  font-weight: 900;
  text-align: center;
}

.ranking-row .player {
  overflow: hidden;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ranking-row .points {
  color: #d55087;
  font-weight: 900;
}

.ranking-empty {
  padding: 5px;
  color: #a38da5;
  font-size: 11px;
  text-align: center;
}

.result-card {
  padding-top: 24px;
}

.result-crown {
  margin-top: 0;
  background: linear-gradient(145deg, #fff2a4, #ffc16e);
  transform: rotate(3deg);
}

.final-score {
  margin: 8px 0 13px;
  padding: 13px;
  border-radius: 20px;
  background: linear-gradient(135deg, #fff1b8, #ffd2e1);
}

.final-score span,
.final-score strong {
  display: block;
}

.final-score span {
  color: #876179;
  font-size: 12px;
  font-weight: 800;
}

.final-score strong {
  color: #cc437c;
  font-size: 38px;
  line-height: 1.1;
}

.result-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
  margin-bottom: 13px;
}

.result-stats div {
  padding: 10px;
  border: 1px solid #f0dce6;
  border-radius: 16px;
  background: white;
}

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

.result-stats b {
  color: #6a4771;
  font-size: 22px;
}

.result-stats span {
  color: #9a849c;
  font-size: 10px;
}

.result-ranking {
  margin-bottom: 13px;
}

.text-button {
  margin-top: 9px;
  border: 0;
  background: transparent;
  color: #9b6f8b;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
}

.leaderboard-card {
  padding-top: 30px;
}

.leaderboard-card ol {
  padding: 8px 13px;
  border-radius: 18px;
  background: #fff5f9;
}

.leaderboard-card .ranking-row {
  min-height: 34px;
  border-bottom: 1px dashed #efdce5;
  font-size: 13px;
}

.leaderboard-card .ranking-row:last-child {
  border-bottom: 0;
}

.close-button {
  position: absolute;
  top: 13px;
  right: 13px;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  background: #f8e9f0;
  color: #815e78;
  font-size: 25px;
  line-height: 1;
  cursor: pointer;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-height: 740px) {
  .overlay-panel {
    padding: 12px;
  }

  .panel-card {
    padding: 18px;
    border-radius: 24px;
  }

  .mascot,
  .result-crown {
    width: 54px;
    height: 54px;
    font-size: 29px;
  }

  .intro {
    margin-bottom: 11px;
  }

  .rules {
    margin: 10px 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
