:root {
  color-scheme: light;
  font-family: "Arial Rounded MT Bold", "Noto Sans TC", "PingFang TC", system-ui, sans-serif;
  --ink: #243642;
  --red: #a73430;
  --yellow: #f9d54a;
  --cream: #fff8dc;
  --sky: #8bd7ee;
  --blue: #2876a1;
}

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

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

body {
  position: fixed;
  inset: 0;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

button {
  font: inherit;
}

.game {
  position: relative;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  isolation: isolate;
  background:
    radial-gradient(circle at 20% 18%, rgb(255 255 255 / 0.34) 0 2px, transparent 3px),
    linear-gradient(#8bd7ee 0 73%, #f0c96d 73% 100%);
  background-size: 28px 28px, auto;
}

#gameCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.hud {
  position: absolute;
  z-index: 8;
  top: max(13px, env(safe-area-inset-top));
  left: 50%;
  display: grid;
  justify-items: center;
  transform: translateX(-50%);
  color: var(--ink);
  opacity: 0;
  pointer-events: none;
  transition: opacity 120ms ease;
}

.hud.is-visible {
  opacity: 1;
}

.score-wrap {
  display: grid;
  justify-items: center;
  min-width: 106px;
  padding: 5px 18px 7px;
  border: 4px solid var(--ink);
  border-radius: 14px;
  background: rgb(255 248 220 / 0.94);
  box-shadow: 0 5px 0 rgb(36 54 66 / 0.22);
}

.hud-label {
  font-size: 0.72rem;
  letter-spacing: 0.19em;
  line-height: 1;
}

#score {
  font-family: Impact, "Arial Black", sans-serif;
  font-size: clamp(2.45rem, 12vw, 4.3rem);
  line-height: 0.96;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}

.hud-best {
  margin-top: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--ink);
  color: white;
  font-size: 0.78rem;
  letter-spacing: 0.08em;
}

.sound-button {
  position: absolute;
  z-index: 30;
  top: max(14px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  min-height: 42px;
  padding: 8px 11px;
  border: 3px solid var(--ink);
  border-radius: 12px;
  background: rgb(255 248 220 / 0.94);
  color: var(--ink);
  box-shadow: 0 4px 0 rgb(36 54 66 / 0.22);
  font-weight: 900;
  font-size: 0.82rem;
}

.sound-button:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 rgb(36 54 66 / 0.22);
}

.timing {
  position: absolute;
  z-index: 15;
  top: max(148px, 18dvh);
  left: 50%;
  width: max-content;
  max-width: 90vw;
  transform: translateX(-50%) scale(0.7) rotate(-2deg);
  opacity: 0;
  color: #fff;
  font-family: Impact, "Arial Black", sans-serif;
  font-size: clamp(2.15rem, 11vw, 4.3rem);
  line-height: 1;
  letter-spacing: 0.035em;
  -webkit-text-stroke: 7px var(--ink);
  paint-order: stroke fill;
  text-shadow: 0 6px 0 rgb(36 54 66 / 0.22);
  pointer-events: none;
}

.timing.show {
  animation: timing-pop 520ms cubic-bezier(0.16, 1, 0.3, 1) both;
}

.timing.god,
.timing.kutar {
  color: var(--yellow);
}

.timing.perfect {
  color: #ff8274;
}

@keyframes timing-pop {
  0% { opacity: 0; transform: translateX(-50%) scale(0.55) rotate(-5deg); }
  22% { opacity: 1; transform: translateX(-50%) scale(1.16) rotate(2deg); }
  62% { opacity: 1; transform: translateX(-50%) scale(1) rotate(-1deg); }
  100% { opacity: 0; transform: translateX(-50%) scale(0.88) translateY(-18px); }
}

.ready {
  position: absolute;
  z-index: 18;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--yellow);
  font-family: Impact, "Arial Black", sans-serif;
  font-size: clamp(4rem, 21vw, 8rem);
  letter-spacing: 0.04em;
  -webkit-text-stroke: 9px var(--ink);
  paint-order: stroke fill;
  text-shadow: 0 10px 0 rgb(36 54 66 / 0.2);
  pointer-events: none;
  opacity: 0;
}

