
@media (max-width:640px),(max-height:520px){
  #hud #lw{display:none}
  #hud .st{gap:4px}
  #hud .st small{display:none}
  #hud .ic{font-size:15px}
  #hud .st b{font-size:14px;min-width:2.2ch}
  #hud .fx1,#hud .fx2,#hud .fx3{width:auto}
  #hud .hg:first-child{flex:none;justify-content:flex-start;gap:10px}
  #hud .hg:last-child button{position:relative;width:30px;height:30px;font-size:14px;box-shadow:0 2px 0 #0b1220;touch-action:manipulation}
  #hud .hg:last-child button::after{content:"";position:absolute;inset:-7px -3px}
  #hud .hg:last-child button svg{width:15px;height:15px}
  #hud .st.w{display:flex;align-items:center;gap:8px}
  #hud .st.w .row{flex:none;gap:6px}
  #hud .st.w small{display:inline;font-size:10px}
  #hud .st.w .bar{flex:1;height:9px;margin-top:0}
  #top .bn{padding:3px 8px;gap:6px;border-radius:10px;border-width:1.5px;font-size:11px;line-height:1.35;white-space:normal;box-shadow:0 2px 0 #0b1220,0 4px 10px #0005}
  #top .bn>span:first-child{flex:1;min-width:0;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden}
  #top .bn .mb2{width:44px;height:6px;flex:none}
  #top .bn button{position:relative;padding:2px 7px;font-size:10px;flex:none}
  #top .bn button::after{content:"";position:absolute;inset:-10px -7px}
  #chips{display:none;flex-wrap:wrap;justify-content:center;gap:4px;max-width:calc(100vw - 112px)}
  #chips>.bn{max-width:100%}
  #top .bn.chip{padding:4px 10px;gap:5px;min-height:32px;cursor:pointer;animation:chipin .3s ease-out}
  #top .bn.chip::after{content:"▾";font-size:9px;opacity:.65}
  #mnb.chip{animation:chipin .3s ease-out,chipbeat 1s .3s ease-in-out infinite}
  #top .bn.open{transition:opacity .45s ease}
  #top .bn.open.fade{opacity:0}
  #top #ms.chip .mb2{display:none}
  #chips>.bn.open{flex:1 1 100%;order:-1;cursor:pointer}
  #chips.rw{display:flex;flex-wrap:wrap;justify-content:center;align-items:stretch;gap:4px;width:100%;max-width:none;pointer-events:none}
  #chips.rw>.bn{flex:0 1 auto;min-width:0;max-width:100%;box-sizing:border-box;pointer-events:auto}
  #chips.rw>.bn.open{flex:0 1 auto;order:0}
  #top #chips.rw>.bn.chip{padding:3px 8px;gap:5px}
  #top #chips.rw>.bn.chip::after{display:none}
  #top #chips.rw>.bn.chip .mb2{display:inline-block;width:30px;height:5px}
  #top #emb.chip button{display:inline-block;min-height:24px;padding:2px 8px;font-size:10px;line-height:1.3}
  #top .bn.chip::before{content:attr(data-ic);font-size:14px;line-height:1}
  #top .bn.chip>span:first-child{display:none}
  #top .bn.chip button{display:none}
  #top .bn.chip .mb2{width:34px}
  #pp .ps{font-size:22px}
  #st2 svg{width:24px;height:24px}
  #st2 .t{font-size:10px;bottom:-7px}
  #toast{top:auto;bottom:calc(120px + env(safe-area-inset-bottom,0px));font-size:11px;padding:4px 12px}
  #big{font-size:20px;max-width:calc(100vw - 24px)}
  #toast{max-width:calc(100vw - 24px);box-sizing:border-box;white-space:normal;text-align:center;line-height:1.35;max-height:2.8em;overflow:hidden}
  #abil{right:8px;bottom:calc(8px + env(safe-area-inset-bottom,0px))}
  #tools{left:8px;bottom:calc(8px + env(safe-area-inset-bottom,0px))}
  .ab{width:66px;height:94px;padding:5px 3px;border-width:4px;border-radius:13px}
  .ab .ci{font-size:26px}
  .ab b,.ab small{font-size:10px}
  .stk.col .ab+.ab{margin-left:-48px}
  .stk.op .ab+.ab{margin-left:5px}
  body.ab-open #tools,body.tl-open #abil{visibility:hidden}
  #zm button{width:40px;height:40px;font-size:22px}
  button{touch-action:manipulation;-webkit-tap-highlight-color:transparent}
  #sel #x{min-width:44px;min-height:40px}
  #sel input[type=range]{height:30px}
  body.sel-open #zm{display:none}
}

