/* ===== 全局 ===== */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: linear-gradient(160deg, #ffe9c7, #ffd6e0 55%, #c9e7ff);
  user-select: none; -webkit-user-select: none;
  -webkit-touch-callout: none; /* 防 iOS 长按弹出菜单 */
  touch-action: manipulation; /* 消除点击延迟，防双击缩放 */
  overscroll-behavior: none; /* 防下拉刷新/边缘滚动 */
}
.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; border: none; }

.view { position: fixed; inset: 0; display: flex; flex-direction: column; }

/* ===== 书架 ===== */
#shelf { overflow-y: auto; padding-bottom: 4vh; }
.shelf-title { text-align: center; margin: 3vh 0 0.5vh; font-size: 44px; color: #7a4a1e; text-shadow: 0 2px 0 #fff; }
.shelf-sub { text-align: center; margin: 0 0 1vh; font-size: 18px; color: #a1793f; }
.reset-btn {
  display: block; margin: 0 auto 2vh; padding: 6px 18px; border-radius: 999px;
  background: rgba(255,255,255,.6); color: #a1793f; font-size: 14px; font-weight: 600;
}
.books { display: flex; justify-content: center; align-items: flex-end; gap: 32px; flex-wrap: wrap; padding: 0 24px; }
.book { display: flex; flex-direction: column; align-items: center; gap: 12px; transition: transform .2s; cursor: pointer; }
.book:hover { transform: translateY(-8px) scale(1.03); }
.book:active { transform: scale(.96); }
.book-cover {
  width: 190px; height: 240px; border-radius: 14px 22px 22px 14px;
  background: #fff; overflow: hidden; position: relative;
  box-shadow: 8px 8px 0 rgba(0,0,0,.12), inset 6px 0 0 rgba(0,0,0,.08);
  border: 3px solid #d8b17a;
  display: flex; align-items: center; justify-content: center;
}
.book-cover img { width: 100%; height: 100%; object-fit: cover; }
.book-progress {
  position: absolute; bottom: 8px; left: 50%; transform: translateX(-50%);
  background: rgba(255,255,255,.94); color: #7a4a1e;
  padding: 4px 12px 6px; border-radius: 999px; white-space: nowrap;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
}
.bp-num { font-size: 17px; font-weight: 800; line-height: 1; }
.bp-bar { display: block; width: 100px; height: 9px; border-radius: 999px; background: #ecd9b8; overflow: hidden; }
.bp-bar i { display: block; height: 100%; border-radius: 999px; background: linear-gradient(90deg,#ffb300,#ff8f00); }
.book-name {
  font-size: 20px; font-weight: 700; color: #fff;
  background: var(--c); padding: 5px 18px; border-radius: 999px;
  box-shadow: 0 3px 0 rgba(0,0,0,.15);
}

/* 窄屏：书本缩小，避免拥挤 */
@media (max-width: 900px) {
  .books { gap: 18px; }
  .book-cover { width: 140px; height: 178px; }
  .book-name { font-size: 16px; padding: 4px 14px; }
}

/* ===== 反应板 ===== */
#board {
  display: flex; align-items: stretch; gap: 12px;
  padding: 14px 16px; flex: 0 0 auto;
}
.round-btn {
  width: 56px; min-width: 56px; border-radius: 18px; font-size: 26px;
  background: #fff; box-shadow: 0 4px 0 rgba(0,0,0,.12); transition: transform .1s;
}
.round-btn:active { transform: scale(.92); }
.help-btn {
  background: #4fc3f7; color: #fff; font-size: 28px;
  box-shadow: 0 4px 0 #0288d1;
}
#board-area {
  flex: 1; height: 190px; position: relative;
  display: flex; align-items: center; justify-content: center;
  background: repeating-linear-gradient(90deg, #e9c894 0 34px, #e2bd82 34px 68px);
  border: 5px solid #b98a4e; border-radius: 22px;
  box-shadow: inset 0 -8px 0 rgba(0,0,0,.08), 0 6px 14px rgba(0,0,0,.15);
}
/* 实验台公式：槽 + 槽 = ？ */
.formula { display: flex; align-items: center; gap: 16px; }
.slot {
  width: 116px; height: 116px; border-radius: 50%; position: relative;
  border: 4px dashed #b98a4e; background: rgba(255,255,255,.45);
  display: flex; align-items: center; justify-content: center;
  transition: border-color .2s, background .2s, transform .2s;
}
.slot.filled { border-style: solid; background: rgba(255,255,255,.8); }
.slot.target { border-color: #ff9800; background: rgba(255,200,80,.3); transform: scale(1.06); }
.slot.shake { animation: slotShake .5s; }
@keyframes slotShake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-9px); }
  75% { transform: translateX(9px); }
}
.op { font-size: 46px; font-weight: 800; color: #8a5a20; text-shadow: 0 2px 0 rgba(255,255,255,.5); }
/* 说明槽位：把物品放上来查看反应公式 */
.info-slot {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  width: 62px; height: 62px; border-radius: 16px;
  background: #e3f2fd; border: 3px dashed #64b5f6; color: #1976d2;
  display: flex; align-items: center; justify-content: center; font-size: 30px;
  transition: transform .2s, background .2s, border-color .2s;
}
.info-slot.target { background: #bbdefb; border-style: solid; border-color: #1976d2; transform: translateY(-50%) scale(1.1); }
.result-spot {
  width: 100px; height: 100px; border-radius: 50%;
  background: rgba(255,255,255,.6); border: 4px solid #e2bd82;
  display: flex; align-items: center; justify-content: center;
  font-size: 42px; color: #b98a4e;
}
/* 槽上的物品 */
.b-item { position: relative; width: 100px; height: 100px; filter: drop-shadow(0 4px 5px rgba(0,0,0,.25)); }
.b-item img { width: 100%; height: 100%; object-fit: contain; pointer-events: none; }
.remove-btn {
  position: absolute; top: -12px; right: -12px; width: 42px; height: 42px;
  border-radius: 50%; background: #ff7043; color: #fff; font-size: 18px; font-weight: 700;
  box-shadow: 0 3px 0 #d84315; z-index: 3;
}
.remove-btn:active { transform: scale(.88); }

/* 窄屏适配：缩小公式元素防拥挤 */
@media (max-width: 680px) {
  .formula { gap: 10px; }
  .slot { width: 92px; height: 92px; border-width: 3px; }
  .b-item { width: 80px; height: 80px; }
  .op { font-size: 32px; }
  .result-spot { width: 78px; height: 78px; font-size: 30px; }
  #board-area { height: 172px; }
}

/* ===== 书页 ===== */
#page-wrap { flex: 1; display: flex; align-items: stretch; gap: 8px; padding: 0 10px 6px; min-height: 0; perspective: 1400px; }
.page-arrow {
  width: 48px; min-width: 48px; border-radius: 16px; font-size: 34px; font-weight: 800;
  background: rgba(255,255,255,.75); color: #b98a4e; box-shadow: 0 4px 0 rgba(0,0,0,.1);
}
.page-arrow:active { transform: scale(.92); }
.page-arrow:disabled { opacity: .3; }
.page-arrow.hint { animation: arrowPulse 1s ease-in-out infinite; }
@keyframes arrowPulse {
  0%, 100% { background: rgba(255,255,255,.75); }
  50% { background: #ffe95e; box-shadow: 0 0 18px #ffb300; }
}
#page {
  flex: 1; background: #fffdf5; border-radius: 20px;
  border: 4px solid #e8d9b8; box-shadow: 0 8px 20px rgba(0,0,0,.1);
  padding: 12px 16px 20px; position: relative; overflow: hidden; min-height: 0;
  transform-style: preserve-3d; backface-visibility: hidden;
}
/* 翻页动画：前后翻都绕同一条左侧书脊轴，方向相反，像真书 */
#page.flipping { animation: pageFlipFwd .45s cubic-bezier(.3,.7,.4,1); transform-origin: left center; }
#page.flipping-back { animation: pageFlipBack .45s cubic-bezier(.3,.7,.4,1); transform-origin: left center; }
@keyframes pageFlipFwd {
  0%   { transform: rotateY(-75deg); opacity: .3; box-shadow: 30px 8px 30px rgba(0,0,0,.25); }
  55%  { opacity: 1; }
  100% { transform: rotateY(0deg); opacity: 1; box-shadow: 0 8px 20px rgba(0,0,0,.1); }
}
@keyframes pageFlipBack {
  0%   { transform: rotateY(75deg); opacity: .3; box-shadow: 30px 8px 30px rgba(0,0,0,.25); }
  55%  { opacity: 1; }
  100% { transform: rotateY(0deg); opacity: 1; box-shadow: 0 8px 20px rgba(0,0,0,.1); }
}
#page::before { /* 书脊装订线 */
  content: ""; position: absolute; top: 0; bottom: 0; left: 50%; width: 2px;
  background: repeating-linear-gradient(#e8d9b8 0 14px, transparent 14px 24px); opacity: .7;
}
.page-name { text-align: center; font-size: 22px; font-weight: 800; color: #b98a4e; margin-bottom: 8px; }
.cards {
  display: flex; flex-wrap: wrap; justify-content: center; align-content: center;
  gap: 22px 30px; height: calc(100% - 44px); overflow: auto; padding: 6px;
}
.page-dots { display: flex; justify-content: center; gap: 10px; padding-bottom: 8px; }
.dot { width: 12px; height: 12px; border-radius: 50%; background: rgba(0,0,0,.15); }
.dot.on { background: #b98a4e; transform: scale(1.25); }

/* 我的口袋：已解锁物品随身收纳，跨书取材料 */
#pocket {
  display: flex; align-items: center; gap: 8px;
  max-width: 820px; width: 100%; margin: 0 auto; padding: 2px 14px 10px;
}
.pocket-label { font-size: 26px; font-weight: 800; color: #7a5a2e; flex: 0 0 auto; }
#pocket-items {
  display: flex; gap: 10px; overflow-x: auto; padding: 5px 2px; flex: 1;
  scrollbar-width: thin;
}
#pocket-items:empty::after {
  content: "解锁的物品会收进口袋，在哪本书都能拿出来用哦";
  color: rgba(0,0,0,.35); font-size: 13px; align-self: center;
}
.p-item {
  flex: 0 0 auto; width: 66px; height: 66px; border-radius: 50%;
  background: #fff; border: 3px solid #ffd54f; cursor: grab; touch-action: none;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 5px rgba(0,0,0,.16);
}
.p-item img { width: 52px; height: 52px; object-fit: contain; pointer-events: none; }
.p-item.drag-src { opacity: .4; }
.p-item.glow { animation: glowPulse 1.1s ease-in-out infinite; border-color: #ffb300; }

/* 物品卡片 */
.card {
  position: relative; width: 118px; display: flex; flex-direction: column; align-items: center; gap: 2px;
  touch-action: none;
}
.card img.item-img {
  width: 100px; height: 100px; object-fit: contain;
  filter: drop-shadow(0 4px 4px rgba(0,0,0,.18));
  transition: filter .3s, transform .3s;
}
.card .item-label { font-size: 15px; font-weight: 700; color: #7a5a2e; min-height: 20px; }
.card.locked img.item-img { filter: brightness(0) opacity(.72); } /* 黑灰剪影 */
.card.locked .item-label { color: #999; }
.card.drag-src img.item-img { opacity: .35; }
.card.glow img.item-img { animation: glowPulse 1.1s ease-in-out infinite; }
.card.just-unlocked img.item-img { animation: unlockPop .8s cubic-bezier(.2,1.6,.4,1); }
.card .speak-btn {
  position: absolute; top: -12px; right: -8px; width: 48px; height: 48px;
  border-radius: 50%; background: #ffca4f; font-size: 24px;
  box-shadow: 0 3px 0 #d19a1e; z-index: 2;
}
.card .speak-btn:active { transform: scale(.88); }
.card.locked .speak-btn { background: #cfcfcf; box-shadow: 0 3px 0 #a5a5a5; }

/* 发光提示 */
@keyframes glowPulse {
  0%, 100% { filter: drop-shadow(0 0 4px #ffe95e) drop-shadow(0 0 10px #ffb300); }
  50% { filter: drop-shadow(0 0 14px #fff3a0) drop-shadow(0 0 26px #ffd54f); }
}

/* ===== 动态引导箭头（SVG 覆盖层） ===== */
#guide-svg {
  position: absolute; inset: 0; width: 100%; height: 100%;
  pointer-events: none; z-index: 40;
}
.guide-path {
  fill: none; stroke: #ff9800; stroke-width: 5; stroke-linecap: round;
  stroke-dasharray: 12 10; opacity: .9;
  animation: dashFlow .7s linear infinite;
}
@keyframes dashFlow { to { stroke-dashoffset: -22; } }

/* ===== 拖拽幽灵 ===== */
.drag-ghost {
  position: fixed; z-index: 900; width: 100px; height: 100px;
  transform: translate(-50%, -55%) scale(1.08);
  pointer-events: none; filter: drop-shadow(0 10px 12px rgba(0,0,0,.3));
}
.drag-ghost img { width: 100%; height: 100%; object-fit: contain; }

/* ===== 反应动画 ===== */
.b-item.reacting { animation: reactSpin .7s ease-in forwards; }
@keyframes reactSpin {
  0% { transform: scale(1) rotate(0); }
  60% { transform: scale(1.25) rotate(180deg); filter: brightness(1.6); }
  100% { transform: scale(0) rotate(360deg); }
}
.pop-item {
  position: fixed; z-index: 950; width: 110px; height: 110px;
  transform: translate(-50%,-50%) scale(0); pointer-events: none;
  filter: drop-shadow(0 6px 8px rgba(0,0,0,.3));
  animation: popIn .6s cubic-bezier(.2,1.7,.4,1) forwards;
}
.pop-item img { width: 100%; height: 100%; object-fit: contain; }
@keyframes popIn { to { transform: translate(-50%,-50%) scale(1); } }
.spark {
  position: fixed; z-index: 940; width: 12px; height: 12px; border-radius: 50%;
  background: radial-gradient(#fff7c0, #ffb300); pointer-events: none;
  animation: sparkFly .8s ease-out forwards;
}
@keyframes sparkFly {
  from { transform: translate(0,0) scale(1); opacity: 1; }
  to { transform: translate(var(--dx), var(--dy)) scale(.2); opacity: 0; }
}

/* ===== 解锁动画 ===== */
@keyframes unlockPop {
  0% { transform: scale(.4) rotate(-15deg); filter: brightness(0); }
  55% { transform: scale(1.25) rotate(6deg); }
  100% { transform: scale(1) rotate(0); }
}
.fly-item {
  position: fixed; z-index: 960; width: 110px; height: 110px;
  transform: translate(-50%,-50%); pointer-events: none;
  animation: flyMove .85s cubic-bezier(.35,-0.15,.3,1.1) forwards; /* 位移由 CSS 变量驱动 */
  filter: drop-shadow(0 6px 8px rgba(0,0,0,.3));
}
@keyframes flyMove {
  to { transform: translate(calc(-50% + var(--fly-dx, 0px)), calc(-50% + var(--fly-dy, 0px))) scale(var(--fly-scale, 1)); }
}
.fly-item img { width: 100%; height: 100%; object-fit: contain; }

/* ===== 故事弹层 ===== */
.modal { position: fixed; inset: 0; z-index: 1000; background: rgba(60,30,10,.45); display: flex; align-items: center; justify-content: center; }
.modal-card {
  background: #fffdf5; border-radius: 28px; padding: 28px 34px; text-align: center;
  box-shadow: 0 16px 40px rgba(0,0,0,.35); border: 5px solid #ffca4f;
  animation: modalPop .4s cubic-bezier(.2,1.5,.4,1);
  max-width: 82vw; position: relative;
}
/* 弹层弹出：只缩放不位移（popIn 带 translate(-50%,-50%) 仅用于 fly-item） */
@keyframes modalPop { from { transform: scale(.5); opacity: 0; } to { transform: scale(1); opacity: 1; } }
/* 右上角大 X 关闭按钮：够大、好按 */
.modal-x {
  position: absolute; top: -18px; right: -18px; width: 56px; height: 56px;
  border-radius: 50%; background: #ff6b57; color: #fff; font-size: 26px; font-weight: 800;
  box-shadow: 0 5px 0 #d14433, 0 6px 14px rgba(0,0,0,.3); border: 4px solid #fffdf5;
  display: flex; align-items: center; justify-content: center; line-height: 1;
}
.modal-x:active { transform: translateY(3px); box-shadow: 0 2px 0 #d14433; }
.modal-items { display: flex; justify-content: center; gap: 18px; margin-bottom: 12px; }
.modal-items img { width: 96px; height: 96px; object-fit: contain; filter: drop-shadow(0 4px 6px rgba(0,0,0,.2)); }
.modal-title { font-size: 24px; font-weight: 800; color: #7a4a1e; margin-bottom: 18px; }
.big-speak {
  font-size: 24px; font-weight: 800; color: #7a4a1e; background: #ffca4f;
  border-radius: 999px; padding: 12px 30px; box-shadow: 0 5px 0 #d19a1e; margin-bottom: 14px;
}
.big-speak:active { transform: translateY(3px); box-shadow: 0 2px 0 #d19a1e; }
.big-speak.speaking { animation: speakWiggle 1s ease-in-out infinite; }
@keyframes speakWiggle { 0%,100% { transform: rotate(-2deg);} 50% { transform: rotate(2deg);} }
.modal-close { display: block; margin: 0 auto; font-size: 18px; font-weight: 700; color: #b98a4e; background: none; }

/* ===== 物品图鉴卡 ===== */
.detail-card {
  min-width: min(520px, 90vw); max-width: 88vw;
  max-height: 86vh; overflow-y: auto; touch-action: pan-y; /* 触屏内可上下滚动 */
  padding: 22px 26px; text-align: center;
}
.detail-head { display: flex; align-items: center; justify-content: center; gap: 16px; }
.detail-img { width: 96px; height: 96px; object-fit: contain; filter: drop-shadow(0 4px 6px rgba(0,0,0,.2)); }
.detail-name { font-size: 30px; font-weight: 900; color: #7a4a1e; }
.detail-speak { font-size: 17px; padding: 8px 18px; margin-top: 8px; }
.rx-section-title { font-size: 17px; font-weight: 800; color: #a1793f; text-align: left; margin: 14px 2px 2px; }
.rx-row {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  background: #fff; border: 3px dashed #e6c88f; border-radius: 18px;
  padding: 8px 12px; margin: 8px 0; cursor: pointer;
}
.rx-cell {
  width: 62px; height: 62px; flex: none;
  display: flex; align-items: center; justify-content: center; border-radius: 50%;
}
.rx-cell img { width: 54px; height: 54px; object-fit: contain; }
.rx-cell.rx-locked img { filter: brightness(0) opacity(.72); } /* 未解锁：黑色剪影 */
.rx-lock { font-size: 22px; margin-left: 6px; }
.rx-focus { background: #fff3c4; box-shadow: 0 0 0 3px #ffca4f; } /* 当前物品高亮 */
.rx-op { font-size: 24px; font-weight: 800; color: #b98a4e; }
/* 图鉴卡反应行的听故事按钮 */
.rx-story-btn {
  flex: none; width: 40px; height: 40px; border-radius: 50%;
  border: none; background: #ffca4f; font-size: 20px; cursor: pointer;
  box-shadow: 0 3px 0 #d19a1e; margin-left: 4px;
}
.rx-story-btn:active { transform: scale(.88); }
.rx-story-btn.speaking { background: #7ed957; box-shadow: 0 3px 0 #4d9e31; animation: speakPulse 1s infinite; }
@keyframes speakPulse { 50% { transform: scale(1.12); } }
.rx-empty { color: #b39b78; font-size: 15px; padding: 10px 0; text-align: center; }
.rx-hidden { opacity: 0; }
.rx-pop { animation: rxPop .5s cubic-bezier(.2,1.6,.4,1); }
@keyframes rxPop { from { transform: scale(0); opacity: 0; } 60% { transform: scale(1.2); } to { transform: scale(1); opacity: 1; } }
.merge-l { animation: mergeL .5s ease-in-out; }
.merge-r { animation: mergeR .5s ease-in-out; }
@keyframes mergeL { 40% { transform: translateX(14px) scale(.8); } }
@keyframes mergeR { 40% { transform: translateX(-14px) scale(.8); } }

/* 小提示气泡 */
.toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%);
  background: rgba(60,30,10,.85); color: #fff; padding: 10px 22px; border-radius: 999px;
  font-size: 17px; z-index: 1100; animation: toastIn .3s;
}
@keyframes toastIn { from { opacity: 0; transform: translateX(-50%) translateY(12px); } }
