/* ==========================================================
   心情漂流瓶 · 蜡笔涂鸦风
   ========================================================== */
:root {
  --paper: #fffbf0;
  --ink: #2b2620;

  --happy: #f0c14b;
  --calm: #7bc0d8;
  --sad: #7c9fe0;
  --complex: #b892e8;
  --anxious: #ec9163;

  --title-gold: #c9973a;
}

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

html, body {
  height: 100%; overflow: hidden;
  background: var(--paper); color: var(--ink);
  font-family: "Yuanti SC", "YouYuan", "PingFang SC", "Microsoft YaHei", sans-serif;
  user-select: none;
}

.svgdefs { position: absolute; width: 0; height: 0; overflow: hidden; pointer-events: none; }

body.hand-mode, body.hand-mode * { cursor: none; }
textarea { user-select: text; cursor: text; }

/* ---------------- 涂鸦背景 ---------------- */
.bgStars {
  position: fixed; inset: 0; z-index: 0;
  pointer-events: none; overflow: hidden;
  background:
    radial-gradient(circle at 15% 20%, rgba(240,193,75,.08), transparent 40%),
    radial-gradient(circle at 85% 75%, rgba(123,192,216,.08), transparent 40%),
    radial-gradient(circle at 50% 50%, rgba(255,255,255,.4), transparent 70%);
}
.bgstar {
  position: absolute;
  transform-origin: center;
  animation: twinkle 5s ease-in-out infinite alternate;
}
.bgstar:nth-child(3n) { animation-delay: .7s; }
.bgstar:nth-child(5n) { animation-delay: 1.4s; }
.bgstar:nth-child(7n) { animation-delay: 2.1s; }
@keyframes twinkle {
  from { transform: rotate(var(--r, 0deg)) scale(1); }
  to   { transform: rotate(var(--r, 0deg)) scale(1.08); opacity: .5; }
}

/* ---------------- 屏幕 ---------------- */
.screen {
  position: fixed; inset: 0; z-index: 1;
  display: none;
  flex-direction: column; align-items: center; justify-content: center;
  overflow: hidden;
}
.screen.active { display: flex; animation: pop .3s ease-out; }
@keyframes pop { from { opacity: 0; transform: scale(.96); } to { opacity: 1; transform: scale(1); } }

/* ---------------- 按钮 ---------------- */
.btn {
  position: relative;
  font-family: inherit; font-size: 16px; font-weight: 800; letter-spacing: 1.5px;
  color: var(--ink); background: #fff;
  border: 3px solid var(--ink);
  border-radius: 18px 14px 20px 15px / 15px 20px 14px 18px;
  padding: 12px 22px;
  box-shadow: 4px 4px 0 rgba(43,38,32,.9);
  transition: transform .1s, box-shadow .1s, background .15s;
  transform: rotate(-.4deg);
}
.btn:hover { transform: translate(2px, 2px) rotate(0deg); box-shadow: 2px 2px 0 rgba(43,38,32,.9); }
.btn:active { transform: translate(4px, 4px); box-shadow: 0 0 0 rgba(43,38,32,.9); }
.btn.primary { background: var(--happy); }
.btn.danger { background: #f5b3a0; }
.btn.small { font-size: 14px; padding: 9px 16px; border-width: 2.5px; }
.btn.big { font-size: 21px; padding: 16px 36px; }
.btn:disabled { opacity: .35; box-shadow: none; }
.btn.corner { position: absolute; top: 18px; right: 18px; z-index: 6; transform: rotate(1deg); }

.btn.hover {
  background: #fff8e2;
  transform: translate(2px, 2px) rotate(0deg);
  box-shadow: 2px 2px 0 rgba(43,38,32,.9);
  outline: 3px dashed var(--acc, var(--happy));
  outline-offset: 4px;
}

.btn.grab { background: #fff8e2; transform: translateY(3px) scale(.98); box-shadow: 1px 1px 0 rgba(43,38,32,.9); }
.btn.grab::after {
  content: "✊"; position: absolute; right: -14px; top: -16px; font-size: 20px;
}

.linklike {
  background: none; border: none; font-family: inherit;
  color: var(--ink); font-size: 13px; text-decoration: underline;
  letter-spacing: 1px; padding: 6px; opacity: .35;
}
.linklike.tiny { font-size: 12px; opacity: .28; }
.linklike:hover { opacity: .8; }

.tag {
  display: inline-block;
  border: 2.5px solid var(--ink); border-radius: 999px;
  padding: 5px 16px; font-weight: 800; font-size: 15px; letter-spacing: 2px;
  background: #fff;
}

.hintbar {
  position: absolute; bottom: 18px; left: 50%; transform: translateX(-50%);
  background: #fff; border: 3px solid var(--ink); border-radius: 999px;
  padding: 8px 24px; font-size: 13px; font-weight: 800; letter-spacing: 1.5px;
  box-shadow: 3px 3px 0 rgba(43,38,32,.85);
  white-space: nowrap; z-index: 5;
}
.hintbar.bottom { bottom: 16px; }
.ok-hint {
  font-weight: 800; letter-spacing: 1px; opacity: .7;
  background: #fff3c4; border: 2.5px solid var(--ink); border-radius: 999px;
  padding: 4px 14px; font-size: 13px;
}

/* ---------------- 连线层 ---------------- */
#linkLayer {
  position: fixed; inset: 0; z-index: 820; pointer-events: none;
  opacity: 0; transition: opacity .12s;
}
#linkLayer.on { opacity: 1; }
#linkPath {
  fill: none; stroke-width: 3.5;
  stroke-dasharray: 2 12; stroke-linecap: round;
  animation: dashRun .7s linear infinite;
}
@keyframes dashRun { to { stroke-dashoffset: -28; } }
#linkDot { fill: #fff; stroke-width: 4; }

