:root {
  --app-height: 100vh;
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  color: #27343a;
  background: #d9f0f7;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

* { box-sizing: border-box; }

html, body {
  position: fixed;
  inset: 0;
  margin: 0;
  width: 100%;
  height: var(--app-height);
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-overflow-scrolling: auto;
  -webkit-touch-callout: none;
}

body {
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 50% 10%, rgba(255,255,255,.95), transparent 32rem),
    #d7eef5;
}

button { font: inherit; -webkit-tap-highlight-color: transparent; }

.game-shell {
  position: relative;
  height: var(--app-height);
  max-height: 1000px;
  width: min(100vw, 500px);
  overflow: hidden;
  background: #acd9e9;
  box-shadow: 0 0 40px rgba(44, 81, 94, .18);
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: pointer;
}

#game:active { cursor: pointer; }

.corner {
  position: absolute;
  z-index: 5;
  top: env(safe-area-inset-top, 0px);
  width: 72px;
  height: 72px;
  padding: 9px 17px 19px 9px;
  border: 0;
  background: rgba(255,255,255,.96);
  color: #d34d57;
  cursor: pointer;
}

.corner svg { width: 35px; height: 35px; fill: currentColor; }
.corner-left { left: 0; border-radius: 0 0 100% 0; }
.corner-right { right: 0; padding: 9px 9px 19px 17px; border-radius: 0 0 0 100%; color: #3a9270; }
.corner:active { transform: scale(.96); }

.tutorial {
  position: absolute;
  z-index: 20;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding:
    max(30px, env(safe-area-inset-top, 0px))
    max(30px, env(safe-area-inset-right, 0px))
    max(30px, env(safe-area-inset-bottom, 0px))
    max(30px, env(safe-area-inset-left, 0px));
  color: white;
  text-align: center;
  background: rgba(28, 47, 56, .72);
  backdrop-filter: blur(1.5px);
  transition: opacity .25s ease, visibility .25s ease;
}

.tutorial.is-hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.tutorial strong { margin-top: 8px; font-size: clamp(28px, 8vw, 40px); letter-spacing: 2px; }
.tutorial span { font-size: clamp(16px, 4.8vw, 22px); font-weight: 700; }
.tutorial small { margin-top: 2px; font-size: 14px; opacity: .82; }
.tutorial button {
  margin-top: 22px;
  min-width: 150px;
  padding: 13px 28px;
  border: 0;
  border-radius: 999px;
  color: #2f5f51;
  background: #fff;
  box-shadow: 0 5px 0 rgba(0,0,0,.16);
  font-size: 18px;
  font-weight: 800;
  cursor: pointer;
}

.tutorial-art { position: relative; width: 130px; height: 205px; }
.gesture-line {
  position: absolute;
  left: 62px;
  top: 0;
  width: 7px;
  height: 112px;
  border-radius: 99px;
  background: repeating-linear-gradient(to top, white 0 13px, transparent 13px 23px);
  animation: linePulse 1.35s ease-in-out infinite;
}
.gesture-line::before {
  content: "";
  position: absolute;
  top: -3px;
  left: -9px;
  width: 20px;
  height: 20px;
  border-left: 7px solid white;
  border-top: 7px solid white;
  transform: rotate(45deg);
}
.gesture-hand {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 122px;
  height: 142px;
  animation: handMove 1.35s ease-in-out infinite;
}
.gesture-hand svg { filter: drop-shadow(0 4px 0 rgba(0,0,0,.16)); }
.gesture-hand path { fill: white; stroke: #4764aa; stroke-width: 7; stroke-linejoin: round; }

.result {
  position: absolute;
  z-index: 15;
  inset: 0;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  overflow: hidden;
  pointer-events: none;
  background: transparent;
  animation: resultIn .18s ease-out;
}
.result:not([hidden]) { display: flex; }
.celebration-burst {
  position: absolute;
  z-index: 1;
  top: 39%;
  left: 50%;
  width: 280px;
  height: 280px;
  transform: translate(-50%, -50%);
  overflow: visible;
  animation: burstIn .52s .08s cubic-bezier(.2,1.4,.4,1) both;
}
.celebration-burst path {
  fill: none;
  stroke-linecap: round;
}
.celebration-burst .ray-outline path { stroke: white; stroke-width: 15; }
.celebration-burst .ray-core path { stroke: #4b65ad; stroke-width: 7; }
.thumb {
  position: absolute;
  z-index: 2;
  top: 29%;
  left: 50%;
  width: 205px;
  height: 205px;
  transform: translateX(-50%);
  animation: thumbPop .62s cubic-bezier(.16,1.65,.32,1) both;
}
.thumb svg { overflow: visible; filter: drop-shadow(0 5px 0 rgba(255,255,255,.98)); }
.thumb path { fill: white; stroke: #4b65ad; stroke-width: 8; stroke-linejoin: round; }
.result-actions {
  position: absolute;
  z-index: 4;
  top: calc(env(safe-area-inset-top, 0px) - 5px);
  left: 50%;
  display: flex;
  gap: 16px;
  transform: translateX(-50%);
  animation: actionsDrop .45s cubic-bezier(.2,1.2,.4,1) both;
  pointer-events: auto;
}
.result-actions button {
  display: grid;
  place-items: center;
  width: 82px;
  height: 105px;
  border: 0;
  padding: 20px 0 9px;
  border-radius: 0 0 30px 30px;
  color: #d48b16;
  background: white;
  box-shadow: 0 6px 0 rgba(48, 82, 95, .12);
  font-size: 45px;
  font-weight: 900;
  cursor: pointer;
}
.result-actions button:active { transform: translateY(4px); box-shadow: 0 2px 0 rgba(48,82,95,.12); }
.result-actions span { display: none; }
.cheer-friend {
  position: absolute;
  z-index: 3;
  right: -13px;
  bottom: 6%;
  width: 150px;
  height: 135px;
  animation: friendSlide .55s .2s cubic-bezier(.2,1.35,.4,1) both;
}
.friend-body { fill: #fffefb; stroke: #22272a; stroke-width: 4; stroke-linejoin: round; }
.friend-smile { fill: none; stroke: #22272a; stroke-width: 3; stroke-linecap: round; }
.blush { fill: #f59aaa; }
.good-sign rect { fill: #f2c77e; stroke: #22272a; stroke-width: 4; }
.good-sign text { fill: #34302b; font-size: 17px; font-weight: 900; text-anchor: middle; font-family: system-ui, sans-serif; }

.toast {
  position: absolute;
  z-index: 30;
  left: 50%;
  bottom: calc(7% + env(safe-area-inset-bottom, 0px));
  min-width: 150px;
  padding: 10px 16px;
  border-radius: 999px;
  color: white;
  background: rgba(39,52,58,.82);
  text-align: center;
  font-weight: 700;
  opacity: 0;
  transform: translate(-50%, 12px);
  pointer-events: none;
  transition: .2s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@keyframes handMove { 0%,100% { transform: translateY(25px); } 50% { transform: translateY(-25px); } }
@keyframes linePulse { 0%,100% { opacity: .4; } 50% { opacity: 1; } }
@keyframes resultIn { from { opacity: 0; } }
@keyframes thumbPop {
  0% { transform: translateX(-50%) scale(.15) rotate(-15deg); opacity: 0; }
  65% { transform: translateX(-50%) scale(1.12) rotate(3deg); opacity: 1; }
  100% { transform: translateX(-50%) scale(1) rotate(0); opacity: 1; }
}
@keyframes burstIn {
  0% { transform: translate(-50%, -50%) scale(.25) rotate(-15deg); opacity: 0; }
  100% { transform: translate(-50%, -50%) scale(1) rotate(0); opacity: 1; }
}
@keyframes actionsDrop { from { transform: translate(-50%, -115px); } to { transform: translate(-50%, 0); } }
@keyframes friendSlide { from { transform: translate(150px, 45px) rotate(12deg); opacity: 0; } to { transform: translate(0, 0) rotate(-4deg); opacity: 1; } }

@media (max-height: 650px) {
  .tutorial-art { transform: scale(.75); margin-bottom: -22px; }
  .tutorial button { margin-top: 10px; }
  .thumb { width: 150px; height: 150px; }
  .celebration-burst { width: 210px; height: 210px; }
  .result-actions button { width: 68px; height: 84px; font-size: 36px; }
}

@supports (height: 100dvh) {
  :root { --app-height: 100dvh; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; }
}
