:root {
  --bg: #fbf3e2;
  --card: #fffdf6;
  --ink: #5a4632;
  --brown: #b98a5e;
  --brown-dark: #8a6a44;
  --salt: #ff8c42;
  --salt-deep: #e8433c;
  --bladder: #4ea1ff;
  --bladder-deep: #8b5cf6;
  --gold: #f5b942;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: system-ui, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: radial-gradient(circle at 20% 10%, #fff8e8, var(--bg) 55%), var(--bg);
  color: var(--ink);
  user-select: none;
  touch-action: manipulation;
  overflow: hidden;
}

/* 死亡 / 危险氛围 */
body.dead { animation: deathShake .5s; }
@keyframes deathShake {
  0%,100%{transform:translateX(0)} 20%{transform:translateX(-9px)} 40%{transform:translateX(9px)} 60%{transform:translateX(-6px)} 80%{transform:translateX(6px)}
}
body::before, body::after {
  content:""; position:fixed; inset:0; pointer-events:none; opacity:0; transition:opacity .3s; z-index:50;
}
body.salt-danger::before { background: radial-gradient(ellipse at center, transparent 55%, rgba(232,67,60,.35)); opacity:1; }
body.bladder-danger::after { background: radial-gradient(ellipse at center, transparent 55%, rgba(139,92,246,.35)); opacity:1; }

#app {
  max-width: 560px; margin: 0 auto; height: 100vh; height: 100dvh;
  display: flex; flex-direction: column; padding: 12px 16px 0;
}

header { display: flex; justify-content: space-between; align-items: center; }
.seed-count { font-size: 17px; font-weight: 800; }
.seed-count b { color: var(--brown-dark); font-size: 26px; }
.hud-right { display: flex; gap: 8px; align-items: center; }
.hud-best { font-size: 13px; font-weight: 700; color: var(--brown-dark); background: var(--card); padding: 5px 10px; border-radius: 10px; box-shadow: 0 2px 6px rgba(90,70,50,.15); }
.hud-btn {
  border: none; background: var(--card); border-radius: 10px; padding: 6px 10px;
  font-size: 14px; cursor: pointer; box-shadow: 0 2px 6px rgba(90,70,50,.15); color: var(--ink);
}

