/* 奶蛙 · 样式
   坐标约定：--u = 素材里的 1 像素（素材 270×470），所以局部图层都写成 calc(var(--u) * 素材坐标) */

:root {
  --frog-h: min(56vh, 470px, 150vw);
  --u: calc(var(--frog-h) / 470);
  --ink: #3a6709;
  --ink-2: #3f6b0e;
  --glow: #86b623;
}
@supports (height: 1svh) {
  :root { --frog-h: min(56svh, 470px, 150vw); }
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
  font-family: -apple-system, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  color: var(--ink);
}
button { font: inherit; color: inherit; }

/* ---------- 背景 ---------- */
.bg {
  position: fixed; inset: 0; z-index: -1; overflow: hidden;
  background: radial-gradient(circle at 50% 38%, #f7ffd4 0%, #dcf28a 26%, #aad83c 58%, #6ea21c 100%);
}
.bg-fever {
  position: absolute; inset: 0; opacity: 0; transition: opacity .6s ease;
  background: radial-gradient(circle at 50% 38%, #fffbe0 0%, #ffe56e 28%, #ffbe3a 62%, #f08a1c 100%);
}
body.lvl-3 .bg-fever, body.lvl-4 .bg-fever { opacity: .82; }

/* 集中线：只在连笑高潮时挂载，平时 display:none 不占合成层 */
.rays {
  display: none;
  position: absolute; left: 50%; top: 38%;
  width: 140vmax; height: 140vmax; margin: -70vmax 0 0 -70vmax;
  background: repeating-conic-gradient(rgba(255,255,255,.26) 0 7deg, rgba(255,255,255,0) 7deg 20deg);
  -webkit-mask-image: radial-gradient(closest-side, #000 20%, transparent 100%);
          mask-image: radial-gradient(closest-side, #000 20%, transparent 100%);
  opacity: 0; transition: opacity .5s ease;
}
body.show-rays .rays { display: block; animation: spin 26s linear infinite; }
body.show-rays.lvl-2 .rays, body.show-rays.lvl-3 .rays, body.show-rays.lvl-4 .rays { opacity: 1; }
@keyframes spin { to { transform: rotate(360deg); } }

.bubble {
  position: absolute; bottom: -12vh; border-radius: 50%;
  background: rgba(255,255,255,.3);
  animation: floatUp linear infinite;
  will-change: transform;
}
@keyframes floatUp {
  from { transform: translateY(0) scale(1); opacity: 0; }
  12%  { opacity: .7; }
  88%  { opacity: .45; }
  to   { transform: translateY(-115vh) scale(1.3); opacity: 0; }
}

/* ---------- 顶栏 ---------- */
.hud {
  position: fixed; top: 0; left: 0; right: 0; z-index: 30;
  display: flex; justify-content: space-between; align-items: center;
  padding: calc(env(safe-area-inset-top, 0px) + 14px) calc(env(safe-area-inset-right, 0px) + 16px) 0 calc(env(safe-area-inset-left, 0px) + 16px);
  pointer-events: none;
}
.hud > * { pointer-events: auto; }
.hud-btn, .pill {
  border: 1.5px solid rgba(255,255,255,.62);
  background: rgba(255,255,255,.36);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  color: var(--ink); cursor: pointer;
}
.hud-btn {
  width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center;
}
.hud-btn svg { width: 20px; height: 20px; fill: currentColor; }
.hud-btn .ic-off, .hud-btn[aria-pressed="true"] .ic-on { display: none; }
.hud-btn[aria-pressed="true"] .ic-off { display: block; }
.pill {
  position: relative;
  border-radius: 999px; padding: 8px 16px;
  font-size: 12.5px; font-weight: 800; letter-spacing: .06em;
}
.pill b { font-variant-numeric: tabular-nums; }
.pill .dot {
  position: absolute; top: -2px; right: -2px; width: 10px; height: 10px; border-radius: 50%;
  background: #ff6a3d; box-shadow: 0 0 0 2px #fff; display: none;
}
.pill.has-new .dot { display: block; }
.hud-btn:focus-visible, .pill:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }

/* ---------- 舞台 ---------- */
.scene {
  min-height: 100%;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 56px 0 28px;
}
.stage {
  position: relative;
  width: calc(var(--u) * 270); height: var(--frog-h);
  transform: scale(var(--grow, 1)); transform-origin: 50% 100%;
  transition: transform .5s cubic-bezier(.3,1.5,.5,1);
}
.shadow {
  position: absolute; left: 50%; bottom: calc(var(--u) * -12);
  width: calc(var(--u) * 240); height: calc(var(--u) * 40); margin-left: calc(var(--u) * -120);
  background: radial-gradient(closest-side, rgba(40,72,4,.42), rgba(40,72,4,0));
  will-change: transform;
}

.frog {
  position: relative; display: block; width: 100%; height: 100%;
  border: 0; background: none; padding: 0; cursor: pointer;
  border-radius: 46% 46% 30% 30%;
  touch-action: none; -webkit-touch-callout: none;
}
.frog:focus { outline: none; }
.frog:focus-visible { outline: 3px dashed rgba(255,255,255,.9); outline-offset: 8px; }
.pose, .bob { position: absolute; inset: 0; display: block; transform-origin: 50% 96%; }
.pose { will-change: transform; }
.bob { animation: breathe 3.6s ease-in-out infinite; }
.bob img {
  position: absolute; left: 0; top: 0; width: 100%; height: 100%;
  pointer-events: none; -webkit-user-drag: none;
}
.base { filter: drop-shadow(0 calc(var(--u) * 16) calc(var(--u) * 16) rgba(46,72,4,.26)); }

/* 肚子：同一张静默图，只露出肚皮区域，单独抖 */
.belly {
  -webkit-mask-image: radial-gradient(calc(var(--u) * 104) calc(var(--u) * 98) at calc(var(--u) * 135) calc(var(--u) * 224), #000 70%, transparent 100%);
          mask-image: radial-gradient(calc(var(--u) * 104) calc(var(--u) * 98) at calc(var(--u) * 135) calc(var(--u) * 224), #000 70%, transparent 100%);
  transform-origin: calc(var(--u) * 135) calc(var(--u) * 240);
}

/* 眼睛：盖住原瞳孔，画一个能动的瞳孔 + 上下眼皮 */
.eye {
  position: absolute; top: calc(var(--u) * 19);
  width: calc(var(--u) * 26); height: calc(var(--u) * 26);
  border-radius: 50%; overflow: hidden;
  transition: opacity .06s;
}
.eye.l { left: calc(var(--u) * 91.6); }
.eye.r { left: calc(var(--u) * 151.5); }
.eye i { position: absolute; display: block; }
.iris {
  inset: calc(var(--u) * 3); border-radius: 50%;
  background: radial-gradient(closest-side, #bfd29e 0 62%, #b3c78e 78%, rgba(168,188,120,0) 100%);
  display: grid !important; place-items: center;
}
.pupil {
  position: static !important;
  width: calc(var(--u) * 12.4); height: calc(var(--u) * 13); border-radius: 50%;
  background:
    radial-gradient(circle at 34% 30%, rgba(255,255,255,.75) 0 9%, rgba(255,255,255,0) 15%),
    #18191a;
  will-change: transform;
}
.lid { left: 0; right: 0; }
.lid.up {
  top: 0; height: 56%;
  background: linear-gradient(#f3cd5e, #e8b44c);
  border-bottom: calc(var(--u) * 1.3) solid #7b4a14;
  transform: translateY(-110%);
}
.lid.lo {
  bottom: 0; height: 46%;
  background: linear-gradient(#e6b04a, #e0a943);
  transform: translateY(110%);
}

/* 表情整图：squint 眯眼笑 / shock 睁眼张嘴 / laugh 咧嘴狂笑
   同一套 270×470 帧，切换只改 opacity，不用抠图拼遮罩 */
.face { opacity: 0; transition: opacity .06s; }
.frog[data-face="squint"] .face-squint,
.frog[data-face="shock"] .face-shock,
.frog[data-face="laugh"] .face-laugh { opacity: 1; }
/* 换成整图表情时，底下可动的瞳孔要藏起来 */
.frog[data-face="laugh"] .eye,
.frog[data-face="squint"] .eye { opacity: 0; }

/* ---------- 身体动画 ---------- */
@keyframes breathe {
  0%, 100% { transform: scale(1, 1) translateY(0); }
  50%      { transform: scale(1.012, .988) translateY(2px); }
}
.frog.laughing .bob { animation: bellyShake .3s ease-in-out infinite; }
.frog.laughing.giggle .bob { animation: giggle .34s ease-in-out infinite; }
.frog.laughing .belly { animation: bellyQuiver .2s ease-in-out infinite; }
@keyframes bellyShake {
  0%, 100% { transform: scale(1, 1) rotate(0); }
  25%      { transform: scale(1.045, .955) rotate(-.8deg); }
  75%      { transform: scale(.965, 1.04) rotate(.8deg); }
}
@keyframes giggle {
  0%, 100% { transform: scale(1, 1); }
  50%      { transform: scale(1.016, .984) translateY(1px); }
}
@keyframes bellyQuiver {
  0%, 100% { transform: scale(1, 1); }
  50%      { transform: scale(1.03, .975); }
}

.ghosts { position: absolute; inset: 0; pointer-events: none; }
.ghost {
  position: absolute; left: 0; top: 0; width: 100%; height: 100%;
  transform-origin: 50% 96%; opacity: 0;
}

/* ---------- 连笑徽章 / 气泡 ---------- */
.combo {
  position: absolute; right: -8%; top: 34%;
  display: flex; flex-direction: column; align-items: center;
  transform: rotate(8deg) scale(.6); opacity: 0;
  transition: opacity .2s, transform .25s cubic-bezier(.3,1.6,.5,1);
  pointer-events: none;
}
.combo.show { opacity: 1; transform: rotate(8deg) scale(1); }
.combo b {
  display: block; font-size: clamp(30px, 6vw, 52px); font-weight: 900; color: #fff; line-height: 1;
  font-variant-numeric: tabular-nums; font-style: italic;
  text-shadow: 0 3px 0 #6d9c14, 0 6px 16px rgba(0,0,0,.25);
}
.combo span {
  margin-top: 4px; font-size: 12px; font-weight: 900; letter-spacing: .2em;
  color: #fff; background: #5e8f12; padding: 2px 8px 2px 10px; border-radius: 999px;
}
body.lvl-3 .combo span, body.lvl-4 .combo span { background: #e0561b; }

.bubble-say {
  position: absolute; left: 64%; top: -2%;
  background: #fff; color: var(--ink); font-weight: 800; font-size: 15px; letter-spacing: .06em;
  padding: 8px 13px; border-radius: 16px; white-space: nowrap;
  box-shadow: 0 6px 18px rgba(40,70,0,.18);
  opacity: 0; transform: translateY(8px) scale(.85); transform-origin: 0 100%;
  transition: opacity .2s, transform .25s cubic-bezier(.3,1.6,.5,1);
  pointer-events: none;
}
.bubble-say::after {
  content: ""; position: absolute; left: 12px; bottom: -7px;
  border: 8px solid transparent; border-top-color: #fff; border-bottom: 0; border-left-width: 2px;
}
.bubble-say.show { opacity: 1; transform: none; }

/* ---------- 文字 ---------- */
h1 {
  margin-top: 18px;
  font-size: clamp(34px, 7vw, 62px);
  letter-spacing: .12em; color: #fff; font-weight: 900; line-height: 1.15;
  text-shadow: 0 3px 0 var(--glow), 0 8px 18px rgba(0,0,0,.24);
}
.hint {
  margin-top: 8px; min-height: 1.4em;
  color: var(--ink-2); font-size: 15px; letter-spacing: .16em; font-weight: 700; opacity: .8;
  transition: opacity .25s;
}
.hint.swap { opacity: 0; }
.foot {
  position: fixed; left: 0; right: 0; bottom: calc(env(safe-area-inset-bottom, 0px) + 12px);
  text-align: center; font-size: 11.5px; color: rgba(40,72,6,.55); letter-spacing: .1em;
  pointer-events: none;
}

/* ---------- 飘字 / 粒子 / 大字 ---------- */
.pops, .fx { position: fixed; inset: 0; pointer-events: none; z-index: 40; }
.fx { width: 100%; height: 100%; }
.pops { overflow: hidden; }
.pop {
  position: absolute; left: 0; top: 0;
  font-size: calc(clamp(20px, 3.2vw, 32px) * var(--s, 1));
  font-weight: 900; color: #fff; white-space: nowrap;
  text-shadow: 0 2px 0 #6d9c14, 0 5px 14px rgba(0,0,0,.3);
  animation: popOut .95s cubic-bezier(.2,.7,.3,1) both;
  will-change: transform, opacity;
}
.pop.small { font-size: calc(clamp(20px, 3.2vw, 32px) * .7); color: #fffbe0; }
.pop.big { text-shadow: 0 3px 0 #6d9c14, 0 0 2px #6d9c14, 0 8px 22px rgba(0,0,0,.3); animation-duration: 1.4s; }
@keyframes popOut {
  0%   { transform: translate(-50%, 0) scale(.5) rotate(0); opacity: 0; }
  20%  { transform: translate(-50%, -18px) scale(1.14) rotate(calc(var(--r, 0deg) * -.4)); opacity: 1; }
  100% { transform: translate(calc(-50% + var(--dx, 0px)), -150px) scale(.92) rotate(var(--r, 0deg)); opacity: 0; }
}
@keyframes popFade {
  0%, 100% { transform: translate(-50%, -20px); opacity: 0; }
  20%, 70% { opacity: 1; }
}

.stamp {
  position: fixed; left: 50%; top: 15%; z-index: 45; pointer-events: none;
  font-size: clamp(40px, 9vw, 84px); font-weight: 900; color: #fff; white-space: nowrap;
  letter-spacing: .06em; opacity: 0;
  text-shadow: 0 4px 0 #6d9c14, 0 0 3px #6d9c14, 0 10px 30px rgba(0,0,0,.3);
}
body.lvl-3 .stamp, body.lvl-4 .stamp { text-shadow: 0 4px 0 #d2541a, 0 0 3px #d2541a, 0 10px 30px rgba(0,0,0,.3); }

/* 放在顶栏下面：放底部会盖住提示语 */
.toast {
  position: fixed; left: 50%; top: calc(env(safe-area-inset-top, 0px) + 64px); z-index: 50;
  max-width: calc(100vw - 24px); overflow: hidden; text-overflow: ellipsis;
  background: #2f520a; color: #ffe14d; font-weight: 800; font-size: 14px; letter-spacing: .08em;
  padding: 9px 18px; border-radius: 999px; white-space: nowrap;
  box-shadow: 0 10px 30px rgba(30,50,0,.3);
  opacity: 0; transform: translate(-50%, -14px); transition: opacity .25s, transform .3s cubic-bezier(.3,1.5,.5,1);
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast small { color: #cfe6a8; font-weight: 700; margin-left: 6px; }

/* ---------- 面板 ---------- */
.panel {
  margin: auto; border: 0; border-radius: 22px;
  width: min(420px, calc(100vw - 28px)); max-height: calc(100vh - 40px);
  padding: 0; overflow: auto;
  background: #fbfff0; color: #2f520a;
  box-shadow: 0 30px 80px rgba(30,50,0,.35);
  user-select: text; -webkit-user-select: text;
}
@supports (height: 1dvh) { .panel { max-height: calc(100dvh - 40px); } }
.panel form { padding: 22px 20px 16px; }
.panel[open] { animation: panelIn .3s cubic-bezier(.3,1.4,.5,1); }
.panel::backdrop { background: rgba(40,64,6,.45); }
@keyframes panelIn { from { transform: translateY(16px) scale(.96); opacity: 0; } }
.panel h2 { text-align: center; font-size: 22px; letter-spacing: .3em; font-weight: 900; }
.panel h3 { margin: 18px 0 8px; font-size: 13px; letter-spacing: .12em; display: flex; justify-content: space-between; }
.stats { margin-top: 14px; display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; text-align: center; }
.stats div { background: #eef8d2; border-radius: 12px; padding: 10px 2px 8px; }
.stats b { display: block; font-size: 20px; font-weight: 900; font-variant-numeric: tabular-nums; }
.stats span { font-size: 11px; color: #6c8a45; letter-spacing: .04em; }
.achs { list-style: none; display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.achs li { border-radius: 10px; padding: 8px 10px; background: #f0f2e6; color: #9aa58a; }
.achs li b { display: block; font-size: 13.5px; }
.achs li span { font-size: 11px; line-height: 1.4; display: block; margin-top: 2px; }
.achs li.on { background: #fff1a8; color: #4d4108; }
.achs li.on span { color: #7d6d1d; }
.card-out { margin-top: 14px; text-align: center; }
.card-out img { width: 100%; border-radius: 14px; display: block; box-shadow: 0 6px 20px rgba(40,70,0,.2); }
.card-out figcaption { font-size: 11.5px; color: #6c8a45; margin-top: 6px; }
.row { margin-top: 16px; display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.btn {
  border: 0; border-radius: 999px; padding: 10px 18px; cursor: pointer;
  font-size: 14px; font-weight: 800; letter-spacing: .08em; text-decoration: none;
  background: #e3f2bd; color: #2f520a;
}
.btn.primary { background: #5e8f12; color: #fff; }
.btn:focus-visible { outline: 3px solid #5e8f12; outline-offset: 2px; }
.btn[hidden] { display: none; }
.tiny { display: block; margin-top: 12px; text-align: center; font-size: 11.5px; color: #7d9a55; }

.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}

/* ---------- 适配 ---------- */
@media (max-height: 600px) {
  h1 { margin-top: 10px; font-size: clamp(28px, 6vw, 44px); }
  .hint { margin-top: 4px; font-size: 13px; }
  .foot { display: none; }
}
@media (max-width: 420px) {
  .combo { right: -2%; }
  .bubble-say { font-size: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  .bob, .frog.laughing .bob, .frog.laughing .belly, .bubble, body.show-rays .rays { animation: none !important; }
  .bubble { display: none; }
  .stage { transition: none; }
  .pop { animation-name: popFade; }
}