@media (max-width:640px){
  body #top{left:8px;right:8px;top:calc(6px + env(safe-area-inset-top,0px));gap:4px}
  #top #hud{display:grid;grid-template-columns:1fr repeat(2,30px);column-gap:6px;row-gap:4px;align-items:center;padding:5px 8px 6px;border-radius:14px;box-shadow:0 3px 0 #0b1220,0 6px 14px #0006,inset 0 1px 0 #ffffff33}
  #hud .hg:first-child{grid-row:1;grid-column:1}
  #hud .hg:last-child{display:contents}
  #hud .hg:last-child button{grid-row:1}
  #hud .hg:last-child .st.w{grid-row:2;grid-column:1/-1;width:auto}
  #pp,#st2{width:42px;height:42px;border-width:3px;top:calc(68px + env(safe-area-inset-top,0px))}
  #pp{left:8px}
  #st2{right:8px}
  #top .bn{max-width:calc(100vw - 112px)}
  #chips.rw{max-width:calc(100vw - 112px)}
  #sel{left:8px;right:8px;top:auto;bottom:calc(112px + env(safe-area-inset-bottom,0px));transform:none;width:auto;max-height:36vh;max-height:36dvh;overflow-y:auto;padding:8px 10px;font-size:12px}
  #zm{left:8px;bottom:calc(112px + env(safe-area-inset-bottom,0px))}
  body.sel-open #toast{bottom:calc(124px + 36vh + env(safe-area-inset-bottom,0px))}
}

@media (max-height:520px) and (min-width:641px){
  body #top{left:64px;right:64px;top:calc(4px + env(safe-area-inset-top,0px));gap:4px}
  #top #hud{display:grid;grid-template-columns:auto 1fr repeat(2,30px);column-gap:8px;align-items:center;padding:4px 10px;border-radius:14px}
  #hud .hg:first-child{grid-row:1;grid-column:1}
  #hud .hg:last-child{display:contents}
  #hud .hg:last-child button{grid-row:1}
  #hud .hg:last-child .st.w{grid-row:1;grid-column:2;width:auto}
  #hud .hg:last-child button::after{inset:-7px -4px}
  #pp,#st2{width:44px;height:44px;border-width:3px;top:calc(6px + env(safe-area-inset-top,0px))}
  #pp{left:10px}
  #st2{right:10px}
  #chips{max-width:min(520px,calc(100vw - 140px))}
  #top .bn{max-width:min(520px,calc(100vw - 140px))}
  #chips.rw{max-width:none}
  #top #chips.rw>.bn.chip{min-height:26px}
  .ab{width:56px;height:80px}
  .ab .ci{font-size:22px}
  .stk.col .ab+.ab{margin-left:-40px}
  #sel{left:8px;top:60px;transform:none;width:250px;max-height:calc(100vh - 150px);overflow-y:auto;padding:8px 10px;font-size:12px}
  #zm{left:8px;bottom:calc(96px + env(safe-area-inset-bottom,0px))}
}