/* ---------------- 光标 ---------------- */
#cursor {
  position: fixed; left: 0; top: 0; z-index: 900;
  width: 56px; height: 56px; margin: -28px 0 0 -28px;
  pointer-events: none; opacity: 0; transition: opacity .2s;
}
#cursor.show { opacity: 1; }
#cursor svg { width: 100%; height: 100%; overflow: visible; transition: transform .1s; transform-origin: 28px 28px; }
#curRing {
  stroke: var(--ink); stroke-dasharray: 145; stroke-dashoffset: 145;
  transform: rotate(-90deg); transform-origin: 28px 28px;
  transition: stroke .12s;
}
#curRing.grab { stroke: var(--happy); }
#curRing.v { stroke: var(--anxious); }
#curRing.back { stroke: var(--calm); }
.cur-dot { fill: #fff; stroke: var(--ink); stroke-width: 4; }
#curIcon { position: absolute; right: -18px; top: -14px; font-size: 22px; line-height: 1; }
#cursor.fist svg { transform: scale(.78); }
#cursor.fist #curRing { stroke: var(--happy); }

#hoverTag {
  position: fixed; left: 0; top: 0; z-index: 910; pointer-events: none;
  background: var(--ink); color: #fff;
  font-size: 14px; font-weight: 900; letter-spacing: 2px;
  padding: 6px 14px; border-radius: 999px;
  white-space: nowrap; transform: translate(-50%, 40px);
  box-shadow: 0 3px 0 rgba(43,38,32,.25);
}

/* ---------------- 摄像头小窗 ---------------- */
#camBox {
  position: fixed; right: 16px; bottom: 16px; z-index: 60;
  width: 190px; aspect-ratio: 4/3;
  border: 3px solid var(--ink); border-radius: 16px;
  overflow: hidden; background: #111;
  box-shadow: 5px 5px 0 rgba(43,38,32,.25);
  transform: rotate(1deg);
}
#camBox video, #camBox canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
#camBox video { object-fit: cover; transform: scaleX(-1); }
#camBox canvas { z-index: 2; pointer-events: none; }
#camBadge {
  position: absolute; left: 6px; bottom: 6px; z-index: 3;
  font-size: 11px; font-weight: 800; letter-spacing: 1px;
  background: #fff; border: 2px solid var(--ink); border-radius: 999px;
  padding: 3px 9px;
}
#camBadge.ok { background: #b8f26a; }

#gesturePill {
  position: fixed; left: 16px; bottom: 16px; z-index: 60;
  background: #fff; border: 3px solid var(--ink); border-radius: 999px;
  padding: 7px 17px; font-weight: 800; font-size: 14px; letter-spacing: 1px;
  box-shadow: 4px 4px 0 rgba(43,38,32,.2);
  transform: rotate(-1deg);
}
.hidden { display: none !important; }