.ready.show {
  animation: ready-pop 360ms ease-out both;
}

@keyframes ready-pop {
  0% { opacity: 0; transform: scale(0.5); }
  40% { opacity: 1; transform: scale(1.12); }
  100% { opacity: 1; transform: scale(1); }
}

.impact {
  position: absolute;
  z-index: 20;
  left: 50%;
  top: 48%;
  opacity: 0;
  color: #fff;
  font-size: clamp(3rem, 16vw, 6.5rem);
  font-weight: 1000;
  -webkit-text-stroke: 7px var(--red);
  paint-order: stroke fill;
  pointer-events: none;
}

.impact.show {
  animation: impact 520ms ease-out both;
}

@keyframes impact {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.4) rotate(-12deg); }
  25% { opacity: 1; transform: translate(-50%, -50%) scale(1.3) rotate(7deg); }
  100% { opacity: 0; transform: translate(-50%, -75%) scale(0.9) rotate(-3deg); }
}

.screen {
  position: absolute;
  z-index: 25;
  inset: 0;
  min-height: 100%;
  padding:
    max(18px, env(safe-area-inset-top))
    max(18px, env(safe-area-inset-right))
    max(18px, env(safe-area-inset-bottom))
    max(18px, env(safe-area-inset-left));
}

.screen[hidden] {
  display: none;
}

.start-screen {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  justify-items: center;
  gap: 4px;
  background:
    linear-gradient(180deg, rgb(139 215 238 / 0.04), rgb(139 215 238 / 0.34) 55%, rgb(240 201 109 / 0.9) 77%);
}

.title-lockup {
  align-self: start;
  margin-top: 3.5dvh;
  text-align: center;
  transform: rotate(-1deg);
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--blue);
  font-weight: 1000;
  font-size: clamp(0.72rem, 3vw, 0.95rem);
  letter-spacing: 0.18em;
}

h1 {
  margin: 0;
  color: var(--cream);
  font-size: clamp(2.25rem, 11.5vw, 4.6rem);
  line-height: 1.02;
  letter-spacing: -0.055em;
  -webkit-text-stroke: 7px var(--ink);
  paint-order: stroke fill;
  text-shadow: 0 8px 0 var(--red);
}

h1 span {
  color: var(--yellow);
}

.start-character {
  align-self: end;
  width: min(72vw, 320px);
  height: min(48dvh, 430px);
  object-fit: contain;
  object-position: center bottom;
  filter: drop-shadow(0 12px 0 rgb(36 54 66 / 0.14));
  pointer-events: none;
}

.start-card,
.result-card {
  width: min(100%, 390px);
  border: 4px solid var(--ink);
  border-radius: 24px;
  background: rgb(255 248 220 / 0.97);
  box-shadow: 0 8px 0 rgb(36 54 66 / 0.24);
}

.start-card {
  position: relative;
  padding: 20px 18px 17px;
  text-align: center;
}

.start-card p {
  margin: 7px 0 14px;
  color: var(--ink);
  font-size: clamp(1rem, 4.4vw, 1.2rem);
  font-weight: 900;
  line-height: 1.45;
}

.best-card {
  position: absolute;
  top: -20px;
  left: 50%;
  min-width: 126px;
  padding: 6px 14px;
  border: 3px solid var(--ink);
  border-radius: 999px;
  background: var(--yellow);
  color: var(--ink);
  transform: translateX(-50%);
  font-weight: 1000;
  letter-spacing: 0.06em;
}

.primary-button {
  width: 100%;
  min-height: 62px;
  border: 4px solid var(--ink);
  border-radius: 17px;
  background: var(--red);
  color: white;
  box-shadow: 0 6px 0 #63231f;
  font-family: Impact, "Arial Black", sans-serif;
  font-size: clamp(1.65rem, 7vw, 2.25rem);
  letter-spacing: 0.055em;
  cursor: pointer;
}

.primary-button:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 #63231f;
}

