.world-tools { max-width:none; align-items:center; padding:8px; z-index:6; }
.world-tools .world-button { min-height:40px; }
.hud-actions .live-status { border-radius:5px; }
#world-settings, #welcome-guide { width:min(600px,calc(100vw - 32px)); max-height:86dvh; overflow:auto; padding:24px; }
#welcome-guide { width:min(480px,calc(100vw - 32px)); padding:30px; }
#welcome-guide h2 { margin:18px 0 14px; font-size:1.9rem; }
#welcome-guide .button-row { margin-top:24px; }
.world-settings-grid { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:16px; margin:22px 0 14px; }
.world-settings-grid label { display:block; font-size:.8rem; color:#d8e5dc; min-width:0; }
.world-settings-grid select { display:block; width:100%; padding:10px; margin-top:7px; background:#10252d; color:var(--ink); border:1px solid #506369; border-radius:8px; }
.world-settings-grid input[type=range] { display:block; width:100%; margin:18px 0 8px; accent-color:var(--mint); cursor:pointer; }
.sensitivity-field output { float:right; color:var(--mint); }
.sensitivity-field .small-note { font-size:.68rem; }
.keyboard-settings { border-top:1px solid var(--line); border-bottom:1px solid var(--line); padding:15px 0; margin:18px 0; }
.keyboard-settings summary { cursor:pointer; font-weight:550; }
.keyboard-settings>p { font-size:.75rem; margin:12px 0; }
.key-binding-row { display:grid; grid-template-columns:minmax(100px,1.3fr) 1fr 1fr; align-items:center; gap:10px; margin:8px 0; font-size:.78rem; }
.key-binding-row button { min-height:38px; }
.key-binding-head { color:var(--muted); font-size:.65rem; margin-top:18px; }
.settings-utilities { border-top:1px solid var(--line); padding-top:16px; }
.vrm-viewer .touch-controls { display:none; }
.vrm-viewer.touch-enabled .touch-controls { position:absolute; left:20px; right:20px; bottom:calc(var(--world-tools-height,56px) + 36px); display:flex; flex-direction:row; justify-content:space-between; align-items:end; gap:10px; z-index:4; pointer-events:none; }
.touch-controls .movement-stick { display:grid; place-items:center; position:relative; flex:0 0 116px; width:116px; height:116px; background:radial-gradient(circle,#1b35438a,#142b309e); backdrop-filter:blur(8px); border:1px solid #d3eac77a; box-shadow:inset 0 0 0 12px #e5f3dd0a,0 4px 18px #102e3220; border-radius:50%; touch-action:none; user-select:none; pointer-events:auto; }
.movement-stick::after { content:'MOVE'; position:absolute; bottom:-22px; font-size:.55rem; letter-spacing:.15em; color:#e1ebde; text-shadow:0 1px 3px #142b30; }
.movement-stick:focus-visible { outline:3px solid var(--mint); outline-offset:4px; }
.movement-stick.active { border-color:#d3eac7; }
.stick-cross { position:absolute; color:#b7d8a73d; font-size:65px; font-weight:200; }
#movement-knob { width:44px; height:44px; border-radius:50%; background:linear-gradient(145deg,#d4e9c6,#95b283); box-shadow:0 3px 12px #102c3260; border:1px solid #f0f8e299; pointer-events:none; }
.touch-controls .touch-actions { display:flex; flex-direction:column; gap:10px; pointer-events:auto; }
.touch-controls .touch-actions button { min-width:62px; width:auto; height:46px; padding:8px 13px; border-radius:15px; border:1px solid #c5dfb97a; background:#142b30da; color:#e6f0df; touch-action:none; user-select:none; font-size:.8rem; }
.touch-controls .touch-actions button[aria-pressed=true] { background:var(--mint); color:var(--deep); }
.vrm-viewer.touch-enabled .viewer-chat { bottom:calc(var(--world-tools-height,56px) + 176px); max-height:150px; }
.viewer-chat--collapsed .ai-chat-notice { display:none; }
/* The canvas must not contribute its full-screen buffer size to the page layout. */
.vrm-section-home .vrm-viewer { flex:none; min-width:0; }
.vrm-viewer > canvas { position:absolute; inset:0; width:100%; height:100%; }
.vrm-viewer:fullscreen { width:100%; height:100dvh; min-height:0; margin:0; border:0; border-radius:0; }
.vrm-section-home .vrm-viewer.viewer-fullscreen { width:100%; height:100vh; height:100dvh; min-height:0; max-height:none; margin:0; border:0; border-radius:0; }
html.world-view-expanded { overflow:hidden; overscroll-behavior:none; }
body.world-view-expanded { position:fixed; top:var(--viewer-scroll-top); left:var(--viewer-scroll-left); width:100%; overflow:hidden; }
.vrm-section-home .vrm-viewer.viewer-expanded { position:fixed; top:var(--viewer-top,0px); left:0; height:var(--viewer-height,100dvh); z-index:1050; }
.viewer-fullscreen .world-hud { top:max(10px,env(safe-area-inset-top)); left:max(10px,env(safe-area-inset-left)); right:max(10px,env(safe-area-inset-right)); }
.viewer-fullscreen .world-tools { bottom:max(10px,env(safe-area-inset-bottom)); right:max(10px,env(safe-area-inset-right)); }
.vrm-viewer.viewer-fullscreen.touch-enabled .touch-controls { left:max(20px,env(safe-area-inset-left)); right:max(20px,env(safe-area-inset-right)); bottom:calc(var(--world-tools-height,56px) + 36px + env(safe-area-inset-bottom)); }
.vrm-viewer.viewer-fullscreen.touch-enabled .viewer-chat { left:max(14px,env(safe-area-inset-left)); bottom:calc(var(--world-tools-height,56px) + 176px + env(safe-area-inset-bottom)); }
.hud-actions #fullscreen-toggle { min-height:44px; white-space:nowrap; }
.world-reduced-motion *, .world-reduced-motion *::before, .world-reduced-motion *::after { scroll-behavior:auto!important; transition:none!important; animation:none!important; }
.world-reduced-motion .world-button:hover { transform:none; }
.world-reduced-motion .interaction-prompt:hover { transform:translateX(-50%); }
@media(max-width:767px) {
  .world-tools { display:grid; grid-template-columns:repeat(4,minmax(0,1fr)); gap:5px; }
  .world-tools .world-button { padding:8px 5px; font-size:.7rem; min-height:42px; }
  .hud-actions { max-width:50%; }
  .hud-actions #world-presence { width:auto; }
  .hud-actions .live-status { padding:3px 5px; font-size:.5rem; }
  .hud-actions #fullscreen-toggle { font-size:.7rem; padding:8px; }
  .world-hud .place-label { min-width:0; }
  .world-hud .place-label > div { min-width:0; }
  .world-hud .place-label strong { overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
  .viewer-fullscreen .world-tools { left:max(10px,env(safe-area-inset-left)); }
  #world-settings { padding:18px; }
  #world-settings h2 { font-size:1.35rem; }
  #world-settings .dialog-header { gap:10px; }
  .world-settings-grid { gap:14px 10px; }
  .world-settings-grid select { font-size:.75rem; padding:9px 6px; }
  .vrm-viewer.touch-enabled .viewer-chat { min-height:105px; max-width:calc(100% - 30px); width:250px; left:14px; }
  .vrm-viewer.touch-enabled .viewer-chat--collapsed { width:115px!important; min-width:115px; }
  .vrm-viewer.touch-enabled .viewer-chat__toggle { width:30px; height:30px; top:4px; right:4px; }
  .vrm-viewer.touch-enabled .viewer-chat__resize-handle { display:none; }
  .world-caption { line-height:1.65; }
}
@media(max-height:500px) and (orientation:landscape) {
  .viewer-fullscreen .place-label { padding:6px 10px; }
  .viewer-fullscreen .place-label .eyebrow { display:none; }
  .viewer-fullscreen .hud-actions { max-width:none; flex-wrap:nowrap; padding:3px 6px; }
  .viewer-fullscreen .world-tools { left:max(10px,env(safe-area-inset-left)); display:flex; justify-content:center; flex-wrap:nowrap; padding:4px; gap:5px; }
  .viewer-fullscreen .world-tools .world-button { min-height:40px; padding:6px; font-size:.65rem; }
  .vrm-viewer.viewer-fullscreen.touch-enabled .touch-controls { bottom:calc(var(--world-tools-height,48px) + 30px + env(safe-area-inset-bottom)); }
  .viewer-fullscreen .touch-controls .movement-stick { flex-basis:88px; width:88px; height:88px; }
  .vrm-viewer.viewer-fullscreen.touch-enabled .viewer-chat { left:50%; transform:translateX(-50%); bottom:calc(var(--world-tools-height,48px) + 20px + env(safe-area-inset-bottom)); min-height:80px; max-height:calc(100% - var(--world-tools-height,48px) - 95px); width:250px; }
}
/* Give chat room above the mobile keyboard while the user is typing. */
.vrm-viewer.viewer-expanded.touch-enabled:has(.viewer-chat__input:focus) .touch-controls { display:none; }
.vrm-viewer.viewer-expanded.touch-enabled:has(.viewer-chat__input:focus) .viewer-chat { bottom:calc(var(--world-tools-height,56px) + 20px + env(safe-area-inset-bottom)); max-height:calc(100% - var(--world-tools-height,56px) - 130px); }
@media(max-width:350px) { .world-settings-grid { grid-template-columns:minmax(0,1fr); } }

/* Mobile chat slides over the world only when requested. */
@media(max-width:767px), (pointer:coarse) {
  /* Focusing a sliding panel must never scroll the world sideways. */
  .vrm-viewer { overflow:clip; }
  #viewer-chat:not(.viewer-chat--drawer) { visibility:hidden; }
}
.viewer-chat-launcher { position:absolute; top:35%; right:0; z-index:7; min-width:64px; min-height:44px; padding:10px 12px; border-radius:12px 0 0 12px; font-size:.8rem; background:#142b30ed; box-shadow:0 3px 16px #07141c30; }
@media(max-height:500px) and (orientation:landscape) { .viewer-chat-launcher { top:max(74px,calc(env(safe-area-inset-top) + 64px)); } }
.vrm-viewer #viewer-chat.viewer-chat--drawer {
  top:max(var(--chat-drawer-top,8px),env(safe-area-inset-top)); right:max(8px,env(safe-area-inset-right));
  bottom:max(var(--chat-drawer-bottom,8px),env(safe-area-inset-bottom)); left:auto;
  width:min(340px,calc(100% - 32px))!important; height:auto!important; min-width:0; min-height:0!important; max-width:none; max-height:none;
  padding:12px; gap:10px; z-index:8; background:#142b30f5; box-shadow:-8px 0 24px #07141c40; overflow:hidden;
  transform:translateX(calc(100% + max(8px,env(safe-area-inset-right)))); visibility:hidden; pointer-events:none;
  transition:transform .2s ease,visibility 0s .2s;
}
.vrm-viewer #viewer-chat.viewer-chat--drawer.viewer-chat--open { transform:translateX(0); visibility:visible; pointer-events:auto; transition-delay:0s; }
.viewer-chat--drawer .viewer-chat__drawer-heading { display:flex; align-items:center; justify-content:space-between; gap:12px; flex-shrink:0; }
.viewer-chat__drawer-heading strong { font-size:1rem; font-weight:550; }
.viewer-chat__drawer-heading button { min-width:44px; min-height:44px; padding:4px; font-size:1.5rem; line-height:1; }
.viewer-chat--drawer .viewer-chat__toggle, .viewer-chat--drawer .viewer-chat__resize-handle, .viewer-chat--drawer .viewer-chat__tablist { display:none; }
.viewer-chat--drawer .ai-chat-notice { max-height:30%; overflow:auto; flex-shrink:0; }
.viewer-chat--drawer .viewer-chat__messages { overscroll-behavior:contain; }
.viewer-chat--drawer .viewer-chat__composer { flex-shrink:0; }
.viewer-chat--drawer .viewer-chat__input { min-width:0; width:100%; font-size:16px; }
.viewer-chat--drawer .viewer-chat__send { min-height:44px; }
@media(prefers-reduced-motion:reduce) { .vrm-viewer #viewer-chat.viewer-chat--drawer { transition:none; } }
.world-interaction-actions { position:absolute; left:50%; top:48%; transform:translateX(-50%); z-index:5; width:max-content; max-width:94%; display:flex; flex-wrap:wrap; gap:5px; justify-content:center; pointer-events:none; }
.world-interaction-actions .world-button { background:#193830ed; border-color:#b5d5a0; box-shadow:0 3px 20px #0004; pointer-events:auto; }
.world-interaction-actions [hidden] { display:none; }