/* ---------------- 开始页 ---------------- */
.start-card { display: flex; flex-direction: column; align-items: center; gap: 16px; padding: 20px; position: relative; z-index: 2; }
.title {
  font-size: clamp(38px, 7vw, 74px); font-weight: 900; letter-spacing: 8px;
  transform: rotate(-1.4deg);
  color: var(--title-gold);
  text-shadow: 4px 4px 0 rgba(43,38,32,.85);
}
.start-sub { font-size: clamp(14px, 1.9vw, 18px); letter-spacing: 3px; font-weight: 700; opacity: .6; }
.start-bottles { display: flex; gap: 8px; margin: 4px 0; }
.start-bottles .mini { width: clamp(42px, 6.2vw, 62px); animation: bob 2.8s ease-in-out infinite alternate; }
.start-bottles .mini:nth-child(2) { animation-delay: .25s; }
.start-bottles .mini:nth-child(3) { animation-delay: .5s; }
.start-bottles .mini:nth-child(4) { animation-delay: .75s; }
.start-bottles .mini:nth-child(5) { animation-delay: 1s; }
.start-tip { font-size: 12.5px; opacity: .5; letter-spacing: 1px; text-align: center; max-width: 480px; line-height: 1.7; }

.start-cam {
  position: relative; width: min(300px, 76vw); aspect-ratio: 4/3;
  border: 4px solid var(--ink); border-radius: 20px;
  overflow: hidden; background: #111;
  box-shadow: 6px 6px 0 rgba(43,38,32,.2);
  animation: pop .35s ease-out;
}
.start-cam video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
.cam-status {
  position: absolute; left: 0; right: 0; bottom: 0;
  background: rgba(43,38,32,.9); color: #fff;
  font-size: 13px; padding: 8px 12px; display: flex; align-items: center; gap: 8px;
}
.loader {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.3); border-top-color: #fff;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.doodle { position: absolute; opacity: .85; pointer-events: none; z-index: 1; }
.doodle svg { display: block; }
.doodle.d1 { width: 110px; left: 6%; top: 14%; transform: rotate(-12deg); }
.doodle.d2 { width: 90px; right: 8%; top: 18%; transform: rotate(10deg); }
.doodle.d3 { width: 130px; left: 12%; bottom: 12%; transform: rotate(6deg); }

/* ---------------- 首页 ---------------- */
#screen-home { justify-content: flex-start; padding-top: clamp(10px, 3vh, 26px); }
.home-top { margin-bottom: 6px; width: 100%; display: flex; justify-content: center; }
.hand-title {
  font-size: clamp(17px, 2.4vw, 24px); font-weight: 900; letter-spacing: 3px;
  transform: rotate(-1deg);
  background: #fff; border: 3px solid var(--ink); border-radius: 999px;
  padding: 9px 24px; box-shadow: 5px 5px 0 rgba(43,38,32,.85);
}
.home-mid { width: 100%; flex: 1; display: flex; align-items: center; justify-content: center; }
.shelf {
  position: relative; display: flex; justify-content: center; align-items: flex-end;
  gap: clamp(4px, 1.8vw, 30px);
  padding: 0 clamp(8px, 2vw, 36px) 34px;
  width: 100%;
}
.shelf::after {
  content: ""; position: absolute; left: 4%; right: 4%; bottom: 8px;
  height: 5px; background: var(--ink); border-radius: 4px;
  transform: rotate(-.3deg);
}

.bottle-slot {
  position: relative;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 14px 8px 2px;
  border-radius: 22px;
  transition: transform .26s cubic-bezier(.3,1.4,.5,1);
  transform-origin: 50% 100%;
}
.bottle-slot.hover { transform: translateY(-10px) scale(1.05); }
.bottle-slot.focus { transform: translateY(-22px) scale(1.13); }
.bottle-slot.focus .bottleWrap { filter: drop-shadow(0 12px 0 rgba(43,38,32,.16)); }

.bottleWrap { position: relative; width: clamp(76px, 12.5vw, 152px); transition: filter .25s; }
.bottleWrap svg { width: 100%; display: block; }

/* 怪物角色 */
.monster {
  position: absolute; left: -18%; top: -26%;
  width: 56%; transition: transform .26s cubic-bezier(.3,1.4,.5,1);
  transform: rotate(-6deg);
  animation: bob 3.2s ease-in-out infinite alternate;
}
.monster svg { width: 100%; display: block; }
.bottle-slot:nth-child(2) .monster { animation-delay: .3s; }
.bottle-slot:nth-child(3) .monster { animation-delay: .6s; }
.bottle-slot:nth-child(4) .monster { animation-delay: .9s; }
.bottle-slot:nth-child(5) .monster { animation-delay: 1.2s; }
.bottle-slot.hover .monster { transform: rotate(-12deg) scale(1.08); }
.bottle-slot.focus .monster { transform: rotate(-16deg) scale(1.16) translateY(-4px); }

.badge {
  position: absolute; right: 2%; top: 4%; z-index: 3;
  min-width: 32px; height: 32px; padding: 0 6px;
  background: var(--acc); border: 3px solid var(--ink); border-radius: 999px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 900; font-size: 15px; transform: rotate(7deg);
  transition: transform .25s;
}
.bottle-slot.focus .badge { transform: rotate(7deg) scale(1.15); }