.result-screen {
  display: grid;
  place-items: center;
  background: rgb(36 54 66 / 0.42);
  backdrop-filter: blur(3px);
}

.result-card {
  max-height: calc(100dvh - max(36px, env(safe-area-inset-top) + env(safe-area-inset-bottom)));
  overflow-y: auto;
  padding: 18px 17px 16px;
  text-align: center;
  scrollbar-width: none;
}

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

.game-over {
  margin: 0;
  color: var(--red);
  font-family: Impact, "Arial Black", sans-serif;
  font-size: clamp(2.25rem, 10vw, 3.6rem);
  line-height: 1;
  letter-spacing: 0.055em;
}

.new-record {
  margin: 9px auto 2px;
  width: max-content;
  padding: 5px 12px;
  border: 3px solid var(--ink);
  border-radius: 999px;
  background: var(--yellow);
  color: var(--red);
  font-family: Impact, "Arial Black", sans-serif;
  font-size: 1.25rem;
  letter-spacing: 0.06em;
  animation: record-bounce 650ms ease-in-out infinite alternate;
}

@keyframes record-bounce {
  to { transform: scale(1.06) rotate(1.5deg); }
}

.result-score {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 8px;
  margin: 8px 0 0;
  color: var(--ink);
  font-weight: 900;
}

.result-score strong {
  color: var(--red);
  font-family: Impact, "Arial Black", sans-serif;
  font-size: clamp(4rem, 18vw, 6rem);
  line-height: 0.96;
  font-variant-numeric: tabular-nums;
}

.result-best {
  margin: 0 0 9px;
  color: var(--blue);
  font-weight: 1000;
  letter-spacing: 0.08em;
}

.stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  padding: 9px;
  border: 3px solid var(--ink);
  border-radius: 14px;
  background: #fff;
}

.stat {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-width: 0;
  padding: 4px 7px;
  border-radius: 7px;
  background: #e9f8fc;
  color: var(--ink);
  font-family: Impact, "Arial Black", sans-serif;
  font-size: 0.92rem;
  letter-spacing: 0.025em;
}

.stat strong {
  color: var(--red);
  font-size: 1.02rem;
}

.comment {
  min-height: 3em;
  margin: 12px 2px;
  color: var(--ink);
  font-size: clamp(1.05rem, 4.6vw, 1.28rem);
  font-weight: 1000;
  line-height: 1.45;
}

.tap-hint {
  position: absolute;
  z-index: 9;
  bottom: max(13px, env(safe-area-inset-bottom));
  left: 50%;
  width: max-content;
  max-width: 90vw;
  margin: 0;
  padding: 7px 13px;
  border-radius: 999px;
  background: rgb(36 54 66 / 0.86);
  color: #fff;
  transform: translateX(-50%);
  font-size: 0.85rem;
  font-weight: 900;
  pointer-events: none;
  animation: hint-fade 3.8s forwards;
}

@keyframes hint-fade {
  0%, 65% { opacity: 1; }
  100% { opacity: 0; }
}

.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;
}

.game.shake {
  animation: screen-shake 380ms linear;
}

@keyframes screen-shake {
  0%, 100% { transform: translate(0); }
  16% { transform: translate(-7px, 2px); }
  32% { transform: translate(7px, -3px); }
  50% { transform: translate(-5px, -1px); }
  68% { transform: translate(4px, 2px); }
  84% { transform: translate(-2px, 0); }
}

@media (max-height: 690px) {
  .title-lockup { margin-top: 0; }
  .start-character { height: 39dvh; }
  .start-card { padding-top: 16px; }
  .start-card p { margin: 5px 0 9px; line-height: 1.28; }
  .primary-button { min-height: 54px; }
  .result-card { padding-top: 13px; }
  .comment { margin: 8px 0; }
}

@media (min-width: 680px) {
  .game {
    width: min(100vw, 520px);
    margin-inline: auto;
    border-inline: 2px solid rgb(36 54 66 / 0.22);
  }
}

@media (prefers-reduced-motion: reduce) {
  .new-record { animation-duration: 1.4s; }
  .game.shake { animation: none; }
}
