/* 桌面保留原有排布；这些容器只在手机端成为面板。 */
.mobile-room-only{display:none}
.room-chat-panel,.room-tools-panel,.mobile-chat-history,.chat-preferences,.chat-preferences::details-content{display:contents}

@media (max-width:700px){
  #live2d:has(.mobile-room){padding:0;border:0;scroll-margin-top:0}
  #live2d:has(.mobile-room)>.wrap{width:100%}
  #live2d:has(.mobile-room)>.wrap>.section-head{display:none}
  #live2d:has(.mobile-room)>.wrap>.source-note{margin:1rem .8rem 0;padding:.7rem .5rem 1.5rem}
  .l2d-layout.mobile-room{
    /* 这些浮层直接叠在每帧重绘的 WebGL 画布上。backdrop-filter 会让浏览器每帧重算高斯模糊
       （Chromium 只在背景内容无变化时才复用模糊结果），是手机长时间运行最大的一笔额外开销。
       浮层底色改到接近实色后观感几乎没有变化，却省掉了整个画布上方逐帧的模糊重算；
       面板内部的半透明分层（聊天记录、气泡、标签）保留，观感不变。 */
    --room-glass:color-mix(in srgb,var(--card) 97%,transparent);
    --room-glass-soft:color-mix(in srgb,var(--card) 90%,transparent);
    --room-zoom-top:calc(max(.7rem,env(safe-area-inset-top)) + 54px);
    --room-panel-limit:calc(100% - var(--room-zoom-top) - 170px - max(.6rem,env(safe-area-inset-bottom)));
    position:relative;isolation:isolate;display:block;width:100%;height:100svh;min-height:360px;
    overflow:hidden;scroll-margin-top:0;background:var(--bg-alt);color:var(--ink);border-radius:0;
  }
  .mobile-room.is-immersive{position:fixed;z-index:220;inset:var(--room-viewport-top,0px) 0 auto;height:var(--room-viewport-height,100dvh);min-height:0}
  body.room-immersive{overscroll-behavior:none}
  body.room-immersive #backToTop{display:none}
  .mobile-room .l2d-stage{
    position:absolute;inset:0 auto auto 0;top:0;width:100%;height:max(100svh,100%);max-height:none;
    border:0;border-radius:0;box-shadow:none;
    background:radial-gradient(ellipse at 34% 26%,#fffafd 0%,transparent 58%),linear-gradient(145deg,#ffe3ee 0%,#e6f5ff 60%,#ede8ff 100%);
  }
  [data-theme="night"] .mobile-room .l2d-stage{background:radial-gradient(ellipse at 32% 28%,#44324d 0%,transparent 62%),linear-gradient(145deg,#251d37,#162e42 70%,#281e41)}
  .mobile-room .l2d-stage::after{content:"";position:absolute;inset:0;pointer-events:none;background:linear-gradient(180deg,color-mix(in srgb,var(--bg) 45%,transparent),transparent 22%,transparent 66%,color-mix(in srgb,var(--bg) 70%,transparent));z-index:1}
  .mobile-room .room-label{display:none}
  .mobile-room .l2d-status{z-index:2;top:44%;font-size:13px;max-width:80%}
  .mobile-room .l2d-fallback{padding:5rem 4rem 7rem 1.5rem}
  .mobile-room .l2d-fallback img{max-height:72%}
  .mobile-room .mobile-room-only{display:flex}
  .mobile-room-top{position:absolute;z-index:4;top:max(.7rem,env(safe-area-inset-top));left:max(.7rem,env(safe-area-inset-left));right:max(.7rem,env(safe-area-inset-right));align-items:center;gap:.65rem;pointer-events:none}
  .mobile-room-top>*{pointer-events:auto}
  .mobile-room-title{flex:1;min-width:0;display:flex;flex-direction:column;gap:.12rem;line-height:1.45;text-shadow:0 1px 8px var(--bg)}
  .mobile-room-title strong{font-size:17px;letter-spacing:.08em}
  .mobile-room-title span{font-size:12px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:100%}
  .mobile-room-icon,.mobile-room-action,.mobile-panel-close,.mobile-panel-settings,.mobile-panel-tabs button,.mobile-room-prompt{color:var(--ink);font-family:var(--font);font-weight:700;cursor:pointer;touch-action:manipulation}
  .mobile-room-icon{display:grid;place-items:center;flex:0 0 44px;width:44px;height:44px;border-radius:50%;border:1px solid var(--line);background:var(--room-glass-soft);font-size:28px;line-height:1}
  .mobile-room-browse{display:flex;flex-direction:column;gap:2px;border-radius:14px;font-size:10px}
  .mobile-room-browse svg{width:18px;height:18px}
  .mobile-room svg{width:22px;height:22px;fill:none;stroke:currentColor;stroke-width:1.8;stroke-linecap:round;stroke-linejoin:round;flex-shrink:0}
  .mobile-room :is(button,summary):focus-visible{outline:2px solid var(--coral-deep);outline-offset:3px}
  .mobile-room-rail{position:absolute;z-index:6;right:max(.6rem,env(safe-area-inset-right));top:max(var(--room-zoom-top),calc(50% - 240px));bottom:max(80px,calc(env(safe-area-inset-bottom) + 64px));width:50px;flex-direction:column;gap:5px;overflow-x:hidden;overflow-y:auto;overscroll-behavior:contain;scrollbar-width:none;pointer-events:auto}
  .mobile-room-dock{position:static;width:50px;flex:0 0 auto;flex-direction:column;gap:5px;pointer-events:none}
  .mobile-room:not([data-panel="closed"]) .mobile-room-rail{top:var(--room-zoom-top);bottom:auto;max-height:calc(100% - var(--room-zoom-top) - max(.6rem,env(safe-area-inset-bottom)))}
  .mobile-room-action{min-width:46px;min-height:48px;flex-shrink:0;padding:4px 3px;display:flex;align-items:center;justify-content:center;flex-direction:column;gap:2px;border:1px solid var(--line);border-radius:15px;background:var(--room-glass-soft);box-shadow:0 4px 18px #241b2d0a;font-size:11px;line-height:1.25;pointer-events:auto}
  .mobile-room-action svg{width:20px;height:20px}
  .mobile-room-arrow{font-size:21px;line-height:20px}
  .mobile-room-prompt{position:absolute;z-index:3;left:max(1rem,env(safe-area-inset-left));right:max(1rem,env(safe-area-inset-right));bottom:max(1rem,env(safe-area-inset-bottom));min-height:48px;align-items:center;justify-content:space-between;gap:1rem;padding:.7rem 1rem;border:1px solid var(--line);border-radius:99px;background:var(--room-glass-soft);font-size:14px;text-align:left}
  .mobile-room-prompt span:last-child{font-size:22px;line-height:1}
  .mobile-room:not([data-panel="closed"]) :is(.mobile-room-dock,.mobile-room-prompt){display:none}
  .mobile-room .l2d-controls{
    position:absolute;z-index:5;inset:auto max(.6rem,env(safe-area-inset-right)) max(.6rem,env(safe-area-inset-bottom)) max(.6rem,env(safe-area-inset-left));
    display:flex;flex-direction:column;gap:0;width:auto;height:min(350px,50%);max-height:var(--room-panel-limit);min-height:0;
    margin:0;padding:0;border:1px solid var(--line);border-radius:18px;overflow:hidden;overscroll-behavior:contain;
    background:var(--room-glass);box-shadow:0 8px 28px #241b2d18;
  }
  .mobile-room[data-panel="closed"] .l2d-controls{display:none}
  .mobile-room:is([data-panel="tools"],[data-panel="expressions"],[data-panel="motions"]) .l2d-controls{height:auto;max-height:min(350px,46%,var(--room-panel-limit))}
  .mobile-panel-heading{flex:0 0 auto;min-height:44px;align-items:center;justify-content:space-between;gap:0;padding:0 .35rem;border-bottom:1px solid var(--line)}
  .mobile-panel-tabs{display:flex;gap:0;min-width:0}
  .mobile-panel-tabs button,.mobile-panel-close{min-width:44px;min-height:44px;padding:.25rem .45rem;border:0;background:transparent;font-size:12px;white-space:nowrap}
  .mobile-panel-tabs button[aria-pressed="true"]{color:var(--coral-deep);box-shadow:inset 0 -2px var(--coral-deep)}
  .mobile-panel-close{color:var(--ink-soft);display:flex;align-items:center;gap:.3rem}
  .mobile-panel-close span{font-size:24px;line-height:1}
  .mobile-panel-actions{display:flex;align-items:center;flex-shrink:0}
  .mobile-panel-settings{display:grid;place-items:center;width:44px;height:44px;padding:0;border:0;background:transparent}
  .mobile-panel-settings[aria-expanded="true"]{color:var(--coral-deep)}
  .mobile-room:not([data-panel="chat"]) .mobile-panel-settings{display:none}
  .mobile-room .room-chat-panel{display:none;flex:1;min-height:0;overflow:hidden;flex-direction:column;padding:.2rem .55rem .4rem}
  .mobile-room[data-panel="chat"] .room-chat-panel{display:flex}
  .mobile-room .chat-heading{display:none}
  .mobile-room .chat-heading h3{display:none}
  .mobile-room .chat-heading .small-badge{font-size:11px;line-height:1.5;padding:0 .4rem;max-width:100%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;background:color-mix(in srgb,var(--bg-alt) 38%,transparent)}
  .mobile-room .chat-preferences{display:none;flex:0 1 auto;min-height:0;max-height:44%;overflow:auto;margin:0;border-bottom:1px solid var(--line);font-size:12px}
  .mobile-room .chat-preferences[open]{display:block;min-height:48px;margin-bottom:.3rem}
  .mobile-room .chat-preferences::details-content{display:block}
  .mobile-room .chat-preferences>summary{display:none}
  .mobile-room .chat-options{margin:.25rem 0;gap:.35rem}
  .mobile-room .chat-options select{min-width:136px;max-width:11rem;background:var(--room-glass-soft)}
  .mobile-room .l2d-controls .chat-options .chip{font-size:12px;min-height:44px}
  .mobile-room .l2d-controls .chat-options :is(#anonChatWebSearch,#anonVoiceAuto,#anonChatUnlock,#anonChatLock){min-height:30px;padding:3px 8px;font-size:11px;line-height:1.35}
  .mobile-room .l2d-controls .chat-disclosure{font-size:11px;line-height:1.5;margin:.3rem 0 .5rem}
  .mobile-room .mobile-chat-history{position:relative;display:flex;flex:1 1 100px;min-height:64px;overflow:hidden}
  .mobile-room .chat-log{flex:1;height:auto;min-height:0;padding:.35rem;gap:.35rem;border-radius:10px;background:color-mix(in srgb,var(--bg) 12%,transparent)}
  .mobile-room .l2d-controls .chat-message{flex-shrink:0;font-size:13px;line-height:1.55;padding:.3rem .45rem;max-width:97%;background:color-mix(in srgb,var(--card) 42%,transparent)}
  .mobile-room .l2d-controls .chat-message strong{font-size:11px}
  .mobile-room .l2d-controls .chat-message--user{background:color-mix(in srgb,var(--coral-soft) 48%,transparent)}
  .mobile-room .chat-voice{gap:.3rem;margin-top:.2rem;font-size:11px;line-height:1.4}
  .mobile-room .l2d-controls .chat-voice-button{min-height:28px;padding:3px 8px;font-size:11px;line-height:1.35;background:var(--room-glass-soft)}
  .mobile-room .chat-voice-toggle[aria-checked="true"]{background:color-mix(in srgb,var(--coral-soft) 48%,transparent)}
  .mobile-room .chat-sources{font-size:11px;line-height:1.5;margin-top:.25rem;padding-top:.2rem}
  .mobile-room .chat-sources summary{min-height:32px}
  .mobile-room .chat-sources a{padding:.25rem 0}
  .mobile-room .chat-search-toggle[aria-checked="true"]{background:color-mix(in srgb,var(--coral-soft) 48%,transparent)}
  .mobile-room .chat-latest-row{position:absolute;right:.4rem;bottom:.35rem;margin:0}
  .mobile-room .chat-latest-row:has(button[hidden]){display:none}
  .mobile-room .chat-latest-row .chip{min-height:32px;font-size:12px;padding:.2rem .55rem}
  .mobile-room .chat-prompts{display:none}
  .mobile-room .chat-form{flex:0 0 auto;margin-top:.35rem}
  .mobile-room .chat-form>label{position:absolute;width:1px;height:1px;margin:-1px;padding:0;clip:rect(0,0,0,0);overflow:hidden;white-space:nowrap}
  .mobile-room .chat-compose{gap:.4rem}
  /* 输入框维持 16px，避免 iOS 聚焦时自动放大；阅读文字使用更紧凑的 13px。 */
  .mobile-room .l2d-controls .chat-compose input{font-size:16px;min-height:44px;padding:.35rem .5rem;background:var(--room-glass-soft)}
  .mobile-room .chat-compose .btn{min-height:44px;padding:.35rem .7rem;font-size:13px}
  .mobile-room .chat-status-row{flex:0 0 auto;min-height:18px;gap:.4rem;margin-top:.25rem}
  .mobile-room .l2d-controls .chat-state{font-size:11px;line-height:1.4;max-height:2.8em;overflow:auto;min-height:0;margin:0}
  .mobile-room .chat-status-row .chip{min-height:36px;font-size:12px;padding:.25rem .5rem}
  .mobile-room .room-tools-panel{display:none;flex:0 1 auto;min-height:0;overflow:auto;overscroll-behavior:contain;padding:.55rem}
  .mobile-room:is([data-panel="tools"],[data-panel="expressions"],[data-panel="motions"]) .room-tools-panel{display:block}
  .mobile-room[data-panel="tools"] :is(#l2dMotionGroup,#l2dExpressionGroup),
  .mobile-room[data-panel="expressions"] :is(#mobileRoomPlayback,#l2dCostumeGroup,#l2dMotionGroup),
  .mobile-room[data-panel="motions"] :is(#mobileRoomPlayback,#l2dCostumeGroup,#l2dExpressionGroup){display:none}
  .mobile-room .mobile-room-zoom-host{position:static;display:flex;flex:0 0 auto;align-items:center;margin:0;width:50px;pointer-events:auto}
  .mobile-room .l2d-zoom{position:static;display:flex;flex-direction:column;align-items:center;gap:0;width:50px;padding:2px;border:1px solid var(--line);border-radius:16px;background:var(--room-glass-soft);box-shadow:0 4px 18px #241b2d0a}
  .mobile-room .l2d-zoom output{order:0;min-width:36px;height:24px;line-height:24px;text-align:center;font-size:12px}
  .mobile-room .l2d-zoom #l2dZoomOut{order:1}
  .mobile-room .l2d-zoom #l2dZoomIn{order:-1}
  .mobile-room .l2d-zoom #l2dZoomReset{order:2}
  .mobile-room .l2d-zoom .chip{width:44px;height:44px;border:0;background:transparent}
  .mobile-room .l2d-zoom .chip:hover:not(:disabled){background:color-mix(in srgb,var(--coral-soft) 58%,transparent)}
  .mobile-room .room-tools{padding:.4rem 0;margin-bottom:.5rem;border-bottom:1px solid var(--line)}
  .mobile-room .room-tools .chip{font-size:12px;min-height:44px}
  .mobile-room .model-settings{margin:0}
  .mobile-room .model-settings>summary{display:none}
  .mobile-room .l2d-group{margin-bottom:.4rem}
  .mobile-room .l2d-label{font-size:12px;margin-bottom:.35rem}
  .mobile-room .l2d-chips{gap:.3rem}
  .mobile-room .l2d-chips .chip{font-size:12px;min-height:44px;padding:.3rem .6rem}
  .mobile-room .l2d-controls .chip:not(.is-active){background:color-mix(in srgb,var(--card) 32%,transparent)}
  .mobile-room .l2d-controls .chip.is-active{background:color-mix(in srgb,var(--coral-deep) 85%,transparent)}
  .mobile-room .l2d-hint{font-size:11px;line-height:1.6;margin:.5rem 0 0}
  .mobile-room .chat-access-dialog{position:fixed;inset:auto .6rem auto;top:calc(var(--room-viewport-top,0px) + var(--room-viewport-height,100dvh) - max(.6rem,env(safe-area-inset-bottom)));transform:translateY(-100%);margin:0 auto;max-height:calc(var(--room-viewport-height,100dvh) - 2rem);padding:1rem;font-size:13px;background:var(--room-glass)}
  .mobile-room .chat-access-dialog::backdrop{background:#23182726}
  .mobile-room .chat-access-dialog h3{font-size:18px;margin:.3rem 0}
  .mobile-room .chat-access-dialog .eyebrow,.mobile-room .chat-access-dialog .chat-access-error:empty{display:none}
  .mobile-room .l2d-controls .chat-access-dialog :is(p,label){font-size:12px;line-height:1.6}
  .mobile-room .chat-access-dialog label{margin-top:.75rem}
  .mobile-room .chat-access-dialog input{padding:.55rem;background:var(--room-glass-soft)}
  .mobile-room .chat-access-actions .btn{font-size:13px;min-height:44px;padding:.4rem .75rem}
  /* 键盘展开后为右侧竖向缩放留出独立空间，避免盖住聊天操作。 */
  .mobile-room.is-keyboard-open .l2d-controls{right:calc(max(.6rem,env(safe-area-inset-right)) + 58px);height:calc(100% - max(76px,calc(env(safe-area-inset-top) + 66px)));max-height:calc(100% - max(76px,calc(env(safe-area-inset-top) + 66px)))}
  .mobile-room.is-keyboard-open .mobile-panel-tabs{flex:1}
  .mobile-room.is-keyboard-open .mobile-panel-tabs button{flex:1;min-width:0;padding-inline:2px;font-size:11px}
  .mobile-room.is-keyboard-open .mobile-panel-close{justify-content:center;width:44px;padding:0;font-size:0;gap:0}
  .mobile-room.is-keyboard-open .chat-heading,.mobile-room.is-keyboard-open .chat-prompts{display:none}
  .mobile-room.is-keyboard-open .chat-preferences>summary{min-height:30px;padding:.3rem .1rem}
  .mobile-room.is-keyboard-open .mobile-chat-history{min-height:32px}
  .mobile-room.is-keyboard-open .chat-latest-row{bottom:0}
}