.label {
  font-size: 14px; font-weight: 900; letter-spacing: 2px;
  border-bottom: 3px solid var(--acc); padding-bottom: 2px;
  transition: font-size .25s;
}
.bottle-slot.focus .label { font-size: 15px; }

.grabHint {
  position: absolute; left: 50%; top: 34%;
  transform: translate(-50%, -50%) scale(.5) rotate(-6deg);
  background: var(--ink); color: #fff;
  font-size: 12px; font-weight: 900; letter-spacing: 1px;
  padding: 4px 10px; border-radius: 999px;
  opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s;
  white-space: nowrap;
}
.bottle-slot.focus .grabHint {
  opacity: 1; transform: translate(-50%, -50%) scale(1) rotate(-6deg);
}

@keyframes bob { from { transform: translateY(0); } to { transform: translateY(-8px); } }

/* ---------------- 瓶子详情 ---------------- */
.bottle-stage { display: flex; flex-direction: column; align-items: center; gap: 10px; position: relative; z-index: 2; }
.bigName {
  font-size: clamp(22px, 3.6vw, 34px); font-weight: 900; letter-spacing: 5px;
  transform: rotate(-1deg);
  border-bottom: 4px solid var(--acc, var(--ink)); padding-bottom: 3px;
  animation: pop .35s ease-out;
}
.bigBottle { width: clamp(170px, 30vh, 250px); animation: wob 2.6s ease-in-out infinite; }
.bigBottle svg { width: 100%; display: block; }
@keyframes wob { 0%,100% { transform: rotate(-1.5deg); } 50% { transform: rotate(1.5deg) translateY(-5px); } }
.bigCount { font-size: 16px; font-weight: 800; letter-spacing: 2px; opacity: .65; }
.actions { display: flex; gap: 12px; margin-top: 6px; flex-wrap: wrap; justify-content: center; }
.miniHint { font-size: 12px; opacity: .4; letter-spacing: 2px; margin-top: 4px; }

/* ---------------- 写字 ---------------- */
.write-wrap {
  display: flex; align-items: center; gap: clamp(18px, 5vw, 56px);
  flex-wrap: wrap; justify-content: center; padding: 0 4vw; position: relative; z-index: 2;
}
.write-bottle { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.write-bottle #wbSvg { width: clamp(120px, 20vh, 175px); }
.write-bottle svg { width: 100%; display: block; }

.paper {
  position: relative;
  background: #fffdf7; border: 3px solid var(--ink);
  border-radius: 20px 16px 22px 18px / 18px 22px 16px 20px;
  padding: 22px; width: min(440px, 86vw);
  box-shadow: 6px 6px 0 rgba(43,38,32,.18);
  transform: rotate(-.3deg);
}
.paper::before {
  content: ""; position: absolute; top: -13px; left: 50%; margin-left: -42px;
  width: 84px; height: 22px; background: var(--acc, var(--happy));
  border: 3px solid var(--ink); border-radius: 5px; transform: rotate(-2deg);
}
.paper-title { font-size: 18px; font-weight: 900; letter-spacing: 2px; margin-bottom: 12px; }
#noteInput {
  width: 100%; resize: none; font-family: inherit; font-size: 16px; line-height: 1.9;
  color: var(--ink); background: #fff;
  border: 2.5px solid var(--ink); border-radius: 12px; padding: 12px 14px;
  outline: none;
}
#noteInput:focus { box-shadow: 4px 4px 0 var(--acc, var(--happy)); }
.paper-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 12px; gap: 10px; }
#charCount { font-size: 12px; opacity: .45; font-weight: 800; }

/* ---------------- 摇瓶子 ---------------- */
.shake-stage {
  display: flex; align-items: center; gap: clamp(22px, 6vw, 70px);
  flex-wrap: wrap; justify-content: center; padding: 0 4vw; position: relative; z-index: 2;
}
.shake-left { position: relative; }
.shake-bottle { width: clamp(170px, 30vh, 250px); }
.shake-bottle svg { width: 100%; display: block; }
.shake-bottle.shaking { animation: shk .9s ease; transform-origin: 50% 88%; }
@keyframes shk {
  0%,100% { transform: rotate(0); }
  14% { transform: rotate(-11deg) translateX(-8px); }
  30% { transform: rotate(9deg) translateX(8px); }
  46% { transform: rotate(-7deg) translateX(-5px); }
  62% { transform: rotate(6deg) translateX(5px); }
  78% { transform: rotate(-4deg); }
  90% { transform: rotate(2deg); }
}
.pop-star { position: absolute; left: 50%; top: 10%; margin-left: -32px; width: 64px; height: 64px; }
.pop-star svg { width: 100%; height: 100%; }
.pop-star.pop-anim { animation: starPop .9s cubic-bezier(.3,1.5,.5,1) forwards; }
@keyframes starPop {
  0% { transform: translateY(26px) scale(.2) rotate(0); opacity: 0; }
  40% { opacity: 1; }
  100% { transform: translateY(-96px) scale(1.1) rotate(320deg); opacity: 1; }
}
.shake-side { display: flex; flex-direction: column; align-items: center; gap: 16px; }
.prompt { font-size: clamp(17px, 2.4vw, 23px); font-weight: 900; letter-spacing: 3px; text-align: center; line-height: 1.8; }