@media (max-height:520px) and (min-width:641px){
  #menu,#shop,#story{box-sizing:border-box;padding:env(safe-area-inset-top,0px) env(safe-area-inset-right,0px) env(safe-area-inset-bottom,0px) env(safe-area-inset-left,0px)}
  .mcard{box-sizing:border-box;padding:12px;width:min(560px,calc(100% - 24px))}
  .mcard.fx{height:calc(100vh - 16px - env(safe-area-inset-top,0px) - env(safe-area-inset-bottom,0px));height:calc(100dvh - 16px - env(safe-area-inset-top,0px) - env(safe-area-inset-bottom,0px))}
  .mcard h2{font-size:16px;margin-bottom:2px}
  .mcard .mfoot{padding-top:8px}

  #shop .mcard.fx{width:min(760px,calc(100% - 24px))!important}
  #shop #sl{display:grid;grid-template-columns:repeat(auto-fill,minmax(320px,1fr));gap:8px;margin-top:8px!important}
  #shop .sr{margin-bottom:0;padding:6px 8px;gap:8px}
  #shop .sr .ci{font-size:24px}
  #shop .sr b{font-size:13px}
  #shop .sr small{font-size:10.5px;line-height:1.45}
  #shop .sr button{padding:5px 8px;font-size:12px}
  #shop #shc{padding:8px!important}

  #stc{width:min(680px,calc(100% - 24px));max-height:calc(100vh - 16px - env(safe-area-inset-top,0px) - env(safe-area-inset-bottom,0px));max-height:calc(100dvh - 16px - env(safe-area-inset-top,0px) - env(safe-area-inset-bottom,0px));display:flex;flex-wrap:wrap;align-content:flex-start;gap:0 8px}
  #stc>*{flex:0 0 100%;min-width:0}
  #stc p{font-size:13px;line-height:1.7;margin:4px 0}
  #stc ul{line-height:1.6;margin:4px 0}
  #stc>.stb{flex:1 1 0;width:auto;margin-top:8px;padding:8px 6px;font-size:14px;box-shadow:0 3px 0 #0b1220}
  #stc>.stb:not(.sec){flex-grow:1.4;font-size:15px;box-shadow:0 3px 0 #365314}
  #stc>.stb.sec{font-size:13px;padding:8px 4px}
  #stc>.stb:active{transform:translateY(2px)}
  #stg{order:1}#stcm{order:2}#stx{order:3}
  .chg{grid-template-columns:repeat(4,1fr);gap:6px;margin-top:6px}
  .chb{padding:6px 4px}.chb b{font-size:18px}
  .chb small{font-size:11px;line-height:1.35}

  .ocard{max-height:calc(100dvh - 12px);overflow-y:auto;transform:scale(.85)}
  #lsc,#lroad{display:none}
  #lk svg{width:auto;height:min(84px,22vh)}
  #lg{margin-top:0;padding:4px 20px 4px 34px}
  #lg .g1,#lg .g2{font-size:28px;-webkit-text-stroke:4px #0b3b8f}
  #lt3{transform:scale(.6);transform-origin:0 0}
  #lsub{display:none}
  #bub{font-size:12px;margin-top:4px}
  #lb{margin:10px 0 2px;height:18px}
  #lcar{top:-24px;font-size:22px}
  .lm{padding:7px 18px;font-size:15px}
  #lmodes{margin-top:4px}
}

@media (max-width:640px){
  #lk svg{width:auto;height:min(238px,22vh)}
  #lg{max-width:94vw;padding:6px 18px 6px 34px}
  #lg .g1,#lg .g2{font-size:min(56px,11.5vw);-webkit-text-stroke:min(8px,1.6vw) #0b3b8f}
  #lsub{font-size:min(14px,3.6vw);padding:4px 14px}
  #lb{margin:min(26px,3vh) 0 6px}
  .lm{padding:10px 22px;font-size:17px}
}

@keyframes chipin{from{transform:scale(.6);opacity:0}}
@keyframes chipbeat{50%{transform:scale(1.1)}}
@media (prefers-reduced-motion:reduce){#top .bn.chip,#mnb.chip{animation:none}#top .bn.open{transition:none}}