.bars { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.bar { display: flex; align-items: center; gap: 8px; }
.bar-icon { width: 24px; text-align: center; font-size: 16px; }
.bar-track { flex: 1; height: 16px; background: #eee3cf; border-radius: 8px; overflow: hidden; border: 1px solid #e0d0b4; }
.bar-fill { height: 100%; width: 0%; border-radius: 8px; transition: width .15s ease, background .3s; }
.bar.salt .bar-fill { background: linear-gradient(90deg, #ffc46b, var(--salt)); }
.bar.bladder .bar-fill { background: linear-gradient(90deg, #7cc4ff, var(--bladder-deep)); }
.bar.combo .bar-fill { background: linear-gradient(90deg, #ffe08a, var(--gold)); }
.bar-fill.warn { animation: pulse .6s infinite alternate; }
.bar.salt .bar-fill.danger { background: linear-gradient(90deg, var(--salt), var(--salt-deep)); }
.bar.bladder .bar-fill.danger { background: linear-gradient(90deg, var(--bladder-deep), #c026d3); }
.bar-text { width: 52px; font-size: 12px; font-weight: 700; text-align: right; }
@keyframes pulse { from { filter: brightness(1); } to { filter: brightness(1.4); } }

#playArea {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; position: relative; cursor: pointer; min-height: 0;
}
.seed-wrap { position: relative; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.seed { width: min(46vw, 220px); position: relative; animation: bob 2.4s ease-in-out infinite; }
.seed.suspicious { animation: bob 2.4s ease-in-out infinite, suspiciousWobble .5s ease-in-out infinite; }
@keyframes bob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
@keyframes suspiciousWobble { 0%,100% { transform: rotate(-3deg); } 50% { transform: rotate(3deg); } }
.seed.cracking { animation: crackPop .12s; }
@keyframes crackPop { 0% { transform: scale(1); } 40% { transform: scale(.9) rotate(-4deg); } 100% { transform: scale(1); } }
.seed svg { width: 100%; display: block; filter: drop-shadow(0 10px 14px rgba(90,70,50,.25)); }
.seed.suspicious svg { filter: drop-shadow(0 10px 14px rgba(90,70,50,.25)) hue-rotate(40deg) saturate(.7); }
.seed-face {
  position: absolute; top: 34%; left: 50%; transform: translate(-50%, -50%);
  font-size: clamp(26px, 7vw, 40px); pointer-events: none; z-index: 2;
}
.hint { font-size: 14px; color: #a08a6a; min-height: 20px; }
.toast {
  position: absolute; bottom: 22%; left: 50%; transform: translateX(-50%);
  background: rgba(90,70,50,.92); color: #fff; padding: 6px 14px; border-radius: 20px;
  font-size: 13px; white-space: nowrap; z-index: 10; transition: opacity .25s;
}
.toast.hidden { opacity: 0; pointer-events: none; }

.pop-text {
  position: absolute; font-weight: 900; color: var(--brown-dark); font-size: 24px;
  animation: popUp .7s forwards; pointer-events: none; z-index: 9; text-shadow: 0 2px 0 #fff;
}
@keyframes popUp {
  from { opacity: 1; transform: translate(-50%, 0) scale(1); }
  to { opacity: 0; transform: translate(-50%, -70px) scale(1.4); }
}
.shell-bit {
  position: absolute; width: 14px; height: 10px; background: var(--brown);
  border-radius: 50% 50% 60% 40%; animation: fly .7s forwards; pointer-events: none;
}
@keyframes fly {
  from { opacity: 1; }
  to { opacity: 0; transform: translate(var(--dx), var(--dy)) rotate(var(--rot)); }
}

.actions { display: flex; justify-content: center; gap: 14px; padding: 14px 0 22px; }
.btn {
  border: none; border-radius: 14px; padding: 12px 22px; font-size: 16px; font-weight: 700;
  cursor: pointer; color: #fff; background: var(--brown);
  box-shadow: 0 3px 8px rgba(90,70,50,.25); transition: transform .1s;
}
.btn:active { transform: scale(.95); }
.btn.drink { background: linear-gradient(135deg, #4ea1ff, #8b5cf6); min-width: 130px; }
.btn.drink.thirsty { animation: thirstPulse .8s infinite alternate; }
.btn.throw { background: linear-gradient(135deg, #8a9a5b, #5f7a3a); }
.btn.primary { background: linear-gradient(135deg, #f5b942, #e8912d); color: #5a3d10; }
.btn.small { padding: 9px 14px; font-size: 14px; background: #eee3cf; color: var(--ink); box-shadow: none; }
.btn.danger { background: #f3e4d6; color: #b0503a; box-shadow: none; }
@keyframes thirstPulse {
  from { box-shadow: 0 0 0 2px rgba(78,161,255,.35); }
  to { box-shadow: 0 0 0 10px rgba(78,161,255,.12); }
}

.modal {
  position: fixed; inset: 0; background: rgba(60,42,24,.45);
  display: flex; align-items: center; justify-content: center; z-index: 100; backdrop-filter: blur(3px);
}
.modal.hidden { display: none; }
.modal-card {
  background: var(--card); border-radius: 22px; padding: 22px 24px;
  width: min(92vw, 430px); max-height: 88dvh; overflow-y: auto;
  box-shadow: 0 20px 60px rgba(60,42,24,.4); text-align: center;
}
.modal-title { font-size: 24px; font-weight: 900; }
.modal-seeds { font-size: 17px; margin-top: 8px; }
.modal-seeds b { font-size: 36px; color: var(--brown-dark); }
.modal-death { margin-top: 6px; color: #b0503a; font-weight: 600; }
.modal-record { margin-top: 8px; color: #e8912d; font-weight: 900; animation: pulse .6s infinite alternate; }
.modal-stats { margin-top: 10px; font-size: 13px; color: #8a7458; background: #f7efdd; border-radius: 10px; padding: 8px; }
.modal-nick { margin-top: 12px; display: flex; gap: 8px; justify-content: center; }
.modal-nick input {
  flex: 1; max-width: 230px; border: 2px solid #e0d0b4; border-radius: 10px;
  padding: 8px 12px; font-size: 14px; outline: none; color: var(--ink); background: #fff;
}
.modal-nick input:focus { border-color: var(--brown); }
.modal-actions { margin-top: 14px; display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

.board-note { font-size: 12px; color: #b3a084; margin-top: 4px; }
.tabs { display: flex; gap: 6px; justify-content: center; margin-top: 10px; }
.tab {
  border: 2px solid #e0d0b4; background: #fff; border-radius: 20px;
  padding: 6px 14px; font-size: 13px; font-weight: 700; color: var(--ink); cursor: pointer;
}
.tab.active { background: var(--brown); border-color: var(--brown); color: #fff; }
.board-list { margin-top: 12px; display: flex; flex-direction: column; gap: 6px; }
.board-row { display: flex; align-items: center; gap: 10px; background: #f7efdd; border-radius: 10px; padding: 8px 12px; font-size: 14px; }
.board-row.me { outline: 2px solid var(--gold); }
.rank { width: 36px; font-weight: 900; color: var(--brown-dark); }
.name { flex: 1; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.val { font-weight: 800; color: var(--brown-dark); }
.board-empty { color: #b3a084; padding: 14px; }
.my-stats { margin-top: 12px; font-size: 13px; background: #f7efdd; border-radius: 10px; padding: 10px; text-align: left; line-height: 1.9; }
.recent-title { margin-top: 12px; font-size: 12px; color: #b3a084; text-align: left; }
.recent-list { display: flex; flex-direction: column; gap: 4px; margin-top: 4px; }
.recent-row { display: flex; justify-content: space-between; font-size: 12px; color: #8a7458; background: #faf3e3; border-radius: 8px; padding: 5px 10px; }

.hidden { display: none !important; }

/* ================= v0.3 新增：尿尿 / 明面臭瓜子 / 死亡动画 ================= */
.btn.pee { background: linear-gradient(135deg, #2fd6b4, #0fa58a); min-width: 120px; }
.btn.pee.urgent { animation: peePulse .7s infinite alternate; }
@keyframes peePulse {
  from { box-shadow: 0 0 0 2px rgba(47,214,180,.4); }
  to { box-shadow: 0 0 0 10px rgba(47,214,180,.15); }
}
.btn.disabled { opacity: .38; pointer-events: none; filter: grayscale(.6); }

/* 左滑手势：拖拽倾斜 + 飞出动画 */
#playArea { touch-action: none; } /* 触屏左滑时不触发页面滚动 */
.seed.drag-left { animation: none !important; transform: rotate(-14deg) translateX(-10px); transition: transform .08s; }
.seed.throw-left { animation: throwLeft .3s forwards !important; }
@keyframes throwLeft {
  to { transform: translateX(-170px) rotate(-55deg) scale(.75); opacity: 0; }
}

/* 明面臭瓜子：腐烂发黑的壳 */
.seed.obvious { animation: bob 2.4s ease-in-out infinite, obviousWobble .7s ease-in-out infinite; }
.seed.obvious svg { filter: drop-shadow(0 10px 14px rgba(60,42,24,.3)) hue-rotate(150deg) brightness(.72) saturate(.55); }
@keyframes obviousWobble { 0%,100% { transform: rotate(-4deg); } 50% { transform: rotate(4deg); } }

/* 尿尿动画：蹲下抖一抖 */
.seed.peeing { animation: peeSquat 1.2s ease-in-out infinite; }
@keyframes peeSquat {
  0%,100% { transform: translateY(0) scale(1,1); }
  40% { transform: translateY(14px) scale(1.15,.85); }
  70% { transform: translateY(10px) scale(1.1,.9); }
}

/* 死亡闪光层（三种颜色） */
#deathFlash { position: fixed; inset: 0; pointer-events: none; opacity: 0; z-index: 60; transition: opacity .18s; }
#deathFlash.show { opacity: 1; }
#deathFlash.bad { background: radial-gradient(circle at center, transparent 42%, rgba(63,77,40,.55)); }
#deathFlash.salt { background: radial-gradient(circle at center, transparent 42%, rgba(232,67,60,.55)); }
#deathFlash.bladder { background: radial-gradient(circle at center, transparent 42%, rgba(78,161,255,.6)); }

/* 死亡动画：臭瓜子=变黑倒地 / 咸死=晕头转向 / 憋死=抖成筛子后瘫倒 */
.seed.die-bad { animation: dieBad .9s forwards; }
@keyframes dieBad {
  0% { transform: rotate(0) scale(1); }
  25% { transform: rotate(-10deg) scale(1.06); }
  50% { filter: grayscale(1) brightness(.55); transform: rotate(10deg) scale(.94); }
  100% { filter: grayscale(1) brightness(.5); transform: rotate(92deg) translateY(26px) scale(.85); opacity: .92; }
}
.seed.die-salt { animation: dieSalt .9s forwards; }
@keyframes dieSalt {
  0%,12% { transform: rotate(0); }
  24% { transform: rotate(-14deg); }
  36% { transform: rotate(14deg); }
  48% { transform: rotate(-11deg); }
  60% { transform: rotate(11deg) scale(1.08); }
  78% { filter: saturate(2.2) hue-rotate(-18deg); transform: rotate(120deg) scale(1.02); }
  100% { filter: saturate(2.2) hue-rotate(-18deg) brightness(.85); transform: rotate(150deg) translateY(34px); }
}
.seed.die-bladder { animation: dieBladder .9s forwards; }
@keyframes dieBladder {
  0%,15% { transform: translateY(0) rotate(0); }
  25% { transform: translateY(-8px) rotate(-5deg); }
  38% { transform: translateY(0) rotate(5deg); }
  50% { transform: translateY(-12px) rotate(-7deg) scale(1.05); }
  65% { transform: translateY(0) rotate(7deg); }
  80% { transform: translateY(-16px) rotate(-9deg); }
  100% { transform: translateY(6px) rotate(178deg) scale(.9); }
}

/* 死亡飘浮 emoji */
.death-emoji {
  position: absolute; font-size: 30px; pointer-events: none; z-index: 59;
  animation: deathFloat .95s forwards;
}

/* ================= 成就面板 ================= */
.ach-card { max-width: 430px; }
.ach-count { text-align: center; color: #8a7a5a; font-size: 13px; margin-bottom: 10px; }
.ach-list { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; max-height: 46vh; overflow-y: auto; padding-right: 2px; }
.ach { display: flex; gap: 8px; align-items: center; background: #f7f1e3; border: 2px solid #e5d9bd; border-radius: 12px; padding: 8px; }
.ach.unlocked { border-color: #e6b84c; background: linear-gradient(135deg, #fdf6e3, #f8e7b8); box-shadow: 0 2px 8px rgba(230, 184, 76, .35); }
.ach.locked { opacity: .55; filter: grayscale(.7); }
.ach-icon { font-size: 26px; width: 44px; height: 44px; display: flex; align-items: center; justify-content: center; background: #fff; border-radius: 50%; flex-shrink: 0; box-shadow: inset 0 0 0 2px #e5d9bd; }
.ach.unlocked .ach-icon { box-shadow: inset 0 0 0 2px #e6b84c; }
.ach-name { font-size: 13px; font-weight: 700; color: #5a4a2a; }
.ach-desc { font-size: 11px; color: #8a7a5a; margin-top: 2px; line-height: 1.3; }
.ach-progress { height: 5px; background: #e5d9bd; border-radius: 3px; margin-top: 5px; overflow: hidden; }
.ach-progress-fill { height: 100%; background: linear-gradient(90deg, #e6b84c, #f2cf6b); border-radius: 3px; }
.ach-progress-text { font-size: 10px; color: #a08a5a; margin-top: 2px; }
/* ================= 分享 ================= */
.share-card { max-width: 380px; text-align: center; }
.share-qr { margin: 10px auto; background: #fff; padding: 8px; border-radius: 12px; display: inline-block; box-shadow: 0 2px 8px rgba(0,0,0,.08); }
.share-qr img { display: block; width: 180px; height: 180px; }
.share-url { font-weight: 700; color: #5a4a2a; word-break: break-all; font-size: 14px; margin: 8px 0; }
.share-tip { font-size: 12px; color: #8a7a5a; margin-bottom: 8px; }
.share-all { font-size: 11px; color: #a08a5a; margin-bottom: 10px; }
.share-all div { padding: 2px 0; }
.share-btn { background: linear-gradient(135deg, #4caf50, #2e7d32) !important; color: #fff !important; font-weight: 700; }
.share-btn:hover { filter: brightness(1.1); }
.share-status { font-size: 12px; color: #2e7d32; margin-bottom: 6px; }

/* ================= 模式选择 ================= */
.mode-card { max-width: 420px; }
.mode-note { text-align: center; color: #8a7a5a; font-size: 13px; margin: 6px 0 14px; }
.mode-options { display: flex; flex-direction: column; gap: 12px; }
.mode-option {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  border: 3px solid #e5d9bd; background: #fbf6e9; border-radius: 16px;
  padding: 18px 12px; cursor: pointer; transition: transform .12s, border-color .12s;
}
.mode-option:hover { transform: scale(1.02); border-color: #e6b84c; }
.mode-option:active { transform: scale(.97); }
.mode-icon { font-size: 40px; }
.mode-name { font-size: 18px; font-weight: 900; color: #5a4a2a; }
.mode-desc { font-size: 12px; color: #8a7a5a; }

/* ================= 手机模式布局 ================= */
body.mode-phone #app { max-width: none; padding: 8px 10px 0; }
body.mode-phone .hud-btn { min-width: 42px; min-height: 42px; font-size: 16px; padding: 8px; }
body.mode-phone .hud-best { font-size: 12px; padding: 6px 8px; }
body.mode-phone .bars { margin-top: 8px; gap: 6px; }
body.mode-phone .bar-track { height: 18px; }
body.mode-phone .bar-icon { font-size: 18px; }
body.mode-phone .bar-text { font-size: 13px; }
body.mode-phone #playArea { flex: 1; min-height: 0; }
body.mode-phone .seed-main { font-size: 92px; }
body.mode-phone .actions { gap: 12px; padding: 10px 0 16px; }
body.mode-phone .btn { min-height: 54px; font-size: 17px; padding: 12px 26px; }
body.mode-phone .btn.drink, body.mode-phone .btn.pee { min-width: 150px; }
body.mode-phone .modal-card { max-width: 92vw; }
@keyframes deathFloat {
  from { opacity: 1; transform: translate(-50%, 0) scale(.6) rotate(0); }
  to { opacity: 0; transform: translate(calc(-50% + var(--dx)), var(--dy)) scale(1.5) rotate(var(--rot)); }
}

/* 死亡卡通图：游戏区中央弹出 */
.death-art-pop {
  position: absolute; left: 50%; top: 42%; width: 190px; height: 190px;
  transform: translate(-50%, -50%); pointer-events: none; z-index: 58;
  filter: drop-shadow(0 6px 12px rgba(0,0,0,.18));
  animation: artPop 1.5s forwards;
}
@keyframes artPop {
  0%   { transform: translate(-50%, -50%) scale(.2) rotate(-14deg); opacity: 0; }
  18%  { transform: translate(-50%, -50%) scale(1.12) rotate(4deg); opacity: 1; }
  30%  { transform: translate(-50%, -50%) scale(1) rotate(-2deg); }
  70%  { transform: translate(-50%, -50%) scale(1) rotate(0); opacity: 1; }
  100% { transform: translate(-50%, -58%) scale(.9); opacity: 0; }
}

/* 结算弹窗里的死亡图 */
.modal-death-art {
  width: 148px; height: 148px; margin: 6px auto 2px; display: block;
  border-radius: 22px; object-fit: cover;
  box-shadow: 0 4px 14px rgba(0,0,0,.14);
  animation: modalArtIn .45s cubic-bezier(.34,1.56,.64,1);
}
@keyframes modalArtIn {
  from { transform: scale(.4) rotate(-8deg); opacity: 0; }
  to   { transform: scale(1) rotate(0); opacity: 1; }
}