.note-card {
  position: relative;
  background: #fff; border: 3px solid var(--ink);
  border-radius: 18px 14px 20px 16px / 16px 20px 14px 18px;
  padding: 26px 22px 16px; width: min(360px, 84vw);
  box-shadow: 6px 6px 0 rgba(43,38,32,.18);
  animation: pop .35s cubic-bezier(.3,1.5,.5,1);
  transform: rotate(.5deg);
}
.tape {
  position: absolute; top: -12px; left: 50%; margin-left: -42px;
  width: 84px; height: 21px; background: var(--acc, var(--happy));
  border: 3px solid var(--ink); border-radius: 5px; transform: rotate(2deg);
}
.note-text { font-size: 16px; line-height: 1.95; word-break: break-word; }
.note-date { margin-top: 10px; font-size: 12px; opacity: .45; font-weight: 800; letter-spacing: 1px; }
.note-actions { display: flex; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
#btnDelete.armed { background: var(--ink); color: #fff; animation: armed .5s ease-in-out infinite alternate; }
@keyframes armed { from { transform: scale(1); } to { transform: scale(1.07) rotate(-1deg); } }

/* ---------------- 清空弹窗 ---------------- */
#modal {
  position: fixed; inset: 0; z-index: 500;
  background: rgba(255,251,240,.9);
  display: none; align-items: center; justify-content: center;
}
#modal.open { display: flex; }
.modal-card {
  background: #fff; border: 4px solid var(--ink);
  border-radius: 24px 18px 26px 20px / 20px 26px 18px 24px;
  padding: 28px 34px; display: flex; flex-direction: column; align-items: center; gap: 13px;
  box-shadow: 8px 8px 0 rgba(43,38,32,.9);
  animation: pop .3s cubic-bezier(.3,1.6,.5,1);
  width: min(390px, 86vw);
  transform: rotate(-.5deg);
}
.modal-title { font-size: 22px; font-weight: 900; letter-spacing: 2px; }
.modal-sub { font-size: 13px; opacity: .55; letter-spacing: 1px; text-align: center; }
.fist-wrap { position: relative; width: 108px; height: 108px; }
.fist-ring { width: 100%; height: 100%; }
.ring-bg { stroke: rgba(43,38,32,.13); }
#fistRing {
  stroke: var(--anxious); stroke-linecap: round;
  stroke-dasharray: 214; stroke-dashoffset: 214;
  transform: rotate(-90deg); transform-origin: 40px 40px;
}
.modal-fist { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 42px; }
.modal-fist.vfist { animation: vPop .5s ease-in-out infinite alternate; }
@keyframes vPop { from { transform: scale(1) rotate(-6deg); } to { transform: scale(1.12) rotate(6deg); } }

/* ---------------- toast / 飞星 ---------------- */
#toast {
  position: fixed; left: 50%; bottom: 10vh; z-index: 950;
  transform: translateX(-50%) translateY(16px);
  background: var(--ink); color: #fff;
  font-size: 15px; font-weight: 800; letter-spacing: 2px;
  padding: 11px 24px; border-radius: 999px;
  opacity: 0; pointer-events: none;
  transition: opacity .22s, transform .22s;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.fly-star {
  position: fixed; z-index: 940; width: 44px; height: 44px;
  pointer-events: none; will-change: transform, opacity;
  filter: drop-shadow(0 0 6px rgba(240,193,75,.6));
}
.fly-star svg { width: 100%; height: 100%; }

/* ---------------- 窄屏 ---------------- */
@media (max-width: 760px) {
  .shelf { padding-bottom: 20px; }
  .shelf::after { display: none; }
  .hintbar { font-size: 10.5px; padding: 7px 12px; }
  .monster { width: 44%; left: -8%; top: -26%; }
  #camBox { width: 140px; }
}
