*{box-sizing:border-box}html,body{margin:0;height:100%;background:#f6f3ee;color:#2b2b2b;font-family:"Noto Sans TC","PingFang TC","Microsoft JhengHei",system-ui,sans-serif}
.app{max-width:1280px;margin:0 auto;padding:14px 18px 24px}
.top{display:flex;align-items:baseline;justify-content:space-between;margin-bottom:10px}
.brand{font-weight:800;font-size:22px;letter-spacing:.3px;color:#2f5d50}.brand span{font-weight:600;color:#c96f53;margin-left:6px}
.tag{font-size:12px;color:#8a8379}
.main{display:grid;grid-template-columns:1fr 260px;gap:18px}
.stagewrap{min-width:0}
.stage{position:relative;width:100%;aspect-ratio:16/9;border-radius:18px;overflow:hidden;background:#cfe3f2;box-shadow:0 10px 30px rgba(60,50,30,.18)}
.stage canvas{display:block;width:100%;height:100%}
.loading{position:absolute;inset:0;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:12px;background:linear-gradient(#dff0fb,#f6f3ee);z-index:5;font-size:14px;color:#5b6b73}
.spin{width:34px;height:34px;border-radius:50%;border:4px solid #c9dbe6;border-top-color:#2f5d50;animation:sp 1s linear infinite}@keyframes sp{to{transform:rotate(360deg)}}
.bar{height:4px;background:#e7e1d8;border-radius:4px;margin:10px 4px 0;overflow:hidden}.prog{height:100%;width:0;background:#c96f53;border-radius:4px}
.card{background:#fff;border-radius:16px;padding:14px 18px;margin-top:12px;box-shadow:0 4px 16px rgba(60,50,30,.08)}
.wordline{display:flex;align-items:baseline;gap:10px;flex-wrap:wrap}
.word{font-size:28px;font-weight:800;color:#2f5d50}.pos{font-style:italic;color:#8a8379}.wzh{font-size:18px;color:#c96f53;font-weight:700}
.btns{margin-left:auto;display:flex;gap:8px}.replay{border:0;background:#2f5d50;color:#fff;border-radius:999px;padding:7px 14px;font-size:14px;cursor:pointer}
.sen{font-size:20px;margin:10px 0 4px;line-height:1.45}.sen b{color:#c96f53;background:#fff1e8;padding:0 4px;border-radius:6px}
.senzh{margin:0;color:#5b5b5b;font-size:16px}
.list h2{font-size:15px;margin:2px 0 10px;color:#5b5b5b}
.words{display:flex;flex-direction:column;gap:8px}
.wbtn{display:flex;justify-content:space-between;align-items:center;border:0;background:#fff;border-radius:12px;padding:10px 14px;font-size:16px;cursor:pointer;box-shadow:0 2px 8px rgba(60,50,30,.07);text-align:left}
.wbtn small{color:#8a8379;font-size:13px}.wbtn .k{font-size:11px;color:#fff;background:#9bb7ad;border-radius:999px;padding:2px 7px;margin-left:6px}
.wbtn.abs .k{background:#d99a7f}.wbtn.on{outline:3px solid #2f5d50}
.ww-overlay{position:absolute;inset:0;pointer-events:none;overflow:hidden}
.ww-bubble{position:absolute;transform:translate(-50%,-100%);background:#fff;border-radius:16px;padding:6px 12px;font:700 16px/1.2 system-ui,sans-serif;white-space:nowrap;box-shadow:0 4px 14px rgba(0,0,0,.18);opacity:0;transition:none}
.ww-bubble:after{content:"";position:absolute;left:50%;bottom:-8px;margin-left:-8px;border:8px solid transparent;border-top-color:#fff;border-bottom:0}
.ww-emote{position:absolute;font-size:30px;opacity:0;filter:drop-shadow(0 2px 3px rgba(0,0,0,.25))}
@media (max-width:760px){
  .app{padding:10px 10px 18px}.main{grid-template-columns:1fr;gap:12px}
  .stage{aspect-ratio:4/3;border-radius:14px}
  .word{font-size:24px}.sen{font-size:17px}.senzh{font-size:15px}
  .words{display:grid;grid-template-columns:1fr 1fr;gap:8px}.wbtn{padding:9px 11px;font-size:15px}
  .ww-bubble{font-size:13px;padding:5px 9px}.ww-emote{font-size:24px}
}
.credits{margin-top:14px;font-size:11px;color:#9a948b;line-height:1.5}

.next{background:#c96f53}
.busy{position:absolute;left:12px;top:12px;background:rgba(255,255,255,.9);border-radius:999px;padding:5px 12px;font-size:13px;opacity:0;transition:opacity .2s;z-index:4}
.list{max-height:calc(100vh - 90px);overflow:auto;padding-right:4px}
.unit{margin-bottom:12px}.unit summary{cursor:pointer;display:flex;justify-content:space-between;align-items:baseline;gap:8px;font-weight:700;color:#2f5d50;padding:6px 2px;list-style:none}
.unit summary::-webkit-details-marker{display:none}.unit summary small{font-weight:400;color:#8a8379;font-size:12px}
.wbtn.off{opacity:.55;cursor:not-allowed;background:#f1ede6;box-shadow:none}.wbtn.off .k{background:#b8b0a4}
@media (max-width:760px){.btns .replay{padding:7px 11px;font-size:13px}}
/* phase 2: mobile fixes for unit sections */
.main>*{min-width:0}.wbtn small{text-align:right}
@media (max-width:760px){
  .main{grid-template-columns:minmax(0,1fr)}
  .wbtn{flex-direction:column;align-items:flex-start;gap:2px;min-width:0}.wbtn small{text-align:left;font-size:12px}
  .wbtn .k{margin-left:4px}.card .btns{flex-wrap:wrap}
}

.ww-bubble.think{background:#f3f6ff;color:#4a5578;font-style:italic;border:2px dashed #aab6d8}.ww-bubble.think:after{border-top-color:#aab6d8}

/* audio UI */
.spk{border:0;background:#eef4f1;border-radius:999px;width:34px;height:34px;font-size:17px;cursor:pointer;margin-left:8px;flex:none;line-height:34px;padding:0}
.senline{display:flex;align-items:flex-start;gap:6px;margin:10px 0 0}.senline .spk{margin:2px 4px 0 0}.senline .sen{margin:0}
.mute{border:0;background:#2f5d50;color:#fff;border-radius:999px;padding:5px 12px;font-size:13px;cursor:pointer;margin-right:6px}.mute.off{background:#9a948b}
.word.speaking{color:#c96f53;transition:color .15s}.sen.reading{color:#1f3b33}.sen b{transition:background .15s,color .15s,transform .15s;display:inline-block}
.sen b.hl-on{margin-right:3px;background:#c96f53;color:#fff;border-radius:6px;transform:scale(1.08)}

.unlockbtn{white-space:nowrap;position:absolute;left:50%;top:50%;transform:translate(-50%,-50%);z-index:6;border:0;border-radius:999px;background:#c96f53;color:#fff;font-size:20px;font-weight:700;padding:14px 26px;box-shadow:0 6px 20px rgba(0,0,0,.25);cursor:pointer;animation:ubpulse 1.6s ease-in-out infinite}.unlockbtn[hidden]{display:none}@keyframes ubpulse{50%{transform:translate(-50%,-50%) scale(1.06)}}

/* sentence is revealed only after the scene animation finishes */
#card.await-sentence .senline, #card.await-sentence .senzh { display: none; }
/* embed mode (iframe in the unit pages): one scene, no list / next / prototype label */
.embed body{background:#f6f3ee}
.embed .app{padding:8px 10px 10px;max-width:none}
.embed .main{grid-template-columns:1fr;gap:0}
.embed .list,.embed .next,.embed .proto{display:none}
.embed .top{margin-bottom:6px}.embed .brand{font-size:16px}
.embed .stagewrap{width:100%;max-width:calc((100vh - 230px) * 16 / 9);margin:0 auto;min-width:min(100%,320px)}
.embed .card{padding:10px 14px;margin-top:8px}
.embed .credits{margin-top:8px;font-size:10px;line-height:1.4}
@media (max-width:760px){.embed .stagewrap{max-width:none}.embed .app{padding:6px 6px 8px}}
/* a6: in-popup navigation (上一個 / 下一個) + Grimm family story header */
.wwnav{display:flex;align-items:stretch;gap:10px;margin:8px 0 0}.wwnav[hidden],.storyhead[hidden]{display:none}
.navbtn{flex:1;min-height:56px;border:0;border-radius:16px;background:#2f5d50;color:#fff;cursor:pointer;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:1px;padding:6px 10px;box-shadow:0 3px 0 #1d3d34;touch-action:manipulation;-webkit-tap-highlight-color:transparent}
.navbtn b{font-size:19px;line-height:1.2}.navbtn small{font-size:12px;opacity:.85;max-width:100%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.navbtn.next2{background:#c96f53;box-shadow:0 3px 0 #8f4a35}
.navbtn:active{transform:translateY(2px);box-shadow:none}
.navbtn:disabled{background:#d9d3ca;color:#8a8379;box-shadow:none;cursor:default}
.navpos{flex:none;align-self:center;min-width:64px;text-align:center;font-weight:800;color:#2f5d50;font-size:16px;line-height:1.2}
.navpos small{display:block;font-size:11px;font-weight:600;color:#8a8379}
.storyhead{background:#fff7e6;border:2px solid #e8c9a0;border-radius:14px;padding:6px 10px;margin-bottom:8px}
.sh-top{display:flex;flex-wrap:wrap;align-items:baseline;gap:4px 10px}.sh-fam{font-weight:800;color:#8f4a35;font-size:15px}.sh-name{font-size:13px;color:#5b5b5b}
.chapters{list-style:none;margin:6px 0 0;padding:0;display:flex;flex-wrap:wrap;gap:5px}
.chap{border:1.5px solid #d9c2a2;background:#fff;border-radius:999px;padding:2px 9px;font-size:12px;cursor:pointer;color:#5b5b5b;line-height:1.5}
.chap.done{background:#eef5f1;border-color:#9bb7ad;color:#2f5d50}.chap.on{background:#c96f53;border-color:#c96f53;color:#fff;font-weight:700}
.chtitle{font-size:13px;color:#8f4a35;font-weight:700;margin:0 0 2px}
.embed.hasnav .stagewrap{max-width:calc((100vh - 320px) * 16 / 9)}
.embed.hasstory .stagewrap{max-width:calc((100vh - 380px) * 16 / 9)}
@media (max-width:760px){.embed.hasnav .stagewrap,.embed.hasstory .stagewrap{max-width:none}.navbtn{min-height:54px}.navbtn b{font-size:17px}.chap{font-size:11.5px;padding:2px 8px}}
/* desktop story layout: chapter list as a left column so the stage + sentence fit without scrolling */
@media (min-width:761px){
  .embed.hasstory .stagewrap{display:grid;grid-template-columns:200px minmax(0,1fr);column-gap:12px;grid-template-areas:"sh st" "sh bar" "sh nav" "sh card";
    max-width:calc((100vh - 345px) * 16 / 9 + 212px);align-items:start}
  .embed.hasstory .storyhead{grid-area:sh;margin:0;align-self:stretch}.embed.hasstory .stage{grid-area:st}.embed.hasstory .bar{grid-area:bar}
  .embed.hasstory .wwnav{grid-area:nav}.embed.hasstory .card{grid-area:card}
  .embed.hasstory .chapters{flex-direction:column;flex-wrap:nowrap}.embed.hasstory .chap{width:100%;text-align:left;font-size:13px;padding:4px 10px}
  .embed.hasstory .sh-top{flex-direction:column;gap:2px}
}

/* Keep the 3D stage + word card on screen; only the word list scrolls
   when the current word changes. Desktop already uses a scrolling .list.
   embed=1 keeps the old flowing layout so the unit-page modal can scroll. */
@media (max-width:760px){
  html:not(.embed),html:not(.embed) body{height:100%;overflow:hidden}
  html:not(.embed) .app{height:100%;height:100dvh;max-height:100dvh;display:flex;flex-direction:column;overflow:hidden;padding-bottom:max(18px,env(safe-area-inset-bottom,0px))}
  html:not(.embed) .main{flex:1 1 auto;min-height:0;display:flex;flex-direction:column;overflow:hidden}
  html:not(.embed) .stagewrap{flex:0 0 auto}
  html:not(.embed) .list{flex:1 1 auto;min-height:140px;max-height:none;overflow:auto;-webkit-overflow-scrolling:touch;overscroll-behavior:contain;padding-right:4px}
  html:not(.embed) .credits{flex:0 0 auto}
}
