:root {
  color-scheme: light;
  font-family:
    "Hiragino Sans", "Yu Gothic", "Meiryo", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  background: #f7f3e8;
  color: #171717;
  --yellow: #f7c72e;
  --ink: #171717;
  --paper: #fffdf7;
  --mint: #8be0d4;
  --red: #f15d4a;
}

* {
  box-sizing: border-box;
}

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

body {
  min-height: 100dvh;
  overflow: hidden;
  touch-action: none;
  background:
    radial-gradient(circle at 16% 12%, rgba(139, 224, 212, 0.55), transparent 24rem),
    linear-gradient(135deg, #fff8dc 0%, #f4c944 38%, #121212 38%, #121212 42%, #fff9ea 42%, #ffffff 100%);
}

button {
  font: inherit;
}

.shell {
  width: 100%;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right))
    max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
}

.game-wrap {
  width: min(100%, 860px);
  display: grid;
  gap: 10px;
}

.topbar,
.controls {
  width: 100%;
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 3px solid var(--ink);
  border-radius: 8px;
  background: rgba(255, 253, 247, 0.92);
  box-shadow: 0 6px 0 var(--ink);
}

.kicker {
  margin: 0 0 2px;
  font-size: 0.68rem;
  font-weight: 900;
  letter-spacing: 0;
}

h1 {
  margin: 0;
  font-size: clamp(1.05rem, 4.8vw, 2rem);
  line-height: 1.05;
}

.stats {
  flex: 0 0 auto;
  display: flex;
  gap: 8px;
  font-weight: 900;
}

.stats span {
  min-width: 64px;
  padding: 8px 10px;
  text-align: center;
  color: #fff;
  background: var(--ink);
  border-radius: 6px;
}

.stats strong {
  color: var(--yellow);
}

.stage {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 10;
  max-height: calc(100dvh - 154px);
  min-height: 360px;
  overflow: hidden;
  border: 4px solid var(--ink);
  border-radius: 8px;
  background: #fffdf7;
  box-shadow: 0 8px 0 var(--ink);
  touch-action: none;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.serve-hint {
  position: absolute;
  left: 50%;
  bottom: 18%;
  z-index: 1;
  min-width: min(76%, 340px);
  padding: 10px 14px;
  border: 3px solid var(--ink);
  border-radius: 8px;
  color: var(--ink);
  background: rgba(247, 199, 46, 0.96);
  box-shadow: 0 5px 0 var(--ink);
  font-weight: 900;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 10px);
  transition:
    opacity 160ms ease,
    transform 160ms ease;
}

.serve-hint.is-open {
  opacity: 1;
  transform: translate(-50%, 0);
}

.message {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 10px;
  padding: 18px;
  text-align: center;
  background: rgba(255, 253, 247, 0.9);
  opacity: 0;
  pointer-events: none;
  transform: scale(1.04);
  transition:
    opacity 180ms ease,
    transform 180ms ease;
}

.message.is-open {
  opacity: 1;
  pointer-events: auto;
  transform: scale(1);
}

.message.is-win img {
  width: min(38vw, 230px);
  animation: pop 680ms cubic-bezier(0.16, 1, 0.3, 1) both;
}

.message img {
  width: min(32vw, 170px);
  max-width: 62%;
  border: 3px solid var(--ink);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 6px 0 var(--ink);
  object-fit: cover;
}

.message h2 {
  max-width: 680px;
  margin: 0;
  font-size: clamp(1.35rem, 6vw, 3rem);
  line-height: 1.02;
}

.message p {
  max-width: 520px;
  margin: 0;
  font-weight: 800;
  line-height: 1.5;
}

.message button,
.control-btn {
  min-width: 56px;
  min-height: 46px;
  border: 3px solid var(--ink);
  border-radius: 8px;
  color: var(--ink);
  background: var(--yellow);
  box-shadow: 0 5px 0 var(--ink);
  font-weight: 900;
  cursor: pointer;
}

.message button {
  min-width: 156px;
  padding: 10px 18px;
}

.message button:active,
.control-btn:active {
  transform: translateY(4px);
  box-shadow: 0 1px 0 var(--ink);
}

.controls {
  justify-content: flex-start;
}

.hint {
  margin-left: auto;
  font-weight: 900;
  white-space: nowrap;
}

@keyframes pop {
  0% {
    transform: translateY(130px) scale(0.35) rotate(-8deg);
  }
  62% {
    transform: translateY(-12px) scale(1.08) rotate(3deg);
  }
  100% {
    transform: translateY(0) scale(1) rotate(0deg);
  }
}

@media (max-width: 640px) {
  .shell {
    align-items: start;
  }

  .game-wrap {
    gap: 8px;
  }

  .topbar,
  .controls {
    min-height: 52px;
    padding: 8px;
    box-shadow: 0 4px 0 var(--ink);
  }

  .stage {
    aspect-ratio: 10 / 15;
    min-height: 0;
    height: calc(100dvh - 172px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    max-height: none;
    box-shadow: 0 5px 0 var(--ink);
  }

  .stats span {
    min-width: 52px;
    padding: 7px 8px;
  }

  .kicker {
    display: none;
  }

  .hint {
    font-size: 0.82rem;
  }
}
